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