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