1 #===-- Makefile.common - Common make rules for LLVM -------*- makefile -*--====
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.
8 # The following functionality can be set by setting incoming variables.
9 # The variable $(LEVEL) *must* be set:
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.
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
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.
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
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.
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
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
42 #===-----------------------------------------------------------------------====
44 # Configuration file to set paths specific to local installation of LLVM
46 include $(LEVEL)/Makefile.config
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:
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.
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.
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.
62 ###########################################################################
65 # Set the source build directory. That is almost always the current directory.
68 BUILD_SRC_DIR = $(shell pwd)
72 # Set the source root directory.
75 BUILD_SRC_ROOT = $(shell cd $(BUILD_SRC_DIR)/$(LEVEL); pwd)
79 # Set the object build directory. Its location depends upon the source path
80 # and where object files should go.
84 BUILD_OBJ_DIR = $(shell pwd)
86 BUILD_OBJ_DIR := $(OBJ_ROOT)$(patsubst $(shell dirname $(BUILD_SRC_ROOT))%,%,$(shell cd $(BUILD_SRC_DIR); pwd))
91 # Set the root of the object directory.
95 BUILD_OBJ_ROOT = $(shell cd $(LEVEL); pwd)
97 BUILD_OBJ_ROOT := $(OBJ_ROOT)$(patsubst $(shell dirname $(BUILD_SRC_ROOT))%,%,$(shell cd $(BUILD_SRC_ROOT); pwd))
102 # Set the LLVM source directory.
103 # It is typically the root directory of what we're compiling now.
106 LLVM_SRC_ROOT = $(BUILD_SRC_ROOT)
110 # Set the LLVM object directory.
113 LLVM_OBJ_ROOT = $(BUILD_OBJ_ROOT)
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).
120 UNAME := $(shell uname)
121 include $(LLVM_SRC_ROOT)/Makefile.$(UNAME)
124 # if SHARED_LIBRARY is specified, the default is to build the dynamic lib
128 # Default Rule: Make sure it's also a :: rule
131 # Default for install is to at least build everything...
134 # Default rule for test. It ensures everything has a test rule
137 #--------------------------------------------------------------------
138 # Variables derived from configuration options...
139 #--------------------------------------------------------------------
141 #BinInstDir=/usr/local/bin
142 #LibInstDir=/usr/local/lib/xxx
143 #DocInstDir=/usr/doc/xxx
147 PURIFY := $(PURIFY) -cache-dir="$(BUILD_OBJ_ROOT)/../purifycache" -chain-length="30" -messages=all
149 ifdef ENABLE_PROFILING
151 CONFIGURATION := Profile
153 ifdef ENABLE_OPTIMIZED
154 CONFIGURATION := Release
156 CONFIGURATION := Debug
160 ###########################################################################
162 # These variables describe various library locations:
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 ###########################################################################
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)
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)
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)
187 ###########################################################################
189 # These variables describe various tool locations:
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 ###########################################################################
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)
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)
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)
216 #---------------------------------------------------------
217 # Compilation options...
218 #---------------------------------------------------------
220 ###########################################################################
221 # Special tools used while building the LLVM tree. Burg is built as part of the
223 ###########################################################################
224 BURG := $(LLVMTOOLCURRENT)/burg
225 RunBurg := $(BURG) $(BURG_OPTS)
227 TBLGEN := $(LLVMTOOLCURRENT)/tblgen
229 # Enable this for profiling support with 'gprof'
230 # This automatically enables optimized builds.
231 ifdef ENABLE_PROFILING
235 ###########################################################################
237 ###########################################################################
240 # Include both the project headers and the LLVM headers for compilation
242 CPPFLAGS += -I$(BUILD_SRC_ROOT)/include -I$(LLVM_SRC_ROOT)/include
244 # By default, strip symbol information from executable
246 STRIP = $(PLATFORMSTRIPOPTS)
247 STRIP_WARN_MSG = "(without symbols) "
250 # Allow gnu extensions...
251 CPPFLAGS += -D_GNU_SOURCE
253 # -Wno-unused-parameter
254 CompileCommonOpts := -Wall -W -Wwrite-strings -Wno-unused -I$(LEVEL)/include
255 CompileOptimizeOpts := -O3 -DNDEBUG -finline-functions -fshort-enums
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)
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)
270 # Link final executable
272 ifdef ENABLE_PURIFY # To enable purify, build with 'gmake ENABLE_PURIFY=1'
273 Link := $(PURIFY) $(CXX) -static
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)
284 LinkG := $(Link) -g -L$(LLVMLIBDEBUGSOURCE) $(STRIP)
285 LinkO := $(Link) -O3 -L$(LLVMLIBRELEASESOURCE)
286 LinkP := $(Link) -O3 -L$(LLVMLIBPROFILESOURCE) $(PROFILE)
291 # Create one .o file from a bunch of .o files...
294 # MakeSO - Create a .so file from a .o files...
295 MakeSO := $(CXX) $(MakeSharedObjectOption)
296 MakeSOO := $(MakeSO) -O3
297 MakeSOP := $(MakeSOO) $(PROFILE)
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)
303 # Archive a bunch of .o files into a .a file...
306 #----------------------------------------------------------
308 # Source includes all of the cpp files, and objects are derived from the
310 # The local Makefile can list other Source files via ExtraSource = ...
313 Source := $(ExtraSource) $(wildcard *.cpp *.c *.y *.l)
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))
322 #---------------------------------------------------------
323 # Handle the DIRS and PARALLEL_DIRS options
324 #---------------------------------------------------------
327 all install clean test ::
328 $(VERB) for dir in ${DIRS}; do \
329 (cd $$dir; $(MAKE) $@) || exit 1; \
333 # Handle 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))
340 %/.makeall %/.makeinstall %/.makeclean %/.maketest:
341 $(VERB) cd $(@D); $(MAKE) $(subst $(@D)/.make,,$@)
344 #---------------------------------------------------------
345 # Handle the LIBRARYNAME option - used when building libs...
346 #---------------------------------------------------------
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.
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.
363 # Make sure there isn't any extranous whitespace on the LIBRARYNAME option
364 LIBRARYNAME := $(strip $(LIBRARYNAME))
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
376 # dynamic target builds a shared object version of the library...
377 dynamic:: $(DESTLIBCURRENT)/lib$(LIBRARYNAME).so
379 # Does the library want a .o version built?
380 ifndef DONT_BUILD_RELINKED
381 all:: $(DESTLIBCURRENT)/$(LIBRARYNAME).o
384 # Does the library want an archive version built?
386 all:: $(DESTLIBCURRENT)/lib$(LIBRARYNAME).a
389 $(LIBNAME_O): $(ObjectsO) $(LibSubDirs) $(DESTLIBRELEASE)/.dir
390 @echo ======= Linking $(LIBRARYNAME) release library =======
391 $(VERB) $(MakeSOO) -o $@ $(ObjectsO) $(LibSubDirs) $(LibLinkOpts)
393 $(LIBNAME_P): $(ObjectsP) $(LibSubDirs) $(DESTLIBPROFILE)/.dir
394 @echo ======= Linking $(LIBRARYNAME) profile library =======
395 $(VERB) $(MakeSOP) -o $@ $(ObjectsP) $(LibSubDirs) $(LibLinkOpts)
397 $(LIBNAME_G): $(ObjectsG) $(LibSubDirs) $(DESTLIBDEBUG)/.dir
398 @echo ======= Linking $(LIBRARYNAME) debug library =======
399 $(VERB) $(MakeSO) -g -o $@ $(ObjectsG) $(LibSubDirs) $(LibLinkOpts)
401 $(LIBNAME_AO): $(ObjectsO) $(LibSubDirs) $(DESTLIBRELEASE)/.dir
402 @echo ======= Linking $(LIBRARYNAME) release library =======
404 $(VERB) $(AR) $@ $(ObjectsO) $(LibSubDirs)
406 $(LIBNAME_AP): $(ObjectsP) $(LibSubDirs) $(DESTLIBPROFILE)/.dir
407 @echo ======= Linking $(LIBRARYNAME) profile library =======
409 $(VERB) $(AR) $@ $(ObjectsP) $(LibSubDirs)
411 $(LIBNAME_AG): $(ObjectsG) $(LibSubDirs) $(DESTLIBDEBUG)/.dir
412 @echo ======= Linking $(LIBRARYNAME) debug library =======
414 $(VERB) $(AR) $@ $(ObjectsG) $(LibSubDirs)
416 $(LIBNAME_OBJO): $(ObjectsO) $(LibSubDirs) $(DESTLIBRELEASE)/.dir
418 $(VERB) $(Relink) -o $@ $(ObjectsO) $(LibSubDirs)
420 $(LIBNAME_OBJP): $(ObjectsP) $(LibSubDirs) $(DESTLIBPROFILE)/.dir
422 $(VERB) $(Relink) -o $@ $(ObjectsP) $(LibSubDirs)
424 $(LIBNAME_OBJG): $(ObjectsG) $(LibSubDirs) $(DESTLIBDEBUG)/.dir
426 $(VERB) $(Relink) -o $@ $(ObjectsG) $(LibSubDirs)
430 #------------------------------------------------------------------------
431 # Create a TAGS database for emacs
432 #------------------------------------------------------------------------
436 etags -l c++ `find include lib tools -name '*.cpp' -o -name '*.h'`
440 #------------------------------------------------------------------------
441 # Handle the TOOLNAME option - used when building tool executables...
442 #------------------------------------------------------------------------
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.
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)
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))
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))
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)
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
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)
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))
492 all:: $(TOOLEXENAMES)
494 $(VERB) rm -f $(TOOLEXENAMES)
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)
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)
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)
512 #---------------------------------------------------------
513 .PRECIOUS: $(BUILD_OBJ_DIR)/Depend/.dir
514 .PRECIOUS: $(BUILD_OBJ_DIR)/Debug/.dir $(BUILD_OBJ_DIR)/Release/.dir
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
519 $(VERB) $(CompileO) $< -o $@
521 $(BUILD_OBJ_DIR)/Release/%.o: $(SourceDir)%.c $(BUILD_OBJ_DIR)/Release/.dir
522 $(VERB) $(CompileCO) $< -o $@
524 $(BUILD_OBJ_DIR)/Profile/%.o: $(SourceDir)%.cpp $(BUILD_OBJ_DIR)/Profile/.dir
526 $(VERB) $(CompileP) $< -o $@
528 $(BUILD_OBJ_DIR)/Profile/%.o: $(SourceDir)%.c $(BUILD_OBJ_DIR)/Profile/.dir
530 $(VERB) $(CompileCP) $< -o $@
532 $(BUILD_OBJ_DIR)/Debug/%.o: $(SourceDir)%.cpp $(BUILD_OBJ_DIR)/Debug/.dir
534 $(VERB) $(CompileG) $< -o $@
536 $(BUILD_OBJ_DIR)/Debug/%.o: $(SourceDir)%.c $(BUILD_OBJ_DIR)/Debug/.dir
537 $(VERB) $(CompileCG) $< -o $@
540 # Rules for building lex/yacc files
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)
548 # Create a .cpp source file from a flex input file... this uses sed to cut down
549 # on the warnings emited by GCC...
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]; )
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)/' > $@
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
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
571 # To create the directories...
576 # To create postscript files from dot files...
580 # 'make clean' nukes the tree
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)
586 # If dependencies were generated for the file that included this file,
587 # include the dependancies now...
589 SourceBaseNames := $(basename $(notdir $(filter-out Debug/%, $(Source))))
590 SourceDepend := $(SourceBaseNames:%=$(BUILD_OBJ_DIR)/Depend/%.d)
592 # Create dependencies for the *.cpp files...
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' > $@
597 # Create dependencies for the *.c files...
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' > $@
602 ifneq ($(SourceDepend),)
603 -include $(SourceDepend)