1 #===-- Makefile.rules - Common make rules for LLVM ---------*- Makefile -*--===#
3 # The LLVM Compiler Infrastructure
5 # This file was developed by the LLVM research group and is distributed under
6 # the University of Illinois Open Source License. See LICENSE.TXT for details.
8 #===------------------------------------------------------------------------===#
10 # This file is included by all of the LLVM makefiles. This file defines common
11 # rules to do things like compile a .cpp file or generate dependency info.
12 # These are platform dependent, so this is the file used to specify these
13 # system dependent operations.
15 # The following functionality can be set by setting incoming variables.
16 # The variable $(LEVEL) *must* be set:
18 # 1. LEVEL - The level of the current subdirectory from the top of the
19 # MagicStats view. This level should be expressed as a path, for
20 # example, ../.. for two levels deep.
22 # 2. DIRS - A list of subdirectories to be built. Fake targets are set up
23 # so that each of the targets "all", "install", and "clean" each build
24 # the subdirectories before the local target. DIRS are guaranteed to be
27 # 3. PARALLEL_DIRS - A list of subdirectories to be built, but that may be
28 # built in any order. All DIRS are built in order before PARALLEL_DIRS are
29 # built, which are then built in any order.
31 # 4. Source - If specified, this sets the source code filenames. If this
32 # is not set, it defaults to be all of the .cpp, .c, .y, and .l files
33 # in the current directory. Also, if you want to build files in addition
34 # to the local files, you can use the ExtraSource variable
36 # 5. SourceDir - If specified, this specifies a directory that the source files
37 # are in, if they are not in the current directory. This should include a
38 # trailing / character.
40 # 6. LLVM_SRC_ROOT - If specified, points to the top of the LLVM source tree.
42 # 8. BUILD_SRC_DIR - The directory which contains the current set of Makefiles
43 # and usually the source code too (unless SourceDir is set).
45 # 9. BUILD_SRC_ROOT - The root directory of the source code being compiled.
47 # 10. BUILD_OBJ_DIR - The directory where object code should be placed.
49 # 11. BUILD_OBJ_ROOT - The root directory for where object code should be
53 # LLVM, LLVM_SRC_ROOT = BUILD_SRC_ROOT
55 #===-----------------------------------------------------------------------====
58 # Set the VPATH so that we can find source files.
62 ###########################################################################
64 # The following targets are the standard top level targets for
66 ###########################################################################
68 # Ensure people re-run configure when it gets updated
69 all::$(LLVM_OBJ_ROOT)/config.status
72 # if SHARED_LIBRARY is specified, the default is to build the dynamic lib
74 install:: install-dynamic-library
77 ifdef BYTECODE_LIBRARY
78 # if BYTECODE_LIBRARY is specified, the default is to build the bytecode lib
80 install:: install-bytecode-library
81 install-bytecode:: install-bytecode-library
84 # Default Rule: Make sure it's also a :: rule
87 # Default for install is to at least build everything...
90 # Default rule for test. It ensures everything has a test rule
93 # Default rule for building only bytecode.
96 # Default rule for installing only bytecode.
99 # Print out the directories used for building
101 @${ECHO} "Build Source Root: " $(BUILD_SRC_ROOT)
102 @${ECHO} "Build Source Dir : " $(BUILD_SRC_DIR)
103 @${ECHO} "Build Object Root: " $(BUILD_OBJ_ROOT)
104 @${ECHO} "Build Object Dir : " $(BUILD_OBJ_DIR)
105 @${ECHO} "LLVM Source Root: " $(LLVM_SRC_ROOT)
106 @${ECHO} "LLVM Object Root: " $(LLVM_OBJ_ROOT)
108 ###########################################################################
109 # Suffixes and implicit rules:
110 # Empty out the list of suffixes, generate a list that is only
111 # used by this Makefile, and cancel useless implicit rules. This
112 # will hopefully speed up compilation a little bit.
113 ###########################################################################
115 .SUFFIXES: .c .cpp .h .hpp .y .l
116 .SUFFIXES: .lo .o .a $(SHLIBEXT) .bc .td
117 .SUFFIXES: .ps .dot .d
120 # Mark all of these targets as phony. This will hopefully speed up builds
121 # slightly since GNU Make will not try to find implicit rules for targets
122 # which are marked as Phony.
124 .PHONY: all dynamic bytecodelib install-bytecode-library
125 .PHONY: clean distclean install test bytecode prdirs
127 ###########################################################################
128 # Miscellaneous paths and commands:
129 # This section defines various configuration macros, such as where
130 # to find burg, tblgen, and libtool.
131 ###########################################################################
133 #--------------------------------------------------------------------
134 # Variables derived from configuration options...
135 #--------------------------------------------------------------------
139 ifdef ENABLE_PROFILING
141 CONFIGURATION := Profile
143 ifdef ENABLE_OPTIMIZED
144 CONFIGURATION := Release
146 CONFIGURATION := Debug
151 # Enable this for profiling support with 'gprof'
152 # This automatically enables optimized builds.
154 ifdef ENABLE_PROFILING
158 ###########################################################################
160 # These variables describe various library locations:
162 # DEST* = Location of where libraries that are built will be placed.
163 # LLVM* = Location of LLVM libraries used for linking.
164 # PROJ* = Location of previously built libraries used for linking.
165 ###########################################################################
167 # Libraries that are being built
168 DESTLIBDEBUG := $(BUILD_OBJ_ROOT)/lib/Debug
169 DESTLIBRELEASE := $(BUILD_OBJ_ROOT)/lib/Release
170 DESTLIBPROFILE := $(BUILD_OBJ_ROOT)/lib/Profile
171 DESTLIBBYTECODE := $(BUILD_OBJ_ROOT)/lib/BytecodeLibs
172 DESTLIBCURRENT := $(BUILD_OBJ_ROOT)/lib/$(CONFIGURATION)
174 # LLVM libraries used for linking
175 LLVMLIBDEBUGSOURCE := $(LLVM_OBJ_ROOT)/lib/Debug
176 LLVMLIBRELEASESOURCE := $(LLVM_OBJ_ROOT)/lib/Release
177 LLVMLIBPROFILESOURCE := $(LLVM_OBJ_ROOT)/lib/Profile
178 LLVMLIBCURRENTSOURCE := $(LLVM_OBJ_ROOT)/lib/$(CONFIGURATION)
180 # Libraries that were built that will now be used for linking
181 PROJLIBDEBUGSOURCE := $(BUILD_OBJ_ROOT)/lib/Debug
182 PROJLIBRELEASESOURCE := $(BUILD_OBJ_ROOT)/lib/Release
183 PROJLIBPROFILESOURCE := $(BUILD_OBJ_ROOT)/lib/Profile
184 PROJLIBCURRENTSOURCE := $(BUILD_OBJ_ROOT)/lib/$(CONFIGURATION)
186 ###########################################################################
188 # These variables describe various tool locations:
190 # DEST* = Location of where tools that are built will be placed.
191 # LLVM* = Location of LLVM tools used for building.
192 # PROJ* = Location of previously built tools used for linking.
193 ###########################################################################
195 DESTTOOLDEBUG := $(BUILD_OBJ_ROOT)/tools/Debug
196 DESTTOOLRELEASE := $(BUILD_OBJ_ROOT)/tools/Release
197 DESTTOOLPROFILE := $(BUILD_OBJ_ROOT)/tools/Profile
198 DESTTOOLCURRENT := $(BUILD_OBJ_ROOT)/tools/$(CONFIGURATION)
200 LLVMTOOLDEBUG := $(LLVM_OBJ_ROOT)/tools/Debug
201 LLVMTOOLRELEASE := $(LLVM_OBJ_ROOT)/tools/Release
202 LLVMTOOLPROFILE := $(LLVM_OBJ_ROOT)/tools/Profile
203 LLVMTOOLCURRENT := $(LLVM_OBJ_ROOT)/tools/$(CONFIGURATION)
205 PROJTOOLDEBUG := $(BUILD_OBJ_ROOT)/tools/Debug
206 PROJTOOLRELEASE := $(BUILD_OBJ_ROOT)/tools/Release
207 PROJTOOLPROFILE := $(BUILD_OBJ_ROOT)/tools/Profile
208 PROJTOOLCURRENT := $(BUILD_OBJ_ROOT)/tools/$(CONFIGURATION)
211 # Libtool is found in the current directory.
213 LIBTOOL := $(LLVM_OBJ_ROOT)/mklib
216 # If we're not building a shared library, use the disable-shared tag with
217 # libtool. This will disable the building of objects for shared libraries and
218 # only generate static library objects.
220 # For dynamic libraries, we'll take the performance hit for now, since we
221 # almost never build them.
223 # This should speed up compilation and require no modifications to future
224 # versions of libtool.
226 ifndef SHARED_LIBRARY
227 LIBTOOL += --tag=disable-shared
238 ###########################################################################
239 # Miscellaneous paths and commands (part deux):
240 # This section defines various configuration macros, such as where
241 # to find burg, tblgen, and libtool.
242 ###########################################################################
244 #--------------------------------------------------------------------------
245 # Utilities used while building the LLVM tree, which live in the utils dir
247 BURG := $(LLVMTOOLCURRENT)/burg$(EXEEXT)
248 RunBurg := $(BURG) $(BURG_OPTS)
249 TBLGEN := $(LLVMTOOLCURRENT)/tblgen$(EXEEXT)
250 LGCCLDPROG := $(LLVMTOOLCURRENT)/gccld$(EXEEXT)
252 #--------------------------------------------------------------------------
253 # The LLVM GCC front-end in C and C++ flavors
255 LLVMGCC := PATH=$(LLVMTOOLCURRENT):$(PATH) $(LLVMGCCDIR)/bin/gcc
256 LLVMGXX := PATH=$(LLVMTOOLCURRENT):$(PATH) $(LLVMGCCDIR)/bin/g++
258 #--------------------------------------------------------------------------
259 # The compiled LLVM tools
262 LLVMAS := $(LLVMTOOLCURRENT)/llvm-as$(EXEEXT)
263 # Find the location of the platform specific LLVM GCC libraries
264 LLVMGCCLIBDIR=$(dir $(shell $(LLVMGCC) -print-file-name=libgcc.a))
265 # LLVM Tool Definitions (LLVMGCC, LLVMGXX, LLVMAS are provided by
267 LLI = $(LLVMTOOLCURRENT)/lli$(EXEEXT)
268 LLC = $(LLVMTOOLCURRENT)/llc$(EXEEXT)
269 LGCCAS = $(LLVMTOOLCURRENT)/gccas$(EXEEXT)
270 LGCCLD = $(LGCCLDPROG) -L$(LLVMGCCLIBDIR) -L$(LLVMGCCDIR)/lib
271 LDIS = $(LLVMTOOLCURRENT)/llvm-dis$(EXEEXT)
272 LOPT = $(LLVMTOOLCURRENT)/opt$(EXEEXT)
273 LLINK = $(LLVMTOOLCURRENT)/llvm-link$(EXEEXT)
274 LPROF = $(LLVMTOOLCURRENT)/llvm-prof$(EXEEXT)
275 LANALYZE = $(LLVMTOOLCURRENT)/analyze$(EXEEXT)
276 LBUGPOINT = $(LLVMTOOLCURRENT)/bugpoint$(EXEEXT)
279 ###########################################################################
281 ###########################################################################
284 # Include both the project headers and the LLVM headers for compilation and
285 # dependency computation.
287 # BUILD_OBJ_DIR : Files local to the particular object directory
288 # (locallly generated header files).
289 # BUILD_SRC_DIR : Files local to the particular source directory.
290 # BUILD_SRC_ROOT/include : Files global to the project.
291 # LLVM_OBJ_ROOT/include : config.h files generated by autoconf
292 # LEVEL/include : config.h files for the project
293 # LLVM_SRC_ROOT/include : Files global to LLVM.
295 CPPFLAGS += -I$(BUILD_OBJ_DIR) -I$(BUILD_SRC_DIR) -I$(LLVM_OBJ_ROOT)/include \
296 -I$(BUILD_SRC_ROOT)/include -I$(LEVEL)/include \
297 -I$(LLVM_SRC_ROOT)/include
299 # By default, strip symbol information from executable
301 STRIP = $(PLATFORMSTRIPOPTS)
302 STRIP_WARN_MSG = "(without symbols)"
305 # Allow GNU extensions:
306 CPPFLAGS += -D_GNU_SOURCE
307 # Pull in limit macros from stdint.h, even in C++:
308 CPPFLAGS += -D__STDC_LIMIT_MACROS
310 ### FIXME: this is GCC specific
311 CPPFLAGS += -DATTR_DEPRECATED='__attribute__ ((deprecated))'
313 CompileCommonOpts := -Wall -W -Wwrite-strings -Wno-unused
314 CompileOptimizeOpts := -O3 -DNDEBUG -finline-functions
317 # Compile commands with libtool.
319 Compile := $(LIBTOOL) --tag=CXX --mode=compile $(CXX) -c $(CPPFLAGS) $(CXXFLAGS) $(CompileCommonOpts)
320 CompileC := $(LIBTOOL) --mode=compile $(CC) -c $(CPPFLAGS) $(CFLAGS) $(CompileCommonOpts)
322 # Compile a cpp file, don't link...
323 CompileG := $(Compile) -g -D_DEBUG
324 CompileO := $(Compile) $(CompileOptimizeOpts) -felide-constructors -fomit-frame-pointer
325 CompileP := $(Compile) $(CompileOptimizeOpts) -felide-constructors $(PROFILE)
327 # Compile a c file, don't link...
328 CompileCG := $(CompileC) -g -D_DEBUG
329 CompileCO := $(CompileC) $(CompileOptimizeOpts) -fomit-frame-pointer
330 CompileCP := $(CompileC) $(CompileOptimizeOpts) $(PROFILE)
332 ###########################################################################
334 ###########################################################################
337 # Link final executable
338 # (Note that we always link with the C++ compiler).
340 Link := $(LIBTOOL) --tag=CXX --mode=link $(CXX)
342 # link both projlib and llvmlib libraries
343 LinkG := $(Link) -g -L$(PROJLIBDEBUGSOURCE) -L$(LLVMLIBDEBUGSOURCE) $(STRIP)
344 LinkO := $(Link) -O3 -L$(PROJLIBRELEASESOURCE) -L$(LLVMLIBRELEASESOURCE)
345 LinkP := $(Link) -O3 -L$(PROJLIBPROFILESOURCE) -L$(LLVMLIBPROFILESOURCE) $(PROFILE)
347 # TOOLLINKOPTSB to pass options to the linker like library search path etc
348 # Note that this is different from TOOLLINKOPTS, these options
349 # are passed to the linker *before* the USEDLIBS options are passed.
350 # e.g. usage TOOLLINKOPTSB = -L/home/xxx/lib
352 LinkG := $(LinkG) $(TOOLLINKOPTSB)
353 LinkO := $(LinkO) $(TOOLLINKOPTSB)
354 LinkP := $(LinkP) $(TOOLLINKOPTSB)
357 # Create one .o file from a bunch of .o files...
358 Relink := ${LIBTOOL} --tag=CXX --mode=link $(CXX)
361 # Configure where the item being compiled should go.
364 Link += -rpath $(DESTLIBCURRENT)
368 Link += -rpath $(DESTTOOLCURRENT)
371 # Create dependency file from CPP file, send to stdout.
372 Depend := $(CXX) -MM -I$(LEVEL)/include $(CPPFLAGS)
373 DependC := $(CC) -MM -I$(LEVEL)/include $(CPPFLAGS)
375 # Archive a bunch of .o files into a .a file...
378 #----------------------------------------------------------
380 # Source includes all of the cpp files, and objects are derived from the
382 # The local Makefile can list other Source files via ExtraSource = ...
385 Source := $(notdir $(ExtraSource) $(wildcard $(SourceDir)/*.cpp \
386 $(SourceDir)/*.cc $(SourceDir)/*.c $(SourceDir)/*.y \
393 Srcs := $(sort $(basename $(Source)))
394 ObjectsO := $(Srcs:%=$(BUILD_OBJ_DIR)/Release/%.lo)
395 ObjectsP := $(Srcs:%=$(BUILD_OBJ_DIR)/Profile/%.lo)
396 ObjectsG := $(Srcs:%=$(BUILD_OBJ_DIR)/Debug/%.lo)
397 ObjectsBC := $(Srcs:%=$(BUILD_OBJ_DIR)/BytecodeObj/%.bc)
400 # The real objects underlying the libtool objects
402 RObjs := $(sort $(patsubst Debug/%.o, %.o, $(addsuffix .o,$(basename $(Source)))))
403 RObjectsO := $(addprefix $(BUILD_OBJ_DIR)/Release/,$(RObjs))
404 RObjectsP := $(addprefix $(BUILD_OBJ_DIR)/Profile/,$(RObjs))
405 RObjectsG := $(addprefix $(BUILD_OBJ_DIR)/Debug/,$(RObjs))
407 #---------------------------------------------------------
408 # Handle the DIRS and PARALLEL_DIRS options
409 #---------------------------------------------------------
412 all install clean test bytecode stripped-bytecode install-bytecode::
413 $(VERB) for dir in ${DIRS}; do \
414 if [ ! -f $$dir/Makefile ]; \
417 cp $(SourceDir)/$$dir/Makefile $$dir/Makefile; \
419 ($(MAKE) -C $$dir $@ $(MFLAGS)) || exit 1; \
423 # Handle PARALLEL_DIRS
425 all :: $(addsuffix /.makeall , $(PARALLEL_DIRS))
426 install :: $(addsuffix /.makeinstall , $(PARALLEL_DIRS))
427 clean :: $(addsuffix /.makeclean , $(PARALLEL_DIRS))
428 test :: $(addsuffix /.maketest , $(PARALLEL_DIRS))
429 bytecode :: $(addsuffix /.makebytecode, $(PARALLEL_DIRS))
430 stripped-bytecode :: $(addsuffix /.makestripped-bytecode, $(PARALLEL_DIRS))
431 install-bytecode :: $(addsuffix /.makeinstall-bytecode, $(PARALLEL_DIRS))
433 %/.makeall %/.makeinstall %/.makeclean %/.maketest %/.makebytecode %/.makestripped-bytecode %/.makeinstall-bytecode:
434 $(VERB) if [ ! -f $(@D)/Makefile ]; \
437 cp $(SourceDir)/$(@D)/Makefile $(@D)/Makefile; \
439 $(MAKE) -C $(@D) $(subst $(@D)/.make,,$@) $(MFLAGS)
442 # Handle directories that may or may not exist
444 all install clean test bytecode stripped-bytecode install-bytecode::
445 $(VERB) for dir in ${OPTIONAL_DIRS}; do \
446 if [ -d $(SourceDir)/$$dir ]; \
448 if [ ! -f $$dir/Makefile ]; \
451 cp $(SourceDir)/$$dir/Makefile $$dir/Makefile; \
453 ($(MAKE) -C$$dir $@ $(MFLAGS)) || exit 1; \
458 #---------------------------------------------------------
459 # Handle the CONFIG_FILES options
460 #---------------------------------------------------------
462 install:: install-config-files
465 $(MKDIR) $(sysconfdir)
467 install-config-files: $(sysconfdir) $(CONFIG_FILES)
468 $(VERB) echo Installing Configuration Files To $(sysconfdir)
469 $(VERB) for file in $(CONFIG_FILES); do \
470 $(INSTALL) $(SourceDir)/$${file} $(sysconfdir) ; \
474 ###########################################################################
475 # Library Build Rules:
477 #---------------------------------------------------------
478 # Handle the LIBRARYNAME option - used when building libs...
479 #---------------------------------------------------------
481 # When libraries are built, they are allowed to optionally define the
482 # DONT_BUILD_RELINKED make variable, which, when defined, prevents a .o file
483 # from being built for the library. This .o files may then be linked to by a
484 # tool if the tool does not need (or want) the semantics a .a file provides
485 # (linking in only object files that are "needed"). If a library is never to
486 # be used in this way, it is better to define DONT_BUILD_RELINKED, and define
487 # BUILD_ARCHIVE instead.
489 # Some libraries must be built as .a files (libscalar for example) because if
490 # it's built as a .o file, then all of the constituent .o files in it will be
491 # linked into tools (for example gccas) even if they only use one of the parts
492 # of it. For this reason, sometimes it's useful to use libraries as .a files.
493 ###########################################################################
495 # Install rule for making bytecode library directory if it does not exist.
496 # Trigger this by making libraries that need to be installed here depend on it.
497 $(DESTDIR)$(bytecode_libdir):
502 # Make sure there isn't any extranous whitespace on the LIBRARYNAME option
503 LIBRARYNAME := $(strip $(LIBRARYNAME))
505 LIBNAME_O := $(DESTLIBRELEASE)/lib$(LIBRARYNAME)$(SHLIBEXT)
506 LIBNAME_P := $(DESTLIBPROFILE)/lib$(LIBRARYNAME)$(SHLIBEXT)
507 LIBNAME_G := $(DESTLIBDEBUG)/lib$(LIBRARYNAME)$(SHLIBEXT)
508 LIBNAME_CUR := $(DESTLIBCURRENT)/lib$(LIBRARYNAME)$(SHLIBEXT)
509 LIBNAME_AO := $(DESTLIBRELEASE)/lib$(LIBRARYNAME).a
510 LIBNAME_AP := $(DESTLIBPROFILE)/lib$(LIBRARYNAME).a
511 LIBNAME_AG := $(DESTLIBDEBUG)/lib$(LIBRARYNAME).a
512 LIBNAME_ACUR := $(DESTLIBCURRENT)/lib$(LIBRARYNAME).a
513 LIBNAME_OBJO := $(DESTLIBRELEASE)/$(LIBRARYNAME).o
514 LIBNAME_OBJP := $(DESTLIBPROFILE)/$(LIBRARYNAME).o
515 LIBNAME_OBJG := $(DESTLIBDEBUG)/$(LIBRARYNAME).o
516 LIBNAME_OBJCUR := $(DESTLIBCURRENT)/$(LIBRARYNAME).o
517 LIBNAME_BC := $(DESTLIBBYTECODE)/lib$(LIBRARYNAME).bc
520 #--------------------------------------------------------------------
522 # Modify the top level targets to build the desired libraries.
523 #--------------------------------------------------------------------
525 # dynamic target builds a shared object version of the library...
526 dynamic:: $(LIBNAME_CUR)
527 bytecodelib:: $(LIBNAME_BC)
528 install-bytecode-library:: $(DESTDIR)$(bytecode_libdir)/lib$(LIBRARYNAME).bc
530 $(DESTDIR)$(bytecode_libdir)/lib$(LIBRARYNAME).bc: $(LIBNAME_BC) $(DESTDIR)$(bytecode_libdir)
531 @${ECHO} ======= Installing $(LIBRARYNAME) bytecode library =======
534 # Does the library want a .o version built?
535 ifndef DONT_BUILD_RELINKED
536 all:: $(LIBNAME_OBJCUR)
537 install:: install-single-object-library
540 # Does the library want an archive version built?
542 all:: $(LIBNAME_ACUR)
543 install:: install-archive-library
546 #--------------------------------------------------------------------
547 # Rules for building libraries
548 #--------------------------------------------------------------------
550 LinkBCLib := $(LLVMGCC) -shared -nostdlib
551 ifdef EXPORTED_SYMBOL_LIST
552 LinkBCLib += -Xlinker -internalize-public-api-list=$(EXPORTED_SYMBOL_LIST)
554 ifdef EXPORTED_SYMBOL_FILE
555 LinkBCLib += -Xlinker -internalize-public-api-file=$(EXPORTED_SYMBOL_FILE)
557 LinkBCLib += -Xlinker -disable-internalize
562 # Rule for building bytecode libraries.
563 $(LIBNAME_BC): $(ObjectsBC) $(LibSubDirs) $(DESTLIBBYTECODE)/.dir
564 @${ECHO} Linking $(LIBRARYNAME) bytecode library
565 $(VERB) $(LinkBCLib) -o $@ $(ObjectsBC) $(LibSubDirs) $(LibLinkOpts)
566 @${ECHO} ======= Finished building $(LIBRARYNAME) bytecode library =======
568 # Rules for building dynamically linked libraries.
570 $(LIBNAME_O): $(ObjectsO) $(LibSubDirs) $(DESTLIBRELEASE)/.dir
571 @${ECHO} Linking $(LIBRARYNAME) dynamic release library
572 $(VERB) $(Link) -o $*.la $(ObjectsO) $(LibSubDirs) $(LibLinkOpts)
573 $(VERB) $(LIBTOOL) --mode=install $(INSTALL) $*.la $(DESTLIBCURRENT)
574 @${ECHO} ======= Finished building $(LIBRARYNAME) dynamic release library =======
576 $(LIBNAME_P): $(ObjectsP) $(LibSubDirs) $(DESTLIBPROFILE)/.dir
577 @${ECHO} Linking $(LIBRARYNAME) dynamic profile library
578 $(VERB) $(Link) -o $*.la $(ObjectsP) $(LibSubDirs) $(LibLinkOpts)
579 $(VERB) $(LIBTOOL) --mode=install $(INSTALL) $*.la $(DESTLIBCURRENT)
580 @${ECHO} ======= Finished building $(LIBRARYNAME) dynamic profile library =======
582 $(LIBNAME_G): $(ObjectsG) $(LibSubDirs) $(DESTLIBDEBUG)/.dir
583 @${ECHO} Linking $(LIBRARYNAME) dynamic debug library
584 $(VERB) $(Link) -o $*.la $(ObjectsG) $(LibSubDirs) $(LibLinkOpts)
585 $(VERB) $(LIBTOOL) --mode=install $(INSTALL) $*.la $(DESTLIBCURRENT)
586 @${ECHO} ======= Finished building $(LIBRARYNAME) dynamic debug library =======
588 install-dynamic-library: $(LIBNAME_CUR)
589 $(MKDIR) $(DESTDIR)$(libdir)
590 $(VERB) $(LIBTOOL) --mode=install $(INSTALL) $(LIBNAME_CUR) $(DESTDIR)$(libdir)/lib$(LIBRARYNAME)$(SHLIBEXT)
593 # Rules for building static archive libraries.
595 $(LIBNAME_AO): $(ObjectsO) $(LibSubDirs) $(DESTLIBRELEASE)/.dir
596 @${ECHO} Linking $(LIBRARYNAME) archive release library
598 $(VERB) $(Link) -03 -o $@ $(ObjectsO) $(LibSubDirs) -static
599 @${ECHO} Finished building $(LIBRARYNAME) archive release library =======
601 $(LIBNAME_AP): $(ObjectsP) $(LibSubDirs) $(DESTLIBPROFILE)/.dir
602 @${ECHO} Linking $(LIBRARYNAME) archive profile library
604 $(VERB) $(Link) -03 $(PROFILE) -o $@ $(ObjectsP) $(LibSubDirs) -static
605 @${ECHO} ======= Finished building $(LIBRARYNAME) archive profile library =======
607 $(LIBNAME_AG): $(ObjectsG) $(LibSubDirs) $(DESTLIBDEBUG)/.dir
608 @${ECHO} Linking $(LIBRARYNAME) archive debug library
610 $(VERB) $(Link) -g $(STRIP) -o $@ $(ObjectsG) $(LibSubDirs) -static
611 @${ECHO} ======= Finished building $(LIBRARYNAME) archive debug library =======
613 install-archive-library: $(LIBNAME_ACUR)
614 $(MKDIR) $(DESTDIR)$(libdir)
615 $(VERB) $(LIBTOOL) --mode=install $(INSTALL) $(LIBNAME_ACUR) $(DESTDIR)$(libdir)/lib$(LIBRARYNAME).a
618 # Rules for building .o libraries.
621 # Note that for this special case, we specify the actual object files
622 # instead of their libtool counterparts. This is because libtool
623 # doesn't want to generate a reloadable object file unless it is given
624 # .o files explicitly.
626 # Note that we're making an assumption here: If we build a .lo file,
627 # it's corresponding .o file will be placed in the same directory.
629 # I think that is safe.
631 $(LIBNAME_OBJO): $(ObjectsO) $(LibSubDirs) $(DESTLIBRELEASE)/.dir
632 @${ECHO} "Linking `basename $@`"
633 $(VERB) $(Relink) -o $@ $(RObjectsO) $(LibSubDirs)
635 $(LIBNAME_OBJP): $(ObjectsP) $(LibSubDirs) $(DESTLIBPROFILE)/.dir
636 @${ECHO} "Linking `basename $@`"
637 $(VERB) $(Relink) -o $@ $(RObjectsP) $(LibSubDirs)
639 $(LIBNAME_OBJG): $(ObjectsG) $(LibSubDirs) $(DESTLIBDEBUG)/.dir
640 @${ECHO} "Linking `basename $@`"
641 $(VERB) $(Relink) -o $@ $(RObjectsG) $(LibSubDirs)
643 install-single-object-library: $(LIBNAME_OBJCUR)
644 $(MKDIR) $(DESTDIR)$(libdir)
645 $(VERB) $(LIBTOOL) --mode=install $(INSTALL) $(LIBNAME_OBJCUR) $(DESTDIR)$(libdir)/$(LIBRARYNAME).o
649 #------------------------------------------------------------------------
650 # Handle the TOOLNAME option - used when building tool executables...
651 #------------------------------------------------------------------------
653 # The TOOLNAME option should be used with a USEDLIBS variable that tells the
654 # libraries (and the order of the libs) that should be linked to the
655 # tool. USEDLIBS should contain a list of library names (some with .a extension)
656 # that are automatically linked in as .o files unless the .a suffix is added.
660 # TOOLEXENAME* - These compute the output filenames to generate...
661 TOOLEXENAME_G := $(DESTTOOLDEBUG)/$(TOOLNAME)
662 TOOLEXENAME_O := $(DESTTOOLRELEASE)/$(TOOLNAME)
663 TOOLEXENAME_P := $(DESTTOOLPROFILE)/$(TOOLNAME)
664 TOOLEXENAMES := $(DESTTOOLCURRENT)/$(TOOLNAME)
666 # USED_LIBS_OPTIONS - Compute the options line that add -llib1 -llib2, etc.
667 PROJ_LIBS_OPTIONS := $(patsubst %.a.o, -l%, $(addsuffix .o, $(USEDLIBS)))
668 PROJ_LIBS_OPTIONS_G := $(patsubst %.o, $(PROJLIBDEBUGSOURCE)/%.o, $(PROJ_LIBS_OPTIONS))
669 PROJ_LIBS_OPTIONS_O := $(patsubst %.o, $(PROJLIBRELEASESOURCE)/%.o,$(PROJ_LIBS_OPTIONS))
670 PROJ_LIBS_OPTIONS_P := $(patsubst %.o, $(PROJLIBPROFILESOURCE)/%.o,$(PROJ_LIBS_OPTIONS))
672 LLVM_LIBS_OPTIONS := $(patsubst %.a.o, -l%, $(addsuffix .o, $(LLVMLIBS)))
673 LLVM_LIBS_OPTIONS_G := $(patsubst %.o, $(LLVMLIBDEBUGSOURCE)/%.o, $(LLVM_LIBS_OPTIONS))
674 LLVM_LIBS_OPTIONS_O := $(patsubst %.o, $(LLVMLIBRELEASESOURCE)/%.o,$(LLVM_LIBS_OPTIONS))
675 LLVM_LIBS_OPTIONS_P := $(patsubst %.o, $(LLVMLIBPROFILESOURCE)/%.o,$(LLVM_LIBS_OPTIONS))
677 LIB_OPTS_G := $(LLVM_LIBS_OPTIONS_G) $(PROJ_LIBS_OPTIONS_G)
678 LIB_OPTS_O := $(LLVM_LIBS_OPTIONS_O) $(PROJ_LIBS_OPTIONS_O)
679 LIB_OPTS_P := $(LLVM_LIBS_OPTIONS_P) $(PROJ_LIBS_OPTIONS_P)
681 # USED_LIB_PATHS - Compute the path of the libraries used so that tools are
682 # rebuilt if libraries change. This has to make sure to handle .a/.so and .o
685 STATICUSEDLIBS := $(patsubst %.a.o, lib%.a, $(addsuffix .o, $(USEDLIBS)))
686 USED_LIB_PATHS_G := $(addprefix $(DESTLIBDEBUG)/, $(STATICUSEDLIBS))
687 USED_LIB_PATHS_O := $(addprefix $(DESTLIBRELEASE)/, $(STATICUSEDLIBS))
688 USED_LIB_PATHS_P := $(addprefix $(DESTLIBPROFILE)/, $(STATICUSEDLIBS))
691 # Libtool link options:
692 # Ensure that all binaries have their symbols exported so that they can
695 LINK_OPTS := -export-dynamic $(TOOLLINKOPTS)
701 # Tell make that we need to rebuild subdirectories before we can link the tool.
702 # This affects things like LLI which has library subdirectories.
703 $(USED_LIB_PATHS_G) $(USED_LIB_PATHS_O) $(USED_LIB_PATHS_P): \
704 $(addsuffix /.makeall, $(PARALLEL_DIRS))
706 all:: $(TOOLEXENAMES)
709 $(VERB) $(RM) -f $(TOOLEXENAMES)
711 $(TOOLEXENAME_G): $(ObjectsG) $(USED_LIB_PATHS_G) $(DESTTOOLDEBUG)/.dir
712 @${ECHO} Linking $(TOOLNAME) debug executable $(STRIP_WARN_MSG)
713 $(VERB) $(LinkG) -o $@ $(ObjectsG) $(LIB_OPTS_G) $(LINK_OPTS) $(LIBS)
714 @${ECHO} ======= Finished building $(TOOLNAME) debug executable $(STRIP_WARN_MSG) =======
716 $(TOOLEXENAME_O): $(ObjectsO) $(USED_LIB_PATHS_O) $(DESTTOOLRELEASE)/.dir
717 @${ECHO} Linking $(TOOLNAME) release executable
718 $(VERB) $(LinkO) -o $@ $(ObjectsO) $(LIB_OPTS_O) $(LINK_OPTS) $(LIBS)
719 @${ECHO} ======= Finished building $(TOOLNAME) release executable =======
721 $(TOOLEXENAME_P): $(ObjectsP) $(USED_LIB_PATHS_P) $(DESTTOOLPROFILE)/.dir
722 @${ECHO} Linking $(TOOLNAME) profile executable
723 $(VERB) $(LinkP) -o $@ $(ObjectsP) $(LIB_OPTS_P) $(LINK_OPTS) $(LIBS)
724 @${ECHO} ======= Finished building $(TOOLNAME) profile executable =======
726 install:: $(TOOLEXENAMES)
727 $(MKDIR) $(DESTDIR)$(bindir)
728 $(LIBTOOL) --mode=install $(INSTALL_PROGRAM) -c -m 0755 $(TOOLEXENAMES) $(DESTDIR)$(bindir)/$(TOOLNAME)
734 #---------------------------------------------------------
735 .PRECIOUS: $(BUILD_OBJ_DIR)/Depend/.dir $(BUILD_OBJ_DIR)/BytecodeObj/.dir
736 .PRECIOUS: $(BUILD_OBJ_DIR)/Debug/.dir $(BUILD_OBJ_DIR)/Release/.dir
737 .PRECIOUS: $(BUILD_OBJ_DIR)/Profile/.dir
739 # Create .lo files in the ObjectFiles directory from the .cpp and .c files...
740 $(BUILD_OBJ_DIR)/Release/%.lo: %.cpp $(BUILD_OBJ_DIR)/Release/.dir
741 @${ECHO} "Compiling `basename $<`"
742 $(VERB) $(CompileO) $< -o $@
744 $(BUILD_OBJ_DIR)/Release/%.lo: %.c $(BUILD_OBJ_DIR)/Release/.dir
745 @${ECHO} "Compiling `basename $<`"
746 $(VERB) $(CompileCO) $< -o $@
748 $(BUILD_OBJ_DIR)/Profile/%.lo: %.cpp $(BUILD_OBJ_DIR)/Profile/.dir
749 @${ECHO} "Compiling `basename $<`"
750 $(VERB) $(CompileP) $< -o $@
752 $(BUILD_OBJ_DIR)/Profile/%.lo: %.c $(BUILD_OBJ_DIR)/Profile/.dir
753 @${ECHO} "Compiling `basename $<`"
754 $(VERB) $(CompileCP) $< -o $@
756 $(BUILD_OBJ_DIR)/Debug/%.lo: %.cpp $(BUILD_OBJ_DIR)/Debug/.dir
757 @${ECHO} "Compiling `basename $<`"
758 $(VERB) $(CompileG) $< -o $@
760 $(BUILD_OBJ_DIR)/Debug/%.lo: %.c $(BUILD_OBJ_DIR)/Debug/.dir
761 @${ECHO} "Compiling `basename $<`"
762 $(VERB) $(CompileCG) $< -o $@
764 $(BUILD_OBJ_DIR)/BytecodeObj/%.bc: %.cpp $(BUILD_OBJ_DIR)/BytecodeObj/.dir $(LCC1XX)
765 @${ECHO} "Compiling `basename $<` to bytecode"
766 $(VERB) $(LLVMGXX) $(CompileCommonOpts) $(CPPFLAGS) -c $< -o $@
768 $(BUILD_OBJ_DIR)/BytecodeObj/%.bc: %.c $(BUILD_OBJ_DIR)/BytecodeObj/.dir $(LCC1)
769 @${ECHO} "Compiling `basename $<` to bytecode"
770 $(VERB) $(LLVMGCC) $(CompileCommonOpts) $(CPPFLAGS) -c $< -o $@
772 $(BUILD_OBJ_DIR)/BytecodeObj/%.bc: %.ll $(BUILD_OBJ_DIR)/BytecodeObj/.dir $(LLVMAS)
773 @${ECHO} "Compiling `basename $<` to bytecode"
774 $(VERB) $(LLVMAS) $< -f -o $@
778 # Rules for building lex/yacc files
780 LEX_FILES = $(filter %.l, $(Source))
781 LEX_OUTPUT = $(LEX_FILES:%.l=%.cpp)
782 YACC_FILES = $(filter %.y, $(Source))
783 YACC_OUTPUT = $(addprefix $(YACC_FILES:%.y=%), .h .cpp .output)
784 .PRECIOUS: $(LEX_OUTPUT) $(YACC_OUTPUT)
786 # Create a .cpp source file from a flex input file... this uses sed to cut down
787 # on the warnings emited by GCC...
789 # The last line is a gross hack to work around flex aparently not being able to
790 # resize the buffer on a large token input. Currently, for uninitialized string
791 # buffers in LLVM we can generate very long tokens, so this is a hack around it.
792 # FIXME. (f.e. char Buffer[10000] )
796 $(VERB) $(FLEX) -t $< | \
797 $(SED) '/^find_rule/d' | \
798 $(SED) 's/void yyunput/inline void yyunput/' | \
799 $(SED) 's/void \*yy_flex_realloc/inline void *yy_flex_realloc/' | \
800 $(SED) 's/#define YY_BUF_SIZE 16384/#define YY_BUF_SIZE (16384*64)/' \
802 $(VERB) cmp -s $@ $@.tmp > /dev/null || ${MV} -f $@.tmp $@
803 @# remove the output of flex if it didn't get moved over...
806 # Rule for building the bison parsers...
807 %.c: %.y # Cancel built-in rules for yacc
808 %.h: %.y # Cancel built-in rules for yacc
810 @${ECHO} "Bisoning `basename $<`"
811 $(VERB) $(BISON) -v -d -p $(<F:%Parser.y=%) -o $*.tab.c $<
812 $(VERB) cmp -s $*.tab.c $*.cpp > /dev/null || ${MV} -f $*.tab.c $*.cpp
813 $(VERB) cmp -s $*.tab.h $*.h > /dev/null || ${MV} -f $*.tab.h $*.h
814 @# If the files were not updated, don't leave them lying around...
815 @rm -f $*.tab.c $*.tab.h
817 # To create the directories...
819 $(VERB) ${MKDIR} $* > /dev/null
822 # To create postscript files from dot files...
825 ${DOT} -Tps < $< > $@
828 ${ECHO} "Cannot build $@: The program dot is not installed"
832 # This rules ensures that header files that are removed still have a rule for
833 # which they can be "generated." This allows make to ignore them and
834 # reproduce the dependency lists.
838 # 'make clean' nukes the tree
840 $(VERB) $(RM) -rf $(BUILD_OBJ_DIR)/Debug $(BUILD_OBJ_DIR)/Release
841 $(VERB) $(RM) -rf $(BUILD_OBJ_DIR)/Profile $(BUILD_OBJ_DIR)/Depend
842 $(VERB) $(RM) -rf $(BUILD_OBJ_DIR)/BytecodeObj
843 $(VERB) $(RM) -f core core.[0-9][0-9]* *.o *.d *~ *.flc
844 ifneq ($(strip $(SHLIBEXT)),) # Extra paranoia - make real sure SHLIBEXT is set
845 $(VERB) $(RM) -f *$(SHLIBEXT)
847 $(VERB) $(RM) -f $(LEX_OUTPUT) $(YACC_OUTPUT)
849 ###########################################################################
851 # Define variables and rules that generate header file dependencies
852 # from C/C++ source files.
853 ###########################################################################
855 ifndef DISABLE_AUTO_DEPENDENCIES
857 # If dependencies were generated for the file that included this file,
858 # include the dependencies now...
860 SourceBaseNames := $(basename $(Source))
861 SourceDepend := $(SourceBaseNames:%=$(BUILD_OBJ_DIR)/Depend/%.d)
863 # Create dependencies for the *.cpp files...
864 $(BUILD_OBJ_DIR)/Depend/%.d: %.cpp $(BUILD_OBJ_DIR)/Depend/.dir
865 $(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' > $@
867 # Create dependencies for the *.c files...
868 $(BUILD_OBJ_DIR)/Depend/%.d: %.c $(BUILD_OBJ_DIR)/Depend/.dir
869 $(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' > $@
872 # Autoconf Dependencies.
874 $(LLVM_OBJ_ROOT)/config.status:: $(LLVM_SRC_ROOT)/configure
875 @${ECHO} "****************************************************************"
876 @${ECHO} " You need to re-run $(LLVM_SRC_ROOT)/configure"
877 @${ECHO} " in directory $(LLVM_OBJ_ROOT)"
878 @${ECHO} "****************************************************************"
881 # If the Makefile in the source tree has been updated, copy it over into the
883 Makefile :: $(BUILD_SRC_DIR)/Makefile
884 @${ECHO} "===== Updating Makefile from source dir: `dirname $<` ====="
889 # Include dependencies generated from C/C++ source files, but not if we
890 # are cleaning (this example taken from the GNU Make Manual).
892 ifneq ($(MAKECMDGOALS),clean)
893 ifneq ($(MAKECMDGOALS),distclean)
894 -include /dev/null $(SourceDepend)
898 endif # ifndef DISABLE_AUTO_DEPENDENCIES