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