-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
executable file
·162 lines (133 loc) · 5.5 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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
SRC := src
BUILD := build
OBJ := ${BUILD}/obj
SHARED_OBJ := ${BUILD}/shared
BIN := ${BUILD}/bin
SRC_COMMON := ${SRC}/common_includes
SRC_SERIAL := ${SRC}/serial_includes
SRC_OMP := ${SRC}/omp_includes
SRC_PARALLEL := ${SRC}/parallel_includes
LIBS := -lpopt -lglut -lGLU -lGL -lm `pkg-config --cflags --libs opencv`
FLAGS := -O2 -std=c++17 -w
DEBUGFLAGS := -g -std=c++17
SUBDIRECTORIES := $(sort $(dir $(wildcard $(SRC)/*/*/)))
DIRECTORIES := $(patsubst $(SRC)/%, $(SHARED_OBJ)/%, $(SUBDIRECTORIES)) $(patsubst $(SRC)/%, $(OBJ)/%, $(SUBDIRECTORIES)) ${BIN}
$(shell mkdir -p ${DIRECTORIES})
ifneq (,$(findstring clean, $(MAKECMDGOALS))) # Prevent searching for compilers if the make target clean
else
ifeq ($(video), 1)
FLAGS := ${FLAGS} -DSHOW_VIDEO
endif
ifeq ($(profile), 1)
FLAGS := ${FLAGS} -DPROFILE
endif
ifeq ($(serial), 1)
CHECK := $(shell g++ --version >/dev/null 2>&1 || (echo "Failed to search for g++ with error: $$"))
SRCS_COMMON := $(wildcard $(SRC_COMMON)/*/*.cpp)
SRCS_SERIAL := $(wildcard $(SRC_SERIAL)/*/*.cpp)
OBJS := $(patsubst $(SRC)/%.cpp, $(OBJ)/%.cpp.o, $(SRCS_COMMON)) $(patsubst $(SRC)/%.cpp, $(OBJ)/%.cpp.o, $(SRCS_SERIAL))
SHARED_OBJS := $(patsubst $(SRC)/%.cpp, $(SHARED_OBJ)/%.cpp.o, $(SRCS_COMMON)) $(patsubst $(SRC)/%.cpp, $(SHARED_OBJ)/%.cpp.o, $(SRCS_SERIAL))
FLAGS := ${FLAGS} -ffast-math
ifeq (,${CHECK})
COMPILER := g++
$(info C++ compiler found: g++)
$(info )
else # Check for clang if g++ is unavailable
CHECK2 := $(shell clang --version >/dev/null 2>&1 || (echo "Failed to search for clang with error: $$?"))
ifeq (,${CHECK2})
$(info C++ compiler found: clang)
$(info )
COMPILER := clang
LIBS := -lstdc++ ${LIBS}
else
$(error No C++ compilers found.)
endif
endif
EXECUTABLE := ${BIN}/stereo_vision_serial
SHARED_LIBRARY := ${BIN}/stereo_vision_serial.so
LIBS := ${LIBS} -lpthread
SHARED_FLAGS := ${FLAGS} -shared -fPIC
else ifeq ($(omp), 1)
CHECK := $(shell g++ --version >/dev/null 2>&1 || (echo "Failed to search for g++ with error: $$"))
SRCS_COMMON := $(wildcard $(SRC_COMMON)/*/*.cpp)
SRCS_OMP := $(wildcard $(SRC_OMP)/*/*.cpp)
OBJS := $(patsubst $(SRC)/%.cpp, $(OBJ)/%.cpp.o, $(SRCS_COMMON)) $(patsubst $(SRC)/%.cpp, $(OBJ)/%.cpp.o, $(SRCS_OMP))
SHARED_OBJS := $(patsubst $(SRC)/%.cpp, $(SHARED_OBJ)/%.cpp.o, $(SRCS_COMMON)) $(patsubst $(SRC)/%.cpp, $(SHARED_OBJ)/%.cpp.o, $(SRCS_OMP))
FLAGS := ${FLAGS} -ffast-math
ifeq (,${CHECK})
COMPILER := g++
$(info C++ compiler found: g++)
$(info )
else # Check for clang if g++ is unavailable
CHECK2 := $(shell clang --version >/dev/null 2>&1 || (echo "Failed to search for clang with error: $$?"))
ifeq (,${CHECK2})
$(info C++ compiler found: clang)
$(info )
COMPILER := clang
LIBS := -lstdc++ ${LIBS}
else
$(error No C++ compilers found.)
endif
endif
EXECUTABLE := ${BIN}/stereo_vision_omp
SHARED_LIBRARY := ${BIN}/stereo_vision_omp.so
FLAGS := ${FLAGS} -fopenmp
LIBS := ${LIBS} -lpthread
SHARED_FLAGS := ${FLAGS} -shared -fPIC
DEBUGFLAGS := ${DEBUGFLAGS} -fopenmp
else
SRCS_COMMON := $(wildcard $(SRC_COMMON)/*/*.cpp)
SRCS_PARALLEL := $(wildcard $(SRC_PARALLEL)/*/*.cpp)
SRCS_PARALLEL_CU := $(wildcard $(SRC_PARALLEL)/*/*.cu)
OBJS := $(patsubst $(SRC)/%.cpp, $(OBJ)/%.cpp.o, $(SRCS_COMMON)) $(patsubst $(SRC)/%.cpp, $(OBJ)/%.cpp.o, $(SRCS_PARALLEL)) $(patsubst $(SRC)/%.cu, $(OBJ)/%.cu.o, $(SRCS_PARALLEL_CU))
SHARED_OBJS := $(patsubst $(SRC)/%.cpp, $(SHARED_OBJ)/%.cpp.o, $(SRCS_COMMON)) $(patsubst $(SRC)/%.cpp, $(SHARED_OBJ)/%.cpp.o, $(SRCS_PARALLEL)) $(patsubst $(SRC)/%.cu, $(SHARED_OBJ)/%.cu.o, $(SRCS_PARALLEL_CU))
CHECK := $(shell nvcc --version >/dev/null 2>&1 || (echo "Failed to search for nvcc with error: $$?"))
ifeq (,${CHECK})
$(info CUDA/C++ compiler found: nvcc)
$(info )
COMPILER := nvcc
else
$(error No CUDA/C++ compilers found. Either install cuda-toolkit or try compiling the serial version)
endif
EXECUTABLE := ${BIN}/stereo_vision_parallel
SHARED_LIBRARY := ${BIN}/stereo_vision_parallel.so
ifeq ($(old), 1)
FLAGS := -gencode arch=compute_50,code=sm_50 -Wno-deprecated-gpu-targets ${FLAGS}
DEBUGFLAGS := -gencode arch=compute_50,code=sm_50 ${DEBUGFLAGS}
endif
SHARED_FLAGS := ${FLAGS} -shared --compiler-options="-fPIC -pie -ffast-math"
FLAGS := ${FLAGS} --compiler-options="-ffast-math" -Xcompiler="-pthread -fopenmp"
DEBUGFLAGS := ${DEBUGFLAGS} -Xcompiler="-pthread -fopenmp"
endif
endif
all:
make stereo_vision serial=1 -j12
make stereo_vision omp=1 -j12
make stereo_vision -j12
stereo_vision: ${OBJS}
@echo
${COMPILER} ${FLAGS} -o ${EXECUTABLE} ${OBJS} ${LIBS}
@echo
@echo "Compiled Successfully!! Run the program using ./${EXECUTABLE} -k path_to_kitti -v 1"
shared_library: FLAGS := ${SHARED_FLAGS}
shared_library: ${SHARED_OBJS}
@echo
${COMPILER} ${FLAGS} -o ${SHARED_LIBRARY} $^ ${LIBS}
@echo
@echo "Compiled the Shared Library Successfully!! You can find it at: ${SHARED_LIBRARY}"
debug: FLAGS := ${DEBUGFLAGS}
debug: ${OBJS}
@echo
${COMPILER} ${FLAGS} -o ${EXECUTABLE} $^ ${LIBS}
@echo
@echo "Compiled Successfully!! Run the program using ./${EXECUTABLE} -k path_to_kitti -v 1"
${OBJ}/%.cu.o: ${SRC}/%.cu
${COMPILER} ${FLAGS} ${LIBS} -c $^ -o $@
${OBJ}/%.cpp.o: ${SRC}/%.cpp
${COMPILER} ${FLAGS} ${LIBS} -c $^ -o $@
${SHARED_OBJ}/%.cu.o: ${SRC}/%.cu
${COMPILER} ${FLAGS} ${LIBS} -c $^ -o $@
${SHARED_OBJ}/%.cpp.o: ${SRC}/%.cpp
${COMPILER} ${FLAGS} ${LIBS} -c $^ -o $@
clean:
rm -rf ${BUILD}