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
83 # Default Rule: Make sure it's also a :: rule
86 # Default for install is to at least build everything...
89 # Default rule for test. It ensures everything has a test rule
92 # Default rule for building only bytecode.
95 # Print out the directories used for building
97 @${ECHO} "Build Source Root: " $(BUILD_SRC_ROOT)
98 @${ECHO} "Build Source Dir : " $(BUILD_SRC_DIR)
99 @${ECHO} "Build Object Root: " $(BUILD_OBJ_ROOT)
100 @${ECHO} "Build Object Dir : " $(BUILD_OBJ_DIR)
101 @${ECHO} "LLVM Source Root: " $(LLVM_SRC_ROOT)
102 @${ECHO} "LLVM Object Root: " $(LLVM_OBJ_ROOT)
104 ###########################################################################
105 # Suffixes and implicit rules:
106 # Empty out the list of suffixes, generate a list that is only
107 # used by this Makefile, and cancel useless implicit rules. This
108 # will hopefully speed up compilation a little bit.
109 ###########################################################################
111 .SUFFIXES: .c .cpp .h .hpp .y .l
112 .SUFFIXES: .lo .o .a $(SHLIBEXT) .bc .td
113 .SUFFIXES: .ps .dot .d
116 # Mark all of these targets as phony. This will hopefully speed up builds
117 # slightly since GNU Make will not try to find implicit rules for targets
118 # which are marked as Phony.
120 .PHONY: all dynamic bytecodelib install-bytecode-library
121 .PHONY: clean distclean install test bytecode prdirs
123 ###########################################################################
124 # Miscellaneous paths and commands:
125 # This section defines various configuration macros, such as where
126 # to find burg, tblgen, and libtool.
127 ###########################################################################
129 #--------------------------------------------------------------------
130 # Variables derived from configuration options...
131 #--------------------------------------------------------------------
135 ifdef ENABLE_PROFILING
137 CONFIGURATION := Profile
139 ifdef ENABLE_OPTIMIZED
140 CONFIGURATION := Release
142 CONFIGURATION := Debug
147 # Enable this for profiling support with 'gprof'
148 # This automatically enables optimized builds.
150 ifdef ENABLE_PROFILING
154 ###########################################################################
156 # These variables describe various library locations:
158 # DEST* = Location of where libraries that are built will be placed.
159 # LLVM* = Location of LLVM libraries used for linking.
160 # PROJ* = Location of previously built libraries used for linking.
161 ###########################################################################
163 # Libraries that are being built
164 DESTLIBDEBUG := $(BUILD_OBJ_ROOT)/lib/Debug
165 DESTLIBRELEASE := $(BUILD_OBJ_ROOT)/lib/Release
166 DESTLIBPROFILE := $(BUILD_OBJ_ROOT)/lib/Profile
167 DESTLIBBYTECODE := $(BUILD_OBJ_ROOT)/lib/BytecodeLibs
168 DESTLIBCURRENT := $(BUILD_OBJ_ROOT)/lib/$(CONFIGURATION)
170 # LLVM libraries used for linking
171 LLVMLIBDEBUGSOURCE := $(LLVM_OBJ_ROOT)/lib/Debug
172 LLVMLIBRELEASESOURCE := $(LLVM_OBJ_ROOT)/lib/Release
173 LLVMLIBPROFILESOURCE := $(LLVM_OBJ_ROOT)/lib/Profile
174 LLVMLIBCURRENTSOURCE := $(LLVM_OBJ_ROOT)/lib/$(CONFIGURATION)
176 # Libraries that were built that will now be used for linking
177 PROJLIBDEBUGSOURCE := $(BUILD_OBJ_ROOT)/lib/Debug
178 PROJLIBRELEASESOURCE := $(BUILD_OBJ_ROOT)/lib/Release
179 PROJLIBPROFILESOURCE := $(BUILD_OBJ_ROOT)/lib/Profile
180 PROJLIBCURRENTSOURCE := $(BUILD_OBJ_ROOT)/lib/$(CONFIGURATION)
182 ###########################################################################
184 # These variables describe various tool locations:
186 # DEST* = Location of where tools that are built will be placed.
187 # LLVM* = Location of LLVM tools used for building.
188 # PROJ* = Location of previously built tools used for linking.
189 ###########################################################################
191 DESTTOOLDEBUG := $(BUILD_OBJ_ROOT)/tools/Debug
192 DESTTOOLRELEASE := $(BUILD_OBJ_ROOT)/tools/Release
193 DESTTOOLPROFILE := $(BUILD_OBJ_ROOT)/tools/Profile
194 DESTTOOLCURRENT := $(BUILD_OBJ_ROOT)/tools/$(CONFIGURATION)
196 LLVMTOOLDEBUG := $(LLVM_OBJ_ROOT)/tools/Debug
197 LLVMTOOLRELEASE := $(LLVM_OBJ_ROOT)/tools/Release
198 LLVMTOOLPROFILE := $(LLVM_OBJ_ROOT)/tools/Profile
199 LLVMTOOLCURRENT := $(LLVM_OBJ_ROOT)/tools/$(CONFIGURATION)
201 PROJTOOLDEBUG := $(BUILD_OBJ_ROOT)/tools/Debug
202 PROJTOOLRELEASE := $(BUILD_OBJ_ROOT)/tools/Release
203 PROJTOOLPROFILE := $(BUILD_OBJ_ROOT)/tools/Profile
204 PROJTOOLCURRENT := $(BUILD_OBJ_ROOT)/tools/$(CONFIGURATION)
207 # Libtool is found in the current directory.
209 LIBTOOL := $(LLVM_OBJ_ROOT)/mklib
212 # If we're not building a shared library, use the disable-shared tag with
213 # libtool. This will disable the building of objects for shared libraries and
214 # only generate static library objects.
216 # For dynamic libraries, we'll take the performance hit for now, since we
217 # almost never build them.
219 # This should speed up compilation and require no modifications to future
220 # versions of libtool.
222 ifndef SHARED_LIBRARY
223 LIBTOOL += --tag=disable-shared
234 ###########################################################################
235 # Miscellaneous paths and commands (part deux):
236 # This section defines various configuration macros, such as where
237 # to find burg, tblgen, and libtool.
238 ###########################################################################
240 #--------------------------------------------------------------------------
241 # Utilities used while building the LLVM tree, which live in the utils dir
243 BURG := $(LLVMTOOLCURRENT)/burg
244 RunBurg := $(BURG) $(BURG_OPTS)
245 TBLGEN := $(LLVMTOOLCURRENT)/tblgen
246 LGCCLDPROG := $(LLVMTOOLCURRENT)/gccld
248 #--------------------------------------------------------------------------
249 # The LLVM GCC front-end in C and C++ flavors
251 LLVMGCC := PATH=$(LLVMTOOLCURRENT):$(PATH) $(LLVMGCCDIR)/bin/gcc
252 LLVMGXX := PATH=$(LLVMTOOLCURRENT):$(PATH) $(LLVMGCCDIR)/bin/g++
254 #--------------------------------------------------------------------------
255 # Some of the compiled LLVM tools which are used for compilation of runtime
258 LLVMAS := $(LLVMTOOLCURRENT)/llvm-as
261 ###########################################################################
263 ###########################################################################
266 # Include both the project headers and the LLVM headers for compilation and
267 # dependency computation.
269 # BUILD_OBJ_DIR : Files local to the particular object directory
270 # (locallly generated header files).
271 # BUILD_SRC_DIR : Files local to the particular source directory.
272 # BUILD_SRC_ROOT/include : Files global to the project.
273 # LLVM_OBJ_ROOT/include : config.h files generated by autoconf
274 # LEVEL/include : config.h files for the project
275 # LLVM_SRC_ROOT/include : Files global to LLVM.
277 CPPFLAGS += -I$(BUILD_OBJ_DIR) -I$(BUILD_SRC_DIR) -I$(LLVM_OBJ_ROOT)/include \
278 -I$(BUILD_SRC_ROOT)/include -I$(LEVEL)/include \
279 -I$(LLVM_SRC_ROOT)/include
281 # By default, strip symbol information from executable
283 STRIP = $(PLATFORMSTRIPOPTS)
284 STRIP_WARN_MSG = "(without symbols)"
287 # Allow GNU extensions:
288 CPPFLAGS += -D_GNU_SOURCE
289 # Pull in limit macros from stdint.h, even in C++:
290 CPPFLAGS += -D__STDC_LIMIT_MACROS
292 ### FIXME: this is GCC specific
293 CPPFLAGS += -DDEPRECATED='__attribute__ ((deprecated))'
295 CompileCommonOpts := -Wall -W -Wwrite-strings -Wno-unused
296 CompileOptimizeOpts := -O3 -DNDEBUG -finline-functions
299 # Compile commands with libtool.
301 Compile := $(LIBTOOL) --mode=compile $(CXX) -c $(CPPFLAGS) $(CXXFLAGS) $(CompileCommonOpts)
302 CompileC := $(LIBTOOL) --mode=compile $(CC) -c $(CPPFLAGS) $(CFLAGS) $(CompileCommonOpts)
304 # Compile a cpp file, don't link...
305 CompileG := $(Compile) -g -D_DEBUG
306 CompileO := $(Compile) $(CompileOptimizeOpts) -felide-constructors -fomit-frame-pointer
307 CompileP := $(Compile) $(CompileOptimizeOpts) -felide-constructors $(PROFILE)
309 # Compile a c file, don't link...
310 CompileCG := $(CompileC) -g -D_DEBUG
311 CompileCO := $(CompileC) $(CompileOptimizeOpts) -fomit-frame-pointer
312 CompileCP := $(CompileC) $(CompileOptimizeOpts) $(PROFILE)
314 ###########################################################################
316 ###########################################################################
319 # Link final executable
320 # (Note that we always link with the C++ compiler).
322 Link := $(LIBTOOL) --mode=link $(CXX)
324 # link both projlib and llvmlib libraries
325 LinkG := $(Link) -g -L$(PROJLIBDEBUGSOURCE) -L$(LLVMLIBDEBUGSOURCE) $(STRIP)
326 LinkO := $(Link) -O3 -L$(PROJLIBRELEASESOURCE) -L$(LLVMLIBRELEASESOURCE)
327 LinkP := $(Link) -O3 -L$(PROJLIBPROFILESOURCE) -L$(LLVMLIBPROFILESOURCE) $(PROFILE)
329 # TOOLLINKOPTSB to pass options to the linker like library search path etc
330 # Note that this is different from TOOLLINKOPTS, these options
331 # are passed to the linker *before* the USEDLIBS options are passed.
332 # e.g. usage TOOLLINKOPTSB = -L/home/xxx/lib
334 LinkG := $(LinkG) $(TOOLLINKOPTSB)
335 LinkO := $(LinkO) $(TOOLLINKOPTSB)
336 LinkP := $(LinkP) $(TOOLLINKOPTSB)
339 # Create one .o file from a bunch of .o files...
340 Relink := ${LIBTOOL} --mode=link $(CXX)
343 # Configure where the item being compiled should go.
346 Link += -rpath $(DESTLIBCURRENT)
350 Link += -rpath $(DESTTOOLCURRENT)
353 # Create dependency file from CPP file, send to stdout.
354 Depend := $(CXX) -MM -I$(LEVEL)/include $(CPPFLAGS)
355 DependC := $(CC) -MM -I$(LEVEL)/include $(CPPFLAGS)
357 # Archive a bunch of .o files into a .a file...
360 #----------------------------------------------------------
362 # Source includes all of the cpp files, and objects are derived from the
364 # The local Makefile can list other Source files via ExtraSource = ...
367 Source := $(notdir $(ExtraSource) $(wildcard $(SourceDir)/*.cpp \
368 $(SourceDir)/*.cc $(SourceDir)/*.c $(SourceDir)/*.y \
375 Srcs := $(sort $(basename $(Source)))
376 ObjectsO := $(Srcs:%=$(BUILD_OBJ_DIR)/Release/%.lo)
377 ObjectsP := $(Srcs:%=$(BUILD_OBJ_DIR)/Profile/%.lo)
378 ObjectsG := $(Srcs:%=$(BUILD_OBJ_DIR)/Debug/%.lo)
379 ObjectsBC := $(Srcs:%=$(BUILD_OBJ_DIR)/BytecodeObj/%.bc)
382 # The real objects underlying the libtool objects
384 RObjs := $(sort $(patsubst Debug/%.o, %.o, $(addsuffix .o,$(basename $(Source)))))
385 RObjectsO := $(addprefix $(BUILD_OBJ_DIR)/Release/,$(RObjs))
386 RObjectsP := $(addprefix $(BUILD_OBJ_DIR)/Profile/,$(RObjs))
387 RObjectsG := $(addprefix $(BUILD_OBJ_DIR)/Debug/,$(RObjs))
389 #---------------------------------------------------------
390 # Handle the DIRS and PARALLEL_DIRS options
391 #---------------------------------------------------------
394 all install clean test bytecode stripped-bytecode::
395 $(VERB) for dir in ${DIRS}; do \
396 if [ ! -f $$dir/Makefile ]; \
399 cp $(SourceDir)/$$dir/Makefile $$dir/Makefile; \
401 ($(MAKE) -C $$dir $@) || exit 1; \
405 # Handle PARALLEL_DIRS
407 all :: $(addsuffix /.makeall , $(PARALLEL_DIRS))
408 install :: $(addsuffix /.makeinstall , $(PARALLEL_DIRS))
409 clean :: $(addsuffix /.makeclean , $(PARALLEL_DIRS))
410 test :: $(addsuffix /.maketest , $(PARALLEL_DIRS))
411 bytecode :: $(addsuffix /.makebytecode, $(PARALLEL_DIRS))
412 stripped-bytecode :: $(addsuffix /.makestripped-bytecode, $(PARALLEL_DIRS))
414 %/.makeall %/.makeinstall %/.makeclean %/.maketest %/.makebytecode %/.makestripped-bytecode:
415 $(VERB) if [ ! -f $(@D)/Makefile ]; \
418 cp $(SourceDir)/$(@D)/Makefile $(@D)/Makefile; \
420 $(MAKE) -C $(@D) $(subst $(@D)/.make,,$@)
423 # Handle directories that may or may not exist
425 all install clean test bytecode stripped-bytecode::
426 $(VERB) for dir in ${OPTIONAL_DIRS}; do \
427 if [ -d $(SourceDir)/$$dir ]; \
429 if [ ! -f $$dir/Makefile ]; \
432 cp $(SourceDir)/$$dir/Makefile $$dir/Makefile; \
434 ($(MAKE) -C$$dir $@) || exit 1; \
439 ###########################################################################
440 # Library Build Rules:
442 #---------------------------------------------------------
443 # Handle the LIBRARYNAME option - used when building libs...
444 #---------------------------------------------------------
446 # When libraries are built, they are allowed to optionally define the
447 # DONT_BUILD_RELINKED make variable, which, when defined, prevents a .o file
448 # from being built for the library. This .o files may then be linked to by a
449 # tool if the tool does not need (or want) the semantics a .a file provides
450 # (linking in only object files that are "needed"). If a library is never to
451 # be used in this way, it is better to define DONT_BUILD_RELINKED, and define
452 # BUILD_ARCHIVE instead.
454 # Some libraries must be built as .a files (libscalar for example) because if
455 # it's built as a .o file, then all of the constituent .o files in it will be
456 # linked into tools (for example gccas) even if they only use one of the parts
457 # of it. For this reason, sometimes it's useful to use libraries as .a files.
458 ###########################################################################
460 # Install rule for making bytecode library directory if it does not exist.
461 # Trigger this by making libraries that need to be installed here depend on it.
462 $(DESTDIR)$(bytecode_libdir):
467 # Make sure there isn't any extranous whitespace on the LIBRARYNAME option
468 LIBRARYNAME := $(strip $(LIBRARYNAME))
470 LIBNAME_O := $(DESTLIBRELEASE)/lib$(LIBRARYNAME)$(SHLIBEXT)
471 LIBNAME_P := $(DESTLIBPROFILE)/lib$(LIBRARYNAME)$(SHLIBEXT)
472 LIBNAME_G := $(DESTLIBDEBUG)/lib$(LIBRARYNAME)$(SHLIBEXT)
473 LIBNAME_CUR := $(DESTLIBCURRENT)/lib$(LIBRARYNAME)$(SHLIBEXT)
474 LIBNAME_AO := $(DESTLIBRELEASE)/lib$(LIBRARYNAME).a
475 LIBNAME_AP := $(DESTLIBPROFILE)/lib$(LIBRARYNAME).a
476 LIBNAME_AG := $(DESTLIBDEBUG)/lib$(LIBRARYNAME).a
477 LIBNAME_ACUR := $(DESTLIBCURRENT)/lib$(LIBRARYNAME).a
478 LIBNAME_OBJO := $(DESTLIBRELEASE)/$(LIBRARYNAME).o
479 LIBNAME_OBJP := $(DESTLIBPROFILE)/$(LIBRARYNAME).o
480 LIBNAME_OBJG := $(DESTLIBDEBUG)/$(LIBRARYNAME).o
481 LIBNAME_OBJCUR := $(DESTLIBCURRENT)/$(LIBRARYNAME).o
482 LIBNAME_BC := $(DESTLIBBYTECODE)/lib$(LIBRARYNAME).bc
485 #--------------------------------------------------------------------
487 # Modify the top level targets to build the desired libraries.
488 #--------------------------------------------------------------------
490 # dynamic target builds a shared object version of the library...
491 dynamic:: $(LIBNAME_CUR)
492 bytecodelib:: $(LIBNAME_BC)
493 install-bytecode-library:: $(DESTDIR)$(bytecode_libdir)/lib$(LIBRARYNAME).bc
495 $(DESTDIR)$(bytecode_libdir)/lib$(LIBRARYNAME).bc: $(LIBNAME_BC) $(DESTDIR)$(bytecode_libdir)
496 @${ECHO} ======= Installing $(LIBRARYNAME) bytecode library =======
499 # Does the library want a .o version built?
500 ifndef DONT_BUILD_RELINKED
501 all:: $(LIBNAME_OBJCUR)
502 install:: install-single-object-library
505 # Does the library want an archive version built?
507 all:: $(LIBNAME_ACUR)
508 install:: install-archive-library
511 #--------------------------------------------------------------------
512 # Rules for building libraries
513 #--------------------------------------------------------------------
515 LinkBCLib := $(LLVMGCC) -shared -nostdlib
516 ifdef EXPORTED_SYMBOL_LIST
517 LinkBCLib += -Xlinker -internalize-public-api-list=$(EXPORTED_SYMBOL_LIST)
519 ifdef EXPORTED_SYMBOL_FILE
520 LinkBCLib += -Xlinker -internalize-public-api-file=$(EXPORTED_SYMBOL_FILE)
522 LinkBCLib += -Xlinker -disable-internalize
527 # Rule for building bytecode libraries.
528 $(LIBNAME_BC): $(ObjectsBC) $(LibSubDirs) $(DESTLIBBYTECODE)/.dir
529 @${ECHO} Linking $(LIBRARYNAME) bytecode library
530 $(VERB) $(LinkBCLib) -o $@ $(ObjectsBC) $(LibSubDirs) $(LibLinkOpts)
531 @${ECHO} ======= Finished building $(LIBRARYNAME) bytecode library =======
533 # Rules for building dynamically linked libraries.
535 $(LIBNAME_O): $(ObjectsO) $(LibSubDirs) $(DESTLIBRELEASE)/.dir
536 @${ECHO} Linking $(LIBRARYNAME) dynamic release library
537 $(VERB) $(Link) -o $*.la $(ObjectsO) $(LibSubDirs) $(LibLinkOpts)
538 $(VERB) $(LIBTOOL) --mode=install $(INSTALL) $*.la $(DESTLIBCURRENT)
539 @${ECHO} ======= Finished building $(LIBRARYNAME) dynamic release library =======
541 $(LIBNAME_P): $(ObjectsP) $(LibSubDirs) $(DESTLIBPROFILE)/.dir
542 @${ECHO} Linking $(LIBRARYNAME) dynamic profile library
543 $(VERB) $(Link) -o $*.la $(ObjectsP) $(LibSubDirs) $(LibLinkOpts)
544 $(VERB) $(LIBTOOL) --mode=install $(INSTALL) $*.la $(DESTLIBCURRENT)
545 @${ECHO} ======= Finished building $(LIBRARYNAME) dynamic profile library =======
547 $(LIBNAME_G): $(ObjectsG) $(LibSubDirs) $(DESTLIBDEBUG)/.dir
548 @${ECHO} Linking $(LIBRARYNAME) dynamic debug library
549 $(VERB) $(Link) -o $*.la $(ObjectsG) $(LibSubDirs) $(LibLinkOpts)
550 $(VERB) $(LIBTOOL) --mode=install $(INSTALL) $*.la $(DESTLIBCURRENT)
551 @${ECHO} ======= Finished building $(LIBRARYNAME) dynamic debug library =======
553 install-dynamic-library: $(LIBNAME_CUR)
554 $(MKDIR) $(DESTDIR)$(libdir)
555 $(VERB) $(LIBTOOL) --mode=install $(INSTALL) $(LIBNAME_CUR) $(DESTDIR)$(libdir)/lib$(LIBRARYNAME)$(SHLIBEXT)
558 # Rules for building static archive libraries.
560 $(LIBNAME_AO): $(ObjectsO) $(LibSubDirs) $(DESTLIBRELEASE)/.dir
561 @${ECHO} Linking $(LIBRARYNAME) archive release library
563 $(VERB) $(Link) -03 -o $@ $(ObjectsO) $(LibSubDirs) -static
564 @${ECHO} Finished building $(LIBRARYNAME) archive release library =======
566 $(LIBNAME_AP): $(ObjectsP) $(LibSubDirs) $(DESTLIBPROFILE)/.dir
567 @${ECHO} Linking $(LIBRARYNAME) archive profile library
569 $(VERB) $(Link) -03 $(PROFILE) -o $@ $(ObjectsP) $(LibSubDirs) -static
570 @${ECHO} ======= Finished building $(LIBRARYNAME) archive profile library =======
572 $(LIBNAME_AG): $(ObjectsG) $(LibSubDirs) $(DESTLIBDEBUG)/.dir
573 @${ECHO} Linking $(LIBRARYNAME) archive debug library
575 $(VERB) $(Link) -g $(STRIP) -o $@ $(ObjectsG) $(LibSubDirs) -static
576 @${ECHO} ======= Finished building $(LIBRARYNAME) archive debug library =======
578 install-archive-library: $(LIBNAME_ACUR)
579 $(MKDIR) $(DESTDIR)$(libdir)
580 $(VERB) $(LIBTOOL) --mode=install $(INSTALL) $(LIBNAME_ACUR) $(DESTDIR)$(libdir)/lib$(LIBRARYNAME).a
583 # Rules for building .o libraries.
586 # Note that for this special case, we specify the actual object files
587 # instead of their libtool counterparts. This is because libtool
588 # doesn't want to generate a reloadable object file unless it is given
589 # .o files explicitly.
591 # Note that we're making an assumption here: If we build a .lo file,
592 # it's corresponding .o file will be placed in the same directory.
594 # I think that is safe.
596 $(LIBNAME_OBJO): $(ObjectsO) $(LibSubDirs) $(DESTLIBRELEASE)/.dir
597 @${ECHO} "Linking `basename $@`"
598 $(VERB) $(Relink) -o $@ $(RObjectsO) $(LibSubDirs)
600 $(LIBNAME_OBJP): $(ObjectsP) $(LibSubDirs) $(DESTLIBPROFILE)/.dir
601 @${ECHO} "Linking `basename $@`"
602 $(VERB) $(Relink) -o $@ $(RObjectsP) $(LibSubDirs)
604 $(LIBNAME_OBJG): $(ObjectsG) $(LibSubDirs) $(DESTLIBDEBUG)/.dir
605 @${ECHO} "Linking `basename $@`"
606 $(VERB) $(Relink) -o $@ $(RObjectsG) $(LibSubDirs)
608 install-single-object-library: $(LIBNAME_OBJCUR)
609 $(MKDIR) $(DESTDIR)$(libdir)
610 $(VERB) $(LIBTOOL) --mode=install $(INSTALL) $(LIBNAME_OBJCUR) $(DESTDIR)$(libdir)/$(LIBRARYNAME).o
614 #------------------------------------------------------------------------
615 # Handle the TOOLNAME option - used when building tool executables...
616 #------------------------------------------------------------------------
618 # The TOOLNAME option should be used with a USEDLIBS variable that tells the
619 # libraries (and the order of the libs) that should be linked to the
620 # tool. USEDLIBS should contain a list of library names (some with .a extension)
621 # that are automatically linked in as .o files unless the .a suffix is added.
625 # TOOLEXENAME* - These compute the output filenames to generate...
626 TOOLEXENAME_G := $(DESTTOOLDEBUG)/$(TOOLNAME)
627 TOOLEXENAME_O := $(DESTTOOLRELEASE)/$(TOOLNAME)
628 TOOLEXENAME_P := $(DESTTOOLPROFILE)/$(TOOLNAME)
629 TOOLEXENAMES := $(DESTTOOLCURRENT)/$(TOOLNAME)
631 # USED_LIBS_OPTIONS - Compute the options line that add -llib1 -llib2, etc.
632 PROJ_LIBS_OPTIONS := $(patsubst %.a.o, -l%, $(addsuffix .o, $(USEDLIBS)))
633 PROJ_LIBS_OPTIONS_G := $(patsubst %.o, $(PROJLIBDEBUGSOURCE)/%.o, $(PROJ_LIBS_OPTIONS))
634 PROJ_LIBS_OPTIONS_O := $(patsubst %.o, $(PROJLIBRELEASESOURCE)/%.o,$(PROJ_LIBS_OPTIONS))
635 PROJ_LIBS_OPTIONS_P := $(patsubst %.o, $(PROJLIBPROFILESOURCE)/%.o,$(PROJ_LIBS_OPTIONS))
637 LLVM_LIBS_OPTIONS := $(patsubst %.a.o, -l%, $(addsuffix .o, $(LLVMLIBS)))
638 LLVM_LIBS_OPTIONS_G := $(patsubst %.o, $(LLVMLIBDEBUGSOURCE)/%.o, $(LLVM_LIBS_OPTIONS))
639 LLVM_LIBS_OPTIONS_O := $(patsubst %.o, $(LLVMLIBRELEASESOURCE)/%.o,$(LLVM_LIBS_OPTIONS))
640 LLVM_LIBS_OPTIONS_P := $(patsubst %.o, $(LLVMLIBPROFILESOURCE)/%.o,$(LLVM_LIBS_OPTIONS))
642 LIB_OPTS_G := $(LLVM_LIBS_OPTIONS_G) $(PROJ_LIBS_OPTIONS_G)
643 LIB_OPTS_O := $(LLVM_LIBS_OPTIONS_O) $(PROJ_LIBS_OPTIONS_O)
644 LIB_OPTS_P := $(LLVM_LIBS_OPTIONS_P) $(PROJ_LIBS_OPTIONS_P)
646 # USED_LIB_PATHS - Compute the path of the libraries used so that tools are
647 # rebuilt if libraries change. This has to make sure to handle .a/.so and .o
650 STATICUSEDLIBS := $(patsubst %.a.o, lib%.a, $(addsuffix .o, $(USEDLIBS)))
651 USED_LIB_PATHS_G := $(addprefix $(DESTLIBDEBUG)/, $(STATICUSEDLIBS))
652 USED_LIB_PATHS_O := $(addprefix $(DESTLIBRELEASE)/, $(STATICUSEDLIBS))
653 USED_LIB_PATHS_P := $(addprefix $(DESTLIBPROFILE)/, $(STATICUSEDLIBS))
656 # Libtool link options:
657 # Ensure that all binaries have their symbols exported so that they can
660 LINK_OPTS := -export-dynamic $(TOOLLINKOPTS)
666 # Tell make that we need to rebuild subdirectories before we can link the tool.
667 # This affects things like LLI which has library subdirectories.
668 $(USED_LIB_PATHS_G) $(USED_LIB_PATHS_O) $(USED_LIB_PATHS_P): \
669 $(addsuffix /.makeall, $(PARALLEL_DIRS))
671 all:: $(TOOLEXENAMES)
674 $(VERB) $(RM) -f $(TOOLEXENAMES)
676 $(TOOLEXENAME_G): $(ObjectsG) $(USED_LIB_PATHS_G) $(DESTTOOLDEBUG)/.dir
677 @${ECHO} Linking $(TOOLNAME) debug executable $(STRIP_WARN_MSG)
678 $(VERB) $(LinkG) -o $@ $(ObjectsG) $(LIB_OPTS_G) $(LINK_OPTS) $(LIBS)
679 @${ECHO} ======= Finished building $(TOOLNAME) debug executable $(STRIP_WARN_MSG) =======
681 $(TOOLEXENAME_O): $(ObjectsO) $(USED_LIB_PATHS_O) $(DESTTOOLRELEASE)/.dir
682 @${ECHO} Linking $(TOOLNAME) release executable
683 $(VERB) $(LinkO) -o $@ $(ObjectsO) $(LIB_OPTS_O) $(LINK_OPTS) $(LIBS)
684 @${ECHO} ======= Finished building $(TOOLNAME) release executable =======
686 $(TOOLEXENAME_P): $(ObjectsP) $(USED_LIB_PATHS_P) $(DESTTOOLPROFILE)/.dir
687 @${ECHO} Linking $(TOOLNAME) profile executable
688 $(VERB) $(LinkP) -o $@ $(ObjectsP) $(LIB_OPTS_P) $(LINK_OPTS) $(LIBS)
689 @${ECHO} ======= Finished building $(TOOLNAME) profile executable =======
691 install:: $(TOOLEXENAMES)
692 $(MKDIR) $(DESTDIR)$(bindir)
693 $(LIBTOOL) --mode=install $(INSTALL_PROGRAM) -c -m 0755 $(TOOLEXENAMES) $(DESTDIR)$(bindir)/$(TOOLNAME)
699 #---------------------------------------------------------
700 .PRECIOUS: $(BUILD_OBJ_DIR)/Depend/.dir $(BUILD_OBJ_DIR)/BytecodeObj/.dir
701 .PRECIOUS: $(BUILD_OBJ_DIR)/Debug/.dir $(BUILD_OBJ_DIR)/Release/.dir
703 # Create .lo files in the ObjectFiles directory from the .cpp and .c files...
704 $(BUILD_OBJ_DIR)/Release/%.lo: %.cpp $(BUILD_OBJ_DIR)/Release/.dir
705 @${ECHO} "Compiling `basename $<`"
706 $(VERB) $(CompileO) $< -o $@
708 $(BUILD_OBJ_DIR)/Release/%.lo: %.c $(BUILD_OBJ_DIR)/Release/.dir
709 @${ECHO} "Compiling `basename $<`"
710 $(VERB) $(CompileCO) $< -o $@
712 $(BUILD_OBJ_DIR)/Profile/%.lo: %.cpp $(BUILD_OBJ_DIR)/Profile/.dir
713 @${ECHO} "Compiling `basename $<`"
714 $(VERB) $(CompileP) $< -o $@
716 $(BUILD_OBJ_DIR)/Profile/%.lo: %.c $(BUILD_OBJ_DIR)/Profile/.dir
717 @${ECHO} "Compiling `basename $<`"
718 $(VERB) $(CompileCP) $< -o $@
720 $(BUILD_OBJ_DIR)/Debug/%.lo: %.cpp $(BUILD_OBJ_DIR)/Debug/.dir
721 @${ECHO} "Compiling `basename $<`"
722 $(VERB) $(CompileG) $< -o $@
724 $(BUILD_OBJ_DIR)/Debug/%.lo: %.c $(BUILD_OBJ_DIR)/Debug/.dir
725 @${ECHO} "Compiling `basename $<`"
726 $(VERB) $(CompileCG) $< -o $@
728 $(BUILD_OBJ_DIR)/BytecodeObj/%.bc: %.cpp $(BUILD_OBJ_DIR)/BytecodeObj/.dir $(LCC1XX)
729 @${ECHO} "Compiling `basename $<` to bytecode"
730 $(VERB) $(LLVMGXX) $(CompileCommonOpts) $(CPPFLAGS) -c $< -o $@
732 $(BUILD_OBJ_DIR)/BytecodeObj/%.bc: %.c $(BUILD_OBJ_DIR)/BytecodeObj/.dir $(LCC1)
733 @${ECHO} "Compiling `basename $<` to bytecode"
734 $(VERB) $(LLVMGCC) $(CompileCommonOpts) $(CPPFLAGS) -c $< -o $@
736 $(BUILD_OBJ_DIR)/BytecodeObj/%.bc: %.ll $(BUILD_OBJ_DIR)/BytecodeObj/.dir $(LLVMAS)
737 @${ECHO} "Compiling `basename $<` to bytecode"
738 $(VERB) $(LLVMAS) $< -f -o $@
742 # Rules for building lex/yacc files
744 LEX_FILES = $(filter %.l, $(Source))
745 LEX_OUTPUT = $(LEX_FILES:%.l=%.cpp)
746 YACC_FILES = $(filter %.y, $(Source))
747 YACC_OUTPUT = $(addprefix $(YACC_FILES:%.y=%), .h .cpp .output)
748 .PRECIOUS: $(LEX_OUTPUT) $(YACC_OUTPUT)
750 # Create a .cpp source file from a flex input file... this uses sed to cut down
751 # on the warnings emited by GCC...
753 # The last line is a gross hack to work around flex aparently not being able to
754 # resize the buffer on a large token input. Currently, for uninitialized string
755 # buffers in LLVM we can generate very long tokens, so this is a hack around it.
756 # FIXME. (f.e. char Buffer[10000] )
760 $(VERB) $(FLEX) -t $< | \
761 $(SED) '/^find_rule/d' | \
762 $(SED) 's/void yyunput/inline void yyunput/' | \
763 $(SED) 's/void \*yy_flex_realloc/inline void *yy_flex_realloc/' | \
764 $(SED) 's/#define YY_BUF_SIZE 16384/#define YY_BUF_SIZE (16384*64)/' \
766 $(VERB) cmp -s $@ $@.tmp > /dev/null || ${MV} -f $@.tmp $@
767 @# remove the output of flex if it didn't get moved over...
770 # Rule for building the bison parsers...
771 %.c: %.y # Cancel built-in rules for yacc
772 %.h: %.y # Cancel built-in rules for yacc
774 @${ECHO} "Bisoning `basename $<`"
775 $(VERB) $(BISON) -v -d -p $(<F:%Parser.y=%) -o $*.tab.c $<
776 $(VERB) cmp -s $*.tab.c $*.cpp > /dev/null || ${MV} -f $*.tab.c $*.cpp
777 $(VERB) cmp -s $*.tab.h $*.h > /dev/null || ${MV} -f $*.tab.h $*.h
778 @# If the files were not updated, don't leave them lying around...
779 @rm -f $*.tab.c $*.tab.h
781 # To create the directories...
783 $(VERB) ${MKDIR} $* > /dev/null
786 # To create postscript files from dot files...
789 ${DOT} -Tps < $< > $@
792 ${ECHO} "Cannot build $@: The program dot is not installed"
796 # This rules ensures that header files that are removed still have a rule for
797 # which they can be "generated." This allows make to ignore them and
798 # reproduce the dependency lists.
802 # 'make clean' nukes the tree
804 $(VERB) $(RM) -rf $(BUILD_OBJ_DIR)/Debug $(BUILD_OBJ_DIR)/Release
805 $(VERB) $(RM) -rf $(BUILD_OBJ_DIR)/Profile $(BUILD_OBJ_DIR)/Depend
806 $(VERB) $(RM) -rf $(BUILD_OBJ_DIR)/BytecodeObj
807 $(VERB) $(RM) -f core core.[0-9][0-9]* *.o *.d *~ *.flc
808 ifneq ($(strip $(SHLIBEXT)),) # Extra paranoia - make real sure SHLIBEXT is set
809 $(VERB) $(RM) -f *$(SHLIBEXT)
811 $(VERB) $(RM) -f $(LEX_OUTPUT) $(YACC_OUTPUT)
813 ###########################################################################
815 # Define variables and rules that generate header file dependencies
816 # from C/C++ source files.
817 ###########################################################################
819 ifndef DISABLE_AUTO_DEPENDENCIES
821 # If dependencies were generated for the file that included this file,
822 # include the dependencies now...
824 SourceBaseNames := $(basename $(Source))
825 SourceDepend := $(SourceBaseNames:%=$(BUILD_OBJ_DIR)/Depend/%.d)
827 # Create dependencies for the *.cpp files...
828 $(BUILD_OBJ_DIR)/Depend/%.d: %.cpp $(BUILD_OBJ_DIR)/Depend/.dir
829 $(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' > $@
831 # Create dependencies for the *.c files...
832 $(BUILD_OBJ_DIR)/Depend/%.d: %.c $(BUILD_OBJ_DIR)/Depend/.dir
833 $(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' > $@
836 # Autoconf Dependencies.
838 $(LLVM_OBJ_ROOT)/config.status:: $(LLVM_SRC_ROOT)/configure
839 @${ECHO} "****************************************************************"
840 @${ECHO} " You need to re-run $(LLVM_SRC_ROOT)/configure"
841 @${ECHO} " in directory $(LLVM_OBJ_ROOT)"
842 @${ECHO} "****************************************************************"
845 # If the Makefile in the source tree has been updated, copy it over into the
847 Makefile :: $(BUILD_SRC_DIR)/Makefile
848 @${ECHO} "===== Updating Makefile from source dir: `dirname $<` ====="
853 # Include dependencies generated from C/C++ source files, but not if we
854 # are cleaning (this example taken from the GNU Make Manual).
856 ifneq ($(MAKECMDGOALS),clean)
857 ifneq ($(MAKECMDGOALS),distclean)
858 -include /dev/null $(SourceDepend)
862 endif # ifndef DISABLE_AUTO_DEPENDENCIES