source: 3DVCSoftware/branches/0.3-poznan-univ/build/linux/common/makefile.base @ 67

Last change on this file since 67 was 48, checked in by poznan-univ, 13 years ago

some bug fix on high level syntax
fixed some compiler warning issues under windows and linux

File size: 12.0 KB
Line 
1#########################################################
2# check CONFIG parameter
3#########################################################
4
5ifneq ($(CONFIG), LIBRARY)
6ifneq ($(CONFIG), CONSOLE)
7CONFIG_ERR = TRUE
8endif
9endif
10
11#########################################################
12# executables used
13#########################################################
14
15CPP     = g++
16AR      = ar
17LD      = $(CPP)
18ASM             = nasm
19
20#########################################################
21# output file names and version information
22#########################################################
23
24ifeq ($(CONFIG), LIBRARY)
25# the libraries that can be created
26STAT_DEBUG_OUT          = $(LIB_DIR)/lib$(PRJ_NAME)Staticd.a
27STAT_RELEASE_OUT        = $(LIB_DIR)/lib$(PRJ_NAME)Static.a
28DYN_DEBUG_OUT           = $(LIB_DIR)/lib$(PRJ_NAME)d.so
29DYN_RELEASE_OUT         = $(LIB_DIR)/lib$(PRJ_NAME).so
30#
31else
32ifeq ($(CONFIG), CONSOLE)
33# the executables that can be created
34STAT_DEBUG_OUT    = $(BIN_DIR)/$(PRJ_NAME)Staticd
35STAT_RELEASE_OUT  = $(BIN_DIR)/$(PRJ_NAME)Static
36DYN_DEBUG_OUT     = $(BIN_DIR)/$(PRJ_NAME)d
37DYN_RELEASE_OUT   = $(BIN_DIR)/$(PRJ_NAME)
38#
39endif
40endif
41
42
43#########################################################
44# c compiler flags
45#########################################################
46
47# default cpp flags for all configurations
48#CPPFLAGS          = -Wall -fPIC $(DEFS) -I$(CURDIR)/$(INC_DIR) $(USER_INC_DIRS)
49CPPFLAGS          = -fPIC $(DEFS) -I$(CURDIR)/$(INC_DIR) $(USER_INC_DIRS) -Wall -Wshadow -Wno-sign-compare -Werror
50
51##########
52# enforce 32-bit build : 1=yes, 0=no
53##########
54M32?= 0
55ifeq ($(M32),1)
56CPPFLAGS+=-m32
57endif
58##########
59
60#
61# debug cpp flags
62DEBUG_CPPFLAGS    = -g  -D_DEBUG
63#
64# release cpp
65RELEASE_CPPFLAGS  =  -O3 -ffloat-store -Wuninitialized
66
67
68#########################################################
69# assembler compiler flags
70#########################################################
71
72# default asm flags for all configurations
73ASMFLAGS          = -f elf $(DEFS)
74#
75# debug asm flags
76DEBUG_ASMFLAGS    = -g
77#
78# release asm flags
79RELEASE_ASMFLAGS  =
80
81
82
83#########################################################
84# linker flags
85#########################################################
86
87# linker flags for all
88ALL_LDFLAGS       = -Wall
89
90##########
91# enforce 32-bit build : 1=yes, 0=no
92##########
93ifeq ($(M32),1)
94ALL_LDFLAGS+=-m32
95endif
96##########
97
98
99ifeq ($(CONFIG), LIBRARY)
100# linker flags for library
101# LDFLAGS           = $(ALL_LDFLAGS) -shared -Wl,-Bsymbolic
102LDFLAGS           = $(ALL_LDFLAGS) -shared
103#
104# debug linker flags for library
105DEBUG_LDFLAGS     = -Wl,-soname,lib$(PRJ_NAME)d.so.$(VER)
106#
107# release linker flags for library
108RELEASE_LDFLAGS   = -Wl,-soname,lib$(PRJ_NAME).so.$(VER)
109#
110else
111ifeq ($(CONFIG), CONSOLE)
112# linker flags for console
113LDFLAGS           = $(ALL_LDFLAGS)
114#
115# debug linker flags for console
116DEBUG_LDFLAGS     =
117#
118# release linker flags for console
119RELEASE_LDFLAGS   =
120#
121endif
122endif
123
124
125
126#########################################################
127# objects that have to be created
128#########################################################
129
130# the object types that have to be created     
131RELEASE_OBJS  = $(OBJS:.o=.r.o)
132DEBUG_OBJS    = $(OBJS:.o=.d.o)
133
134
135#########################################################
136# rules
137#########################################################
138
139# suffixes
140.SUFFIXES: .cpp .asm .r.o .d.o
141
142#########################################################
143# assembler rules
144#########################################################
145
146
147# create release objects
148$(OBJ_DIR)/%.r.o: $(SRC_DIR)/%.asm
149        $(ASM) $(ASMFLAGS) $(RELEASE_ASMFLAGS) -o $@ $<
150
151# create debug objects
152$(OBJ_DIR)/%.d.o: $(SRC_DIR)/%.asm
153        $(ASM) $(ASMFLAGS) $(DEBUG_ASMFLAGS) -o $@ $<
154
155# create release objects
156$(OBJ_DIR)/%.r.o: $(SRC_DIR1)/%.asm
157        $(ASM) $(ASMFLAGS) $(RELEASE_ASMFLAGS) -o $@ $<
158
159# create debug objects
160$(OBJ_DIR)/%.d.o: $(SRC_DIR1)/%.asm
161        $(ASM) $(ASMFLAGS) $(DEBUG_ASMFLAGS) -o $@ $<
162
163# create release objects
164$(OBJ_DIR)/%.r.o: $(SRC_DIR2)/%.asm
165        $(ASM) $(ASMFLAGS) $(RELEASE_ASMFLAGS) -o $@ $<
166
167# create debug objects
168$(OBJ_DIR)/%.d.o: $(SRC_DIR2)/%.asm
169        $(ASM) $(ASMFLAGS) $(DEBUG_ASMFLAGS) -o $@ $<
170
171# create release objects
172$(OBJ_DIR)/%.r.o: $(SRC_DIR3)/%.asm
173        $(ASM) $(ASMFLAGS) $(RELEASE_ASMFLAGS) -o $@ $<
174
175# create debug objects
176$(OBJ_DIR)/%.d.o: $(SRC_DIR3)/%.asm
177        $(ASM) $(ASMFLAGS) $(DEBUG_ASMFLAGS) -o $@ $<
178
179# create release objects
180$(OBJ_DIR)/%.r.o: $(SRC_DIR4)/%.asm
181        $(ASM) $(ASMFLAGS) $(RELEASE_ASMFLAGS) -o $@ $<
182
183# create debug objects
184$(OBJ_DIR)/%.d.o: $(SRC_DIR4)/%.asm
185        $(ASM) $(ASMFLAGS) $(DEBUG_ASMFLAGS) -o $@ $<
186
187
188
189#########################################################
190# c rules
191#########################################################
192
193# Generate dependency files during compilation
194# see also: http://make.paulandlesley.org/autodep.html
195#    2005-01-25 Steffen Kamp (kamp@ient.rwth-aachen.de), RWTH Aachen
196define COMPILE_AND_DEPEND_RELEASE
197        $(CPP) -c -MMD -MF $(OBJ_DIR)/$*.r.d -MT $(OBJ_DIR)/$*.r.o $(CPPFLAGS) $(RELEASE_CPPFLAGS) -o $@ $(CURDIR)/$<
198        @cp $(OBJ_DIR)/$*.r.d $(OBJ_DIR)/$*.r.P; \
199                sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \
200                -e '/^$$/ d' -e 's/$$/ :/' < $(OBJ_DIR)/$*.r.d >> $(OBJ_DIR)/$*.r.P; \
201                rm -f $(OBJ_DIR)/$*.r.d
202endef
203define COMPILE_AND_DEPEND_DEBUG
204        $(CPP) -c -MMD -MF $(OBJ_DIR)/$*.d.d -MT $(OBJ_DIR)/$*.d.o $(CPPFLAGS) $(DEBUG_CPPFLAGS) -o $@ $(CURDIR)/$<
205        @cp $(OBJ_DIR)/$*.d.d $(OBJ_DIR)/$*.d.P; \
206                sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \
207                -e '/^$$/ d' -e 's/$$/ :/' < $(OBJ_DIR)/$*.d.d >> $(OBJ_DIR)/$*.d.P; \
208                rm -f $(OBJ_DIR)/$*.d.d
209endef
210
211# create release objects
212$(OBJ_DIR)/%.r.o: $(SRC_DIR)/%.cpp
213        $(COMPILE_AND_DEPEND_RELEASE)
214
215# create debug objects
216$(OBJ_DIR)/%.d.o: $(SRC_DIR)/%.cpp
217        $(COMPILE_AND_DEPEND_DEBUG)
218
219# create release objects
220$(OBJ_DIR)/%.r.o: $(SRC_DIR1)/%.cpp
221        $(COMPILE_AND_DEPEND_RELEASE)
222
223# create debug objects
224$(OBJ_DIR)/%.d.o: $(SRC_DIR1)/%.cpp
225        $(COMPILE_AND_DEPEND_DEBUG)
226
227# create release objects
228$(OBJ_DIR)/%.r.o: $(SRC_DIR2)/%.cpp
229        $(COMPILE_AND_DEPEND_RELEASE)
230
231# create debug objects
232$(OBJ_DIR)/%.d.o: $(SRC_DIR2)/%.cpp
233        $(COMPILE_AND_DEPEND_DEBUG)
234
235# create release objects
236$(OBJ_DIR)/%.r.o: $(SRC_DIR3)/%.cpp
237        $(COMPILE_AND_DEPEND_RELEASE)
238
239# create debug objects
240$(OBJ_DIR)/%.d.o: $(SRC_DIR3)/%.cpp
241        $(COMPILE_AND_DEPEND_DEBUG)
242
243# create release objects
244$(OBJ_DIR)/%.r.o: $(SRC_DIR4)/%.cpp
245        $(COMPILE_AND_DEPEND_RELEASE)
246
247# create debug objects
248$(OBJ_DIR)/%.d.o: $(SRC_DIR4)/%.cpp
249        $(COMPILE_AND_DEPEND_DEBUG)
250
251# create release objects
252$(OBJ_DIR)/%.r.o: $(SRC_DIR)/%.c
253        $(COMPILE_AND_DEPEND_RELEASE)
254
255# create debug objects
256$(OBJ_DIR)/%.d.o: $(SRC_DIR)/%.c
257        $(COMPILE_AND_DEPEND_DEBUG)
258
259# create release objects
260$(OBJ_DIR)/%.r.o: $(SRC_DIR1)/%.c
261        $(COMPILE_AND_DEPEND_RELEASE)
262
263# create debug objects
264$(OBJ_DIR)/%.d.o: $(SRC_DIR1)/%.c
265        $(COMPILE_AND_DEPEND_DEBUG)
266
267# create release objects
268$(OBJ_DIR)/%.r.o: $(SRC_DIR2)/%.c
269        $(COMPILE_AND_DEPEND_RELEASE)
270
271# create debug objects
272$(OBJ_DIR)/%.d.o: $(SRC_DIR2)/%.c
273        $(COMPILE_AND_DEPEND_DEBUG)
274
275# create release objects
276$(OBJ_DIR)/%.r.o: $(SRC_DIR3)/%.c
277        $(COMPILE_AND_DEPEND_RELEASE)
278
279# create debug objects
280$(OBJ_DIR)/%.d.o: $(SRC_DIR3)/%.c
281        $(COMPILE_AND_DEPEND_DEBUG)
282
283# create release objects
284$(OBJ_DIR)/%.r.o: $(SRC_DIR4)/%.c
285        $(COMPILE_AND_DEPEND_RELEASE)
286
287# create debug objects
288$(OBJ_DIR)/%.d.o: $(SRC_DIR4)/%.c
289        $(COMPILE_AND_DEPEND_DEBUG)
290
291
292#########################################################
293# directory settings
294#########################################################
295
296ifeq ($(CONFIG), LIBRARY)
297# directories that have to be created for a library
298CHECK_DIRS = $(OBJ_DIR) $(LIB_DIR)
299#
300else
301ifeq ($(CONFIG), CONSOLE)
302# directories that have to be created for console and MFC
303CHECK_DIRS = $(OBJ_DIR) $(BIN_DIR)
304#
305endif
306endif
307
308
309#########################################################
310# targets
311#########################################################
312
313all:                    check_errors debug release
314
315debug:                  check_errors \
316                                        $(CHECK_DIRS) \
317                                        $(STAT_DEBUG_OUT)
318
319release:                check_errors \
320                                        $(CHECK_DIRS) \
321                                        $(STAT_RELEASE_OUT)
322
323
324#all:                   check_errors debug release
325#
326#debug:                 check_errors \
327#                                       $(CHECK_DIRS) \
328#                                       $(DYN_DEBUG_OUT) \
329#                                       $(STAT_DEBUG_OUT)
330#
331#release:               check_errors \
332#                                       $(CHECK_DIRS) \
333#                                       $(DYN_RELEASE_OUT) \
334#                                       $(STAT_RELEASE_OUT)
335#
336#stat_debug:            check_errors \
337#                                       $(CHECK_DIRS) \
338#                                       $(STAT_DEBUG_OUT)
339#         
340#dyn_debug:             check_errors \
341#                                       $(CHECK_DIRS) \
342#                                       $(DYN_DEBUG_OUT)
343#
344#stat_release:          check_errors \
345#                                       $(CHECK_DIRS) \
346#                                       $(STAT_RELEASE_OUT)
347#       
348#dyn_release:           check_errors \
349#                                       $(CHECK_DIRS) \
350#                                       $(DYN_RELEASE_OUT)
351
352##########################################################
353# check for errors
354##########################################################
355check_errors:
356        @if [ "$(CONFIG_ERR)" = "TRUE" ]; then\
357                echo "Wrong CONFIG parameter specified: $(CONFIG)";\
358                false;\
359        fi
360
361
362##########################################################
363# create directories
364##########################################################
365
366$(OBJ_DIR):
367        @if [ ! -d $(OBJ_DIR) ]; then\
368                mkdir $(OBJ_DIR);\
369        fi
370
371$(LIB_DIR):
372        @if [ ! -d $(LIB_DIR) ]; then\
373                mkdir $(LIB_DIR);\
374        fi
375
376$(BIN_DIR):
377        @if [ ! -d $(BIN_DIR) ]; then\
378                mkdir $(BIN_DIR);\
379        fi
380
381
382
383##########################################################
384# create output files
385##########################################################
386
387ifeq ($(CONFIG), LIBRARY)
388#
389# create static debug out
390$(STAT_DEBUG_OUT): $(DEBUG_OBJS)
391        $(AR) -crs $@ $(DEBUG_OBJS)
392#
393#
394# create release debug out
395$(STAT_RELEASE_OUT): $(RELEASE_OBJS)
396        $(AR) -crs $@ $(RELEASE_OBJS)
397#
398#
399# create dynamic debug out
400$(DYN_DEBUG_OUT): $(DYN_DEBUG_OUT).$(VER)
401        ln -fs lib$(PRJ_NAME)d.so.$(VER) $@
402#
403# create dynamic debug out
404$(DYN_DEBUG_OUT).$(VER): $(DEBUG_OBJS)
405        $(LD) $(LDFLAGS) $(DEBUG_LDFLAGS) -o $@ $(DEBUG_OBJS) -L$(LIB_DIR) $(USER_LIB_DIRS) $(LIBS) $(DEBUG_LIBS) $(DYN_LIBS) $(DYN_DEBUG_LIBS)
406#
407#
408# create dynamic release out
409$(DYN_RELEASE_OUT): $(DYN_RELEASE_OUT).$(VER)
410        ln -fs lib$(PRJ_NAME).so.$(VER) $@
411#
412# create dynamic release out
413$(DYN_RELEASE_OUT).$(VER): $(RELEASE_OBJS)
414        $(LD) $(LDFLAGS) $(RELEASE_LDFLAGS) -o $@ $(RELEASE_OBJS) -L$(LIB_DIR) $(USER_LIB_DIRS) $(LIBS) $(RELEASE_LIBS) $(DYN_LIBS) $(DYN_RELEASE_LIBS)
415#
416#
417#
418#
419#
420else
421ifeq ($(CONFIG), CONSOLE)
422#
423# added linked libraries to target prerequisites - $(*_PREREQS) variables - to force relinking when libraries have been rebuilt
424#    2005-01-25 Steffen Kamp (kamp@ient.rwth-aachen.de), RWTH Aachen
425#
426# create static debug out
427$(STAT_DEBUG_OUT): $(DEBUG_OBJS) $(STAT_DEBUG_PREREQS)
428        $(LD) -o $@ $(LDFLAGS) $(DEBUG_LDFLAGS) $(DEBUG_OBJS) -L$(LIB_DIR) $(USER_LIB_DIRS) $(LIBS) $(DEBUG_LIBS) $(STAT_LIBS) $(STAT_DEBUG_LIBS)
429#
430#
431# create static release out
432$(STAT_RELEASE_OUT): $(RELEASE_OBJS) $(STAT_RELEASE_PREREQS)
433        $(LD) -o $@ $(LDFLAGS) $(RELEASE_LDFLAGS) $(RELEASE_OBJS) -L$(LIB_DIR) $(USER_LIB_DIRS) $(LIBS) $(RELEASE_LIBS) $(STAT_LIBS) $(STAT_RELEASE_LIBS)
434#
435#
436# create dynamic debug out
437$(DYN_DEBUG_OUT): $(DEBUG_OBJS) $(DYN_DEBUG_PREREQS)
438        $(LD) -o $@ $(LDFLAGS) $(DEBUG_LDFLAGS) $(DEBUG_OBJS) -L$(LIB_DIR) $(USER_LIB_DIRS) $(LIBS) $(DEBUG_LIBS) $(DYN_LIBS) $(DYN_DEBUG_LIBS)
439#
440#
441# create dynamic release out
442$(DYN_RELEASE_OUT): $(RELEASE_OBJS) $(DYN_RELEASE_PREREQS)
443        $(LD) -o $@ $(LDFLAGS) $(RELEASE_LDFLAGS) $(RELEASE_OBJS) -L$(LIB_DIR) $(USER_LIB_DIRS) $(LIBS) $(RELEASE_LIBS) $(DYN_LIBS) $(DYN_RELEASE_LIBS)
444#
445#
446endif
447endif
448
449##########################################################
450# delete all produced files
451##########################################################
452
453clean:
454        /bin/rm -rf $(STAT_DEBUG_OUT)
455        /bin/rm -rf $(STAT_RELEASE_OUT)
456        /bin/rm -rf $(DYN_DEBUG_OUT)
457        /bin/rm -rf $(DYN_RELEASE_OUT)
458        /bin/rm -rf $(OBJ_DIR)
459
460ifeq ($(CONFIG), LIBRARY)
461        /bin/rm -rf $(DYN_DEBUG_OUT).$(VER)
462        /bin/rm -rf $(DYN_RELEASE_OUT).$(VER)
463endif
464
465
466##########################################################
467# include dependency files
468##########################################################
469
470-include $(OBJS:.o=.d.P)
471-include $(OBJS:.o=.r.P)
Note: See TracBrowser for help on using the repository browser.