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. LLVM_SRC_ROOT - If specified, points to the top of the LLVM source tree.
35 # 7. LLVM_OBJ_ROOT - If specified, points to the top directory where LLVM
36 # object files are placed.
38 # 8. BUILD_SRC_DIR - The directory which contains the current set of Makefiles
39 # and usually the source code too (unless SourceDir is set).
41 # 9. BUILD_SRC_ROOT - The root directory of the source code being compiled.
43 # 10. BUILD_OBJ_DIR - The directory where object code should be placed.
45 # 11. BUILD_OBJ_ROOT - The root directory for where object code should be
49 # LLVM, LLVM_SRC_ROOT = BUILD_SRC_ROOT, and
50 # LLVM_OBJ_ROOT = BUILD_OBJ_ROOT.
52 #===-----------------------------------------------------------------------====
55 # Configuration file to set paths specific to local installation of LLVM
57 include $(LEVEL)/Makefile.config
59 ###########################################################################
60 # Directory Configuration
61 # This section of the Makefile determines what is where. To be
62 # specific, there are several locations that need to be defined:
64 # o LLVM_SRC_ROOT : The root directory of the LLVM source code.
65 # o LLVM_OBJ_ROOT : The root directory containing the built LLVM code.
67 # o BUILD_SRC_DIR : The directory containing the code to build.
68 # o BUILD_SRC_ROOT : The root directory of the code to build.
70 # o BUILD_OBJ_DIR : The directory in which compiled code will be placed.
71 # o BUILD_OBJ_ROOT : The root directory in which compiled code is placed.
73 ###########################################################################
76 # Set the source build directory. That is almost always the current directory.
79 BUILD_SRC_DIR = $(shell pwd)
83 # Set the source root directory.
86 BUILD_SRC_ROOT = $(shell cd $(BUILD_SRC_DIR)/$(LEVEL); pwd)
90 # Determine the path of the source tree relative from $HOME (the mythical
93 HOME_OBJ_ROOT := $(OBJ_ROOT)$(patsubst $(HOME)%,%,$(BUILD_SRC_ROOT))
96 # Set the object build directory. Its location depends upon the source path
97 # and where object files should go.
101 BUILD_OBJ_DIR = $(BUILD_SRC_DIR)
103 BUILD_OBJ_DIR := $(HOME_OBJ_ROOT)$(patsubst $(BUILD_SRC_ROOT)%,%,$(BUILD_SRC_DIR))
108 # Set the root of the object directory.
110 ifndef BUILD_OBJ_ROOT
112 BUILD_OBJ_ROOT = $(BUILD_SRC_ROOT)
114 BUILD_OBJ_ROOT := $(HOME_OBJ_ROOT)
119 # Set the LLVM source directory.
120 # It is typically the root directory of what we're compiling now.
123 LLVM_SRC_ROOT := $(BUILD_SRC_ROOT)
127 # Set the LLVM object directory.
130 LLVM_OBJ_ROOT := $(BUILD_OBJ_ROOT)
133 ###########################################################################
135 # The following targets are the standard top level targets for
137 ###########################################################################
140 # if SHARED_LIBRARY is specified, the default is to build the dynamic lib
144 ifdef BYTECODE_LIBRARY
145 # if BYTECODE_LIBRARY is specified, the default is to build the bytecode lib
147 install:: bytecodelib-install
150 # Default Rule: Make sure it's also a :: rule
153 # Default for install is to at least build everything...
156 # Default rule for test. It ensures everything has a test rule
159 # Default rule for building only bytecode.
162 # Print out the directories used for building
164 echo "Home Offset : " $(HOME_OBJ_ROOT)
165 echo "Build Source Root: " $(BUILD_SRC_ROOT)
166 echo "Build Source Dir : " $(BUILD_SRC_DIR)
167 echo "Build Object Root: " $(BUILD_OBJ_ROOT)
168 echo "Build Object Dir : " $(BUILD_OBJ_DIR)
169 echo "LLVM Source Root: " $(LLVM_SRC_ROOT)
170 echo "LLVM Object Root: " $(LLVM_OBJ_ROOT)
172 ###########################################################################
173 # Suffixes and implicit rules:
174 # Empty out the list of suffixes, generate a list that is only
175 # used by this Makefile, and cancel useless implicit rules. This
176 # will hopefully speed up compilation a little bit.
177 ###########################################################################
179 .SUFFIXES: .c .cpp .h .hpp .y .l
180 .SUFFIXES: .lo .o .a .so .bc
181 .SUFFIXES: .ps .dot .d
184 # Mark all of these targets as phony. This will hopefully speed up builds
185 # slightly since GNU Make will not try to find implicit rules for targets
186 # which are marked as Phony.
188 .PHONY: all dynamic bytecodelib bytecodelib-install
189 .PHONY: clean cleandeps distclean install test bytecode prdirs
191 ###########################################################################
192 # Miscellaneous paths and commands:
193 # This section defines various configuration macros, such as where
194 # to find burg, tblgen, and libtool.
195 ###########################################################################
197 #--------------------------------------------------------------------
198 # Variables derived from configuration options...
199 #--------------------------------------------------------------------
201 #BinInstDir=/usr/local/bin
202 #LibInstDir=/usr/local/lib/xxx
203 #DocInstDir=/usr/doc/xxx
207 ifdef ENABLE_PROFILING
209 CONFIGURATION := Profile
211 ifdef ENABLE_OPTIMIZED
212 CONFIGURATION := Release
214 CONFIGURATION := Debug
219 # Enable this for profiling support with 'gprof'
220 # This automatically enables optimized builds.
222 ifdef ENABLE_PROFILING
226 ###########################################################################
228 # These variables describe various library locations:
230 # DEST* = Location of where libraries that are built will be placed.
231 # LLVM* = Location of LLVM libraries used for linking.
232 # PROJ* = Location of previously built libraries used for linking.
233 ###########################################################################
235 # Libraries that are being built
236 DESTLIBDEBUG := $(BUILD_OBJ_ROOT)/lib/Debug
237 DESTLIBRELEASE := $(BUILD_OBJ_ROOT)/lib/Release
238 DESTLIBPROFILE := $(BUILD_OBJ_ROOT)/lib/Profile
239 DESTLIBBYTECODE := $(BUILD_OBJ_ROOT)/lib/Bytecode
240 DESTLIBCURRENT := $(BUILD_OBJ_ROOT)/lib/$(CONFIGURATION)
242 # LLVM libraries used for linking
243 LLVMLIBDEBUGSOURCE := $(LLVM_OBJ_ROOT)/lib/Debug
244 LLVMLIBRELEASESOURCE := $(LLVM_OBJ_ROOT)/lib/Release
245 LLVMLIBPROFILESOURCE := $(LLVM_OBJ_ROOT)/lib/Profile
246 LLVMLIBCURRENTSOURCE := $(LLVM_OBJ_ROOT)/lib/$(CONFIGURATION)
248 # Libraries that were built that will now be used for linking
249 PROJLIBDEBUGSOURCE := $(BUILD_OBJ_ROOT)/lib/Debug
250 PROJLIBRELEASESOURCE := $(BUILD_OBJ_ROOT)/lib/Release
251 PROJLIBPROFILESOURCE := $(BUILD_OBJ_ROOT)/lib/Profile
252 PROJLIBCURRENTSOURCE := $(BUILD_OBJ_ROOT)/lib/$(CONFIGURATION)
254 ###########################################################################
256 # These variables describe various tool locations:
258 # DEST* = Location of where tools that are built will be placed.
259 # LLVM* = Location of LLVM tools used for building.
260 # PROJ* = Location of previously built tools used for linking.
261 ###########################################################################
263 DESTTOOLDEBUG := $(BUILD_OBJ_ROOT)/tools/Debug
264 DESTTOOLRELEASE := $(BUILD_OBJ_ROOT)/tools/Release
265 DESTTOOLPROFILE := $(BUILD_OBJ_ROOT)/tools/Profile
266 DESTTOOLCURRENT := $(BUILD_OBJ_ROOT)/tools/$(CONFIGURATION)
268 LLVMTOOLDEBUG := $(LLVM_OBJ_ROOT)/tools/Debug
269 LLVMTOOLRELEASE := $(LLVM_OBJ_ROOT)/tools/Release
270 LLVMTOOLPROFILE := $(LLVM_OBJ_ROOT)/tools/Profile
271 LLVMTOOLCURRENT := $(LLVM_OBJ_ROOT)/tools/$(CONFIGURATION)
273 PROJTOOLDEBUG := $(BUILD_OBJ_ROOT)/tools/Debug
274 PROJTOOLRELEASE := $(BUILD_OBJ_ROOT)/tools/Release
275 PROJTOOLPROFILE := $(BUILD_OBJ_ROOT)/tools/Profile
276 PROJTOOLCURRENT := $(BUILD_OBJ_ROOT)/tools/$(CONFIGURATION)
279 # Libtool is found in the current directory.
281 LIBTOOL := $(LLVM_SRC_ROOT)/mklib
284 # If we're not building a shared library, use the disable-shared tag with
285 # libtool. This will disable the building of objects for shared libraries and
286 # only generate static library objects.
288 # For dynamic libraries, we'll take the performance hit for now, since we
289 # almost never build them.
291 # This should speed up compilation and require no modifications to future
292 # versions of libtool.
294 ifndef SHARED_LIBRARY
295 LIBTOOL += --tag=disable-shared
306 ###########################################################################
307 # Miscellaneous paths and commands (part deux):
308 # This section defines various configuration macros, such as where
309 # to find burg, tblgen, and libtool.
310 ###########################################################################
312 #--------------------------------------------------------------------------
313 # Utilities used while building the LLVM tree, which live in the utils dir
315 BURG := $(LLVMTOOLCURRENT)/burg
316 RunBurg := $(BURG) $(BURG_OPTS)
317 TBLGEN := $(LLVMTOOLCURRENT)/tblgen
319 #--------------------------------------------------------------------------
320 # The LLVM GCC front-end in C and C++ flavors
322 LLVMGCC := PATH=$(LLVMTOOLCURRENT):$(PATH) $(LLVMGCCDIR)/bin/gcc
323 LCC1 := $(LLVMGCCDIR)/lib/gcc-lib/$(LLVMGCCARCH)/cc1
324 LLVMGXX := PATH=$(LLVMTOOLCURRENT):$(PATH) $(LLVMGCCDIR)/bin/g++
325 LCC1XX := $(LLVMGCCDIR)/lib/gcc-lib/$(LLVMGCCARCH)/cc1plus
327 #--------------------------------------------------------------------------
328 # Some of the compiled LLVM tools which are used for compilation of runtime
331 LLVMAS := $(LLVMTOOLCURRENT)/as
334 ###########################################################################
336 ###########################################################################
339 # Include both the project headers and the LLVM headers for compilation and
340 # dependency computation.
342 CPPFLAGS += -I$(BUILD_SRC_ROOT)/include -I$(LLVM_SRC_ROOT)/include
344 # By default, strip symbol information from executable
346 STRIP = $(PLATFORMSTRIPOPTS)
347 STRIP_WARN_MSG = "(without symbols)"
350 # Allow gnu extensions...
351 CPPFLAGS += -D_GNU_SOURCE
353 CompileCommonOpts := -Wall -W -Wwrite-strings -Wno-unused -I$(LEVEL)/include
354 CompileOptimizeOpts := -O3 -DNDEBUG -finline-functions -fshort-enums
357 # Compile commands with libtool.
359 Compile := $(LIBTOOL) --mode=compile $(CXX) -c $(CPPFLAGS) $(CXXFLAGS) $(CompileCommonOpts)
360 CompileC := $(LIBTOOL) --mode=compile $(CC) -c $(CPPFLAGS) $(CCFLAGS) $(CompileCommonOpts)
362 # Compile a cpp file, don't link...
363 CompileG := $(Compile) -g -D_DEBUG
364 CompileO := $(Compile) $(CompileOptimizeOpts) -felide-constructors -fomit-frame-pointer
365 CompileP := $(Compile) $(CompileOptimizeOpts) -felide-constructors $(PROFILE)
367 # Compile a c file, don't link...
368 CompileCG := $(CompileC) -g -D_DEBUG
369 CompileCO := $(CompileC) $(CompileOptimizeOpts) -fomit-frame-pointer
370 CompileCP := $(CompileC) $(CompileOptimizeOpts) $(PROFILE)
372 ###########################################################################
374 ###########################################################################
377 # Link final executable
378 # (Note that we always link with the C++ compiler).
380 Link := $(LIBTOOL) --mode=link $(CXX)
382 # link both projlib and llvmlib libraries
383 LinkG := $(Link) -g -L$(PROJLIBDEBUGSOURCE) -L$(LLVMLIBDEBUGSOURCE) $(STRIP)
384 LinkO := $(Link) -O3 -L$(PROJLIBRELEASESOURCE) -L$(LLVMLIBRELEASESOURCE)
385 LinkP := $(Link) -O3 -L$(PROJLIBPROFILESOURCE) -L$(LLVMLIBPROFILESOURCE) $(PROFILE)
387 # Create one .o file from a bunch of .o files...
388 Relink := ${LIBTOOL} --mode=link $(CXX)
391 # Configure where the item being compiled should go.
394 Link += -rpath $(DESTLIBCURRENT)
398 Link += -rpath $(DESTTOOLCURRENT)
401 # Create dependancy file from CPP file, send to stdout.
402 Depend := $(CXX) -MM -I$(LEVEL)/include $(CPPFLAGS)
403 DependC := $(CC) -MM -I$(LEVEL)/include $(CPPFLAGS)
405 # Archive a bunch of .o files into a .a file...
408 #----------------------------------------------------------
410 # Source includes all of the cpp files, and objects are derived from the
412 # The local Makefile can list other Source files via ExtraSource = ...
415 Source := $(ExtraSource) $(wildcard *.cpp *.c *.y *.l)
421 Srcs := $(sort $(notdir $(basename $(Source))))
422 Objs := $(addsuffix .lo, $(Srcs))
423 ObjectsO := $(addprefix $(BUILD_OBJ_DIR)/Release/,$(Objs))
424 ObjectsP := $(addprefix $(BUILD_OBJ_DIR)/Profile/,$(Objs))
425 ObjectsG := $(addprefix $(BUILD_OBJ_DIR)/Debug/,$(Objs))
426 ObjectsBC := $(addprefix $(BUILD_OBJ_DIR)/Bytecode/,$(addsuffix .bc, $(Srcs)))
429 # The real objects underlying the libtool objects
431 RObjs := $(sort $(patsubst Debug/%.o, %.o, $(addsuffix .o,$(notdir $(basename $(Source))))))
432 RObjectsO := $(addprefix $(BUILD_OBJ_DIR)/Release/,$(RObjs))
433 RObjectsP := $(addprefix $(BUILD_OBJ_DIR)/Profile/,$(RObjs))
434 RObjectsG := $(addprefix $(BUILD_OBJ_DIR)/Debug/,$(RObjs))
436 #---------------------------------------------------------
437 # Handle the DIRS and PARALLEL_DIRS options
438 #---------------------------------------------------------
441 all install clean cleandeps test bytecode ::
442 $(VERB) for dir in ${DIRS}; do \
443 (cd $$dir; $(MAKE) $@) || exit 1; \
447 # Handle PARALLEL_DIRS
449 all :: $(addsuffix /.makeall , $(PARALLEL_DIRS))
450 install :: $(addsuffix /.makeinstall , $(PARALLEL_DIRS))
451 clean :: $(addsuffix /.makeclean , $(PARALLEL_DIRS))
452 cleandeps:: $(addsuffix /.makecleandeps, $(PARALLEL_DIRS))
453 test :: $(addsuffix /.maketest , $(PARALLEL_DIRS))
454 bytecode :: $(addsuffix /.makebytecode, $(PARALLEL_DIRS))
456 %/.makeall %/.makeinstall %/.makeclean %/.makecleandeps %/.maketest \
458 $(VERB) cd $(@D); $(MAKE) $(subst $(@D)/.make,,$@)
461 # Handle directories that may or may not exist
463 all install clean cleandeps test bytecode ::
464 $(VERB) for dir in ${OPTIONAL_DIRS}; do \
467 (cd $$dir; $(MAKE) $@) || exit 1; \
472 ###########################################################################
473 # Library Build Rules:
475 #---------------------------------------------------------
476 # Handle the LIBRARYNAME option - used when building libs...
477 #---------------------------------------------------------
479 # When libraries are built, they are allowed to optionally define the
480 # DONT_BUILD_RELINKED make variable, which, when defined, prevents a .o file
481 # from being built for the library. This .o files may then be linked to by a
482 # tool if the tool does not need (or want) the semantics a .a file provides
483 # (linking in only object files that are "needed"). If a library is never to
484 # be used in this way, it is better to define DONT_BUILD_RELINKED, and define
485 # BUILD_ARCHIVE instead.
487 # Some libraries must be built as .a files (libscalar for example) because if
488 # it's built as a .o file, then all of the constituent .o files in it will be
489 # linked into tools (for example gccas) even if they only use one of the parts
490 # of it. For this reason, sometimes it's useful to use libraries as .a files.
491 ###########################################################################
495 # Make sure there isn't any extranous whitespace on the LIBRARYNAME option
496 LIBRARYNAME := $(strip $(LIBRARYNAME))
498 LIBNAME_O := $(DESTLIBRELEASE)/lib$(LIBRARYNAME).so
499 LIBNAME_P := $(DESTLIBPROFILE)/lib$(LIBRARYNAME).so
500 LIBNAME_G := $(DESTLIBDEBUG)/lib$(LIBRARYNAME).so
501 LIBNAME_AO := $(DESTLIBRELEASE)/lib$(LIBRARYNAME).a
502 LIBNAME_AP := $(DESTLIBPROFILE)/lib$(LIBRARYNAME).a
503 LIBNAME_AG := $(DESTLIBDEBUG)/lib$(LIBRARYNAME).a
504 LIBNAME_OBJO := $(DESTLIBRELEASE)/$(LIBRARYNAME).o
505 LIBNAME_OBJP := $(DESTLIBPROFILE)/$(LIBRARYNAME).o
506 LIBNAME_OBJG := $(DESTLIBDEBUG)/$(LIBRARYNAME).o
507 LIBNAME_BC := $(DESTLIBBYTECODE)/lib$(LIBRARYNAME).bc
509 #--------------------------------------------------------------------
511 # Modify the top level targets to build the desired libraries.
512 #--------------------------------------------------------------------
514 # dynamic target builds a shared object version of the library...
515 dynamic:: $(DESTLIBCURRENT)/lib$(LIBRARYNAME).so
516 bytecodelib:: $(LIBNAME_BC)
517 bytecodelib-install:: $(LLVMGCCDIR)/bytecode-libs/lib$(LIBRARYNAME).bc
519 $(LLVMGCCDIR)/bytecode-libs/lib$(LIBRARYNAME).bc: $(LIBNAME_BC)
520 @echo ======= Installing $(LIBRARYNAME) bytecode library =======
523 # Does the library want a .o version built?
524 ifndef DONT_BUILD_RELINKED
525 all:: $(DESTLIBCURRENT)/$(LIBRARYNAME).o
528 # Does the library want an archive version built?
530 all:: $(DESTLIBCURRENT)/lib$(LIBRARYNAME).a
533 #--------------------------------------------------------------------
534 # Rules for building libraries
535 #--------------------------------------------------------------------
537 LinkBCLib := $(LLVMGCC) -shared
538 ifdef EXPORTED_SYMBOL_LIST
539 LinkBCLib += -Xlinker -internalize-public-api-list=$(EXPORTED_SYMBOL_LIST)
541 LinkBCLib += -Xlinker -disable-internalize
545 # Rule for building bytecode libraries.
546 $(LIBNAME_BC): $(ObjectsBC) $(LibSubDirs) $(DESTLIBBYTECODE)/.dir
547 @echo ======= Linking $(LIBRARYNAME) bytecode library =======
548 $(VERB) $(LinkBCLib) -o $@ $(ObjectsBC) $(LibSubDirs) $(LibLinkOpts)
550 # Rules for building dynamically linked libraries.
552 $(LIBNAME_O): $(ObjectsO) $(LibSubDirs) $(DESTLIBRELEASE)/.dir
553 @echo ======= Linking $(LIBRARYNAME) dynamic release library =======
554 $(VERB) $(Link) -o $*.la $(ObjectsO) $(LibSubDirs) $(LibLinkOpts)
555 $(VERB) $(LIBTOOL) --mode=install $(INSTALL) $*.la $(DESTLIBCURRENT)
557 $(LIBNAME_P): $(ObjectsP) $(LibSubDirs) $(DESTLIBPROFILE)/.dir
558 @echo ======= Linking $(LIBRARYNAME) dynamic profile library =======
559 $(VERB) $(Link) -o $*.la $(ObjectsP) $(LibSubDirs) $(LibLinkOpts)
560 $(VERB) $(LIBTOOL) --mode=install $(INSTALL) $*.la $(DESTLIBCURRENT)
562 $(LIBNAME_G): $(ObjectsG) $(LibSubDirs) $(DESTLIBDEBUG)/.dir
563 @echo ======= Linking $(LIBRARYNAME) dynamic debug library =======
564 $(VERB) $(Link) -o $*.la $(ObjectsG) $(LibSubDirs) $(LibLinkOpts)
565 $(VERB) $(LIBTOOL) --mode=install $(INSTALL) $*.la $(DESTLIBCURRENT)
568 # Rules for building static archive libraries.
570 $(LIBNAME_AO): $(ObjectsO) $(LibSubDirs) $(DESTLIBRELEASE)/.dir
571 @echo ======= Linking $(LIBRARYNAME) archive release library =======
573 $(VERB) $(Link) -03 -o $@ $(ObjectsO) $(LibSubDirs) -static
575 $(LIBNAME_AP): $(ObjectsP) $(LibSubDirs) $(DESTLIBPROFILE)/.dir
576 @echo ======= Linking $(LIBRARYNAME) archive profile library =======
578 $(VERB) $(Link) -03 $(PROFILE) -o $@ $(ObjectsP) $(LibSubDirs) -static
580 $(LIBNAME_AG): $(ObjectsG) $(LibSubDirs) $(DESTLIBDEBUG)/.dir
581 @echo ======= Linking $(LIBRARYNAME) archive debug library =======
583 $(VERB) $(Link) -g $(STRIP) -o $@ $(ObjectsG) $(LibSubDirs) -static
587 # Rules for building .o libraries.
590 # Note that for this special case, we specify the actual object files
591 # instead of their libtool counterparts. This is because libtool
592 # doesn't want to generate a reloadable object file unless it is given
593 # .o files explicitly.
595 # Note that we're making an assumption here: If we build a .lo file,
596 # it's corresponding .o file will be placed in the same directory.
598 # I think that is safe.
600 $(LIBNAME_OBJO): $(ObjectsO) $(LibSubDirs) $(DESTLIBRELEASE)/.dir
602 $(VERB) $(Relink) -o $@ $(RObjectsO) $(LibSubDirs)
604 $(LIBNAME_OBJP): $(ObjectsP) $(LibSubDirs) $(DESTLIBPROFILE)/.dir
606 $(VERB) $(Relink) -o $@ $(RObjectsP) $(LibSubDirs)
608 $(LIBNAME_OBJG): $(ObjectsG) $(LibSubDirs) $(DESTLIBDEBUG)/.dir
610 $(VERB) $(Relink) -o $@ $(RObjectsG) $(LibSubDirs)
614 #------------------------------------------------------------------------
615 # Create a TAGS database for emacs
616 #------------------------------------------------------------------------
621 $(ETAGS) -l c++ `find include lib tools -name '*.cpp' -o -name '*.h'`
626 ${ECHO} "Cannot build $@: The program etags is not installed"
629 #------------------------------------------------------------------------
630 # Handle the TOOLNAME option - used when building tool executables...
631 #------------------------------------------------------------------------
633 # The TOOLNAME option should be used with a USEDLIBS variable that tells the
634 # libraries (and the order of the libs) that should be linked to the
635 # tool. USEDLIBS should contain a list of library names (some with .a extension)
636 # that are automatically linked in as .o files unless the .a suffix is added.
640 # TOOLEXENAME* - These compute the output filenames to generate...
641 TOOLEXENAME_G := $(DESTTOOLDEBUG)/$(TOOLNAME)
642 TOOLEXENAME_O := $(DESTTOOLRELEASE)/$(TOOLNAME)
643 TOOLEXENAME_P := $(DESTTOOLPROFILE)/$(TOOLNAME)
644 TOOLEXENAMES := $(DESTTOOLCURRENT)/$(TOOLNAME)
646 # USED_LIBS_OPTIONS - Compute the options line that add -llib1 -llib2, etc.
647 PROJ_LIBS_OPTIONS := $(patsubst %.a.o, -l%, $(addsuffix .o, $(USEDLIBS)))
648 PROJ_LIBS_OPTIONS_G := $(patsubst %.o, $(PROJLIBDEBUGSOURCE)/%.o, $(PROJ_LIBS_OPTIONS))
649 PROJ_LIBS_OPTIONS_O := $(patsubst %.o, $(PROJLIBRELEASESOURCE)/%.o,$(PROJ_LIBS_OPTIONS))
650 PROJ_LIBS_OPTIONS_P := $(patsubst %.o, $(PROJLIBPROFILESOURCE)/%.o,$(PROJ_LIBS_OPTIONS))
652 LLVM_LIBS_OPTIONS := $(patsubst %.a.o, -l%, $(addsuffix .o, $(LLVMLIBS)))
653 LLVM_LIBS_OPTIONS_G := $(patsubst %.o, $(LLVMLIBDEBUGSOURCE)/%.o, $(LLVM_LIBS_OPTIONS))
654 LLVM_LIBS_OPTIONS_O := $(patsubst %.o, $(LLVMLIBRELEASESOURCE)/%.o,$(LLVM_LIBS_OPTIONS))
655 LLVM_LIBS_OPTIONS_P := $(patsubst %.o, $(LLVMLIBPROFILESOURCE)/%.o,$(LLVM_LIBS_OPTIONS))
657 LIB_OPTS_G := $(LLVM_LIBS_OPTIONS_G) $(PROJ_LIBS_OPTIONS_G)
658 LIB_OPTS_O := $(LLVM_LIBS_OPTIONS_O) $(PROJ_LIBS_OPTIONS_O)
659 LIB_OPTS_P := $(LLVM_LIBS_OPTIONS_P) $(PROJ_LIBS_OPTIONS_P)
661 # USED_LIB_PATHS - Compute the path of the libraries used so that tools are
662 # rebuilt if libraries change. This has to make sure to handle .a/.so and .o
665 STATICUSEDLIBS := $(patsubst %.a.o, lib%.a, $(addsuffix .o, $(USEDLIBS)))
666 USED_LIB_PATHS_G := $(addprefix $(DESTLIBDEBUG)/, $(STATICUSEDLIBS))
667 USED_LIB_PATHS_O := $(addprefix $(DESTLIBRELEASE)/, $(STATICUSEDLIBS))
668 USED_LIB_PATHS_P := $(addprefix $(DESTLIBPROFILE)/, $(STATICUSEDLIBS))
671 # Libtool link options:
672 # Ensure that all binaries have their symbols exported so that they can
675 LINK_OPTS := -export-dynamic $(TOOLLINKOPTS)
681 # Tell make that we need to rebuild subdirectories before we can link the tool.
682 # This affects things like LLI which has library subdirectories.
683 $(USED_LIB_PATHS_G) $(USED_LIB_PATHS_O) $(USED_LIB_PATHS_P): \
684 $(addsuffix /.makeall, $(PARALLEL_DIRS))
686 all:: $(TOOLEXENAMES)
689 $(VERB) $(RM) -f $(TOOLEXENAMES)
691 $(TOOLEXENAME_G): $(ObjectsG) $(USED_LIB_PATHS_G) $(DESTTOOLDEBUG)/.dir
692 @echo ======= Linking $(TOOLNAME) debug executable $(STRIP_WARN_MSG) =======
693 $(VERB) $(LinkG) -o $@ $(ObjectsG) $(LIB_OPTS_G) $(LINK_OPTS) $(LIBS)
695 $(TOOLEXENAME_O): $(ObjectsO) $(USED_LIB_PATHS_O) $(DESTTOOLRELEASE)/.dir
696 @echo ======= Linking $(TOOLNAME) release executable =======
697 $(VERB) $(LinkO) -o $@ $(ObjectsO) $(LIB_OPTS_O) $(LINK_OPTS) $(LIBS)
699 $(TOOLEXENAME_P): $(ObjectsP) $(USED_LIB_PATHS_P) $(DESTTOOLPROFILE)/.dir
700 @echo ======= Linking $(TOOLNAME) profile executable =======
701 $(VERB) $(LinkP) -o $@ $(ObjectsP) $(LIB_OPTS_P) $(LINK_OPTS) $(LIBS)
707 #---------------------------------------------------------
708 .PRECIOUS: $(BUILD_OBJ_DIR)/Depend/.dir $(BUILD_OBJ_DIR)/Bytecode/.dir
709 .PRECIOUS: $(BUILD_OBJ_DIR)/Debug/.dir $(BUILD_OBJ_DIR)/Release/.dir
711 # Create .lo files in the ObjectFiles directory from the .cpp and .c files...
712 $(BUILD_OBJ_DIR)/Release/%.lo: $(SourceDir)%.cpp $(BUILD_OBJ_DIR)/Release/.dir
714 $(VERB) $(CompileO) $< -o $@
716 $(BUILD_OBJ_DIR)/Release/%.lo: $(SourceDir)%.c $(BUILD_OBJ_DIR)/Release/.dir
718 $(VERB) $(CompileCO) $< -o $@
720 $(BUILD_OBJ_DIR)/Profile/%.lo: $(SourceDir)%.cpp $(BUILD_OBJ_DIR)/Profile/.dir
722 $(VERB) $(CompileP) $< -o $@
724 $(BUILD_OBJ_DIR)/Profile/%.lo: $(SourceDir)%.c $(BUILD_OBJ_DIR)/Profile/.dir
726 $(VERB) $(CompileCP) $< -o $@
728 $(BUILD_OBJ_DIR)/Debug/%.lo: $(SourceDir)%.cpp $(BUILD_OBJ_DIR)/Debug/.dir
730 $(VERB) $(CompileG) $< -o $@
732 $(BUILD_OBJ_DIR)/Debug/%.lo: $(SourceDir)%.c $(BUILD_OBJ_DIR)/Debug/.dir
734 $(VERB) $(CompileCG) $< -o $@
736 $(BUILD_OBJ_DIR)/Bytecode/%.bc: $(SourceDir)%.cpp $(BUILD_OBJ_DIR)/Bytecode/.dir $(LCC1XX)
737 @echo "Compiling $< to bytecode"
738 $(VERB) $(LLVMGXX) $(CPPFLAGS) -c $< -o $@
740 $(BUILD_OBJ_DIR)/Bytecode/%.bc: $(SourceDir)%.c $(BUILD_OBJ_DIR)/Bytecode/.dir $(LCC1)
741 @echo "Compiling $< to bytecode"
742 $(VERB) $(LLVMGCC) $(CPPFLAGS) -c $< -o $@
744 $(BUILD_OBJ_DIR)/Bytecode/%.bc: $(SourceDir)%.ll $(BUILD_OBJ_DIR)/Bytecode/.dir $(LCC1)
745 @echo "Compiling $< to bytecode"
746 $(VERB) $(LLVMAS) $< -f -o $@
750 # Rules for building lex/yacc files
752 LEX_FILES = $(filter %.l, $(Source))
753 LEX_OUTPUT = $(LEX_FILES:%.l=%.cpp)
754 YACC_FILES = $(filter %.y, $(Source))
755 YACC_OUTPUT = $(addprefix $(YACC_FILES:%.y=%), .h .cpp .output)
756 .PRECIOUS: $(LEX_OUTPUT) $(YACC_OUTPUT)
758 # Create a .cpp source file from a flex input file... this uses sed to cut down
759 # on the warnings emited by GCC...
761 # The last line is a gross hack to work around flex aparently not being able to
762 # resize the buffer on a large token input. Currently, for uninitialized string
763 # buffers in LLVM we can generate very long tokens, so this is a hack around it.
764 # FIXME. (f.e. char Buffer[10000] )
767 @echo Flex\'ing $<...
768 $(VERB) $(FLEX) -t $< | \
769 $(SED) '/^find_rule/d' | \
770 $(SED) 's/void yyunput/inline void yyunput/' | \
771 $(SED) 's/void \*yy_flex_realloc/inline void *yy_flex_realloc/' | \
772 $(SED) 's/#define YY_BUF_SIZE 16384/#define YY_BUF_SIZE (16384*64)/' \
774 $(VERB) cmp -s $@ $@.tmp > /dev/null || ${MV} -f $@.tmp $@
775 @# remove the output of flex if it didn't get moved over...
778 # Rule for building the bison parsers...
779 %.c: %.y # Cancel built-in rules for yacc
780 %.h: %.y # Cancel built-in rules for yacc
782 @echo Bison\'ing $<...
783 $(VERB) $(BISON) -v -d -p $(<:%Parser.y=%) $*.y
784 $(VERB) cmp -s $*.tab.c $*.cpp > /dev/null || ${MV} -f $*.tab.c $*.cpp
785 $(VERB) cmp -s $*.tab.h $*.h > /dev/null || ${MV} -f $*.tab.h $*.h
786 @# If the files were not updated, don't leave them lying around...
787 @rm -f $*.tab.c $*.tab.h
789 # To create the directories...
791 $(VERB) ${MKDIR} $* > /dev/null
794 # To create postscript files from dot files...
797 ${DOT} -Tps < $< > $@
800 ${ECHO} "Cannot build $@: The program dot is not installed"
803 # 'make clean' nukes the tree
805 $(VERB) $(RM) -rf $(BUILD_OBJ_DIR)/Debug $(BUILD_OBJ_DIR)/Release
806 $(VERB) $(RM) -rf $(BUILD_OBJ_DIR)/Profile $(BUILD_OBJ_DIR)/Depend
807 $(VERB) $(RM) -rf $(BUILD_OBJ_DIR)/Bytecode
808 $(VERB) $(RM) -f core core.[0-9][0-9]* *.o *.d *.so *~ *.flc
809 $(VERB) $(RM) -f $(LEX_OUTPUT) $(YACC_OUTPUT)
811 ###########################################################################
813 # Define variables and rules that generate header file dependencies
814 # from C/C++ source files.
815 ###########################################################################
817 # If dependencies were generated for the file that included this file,
818 # include the dependancies now...
820 SourceBaseNames := $(basename $(notdir $(filter-out Debug/%, $(Source))))
821 SourceDepend := $(SourceBaseNames:%=$(BUILD_OBJ_DIR)/Depend/%.d)
823 # Create dependencies for the *.cpp files...
825 $(BUILD_OBJ_DIR)/Depend/%.d: $(SourceDir)%.cpp $(BUILD_OBJ_DIR)/Depend/.dir
826 $(VERB) $(Depend) $< | $(SED) 's|\.o|\.lo|' | $(SED) 's|$*\.lo *|$(BUILD_OBJ_DIR)/Release/& $(BUILD_OBJ_DIR)/Profile/& $(BUILD_OBJ_DIR)/Debug/& $(BUILD_OBJ_DIR)/Depend/$(@F)|g' > $@
828 # Create dependencies for the *.c files...
830 $(BUILD_OBJ_DIR)/Depend/%.d: $(SourceDir)%.c $(BUILD_OBJ_DIR)/Depend/.dir
831 $(VERB) $(DependC) -o $@ $< | $(SED) 's|\.o|\.lo|' | $(SED) 's|$*\.lo *|$(BUILD_OBJ_DIR)/Release/& $(BUILD_OBJ_DIR)/Profile/& $(BUILD_OBJ_DIR)/Debug/& $(BUILD_OBJ_DIR)/Depend/$(@F)|g' > $@
834 # Include dependencies generated from C/C++ source files, but not if we
835 # are cleaning (this example taken from the GNU Make Manual).
837 ifneq ($(MAKECMDGOALS),clean)
838 ifneq ($(MAKECMDGOALS),distclean)
839 ifneq ($(MAKECMDGOALS),cleandeps)
840 ifneq ($(SourceDepend),)
841 -include $(SourceDepend)
848 $(VERB) rm -f $(SourceDepend)