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 dependency info.
5 # These are platform dependent, so this is the file used to specify these
6 # system dependent 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 # 8. BUILD_SRC_DIR - The directory which contains the current set of Makefiles
36 # and usually the source code too (unless SourceDir is set).
38 # 9. BUILD_SRC_ROOT - The root directory of the source code being compiled.
40 # 10. BUILD_OBJ_DIR - The directory where object code should be placed.
42 # 11. BUILD_OBJ_ROOT - The root directory for where object code should be
46 # LLVM, LLVM_SRC_ROOT = BUILD_SRC_ROOT
48 #===-----------------------------------------------------------------------====
51 # Configuration file to set paths specific to local installation of LLVM
54 include $(LLVM_SRC_ROOT)/Makefile.config
56 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 object directory.
123 LLVM_OBJ_ROOT := $(shell cd $(BUILD_OBJ_DIR); cd $(LLVM_SRC_ROOT); pwd)
125 LLVM_OBJ_ROOT := $(shell cd $(BUILD_OBJ_ROOT); pwd)
130 # Set the LLVM source directory.
131 # It is typically the root directory of what we're compiling now.
134 LLVM_SRC_ROOT := $(BUILD_SRC_ROOT)
137 ###########################################################################
139 # The following targets are the standard top level targets for
141 ###########################################################################
144 # if SHARED_LIBRARY is specified, the default is to build the dynamic lib
148 ifdef BYTECODE_LIBRARY
149 # if BYTECODE_LIBRARY is specified, the default is to build the bytecode lib
151 install:: bytecodelib-install
154 # Default Rule: Make sure it's also a :: rule
157 # Default for install is to at least build everything...
160 # Default rule for test. It ensures everything has a test rule
163 # Default rule for building only bytecode.
166 # Print out the directories used for building
168 @echo "Home Offset : " $(HOME_OBJ_ROOT)
169 @echo "Build Source Root: " $(BUILD_SRC_ROOT)
170 @echo "Build Source Dir : " $(BUILD_SRC_DIR)
171 @echo "Build Object Root: " $(BUILD_OBJ_ROOT)
172 @echo "Build Object Dir : " $(BUILD_OBJ_DIR)
173 @echo "LLVM Source Root: " $(LLVM_SRC_ROOT)
174 @echo "LLVM Object Root: " $(LLVM_OBJ_ROOT)
176 ###########################################################################
177 # Suffixes and implicit rules:
178 # Empty out the list of suffixes, generate a list that is only
179 # used by this Makefile, and cancel useless implicit rules. This
180 # will hopefully speed up compilation a little bit.
181 ###########################################################################
183 .SUFFIXES: .c .cpp .h .hpp .y .l
184 .SUFFIXES: .lo .o .a .so .bc
185 .SUFFIXES: .ps .dot .d
188 # Mark all of these targets as phony. This will hopefully speed up builds
189 # slightly since GNU Make will not try to find implicit rules for targets
190 # which are marked as Phony.
192 .PHONY: all dynamic bytecodelib bytecodelib-install
193 .PHONY: clean distclean install test bytecode prdirs
195 ###########################################################################
196 # Miscellaneous paths and commands:
197 # This section defines various configuration macros, such as where
198 # to find burg, tblgen, and libtool.
199 ###########################################################################
201 #--------------------------------------------------------------------
202 # Variables derived from configuration options...
203 #--------------------------------------------------------------------
205 #BinInstDir=/usr/local/bin
206 #LibInstDir=/usr/local/lib/xxx
207 #DocInstDir=/usr/doc/xxx
211 ifdef ENABLE_PROFILING
213 CONFIGURATION := Profile
215 ifdef ENABLE_OPTIMIZED
216 CONFIGURATION := Release
218 CONFIGURATION := Debug
223 # Enable this for profiling support with 'gprof'
224 # This automatically enables optimized builds.
226 ifdef ENABLE_PROFILING
230 ###########################################################################
232 # These variables describe various library locations:
234 # DEST* = Location of where libraries that are built will be placed.
235 # LLVM* = Location of LLVM libraries used for linking.
236 # PROJ* = Location of previously built libraries used for linking.
237 ###########################################################################
239 # Libraries that are being built
240 DESTLIBDEBUG := $(BUILD_OBJ_ROOT)/lib/Debug
241 DESTLIBRELEASE := $(BUILD_OBJ_ROOT)/lib/Release
242 DESTLIBPROFILE := $(BUILD_OBJ_ROOT)/lib/Profile
243 DESTLIBBYTECODE := $(BUILD_OBJ_ROOT)/lib/Bytecode
244 DESTLIBCURRENT := $(BUILD_OBJ_ROOT)/lib/$(CONFIGURATION)
246 # LLVM libraries used for linking
247 LLVMLIBDEBUGSOURCE := $(LLVM_OBJ_ROOT)/lib/Debug
248 LLVMLIBRELEASESOURCE := $(LLVM_OBJ_ROOT)/lib/Release
249 LLVMLIBPROFILESOURCE := $(LLVM_OBJ_ROOT)/lib/Profile
250 LLVMLIBCURRENTSOURCE := $(LLVM_OBJ_ROOT)/lib/$(CONFIGURATION)
252 # Libraries that were built that will now be used for linking
253 PROJLIBDEBUGSOURCE := $(BUILD_OBJ_ROOT)/lib/Debug
254 PROJLIBRELEASESOURCE := $(BUILD_OBJ_ROOT)/lib/Release
255 PROJLIBPROFILESOURCE := $(BUILD_OBJ_ROOT)/lib/Profile
256 PROJLIBCURRENTSOURCE := $(BUILD_OBJ_ROOT)/lib/$(CONFIGURATION)
258 ###########################################################################
260 # These variables describe various tool locations:
262 # DEST* = Location of where tools that are built will be placed.
263 # LLVM* = Location of LLVM tools used for building.
264 # PROJ* = Location of previously built tools used for linking.
265 ###########################################################################
267 DESTTOOLDEBUG := $(BUILD_OBJ_ROOT)/tools/Debug
268 DESTTOOLRELEASE := $(BUILD_OBJ_ROOT)/tools/Release
269 DESTTOOLPROFILE := $(BUILD_OBJ_ROOT)/tools/Profile
270 DESTTOOLCURRENT := $(BUILD_OBJ_ROOT)/tools/$(CONFIGURATION)
272 LLVMTOOLDEBUG := $(LLVM_OBJ_ROOT)/tools/Debug
273 LLVMTOOLRELEASE := $(LLVM_OBJ_ROOT)/tools/Release
274 LLVMTOOLPROFILE := $(LLVM_OBJ_ROOT)/tools/Profile
275 LLVMTOOLCURRENT := $(LLVM_OBJ_ROOT)/tools/$(CONFIGURATION)
277 PROJTOOLDEBUG := $(BUILD_OBJ_ROOT)/tools/Debug
278 PROJTOOLRELEASE := $(BUILD_OBJ_ROOT)/tools/Release
279 PROJTOOLPROFILE := $(BUILD_OBJ_ROOT)/tools/Profile
280 PROJTOOLCURRENT := $(BUILD_OBJ_ROOT)/tools/$(CONFIGURATION)
283 # Libtool is found in the current directory.
285 LIBTOOL := $(LLVM_SRC_ROOT)/mklib
288 # If we're not building a shared library, use the disable-shared tag with
289 # libtool. This will disable the building of objects for shared libraries and
290 # only generate static library objects.
292 # For dynamic libraries, we'll take the performance hit for now, since we
293 # almost never build them.
295 # This should speed up compilation and require no modifications to future
296 # versions of libtool.
298 ifndef SHARED_LIBRARY
299 LIBTOOL += --tag=disable-shared
310 ###########################################################################
311 # Miscellaneous paths and commands (part deux):
312 # This section defines various configuration macros, such as where
313 # to find burg, tblgen, and libtool.
314 ###########################################################################
316 #--------------------------------------------------------------------------
317 # Utilities used while building the LLVM tree, which live in the utils dir
319 BURG := $(LLVMTOOLCURRENT)/burg
320 RunBurg := $(BURG) $(BURG_OPTS)
321 TBLGEN := $(LLVMTOOLCURRENT)/tblgen
323 #--------------------------------------------------------------------------
324 # The LLVM GCC front-end in C and C++ flavors
326 LLVMGCC := PATH=$(LLVMTOOLCURRENT):$(PATH) $(LLVMGCCDIR)/bin/gcc
327 LCC1 := $(LLVMGCCDIR)/libexec/gcc/$(LLVMGCCARCH)/cc1
328 LLVMGXX := PATH=$(LLVMTOOLCURRENT):$(PATH) $(LLVMGCCDIR)/bin/g++
329 LCC1XX := $(LLVMGCCDIR)/libexec/gcc/$(LLVMGCCARCH)/cc1plus
331 #--------------------------------------------------------------------------
332 # Some of the compiled LLVM tools which are used for compilation of runtime
335 LLVMAS := $(LLVMTOOLCURRENT)/llvm-as
338 ###########################################################################
340 ###########################################################################
343 # Include both the project headers and the LLVM headers for compilation and
344 # dependency computation.
346 CPPFLAGS += -I$(BUILD_SRC_ROOT)/include -I$(LLVM_SRC_ROOT)/include
348 # By default, strip symbol information from executable
350 STRIP = $(PLATFORMSTRIPOPTS)
351 STRIP_WARN_MSG = "(without symbols)"
354 # Allow gnu extensions...
355 CPPFLAGS += -D_GNU_SOURCE
357 CompileWarnings := -Wall -W -Wwrite-strings -Wno-unused
358 CompileCommonOpts := $(CompileWarnings) -I$(LEVEL)/include -fshort-enums
359 CompileOptimizeOpts := -O3 -DNDEBUG -finline-functions
362 # Compile commands with libtool.
364 Compile := $(LIBTOOL) --mode=compile $(CXX) -c $(CPPFLAGS) $(CXXFLAGS) $(CompileCommonOpts)
365 CompileC := $(LIBTOOL) --mode=compile $(CC) -c $(CPPFLAGS) $(CFLAGS) $(CompileCommonOpts)
367 # Compile a cpp file, don't link...
368 CompileG := $(Compile) -g -D_DEBUG
369 CompileO := $(Compile) $(CompileOptimizeOpts) -felide-constructors -fomit-frame-pointer
370 CompileP := $(Compile) $(CompileOptimizeOpts) -felide-constructors $(PROFILE)
372 # Compile a c file, don't link...
373 CompileCG := $(CompileC) -g -D_DEBUG
374 CompileCO := $(CompileC) $(CompileOptimizeOpts) -fomit-frame-pointer
375 CompileCP := $(CompileC) $(CompileOptimizeOpts) $(PROFILE)
377 ###########################################################################
379 ###########################################################################
382 # Link final executable
383 # (Note that we always link with the C++ compiler).
385 Link := $(LIBTOOL) --mode=link $(CXX)
387 # link both projlib and llvmlib libraries
388 LinkG := $(Link) -g -L$(PROJLIBDEBUGSOURCE) -L$(LLVMLIBDEBUGSOURCE) $(STRIP)
389 LinkO := $(Link) -O3 -L$(PROJLIBRELEASESOURCE) -L$(LLVMLIBRELEASESOURCE)
390 LinkP := $(Link) -O3 -L$(PROJLIBPROFILESOURCE) -L$(LLVMLIBPROFILESOURCE) $(PROFILE)
392 # Create one .o file from a bunch of .o files...
393 Relink := ${LIBTOOL} --mode=link $(CXX)
396 # Configure where the item being compiled should go.
399 Link += -rpath $(DESTLIBCURRENT)
403 Link += -rpath $(DESTTOOLCURRENT)
406 # Create dependency file from CPP file, send to stdout.
407 Depend := $(CXX) -MM -I$(LEVEL)/include $(CPPFLAGS)
408 DependC := $(CC) -MM -I$(LEVEL)/include $(CPPFLAGS)
410 # Archive a bunch of .o files into a .a file...
413 #----------------------------------------------------------
415 # Source includes all of the cpp files, and objects are derived from the
417 # The local Makefile can list other Source files via ExtraSource = ...
420 Source := $(ExtraSource) $(wildcard *.cpp *.c *.y *.l)
426 Srcs := $(sort $(notdir $(basename $(Source))))
427 Objs := $(addsuffix .lo, $(Srcs))
428 ObjectsO := $(addprefix $(BUILD_OBJ_DIR)/Release/,$(Objs))
429 ObjectsP := $(addprefix $(BUILD_OBJ_DIR)/Profile/,$(Objs))
430 ObjectsG := $(addprefix $(BUILD_OBJ_DIR)/Debug/,$(Objs))
431 ObjectsBC := $(addprefix $(BUILD_OBJ_DIR)/Bytecode/,$(addsuffix .bc, $(Srcs)))
434 # The real objects underlying the libtool objects
436 RObjs := $(sort $(patsubst Debug/%.o, %.o, $(addsuffix .o,$(notdir $(basename $(Source))))))
437 RObjectsO := $(addprefix $(BUILD_OBJ_DIR)/Release/,$(RObjs))
438 RObjectsP := $(addprefix $(BUILD_OBJ_DIR)/Profile/,$(RObjs))
439 RObjectsG := $(addprefix $(BUILD_OBJ_DIR)/Debug/,$(RObjs))
441 #---------------------------------------------------------
442 # Handle the DIRS and PARALLEL_DIRS options
443 #---------------------------------------------------------
446 all install clean test bytecode ::
447 $(VERB) for dir in ${DIRS}; do \
448 (cd $$dir; $(MAKE) $@) || exit 1; \
452 # Handle PARALLEL_DIRS
454 all :: $(addsuffix /.makeall , $(PARALLEL_DIRS))
455 install :: $(addsuffix /.makeinstall , $(PARALLEL_DIRS))
456 clean :: $(addsuffix /.makeclean , $(PARALLEL_DIRS))
457 test :: $(addsuffix /.maketest , $(PARALLEL_DIRS))
458 bytecode :: $(addsuffix /.makebytecode, $(PARALLEL_DIRS))
460 %/.makeall %/.makeinstall %/.makeclean %/.maketest %/.makebytecode:
461 $(VERB) cd $(@D); $(MAKE) $(subst $(@D)/.make,,$@)
464 # Handle directories that may or may not exist
466 all install clean test bytecode ::
467 $(VERB) for dir in ${OPTIONAL_DIRS}; do \
470 (cd $$dir; $(MAKE) $@) || exit 1; \
475 ###########################################################################
476 # Library Build Rules:
478 #---------------------------------------------------------
479 # Handle the LIBRARYNAME option - used when building libs...
480 #---------------------------------------------------------
482 # When libraries are built, they are allowed to optionally define the
483 # DONT_BUILD_RELINKED make variable, which, when defined, prevents a .o file
484 # from being built for the library. This .o files may then be linked to by a
485 # tool if the tool does not need (or want) the semantics a .a file provides
486 # (linking in only object files that are "needed"). If a library is never to
487 # be used in this way, it is better to define DONT_BUILD_RELINKED, and define
488 # BUILD_ARCHIVE instead.
490 # Some libraries must be built as .a files (libscalar for example) because if
491 # it's built as a .o file, then all of the constituent .o files in it will be
492 # linked into tools (for example gccas) even if they only use one of the parts
493 # of it. For this reason, sometimes it's useful to use libraries as .a files.
494 ###########################################################################
498 # Make sure there isn't any extranous whitespace on the LIBRARYNAME option
499 LIBRARYNAME := $(strip $(LIBRARYNAME))
501 LIBNAME_O := $(DESTLIBRELEASE)/lib$(LIBRARYNAME).so
502 LIBNAME_P := $(DESTLIBPROFILE)/lib$(LIBRARYNAME).so
503 LIBNAME_G := $(DESTLIBDEBUG)/lib$(LIBRARYNAME).so
504 LIBNAME_AO := $(DESTLIBRELEASE)/lib$(LIBRARYNAME).a
505 LIBNAME_AP := $(DESTLIBPROFILE)/lib$(LIBRARYNAME).a
506 LIBNAME_AG := $(DESTLIBDEBUG)/lib$(LIBRARYNAME).a
507 LIBNAME_OBJO := $(DESTLIBRELEASE)/$(LIBRARYNAME).o
508 LIBNAME_OBJP := $(DESTLIBPROFILE)/$(LIBRARYNAME).o
509 LIBNAME_OBJG := $(DESTLIBDEBUG)/$(LIBRARYNAME).o
510 LIBNAME_BC := $(DESTLIBBYTECODE)/lib$(LIBRARYNAME).bc
512 #--------------------------------------------------------------------
514 # Modify the top level targets to build the desired libraries.
515 #--------------------------------------------------------------------
517 # dynamic target builds a shared object version of the library...
518 dynamic:: $(DESTLIBCURRENT)/lib$(LIBRARYNAME).so
519 bytecodelib:: $(LIBNAME_BC)
520 bytecodelib-install:: $(LLVMGCCDIR)/bytecode-libs/lib$(LIBRARYNAME).bc
522 $(LLVMGCCDIR)/bytecode-libs/lib$(LIBRARYNAME).bc: $(LIBNAME_BC)
523 @echo ======= Installing $(LIBRARYNAME) bytecode library =======
526 # Does the library want a .o version built?
527 ifndef DONT_BUILD_RELINKED
528 all:: $(DESTLIBCURRENT)/$(LIBRARYNAME).o
531 # Does the library want an archive version built?
533 all:: $(DESTLIBCURRENT)/lib$(LIBRARYNAME).a
536 #--------------------------------------------------------------------
537 # Rules for building libraries
538 #--------------------------------------------------------------------
540 LinkBCLib := $(LLVMGCC) -shared
541 ifdef EXPORTED_SYMBOL_LIST
542 LinkBCLib += -Xlinker -internalize-public-api-list=$(EXPORTED_SYMBOL_LIST)
544 LinkBCLib += -Xlinker -disable-internalize
548 # Rule for building bytecode libraries.
549 $(LIBNAME_BC): $(ObjectsBC) $(LibSubDirs) $(DESTLIBBYTECODE)/.dir
550 @echo ======= Linking $(LIBRARYNAME) bytecode library =======
551 $(VERB) $(LinkBCLib) -o $@ $(ObjectsBC) $(LibSubDirs) $(LibLinkOpts)
553 # Rules for building dynamically linked libraries.
555 $(LIBNAME_O): $(ObjectsO) $(LibSubDirs) $(DESTLIBRELEASE)/.dir
556 @echo ======= Linking $(LIBRARYNAME) dynamic release library =======
557 $(VERB) $(Link) -o $*.la $(ObjectsO) $(LibSubDirs) $(LibLinkOpts)
558 $(VERB) $(LIBTOOL) --mode=install $(INSTALL) $*.la $(DESTLIBCURRENT)
560 $(LIBNAME_P): $(ObjectsP) $(LibSubDirs) $(DESTLIBPROFILE)/.dir
561 @echo ======= Linking $(LIBRARYNAME) dynamic profile library =======
562 $(VERB) $(Link) -o $*.la $(ObjectsP) $(LibSubDirs) $(LibLinkOpts)
563 $(VERB) $(LIBTOOL) --mode=install $(INSTALL) $*.la $(DESTLIBCURRENT)
565 $(LIBNAME_G): $(ObjectsG) $(LibSubDirs) $(DESTLIBDEBUG)/.dir
566 @echo ======= Linking $(LIBRARYNAME) dynamic debug library =======
567 $(VERB) $(Link) -o $*.la $(ObjectsG) $(LibSubDirs) $(LibLinkOpts)
568 $(VERB) $(LIBTOOL) --mode=install $(INSTALL) $*.la $(DESTLIBCURRENT)
571 # Rules for building static archive libraries.
573 $(LIBNAME_AO): $(ObjectsO) $(LibSubDirs) $(DESTLIBRELEASE)/.dir
574 @echo ======= Linking $(LIBRARYNAME) archive release library =======
576 $(VERB) $(Link) -03 -o $@ $(ObjectsO) $(LibSubDirs) -static
578 $(LIBNAME_AP): $(ObjectsP) $(LibSubDirs) $(DESTLIBPROFILE)/.dir
579 @echo ======= Linking $(LIBRARYNAME) archive profile library =======
581 $(VERB) $(Link) -03 $(PROFILE) -o $@ $(ObjectsP) $(LibSubDirs) -static
583 $(LIBNAME_AG): $(ObjectsG) $(LibSubDirs) $(DESTLIBDEBUG)/.dir
584 @echo ======= Linking $(LIBRARYNAME) archive debug library =======
586 $(VERB) $(Link) -g $(STRIP) -o $@ $(ObjectsG) $(LibSubDirs) -static
590 # Rules for building .o libraries.
593 # Note that for this special case, we specify the actual object files
594 # instead of their libtool counterparts. This is because libtool
595 # doesn't want to generate a reloadable object file unless it is given
596 # .o files explicitly.
598 # Note that we're making an assumption here: If we build a .lo file,
599 # it's corresponding .o file will be placed in the same directory.
601 # I think that is safe.
603 $(LIBNAME_OBJO): $(ObjectsO) $(LibSubDirs) $(DESTLIBRELEASE)/.dir
605 $(VERB) $(Relink) -o $@ $(RObjectsO) $(LibSubDirs)
607 $(LIBNAME_OBJP): $(ObjectsP) $(LibSubDirs) $(DESTLIBPROFILE)/.dir
609 $(VERB) $(Relink) -o $@ $(RObjectsP) $(LibSubDirs)
611 $(LIBNAME_OBJG): $(ObjectsG) $(LibSubDirs) $(DESTLIBDEBUG)/.dir
613 $(VERB) $(Relink) -o $@ $(RObjectsG) $(LibSubDirs)
617 #------------------------------------------------------------------------
618 # Create a TAGS database for emacs
619 #------------------------------------------------------------------------
623 SRCDIRS := $(wildcard include lib tools)
626 $(ETAGS) -l c++ `find $(SRCDIRS) -name '*.cpp' -o -name '*.h'`
631 ${ECHO} "Cannot build $@: The program etags is not installed"
634 #------------------------------------------------------------------------
635 # Handle the TOOLNAME option - used when building tool executables...
636 #------------------------------------------------------------------------
638 # The TOOLNAME option should be used with a USEDLIBS variable that tells the
639 # libraries (and the order of the libs) that should be linked to the
640 # tool. USEDLIBS should contain a list of library names (some with .a extension)
641 # that are automatically linked in as .o files unless the .a suffix is added.
645 # TOOLEXENAME* - These compute the output filenames to generate...
646 TOOLEXENAME_G := $(DESTTOOLDEBUG)/$(TOOLNAME)
647 TOOLEXENAME_O := $(DESTTOOLRELEASE)/$(TOOLNAME)
648 TOOLEXENAME_P := $(DESTTOOLPROFILE)/$(TOOLNAME)
649 TOOLEXENAMES := $(DESTTOOLCURRENT)/$(TOOLNAME)
651 # USED_LIBS_OPTIONS - Compute the options line that add -llib1 -llib2, etc.
652 PROJ_LIBS_OPTIONS := $(patsubst %.a.o, -l%, $(addsuffix .o, $(USEDLIBS)))
653 PROJ_LIBS_OPTIONS_G := $(patsubst %.o, $(PROJLIBDEBUGSOURCE)/%.o, $(PROJ_LIBS_OPTIONS))
654 PROJ_LIBS_OPTIONS_O := $(patsubst %.o, $(PROJLIBRELEASESOURCE)/%.o,$(PROJ_LIBS_OPTIONS))
655 PROJ_LIBS_OPTIONS_P := $(patsubst %.o, $(PROJLIBPROFILESOURCE)/%.o,$(PROJ_LIBS_OPTIONS))
657 LLVM_LIBS_OPTIONS := $(patsubst %.a.o, -l%, $(addsuffix .o, $(LLVMLIBS)))
658 LLVM_LIBS_OPTIONS_G := $(patsubst %.o, $(LLVMLIBDEBUGSOURCE)/%.o, $(LLVM_LIBS_OPTIONS))
659 LLVM_LIBS_OPTIONS_O := $(patsubst %.o, $(LLVMLIBRELEASESOURCE)/%.o,$(LLVM_LIBS_OPTIONS))
660 LLVM_LIBS_OPTIONS_P := $(patsubst %.o, $(LLVMLIBPROFILESOURCE)/%.o,$(LLVM_LIBS_OPTIONS))
662 LIB_OPTS_G := $(LLVM_LIBS_OPTIONS_G) $(PROJ_LIBS_OPTIONS_G)
663 LIB_OPTS_O := $(LLVM_LIBS_OPTIONS_O) $(PROJ_LIBS_OPTIONS_O)
664 LIB_OPTS_P := $(LLVM_LIBS_OPTIONS_P) $(PROJ_LIBS_OPTIONS_P)
666 # USED_LIB_PATHS - Compute the path of the libraries used so that tools are
667 # rebuilt if libraries change. This has to make sure to handle .a/.so and .o
670 STATICUSEDLIBS := $(patsubst %.a.o, lib%.a, $(addsuffix .o, $(USEDLIBS)))
671 USED_LIB_PATHS_G := $(addprefix $(DESTLIBDEBUG)/, $(STATICUSEDLIBS))
672 USED_LIB_PATHS_O := $(addprefix $(DESTLIBRELEASE)/, $(STATICUSEDLIBS))
673 USED_LIB_PATHS_P := $(addprefix $(DESTLIBPROFILE)/, $(STATICUSEDLIBS))
676 # Libtool link options:
677 # Ensure that all binaries have their symbols exported so that they can
680 LINK_OPTS := -export-dynamic $(TOOLLINKOPTS)
686 # Tell make that we need to rebuild subdirectories before we can link the tool.
687 # This affects things like LLI which has library subdirectories.
688 $(USED_LIB_PATHS_G) $(USED_LIB_PATHS_O) $(USED_LIB_PATHS_P): \
689 $(addsuffix /.makeall, $(PARALLEL_DIRS))
691 all:: $(TOOLEXENAMES)
694 $(VERB) $(RM) -f $(TOOLEXENAMES)
696 $(TOOLEXENAME_G): $(ObjectsG) $(USED_LIB_PATHS_G) $(DESTTOOLDEBUG)/.dir
697 @echo ======= Linking $(TOOLNAME) debug executable $(STRIP_WARN_MSG) =======
698 $(VERB) $(LinkG) -o $@ $(ObjectsG) $(LIB_OPTS_G) $(LINK_OPTS) $(LIBS)
700 $(TOOLEXENAME_O): $(ObjectsO) $(USED_LIB_PATHS_O) $(DESTTOOLRELEASE)/.dir
701 @echo ======= Linking $(TOOLNAME) release executable =======
702 $(VERB) $(LinkO) -o $@ $(ObjectsO) $(LIB_OPTS_O) $(LINK_OPTS) $(LIBS)
704 $(TOOLEXENAME_P): $(ObjectsP) $(USED_LIB_PATHS_P) $(DESTTOOLPROFILE)/.dir
705 @echo ======= Linking $(TOOLNAME) profile executable =======
706 $(VERB) $(LinkP) -o $@ $(ObjectsP) $(LIB_OPTS_P) $(LINK_OPTS) $(LIBS)
712 #---------------------------------------------------------
713 .PRECIOUS: $(BUILD_OBJ_DIR)/Depend/.dir $(BUILD_OBJ_DIR)/Bytecode/.dir
714 .PRECIOUS: $(BUILD_OBJ_DIR)/Debug/.dir $(BUILD_OBJ_DIR)/Release/.dir
716 # Create .lo files in the ObjectFiles directory from the .cpp and .c files...
717 $(BUILD_OBJ_DIR)/Release/%.lo: $(SourceDir)%.cpp $(BUILD_OBJ_DIR)/Release/.dir
719 $(VERB) $(CompileO) $< -o $@
721 $(BUILD_OBJ_DIR)/Release/%.lo: $(SourceDir)%.c $(BUILD_OBJ_DIR)/Release/.dir
723 $(VERB) $(CompileCO) $< -o $@
725 $(BUILD_OBJ_DIR)/Profile/%.lo: $(SourceDir)%.cpp $(BUILD_OBJ_DIR)/Profile/.dir
727 $(VERB) $(CompileP) $< -o $@
729 $(BUILD_OBJ_DIR)/Profile/%.lo: $(SourceDir)%.c $(BUILD_OBJ_DIR)/Profile/.dir
731 $(VERB) $(CompileCP) $< -o $@
733 $(BUILD_OBJ_DIR)/Debug/%.lo: $(SourceDir)%.cpp $(BUILD_OBJ_DIR)/Debug/.dir
735 $(VERB) $(CompileG) $< -o $@
737 $(BUILD_OBJ_DIR)/Debug/%.lo: $(SourceDir)%.c $(BUILD_OBJ_DIR)/Debug/.dir
739 $(VERB) $(CompileCG) $< -o $@
741 $(BUILD_OBJ_DIR)/Bytecode/%.bc: $(SourceDir)%.cpp $(BUILD_OBJ_DIR)/Bytecode/.dir $(LCC1XX)
742 @echo "Compiling $< to bytecode"
743 $(VERB) $(LLVMGXX) $(CompileWarnings) $(CPPFLAGS) -c $< -o $@
745 $(BUILD_OBJ_DIR)/Bytecode/%.bc: $(SourceDir)%.c $(BUILD_OBJ_DIR)/Bytecode/.dir $(LCC1)
746 @echo "Compiling $< to bytecode"
747 $(VERB) $(LLVMGCC) $(CompileWarnings) $(CPPFLAGS) -c $< -o $@
749 $(BUILD_OBJ_DIR)/Bytecode/%.bc: $(SourceDir)%.ll $(BUILD_OBJ_DIR)/Bytecode/.dir $(LLVMAS)
750 @echo "Compiling $< to bytecode"
751 $(VERB) $(LLVMAS) $< -f -o $@
755 # Rules for building lex/yacc files
757 LEX_FILES = $(filter %.l, $(Source))
758 LEX_OUTPUT = $(LEX_FILES:%.l=%.cpp)
759 YACC_FILES = $(filter %.y, $(Source))
760 YACC_OUTPUT = $(addprefix $(YACC_FILES:%.y=%), .h .cpp .output)
761 .PRECIOUS: $(LEX_OUTPUT) $(YACC_OUTPUT)
763 # Create a .cpp source file from a flex input file... this uses sed to cut down
764 # on the warnings emited by GCC...
766 # The last line is a gross hack to work around flex aparently not being able to
767 # resize the buffer on a large token input. Currently, for uninitialized string
768 # buffers in LLVM we can generate very long tokens, so this is a hack around it.
769 # FIXME. (f.e. char Buffer[10000] )
772 @echo Flex\'ing $<...
773 $(VERB) $(FLEX) -t $< | \
774 $(SED) '/^find_rule/d' | \
775 $(SED) 's/void yyunput/inline void yyunput/' | \
776 $(SED) 's/void \*yy_flex_realloc/inline void *yy_flex_realloc/' | \
777 $(SED) 's/#define YY_BUF_SIZE 16384/#define YY_BUF_SIZE (16384*64)/' \
779 $(VERB) cmp -s $@ $@.tmp > /dev/null || ${MV} -f $@.tmp $@
780 @# remove the output of flex if it didn't get moved over...
783 # Rule for building the bison parsers...
784 %.c: %.y # Cancel built-in rules for yacc
785 %.h: %.y # Cancel built-in rules for yacc
787 @echo Bison\'ing $<...
788 $(VERB) $(BISON) -v -d -p $(<:%Parser.y=%) $*.y
789 $(VERB) cmp -s $*.tab.c $*.cpp > /dev/null || ${MV} -f $*.tab.c $*.cpp
790 $(VERB) cmp -s $*.tab.h $*.h > /dev/null || ${MV} -f $*.tab.h $*.h
791 @# If the files were not updated, don't leave them lying around...
792 @rm -f $*.tab.c $*.tab.h
794 # To create the directories...
796 $(VERB) ${MKDIR} $* > /dev/null
799 # To create postscript files from dot files...
802 ${DOT} -Tps < $< > $@
805 ${ECHO} "Cannot build $@: The program dot is not installed"
808 # 'make clean' nukes the tree
810 $(VERB) $(RM) -rf $(BUILD_OBJ_DIR)/Debug $(BUILD_OBJ_DIR)/Release
811 $(VERB) $(RM) -rf $(BUILD_OBJ_DIR)/Profile $(BUILD_OBJ_DIR)/Depend
812 $(VERB) $(RM) -rf $(BUILD_OBJ_DIR)/Bytecode
813 $(VERB) $(RM) -f core core.[0-9][0-9]* *.o *.d *.so *~ *.flc
814 $(VERB) $(RM) -f $(LEX_OUTPUT) $(YACC_OUTPUT)
816 ###########################################################################
818 # Define variables and rules that generate header file dependencies
819 # from C/C++ source files.
820 ###########################################################################
822 ifndef DISABLE_AUTO_DEPENDENCIES
824 # If dependencies were generated for the file that included this file,
825 # include the dependencies now...
827 SourceBaseNames := $(basename $(notdir $(filter-out Debug/%, $(Source))))
828 SourceDepend := $(SourceBaseNames:%=$(BUILD_OBJ_DIR)/Depend/%.d)
830 # Create dependencies for the *.cpp files...
831 $(BUILD_OBJ_DIR)/Depend/%.d: $(SourceDir)%.cpp $(BUILD_OBJ_DIR)/Depend/.dir
832 $(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' > $@
833 $(VERB) $(Depend) $< | $(SED) 's|$*.o: $*.cpp||' | $(SED) 's|[^\]$$|&::|' >> $@
835 # Create dependencies for the *.c files...
836 $(BUILD_OBJ_DIR)/Depend/%.d: $(SourceDir)%.c $(BUILD_OBJ_DIR)/Depend/.dir
837 $(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' > $@
838 $(VERB) $(Depend) $< | $(SED) 's|$*.o: $*.c||' | $(SED) 's|[^\]$$|&::|' >> $@
841 # Include dependencies generated from C/C++ source files, but not if we
842 # are cleaning (this example taken from the GNU Make Manual).
844 ifneq ($(MAKECMDGOALS),clean)
845 ifneq ($(MAKECMDGOALS),distclean)
846 -include /dev/null $(SourceDepend)
850 endif # ifndef DISABLE_AUTO_DEPENDENCIES