-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
265 lines (207 loc) · 7.49 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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
# compiler env.
UNAME := $(shell uname -s)
ifeq ($(UNAME),Linux)
CXX=ccache clang++
LDLIBS=-ldl
SHARED_CXXFLAGS= -fPIC -shared
endif
ifeq ($(UNAME),Darwin)
CXX=ccache clang++
LDLIBS=-stdlib=libc++
SHARED_CXXFLAGS= -flat_namespace -dynamiclib
endif
CXXFLAGS=-std=c++2a -MMD -MP -Wall
LDFLAGS=-pthread
# project config
SRC_DIR ?= ./src
INC_DIR=./include
TEST_DIR=./test
FDK_DIR=./fdk
EXF_DIR=./example_filter
EXI_DIR=./example_source
EXO_DIR=./example_sink
EXC_DIR=./example_codec
LIB_DIR=./lib
LIB_FILTER_DIR=$(LIB_DIR)/filter-plugin
LIB_SOURCE_DIR=$(LIB_DIR)/source-plugin
LIB_SINK_DIR=$(LIB_DIR)/sink-plugin
LIB_CODEC_DIR=$(LIB_DIR)/codec-plugin
BIN_DIR=./bin
OBJ_DIR=./out
# --- source code config --------------
INCS = $(wildcard $(INC_DIR)/*.hpp)
AFW_SRCS = $(wildcard $(SRC_DIR)/*.cpp)
TEST_SRCS = $(wildcard $(TEST_DIR)/*.cpp)
INTEG_SRCS = $(AFW_SRCS) $(TEST_SRCS)
FDK_SRCS = $(wildcard $(FDK_DIR)/*.cpp)
FEX_SRCS = $(wildcard $(EXF_DIR)/*.cpp)
EXI_SRCS = $(wildcard $(EXI_DIR)/*.cpp)
EXO_SRCS = $(wildcard $(EXO_DIR)/*.cpp)
EXC_SRCS = $(wildcard $(EXC_DIR)/*.cpp)
# --- the object files config --------------
AFW_OBJS = $(addprefix $(OBJ_DIR)/, $(notdir $(AFW_SRCS:.cpp=.o)))
TEST_OBJS = $(addprefix $(OBJ_DIR)/, $(notdir $(TEST_SRCS:.cpp=.o)))
INTEG_OBJS = $(addprefix $(OBJ_DIR)/, $(notdir $(INTEG_SRCS:.cpp=.o)))
FDK_OBJS = $(addprefix $(OBJ_DIR)/, $(notdir $(FDK_SRCS:.cpp=.o)))
FEX_OBJS = $(addprefix $(OBJ_DIR)/, $(notdir $(FEX_SRCS:.cpp=.o)))
EXI_OBJS = $(addprefix $(OBJ_DIR)/, $(notdir $(EXI_SRCS:.cpp=.o)))
EXO_OBJS = $(addprefix $(OBJ_DIR)/, $(notdir $(EXO_SRCS:.cpp=.o)))
EXC_OBJS = $(addprefix $(OBJ_DIR)/, $(notdir $(EXC_SRCS:.cpp=.o)))
# --- build gtest (integrated) --------
INTEG_TARGET = $(BIN_DIR)/afw_test
INTEG_DEPS = $(INTEG_OBJS:.o=.d)
default: $(INTEG_TARGET)
.PHONY: default
#$(INTEG_TARGET): $(INTEG_SRCS)
# @[ -d $(BIN_DIR) ] || mkdir -p $(BIN_DIR)
# $(CXX) $(CXXFLAGS) -I$(INC_DIR) $(LDLIBS) -o $@ $^ -lgtest_main -lgtest
$(INTEG_TARGET): $(INTEG_OBJS)
@[ -d $(BIN_DIR) ] || mkdir -p $(BIN_DIR)
$(CXX) $(LDFLAGS) $(INTEG_OBJS) -o $@ $(LDLIBS) -lgtest_main -lgtest
$(AFW_OBJS): $(AFW_SRCS)
@[ -d $(OBJ_DIR) ] || mkdir -p $(OBJ_DIR)
$(CXX) $(CXXFLAGS) -I $(INC_DIR) -c src/$(notdir $(@:.o=.cpp)) -o $@
$(TEST_OBJS): $(TEST_SRCS)
@[ -d $(OBJ_DIR) ] || mkdir -p $(OBJ_DIR)
$(CXX) $(CXXFLAGS) -I $(INC_DIR) -c test/$(notdir $(@:.o=.cpp)) -o $@
-include $(INTEG_DEPS)
# --- Build for AFW -------------------
AFW_TARGET = $(LIB_DIR)/libafw.a
AFW_DEPS = $(AFW_OBJS:.o=.d)
afw: $(AFW_TARGET)
.PHONY: afw
CXXFLAGS+= -fPIC #-flto=full
$(AFW_TARGET): $(AFW_OBJS)
@[ -d $(LIB_DIR) ] || mkdir -p $(LIB_DIR)
ar rs $(AFW_TARGET) $(AFW_OBJS)
ranlib -c $(AFW_TARGET)
# $(AR) rvs $(AFW_TARGET) $(AFW_OBJS)
# ranlib -c $@
-include $(AFW_DEPS)
# --- Build for AFW(shared) ------------
UNAME := $(shell uname -s)
ifeq ($(UNAME),Linux)
AFW_SO_TARGET = $(LIB_DIR)/libafw.so
endif
ifeq ($(UNAME),Darwin)
AFW_SO_TARGET = $(LIB_DIR)/libafw.dylib
endif
afwshared: $(AFW_SO_TARGET)
.PHONY: afwshared
$(AFW_SO_TARGET): $(AFW_OBJS)
@[ -d $(LIB_DIR) ] || mkdir -p $(LIB_DIR)
$(CXX) $(LDFLAGS) $(AFW_OBJS) $(SHARED_CXXFLAGS) -o $@ $(LDLIBS)
# --- Build for test cases w/libafw.a ---
TEST_TARGET = $(BIN_DIR)/test_with_afwlib
TEST_LDLIBS = $(LDLIBS) -L$(LIB_DIR)
TEST_LIBS = $(AFW_TARGET)
test: $(TEST_TARGET)
.PHONY: test
$(TEST_TARGET): $(TEST_OBJS)
@[ -d $(BIN_DIR) ] || mkdir -p $(BIN_DIR)
$(CXX) $(LDFLAGS) $(TEST_LDLIBS) $(TEST_OBJS) $(TEST_LIBS) -o $@ -lgtest_main -lgtest
# --- Build for test cases w/libafw.so ---
TEST_SHARED_TARGET = $(BIN_DIR)/test_with_afwlib_so
TEST_LDLIBS = $(LDLIBS) -L$(LIB_DIR)
TEST_LIBS = $(AFW_SO_TARGET)
testshared: $(TEST_SHARED_TARGET)
.PHONY: testshared
$(TEST_SHARED_TARGET): $(TEST_OBJS)
@[ -d $(BIN_DIR) ] || mkdir -p $(BIN_DIR)
$(CXX) $(LDFLAGS) $(TEST_LDLIBS) $(TEST_OBJS) $(TEST_LIBS) -o $@ -lgtest_main -lgtest
# --- Build for FDK w/libafw.a ------------
FDK_TARGET = $(BIN_DIR)/fdk_exec
FDK_LDLIBS = $(LDLIBS) -L$(LIB_DIR)
FDK_LIBS = $(AFW_SO_TARGET)
#FDK_LIBS = $(AFW_TARGET)
FDK_DEPS = $(FDK_OBJS:.o=.d)
fdk: $(FDK_TARGET)
.PHONY: fdk
$(FDK_TARGET): $(FDK_OBJS)
@[ -d $(BIN_DIR) ] || mkdir -p $(BIN_DIR)
$(CXX) $(LDFLAGS) $(FDK_LDLIBS) $(FDK_OBJS) $(FDK_LIBS) -o $@
$(FDK_OBJS): $(FDK_SRCS)
@[ -d $(OBJ_DIR) ] || mkdir -p $(OBJ_DIR)
$(CXX) $(CXXFLAGS) -I $(INC_DIR) -c fdk/$(notdir $(@:.o=.cpp)) -o $@
-include $(FDK_DEPS)
# --- Build for filter example(shared) ------------
UNAME := $(shell uname -s)
ifeq ($(UNAME),Linux)
FEX_SO_TARGET = $(LIB_FILTER_DIR)/libfilter_example.so
endif
ifeq ($(UNAME),Darwin)
FEX_SO_TARGET = $(LIB_FILTER_DIR)/libfilter_example.dylib
endif
FDK_DEPS = $(FEX_OBJS:.o=.d)
filterexample: $(FEX_SO_TARGET)
.PHONY: filterexample
$(FEX_SO_TARGET): $(FEX_OBJS)
@[ -d $(LIB_DIR) ] || mkdir -p $(LIB_DIR)
@[ -d $(LIB_FILTER_DIR) ] || mkdir -p $(LIB_FILTER_DIR)
$(CXX) $(LDFLAGS) $(FEX_OBJS) $(SHARED_CXXFLAGS) -o $@ $(LDLIBS) $(AFW_SO_TARGET)
$(FEX_OBJS): $(FEX_SRCS)
@[ -d $(OBJ_DIR) ] || mkdir -p $(OBJ_DIR)
$(CXX) $(CXXFLAGS) -I $(INC_DIR) -c $(EXF_DIR)/$(notdir $(@:.o=.cpp)) -o $@
-include $(FEX_DEPS)
# --- Build for source example(shared) ------------
UNAME := $(shell uname -s)
ifeq ($(UNAME),Linux)
EXI_SO_TARGET = $(LIB_SOURCE_DIR)/libsource_example.so
endif
ifeq ($(UNAME),Darwin)
EXI_SO_TARGET = $(LIB_SOURCE_DIR)/libsource_example.dylib
endif
EXI_DEPS = $(EXI_OBJS:.o=.d)
sourceexample: $(EXI_SO_TARGET)
.PHONY: sourceexample
$(EXI_SO_TARGET): $(EXI_OBJS)
@[ -d $(LIB_DIR) ] || mkdir -p $(LIB_DIR)
@[ -d $(LIB_SOURCE_DIR) ] || mkdir -p $(LIB_SOURCE_DIR)
$(CXX) $(LDFLAGS) $(EXI_OBJS) $(SHARED_CXXFLAGS) -o $@ $(LDLIBS) $(AFW_SO_TARGET)
$(EXI_OBJS): $(EXI_SRCS)
@[ -d $(OBJ_DIR) ] || mkdir -p $(OBJ_DIR)
$(CXX) $(CXXFLAGS) -I $(INC_DIR) -c $(EXI_DIR)/$(notdir $(@:.o=.cpp)) -o $@
-include $(EXI_DEPS)
# --- Build for sink example(shared) ------------
UNAME := $(shell uname -s)
ifeq ($(UNAME),Linux)
EXO_SO_TARGET = $(LIB_SINK_DIR)/libsink_example.so
endif
ifeq ($(UNAME),Darwin)
EXO_SO_TARGET = $(LIB_SINK_DIR)/libsink_example.dylib
endif
EXO_DEPS = $(EXO_OBJS:.o=.d)
sinkexample: $(EXO_SO_TARGET)
.PHONY: sinkexample
$(EXO_SO_TARGET): $(EXO_OBJS)
@[ -d $(LIB_DIR) ] || mkdir -p $(LIB_DIR)
@[ -d $(LIB_SINK_DIR) ] || mkdir -p $(LIB_SINK_DIR)
$(CXX) $(LDFLAGS) $(EXO_OBJS) $(SHARED_CXXFLAGS) -o $@ $(LDLIBS) $(AFW_SO_TARGET)
$(EXO_OBJS): $(EXO_SRCS)
@[ -d $(OBJ_DIR) ] || mkdir -p $(OBJ_DIR)
$(CXX) $(CXXFLAGS) -I $(INC_DIR) -c $(EXO_DIR)/$(notdir $(@:.o=.cpp)) -o $@
-include $(EXO_DEPS)
# --- Build for codec example(shared) ------------
UNAME := $(shell uname -s)
ifeq ($(UNAME),Linux)
EXC_SO_TARGET = $(LIB_CODEC_DIR)/libcodec_example.so
endif
ifeq ($(UNAME),Darwin)
EXC_SO_TARGET = $(LIB_CODEC_DIR)/libcodec_example.dylib
endif
EXC_DEPS = $(EXC_OBJS:.o=.d)
codecexample: $(EXC_SO_TARGET)
.PHONY: codecexample
$(EXC_SO_TARGET): $(EXC_OBJS)
@[ -d $(LIB_DIR) ] || mkdir -p $(LIB_DIR)
@[ -d $(LIB_CODEC_DIR) ] || mkdir -p $(LIB_CODEC_DIR)
$(CXX) $(LDFLAGS) $(EXC_OBJS) $(SHARED_CXXFLAGS) -o $@ $(LDLIBS) $(AFW_SO_TARGET)
$(EXC_OBJS): $(EXC_SRCS)
@[ -d $(OBJ_DIR) ] || mkdir -p $(OBJ_DIR)
$(CXX) $(CXXFLAGS) -I $(INC_DIR) -c $(EXC_DIR)/$(notdir $(@:.o=.cpp)) -o $@
-include $(EXC_DEPS)
.PHONY: all
all: $(AFW_TARGET) $(AFW_SO_TARGET) $(TEST_TARGET) $(TEST_SHARED_TARGET) $(INTEG_TARGET) $(FDK_TARGET) $(FEX_SO_TARGET) $(EXI_SO_TARGET) $(EXO_SO_TARGET) $(EXC_SO_TARGET)
# --- clean up ------------------------
clean:
rm -f $(TARGET) $(TEST_TARGET) $(INTEG_TARGET) $(OBJS) $(AFW_DEPS) $(TEST_OBJS) $(INTEG_OBJS) $(INTEG_DEPS) $(FDK_OBJS) $(FDK_DEPS) $(FEX_OBJS) $(FEX_DEPS)