Removed configuration options that are better served in Makefile.config.
[oota-llvm.git] / Makefile.rules
1 #===-- Makefile.common - Common make rules for LLVM -------*- makefile -*--====
2 #
3 # This file is included by all of the LLVM makefiles.  This file defines common
4 # rules to do things like compile a .cpp file or generate dependancy info.
5 # These are platform dependant, so this is the file used to specify these
6 # system dependant operations.
7 #
8 # The following functionality can be set by setting incoming variables.
9 # The variable $(LEVEL) *must* be set:
10 #
11 # 1. LEVEL - The level of the current subdirectory from the top of the 
12 #    MagicStats view.  This level should be expressed as a path, for 
13 #    example, ../.. for two levels deep.
14 #
15 # 2. DIRS - A list of subdirectories to be built.  Fake targets are set up
16 #    so that each of the targets "all", "install", and "clean" each build
17 #    the subdirectories before the local target.  DIRS are guaranteed to be
18 #    built in order.
19 #
20 # 3. PARALLEL_DIRS - A list of subdirectories to be built, but that may be
21 #    built in any order.  All DIRS are built in order before PARALLEL_DIRS are
22 #    built, which are then built in any order.
23 #
24 # 4. Source - If specified, this sets the source code filenames.  If this
25 #    is not set, it defaults to be all of the .cpp, .c, .y, and .l files 
26 #    in the current directory.  Also, if you want to build files in addition
27 #    to the local files, you can use the ExtraSource variable
28 #
29 # 5. SourceDir - If specified, this specifies a directory that the source files
30 #    are in, if they are not in the current directory.  This should include a
31 #    trailing / character.
32 #
33 #===-----------------------------------------------------------------------====
34
35 # Configuration file to set paths specific to local installation of LLVM
36
37 include $(LEVEL)/Makefile.config
38
39 # Figure out how to do platform specific stuff on this platform.  This is really
40 # gross and should be autoconfiscated (automake actually), but should hopefully
41 # work on Linux and solaris (SunOS).
42 #
43 UNAME := $(shell uname)
44 include $(LEVEL)/Makefile.$(UNAME)
45
46 ifdef SHARED_LIBRARY
47 # if SHARED_LIBRARY is specified, the default is to build the dynamic lib
48 dynamic ::
49 endif
50
51 # Default Rule:  Make sure it's also a :: rule
52 all ::
53
54 # Default for install is to at least build everything...
55 install ::
56
57
58 # Figure out which directory to build stuff into.  We want to build into the
59 # /shared directory by default because it is guaranteed to be local to the
60 # current machine.
61 #
62 ifeq ($(LLVM_OBJ_DIR),.)
63 BUILD_ROOT     = $(LLVM_OBJ_DIR)
64 BUILD_ROOT_TOP = $(LEVEL)
65 else
66
67 BUILD_ROOT := $(LLVM_OBJ_DIR)$(patsubst $(HOME)%,%,$(shell pwd))
68
69 # Calculate the BUILD_ROOT_TOP variable, which is the top of the llvm/ tree.
70 # Note that although this is just equal to $(BUILD_ROOT)/$(LEVEL), we cannot use
71 # this expression because some of the directories on the source tree may not
72 # exist in the build tree (for example the test/ heirarchy).  Thus we evaluate
73 # the directory to eliminate the ../'s
74 #
75 ifdef PROJ_COMPILE
76 TOP_DIRECTORY := $(shell cd $(TOPLEVEL); pwd)
77 else 
78 TOP_DIRECTORY := $(shell cd $(LEVEL); pwd)
79 endif
80
81 BUILD_ROOT_TOP := $(LLVM_OBJ_DIR)$(patsubst $(HOME)%,%,$(TOP_DIRECTORY))
82 endif
83
84
85
86
87 #--------------------------------------------------------------------
88 # Variables derived from configuration options... 
89 #--------------------------------------------------------------------
90
91 #BinInstDir=/usr/local/bin
92 #LibInstDir=/usr/local/lib/xxx
93 #DocInstDir=/usr/doc/xxx
94
95 BURG_OPTS = -I
96
97 PURIFY := $(PURIFY) -cache-dir="$(BUILD_ROOT_TOP)/../purifycache" -chain-length="30" -messages=all 
98
99 ifdef ENABLE_PROFILING
100   ENABLE_OPTIMIZED = 1
101   CONFIGURATION := Profile
102 else
103   ifdef ENABLE_OPTIMIZED
104     CONFIGURATION := Release
105   else
106     CONFIGURATION := Debug
107   endif
108 endif
109
110 # Shorthand for commonly accessed directories
111 DESTLIBDEBUG    := $(BUILD_ROOT_TOP)/lib/Debug
112 DESTLIBRELEASE  := $(BUILD_ROOT_TOP)/lib/Release
113 DESTLIBPROFILE  := $(BUILD_ROOT_TOP)/lib/Profile
114 DESTLIBCURRENT  := $(BUILD_ROOT_TOP)/lib/$(CONFIGURATION)
115
116 ifdef PROJ_COMPILE
117 LLVMLIBDEBUGSOURCE    := $(LLVM_LIB_DIR)/lib/Debug
118 LLVMLIBRELEASESOURCE  := $(LLVM_LIB_DIR)/lib/Release
119 LLVMLIBPROFILESOURCE  := $(LLVM_LIB_DIR)/lib/Profile
120 LLVMLIBCURRENTSOURCE  := $(LLVM_LIB_DIR)/lib/$(CONFIGURATION)
121
122 PROJLIBDEBUGSOURCE    := $(BUILD_ROOT_TOP)/lib/Debug
123 PROJLIBRELEASESOURCE  := $(BUILD_ROOT_TOP)/lib/Release
124 PROJLIBPROFILESOURCE  := $(BUILD_ROOT_TOP)/lib/Profile
125 PROJLIBCURRENTSOURCE  := $(BUILD_ROOT_TOP)/lib/$(CONFIGURATION)
126
127 else 
128
129 LLVMLIBDEBUGSOURCE    := $(BUILD_ROOT_TOP)/lib/Debug
130 LLVMLIBRELEASESOURCE  := $(BUILD_ROOT_TOP)/lib/Release
131 LLVMLIBPROFILESOURCE  := $(BUILD_ROOT_TOP)/lib/Profile
132 LLVMLIBCURRENTSOURCE  := $(BUILD_ROOT_TOP)/lib/$(CONFIGURATION)
133 endif
134
135
136 TOOLDEBUG   := $(BUILD_ROOT_TOP)/tools/Debug
137 TOOLRELEASE := $(BUILD_ROOT_TOP)/tools/Release
138 TOOLPROFILE := $(BUILD_ROOT_TOP)/tools/Profile
139 TOOLCURRENT := $(BUILD_ROOT_TOP)/tools/$(CONFIGURATION)
140
141 # Verbosity levels
142 ifndef VERBOSE
143 VERB := @
144 endif
145
146 #---------------------------------------------------------
147 # Compilation options...
148 #---------------------------------------------------------
149
150 # Special tools used while building the LLVM tree.  Burg is built as part of the
151 # utils directory.
152 #
153 BURG    := $(TOOLCURRENT)/burg
154 RunBurg := $(BURG) $(BURG_OPTS)
155
156
157 # Enable this for profiling support with 'gprof'
158 # This automatically enables optimized builds.
159 ifdef ENABLE_PROFILING
160   PROFILE = -pg
161 endif
162
163 #if PROJDIR is defined then we include PROJ DIR includes and libraries
164 ifndef PROJ_COMPILE
165 PROJ_INCLUDE = "."
166 else
167 PROJ_INCLUDE = $(PROJ_DIR)/include
168 endif 
169
170 # By default, strip symbol information from executable
171 ifndef KEEP_SYMBOLS
172 STRIP = $(PLATFORMSTRIPOPTS)
173 STRIP_WARN_MSG = "(without symbols) "
174 endif
175
176 # Allow gnu extensions...
177 CPPFLAGS += -D_GNU_SOURCE
178
179 # -Wno-unused-parameter
180 CompileCommonOpts := -Wall -W  -Wwrite-strings -Wno-unused -I$(LEVEL)/include -I$(PROJ_INCLUDE)
181 CompileOptimizeOpts := -O3 -DNDEBUG -finline-functions -fshort-enums
182
183 # Compile a cpp file, don't link...
184 Compile  := $(CXX) -c $(CPPFLAGS) $(CXXFLAGS) $(CompileCommonOpts)
185 CompileG := $(Compile) -g  -D_DEBUG
186 CompileO := $(Compile) $(CompileOptimizeOpts) -felide-constructors -fomit-frame-pointer
187 CompileP := $(Compile) $(CompileOptimizeOpts) -felide-constructors $(PROFILE)
188
189 # Compile a c file, don't link...
190 CompileC  := $(CC) -c $(CPPFLAGS) $(CCFLAGS) $(CompileCommonOpts)
191 CompileCG := $(CompileC) -g  -D_DEBUG
192 CompileCO := $(CompileC) $(CompileOptimizeOpts) -fomit-frame-pointer
193 CompileCP := $(CompileC) $(CompileOptimizeOpts) $(PROFILE)
194
195
196 # Link final executable
197
198 ifdef ENABLE_PURIFY # To enable purify, build with 'gmake ENABLE_PURIFY=1'
199 Link     := $(PURIFY) $(CXX) -static
200 else
201 Link     := $(CXX)
202 endif
203
204 ifdef PROJ_COMPILE
205 LinkG    := $(Link) -g -L$(PROJLIBDEBUGSOURCE)  -L$(LLVMLIBDEBUGSOURCE) $(STRIP)
206 LinkO    := $(Link) -O3 -L$(PROJLIBRELEASESOURCE) -L$(LLVMLIBRELEASESOURCE)
207 LinkP    := $(Link) -O3 -L$(PROJLIBPROFILESOURCE) -L$(LLVMLIBPROFILESOURCE) $(PROFILE)
208 else
209 LinkG    := $(Link) -g  -L$(LLVMLIBDEBUGSOURCE) $(STRIP)
210 LinkO    := $(Link) -O3 -L$(LLVMLIBRELEASESOURCE)
211 LinkP    := $(Link) -O3 -L$(LLVMLIBPROFILESOURCE) $(PROFILE)
212 endif
213
214
215
216 # Create one .o file from a bunch of .o files...
217 Relink = ld -r
218
219 # MakeSO - Create a .so file from a .o files...
220 MakeSO   := $(CXX) $(MakeSharedObjectOption)
221 MakeSOO  := $(MakeSO) -O3
222 MakeSOP  := $(MakeSOO) $(PROFILE)
223
224 # Create dependancy file from CPP file, send to stdout.
225 Depend   := $(CXX) -MM -I$(LEVEL)/include -I$(PROJ_INCLUDE) $(CPPFLAGS) 
226 DependC  := $(CC)  -MM -I$(LEVEL)/include -I$(PROJ_INCLUDE) $(CPPFLAGS) 
227
228 # Archive a bunch of .o files into a .a file...
229 AR       = ar cq 
230
231 #----------------------------------------------------------
232
233 # Source includes all of the cpp files, and objects are derived from the
234 # source files...
235 # The local Makefile can list other Source files via ExtraSource = ...
236
237 ifndef Source
238 Source  := $(ExtraSource) $(wildcard *.cpp *.c *.y *.l)
239 endif
240
241 Objs := $(sort $(patsubst Debug/%.o, %.o, $(addsuffix .o,$(notdir $(basename $(Source))))))
242 ObjectsO := $(addprefix $(BUILD_ROOT)/Release/,$(Objs))
243 ObjectsP := $(addprefix $(BUILD_ROOT)/Profile/,$(Objs))
244 ObjectsG := $(addprefix $(BUILD_ROOT)/Debug/,$(Objs))
245
246
247 #---------------------------------------------------------
248 # Handle the DIRS and PARALLEL_DIRS options
249 #---------------------------------------------------------
250
251 ifdef DIRS
252 all install clean test ::
253         $(VERB) for dir in ${DIRS}; do \
254                 (cd $$dir; $(MAKE) $@) || exit 1; \
255         done
256 endif
257
258 # Handle PARALLEL_DIRS
259 ifdef PARALLEL_DIRS
260 all     :: $(addsuffix /.makeall    , $(PARALLEL_DIRS))
261 install :: $(addsuffix /.makeinstall, $(PARALLEL_DIRS))
262 clean   :: $(addsuffix /.makeclean  , $(PARALLEL_DIRS))
263 test    :: $(addsuffix /.maketest   , $(PARALLEL_DIRS))
264
265 %/.makeall %/.makeinstall %/.makeclean %/.maketest:
266         $(VERB) cd $(@D); $(MAKE) $(subst $(@D)/.make,,$@)
267 endif
268
269 #---------------------------------------------------------
270 # Handle the LIBRARYNAME option - used when building libs...
271 #---------------------------------------------------------
272 #
273 #  When libraries are built, they are allowed to optionally define the
274 #  DONT_BUILD_RELINKED make variable, which, when defined, prevents a .o file
275 #  from being built for the library. This .o files may then be linked to by a
276 #  tool if the tool does not need (or want) the semantics a .a file provides
277 #  (linking in only object files that are "needed").  If a library is never to
278 #  be used in this way, it is better to define DONT_BUILD_RELINKED, and define
279 #  BUILD_ARCHIVE instead.
280 #
281 #  Some libraries must be built as .a files (libscalar for example) because if
282 #  it's built as a .o file, then all of the constituent .o files in it will be
283 #  linked into tools (for example gccas) even if they only use one of the parts
284 #  of it.  For this reason, sometimes it's useful to use libraries as .a files.
285
286 ifdef LIBRARYNAME
287
288 # Make sure there isn't any extranous whitespace on the LIBRARYNAME option
289 LIBRARYNAME := $(strip $(LIBRARYNAME))
290
291 LIBNAME_O    := $(DESTLIBRELEASE)/lib$(LIBRARYNAME).so
292 LIBNAME_P    := $(DESTLIBPROFILE)/lib$(LIBRARYNAME).so
293 LIBNAME_G    := $(DESTLIBDEBUG)/lib$(LIBRARYNAME).so
294 LIBNAME_AO   := $(DESTLIBRELEASE)/lib$(LIBRARYNAME).a
295 LIBNAME_AP   := $(DESTLIBPROFILE)/lib$(LIBRARYNAME).a
296 LIBNAME_AG   := $(DESTLIBDEBUG)/lib$(LIBRARYNAME).a
297 LIBNAME_OBJO := $(DESTLIBRELEASE)/$(LIBRARYNAME).o
298 LIBNAME_OBJP := $(DESTLIBPROFILE)/$(LIBRARYNAME).o
299 LIBNAME_OBJG := $(DESTLIBDEBUG)/$(LIBRARYNAME).o
300
301 # dynamic target builds a shared object version of the library...
302 dynamic:: $(DESTLIBCURRENT)/lib$(LIBRARYNAME).so
303
304 # Does the library want a .o version built?
305 ifndef DONT_BUILD_RELINKED
306 all:: $(DESTLIBCURRENT)/$(LIBRARYNAME).o
307 endif
308
309 # Does the library want an archive version built?
310 ifdef BUILD_ARCHIVE
311 all:: $(DESTLIBCURRENT)/lib$(LIBRARYNAME).a
312 endif
313
314 $(LIBNAME_O): $(ObjectsO) $(LibSubDirs) $(DESTLIBRELEASE)/.dir
315         @echo ======= Linking $(LIBRARYNAME) release library =======
316         $(VERB) $(MakeSOO) -o $@ $(ObjectsO) $(LibSubDirs) $(LibLinkOpts)
317
318 $(LIBNAME_P): $(ObjectsP) $(LibSubDirs) $(DESTLIBPROFILE)/.dir
319         @echo ======= Linking $(LIBRARYNAME) profile library =======
320         $(VERB) $(MakeSOP) -o $@ $(ObjectsP) $(LibSubDirs) $(LibLinkOpts)
321
322 $(LIBNAME_G): $(ObjectsG) $(LibSubDirs) $(DESTLIBDEBUG)/.dir
323         @echo ======= Linking $(LIBRARYNAME) debug library =======
324         $(VERB) $(MakeSO) -g -o $@ $(ObjectsG) $(LibSubDirs) $(LibLinkOpts)
325
326 $(LIBNAME_AO): $(ObjectsO) $(LibSubDirs) $(DESTLIBRELEASE)/.dir
327         @echo ======= Linking $(LIBRARYNAME) release library =======
328         @rm -f $@
329         $(VERB) $(AR) $@ $(ObjectsO) $(LibSubDirs)
330
331 $(LIBNAME_AP): $(ObjectsP) $(LibSubDirs) $(DESTLIBPROFILE)/.dir
332         @echo ======= Linking $(LIBRARYNAME) profile library =======
333         @rm -f $@
334         $(VERB) $(AR) $@ $(ObjectsP) $(LibSubDirs)
335
336 $(LIBNAME_AG): $(ObjectsG) $(LibSubDirs) $(DESTLIBDEBUG)/.dir
337         @echo ======= Linking $(LIBRARYNAME) debug library =======
338         @rm -f $@
339         $(VERB) $(AR) $@ $(ObjectsG) $(LibSubDirs)
340
341 $(LIBNAME_OBJO): $(ObjectsO) $(LibSubDirs) $(DESTLIBRELEASE)/.dir
342         @echo "Linking $@"
343         $(VERB) $(Relink) -o $@ $(ObjectsO) $(LibSubDirs)
344
345 $(LIBNAME_OBJP): $(ObjectsP) $(LibSubDirs) $(DESTLIBPROFILE)/.dir
346         @echo "Linking $@"
347         $(VERB) $(Relink) -o $@ $(ObjectsP) $(LibSubDirs)
348
349 $(LIBNAME_OBJG): $(ObjectsG) $(LibSubDirs) $(DESTLIBDEBUG)/.dir
350         @echo "Linking $@"
351         $(VERB) $(Relink) -o $@ $(ObjectsG) $(LibSubDirs)
352
353 endif
354
355 #------------------------------------------------------------------------
356 # Create a TAGS database for emacs
357 #------------------------------------------------------------------------
358
359 ifeq ($(LEVEL), .)
360 tags:
361         etags -l c++ `find include lib tools -name '*.cpp' -o -name '*.h'`
362 all:: tags
363 endif
364
365 #------------------------------------------------------------------------
366 # Handle the TOOLNAME option - used when building tool executables...
367 #------------------------------------------------------------------------
368 #
369 # The TOOLNAME option should be used with a USEDLIBS variable that tells the
370 # libraries (and the order of the libs) that should be linked to the
371 # tool. USEDLIBS should contain a list of library names (some with .a extension)
372 # that are automatically linked in as .o files unless the .a suffix is added.
373 #
374 ifdef TOOLNAME
375
376 # TOOLEXENAME* - These compute the output filenames to generate...
377 TOOLEXENAME_G := $(BUILD_ROOT_TOP)/tools/Debug/$(TOOLNAME)
378 TOOLEXENAME_O := $(BUILD_ROOT_TOP)/tools/Release/$(TOOLNAME)
379 TOOLEXENAME_P := $(BUILD_ROOT_TOP)/tools/Profile/$(TOOLNAME)
380 TOOLEXENAMES  := $(BUILD_ROOT_TOP)/tools/$(CONFIGURATION)/$(TOOLNAME)
381
382 # USED_LIBS_OPTIONS - Compute the options line that add -llib1 -llib2, etc.
383 ifdef PROJ_COMPILE
384
385 PROJ_LIBS_OPTIONS   := $(patsubst %.a.o, -l%, $(addsuffix .o, $(USEDLIBS)))
386 PROJ_LIBS_OPTIONS_G := $(patsubst %.o, $(PROJLIBDEBUGSOURCE)/%.o,  $(PROJ_LIBS_OPTIONS))
387 PROJ_LIBS_OPTIONS_O := $(patsubst %.o, $(PROJLIBRELEASESOURCE)/%.o,$(PROJ_LIBS_OPTIONS))
388 PROJ_LIBS_OPTIONS_P := $(patsubst %.o, $(PROJLIBPROFILESOURCE)/%.o,$(PROJ_LIBS_OPTIONS))
389
390 LLVM_LIBS_OPTIONS   := $(patsubst %.a.o, -l%, $(addsuffix .o, $(LLVMLIBS)))
391 LLVM_LIBS_OPTIONS_G := $(patsubst %.o, $(LLVMLIBDEBUGSOURCE)/%.o,  $(LLVM_LIBS_OPTIONS))
392 LLVM_LIBS_OPTIONS_O := $(patsubst %.o, $(LLVMLIBRELEASESOURCE)/%.o,$(LLVM_LIBS_OPTIONS))
393 LLVM_LIBS_OPTIONS_P := $(patsubst %.o, $(LLVMLIBPROFILESOURCE)/%.o,$(LLVM_LIBS_OPTIONS))
394
395 LIB_OPTS_G :=  $(LLVM_LIBS_OPTIONS_G) $(PROJ_LIBS_OPTIONS_G)
396 LIB_OPTS_O :=  $(LLVM_LIBS_OPTIONS_O) $(PROJ_LIBS_OPTIONS_P)
397 LIB_OPTS_P :=  $(LLVM_LIBS_OPTIONS_P) $(PROJ_LIBS_OPTIONS_P)
398
399 else
400
401 LLVM_LIBS_OPTIONS   := $(patsubst %.a.o, -l%, $(addsuffix .o, $(USEDLIBS)))
402 LLVM_LIBS_OPTIONS_G := $(patsubst %.o, $(LLVMLIBDEBUGSOURCE)/%.o,  $(LLVM_LIBS_OPTIONS))
403 LLVM_LIBS_OPTIONS_O := $(patsubst %.o, $(LLVMLIBRELEASESOURCE)/%.o,$(LLVM_LIBS_OPTIONS))
404 LLVM_LIBS_OPTIONS_P := $(patsubst %.o, $(LLVMLIBPROFILESOURCE)/%.o,$(LLVM_LIBS_OPTIONS))
405
406 LIB_OPTS_G :=  $(LLVM_LIBS_OPTIONS_G) 
407 LIB_OPTS_O :=  $(LLVM_LIBS_OPTIONS_O) 
408 LIB_OPTS_P :=  $(LLVM_LIBS_OPTIONS_P)
409 endif
410
411
412
413
414
415
416 # USED_LIB_PATHS - Compute the path of the libraries used so that tools are
417 # rebuilt if libraries change.  This has to make sure to handle .a/.so and .o
418 # files seperately.
419 #
420 STATICUSEDLIBS   := $(patsubst %.a.o, lib%.a, $(addsuffix .o, $(USEDLIBS)))
421 USED_LIB_PATHS_G := $(addprefix $(DESTLIBDEBUG)/, $(STATICUSEDLIBS))
422 USED_LIB_PATHS_O := $(addprefix $(DESTLIBRELEASE)/, $(STATICUSEDLIBS))
423 USED_LIB_PATHS_P := $(addprefix $(DESTLIBPROFILE)/, $(STATICUSEDLIBS))
424 LINK_OPTS        := $(TOOLLINKOPTS) $(PLATFORMLINKOPTS)
425
426
427
428
429
430
431 # Tell make that we need to rebuild subdirectories before we can link the tool.
432 # This affects things like LLI which has library subdirectories.
433 $(USED_LIB_PATHS_G) $(USED_LIB_PATHS_O) $(USED_LIB_PATHS_P): \
434         $(addsuffix /.makeall, $(PARALLEL_DIRS))
435
436 all::   $(TOOLEXENAMES)
437 clean::
438         $(VERB) rm -f $(TOOLEXENAMES)
439
440 $(TOOLEXENAME_G): $(ObjectsG) $(USED_LIB_PATHS_G) $(TOOLDEBUG)/.dir
441         @echo ======= Linking $(TOOLNAME) debug executable $(STRIP_WARN_MSG)=======
442         $(VERB) $(LinkG) -o $@ $(ObjectsG) $(LIB_OPTS_G) $(LINK_OPTS)
443
444 $(TOOLEXENAME_O): $(ObjectsO) $(USED_LIB_PATHS_O) $(TOOLRELEASE)/.dir
445         @echo ======= Linking $(TOOLNAME) release executable =======
446         $(VERB) $(LinkO) -o $@ $(ObjectsO) $(LIB_OPTS_O) $(LINK_OPTS)
447
448 $(TOOLEXENAME_P): $(ObjectsP) $(USED_LIB_PATHS_P) $(TOOLPROFILE)/.dir
449         @echo ======= Linking $(TOOLNAME) profile executable =======
450         $(VERB) $(LinkP) -o $@ $(ObjectsP) $(LIB_OPTS_P) $(LINK_OPTS)
451
452 endif
453
454
455
456 #---------------------------------------------------------
457 .PRECIOUS: $(BUILD_ROOT)/Depend/.dir
458 .PRECIOUS: $(BUILD_ROOT)/Debug/.dir $(BUILD_ROOT)/Release/.dir
459
460 # Create .o files in the ObjectFiles directory from the .cpp and .c files...
461 $(BUILD_ROOT)/Release/%.o: $(SourceDir)%.cpp $(BUILD_ROOT)/Release/.dir
462         @echo "Compiling $<"
463         $(VERB) $(CompileO) $< -o $@
464
465 $(BUILD_ROOT)/Release/%.o: $(SourceDir)%.c $(BUILD_ROOT)/Release/.dir
466         $(VERB) $(CompileCO) $< -o $@
467
468 $(BUILD_ROOT)/Profile/%.o: $(SourceDir)%.cpp $(BUILD_ROOT)/Profile/.dir
469         @echo "Compiling $<"
470         $(VERB) $(CompileP) $< -o $@
471
472 $(BUILD_ROOT)/Profile/%.o: $(SourceDir)%.c $(BUILD_ROOT)/Profile/.dir
473         @echo "Compiling $<"
474         $(VERB) $(CompileCP) $< -o $@
475
476 $(BUILD_ROOT)/Debug/%.o: $(SourceDir)%.cpp $(BUILD_ROOT)/Debug/.dir
477         @echo "Compiling $<"
478         $(VERB) $(CompileG) $< -o $@
479
480 $(BUILD_ROOT)/Debug/%.o: $(SourceDir)%.c $(BUILD_ROOT)/Debug/.dir 
481         $(VERB) $(CompileCG) $< -o $@
482
483 #
484 # Rules for building lex/yacc files
485 #
486 LEX_FILES   = $(filter %.l, $(Source))
487 LEX_OUTPUT  = $(LEX_FILES:%.l=%.cpp)
488 YACC_FILES  = $(filter %.y, $(Source))
489 YACC_OUTPUT = $(addprefix $(YACC_FILES:%.y=%), .h .cpp .output)
490 .PRECIOUS: $(LEX_OUTPUT) $(YACC_OUTPUT)
491
492 # Create a .cpp source file from a flex input file... this uses sed to cut down
493 # on the warnings emited by GCC...
494 #
495 # The last line is a gross hack to work around flex aparently not being able to
496 # resize the buffer on a large token input.  Currently, for uninitialized string
497 # buffers in LLVM we can generate very long tokens, so this is a hack around it.
498 # FIXME.  (f.e. char Buffer[10000]; )
499 #
500 %.cpp: %.l
501         $(FLEX) -t $< | sed '/^find_rule/d' | \
502                      sed 's/void yyunput/inline void yyunput/' | \
503           sed 's/void \*yy_flex_realloc/inline void *yy_flex_realloc/' | \
504           sed 's/#define YY_BUF_SIZE 16384/#define YY_BUF_SIZE (16384*64)/' > $@
505
506 # Rule for building the bison parsers...
507 %.c: %.y     # Cancel built-in rules for yacc
508 %.h: %.y     # Cancel built-in rules for yacc
509 %.cpp %.h : %.y
510         @echo Bison\'ing $<...
511         $(VERB) $(BISON) -v -d -p $(<:%Parser.y=%) $*.y
512         $(VERB) mv -f $*.tab.c $*.cpp
513         $(VERB) mv -f $*.tab.h $*.h
514
515 # To create the directories...
516 %/.dir:
517         $(VERB) mkdir -p $*
518         @date > $@
519
520 # To create postscript files from dot files...
521 %.ps: %.dot
522         dot -Tps < $< > $@
523
524 # 'make clean' nukes the tree
525 clean::
526         $(VERB) rm -rf $(BUILD_ROOT)/Debug $(BUILD_ROOT)/Release $(BUILD_ROOT)/Profile $(BUILD_ROOT)/Depend
527         $(VERB) rm -f core core.[0-9][0-9]* *.o *.d *.so *~ *.flc
528         $(VERB) rm -f $(LEX_OUTPUT) $(YACC_OUTPUT)
529
530 # If dependencies were generated for the file that included this file,
531 # include the dependancies now...
532 #
533 SourceBaseNames := $(basename $(notdir $(filter-out Debug/%, $(Source))))
534 SourceDepend := $(SourceBaseNames:%=$(BUILD_ROOT)/Depend/%.d)
535
536 # Create dependencies for the *.cpp files...
537 #$(SourceDepend): \x
538 $(BUILD_ROOT)/Depend/%.d: $(SourceDir)%.cpp $(BUILD_ROOT)/Depend/.dir
539         $(VERB) $(Depend) $< | sed 's|$*\.o *|$(BUILD_ROOT)/Release/& $(BUILD_ROOT)/Profile/& $(BUILD_ROOT)/Debug/& $(BUILD_ROOT)/Depend/$(@F)|g' > $@
540
541 # Create dependencies for the *.c files...
542 #$(SourceDepend): \x
543 $(BUILD_ROOT)/Depend/%.d: $(SourceDir)%.c $(BUILD_ROOT)/Depend/.dir
544         $(VERB) $(DependC) $< | sed 's|$*\.o *|Release/& Profile/& Debug/& Depend/$(@F)|g' > $@
545
546 ifneq ($(SourceDepend),)
547 -include $(SourceDepend)
548 endif