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