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