resurrecting the gnu c++ build on windows
[feisty_meow.git] / scripts / z_outgoing / dotnet-retired / 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 # Modify the output directory for executable files if we're building a
19 # test project.
20 ifeq "$(TYPE)" "test"
21   EXECUTABLE_DIR = $(TARGETS_STORE)/tests/$(PROJECT)
22   ifneq "$(CONSOLE_MODE)" ""
23     COMPILER_FLAGS += -target:exe
24   else
25     COMPILER_FLAGS += -target:winexe
26   endif
27 endif
28 ifeq "$(TYPE)" "application"
29   ifneq "$(CONSOLE_MODE)" ""
30     COMPILER_FLAGS += -target:exe
31   else
32     COMPILER_FLAGS += -target:winexe
33   endif
34 endif
35 ifeq "$(TYPE)" "library"
36   COMPILER_FLAGS += -target:library
37 endif
38
39 # prep the actual source variable so that certain file names are translated.
40 ACTUAL_RESX = $(RESX:%.resx=%.resources)
41
42 ifeq "$(OP_SYSTEM)" "WIN32"
43   ifneq "$(OMIT_VERSIONS)" ""
44     # remove version rc files if we're not dealing with versions.
45     ACTUAL_RESOURCE = $(RESOURCE:%.rc=)
46   else
47     ACTUAL_RESOURCE = $(RESOURCE:%.rc=%.res)
48   endif
49 else
50   # replace this when supporting resource files on unix.
51   ACTUAL_RESOURCE = $(RESOURCE:%.rc=)
52 endif
53
54 # patch the sources so that subdirs work.
55 ACTUAL_SOURCE = $(SOURCE:%.cs=$(CURRENT_DIR)/%.cs)
56
57 # visual studio settings.
58 ifeq "$(COMPILER)" "VISUAL_CPP"
59   # processes the def file for linkage, if one has been specified.
60   ifneq "$(DEF_FILE)" ""
61     LOAD_FLAG_PREFIX += -def:$(DEF_FILE)
62   endif
63
64   # these are loaded after any special debugging libs.
65   ifneq "$(VCPP_USE_BASE)" ""
66     # the first set will be included in almost any old program.  we include
67     # winmm for multimedia in the base support since we make heavy use of the
68     # more accurate uptime function.
69 #    LOAD_FLAG_PREFIX += advapi32.lib kernel32.lib version.lib winmm.lib 
70   endif
71 #is advapi32 really part of the base required stuff?  will it work on
72 #win98?  how about win95?
73
74   ifneq "$(VCPP_USE_GUI)" ""
75     LOAD_FLAG_PREFIX += comdlg32.lib gdi32.lib user32.lib winspool.lib
76   endif
77
78   ifneq "$(VCPP_USE_OLE)" ""
79     LOAD_FLAG_PREFIX += ole32.lib oleaut32.lib uuid.lib
80     VCPP_USE_RPC = t
81   endif
82   ifneq "$(VCPP_USE_RPC)" ""
83     LOAD_FLAG_PREFIX += rpcndr.lib rpcns4.lib rpcrt4.lib
84     VCPP_USE_SOCK = t
85   endif
86   ifneq "$(VCPP_USE_SOCK)" ""
87     LOAD_FLAG_PREFIX += netapi32.lib ws2_32.lib
88   endif
89 endif
90
91 # Updates the search path for the compiler and local libraries.
92 BASE_HEADER_PATH = $(CODEBASE_HEADERS) $(LOCAL_HEADERS) $(HOOPLE_HEADERS) $(SEARCH_DIRS)
93 HEADER_SEARCH_PATH += $(BASE_HEADER_PATH) $(COMPILER_HEADER_DIR)
94
95 LIBRARY_SEARCH_PATH += $(LOCAL_LIBRARIES) $(HOOPLE_LIBRARIES) \
96   $(STATIC_LIBRARY_DIR) $(COMPILER_LIBRARY_DIR) $(SEARCH_DIRS)
97
98 # Adds some directories that must be searched onto the search path for
99 # header files, such as the compiler's own special header file directory.
100 COMPILER_FLAGS += $(DEFINITIONS:%=-D:%) $(UNDEFINITIONS:%=-U%) 
101 #$(HEADER_SEARCH_PATH:%=-I%)
102
103 # The load flags are updated by looking for code libraries in the directories
104 # to search and by adding all of the code libraries that are used.
105 LOAD_FLAG_PREFIX += $(LIBRARY_SEARCH_PATH:%=$(LIBRARY_PATH_FLAG)%)
106 LOAD_FLAG_PREFIX += $(LIBS_USED:%=$(LIBRARY_NAME_FLAG)%)
107
108 # prepare for mfc style DLLs.  currently we plan on all dlls we create being
109 # based on MFC.  this is an unfortunate requirement for using the mfc debug
110 # support for allocations; if regular new and DEBUG_NEW get mixed together,
111 # crashes used to result.  supposedly these are gone now at least.
112 ifneq "$(USE_MFC)" ""
113   # set the flag that says we are doing mfc extension dlls.
114   DEFINITIONS += _AFXDLL
115
116   # add in the mfc directories.
117   COMPILER_HEADER_DIR += $(COMPILER_ROOT_DIR)/mfc/include
118   COMPILER_LIBRARY_DIR += $(COMPILER_ROOT_DIR)/mfc/lib
119 endif
120
121 ifeq "$(OMIT_VERSIONS)" ""
122   ifneq "$(VERSION_RC_ROOT)" ""
123     VERSION_TARGET = $(VERSION_RC_ROOT)_version.rc
124   endif
125 endif
126
127 # Make sure that the directory for objects exists.
128 ACTUAL_FIRST_TARGETS = check_requirements $(VERSION_TARGET) $(FIRST_TARGETS) pre_compilation
129
130 # Adds the primary targets to the list of products to create.
131 ACTUAL_TARGETS1 = $(TARGETS:%.exe=$(EXECUTABLE_DIR)/%.exe) 
132 ACTUAL_TARGETS2 = $(ACTUAL_TARGETS1:%.dll=$(DYNAMIC_LIBRARY_DIR)/%.dynlibrary)
133 ACTUAL_TARGETS3 = $(ACTUAL_TARGETS2:%.so=$(DYNAMIC_LIBRARY_DIR)/%.so)
134 ACTUAL_TARGETS4 = $(ACTUAL_TARGETS3:%.lib=$(STATIC_LIBRARY_DIR)/%.library)
135 ACTUAL_TARGETS = $(ACTUAL_TARGETS4:%.elf=$(EXECUTABLE_DIR)/%.elf)
136
137 # Adds the last few targets for CLAM to do.
138 ACTUAL_LAST_TARGETS = post_compilation $(LAST_TARGETS)
139
140 ############################################################################
141
142 # This section defines the rules used to generate various objects from their
143 # source files.
144
145 ############################################################################
146
147 # resource compiler for c#.
148
149 %.resources: %.resx
150         @echo Creating resource file [$@].
151         $(RC) $< $@ 
152 #       $(CATCHER)$(RC) $< $@ 
153
154 ############################################################################
155
156 # resource compiler for standard resource files.
157
158 ifeq "$(OP_SYSTEM)" "WIN32"
159 %.res: %.rc
160         @echo Creating resource file [$@].
161 ifeq "$(NO_COMPILE)" ""
162         $(CATCHER)$(STANDARD_RC) -r $(DEFINITIONS:%=-D%) $(HEADER_SEARCH_PATH:%=-i%) -fo $@ $<
163 endif
164 endif
165
166 ############################################################################
167
168 # creates dynamic libraries.
169
170 # we whack any existing LIB file, since we want to use changes in that file
171 # as a clue for when we should rescan the dependencies.  we'd be fine if
172 # visual c++ didn't keep an existing LIB if it doesn't change (even when the
173 # DLL does).
174
175 $(DYNAMIC_LIBRARY_DIR)/%.dynlibrary: $(LOCAL_LIBS_USED:%=$(DYNAMIC_LIBRARY_DIR)/$(LIB_PREFIX)%$(LIB_ENDING)) $(ACTUAL_RESX) $(ACTUAL_SOURCE) $(ACTUAL_RESOURCE)
176         $(HIDER)echo Creating dynamic library [$@].
177         @echo $@ >$(DIRTY_FILE)
178         $(HIDER)rm -f $(@:%.dll=%.lib)
179         $(CATCHER)$(CC) $(COMPILER_FLAGS) $(EXE_FLAGS) $(LOAD_FLAG_PREFIX) $(LOCAL_LIBS_USED:%=$(LIBRARY_NAME_FLAG)$(DYNAMIC_LIBRARY_DIR)/$(LIB_PREFIX)%$(LIB_ENDING)) $(LOAD_FLAG_SUFFIX) $(LINKER_OUTPUT_FLAG)$@ $(ACTUAL_SOURCE) $(ACTUAL_RESX:%=-res:%) $(ACTUAL_RESOURCE:%=-win32res:%)
180 ifneq "$(VCPP_VISTA_ICON)" ""
181         $(HIDER)ReplaceVistaIcon "$@" "$(VCPP_VISTA_ICON)"
182 endif
183         $(HIDER)mv $@ $(DYNAMIC_LIBRARY_DIR)/$(LIB_PREFIX)$*$(LIB_ENDING)
184 ifneq "$(CREATE_TLB)" ""
185         $(CATCHER)$(TLBEXPORT) $(DYNAMIC_LIBRARY_DIR)/$(LIB_PREFIX)$*$(LIB_ENDING) -out:$(DYNAMIC_LIBRARY_DIR)/$(LIB_PREFIX)$*.tlb
186 endif
187         $(HIDER)echo nil >$@
188         
189 #$(LINKER_OUTPUT_FLAG)$@ -dll $(LOAD_FLAG_PREFIX) $(ACTUAL_OBJECTS:%=$(OBJECT_DIR)/%) $(LOCAL_LIBS_USED:%=$(LIBRARY_NAME_FLAG)$(LIB_PREFIX)%$(LIB_ENDING)) $(LOAD_FLAG_SUFFIX) 
190
191 ############################################################################
192
193 # creates "exe" executables using all of the appropriate objects.
194 $(EXECUTABLE_DIR)/%.exe: $(LOCAL_LIBS_USED:%=$(DYNAMIC_LIBRARY_DIR)/$(LIB_PREFIX)%$(LIB_ENDING)) $(ACTUAL_RESX) $(ACTUAL_SOURCE) $(ACTUAL_RESOURCE)
195         $(HIDER)echo Building program [$@].
196         @echo $@ >$(DIRTY_FILE)
197         $(CATCHER)$(CC) $(COMPILER_FLAGS) $(EXE_FLAGS) $(LOAD_FLAG_PREFIX) $(LOCAL_LIBS_USED:%=$(LIBRARY_NAME_FLAG)$(DYNAMIC_LIBRARY_DIR)/$(LIB_PREFIX)%$(LIB_ENDING)) $(LOAD_FLAG_SUFFIX) $(LINKER_OUTPUT_FLAG)$@ $(ACTUAL_SOURCE) $(ACTUAL_RESX:%=-res:%) $(ACTUAL_RESOURCE:%=-win32res:%)
198 ifneq "$(VCPP_VISTA_ICON)" ""
199         $(HIDER)ReplaceVistaIcon "$@" "$(VCPP_VISTA_ICON)"
200 endif
201
202 ############################################################################
203
204 # handles creating version resource files if this project has a version.ini.
205
206 ifeq "$(OMIT_VERSIONS)" ""
207   ifneq "$(VERSION_RC_ROOT)" ""
208 # only redo the version resource if it or version.ini is out of date.
209 %_version.rc: version.ini $(PARAMETER_FILE)
210         $(CATCHER)$(CLAM_BINARIES)/version_stamper$(EXE_END) . $(PARAMETER_FILE)
211   endif
212 endif
213
214 ############################################################################
215
216 # Now the active part of the make process...
217
218 # Adds the main CLAM system in to get some work done.  This should be placed
219 # after the module's rules are defined and before the module's targets are
220 # defined.
221 include rules.def
222
223 # preserves intermediate files from being deleted.
224 ##.PRECIOUS: %.resources
225
226 # zaps things when they could not be created correctly.
227 .DELETE_ON_ERROR:
228
229 ############################################################################
230
231 # examines the required variables and complains if they're missing.
232 check_requirements:
233         $(HIDESH) -c 'if [ -z "$(PROJECT)" ]; then echo the PROJECT variable is not defined!; . $(CLAM_SCRIPTS)/exit_make.sh; fi'
234         $(HIDESH) -c 'if [ -z "$(TYPE)" ]; then echo the TYPE variable is not defined!; . $(CLAM_SCRIPTS)/exit_make.sh; fi'
235  
236 ############################################################################
237
238 # calls the script for preparing output directories and such.
239 pre_compilation:
240         $(HIDESH)$(CLAM_SCRIPTS)/csharp/preconditions.sh
241
242 ############################################################################
243
244 # calls the script for copying the final products to the library directory.
245 # we don't bother reporting errors from touch since there will sometimes
246 # not be any objects in the final directory.
247 post_compilation:
248         $(HIDESH)$(CLAM_SCRIPTS)/csharp/postconditions.sh
249
250 ############################################################################
251
252 # if REBUILD is defined, then we cause all objects to be recompiled.
253 .PHONY: force_rebuild
254 force_rebuild:
255
256 ifneq "$(REBUILD)" ""
257   # the target below needs the blank rule that it has for this to work.
258   $(FIRST_TARGETS) $(ACTUAL_OBJECTS:%=$(OBJECT_DIR)/%) $(ACTUAL_TARGETS) $(LAST_TARGETS): force_rebuild
259 endif
260
261 ############################################################################
262