-
Notifications
You must be signed in to change notification settings - Fork 7
/
Makefile
114 lines (84 loc) · 2.69 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
CUDAVERSION=cuda
CC = g++
CUCC = /usr/local/$(CUDAVERSION)/bin/nvcc -m64 -ccbin $(CC)
LIBDIR=lib64
TENSORRT_LIB_PATH = /usr/lib/x86_64-linux-gnu/
TENSORRT_INC_PATH = /usr/include/x86_64-linux-gnu/
OPENCV_LIB_PATH = /usr/lib/x86_64-linux-gnu/
OPENCV_INC_PATH = /usr/include/opencv4/
VERBOSE = 1
ifdef VERBOSE
AT=
else
AT=@
endif
ECHO = @echo
SHELL=/bin/sh
OUT_PATH=.
OUTDIR=$(OUT_PATH)
define concat
$1$2$3$4$5$6$7$8
endef
#$(call make-depend,source-file,object-file,depend-file)
define make-depend
$(AT)$(CC) -MM -MF $3 -MP -MT $2 $(COMMON_FLAGS) $1
endef
#########################
INCPATHS =-I./include
LIBPATHS =-L$(TENSORRT_LIB_PATH)
INCPATHS +=-I$(TENSORRT_INC_PATH) -I./src
INCPATHS +=-I/usr/local/$(CUDAVERSION)/include
LIBPATHS +=-L/usr/local/$(CUDAVERSION)/$(LIBDIR)
INCPATHS +=-I$(OPENCV_INC_PATH)
LIBPATHS +=-L$(OPENCV_LIB_PATH)
.SUFFIXES:
# COMMON_FLAGS += -Wall
COMMON_FLAGS += -std=c++11 $(INCPATHS)
COMMON_LD_FLAGS=$(LIBPATHS) -L$(OUTDIR)
OBJDIR =$(call concat,$(OUTDIR),/chobj)
# TEST_OBJDIR =$(call concat,$(OUTDIR),/testobj)
COMMON_LIBS = -lnvinfer -lcudart -lopencv_core -lopencv_imgproc -lopencv_imgcodecs -lcublas -lnvinfer_plugin
COMMON_LD_FLAGS += $(COMMON_LIBS)
OUTNAME_RELEASE = libnvocdr.so
SRC_ROOT=./src
CSRCS:= $(wildcard $(SRC_ROOT)/*.cpp)
COBJS:= $(notdir $(CSRCS:.cpp=.o))
OBJS=$(foreach obj, $(COBJS), $(OBJDIR)/$(obj))
CUSRCS:= $(wildcard $(SRC_ROOT)/*.cu)
TCUOBJS:= $(notdir $(CUSRCS:.cu=.o))
CUOBJS=$(foreach obj, $(TCUOBJS), $(OBJDIR)/$(obj))
# TEST_OBJS:= $(TEST_OBJDIR)/test_main.o
CFLAGS=$(COMMON_FLAGS)
LFLAGS=$(COMMON_LD_FLAGS)
all: release
release : $(OUTDIR)/$(OUTNAME_RELEASE)
# release:
# $(ECHO) $(OBJS)
# $(ECHO) $(CUOBJS)
# $(ECHO) $(CFLAGS)
# $(ECHO) $(LFLAGS)
# $(OUTDIR)/$(OUTNAME_RELEASE) : $(OBJS) $(TEST_OBJS) $(CUOBJS)
$(OUTDIR)/$(OUTNAME_RELEASE) : $(OBJS) $(CUOBJS)
$(ECHO) Linking: $@
$(AT)$(CC) -shared -Wl,-no-undefined -o $@ $^ $(LFLAGS) $(LIBS)
$(OBJDIR)/%.o: $(SRC_ROOT)/%.cpp
$(AT)if [ ! -d $(OBJDIR) ]; then mkdir -p $(OBJDIR); fi
$(call make-depend,$<,$@,$(subst .o,.d,$@))
$(ECHO) Compiling: $<
$(AT)$(CC) $(CFLAGS) -fPIC -c -o $@ $<
# $(TEST_OBJDIR)/%.o: %.cpp
# $(AT)if [ ! -d $(TEST_OBJDIR) ]; then mkdir -p $(TEST_OBJDIR); fi
# $(call make-depend,$<,$@,$(subst .o,.d,$@))
# $(ECHO) Compiling: $<
# $(AT)$(CC) $(CFLAGS) -fPIC -c -o $@ $<
$(OBJDIR)/%.o: $(SRC_ROOT)/%.cu
$(AT)if [ ! -d $(OBJDIR) ]; then mkdir -p $(OBJDIR); fi
$(call make-depend,$<,$@,$(subst .o,.d,$@))
$(ECHO) Compiling: $<
$(AT)$(CUCC) --compiler-options '-fPIC' $(CFLAGS) -c -o $@ $<
clean:
$(ECHO) Cleaning...
$(AT)-rm -rf $(OBJDIR) $(TEST_OBJDIR) $(OUTDIR)/$(OUTNAME_RELEASE)
ifneq "$(MAKECMDGOALS)" "clean"
-include $(OBJDIR)/*.d
endif