Added a path to the current version of the built TableGen.
[oota-llvm.git] / Makefile.common
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 TBLGEN  := $(TOOLCURRENT)/tblgen
157
158 # Enable this for profiling support with 'gprof'
159 # This automatically enables optimized builds.
160 ifdef ENABLE_PROFILING
161   PROFILE = -pg
162 endif
163
164 #if PROJDIR is defined then we include PROJ DIR includes and libraries
165 ifndef PROJ_COMPILE
166 PROJ_INCLUDE = "."
167 else
168 PROJ_INCLUDE = $(PROJ_DIR)/include
169 endif 
170
171 # By default, strip symbol information from executable
172 ifndef KEEP_SYMBOLS
173 STRIP = $(PLATFORMSTRIPOPTS)
174 STRIP_WARN_MSG = "(without symbols) "
175 endif
176
177 # Allow gnu extensions...
178 CPPFLAGS += -D_GNU_SOURCE
179
180 # -Wno-unused-parameter
181 CompileCommonOpts := -Wall -W  -Wwrite-strings -Wno-unused -I$(LEVEL)/include -I$(PROJ_INCLUDE)
182 CompileOptimizeOpts := -O3 -DNDEBUG -finline-functions -fshort-enums
183
184 # Compile a cpp file, don't link...
185 Compile  := $(CXX) -c $(CPPFLAGS) $(CXXFLAGS) $(CompileCommonOpts)
186 CompileG := $(Compile) -g  -D_DEBUG
187 CompileO := $(Compile) $(CompileOptimizeOpts) -felide-constructors -fomit-frame-pointer
188 CompileP := $(Compile) $(CompileOptimizeOpts) -felide-constructors $(PROFILE)
189
190 # Compile a c file, don't link...
191 CompileC  := $(CC) -c $(CPPFLAGS) $(CCFLAGS) $(CompileCommonOpts)
192 CompileCG := $(CompileC) -g  -D_DEBUG
193 CompileCO := $(CompileC) $(CompileOptimizeOpts) -fomit-frame-pointer
194 CompileCP := $(CompileC) $(CompileOptimizeOpts) $(PROFILE)
195
196
197 # Link final executable
198
199 ifdef ENABLE_PURIFY # To enable purify, build with 'gmake ENABLE_PURIFY=1'
200 Link     := $(PURIFY) $(CXX) -static
201 else
202 Link     := $(CXX)
203 endif
204
205 ifdef PROJ_COMPILE
206 LinkG    := $(Link) -g -L$(PROJLIBDEBUGSOURCE)  -L$(LLVMLIBDEBUGSOURCE) $(STRIP)
207 LinkO    := $(Link) -O3 -L$(PROJLIBRELEASESOURCE) -L$(LLVMLIBRELEASESOURCE)
208 LinkP    := $(Link) -O3 -L$(PROJLIBPROFILESOURCE) -L$(LLVMLIBPROFILESOURCE) $(PROFILE)
209 else
210 LinkG    := $(Link) -g  -L$(LLVMLIBDEBUGSOURCE) $(STRIP)
211 LinkO    := $(Link) -O3 -L$(LLVMLIBRELEASESOURCE)
212 LinkP    := $(Link) -O3 -L$(LLVMLIBPROFILESOURCE) $(PROFILE)
213 endif
214
215
216
217 # Create one .o file from a bunch of .o files...
218 Relink = ld -r
219
220 # MakeSO - Create a .so file from a .o files...
221 MakeSO   := $(CXX) $(MakeSharedObjectOption)
222 MakeSOO  := $(MakeSO) -O3
223 MakeSOP  := $(MakeSOO) $(PROFILE)
224
225 # Create dependancy file from CPP file, send to stdout.
226 Depend   := $(CXX) -MM -I$(LEVEL)/include -I$(PROJ_INCLUDE) $(CPPFLAGS) 
227 DependC  := $(CC)  -MM -I$(LEVEL)/include -I$(PROJ_INCLUDE) $(CPPFLAGS) 
228
229 # Archive a bunch of .o files into a .a file...
230 AR       = ar cq 
231
232 #----------------------------------------------------------
233
234 # Source includes all of the cpp files, and objects are derived from the
235 # source files...
236 # The local Makefile can list other Source files via ExtraSource = ...
237
238 ifndef Source
239 Source  := $(ExtraSource) $(wildcard *.cpp *.c *.y *.l)
240 endif
241
242 Objs := $(sort $(patsubst Debug/%.o, %.o, $(addsuffix .o,$(notdir $(basename $(Source))))))
243 ObjectsO := $(addprefix $(BUILD_ROOT)/Release/,$(Objs))
244 ObjectsP := $(addprefix $(BUILD_ROOT)/Profile/,$(Objs))
245 ObjectsG := $(addprefix $(BUILD_ROOT)/Debug/,$(Objs))
246
247
248 #---------------------------------------------------------
249 # Handle the DIRS and PARALLEL_DIRS options
250 #---------------------------------------------------------
251
252 ifdef DIRS
253 all install clean test ::
254         $(VERB) for dir in ${DIRS}; do \
255                 (cd $$dir; $(MAKE) $@) || exit 1; \
256         done
257 endif
258
259 # Handle PARALLEL_DIRS
260 ifdef PARALLEL_DIRS
261 all     :: $(addsuffix /.makeall    , $(PARALLEL_DIRS))
262 install :: $(addsuffix /.makeinstall, $(PARALLEL_DIRS))
263 clean   :: $(addsuffix /.makeclean  , $(PARALLEL_DIRS))
264 test    :: $(addsuffix /.maketest   , $(PARALLEL_DIRS))
265
266 %/.makeall %/.makeinstall %/.makeclean %/.maketest:
267         $(VERB) cd $(@D); $(MAKE) $(subst $(@D)/.make,,$@)
268 endif
269
270 #---------------------------------------------------------
271 # Handle the LIBRARYNAME option - used when building libs...
272 #---------------------------------------------------------
273 #
274 #  When libraries are built, they are allowed to optionally define the
275 #  DONT_BUILD_RELINKED make variable, which, when defined, prevents a .o file
276 #  from being built for the library. This .o files may then be linked to by a
277 #  tool if the tool does not need (or want) the semantics a .a file provides
278 #  (linking in only object files that are "needed").  If a library is never to
279 #  be used in this way, it is better to define DONT_BUILD_RELINKED, and define
280 #  BUILD_ARCHIVE instead.
281 #
282 #  Some libraries must be built as .a files (libscalar for example) because if
283 #  it's built as a .o file, then all of the constituent .o files in it will be
284 #  linked into tools (for example gccas) even if they only use one of the parts
285 #  of it.  For this reason, sometimes it's useful to use libraries as .a files.
286
287 ifdef LIBRARYNAME
288
289 # Make sure there isn't any extranous whitespace on the LIBRARYNAME option
290 LIBRARYNAME := $(strip $(LIBRARYNAME))
291
292 LIBNAME_O    := $(DESTLIBRELEASE)/lib$(LIBRARYNAME).so
293 LIBNAME_P    := $(DESTLIBPROFILE)/lib$(LIBRARYNAME).so
294 LIBNAME_G    := $(DESTLIBDEBUG)/lib$(LIBRARYNAME).so
295 LIBNAME_AO   := $(DESTLIBRELEASE)/lib$(LIBRARYNAME).a
296 LIBNAME_AP   := $(DESTLIBPROFILE)/lib$(LIBRARYNAME).a
297 LIBNAME_AG   := $(DESTLIBDEBUG)/lib$(LIBRARYNAME).a
298 LIBNAME_OBJO := $(DESTLIBRELEASE)/$(LIBRARYNAME).o
299 LIBNAME_OBJP := $(DESTLIBPROFILE)/$(LIBRARYNAME).o
300 LIBNAME_OBJG := $(DESTLIBDEBUG)/$(LIBRARYNAME).o
301
302 # dynamic target builds a shared object version of the library...
303 dynamic:: $(DESTLIBCURRENT)/lib$(LIBRARYNAME).so
304
305 # Does the library want a .o version built?
306 ifndef DONT_BUILD_RELINKED
307 all:: $(DESTLIBCURRENT)/$(LIBRARYNAME).o
308 endif
309
310 # Does the library want an archive version built?
311 ifdef BUILD_ARCHIVE
312 all:: $(DESTLIBCURRENT)/lib$(LIBRARYNAME).a
313 endif
314
315 $(LIBNAME_O): $(ObjectsO) $(LibSubDirs) $(DESTLIBRELEASE)/.dir
316         @echo ======= Linking $(LIBRARYNAME) release library =======
317         $(VERB) $(MakeSOO) -o $@ $(ObjectsO) $(LibSubDirs) $(LibLinkOpts)
318
319 $(LIBNAME_P): $(ObjectsP) $(LibSubDirs) $(DESTLIBPROFILE)/.dir
320         @echo ======= Linking $(LIBRARYNAME) profile library =======
321         $(VERB) $(MakeSOP) -o $@ $(ObjectsP) $(LibSubDirs) $(LibLinkOpts)
322
323 $(LIBNAME_G): $(ObjectsG) $(LibSubDirs) $(DESTLIBDEBUG)/.dir
324         @echo ======= Linking $(LIBRARYNAME) debug library =======
325         $(VERB) $(MakeSO) -g -o $@ $(ObjectsG) $(LibSubDirs) $(LibLinkOpts)
326
327 $(LIBNAME_AO): $(ObjectsO) $(LibSubDirs) $(DESTLIBRELEASE)/.dir
328         @echo ======= Linking $(LIBRARYNAME) release library =======
329         @rm -f $@
330         $(VERB) $(AR) $@ $(ObjectsO) $(LibSubDirs)
331
332 $(LIBNAME_AP): $(ObjectsP) $(LibSubDirs) $(DESTLIBPROFILE)/.dir
333         @echo ======= Linking $(LIBRARYNAME) profile library =======
334         @rm -f $@
335         $(VERB) $(AR) $@ $(ObjectsP) $(LibSubDirs)
336
337 $(LIBNAME_AG): $(ObjectsG) $(LibSubDirs) $(DESTLIBDEBUG)/.dir
338         @echo ======= Linking $(LIBRARYNAME) debug library =======
339         @rm -f $@
340         $(VERB) $(AR) $@ $(ObjectsG) $(LibSubDirs)
341
342 $(LIBNAME_OBJO): $(ObjectsO) $(LibSubDirs) $(DESTLIBRELEASE)/.dir
343         @echo "Linking $@"
344         $(VERB) $(Relink) -o $@ $(ObjectsO) $(LibSubDirs)
345
346 $(LIBNAME_OBJP): $(ObjectsP) $(LibSubDirs) $(DESTLIBPROFILE)/.dir
347         @echo "Linking $@"
348         $(VERB) $(Relink) -o $@ $(ObjectsP) $(LibSubDirs)
349
350 $(LIBNAME_OBJG): $(ObjectsG) $(LibSubDirs) $(DESTLIBDEBUG)/.dir
351         @echo "Linking $@"
352         $(VERB) $(Relink) -o $@ $(ObjectsG) $(LibSubDirs)
353
354 endif
355
356 #------------------------------------------------------------------------
357 # Create a TAGS database for emacs
358 #------------------------------------------------------------------------
359
360 ifeq ($(LEVEL), .)
361 tags:
362         etags -l c++ `find include lib tools -name '*.cpp' -o -name '*.h'`
363 all:: tags
364 endif
365
366 #------------------------------------------------------------------------
367 # Handle the TOOLNAME option - used when building tool executables...
368 #------------------------------------------------------------------------
369 #
370 # The TOOLNAME option should be used with a USEDLIBS variable that tells the
371 # libraries (and the order of the libs) that should be linked to the
372 # tool. USEDLIBS should contain a list of library names (some with .a extension)
373 # that are automatically linked in as .o files unless the .a suffix is added.
374 #
375 ifdef TOOLNAME
376
377 # TOOLEXENAME* - These compute the output filenames to generate...
378 TOOLEXENAME_G := $(BUILD_ROOT_TOP)/tools/Debug/$(TOOLNAME)
379 TOOLEXENAME_O := $(BUILD_ROOT_TOP)/tools/Release/$(TOOLNAME)
380 TOOLEXENAME_P := $(BUILD_ROOT_TOP)/tools/Profile/$(TOOLNAME)
381 TOOLEXENAMES  := $(BUILD_ROOT_TOP)/tools/$(CONFIGURATION)/$(TOOLNAME)
382
383 # USED_LIBS_OPTIONS - Compute the options line that add -llib1 -llib2, etc.
384 ifdef PROJ_COMPILE
385
386 PROJ_LIBS_OPTIONS   := $(patsubst %.a.o, -l%, $(addsuffix .o, $(USEDLIBS)))
387 PROJ_LIBS_OPTIONS_G := $(patsubst %.o, $(PROJLIBDEBUGSOURCE)/%.o,  $(PROJ_LIBS_OPTIONS))
388 PROJ_LIBS_OPTIONS_O := $(patsubst %.o, $(PROJLIBRELEASESOURCE)/%.o,$(PROJ_LIBS_OPTIONS))
389 PROJ_LIBS_OPTIONS_P := $(patsubst %.o, $(PROJLIBPROFILESOURCE)/%.o,$(PROJ_LIBS_OPTIONS))
390
391 LLVM_LIBS_OPTIONS   := $(patsubst %.a.o, -l%, $(addsuffix .o, $(LLVMLIBS)))
392 LLVM_LIBS_OPTIONS_G := $(patsubst %.o, $(LLVMLIBDEBUGSOURCE)/%.o,  $(LLVM_LIBS_OPTIONS))
393 LLVM_LIBS_OPTIONS_O := $(patsubst %.o, $(LLVMLIBRELEASESOURCE)/%.o,$(LLVM_LIBS_OPTIONS))
394 LLVM_LIBS_OPTIONS_P := $(patsubst %.o, $(LLVMLIBPROFILESOURCE)/%.o,$(LLVM_LIBS_OPTIONS))
395
396 LIB_OPTS_G :=  $(LLVM_LIBS_OPTIONS_G) $(PROJ_LIBS_OPTIONS_G)
397 LIB_OPTS_O :=  $(LLVM_LIBS_OPTIONS_O) $(PROJ_LIBS_OPTIONS_P)
398 LIB_OPTS_P :=  $(LLVM_LIBS_OPTIONS_P) $(PROJ_LIBS_OPTIONS_P)
399
400 else
401
402 LLVM_LIBS_OPTIONS   := $(patsubst %.a.o, -l%, $(addsuffix .o, $(USEDLIBS)))
403 LLVM_LIBS_OPTIONS_G := $(patsubst %.o, $(LLVMLIBDEBUGSOURCE)/%.o,  $(LLVM_LIBS_OPTIONS))
404 LLVM_LIBS_OPTIONS_O := $(patsubst %.o, $(LLVMLIBRELEASESOURCE)/%.o,$(LLVM_LIBS_OPTIONS))
405 LLVM_LIBS_OPTIONS_P := $(patsubst %.o, $(LLVMLIBPROFILESOURCE)/%.o,$(LLVM_LIBS_OPTIONS))
406
407 LIB_OPTS_G :=  $(LLVM_LIBS_OPTIONS_G) 
408 LIB_OPTS_O :=  $(LLVM_LIBS_OPTIONS_O) 
409 LIB_OPTS_P :=  $(LLVM_LIBS_OPTIONS_P)
410 endif
411
412
413
414
415
416
417 # USED_LIB_PATHS - Compute the path of the libraries used so that tools are
418 # rebuilt if libraries change.  This has to make sure to handle .a/.so and .o
419 # files seperately.
420 #
421 STATICUSEDLIBS   := $(patsubst %.a.o, lib%.a, $(addsuffix .o, $(USEDLIBS)))
422 USED_LIB_PATHS_G := $(addprefix $(DESTLIBDEBUG)/, $(STATICUSEDLIBS))
423 USED_LIB_PATHS_O := $(addprefix $(DESTLIBRELEASE)/, $(STATICUSEDLIBS))
424 USED_LIB_PATHS_P := $(addprefix $(DESTLIBPROFILE)/, $(STATICUSEDLIBS))
425 LINK_OPTS        := $(TOOLLINKOPTS) $(PLATFORMLINKOPTS)
426
427
428
429
430
431
432 # Tell make that we need to rebuild subdirectories before we can link the tool.
433 # This affects things like LLI which has library subdirectories.
434 $(USED_LIB_PATHS_G) $(USED_LIB_PATHS_O) $(USED_LIB_PATHS_P): \
435         $(addsuffix /.makeall, $(PARALLEL_DIRS))
436
437 all::   $(TOOLEXENAMES)
438 clean::
439         $(VERB) rm -f $(TOOLEXENAMES)
440
441 $(TOOLEXENAME_G): $(ObjectsG) $(USED_LIB_PATHS_G) $(TOOLDEBUG)/.dir
442         @echo ======= Linking $(TOOLNAME) debug executable $(STRIP_WARN_MSG)=======
443         $(VERB) $(LinkG) -o $@ $(ObjectsG) $(LIB_OPTS_G) $(LINK_OPTS)
444
445 $(TOOLEXENAME_O): $(ObjectsO) $(USED_LIB_PATHS_O) $(TOOLRELEASE)/.dir
446         @echo ======= Linking $(TOOLNAME) release executable =======
447         $(VERB) $(LinkO) -o $@ $(ObjectsO) $(LIB_OPTS_O) $(LINK_OPTS)
448
449 $(TOOLEXENAME_P): $(ObjectsP) $(USED_LIB_PATHS_P) $(TOOLPROFILE)/.dir
450         @echo ======= Linking $(TOOLNAME) profile executable =======
451         $(VERB) $(LinkP) -o $@ $(ObjectsP) $(LIB_OPTS_P) $(LINK_OPTS)
452
453 endif
454
455
456
457 #---------------------------------------------------------
458 .PRECIOUS: $(BUILD_ROOT)/Depend/.dir
459 .PRECIOUS: $(BUILD_ROOT)/Debug/.dir $(BUILD_ROOT)/Release/.dir
460
461 # Create .o files in the ObjectFiles directory from the .cpp and .c files...
462 $(BUILD_ROOT)/Release/%.o: $(SourceDir)%.cpp $(BUILD_ROOT)/Release/.dir
463         @echo "Compiling $<"
464         $(VERB) $(CompileO) $< -o $@
465
466 $(BUILD_ROOT)/Release/%.o: $(SourceDir)%.c $(BUILD_ROOT)/Release/.dir
467         $(VERB) $(CompileCO) $< -o $@
468
469 $(BUILD_ROOT)/Profile/%.o: $(SourceDir)%.cpp $(BUILD_ROOT)/Profile/.dir
470         @echo "Compiling $<"
471         $(VERB) $(CompileP) $< -o $@
472
473 $(BUILD_ROOT)/Profile/%.o: $(SourceDir)%.c $(BUILD_ROOT)/Profile/.dir
474         @echo "Compiling $<"
475         $(VERB) $(CompileCP) $< -o $@
476
477 $(BUILD_ROOT)/Debug/%.o: $(SourceDir)%.cpp $(BUILD_ROOT)/Debug/.dir
478         @echo "Compiling $<"
479         $(VERB) $(CompileG) $< -o $@
480
481 $(BUILD_ROOT)/Debug/%.o: $(SourceDir)%.c $(BUILD_ROOT)/Debug/.dir 
482         $(VERB) $(CompileCG) $< -o $@
483
484 #
485 # Rules for building lex/yacc files
486 #
487 LEX_FILES   = $(filter %.l, $(Source))
488 LEX_OUTPUT  = $(LEX_FILES:%.l=%.cpp)
489 YACC_FILES  = $(filter %.y, $(Source))
490 YACC_OUTPUT = $(addprefix $(YACC_FILES:%.y=%), .h .cpp .output)
491 .PRECIOUS: $(LEX_OUTPUT) $(YACC_OUTPUT)
492
493 # Create a .cpp source file from a flex input file... this uses sed to cut down
494 # on the warnings emited by GCC...
495 #
496 # The last line is a gross hack to work around flex aparently not being able to
497 # resize the buffer on a large token input.  Currently, for uninitialized string
498 # buffers in LLVM we can generate very long tokens, so this is a hack around it.
499 # FIXME.  (f.e. char Buffer[10000]; )
500 #
501 %.cpp: %.l
502         $(FLEX) -t $< | sed '/^find_rule/d' | \
503                      sed 's/void yyunput/inline void yyunput/' | \
504           sed 's/void \*yy_flex_realloc/inline void *yy_flex_realloc/' | \
505           sed 's/#define YY_BUF_SIZE 16384/#define YY_BUF_SIZE (16384*64)/' > $@
506
507 # Rule for building the bison parsers...
508 %.c: %.y     # Cancel built-in rules for yacc
509 %.h: %.y     # Cancel built-in rules for yacc
510 %.cpp %.h : %.y
511         @echo Bison\'ing $<...
512         $(VERB) $(BISON) -v -d -p $(<:%Parser.y=%) $*.y
513         $(VERB) mv -f $*.tab.c $*.cpp
514         $(VERB) mv -f $*.tab.h $*.h
515
516 # To create the directories...
517 %/.dir:
518         $(VERB) mkdir -p $*
519         @date > $@
520
521 # To create postscript files from dot files...
522 %.ps: %.dot
523         dot -Tps < $< > $@
524
525 # 'make clean' nukes the tree
526 clean::
527         $(VERB) rm -rf $(BUILD_ROOT)/Debug $(BUILD_ROOT)/Release $(BUILD_ROOT)/Profile $(BUILD_ROOT)/Depend
528         $(VERB) rm -f core core.[0-9][0-9]* *.o *.d *.so *~ *.flc
529         $(VERB) rm -f $(LEX_OUTPUT) $(YACC_OUTPUT)
530
531 # If dependencies were generated for the file that included this file,
532 # include the dependancies now...
533 #
534 SourceBaseNames := $(basename $(notdir $(filter-out Debug/%, $(Source))))
535 SourceDepend := $(SourceBaseNames:%=$(BUILD_ROOT)/Depend/%.d)
536
537 # Create dependencies for the *.cpp files...
538 #$(SourceDepend): \x
539 $(BUILD_ROOT)/Depend/%.d: $(SourceDir)%.cpp $(BUILD_ROOT)/Depend/.dir
540         $(VERB) $(Depend) $< | sed 's|$*\.o *|$(BUILD_ROOT)/Release/& $(BUILD_ROOT)/Profile/& $(BUILD_ROOT)/Debug/& $(BUILD_ROOT)/Depend/$(@F)|g' > $@
541
542 # Create dependencies for the *.c files...
543 #$(SourceDepend): \x
544 $(BUILD_ROOT)/Depend/%.d: $(SourceDir)%.c $(BUILD_ROOT)/Depend/.dir
545         $(VERB) $(DependC) $< | sed 's|$*\.o *|Release/& Profile/& Debug/& Depend/$(@F)|g' > $@
546
547 ifneq ($(SourceDepend),)
548 -include $(SourceDepend)
549 endif