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 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)/libexec/gcc/$(LLVMGCCARCH)/cc1
324 LLVMGXX := PATH=$(LLVMTOOLCURRENT):$(PATH) $(LLVMGCCDIR)/bin/g++
325 LCC1XX := $(LLVMGCCDIR)/libexec/gcc/$(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 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 test :: $(addsuffix /.maketest , $(PARALLEL_DIRS))
453 bytecode :: $(addsuffix /.makebytecode, $(PARALLEL_DIRS))
455 %/.makeall %/.makeinstall %/.makeclean %/.maketest %/.makebytecode:
456 $(VERB) cd $(@D); $(MAKE) $(subst $(@D)/.make,,$@)
459 # Handle directories that may or may not exist
461 all install clean test bytecode ::
462 $(VERB) for dir in ${OPTIONAL_DIRS}; do \
465 (cd $$dir; $(MAKE) $@) || exit 1; \
470 ###########################################################################
471 # Library Build Rules:
473 #---------------------------------------------------------
474 # Handle the LIBRARYNAME option - used when building libs...
475 #---------------------------------------------------------
477 # When libraries are built, they are allowed to optionally define the
478 # DONT_BUILD_RELINKED make variable, which, when defined, prevents a .o file
479 # from being built for the library. This .o files may then be linked to by a
480 # tool if the tool does not need (or want) the semantics a .a file provides
481 # (linking in only object files that are "needed"). If a library is never to
482 # be used in this way, it is better to define DONT_BUILD_RELINKED, and define
483 # BUILD_ARCHIVE instead.
485 # Some libraries must be built as .a files (libscalar for example) because if
486 # it's built as a .o file, then all of the constituent .o files in it will be
487 # linked into tools (for example gccas) even if they only use one of the parts
488 # of it. For this reason, sometimes it's useful to use libraries as .a files.
489 ###########################################################################
493 # Make sure there isn't any extranous whitespace on the LIBRARYNAME option
494 LIBRARYNAME := $(strip $(LIBRARYNAME))
496 LIBNAME_O := $(DESTLIBRELEASE)/lib$(LIBRARYNAME).so
497 LIBNAME_P := $(DESTLIBPROFILE)/lib$(LIBRARYNAME).so
498 LIBNAME_G := $(DESTLIBDEBUG)/lib$(LIBRARYNAME).so
499 LIBNAME_AO := $(DESTLIBRELEASE)/lib$(LIBRARYNAME).a
500 LIBNAME_AP := $(DESTLIBPROFILE)/lib$(LIBRARYNAME).a
501 LIBNAME_AG := $(DESTLIBDEBUG)/lib$(LIBRARYNAME).a
502 LIBNAME_OBJO := $(DESTLIBRELEASE)/$(LIBRARYNAME).o
503 LIBNAME_OBJP := $(DESTLIBPROFILE)/$(LIBRARYNAME).o
504 LIBNAME_OBJG := $(DESTLIBDEBUG)/$(LIBRARYNAME).o
505 LIBNAME_BC := $(DESTLIBBYTECODE)/lib$(LIBRARYNAME).bc
507 #--------------------------------------------------------------------
509 # Modify the top level targets to build the desired libraries.
510 #--------------------------------------------------------------------
512 # dynamic target builds a shared object version of the library...
513 dynamic:: $(DESTLIBCURRENT)/lib$(LIBRARYNAME).so
514 bytecodelib:: $(LIBNAME_BC)
515 bytecodelib-install:: $(LLVMGCCDIR)/bytecode-libs/lib$(LIBRARYNAME).bc
517 $(LLVMGCCDIR)/bytecode-libs/lib$(LIBRARYNAME).bc: $(LIBNAME_BC)
518 @echo ======= Installing $(LIBRARYNAME) bytecode library =======
521 # Does the library want a .o version built?
522 ifndef DONT_BUILD_RELINKED
523 all:: $(DESTLIBCURRENT)/$(LIBRARYNAME).o
526 # Does the library want an archive version built?
528 all:: $(DESTLIBCURRENT)/lib$(LIBRARYNAME).a
531 #--------------------------------------------------------------------
532 # Rules for building libraries
533 #--------------------------------------------------------------------
535 LinkBCLib := $(LLVMGCC) -shared
536 ifdef EXPORTED_SYMBOL_LIST
537 LinkBCLib += -Xlinker -internalize-public-api-list=$(EXPORTED_SYMBOL_LIST)
539 LinkBCLib += -Xlinker -disable-internalize
543 # Rule for building bytecode libraries.
544 $(LIBNAME_BC): $(ObjectsBC) $(LibSubDirs) $(DESTLIBBYTECODE)/.dir
545 @echo ======= Linking $(LIBRARYNAME) bytecode library =======
546 $(VERB) $(LinkBCLib) -o $@ $(ObjectsBC) $(LibSubDirs) $(LibLinkOpts)
548 # Rules for building dynamically linked libraries.
550 $(LIBNAME_O): $(ObjectsO) $(LibSubDirs) $(DESTLIBRELEASE)/.dir
551 @echo ======= Linking $(LIBRARYNAME) dynamic release library =======
552 $(VERB) $(Link) -o $*.la $(ObjectsO) $(LibSubDirs) $(LibLinkOpts)
553 $(VERB) $(LIBTOOL) --mode=install $(INSTALL) $*.la $(DESTLIBCURRENT)
555 $(LIBNAME_P): $(ObjectsP) $(LibSubDirs) $(DESTLIBPROFILE)/.dir
556 @echo ======= Linking $(LIBRARYNAME) dynamic profile library =======
557 $(VERB) $(Link) -o $*.la $(ObjectsP) $(LibSubDirs) $(LibLinkOpts)
558 $(VERB) $(LIBTOOL) --mode=install $(INSTALL) $*.la $(DESTLIBCURRENT)
560 $(LIBNAME_G): $(ObjectsG) $(LibSubDirs) $(DESTLIBDEBUG)/.dir
561 @echo ======= Linking $(LIBRARYNAME) dynamic debug library =======
562 $(VERB) $(Link) -o $*.la $(ObjectsG) $(LibSubDirs) $(LibLinkOpts)
563 $(VERB) $(LIBTOOL) --mode=install $(INSTALL) $*.la $(DESTLIBCURRENT)
566 # Rules for building static archive libraries.
568 $(LIBNAME_AO): $(ObjectsO) $(LibSubDirs) $(DESTLIBRELEASE)/.dir
569 @echo ======= Linking $(LIBRARYNAME) archive release library =======
571 $(VERB) $(Link) -03 -o $@ $(ObjectsO) $(LibSubDirs) -static
573 $(LIBNAME_AP): $(ObjectsP) $(LibSubDirs) $(DESTLIBPROFILE)/.dir
574 @echo ======= Linking $(LIBRARYNAME) archive profile library =======
576 $(VERB) $(Link) -03 $(PROFILE) -o $@ $(ObjectsP) $(LibSubDirs) -static
578 $(LIBNAME_AG): $(ObjectsG) $(LibSubDirs) $(DESTLIBDEBUG)/.dir
579 @echo ======= Linking $(LIBRARYNAME) archive debug library =======
581 $(VERB) $(Link) -g $(STRIP) -o $@ $(ObjectsG) $(LibSubDirs) -static
585 # Rules for building .o libraries.
588 # Note that for this special case, we specify the actual object files
589 # instead of their libtool counterparts. This is because libtool
590 # doesn't want to generate a reloadable object file unless it is given
591 # .o files explicitly.
593 # Note that we're making an assumption here: If we build a .lo file,
594 # it's corresponding .o file will be placed in the same directory.
596 # I think that is safe.
598 $(LIBNAME_OBJO): $(ObjectsO) $(LibSubDirs) $(DESTLIBRELEASE)/.dir
600 $(VERB) $(Relink) -o $@ $(RObjectsO) $(LibSubDirs)
602 $(LIBNAME_OBJP): $(ObjectsP) $(LibSubDirs) $(DESTLIBPROFILE)/.dir
604 $(VERB) $(Relink) -o $@ $(RObjectsP) $(LibSubDirs)
606 $(LIBNAME_OBJG): $(ObjectsG) $(LibSubDirs) $(DESTLIBDEBUG)/.dir
608 $(VERB) $(Relink) -o $@ $(RObjectsG) $(LibSubDirs)
612 #------------------------------------------------------------------------
613 # Create a TAGS database for emacs
614 #------------------------------------------------------------------------
619 $(ETAGS) -l c++ `find include lib tools -name '*.cpp' -o -name '*.h'`
624 ${ECHO} "Cannot build $@: The program etags is not installed"
627 #------------------------------------------------------------------------
628 # Handle the TOOLNAME option - used when building tool executables...
629 #------------------------------------------------------------------------
631 # The TOOLNAME option should be used with a USEDLIBS variable that tells the
632 # libraries (and the order of the libs) that should be linked to the
633 # tool. USEDLIBS should contain a list of library names (some with .a extension)
634 # that are automatically linked in as .o files unless the .a suffix is added.
638 # TOOLEXENAME* - These compute the output filenames to generate...
639 TOOLEXENAME_G := $(DESTTOOLDEBUG)/$(TOOLNAME)
640 TOOLEXENAME_O := $(DESTTOOLRELEASE)/$(TOOLNAME)
641 TOOLEXENAME_P := $(DESTTOOLPROFILE)/$(TOOLNAME)
642 TOOLEXENAMES := $(DESTTOOLCURRENT)/$(TOOLNAME)
644 # USED_LIBS_OPTIONS - Compute the options line that add -llib1 -llib2, etc.
645 PROJ_LIBS_OPTIONS := $(patsubst %.a.o, -l%, $(addsuffix .o, $(USEDLIBS)))
646 PROJ_LIBS_OPTIONS_G := $(patsubst %.o, $(PROJLIBDEBUGSOURCE)/%.o, $(PROJ_LIBS_OPTIONS))
647 PROJ_LIBS_OPTIONS_O := $(patsubst %.o, $(PROJLIBRELEASESOURCE)/%.o,$(PROJ_LIBS_OPTIONS))
648 PROJ_LIBS_OPTIONS_P := $(patsubst %.o, $(PROJLIBPROFILESOURCE)/%.o,$(PROJ_LIBS_OPTIONS))
650 LLVM_LIBS_OPTIONS := $(patsubst %.a.o, -l%, $(addsuffix .o, $(LLVMLIBS)))
651 LLVM_LIBS_OPTIONS_G := $(patsubst %.o, $(LLVMLIBDEBUGSOURCE)/%.o, $(LLVM_LIBS_OPTIONS))
652 LLVM_LIBS_OPTIONS_O := $(patsubst %.o, $(LLVMLIBRELEASESOURCE)/%.o,$(LLVM_LIBS_OPTIONS))
653 LLVM_LIBS_OPTIONS_P := $(patsubst %.o, $(LLVMLIBPROFILESOURCE)/%.o,$(LLVM_LIBS_OPTIONS))
655 LIB_OPTS_G := $(LLVM_LIBS_OPTIONS_G) $(PROJ_LIBS_OPTIONS_G)
656 LIB_OPTS_O := $(LLVM_LIBS_OPTIONS_O) $(PROJ_LIBS_OPTIONS_O)
657 LIB_OPTS_P := $(LLVM_LIBS_OPTIONS_P) $(PROJ_LIBS_OPTIONS_P)
659 # USED_LIB_PATHS - Compute the path of the libraries used so that tools are
660 # rebuilt if libraries change. This has to make sure to handle .a/.so and .o
663 STATICUSEDLIBS := $(patsubst %.a.o, lib%.a, $(addsuffix .o, $(USEDLIBS)))
664 USED_LIB_PATHS_G := $(addprefix $(DESTLIBDEBUG)/, $(STATICUSEDLIBS))
665 USED_LIB_PATHS_O := $(addprefix $(DESTLIBRELEASE)/, $(STATICUSEDLIBS))
666 USED_LIB_PATHS_P := $(addprefix $(DESTLIBPROFILE)/, $(STATICUSEDLIBS))
669 # Libtool link options:
670 # Ensure that all binaries have their symbols exported so that they can
673 LINK_OPTS := -export-dynamic $(TOOLLINKOPTS)
679 # Tell make that we need to rebuild subdirectories before we can link the tool.
680 # This affects things like LLI which has library subdirectories.
681 $(USED_LIB_PATHS_G) $(USED_LIB_PATHS_O) $(USED_LIB_PATHS_P): \
682 $(addsuffix /.makeall, $(PARALLEL_DIRS))
684 all:: $(TOOLEXENAMES)
687 $(VERB) $(RM) -f $(TOOLEXENAMES)
689 $(TOOLEXENAME_G): $(ObjectsG) $(USED_LIB_PATHS_G) $(DESTTOOLDEBUG)/.dir
690 @echo ======= Linking $(TOOLNAME) debug executable $(STRIP_WARN_MSG) =======
691 $(VERB) $(LinkG) -o $@ $(ObjectsG) $(LIB_OPTS_G) $(LINK_OPTS) $(LIBS)
693 $(TOOLEXENAME_O): $(ObjectsO) $(USED_LIB_PATHS_O) $(DESTTOOLRELEASE)/.dir
694 @echo ======= Linking $(TOOLNAME) release executable =======
695 $(VERB) $(LinkO) -o $@ $(ObjectsO) $(LIB_OPTS_O) $(LINK_OPTS) $(LIBS)
697 $(TOOLEXENAME_P): $(ObjectsP) $(USED_LIB_PATHS_P) $(DESTTOOLPROFILE)/.dir
698 @echo ======= Linking $(TOOLNAME) profile executable =======
699 $(VERB) $(LinkP) -o $@ $(ObjectsP) $(LIB_OPTS_P) $(LINK_OPTS) $(LIBS)
705 #---------------------------------------------------------
706 .PRECIOUS: $(BUILD_OBJ_DIR)/Depend/.dir $(BUILD_OBJ_DIR)/Bytecode/.dir
707 .PRECIOUS: $(BUILD_OBJ_DIR)/Debug/.dir $(BUILD_OBJ_DIR)/Release/.dir
709 # Create .lo files in the ObjectFiles directory from the .cpp and .c files...
710 $(BUILD_OBJ_DIR)/Release/%.lo: $(SourceDir)%.cpp $(BUILD_OBJ_DIR)/Release/.dir
712 $(VERB) $(CompileO) $< -o $@
714 $(BUILD_OBJ_DIR)/Release/%.lo: $(SourceDir)%.c $(BUILD_OBJ_DIR)/Release/.dir
716 $(VERB) $(CompileCO) $< -o $@
718 $(BUILD_OBJ_DIR)/Profile/%.lo: $(SourceDir)%.cpp $(BUILD_OBJ_DIR)/Profile/.dir
720 $(VERB) $(CompileP) $< -o $@
722 $(BUILD_OBJ_DIR)/Profile/%.lo: $(SourceDir)%.c $(BUILD_OBJ_DIR)/Profile/.dir
724 $(VERB) $(CompileCP) $< -o $@
726 $(BUILD_OBJ_DIR)/Debug/%.lo: $(SourceDir)%.cpp $(BUILD_OBJ_DIR)/Debug/.dir
728 $(VERB) $(CompileG) $< -o $@
730 $(BUILD_OBJ_DIR)/Debug/%.lo: $(SourceDir)%.c $(BUILD_OBJ_DIR)/Debug/.dir
732 $(VERB) $(CompileCG) $< -o $@
734 $(BUILD_OBJ_DIR)/Bytecode/%.bc: $(SourceDir)%.cpp $(BUILD_OBJ_DIR)/Bytecode/.dir $(LCC1XX)
735 @echo "Compiling $< to bytecode"
736 $(VERB) $(LLVMGXX) $(CPPFLAGS) -c $< -o $@
738 $(BUILD_OBJ_DIR)/Bytecode/%.bc: $(SourceDir)%.c $(BUILD_OBJ_DIR)/Bytecode/.dir $(LCC1)
739 @echo "Compiling $< to bytecode"
740 $(VERB) $(LLVMGCC) $(CPPFLAGS) -c $< -o $@
742 $(BUILD_OBJ_DIR)/Bytecode/%.bc: $(SourceDir)%.ll $(BUILD_OBJ_DIR)/Bytecode/.dir $(LLVMAS)
743 @echo "Compiling $< to bytecode"
744 $(VERB) $(LLVMAS) $< -f -o $@
748 # Rules for building lex/yacc files
750 LEX_FILES = $(filter %.l, $(Source))
751 LEX_OUTPUT = $(LEX_FILES:%.l=%.cpp)
752 YACC_FILES = $(filter %.y, $(Source))
753 YACC_OUTPUT = $(addprefix $(YACC_FILES:%.y=%), .h .cpp .output)
754 .PRECIOUS: $(LEX_OUTPUT) $(YACC_OUTPUT)
756 # Create a .cpp source file from a flex input file... this uses sed to cut down
757 # on the warnings emited by GCC...
759 # The last line is a gross hack to work around flex aparently not being able to
760 # resize the buffer on a large token input. Currently, for uninitialized string
761 # buffers in LLVM we can generate very long tokens, so this is a hack around it.
762 # FIXME. (f.e. char Buffer[10000] )
765 @echo Flex\'ing $<...
766 $(VERB) $(FLEX) -t $< | \
767 $(SED) '/^find_rule/d' | \
768 $(SED) 's/void yyunput/inline void yyunput/' | \
769 $(SED) 's/void \*yy_flex_realloc/inline void *yy_flex_realloc/' | \
770 $(SED) 's/#define YY_BUF_SIZE 16384/#define YY_BUF_SIZE (16384*64)/' \
772 $(VERB) cmp -s $@ $@.tmp > /dev/null || ${MV} -f $@.tmp $@
773 @# remove the output of flex if it didn't get moved over...
776 # Rule for building the bison parsers...
777 %.c: %.y # Cancel built-in rules for yacc
778 %.h: %.y # Cancel built-in rules for yacc
780 @echo Bison\'ing $<...
781 $(VERB) $(BISON) -v -d -p $(<:%Parser.y=%) $*.y
782 $(VERB) cmp -s $*.tab.c $*.cpp > /dev/null || ${MV} -f $*.tab.c $*.cpp
783 $(VERB) cmp -s $*.tab.h $*.h > /dev/null || ${MV} -f $*.tab.h $*.h
784 @# If the files were not updated, don't leave them lying around...
785 @rm -f $*.tab.c $*.tab.h
787 # To create the directories...
789 $(VERB) ${MKDIR} $* > /dev/null
792 # To create postscript files from dot files...
795 ${DOT} -Tps < $< > $@
798 ${ECHO} "Cannot build $@: The program dot is not installed"
801 # 'make clean' nukes the tree
803 $(VERB) $(RM) -rf $(BUILD_OBJ_DIR)/Debug $(BUILD_OBJ_DIR)/Release
804 $(VERB) $(RM) -rf $(BUILD_OBJ_DIR)/Profile $(BUILD_OBJ_DIR)/Depend
805 $(VERB) $(RM) -rf $(BUILD_OBJ_DIR)/Bytecode
806 $(VERB) $(RM) -f core core.[0-9][0-9]* *.o *.d *.so *~ *.flc
807 $(VERB) $(RM) -f $(LEX_OUTPUT) $(YACC_OUTPUT)
809 ###########################################################################
811 # Define variables and rules that generate header file dependencies
812 # from C/C++ source files.
813 ###########################################################################
815 # If dependencies were generated for the file that included this file,
816 # include the dependancies now...
818 SourceBaseNames := $(basename $(notdir $(filter-out Debug/%, $(Source))))
819 SourceDepend := $(SourceBaseNames:%=$(BUILD_OBJ_DIR)/Depend/%.d)
821 # Create dependencies for the *.cpp files...
822 $(BUILD_OBJ_DIR)/Depend/%.d: $(SourceDir)%.cpp $(BUILD_OBJ_DIR)/Depend/.dir
823 $(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' > $@
824 $(VERB) $(Depend) $< | $(SED) 's|$*.o: $*.cpp||' | $(SED) 's|[^\]$$|&::|' >> $@
826 # Create dependencies for the *.c files...
827 $(BUILD_OBJ_DIR)/Depend/%.d: $(SourceDir)%.c $(BUILD_OBJ_DIR)/Depend/.dir
828 $(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' > $@
829 $(VERB) $(Depend) $< | $(SED) 's|$*.o: $*.c||' | $(SED) 's|[^\]$$|&::|' >> $@
832 # Include dependencies generated from C/C++ source files, but not if we
833 # are cleaning (this example taken from the GNU Make Manual).
835 ifneq ($(MAKECMDGOALS),clean)
836 ifneq ($(MAKECMDGOALS),distclean)
837 ifneq ($(SourceDepend),)
838 -include $(SourceDepend)
844 $(VERB) rm -f $(SourceDepend)