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