yep, mac needed the start-group stuff turned off.
[feisty_meow.git] / scripts / clam / cpp / rules.def
1 ###############################################################################
2
3 # CLAM System default rules and targets for C++ compilation.
4
5 # This file composite macros and rules for creating compilation objects
6 # (such as library archives, object files, executable programs, and others).
7
8 # This file should be included in the user's Makefile after the variables
9 # have been initialized appropriately for the particular project being
10 # compiled.  The user's own targets should be placed after the include
11 # directive that specifies this file.
12
13 ###############################################################################
14
15 # This section manipulates variable values to prepare them for their use
16 # in the standard CLAM support.
17
18 # special actions for projects that are tests.
19 ifneq "$(findstring test, $(TYPE))" ""
20   # add the clean task at the end, so that we will always rebuild the tests
21   # and run them again.
22 #hmmm: this is a kludge to make sure we always run the tests.  there has got
23 #      to be a better way.
24   LAST_TARGETS += clean
25 endif
26
27 # see if they have got the clean flag set.  if so, we will not build anything.
28 ifneq "$(CLEAN)" ""
29   NO_COMPILE = t
30 endif
31 # also omit version compilation and some logging when not compiling.
32 ifneq "$(NO_COMPILE)" ""
33   QUIET = t
34 endif
35
36 # implement special bits for gnu on unix.
37 ifeq "$(COMPILER)" "GNU_LINUX"
38   ifneq "$(USE_XWIN)" ""
39     ifneq "$(OP_SYSTEM)" "WIN32"
40       DEFINITIONS += __XWINDOWS__ __X__
41       LIBS_USED += Xm Xt X11 Xft Xp 
42 #need to separate out with a USE_MOTIF kind of thing.
43 LIBS_USED += Xmu
44       HEADER_SEARCH_PATH += /usr/include/X11 /usr/X11R6/include /usr/include/g++
45       LIBRARY_SEARCH_PATH += /usr/X11R6/lib 
46     endif
47   endif
48
49   ifneq "$(USE_SSL)" ""
50     LIBS_USED += ssl crypto
51   endif
52   
53   ifneq "$(USE_WXWIDGETS)" ""
54     DEFINITIONS += __WXWIDGETS__ 
55     use_unicode =
56     ifneq "$(findstring UNICODE, $(DEFINITIONS))" ""
57 #      ifeq "$(OP_SYSTEM)" "WIN32"
58         use_unicode = true
59 #      endif
60     endif
61
62     # decide whether to turn on the unicode flag or not.
63     ifneq "$(use_unicode)" ""
64       DEFINITIONS += wxUSE_UNICODE
65       UNICODE_FLAG_ADD = --unicode=yes
66     else
67       UNICODE_FLAG_ADD = --unicode=no
68     endif
69     # could add for debugging: --debug=yes 
70     COMPILER_FLAGS += $(shell wx-config --cxxflags $(UNICODE_FLAG_ADD) )
71
72     LOAD_FLAG_PREFIX += $(shell wx-config --libs $(UNICODE_FLAG_ADD) )
73   endif
74
75   ifneq "$(USE_CURL)" ""
76     COMPILER_FLAGS += `curl-config --cflags`
77     LOAD_FLAG_SUFFIX += `curl-config --static-libs`
78   endif
79
80 endif
81
82 ###############################################################################
83
84 ifeq "$(COMPILER)" "GNU_DARWIN"
85   ifneq "$(USE_XWIN)" ""
86     DEFINITIONS += __XWINDOWS__ __X__
87     LIBS_USED += 
88 #Xm Xt X11 Xft Xp 
89 #need to separate out with a USE_MOTIF kind of thing.
90 #LIBS_USED += Xmu
91     HEADER_SEARCH_PATH += /usr/include/X11 /usr/X11R6/include /usr/include/g++
92     LIBRARY_SEARCH_PATH += /usr/X11R6/lib 
93   endif
94
95   ifneq "$(USE_SSL)" ""
96     LIBS_USED += crypto
97   endif
98   
99   ifneq "$(USE_WXWIDGETS)" ""
100     DEFINITIONS += __WXWIDGETS__ 
101     use_unicode =
102     ifneq "$(findstring UNICODE, $(DEFINITIONS))" ""
103 #      ifeq "$(OP_SYSTEM)" "WIN32"
104         use_unicode = true
105 #      endif
106     endif
107
108     # decide whether to turn on the unicode flag or not.
109 ###    ifneq "$(findstring UNICODE, $(DEFINITIONS))" ""
110     ifneq "$(use_unicode)" ""
111       UNICODE_FLAG_ADD = --unicode=yes
112       DEFINITIONS += wxUSE_UNICODE
113     else
114       UNICODE_FLAG_ADD = --unicode=no
115     endif
116
117     COMPILER_FLAGS += $(shell wx-config --cxxflags $(UNICODE_FLAG_ADD) )
118     LOAD_FLAG_PREFIX += $(shell wx-config --libs $(UNICODE_FLAG_ADD) )
119   endif
120
121   ifneq "$(USE_CURL)" ""
122     COMPILER_FLAGS += `curl-config --cflags`
123     LOAD_FLAG_SUFFIX += `curl-config --libs`
124   endif
125
126 endif
127
128 ###############################################################################
129
130
131 # additions for gnu x86 and arm compilers.
132 ifneq "$(OP_SYSTEM)" "WIN32"
133   # is the freetds library support available on this host.
134   ifneq "$(ENABLE_FREETDS)" ""
135     # establish the headers if freetds is enabled.  that just means things
136     # can be compiled against it.  to link in the db-lib, the makefile should
137     # have a 'USE_FREETDS = true' statement.
138
139     # is this particular library or app using freetds?
140     ifneq "$(USE_FREETDS)" ""
141       DEFINITIONS += ENABLE_FREETDS _FREETDS_LIBRARY_SOURCE
142       LIBS_USED += rt sybdb 
143     endif
144   endif
145 endif
146
147 # win32 compiler additions.
148 ifeq "$(OP_SYSTEM)" "WIN32"
149   # processes the def file for linkage, if one has been specified.
150   ifneq "$(DEF_FILE)" ""
151     LOAD_FLAG_PREFIX += -def:$(DEF_FILE)
152   endif
153
154   ifneq "$(TYPE)" "library"
155     ifneq "$(USE_MFC)" ""
156       ifneq "$(findstring UNICODE, $(DEFINITIONS))" "" 
157         # specify the winmain type for unicode explicitly.
158         LOAD_FLAG_PREFIX += -entry:wWinMainCRTStartup
159       endif
160     endif
161   endif
162
163   # these are loaded after any special debugging libs.
164   ifneq "$(VCPP_USE_BASE)" ""
165     # the first set will be included in almost any old program.  we include
166     # winmm for multimedia in the base support since we make heavy use of the
167     # more accurate uptime function.
168     LOAD_FLAG_PREFIX += kernel32.lib user32.lib advapi32.lib shell32.lib \
169       version.lib winmm.lib shlwapi.lib 
170   endif
171
172   ifneq "$(USE_WXWIDGETS)" ""
173     DEFINITIONS += __WXWIDGETS__ __WXMSW__ 
174     LOCAL_HEADERS += $(THIRD_PARTY_DIR)/wxwidgets/include 
175     LIBRARY_SEARCH_PATH += $(THIRD_PARTY_DIR)/wxwidgets/lib
176 #    ifeq "$(findstring UNICODE, $(DEFINITIONS))" ""
177       LIBS_USED += wxmsw28_core.lib
178       LOCAL_HEADERS += $(THIRD_PARTY_DIR)/wxwidgets/lib/msw
179 #    else
180 #      DEFINITIONS += wxUSE_UNICODE
181 #      LIBS_USED += wxmsw28u_core.lib
182 #      LOCAL_HEADERS += $(THIRD_PARTY_DIR)/wxwidgets/lib/mswu
183 #    endif
184
185 ##    LOAD_FLAG_PREFIX += comctl32.lib shell32.lib
186     VCPP_USE_GUI = t
187     VCPP_USE_OLE = t
188   endif
189
190   ifneq "$(USE_CURL)" ""
191     DEFINITIONS += _WIN32
192     LOCAL_HEADERS += $(THIRD_PARTY_DIR)/curl/include
193     LIBRARY_SEARCH_PATH += $(THIRD_PARTY_DIR)/curl/lib
194 #    ifeq "$(findstring libcurl, $(LIBS_USED))" ""
195       LIBS_USED += libcurl.dll.a
196 #    endif
197   endif
198
199   ifneq "$(VCPP_USE_GUI)" ""
200     LOAD_FLAG_PREFIX += comctl32.lib comdlg32.lib gdi32.lib winspool.lib
201   endif
202
203   ifneq "$(VCPP_USE_OLE)" ""
204     LOAD_FLAG_PREFIX += ole32.lib oleaut32.lib uuid.lib
205     VCPP_USE_RPC = t
206   endif
207   ifneq "$(VCPP_USE_RPC)" ""
208     ifeq "$(COMPILER_VERSION)" "8"
209       LOAD_FLAG_PREFIX += rpcndr.lib rpcns4.lib rpcrt4.lib
210     endif
211     ifeq "$(COMPILER_VERSION)" "10"
212       LOAD_FLAG_PREFIX += rpcrt4.lib
213     endif
214     VCPP_USE_SOCK = t
215   endif
216   ifneq "$(VCPP_USE_SOCK)" ""
217     LOAD_FLAG_PREFIX += netapi32.lib ws2_32.lib
218   endif
219   ifneq "$(VCPP_USE_CLR)" ""
220     LOAD_FLAG_PREFIX += -noentry -include:"__DllMainCRTStartup@12"
221     COMPILER_FLAGS += -EHa -clr -AI "$(FRAMEWORK_DIR)" -AI "$(DYNAMIC_LIBRARY_DIR)" -FU "mscorlib.dll" -FU "System.dll" -FU "System.Data.dll" -FU "System.Windows.Forms.dll" -FU "System.Drawing.dll"
222   endif
223
224   ifneq "$(USE_SSL)" ""
225     LOCAL_HEADERS += $(THIRD_PARTY_DIR)/openssl/include
226     LIBRARY_SEARCH_PATH += $(THIRD_PARTY_DIR)/openssl/lib
227     LIBS_USED += libeay32.lib
228     $(shell cp $(THIRD_PARTY_DIR)/openssl/lib/*dll $(EXECUTABLE_DIR) )
229   endif
230   
231 endif
232
233 ifeq "$(OP_SYSTEM)" "WIN32"
234   # prep the actual source variable so that certain file names are translated.
235   ACTUAL_RESX = $(RESX:%.resx=$(OBJECT_DIR)/%.resources)
236   ACTUAL_RESX_FLAGS = $(ACTUAL_RESX:%=-ASSEMBLYLINKRESOURCE:%) 
237 else
238   ACTUAL_RESX = 
239   ACTUAL_RESX_FLAGS = 
240 endif
241
242 # Create the real list of local libraries needed.
243 TEMP_LOC1 = $(LOCAL_LIBS_USED:%=%$(TRIPART_VERSION))
244 ACTUAL_LOCAL_LIBS = $(TEMP_LOC1)
245
246 # Create the list of objects from the list of source files.
247 TEMP_OBJ1 = $(SOURCE:%.cpp=%.obj)
248 TEMP_OBJ2 = $(TEMP_OBJ1:%.c=%.obj)
249 ifeq "$(OP_SYSTEM)" "WIN32"
250   ifneq "$(OMIT_VERSIONS)" ""
251     # remove version rc files if we're not dealing with versions.
252     TEMP_OBJ3a = $(TEMP_OBJ2:%_version.rc=)
253   else
254     TEMP_OBJ3a = $(TEMP_OBJ2)
255   endif
256   TEMP_OBJ3 = $(TEMP_OBJ3a:%.rc=%.res)
257 else
258   # replace this when supporting resource files on unix.
259   TEMP_OBJ3 = $(TEMP_OBJ2:%.rc=)
260 endif
261 TEMP_OBJ4 = $(TEMP_OBJ3:%.h=%.bad)
262 OBJECTS = $(TEMP_OBJ4)
263
264 # special case for multi-build and res files that need to be rebuilt.
265 #RES_OBJECTS_0 = $(SOURCE:%.cpp=)
266 #RES_OBJECTS_1 = $(RES_OBJECTS_0:%.c=)
267 #RES_OBJECTS = $(RES_OBJECTS_1:%.rc=$(OBJECT_DIR)/%.res)
268
269 # not much conversion anymore...
270 ACTUAL_OBJECTS = $(OBJECTS) $(EXTRA_OBJECTS)
271
272 # Updates the search path for the compiler and local libraries.
273 BASE_HEADER_PATH = $(CODEBASE_HEADERS) $(LOCAL_HEADERS) $(HOOPLE_HEADERS) $(SEARCH_DIRS)
274 HEADER_SEARCH_PATH += $(BASE_HEADER_PATH) $(COMPILER_HEADER_DIR)
275
276 LIBRARY_SEARCH_PATH += $(LOCAL_LIBRARIES) $(HOOPLE_LIBRARIES) \
277   $(STATIC_LIBRARY_DIR) $(COMPILER_LIBRARY_DIR) $(SEARCH_DIRS)
278
279 # Adds some directories that must be searched onto the search path for
280 # header files, such as the header file directory for the compiler.
281 COMPILER_FLAGS += $(HEADER_SEARCH_PATH:%=-I%) $(DEFINITIONS:%=-D%) $(UNDEFINITIONS:%=-U%) -DGLOBAL_PRODUCT_NAME="$(GLOBAL_PRODUCT_NAME)"
282
283 # The load flags are updated by looking for code libraries in the directories
284 # to search and by adding all of the code libraries that are used.
285 LOAD_FLAG_PREFIX += $(LIBRARY_SEARCH_PATH:%=$(LIBRARY_PATH_FLAG)%)
286 ifeq "$(OP_SYSTEM)" "UNIX"
287   ifneq "$(COMPILER)" "GNU_DARWIN"
288     LOAD_FLAG_PREFIX += -Xlinker --start-group
289     LOAD_FLAG_SUFFIX += -Xlinker --end-group
290   endif
291 endif
292 # had to switch from prefix to suffix recently.  oddity.
293 #LOAD_FLAG_PREFIX += $(LIBS_USED:%=$(LIBRARY_NAME_FLAG)%)
294 LOAD_FLAG_SUFFIX += $(LIBS_USED:%=$(LIBRARY_NAME_FLAG)%)
295
296 # we steal the exe targets and represent their dependency from the hidden
297 # cpp for the exe.
298 EXE_TEMP_0 = $(TARGETS:%.dll=)
299 EXE_TEMP_1 = $(EXE_TEMP_0:%.so=)
300 EXE_TEMP_2 = $(EXE_TEMP_1:%.lib=)
301 EXE_TEMP_3 = $(EXE_TEMP_2:%.elf=%.cpp)
302 EXE_CPPS   = $(EXE_TEMP_3:%.exe=%.cpp)
303
304 # used for compiling multiple source files at the same time with visual cpp.
305 MULTI_BUILD_CMD = $(CC) $(COMPILER_FLAGS) -c `cat $(BUILD_LIST_FILE)` $(OBJECT_NAME_FLAG)$(OBJECT_DIR)/
306
307 # prepare for mfc style DLLs.  currently we plan on all dlls we create being
308 # based on MFC.  this is an unfortunate requirement for using the mfc debug
309 # support for allocations; if regular new and DEBUG_NEW get mixed together,
310 # crashes used to result.  supposedly these are gone now at least.
311 ifneq "$(USE_MFC)" ""
312   ifeq "$(OP_SYSTEM)" "WIN32"
313     # set the flag that says we are doing mfc extension dlls.
314     DEFINITIONS += _AFXDLL
315     DEPENDENCY_DEFINITIONS += _MT _DLL
316     DEPENDENCY_DEFINITIONS += __AFXWIN_H__  # add this flag to shut stdafx up.
317   endif
318 endif
319
320 ifeq "$(OMIT_VERSIONS)" ""
321   ifneq "$(VERSION_RC_ROOT)" ""
322     VERSION_TARGET = $(VERSION_RC_ROOT)_version.rc
323   endif
324 endif
325
326 ifneq "$(GENDEPS)" ""
327   EXTRA_FIRST_TARGETS += gendeps
328 endif
329
330 # only do the deps generation for makefiles that are properly marked.
331 ifneq "$(findstring __BUILD_STATIC_APPLICATION__, $(DEFINITIONS))" ""
332   # generate static build dependencies for all targets in the makefile.
333   GENERATED_DEPS_LIST = $(TARGETS:%.exe=%.gendeps)
334 endif
335
336 # Make sure that the directory for objects exists.
337 ACTUAL_FIRST_TARGETS = check_requirements $(EXTRA_FIRST_TARGETS) $(VERSION_TARGET) $(FIRST_TARGETS) pre_compilation
338
339 # Adds the primary targets to the list of products to create.
340 ifeq "$(NO_COMPILE)" ""
341   ifeq "$(OP_SYSTEM)" "UNIX"
342     ACTUAL_TARGETS1 = $(TARGETS:%.exe=$(EXECUTABLE_DIR)/%)
343   else
344     ACTUAL_TARGETS1 = $(TARGETS:%.exe=$(EXECUTABLE_DIR)/%.exe)
345   endif
346   ifeq "$(OP_SYSTEM)" "UNIX"
347     ACTUAL_TARGETS2 = $(ACTUAL_TARGETS1:%.dll=%.so)
348     ACTUAL_TARGETS3 = $(ACTUAL_TARGETS2:%.so=$(DYNAMIC_LIBRARY_DIR)/%$(TRIPART_VERSION).so)
349   else
350     ACTUAL_TARGETS2 = $(ACTUAL_TARGETS1:%.so=%.dll)
351     ACTUAL_TARGETS3 = $(ACTUAL_TARGETS2:%.dll=$(DYNAMIC_LIBRARY_DIR)/%$(TRIPART_VERSION).dll)
352   endif
353   ACTUAL_TARGETS4 = $(ACTUAL_TARGETS3:%.lib=$(STATIC_LIBRARY_DIR)/%$(TRIPART_VERSION).library)
354   ACTUAL_TARGETS = $(ACTUAL_TARGETS4:%.elf=$(EXECUTABLE_DIR)/%.elf)
355 else #is no_compile
356   ACTUAL_TARGETS1 = $(TARGETS:%.exe=)
357   ACTUAL_TARGETS2 = $(ACTUAL_TARGETS1:%.dll=)
358   ACTUAL_TARGETS3 = $(ACTUAL_TARGETS2:%.so=)
359   ACTUAL_TARGETS4 = $(ACTUAL_TARGETS3:%.lib=)
360   ACTUAL_TARGETS = $(ACTUAL_TARGETS4:%.elf=)
361 endif
362
363 # Adds the last few targets for CLAM to do.
364 ACTUAL_LAST_TARGETS = post_compilation $(LAST_TARGETS)
365
366 ############################################################################
367
368 # This section defines the rules used to generate various objects from their
369 # source files.
370
371 ############################################################################
372
373 # The first section provides simplistic pseudo-targets for testing compilation
374 # rather than generating built products.
375
376 # the blank target is used to (somewhat) safely remove items from the SOURCE
377 # list.  it is an empty file that should be able to go in a library archive
378 # without hosing it up.
379 %.nil:
380 ifeq "$(NO_COMPILE)" ""
381         $(CATCHER)$(CC) -c $(CLAM_DIR)/cpp/blank_target.c -o $@
382 endif
383
384 %.bad:
385         @echo There is a problem with the makefile in the SOURCE variable.
386         @echo The offending item is: $@
387         $(HIDESH)$(CLAM_DIR)/exit_make.sh
388
389 ## faked debug object.
390 #%.obj: %.cpp
391 #ifeq "$(NO_COMPILE)" ""
392 #       @echo Bogus [$@].
393 #       $(CATCHER)$(CC) $(COMPILER_FLAGS) -c $< $(OBJECT_NAME_FLAG)$(TEMP)/$@
394 #endif
395
396 # recreate dependencies for static applications.
397 %.gendeps: %.cpp
398         @echo "Generating Static Deps: $*.cpp"
399         $(CATCHER)$(CLAM_DIR)/cpp/buildor_gen_deps.sh "$*.cpp"
400
401 ############################################################################
402
403 # C++ source to object file translation.
404 # if there is a special set of flags for this source file, we use them
405 # instead of the default compiler flags.
406
407 $(OBJECT_DIR)/%.obj: $(CURRENT_DIR)/%.cpp
408 ifeq "$(NO_COMPILE)" ""
409   ifneq "$(COMPILER)" "VISUAL_CPP"
410         @echo Compiling [$(shell basename $@)]
411         $(HIDESH)-c 'if [ ! -d $(@D) ]; then mkdir $(@D); fi'
412         $(CATCHER)$(CC) $(COMPILER_FLAGS) -c $< $(OBJECT_NAME_FLAG)$@
413   else
414         @echo $< >>$(BUILD_LIST_FILE)
415         @echo $@ >>$(BUILD_WHACK_FILE)
416         @echo >$@
417   endif
418 endif
419
420 ############################################################################
421
422 # C source to object file translation.
423
424 $(OBJECT_DIR)/%.obj: $(CURRENT_DIR)/%.c
425 ifeq "$(NO_COMPILE)" ""
426   ifneq "$(COMPILER)" "VISUAL_CPP"
427         @echo Compiling [$@]
428         $(HIDESH)-c 'if [ ! -d $(@D) ]; then mkdir $(@D); fi'
429         $(CATCHER)$(CC) $(COMPILER_FLAGS) -c $< $(OBJECT_NAME_FLAG)$@
430   else
431         @echo $< >>$(BUILD_LIST_FILE)
432         @echo $@ >>$(BUILD_WHACK_FILE)
433         @echo >$@
434   endif
435 endif
436
437 ############################################################################
438
439 # resource compiler for win32.
440
441 ifeq "$(OP_SYSTEM)" "WIN32"
442 $(OBJECT_DIR)/%.res: %.rc $(PARAMETER_FILE)
443   ifeq "$(NO_COMPILE)" ""
444         @echo Resource [$@]
445         $(HIDESH)-c 'if [ ! -d $(@D) ]; then mkdir $(@D); fi'
446         $(CATCHER)$(RC) -r $(DEFINITIONS:%=-D%) $(HEADER_SEARCH_PATH:%=-i%) -fo $@ $<
447   endif
448
449 $(OBJECT_DIR)/%.resources: %.resx $(PARAMETER_FILE)
450   ifeq "$(NO_COMPILE)" ""
451         @echo Resource [$@]
452         $(HIDESH)-c 'if [ ! -d $(@D) ]; then mkdir $(@D); fi'
453         $(VCS_ROOT)/../SDK/v1.1/bin/resgen $< $@
454   endif
455 else #non-win32
456   # this platform probably does not use rc files.
457 $(OBJECT_DIR)/%.res: %.rc
458   ifeq "$(NO_COMPILE)" ""
459         @echo Bogus resource [$@]
460         @echo >$@
461   endif
462 endif #win32
463
464 ############################################################################
465
466 # creates static libraries.
467 ifneq "$(NO_COMPILE)" ""
468 $(STATIC_LIBRARY_DIR)/%.library:
469 endif
470
471 ifeq "$(NO_COMPILE)" ""
472 $(STATIC_LIBRARY_DIR)/%.library: $(ACTUAL_OBJECTS:%=$(OBJECT_DIR)/%) $(ACTUAL_LOCAL_LIBS:%=$(STATIC_LIBRARY_DIR)/$(LIB_PREFIX)%$(LIB_ENDING)) $(PARAMETER_FILE)
473         $(HIDER)echo Static [$@]
474         @echo $@ >$(DIRTY_FILE)
475   ifeq "$(COMPILER)" "VISUAL_CPP"
476         $(HIDESH)-c 'if [ -f $(BUILD_LIST_FILE) ]; then $(SHELL) $(CLAM_DIR)/cpp/rebuild_oldies.sh $(MULTI_BUILD_CMD); fi'
477   endif
478         $(CATCHER)$(LIBRARY_TOOL) $(LIBRARIAN_FLAGS) $(CREATE_LIBRARY_FLAG)$@ $(ACTUAL_OBJECTS:%=$(OBJECT_DIR)/%)
479   ifneq "$(OP_SYSTEM)" "UNIX"
480         $(HIDER)mv $@ $(STATIC_LIBRARY_DIR)/$(LIB_PREFIX)$*$(LIB_ENDING)
481         $(HIDER)echo nil >$@
482   else
483         $(HIDER)ranlib $@ 
484         $(HIDER)rm -f $(STATIC_LIBRARY_DIR)/$(LIB_PREFIX)$*$(LIB_ENDING)
485         $(HIDER)ln -s $@ $(STATIC_LIBRARY_DIR)/$(LIB_PREFIX)$*$(LIB_ENDING)
486   endif
487 endif #no_compile
488
489 ############################################################################
490
491 # creates dynamic libraries.
492
493 # we whack any existing LIB file, since we want to use changes in that file
494 # as a clue for when we should rescan the dependencies.  we'd be fine if
495 # visual c++ didn't keep an existing LIB if it doesn't change (even when the
496 # DLL does).
497
498 ifneq "$(NO_COMPILE)" ""
499 $(DYNAMIC_LIBRARY_DIR)/%.dll:
500 endif
501
502 ifeq "$(NO_COMPILE)" ""
503 $(DYNAMIC_LIBRARY_DIR)/%.dll: $(ACTUAL_OBJECTS:%=$(OBJECT_DIR)/%) $(ACTUAL_LOCAL_LIBS:%=$(STATIC_LIBRARY_DIR)/$(LIB_PREFIX)%$(LIB_ENDING)) $(ACTUAL_RESX) $(PARAMETER_FILE) 
504 #hmmm: use the res objects variable to rebuild res files as needed.
505 ###$(RES_OBJECTS) 
506         $(HIDER)echo Dynamic [$@]
507         @echo $@ >$(DIRTY_FILE)
508   ifeq "$(COMPILER)" "VISUAL_CPP"
509         $(HIDESH)-c 'if [ -f $(BUILD_LIST_FILE) ]; then $(SHELL) $(CLAM_DIR)/cpp/rebuild_oldies.sh $(MULTI_BUILD_CMD); fi'
510   endif
511         $(HIDER)rm -f $(@:%.dll=%.lib)
512         $(CATCHER)$(LINK_TOOL) $(LINKER_OUTPUT_FLAG)$@ -dll $(LOAD_FLAG_PREFIX) $(ACTUAL_OBJECTS:%=$(OBJECT_DIR)/%) $(ACTUAL_RESX_FLAGS) $(ACTUAL_LOCAL_LIBS:%=$(LIBRARY_NAME_FLAG)$(LIB_PREFIX)%$(LIB_ENDING)) $(LOAD_FLAG_SUFFIX)
513   ifeq "$(COMPILER_VERSION)" "8"
514         $(HIDESH)$(CLAM_DIR)/cpp/ms_manifest.sh "$@" "2"
515   endif
516   ifeq "$(COMPILER_VERSION)" "10"
517         $(HIDESH)$(CLAM_DIR)/cpp/ms_manifest.sh "$@" "2"
518   endif
519   ifneq "$(VCPP_VISTA_ICON)" ""
520         $(HIDER)ReplaceVistaIcon "$@" "$(VCPP_VISTA_ICON)"
521   endif
522 endif #no_compile
523
524 ifneq "$(NO_COMPILE)" ""
525 $(DYNAMIC_LIBRARY_DIR)/%.so:
526 endif
527
528 ifeq "$(NO_COMPILE)" ""
529 $(DYNAMIC_LIBRARY_DIR)/%.so: $(ACTUAL_OBJECTS:%=$(OBJECT_DIR)/%) $(ACTUAL_LOCAL_LIBS:%=$(STATIC_LIBRARY_DIR)/$(LIB_PREFIX)%$(LIB_ENDING)) $(PARAMETER_FILE)
530   ifeq "$(COMPILER:%_LINUX=LINUX)" "LINUX"
531         $(HIDER)echo Shared [$@]
532         @echo $@ >$(DIRTY_FILE)
533         $(CATCHER)$(LINK_TOOL) $(LINKER_OUTPUT_FLAG)$@ $(LOAD_FLAG_PREFIX) -shared -Wl,-soname,$*.so $(ACTUAL_OBJECTS:%=$(OBJECT_DIR)/%) $(ACTUAL_LOCAL_LIBS:%=$(LIBRARY_NAME_FLAG)%) $(LOAD_FLAG_SUFFIX) 
534         $(HIDER)rm -f $(STATIC_LIBRARY_DIR)/$(LIB_PREFIX)$*$(LIB_ENDING)
535         $(HIDER)ln -s $@ $(STATIC_LIBRARY_DIR)/$(LIB_PREFIX)$*$(LIB_ENDING)
536   endif
537 endif #no_compile
538
539 ############################################################################
540
541 # creates "exe" executables using all of the appropriate objects.
542
543 ifeq "$(OP_SYSTEM)" "WIN32"
544   ifneq "$(NO_COMPILE)" ""
545 $(EXECUTABLE_DIR)/%.exe:
546   endif
547
548   ifeq "$(NO_COMPILE)" ""
549 $(EXECUTABLE_DIR)/%.exe: $(OBJECT_DIR)/%.obj $(ACTUAL_OBJECTS:%=$(OBJECT_DIR)/%) $(ACTUAL_LOCAL_LIBS:%=$(STATIC_LIBRARY_DIR)/$(LIB_PREFIX)%$(LIB_ENDING)) $(ACTUAL_RESX) $(PARAMETER_FILE)
550         $(HIDER)echo Application [$@]
551         @echo $@ >$(DIRTY_FILE)
552     ifeq "$(COMPILER)" "VISUAL_CPP"
553         $(HIDESH)-c 'if [ -f $(BUILD_LIST_FILE) ]; then $(SHELL) $(CLAM_DIR)/cpp/rebuild_oldies.sh $(MULTI_BUILD_CMD); fi'
554     endif
555         $(CATCHER)$(LINK_TOOL) $(EXE_FLAGS) $(LOAD_FLAG_PREFIX) $< $(ACTUAL_OBJECTS:%=$(OBJECT_DIR)/%) $(ACTUAL_RESX_FLAGS) $(ACTUAL_LOCAL_LIBS:%=$(LIBRARY_NAME_FLAG)$(LIB_PREFIX)%$(LIB_ENDING)) $(LOAD_FLAG_SUFFIX) $(LINKER_OUTPUT_FLAG)$@
556 #$(^:force_rebuild=) 
557     ifeq "$(COMPILER_VERSION)" "8"
558         $(HIDESH)$(CLAM_DIR)/cpp/ms_manifest.sh "$@" "1"
559     endif
560     ifeq "$(COMPILER_VERSION)" "10"
561         $(HIDESH)$(CLAM_DIR)/cpp/ms_manifest.sh "$@" "1"
562     endif
563     ifneq "$(VCPP_VISTA_ICON)" ""
564         $(HIDER)ReplaceVistaIcon "$@" "$(VCPP_VISTA_ICON)"
565     endif
566   endif #no_compile
567 endif #win32
568
569 ifeq "$(OP_SYSTEM)" "UNIX"
570   ifneq "$(NO_COMPILE)" ""
571 $(EXECUTABLE_DIR)/%:
572   endif
573
574   ifeq "$(NO_COMPILE)" ""
575 $(EXECUTABLE_DIR)/%: $(OBJECT_DIR)/%.obj $(ACTUAL_OBJECTS:%=$(OBJECT_DIR)/%) $(ACTUAL_LOCAL_LIBS:%=$(STATIC_LIBRARY_DIR)/$(LIB_PREFIX)%$(LIB_ENDING)) $(PARAMETER_FILE)
576         $(HIDER)echo Application [$@]
577         @echo $@ >$(DIRTY_FILE)
578         $(CATCHER)$(LINK_TOOL) $(EXE_FLAGS) $(LOAD_FLAG_PREFIX) $< $(ACTUAL_OBJECTS:%=$(OBJECT_DIR)/%) $(ACTUAL_LOCAL_LIBS:%=$(LIBRARY_NAME_FLAG)%) $(LOAD_FLAG_SUFFIX) $(LINKER_OUTPUT_FLAG)$@
579 #hmmm: experimental item below.
580 #$(^:force_rebuild=) 
581   endif #no_compile
582 endif #unix
583
584 ############################################################################
585
586 # creates firmware "elf" executables with the proper objects.
587
588 ifneq "$(NO_COMPILE)" ""
589 $(EXECUTABLE_DIR)/%.elf:
590 endif
591
592 ifeq "$(NO_COMPILE)" ""
593 $(EXECUTABLE_DIR)/%.elf: $(OBJECT_DIR)/%.obj $(ACTUAL_OBJECTS:%=$(OBJECT_DIR)/%) $(ACTUAL_LOCAL_LIBS:%=$(STATIC_LIBRARY_DIR)/$(LIB_PREFIX)%$(LIB_ENDING)) $(PARAMETER_FILE)
594         $(HIDER)echo Application [$@]
595         @echo $@ >$(DIRTY_FILE)
596         $(CATCHER)$(LINK_TOOL) $(MAP) $(LOAD_FLAG_PREFIX) $< $(LINKER_COMMAND_FILE) $(STARTUP_OBJECT_FILE) $(ACTUAL_OBJECTS:%=$(OBJECT_DIR)/%) $(ACTUAL_LOCAL_LIBS:%=$(LIBRARY_NAME_FLAG)%) $(LOAD_FLAG_SUFFIX) $(LINKER_OUTPUT_FLAG)$@
597 #$(^:force_rebuild=) 
598         @echo Hex [$(EXECUTABLE_DIR)/$*.out]
599         $(CATCHER)$(DDUMP_TOOL) $(DDUMP_OPTIONS) $@ -o$(EXECUTABLE_DIR)/$*.out
600         @echo Binary [$(EXECUTABLE_DIR)/$*.bin]
601         $(CATCHER)$(DDUMP_TOOL) $(DDUMP_BIN_OPTIONS) $@ -o$(EXECUTABLE_DIR)/$*.bin
602 endif #no_compile
603
604 ############################################################################
605
606 # handles creating version resource files if this project has a version.ini.
607
608 ifeq "$(OMIT_VERSIONS)" ""
609   ifneq "$(VERSION_RC_ROOT)" ""
610 # only redo the version resource if it or version.ini is out of date.
611 %_version.rc: version.ini $(PARAMETER_FILE)
612         $(CATCHER)$(CLAM_BIN)/version_stamper$(EXE_END) . $(PARAMETER_FILE)
613   endif
614 endif
615
616 ############################################################################
617
618 # Now the active part of the make process...
619
620 # Adds the main CLAM system in to get some work done.  This should be placed
621 # after the module's rules are defined and before the module's targets are
622 # defined.
623 include rules.def
624
625 # make sure we really want to include the dependencies file.
626 ifeq "$(TYPE)" "hierarchy"
627   # no dependencies for a simple hierarchy builder.
628   NO_DEPS = t
629 endif
630 ifneq "$(CLEAN)" ""
631   NO_DEPS = t
632   # no dependencies get left when we are cleaning up.
633   $(shell rm -f $(DEPS_FILE))
634 endif
635 ifneq "$(NO_COMPILE)" ""
636   # non compiling projects do not need dependencies.
637   NO_DEPS = t
638 endif
639 ifneq "$(REBUILD)" ""
640   NO_DEPS = t
641   # if we are rebuilding everything, we zap the deps file.
642   $(shell rm -f $(DEPS_FILE))
643 endif
644
645 # includes the auto-dependency information.  the dependency file is checked
646 # for being up-to-date.  if not, it gets rebuilt and the make is restarted.
647 ifeq "$(NO_DEPS)" ""
648   include $(DEPS_FILE)
649 endif
650
651 # preserves intermediate files from being deleted.
652 ifeq "$(CLEAN)" ""
653 .PRECIOUS: $(OBJECT_DIR)/%.obj $(OBJECT_DIR)/%.res $(OBJECT_DIR)/%.resources
654 endif
655
656 # zaps things when they could not be created correctly.
657 ####.DELETE_ON_ERROR:
658
659 ############################################################################
660
661 # autodependency file creator.  See the make_dep man page for more info.
662
663 # we do the auto-dependencies unless the disabling flag is set.
664 ifneq "$(NO_DEPS)" ""
665     # makes the dependencies a no-op.
666     deps: $(PARAMETER_FILE)
667
668     $(DEPS_FILE): $(PARAMETER_FILE)
669
670 else
671   deps: $(DEPS_FILE)
672
673   # this causes the dependency file to be regenerated if the sources or libs
674   # have changed.  we have to touch the deps file in case it's missing;
675   # makedep doesn't deal well with that.  also, we touch the dirty flag file
676   # to ensure that the fact we redid dependencies for some reason causes us
677   # to re-promote.  we only bother with any of this if we know we're going
678   # to really do some compilation; if in non-compile mode, we'll skip it.
679   ifneq "$(NO_COMPILE)" ""
680     # no dependencies in non-compile mode.
681     $(DEPS_FILE):
682
683   else
684     ifeq "$(LAX_DEPENDENCIES)" ""
685       $(DEPS_FILE): $(SOURCE) $(ACTUAL_LOCAL_LIBS:%=$(STATIC_LIBRARY_DIR)/$(LIB_PREFIX)%$(LIB_ENDING)) $(wildcard *.h) $(EXE_CPPS)
686     else  # lax dependencies means create if missing or if parm file changed.
687       $(DEPS_FILE): $(PARAMETER_FILE)
688     endif # !lax dependencies.
689     ifneq "$(VERSION_RC_ROOT)" ""
690       ifeq "$(OMIT_VERSIONS)" ""
691         $(DEPS_FILE): $(VERSION_RC_ROOT)_version.rc
692       endif
693     endif
694         @echo Dependencies [$(shell basename $@)]
695         -$(HIDESH)$(CLAM_DIR)/cpp/preconditions.sh
696         @touch $@
697 #       @echo dep adds: $(DEPENDENCY_ADDITIONS)
698         @$(CLAM_BIN)/makedep$(EXE_END) $(DEPENDENCY_DEFINITIONS:%=-D%) $(DEPENDENCY_ADDITIONS) -f$@ -o.obj -p$(OBJECT_DIR)/ -w 420 $(COMPILER_HEADER_DIR:%=-X%) $(THIRD_PARTY_DIR:%=-X%) -- $(COMPILER_FLAGS) $(SOURCE) $(EXE_CPPS)
699 #       $(CATCHER)$(CLAM_BIN)/makedep$(EXE_END) $(DEPENDENCY_DEFINITIONS:%=-D%) $(DEPENDENCY_ADDITIONS) -f$@ -o.obj -p$(OBJECT_DIR)/ -w 420 $(COMPILER_HEADER_DIR:%=-X%) $(THIRD_PARTY_DIR:%=-X%) -- $(COMPILER_FLAGS) $(SOURCE) $(EXE_CPPS)
700         @echo $@ >$(SUBMAKE_FLAG)
701   endif # non-compile.
702 endif # no-deps.
703
704 ############################################################################
705
706 # examines the required variables and complains if they're missing.
707 check_requirements:
708         $(HIDESH) -c 'if [ -z "$(PROJECT)" ]; then echo the PROJECT variable is not defined!; . $(CLAM_DIR)/exit_make.sh; fi'
709         $(HIDESH) -c 'if [ -z "$(TYPE)" ]; then echo the TYPE variable is not defined!; . $(CLAM_DIR)/exit_make.sh; fi'
710  
711 ############################################################################
712
713 # calls the script for preparing output directories and such.
714 pre_compilation:
715         $(HIDESH)$(CLAM_DIR)/cpp/preconditions.sh
716
717 ############################################################################
718
719 # calls the script for copying the final products to the library directory.
720 # we don't bother reporting errors from touch since there will sometimes
721 # not be any objects in the final directory.
722 post_compilation:
723         $(HIDESH)$(CLAM_DIR)/cpp/postconditions.sh
724
725 ############################################################################
726
727 # if REBUILD is defined, then we cause all objects to be recompiled.
728 .PHONY: force_rebuild
729 force_rebuild:
730
731 ifneq "$(REBUILD)" ""
732   # the target below needs the blank rule that it has for this to work.
733   $(FIRST_TARGETS) $(ACTUAL_OBJECTS:%=$(OBJECT_DIR)/%) $(ACTUAL_TARGETS) $(EXE_CPPS:%.cpp=$(OBJECT_DIR)/%.obj) $(LAST_TARGETS): force_rebuild
734 endif
735
736 ############################################################################
737
738 # generate dependencies for any static targets if requested.
739 gendeps: $(GENERATED_DEPS_LIST)
740
741 ############################################################################
742