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