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