-
Notifications
You must be signed in to change notification settings - Fork 0
/
makefile.base
486 lines (397 loc) · 12.8 KB
/
makefile.base
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
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
#########################################################
# check CONFIG parameter
#########################################################
ifneq ($(CONFIG), LIBRARY)
ifneq ($(CONFIG), CONSOLE)
CONFIG_ERR = TRUE
endif
endif
#########################################################
# executables used
#########################################################
CPP = clang++
CC = clang++
AR = ar
LD = $(CPP)
ASM = nasm
#########################################################
# output file names and version information
#########################################################
ifeq ($(CONFIG), LIBRARY)
# the libraries that can be created
STAT_DEBUG_OUT = $(LIB_DIR)/lib$(PRJ_NAME)Staticd.a
STAT_RELEASE_OUT = $(LIB_DIR)/lib$(PRJ_NAME)Static.a
DYN_DEBUG_OUT = $(LIB_DIR)/lib$(PRJ_NAME)d.so
DYN_RELEASE_OUT = $(LIB_DIR)/lib$(PRJ_NAME).so
#
else
ifeq ($(CONFIG), CONSOLE)
# the executables that can be created
STAT_DEBUG_OUT = $(BIN_DIR)/$(PRJ_NAME)d
STAT_RELEASE_OUT = $(BIN_DIR)/$(PRJ_NAME)
DYN_DEBUG_OUT = $(BIN_DIR)/$(PRJ_NAME)Dd
DYN_RELEASE_OUT = $(BIN_DIR)/$(PRJ_NAME)D
#
endif
endif
#########################################################
# c compiler flags
#########################################################
# default cpp flags for all configurations
#CPPFLAGS = -Wall $(DEFS) -I$(CURDIR)/$(INC_DIR) $(USER_INC_DIRS) -Werror
CPPFLAGS = $(DEFS) -I$(CURDIR)/$(INC_DIR) $(USER_INC_DIRS) -Wall -Wshadow -Wno-sign-compare -Werror -std=c++14
##########
# enforce 32-bit build : 1=yes, 0=no
##########
M32?= 0
ifeq ($(M32),1)
CPPFLAGS+=-m32
endif
##########
#
# debug cpp flags
DEBUG_CPPFLAGS = -g -D_DEBUG
#
# release cpp
RELEASE_CPPFLAGS = -O3 -Wuninitialized
#########################################################
# assembler compiler flags
#########################################################
# default asm flags for all configurations
ASMFLAGS = -f elf $(DEFS)
#
# debug asm flags
DEBUG_ASMFLAGS = -g
#
# release asm flags
RELEASE_ASMFLAGS =
#########################################################
# linker flags
#########################################################
# linker flags for all
ALL_LDFLAGS = -Wall
##########
# enforce 32-bit build : 1=yes, 0=no
##########
ifeq ($(M32),1)
ALL_LDFLAGS+=-m32
endif
##########
ifeq ($(CONFIG), LIBRARY)
# linker flags for library
# LDFLAGS = $(ALL_LDFLAGS) -shared -Wl,-Bsymbolic
LDFLAGS = $(ALL_LDFLAGS) -shared
#
# debug linker flags for library
DEBUG_LDFLAGS = -Wl,-soname,lib$(PRJ_NAME)d.so.$(VER)
#
# release linker flags for library
RELEASE_LDFLAGS = -Wl,-soname,lib$(PRJ_NAME).so.$(VER)
#
else
ifeq ($(CONFIG), CONSOLE)
# linker flags for console
LDFLAGS = $(ALL_LDFLAGS)
#
# debug linker flags for console
DEBUG_LDFLAGS =
#
# release linker flags for console
RELEASE_LDFLAGS =
#
endif
endif
#########################################################
# objects that have to be created
#########################################################
# the object types that have to be created
RELEASE_OBJS = $(OBJS:.o=.r.o)
DEBUG_OBJS = $(OBJS:.o=.d.o)
#########################################################
# rules
#########################################################
# suffixes
.SUFFIXES: .cpp .asm .r.o .d.o
#########################################################
# assembler rules
#########################################################
# create release objects
$(OBJ_DIR)/%.r.o: $(SRC_DIR)/%.asm
$(ASM) $(ASMFLAGS) $(RELEASE_ASMFLAGS) -o $@ $<
# create debug objects
$(OBJ_DIR)/%.d.o: $(SRC_DIR)/%.asm
$(ASM) $(ASMFLAGS) $(DEBUG_ASMFLAGS) -o $@ $<
# create release objects
$(OBJ_DIR)/%.r.o: $(SRC_DIR1)/%.asm
$(ASM) $(ASMFLAGS) $(RELEASE_ASMFLAGS) -o $@ $<
# create debug objects
$(OBJ_DIR)/%.d.o: $(SRC_DIR1)/%.asm
$(ASM) $(ASMFLAGS) $(DEBUG_ASMFLAGS) -o $@ $<
# create release objects
$(OBJ_DIR)/%.r.o: $(SRC_DIR2)/%.asm
$(ASM) $(ASMFLAGS) $(RELEASE_ASMFLAGS) -o $@ $<
# create debug objects
$(OBJ_DIR)/%.d.o: $(SRC_DIR2)/%.asm
$(ASM) $(ASMFLAGS) $(DEBUG_ASMFLAGS) -o $@ $<
# create release objects
$(OBJ_DIR)/%.r.o: $(SRC_DIR3)/%.asm
$(ASM) $(ASMFLAGS) $(RELEASE_ASMFLAGS) -o $@ $<
# create debug objects
$(OBJ_DIR)/%.d.o: $(SRC_DIR3)/%.asm
$(ASM) $(ASMFLAGS) $(DEBUG_ASMFLAGS) -o $@ $<
# create release objects
$(OBJ_DIR)/%.r.o: $(SRC_DIR4)/%.asm
$(ASM) $(ASMFLAGS) $(RELEASE_ASMFLAGS) -o $@ $<
# create debug objects
$(OBJ_DIR)/%.d.o: $(SRC_DIR4)/%.asm
$(ASM) $(ASMFLAGS) $(DEBUG_ASMFLAGS) -o $@ $<
#########################################################
# c rules
#########################################################
# Generate dependency files during compilation
# see also: http://make.paulandlesley.org/autodep.html
# 2005-01-25 Steffen Kamp (kamp@ient.rwth-aachen.de), RWTH Aachen
define COMPILE_AND_DEPEND_RELEASE
$(CPP) -c -MMD -MF $(OBJ_DIR)/$*.r.d -MT $(OBJ_DIR)/$*.r.o $(CPPFLAGS) $(RELEASE_CPPFLAGS) -o $@ $(CURDIR)/$<
@cp $(OBJ_DIR)/$*.r.d $(OBJ_DIR)/$*.r.P; \
sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \
-e '/^$$/ d' -e 's/$$/ :/' < $(OBJ_DIR)/$*.r.d >> $(OBJ_DIR)/$*.r.P; \
rm -f $(OBJ_DIR)/$*.r.d
endef
define COMPILE_AND_DEPEND_DEBUG
$(CPP) -c -MMD -MF $(OBJ_DIR)/$*.d.d -MT $(OBJ_DIR)/$*.d.o $(CPPFLAGS) $(DEBUG_CPPFLAGS) -o $@ $(CURDIR)/$<
@cp $(OBJ_DIR)/$*.d.d $(OBJ_DIR)/$*.d.P; \
sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \
-e '/^$$/ d' -e 's/$$/ :/' < $(OBJ_DIR)/$*.d.d >> $(OBJ_DIR)/$*.d.P; \
rm -f $(OBJ_DIR)/$*.d.d
endef
define COMPILE_AND_DEPEND_RELEASE_C
$(CC) -c -MMD -MF $(OBJ_DIR)/$*.r.d -MT $(OBJ_DIR)/$*.r.o $(CPPFLAGS) $(RELEASE_CPPFLAGS) -o $@ $(CURDIR)/$<
@cp $(OBJ_DIR)/$*.r.d $(OBJ_DIR)/$*.r.P; \
sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \
-e '/^$$/ d' -e 's/$$/ :/' < $(OBJ_DIR)/$*.r.d >> $(OBJ_DIR)/$*.r.P; \
rm -f $(OBJ_DIR)/$*.r.d
endef
define COMPILE_AND_DEPEND_DEBUG_C
$(CC) -c -MMD -MF $(OBJ_DIR)/$*.d.d -MT $(OBJ_DIR)/$*.d.o $(CPPFLAGS) $(DEBUG_CPPFLAGS) -o $@ $(CURDIR)/$<
@cp $(OBJ_DIR)/$*.d.d $(OBJ_DIR)/$*.d.P; \
sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \
-e '/^$$/ d' -e 's/$$/ :/' < $(OBJ_DIR)/$*.d.d >> $(OBJ_DIR)/$*.d.P; \
rm -f $(OBJ_DIR)/$*.d.d
endef
# create release objects
$(OBJ_DIR)/%.r.o: $(SRC_DIR)/%.cpp
$(COMPILE_AND_DEPEND_RELEASE)
# create debug objects
$(OBJ_DIR)/%.d.o: $(SRC_DIR)/%.cpp
$(COMPILE_AND_DEPEND_DEBUG)
# create release objects
$(OBJ_DIR)/%.r.o: $(SRC_DIR1)/%.cpp
$(COMPILE_AND_DEPEND_RELEASE)
# create debug objects
$(OBJ_DIR)/%.d.o: $(SRC_DIR1)/%.cpp
$(COMPILE_AND_DEPEND_DEBUG)
# create release objects
$(OBJ_DIR)/%.r.o: $(SRC_DIR2)/%.cpp
$(COMPILE_AND_DEPEND_RELEASE)
# create debug objects
$(OBJ_DIR)/%.d.o: $(SRC_DIR2)/%.cpp
$(COMPILE_AND_DEPEND_DEBUG)
# create release objects
$(OBJ_DIR)/%.r.o: $(SRC_DIR3)/%.cpp
$(COMPILE_AND_DEPEND_RELEASE)
# create debug objects
$(OBJ_DIR)/%.d.o: $(SRC_DIR3)/%.cpp
$(COMPILE_AND_DEPEND_DEBUG)
# create release objects
$(OBJ_DIR)/%.r.o: $(SRC_DIR4)/%.cpp
$(COMPILE_AND_DEPEND_RELEASE)
# create debug objects
$(OBJ_DIR)/%.d.o: $(SRC_DIR4)/%.cpp
$(COMPILE_AND_DEPEND_DEBUG)
# create release objects
$(OBJ_DIR)/%.r.o: $(SRC_DIR)/%.c
$(COMPILE_AND_DEPEND_RELEASE_C)
# create debug objects
$(OBJ_DIR)/%.d.o: $(SRC_DIR)/%.c
$(COMPILE_AND_DEPEND_DEBUG_C)
# create release objects
$(OBJ_DIR)/%.r.o: $(SRC_DIR1)/%.c
$(COMPILE_AND_DEPEND_RELEASE_C)
# create debug objects
$(OBJ_DIR)/%.d.o: $(SRC_DIR1)/%.c
$(COMPILE_AND_DEPEND_DEBUG_C)
# create release objects
$(OBJ_DIR)/%.r.o: $(SRC_DIR2)/%.c
$(COMPILE_AND_DEPEND_RELEASE_C)
# create debug objects
$(OBJ_DIR)/%.d.o: $(SRC_DIR2)/%.c
$(COMPILE_AND_DEPEND_DEBUG_C)
# create release objects
$(OBJ_DIR)/%.r.o: $(SRC_DIR3)/%.c
$(COMPILE_AND_DEPEND_RELEASE_C)
# create debug objects
$(OBJ_DIR)/%.d.o: $(SRC_DIR3)/%.c
$(COMPILE_AND_DEPEND_DEBUG_C)
# create release objects
$(OBJ_DIR)/%.r.o: $(SRC_DIR4)/%.c
$(COMPILE_AND_DEPEND_RELEASE_C)
# create debug objects
$(OBJ_DIR)/%.d.o: $(SRC_DIR4)/%.c
$(COMPILE_AND_DEPEND_DEBUG_C)
#########################################################
# directory settings
#########################################################
ifeq ($(CONFIG), LIBRARY)
# directories that have to be created for a library
CHECK_DIRS = $(OBJ_DIR) $(LIB_DIR)
#
else
ifeq ($(CONFIG), CONSOLE)
# directories that have to be created for console and MFC
CHECK_DIRS = $(OBJ_DIR) $(BIN_DIR)
#
endif
endif
#########################################################
# targets
#########################################################
all: check_errors release
debug: check_errors \
$(CHECK_DIRS) \
$(STAT_DEBUG_OUT)
release: check_errors \
$(CHECK_DIRS) \
$(STAT_RELEASE_OUT)
#all: check_errors debug release
#
#debug: check_errors \
# $(CHECK_DIRS) \
# $(DYN_DEBUG_OUT) \
# $(STAT_DEBUG_OUT)
#
#release: check_errors \
# $(CHECK_DIRS) \
# $(DYN_RELEASE_OUT) \
# $(STAT_RELEASE_OUT)
#
#stat_debug: check_errors \
# $(CHECK_DIRS) \
# $(STAT_DEBUG_OUT)
#
#dyn_debug: check_errors \
# $(CHECK_DIRS) \
# $(DYN_DEBUG_OUT)
#
#stat_release: check_errors \
# $(CHECK_DIRS) \
# $(STAT_RELEASE_OUT)
#
#dyn_release: check_errors \
# $(CHECK_DIRS) \
# $(DYN_RELEASE_OUT)
##########################################################
# check for errors
##########################################################
check_errors:
@if [ "$(CONFIG_ERR)" = "TRUE" ]; then\
echo "Wrong CONFIG parameter specified: $(CONFIG)";\
false;\
fi
##########################################################
# create directories
##########################################################
$(OBJ_DIR):
@if [ ! -d $(OBJ_DIR) ]; then\
mkdir $(OBJ_DIR);\
fi
$(LIB_DIR):
@if [ ! -d $(LIB_DIR) ]; then\
mkdir $(LIB_DIR);\
fi
$(BIN_DIR):
@if [ ! -d $(BIN_DIR) ]; then\
mkdir $(BIN_DIR);\
fi
##########################################################
# create output files
##########################################################
ifeq ($(CONFIG), LIBRARY)
#
# create static debug out
$(STAT_DEBUG_OUT): $(DEBUG_OBJS)
$(AR) -crs $@ $(DEBUG_OBJS)
#
#
# create release debug out
$(STAT_RELEASE_OUT): $(RELEASE_OBJS)
$(AR) -crs $@ $(RELEASE_OBJS)
#
#
# create dynamic debug out
$(DYN_DEBUG_OUT): $(DYN_DEBUG_OUT).$(VER)
ln -fs lib$(PRJ_NAME)d.so.$(VER) $@
#
# create dynamic debug out
$(DYN_DEBUG_OUT).$(VER): $(DEBUG_OBJS)
$(LD) $(LDFLAGS) $(DEBUG_LDFLAGS) -o $@ $(DEBUG_OBJS) -L$(LIB_DIR) $(USER_LIB_DIRS) $(LIBS) $(DEBUG_LIBS) $(DYN_LIBS) $(DYN_DEBUG_LIBS)
#
#
# create dynamic release out
$(DYN_RELEASE_OUT): $(DYN_RELEASE_OUT).$(VER)
ln -fs lib$(PRJ_NAME).so.$(VER) $@
#
# create dynamic release out
$(DYN_RELEASE_OUT).$(VER): $(RELEASE_OBJS)
$(LD) $(LDFLAGS) $(RELEASE_LDFLAGS) -o $@ $(RELEASE_OBJS) -L$(LIB_DIR) $(USER_LIB_DIRS) $(LIBS) $(RELEASE_LIBS) $(DYN_LIBS) $(DYN_RELEASE_LIBS)
#
#
#
#
#
else
ifeq ($(CONFIG), CONSOLE)
#
# added linked libraries to target prerequisites - $(*_PREREQS) variables - to force relinking when libraries have been rebuilt
# 2005-01-25 Steffen Kamp (kamp@ient.rwth-aachen.de), RWTH Aachen
#
# create static debug out
$(STAT_DEBUG_OUT): $(DEBUG_OBJS) $(STAT_DEBUG_PREREQS)
$(LD) -o $@ $(LDFLAGS) $(DEBUG_LDFLAGS) $(DEBUG_OBJS) -L$(LIB_DIR) $(USER_LIB_DIRS) $(LIBS) $(DEBUG_LIBS) $(STAT_LIBS) $(STAT_DEBUG_LIBS)
#
#
# create static release out
$(STAT_RELEASE_OUT): $(RELEASE_OBJS) $(STAT_RELEASE_PREREQS)
$(LD) -o $@ $(LDFLAGS) $(RELEASE_LDFLAGS) $(RELEASE_OBJS) -L$(LIB_DIR) $(USER_LIB_DIRS) $(LIBS) $(RELEASE_LIBS) $(STAT_LIBS) $(STAT_RELEASE_LIBS)
#
#
# create dynamic debug out
$(DYN_DEBUG_OUT): $(DEBUG_OBJS) $(DYN_DEBUG_PREREQS)
$(LD) -o $@ $(LDFLAGS) $(DEBUG_LDFLAGS) $(DEBUG_OBJS) -L$(LIB_DIR) $(USER_LIB_DIRS) $(LIBS) $(DEBUG_LIBS) $(DYN_LIBS) $(DYN_DEBUG_LIBS)
#
#
# create dynamic release out
$(DYN_RELEASE_OUT): $(RELEASE_OBJS) $(DYN_RELEASE_PREREQS)
$(LD) -o $@ $(LDFLAGS) $(RELEASE_LDFLAGS) $(RELEASE_OBJS) -L$(LIB_DIR) $(USER_LIB_DIRS) $(LIBS) $(RELEASE_LIBS) $(DYN_LIBS) $(DYN_RELEASE_LIBS)
#
#
endif
endif
##########################################################
# delete all produced files
##########################################################
clean:
/bin/rm -rf $(STAT_DEBUG_OUT)
/bin/rm -rf $(STAT_RELEASE_OUT)
/bin/rm -rf $(DYN_DEBUG_OUT)
/bin/rm -rf $(DYN_RELEASE_OUT)
/bin/rm -rf $(OBJ_DIR)
ifeq ($(CONFIG), LIBRARY)
/bin/rm -rf $(DYN_DEBUG_OUT).$(VER)
/bin/rm -rf $(DYN_RELEASE_OUT).$(VER)
endif
##########################################################
# include dependency files
##########################################################
-include $(OBJS:.o=.d.P)
-include $(OBJS:.o=.r.P)