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 BUILT_SOURCES variable
36 # 6. LLVM_SRC_ROOT - If specified, points to the top of the LLVM source tree.
38 # 8. BUILD_SRC_DIR - The directory which contains the current set of Makefiles
39 # and usually the source code too (unless SourceDir is set).
41 # 9. BUILD_SRC_ROOT - The root directory of the source code being compiled.
43 # 10. BUILD_OBJ_DIR - The directory where object code should be placed.
45 # 11. BUILD_OBJ_ROOT - The root directory for where object code should be
49 # LLVM, LLVM_SRC_ROOT = BUILD_SRC_ROOT
51 #===-----------------------------------------------------------------------====
54 # Set the VPATH so that we can find source files.
56 VPATH=$(BUILD_SRC_DIR)
58 ###########################################################################
60 # The following targets are the standard top level targets for
62 ###########################################################################
65 # Ensure all preconditions are met
68 # Make sure all the user-target rules are double colon rules
71 install :: preconditions
72 uninstall :: preconditions
75 distcheck:: preconditions
76 distclean:: preconditions
79 ###########################################################################
80 # Suffixes and implicit rules:
81 # Empty out the list of suffixes, generate a list that is only
82 # used by this Makefile, and cancel useless implicit rules. This
83 # will hopefully speed up compilation a little bit.
84 ###########################################################################
86 .SUFFIXES: .c .cpp .h .hpp .y .l
87 .SUFFIXES: .lo .o .a $(SHLIBEXT) .bc .td
88 .SUFFIXES: .ps .dot .d
91 # Mark all of these targets as phony. This will hopefully speed up builds
92 # slightly since GNU Make will not try to find implicit rules for targets
93 # which are marked as Phony.
95 ALL_TARGETS= all dynamic bytecodelib install-bytecode-library clean distclean install test bytecode prdirs
96 .PHONY: $(ALL_TARGETS) preconditions
98 ###########################################################################
99 # Miscellaneous paths and commands:
100 # This section defines various configuration macros, such as where
101 # to find burg, tblgen, and libtool.
102 ###########################################################################
104 #--------------------------------------------------------------------
105 # Variables derived from configuration options...
106 #--------------------------------------------------------------------
108 ifdef ENABLE_PROFILING
109 CONFIGURATION := Profile
110 CXXFLAGS += -O3 -DNDEBUG -felide-constructors -finline-functions -pg
111 CFLAGS += -O3 -DNDEBUG -pg
112 LDFLAGS += -O3 -DNDEBUG -pg
114 ifdef ENABLE_OPTIMIZED
115 CONFIGURATION := Release
116 CXXFLAGS += -O3 -DNDEBUG -finline-functions -felide-constructors -fomit-frame-pointer
117 CFLAGS += -O3 -DNDEBUG -fomit-frame-pointer
118 LDFLAGS += -O3 -DNDEBUG
120 CONFIGURATION := Debug
121 CXXFLAGS += -g -D_DEBUG
122 CFLAGS += -g -D_DEBUG
123 LDFLAGS += -g -D_DEBUG
129 #------------------------------------------------------------------------------
130 # Directory locations
131 OBJDIR := $(BUILD_OBJ_DIR)/$(CONFIGURATION)
132 LIBDIR := $(BUILD_OBJ_ROOT)/lib/$(CONFIGURATION)
133 TOOLDIR := $(BUILD_OBJ_ROOT)/tools/$(CONFIGURATION)
134 LLVMLIBDIR := $(LLVM_OBJ_ROOT)/lib/$(CONFIGURATION)
135 LLVMTOOLDIR := $(LLVM_OBJ_ROOT)/tools/$(CONFIGURATION)
137 #------------------------------------------------------------------------------
138 # Full Paths To Compiled Tools and Utilities
139 LIBTOOL := $(LLVM_OBJ_ROOT)/mklib
140 LLVMAS := $(LLVMTOOLDIR)/llvm-as$(EXEEXT)
141 BURG := $(LLVMTOOLDIR)/burg$(EXEEXT)
142 TBLGEN := $(LLVMTOOLDIR)/tblgen$(EXEEXT)
143 GCCLD := $(LLVMTOOLDIR)/gccld$(EXEEXT)
144 LLVMGCC := PATH=$(LLVMTOOLDIR):$(PATH) $(LLVMGCCDIR)/bin/gcc
145 LLVMGXX := PATH=$(LLVMTOOLDIR):$(PATH) $(LLVMGCCDIR)/bin/g++
147 # Need a better way to compute this.
148 LLVMGCCLIBDIR := $(dir $(shell $(LLVMGCC) -print-file-name=libgcc.a))/
150 #------------------------------------------------------------------------------
151 # Adjust to user's request
153 ifndef SHARED_LIBRARY
154 LIBTOOL += --tag=disable-shared
156 LDFLAGS += -rpath $(LIBDIR)
165 AR += >/dev/null 2>/dev/null
168 # By default, strip symbol information from executable
170 STRIP = $(PLATFORMSTRIPOPTS)
171 STRIP_WARN_MSG = "(without symbols)"
175 LDFLAGS += -rpath $(TOOLDIR) -export-dynamic $(TOOLLINKOPTS)
178 # TOOLLINKOPTSB to pass options to the linker like library search path etc
179 # Note that this is different from TOOLLINKOPTS, these options
180 # are passed to the linker *before* the USEDLIBS options are passed.
181 # e.g. usage TOOLLINKOPTSB = -L/home/xxx/lib
183 LDFLAGS += $(TOOLLINKOPTSB)
186 LDFLAGS += -L$(LIBDIR) -L$(LLVMLIBDIR)
188 #------------------------------------------------------------------------------
189 # Options To Invoke Tools
191 CompileCommonOpts := -Wall -W -Wwrite-strings -Wno-unused
193 CPPFLAGS += -I$(BUILD_OBJ_DIR) \
195 -I$(BUILD_SRC_ROOT)/include \
196 -I$(BUILD_OBJ_ROOT)/include \
197 -I$(LLVM_OBJ_ROOT)/include \
198 -I$(LLVM_SRC_ROOT)/include \
199 -D_GNU_SOURCE -D__STDC_LIMIT_MACROS
201 CXXCompile := $(CXX) $(CPPFLAGS) $(CompileCommonOpts) $(CXXFLAGS) -c
202 LTCXXCompile := $(LIBTOOL) --tag=CXX --mode=compile $(CXXCompile)
203 CCompile := $(CC) $(CPPFLAGS) $(CompileCommonOpts) -c $(CFLAGS)
204 LTCCompile := $(LIBTOOL) --mode=compile $(CCompile)
205 BCCXXCompile := $(LLVMGXX) $(CPPFLAGS) $(CompileCommonOpts) $(CXXFLAGS) -c
206 BCCCompile := $(LLVMGCC) $(CPPFLAGS) $(CompileCommonOpts) $(CFLAGS) -c
207 Link := $(LIBTOOL) --tag=CXX --mode=link $(CXX) $(CPPFLAGS) $(CompileCommonOpts) $(LDFLAGS) $(STRIP)
208 Relink := $(LIBTOOL) --tag=CXX --mode=link $(CXX)
209 BCLinkLib := $(LLVMGCC) -shared -nostdlib
210 Burg := $(BURG) -I $(BUILD_SRC_DIR)
211 TableGen := $(TBLGEN) -I $(BUILD_SRC_DIR)
212 Archive := $(AR) $(ARFLAGS)
219 #----------------------------------------------------------
220 # Source includes all of the cpp files, and objects are derived from the
222 # The local Makefile can list other Source files via BUILT_SOURCES = ...
226 Source := $(notdir $(wildcard $(BUILD_SRC_DIR)/*.cpp \
227 $(BUILD_SRC_DIR)/*.cc $(BUILD_SRC_DIR)/*.c $(BUILD_SRC_DIR)/*.y \
228 $(BUILD_SRC_DIR)/*.l))
232 Source += $(filter %.cpp %.c %.cc %.y %.l,$(BUILT_SOURCES))
238 Srcs := $(sort $(basename $(Source)))
239 ObjectsO := $(Srcs:%=$(OBJDIR)/%.o)
240 ObjectsLO := $(Srcs:%=$(OBJDIR)/%.lo)
241 ObjectsBC := $(Srcs:%=$(OBJDIR)/%.bc)
243 #---------------------------------------------------------
244 # Handle the DIRS and PARALLEL_DIRS options
245 #---------------------------------------------------------
249 $(VERB) for dir in $(DIRS); do \
250 if [ ! -f $$dir/Makefile ]; then \
252 cp $(BUILD_SRC_DIR)/$$dir/Makefile $$dir/Makefile; \
254 ($(MAKE) -C $$dir $@ $(MFLAGS)) || exit 1; \
258 # Handle PARALLEL_DIRS
260 all :: $(addsuffix /.makeall , $(PARALLEL_DIRS))
261 install :: $(addsuffix /.makeinstall , $(PARALLEL_DIRS))
262 clean :: $(addsuffix /.makeclean , $(PARALLEL_DIRS))
263 test :: $(addsuffix /.maketest , $(PARALLEL_DIRS))
264 bytecode :: $(addsuffix /.makebytecode, $(PARALLEL_DIRS))
265 stripped-bytecode :: $(addsuffix /.makestripped-bytecode, $(PARALLEL_DIRS))
266 install-bytecode :: $(addsuffix /.makeinstall-bytecode, $(PARALLEL_DIRS))
268 %/.makeall %/.makeinstall %/.makeclean %/.maketest %/.makebytecode %/.makestripped-bytecode %/.makeinstall-bytecode:
269 $(VERB) if [ ! -f $(@D)/Makefile ]; then \
271 cp $(BUILD_SRC_DIR)/$(@D)/Makefile $(@D)/Makefile; \
273 $(MAKE) -C $(@D) $(subst $(@D)/.make,,$@) $(MFLAGS)
276 # Handle directories that may or may not exist
279 $(VERB) for dir in $(OPTIONAL_DIRS); do \
280 if [ -d $(BUILD_SRC_DIR)/$$dir ]; then\
281 if [ ! -f $$dir/Makefile ]; then \
283 cp $(BUILD_SRC_DIR)/$$dir/Makefile $$dir/Makefile; \
285 ($(MAKE) -C$$dir $@ $(MFLAGS)) || exit 0; \
290 #---------------------------------------------------------
291 # Handle the CONFIG_FILES options
292 #---------------------------------------------------------
294 install:: install-config-files
297 $(MKDIR) $(sysconfdir)
299 install-config-files: $(sysconfdir) $(CONFIG_FILES)
300 $(VERB)$(ECHO) Installing Configuration Files To $(sysconfdir)
301 $(VERB)for file in $(CONFIG_FILES); do \
302 $(INSTALL) $(BUILD_SRC_DIR)/$${file} $(sysconfdir) ; \
306 ###########################################################################
307 # Library Build Rules:
309 #---------------------------------------------------------
310 # Handle the LIBRARYNAME option - used when building libs...
311 #---------------------------------------------------------
313 # When libraries are built, they are allowed to optionally define the
314 # DONT_BUILD_RELINKED make variable, which, when defined, prevents a .o file
315 # from being built for the library. This .o files may then be linked to by a
316 # tool if the tool does not need (or want) the semantics a .a file provides
317 # (linking in only object files that are "needed"). If a library is never to
318 # be used in this way, it is better to define DONT_BUILD_RELINKED, and define
319 # BUILD_ARCHIVE instead.
321 # Some libraries must be built as .a files (libscalar for example) because if
322 # it's built as a .o file, then all of the constituent .o files in it will be
323 # linked into tools (for example gccas) even if they only use one of the parts
324 # of it. For this reason, sometimes it's useful to use libraries as .a files.
325 ###########################################################################
327 # Install rule for making bytecode library directory if it does not exist.
328 # Trigger this by making libraries that need to be installed here depend on it.
329 $(DESTDIR)$(bytecode_libdir):
334 # Make sure there isn't any extranous whitespace on the LIBRARYNAME option
335 LIBRARYNAME := $(strip $(LIBRARYNAME))
336 LIBNAME_LA := $(LIBDIR)/lib$(LIBRARYNAME).la
337 LIBNAME_A := $(LIBDIR)/lib$(LIBRARYNAME).a
338 LIBNAME_O := $(LIBDIR)/$(LIBRARYNAME).o
339 LIBNAME_BC := $(LIBDIR)/lib$(LIBRARYNAME).bc
341 #-------------------------------------------------------------------------------
342 # Shared Library Targets
343 # Modify the top level targets to build the desired libraries.
344 #-------------------------------------------------------------------------------
346 # Does the library want a shared library version built?
351 $(LIBNAME_LA): $(BUILT_SOURCES) $(ObjectsLO) $(LIBDIR)/.dir
352 @$(ECHO) Linking shared library $(notdir $@)
353 $(VERB) $(Link) -o $@ $(ObjectsLO)
354 $(VERB) $(LIBTOOL) --mode=install $(INSTALL) $@ $(LIBDIR)
355 @$(ECHO) Finished linking shared library $(LIBRARYNAME).la
357 $(VERB) $(RM) -f $(LIBNAME_LA)
359 install:: $(DESTDIR)$(libdir)/lib$(LIBRARYNAME)$(SHLIBEXT)
361 $(DESTDIR)/lib/lib$(LIBRARYNAME)$(SHLIBEXT): $(LIBNAME_LA)
362 @$(ECHO) Installing shared library $(notdir $@)
363 $(VERB) $(MKDIR) $(DESTDIR)
364 $(VERB) $(LIBTOOL) --mode=install $(INSTALL) $(LIBNAME_LA) $(DESTDIR)$(libdir)/lib$(LIBRARYNAME)$(SHLIBEXT)
365 $(VERB) $(LIBTOOL) --finish $(DESTDIR)$(libdir)
368 # Does the library want a bytecode version built?
369 ifdef BYTECODE_LIBRARY
371 ifdef EXPORTED_SYMBOL_LIST
372 BCLinkLib += -Xlinker -internalize-public-api-list=$(EXPORTED_SYMBOL_LIST)
374 ifdef EXPORTED_SYMBOL_FILE
375 BCLinkLib += -Xlinker -internalize-public-api-file=$(EXPORTED_SYMBOL_FILE)
377 BCLinkLib += -Xlinker -disable-internalize
383 $(LIBNAME_BC): $(BUILT_SOURCES) $(ObjectsBC) $(LIBDIR)/.dir
384 @$(ECHO) Linking bytecode library $(notdir $@)
385 $(VERB) $(BCLinkLib) -o $@ $(ObjectsBC)
388 $(VERB) $(RM) -f $(LIBNAME_BC)
390 install:: $(DESTDIR)$(bytecode_libdir)/lib$(LIBRARYNAME).bc
392 $(DESTDIR)$(bytecode_libdir)/lib$(LIBRARYNAME).bc: $(LIBNAME_BC) $(DESTDIR)$(bytecode_libdir)
393 @$(ECHO) Installing bytecode library $(notdir $@)
394 $(VERB)$(INSTALL) $< $@
398 # Does the library want a .o version built?
399 ifndef DONT_BUILD_RELINKED
402 $(LIBNAME_O): $(BUILT_SOURCES) $(ObjectsO) $(LIBDIR)/.dir
403 @$(ECHO) Linking object $(notdir $@)
404 $(VERB) $(Relink) -o $@ $(ObjectsO)
406 install:: $(DESTDIR)$(libdir)/$(LIBRARYNAME).o
408 $(DESTDIR)$(libdir)/$(LIBRARYNAME).o: $(LIBNAME_O)
409 @$(ECHO) Installing object library $(notdir $@)
410 $(VERB) $(MKDIR) $(DESTDIR)$(libdir)
411 $(VERB) $(LIBTOOL) --mode=install $(INSTALL) $(LIBNAME_O) $(DESTDIR)$(libdir)/$(LIBRARYNAME).o
414 $(VERB) $(RM) -f $(LIBNAME_O)
418 # Does the library want an archive version built?
422 $(LIBNAME_A): $(BUILT_SOURCES) $(ObjectsO) $(LIBDIR)/.dir
423 @$(ECHO) Linking archive $(notdir $@) library
425 $(VERB) $(Archive) $@ $(ObjectsO)
429 $(VERB) $(RM) -f $(LIBNAME_A)
431 install:: $(DESTDIR)$(libdir)/lib$(LIBRARYNAME).a
433 $(DESTDIR)$(libdir)/lib$(LIBRARYNAME).a: $(LIBNAME_A)
434 $(MKDIR) $(DESTDIR)$(libdir)
435 $(VERB) $(LIBTOOL) --mode=install $(INSTALL) $(LIBNAME_A) $(DESTDIR)$(libdir)/lib$(LIBRARYNAME).a
441 #------------------------------------------------------------------------
442 # Handle the TOOLNAME option - used when building tool executables...
443 #------------------------------------------------------------------------
445 # The TOOLNAME option should be used with a USEDLIBS variable that tells the
446 # libraries (and the order of the libs) that should be linked to the
447 # tool. USEDLIBS should contain a list of library names (some with .a extension)
448 # that are automatically linked in as .o files unless the .a suffix is added.
452 # TOOLLINKOPTSB to pass options to the linker like library search path etc
453 # Note that this is different from TOOLLINKOPTS, these options
454 # are passed to the linker *before* the USEDLIBS options are passed.
455 # e.g. usage TOOLLINKOPTSB = -L/home/xxx/lib
457 Link += $(TOOLLINKOPTSB)
460 # TOOLEXENAME* - These compute the output filenames to generate...
461 TOOLEXENAME := $(TOOLDIR)/$(TOOLNAME)
463 # USED_LIBS_OPTIONS - Compute the options line that add -llib1 -llib2, etc.
464 PROJ_LIBS_OPTIONS := $(patsubst %.a.o, -l%, $(addsuffix .o, $(USEDLIBS)))
465 PROJ_LIBS_OPTIONS := $(patsubst %.o, $(LIBDIR)/%.o, $(PROJ_LIBS_OPTIONS))
466 LLVM_LIBS_OPTIONS := $(patsubst %.a.o, -l%, $(addsuffix .o, $(LLVMLIBS)))
467 LLVM_LIBS_OPTIONS := $(patsubst %.o, $(LLVMLIBDIR)/%.o, $(LLVM_LIBS_OPTIONS))
469 PROJ_USED_LIBS := $(patsubst %.a.o, lib%.a, $(addsuffix .o, $(USEDLIBS)))
470 LLVM_USED_LIBS := $(patsubst %.a.o, lib%.a, $(addsuffix .o, $(LLVMLIBS)))
471 PROJ_LIBS_PATHS := $(addprefix $(LIBDIR)/,$(PROJ_USED_LIBS))
472 LLVM_LIBS_PATHS := $(addprefix $(LLVMLIBDIR)/,$(LLVM_USED_LIBS))
474 LINK_OPTS := $(TOOLLINKOPTS) $(PROJ_LIBS_OPTIONS) $(LLVM_LIBS_OPTIONS)
477 # Libtool link options:
478 # Ensure that all binaries have their symbols exported so that they can
482 # Handle compression libraries automatically
483 ifeq ($(HAVE_BZIP2),1)
486 ifeq ($(HAVE_ZLIB),1)
490 # Tell make that we need to rebuild subdirectories before we can link the tool.
491 # This affects things like LLI which has library subdirectories.
492 $(LIBS): $(addsuffix /.makeall, $(PARALLEL_DIRS))
497 $(VERB) $(RM) -f $(TOOLEXENAME)
499 $(TOOLEXENAME): $(BUILT_SOURCES) $(ObjectsO) $(PROJ_LIBS_PATHS) $(LLVM_LIBS_PATHS) $(TOOLDIR)/.dir
500 @$(ECHO) Linking $(CONFIGURATION) executable $(TOOLNAME) $(STRIP_WARN_MSG)
501 $(VERB) $(Link) -o $@ $(ObjectsO) $(PROJ_LIBS_OPTIONS) $(LLVM_LIBS_OPTIONS) $(LIBS)
502 @$(ECHO) ======= Finished linking $(CONFIGURATION) executable $(TOOLNAME) $(STRIP_WARN_MSG)
504 install:: $(TOOLEXENAME)
505 @$(ECHO) Installing $(TOOLNAME)
506 $(VERB) $(INSTALL) $(TOOLEXENAME) $(DESTDIR)/bin
509 ifndef DISABLE_AUTO_DEPENDENCIES
511 # Create .lo files in the OBJDIR directory from the .cpp and .c files...
512 $(OBJDIR)/%.lo: %.cpp $(OBJDIR)/.dir
513 @$(ECHO) "Compiling $(CONFIGURATION) $*.cpp For Shared Library"
514 $(VERB) if $(LTCXXCompile) -MD -MT $@ -MP -MF $(OBJDIR)/$*.Td $< -o $@ ; \
515 then mv -f "$(OBJDIR)/$*.Td" "$(OBJDIR)/$*.d"; else rm -f "$(OBJDIR)/$*.Td"; exit 1; fi
517 $(OBJDIR)/%.o: %.cpp $(OBJDIR)/.dir
518 @$(ECHO) "Compiling $(CONFIGURATION) $*.cpp For Archive"
519 $(VERB) if $(CXXCompile) -MD -MT $@ -MP -MF $(OBJDIR)/$*.Td $< -o $@ ; \
520 then mv -f "$(OBJDIR)/$*.Td" "$(OBJDIR)/$*.d"; else rm -f "$(OBJDIR)/$*.Td"; exit 1; fi
522 $(OBJDIR)/%.lo: %.c $(OBJDIR)/.dir
523 @$(ECHO) "Compiling $(CONFIGURATION) $*.c For Shared Library"
524 $(VERB) if $(LTCCompile) -MD -MT $@ -MP -MF $(OBJDIR)/$*.Td $< -o $@ ; \
525 then mv -f "$(OBJDIR)/$*.Td" "$(OBJDIR)/$*.d"; else rm -f "$(OBJDIR)/$*.Td"; exit 1; fi
527 $(OBJDIR)/%.o: %.c $(OBJDIR)/.dir
528 @$(ECHO) "Compiling $(CONFIGURATION) $*.c For Archive"
529 $(VERB) if $(CCompile) -MD -MT $@ -MP -MF $(OBJDIR)/$*.Td $< -o $@ ; \
530 then mv -f "$(OBJDIR)/$*.Td" "$(OBJDIR)/$*.d"; else rm -f "$(OBJDIR)/$*.Td"; exit 1; fi
532 # Create .bc files in the OBJDIR directory from .cpp and .c files...
533 $(OBJDIR)/%.bc: %.cpp $(OBJDIR)/.dir
534 @$(ECHO) "Compiling $(CONFIGURATION) $*.cpp to bytecode"
535 $(VERB) if $(BCCXXCompile) -MD -MT $@ -MP -MF "$(OBJDIR)/$*.Td" $< -o $@ ; \
536 then mv -f "$(OBJDIR)/$*.Td" "$(OBJDIR)/$*.d"; else rm -f "$(OBJDIR)/$*.Td"; exit 1; fi
538 $(OBJDIR)/%.bc: %.c $(OBJDIR)/.dir
539 @$(ECHO) "Compiling $(CONFIGURATION) $*.c to bytecode"
540 $(VERB) if $(BCCCompile) -MD -MT $@ -MP -MF "$(OBJDIR)/$*.Td" $< -o $@ ; \
541 then mv -f "$(OBJDIR)/$*.Td" "$(OBJDIR)/$*.d"; else rm -f "$(OBJDIR)/$*.Tpo"; exit 1; fi
545 $(OBJDIR)/%.lo: %.cpp $(OBJDIR)/.dir
546 @$(ECHO) "Compiling $(CONFIGURATION) $*.cpp For Shared Library"
547 $(LTCXXCompile) $< -o $@
549 $(OBJDIR)/%.o: %.cpp $(OBJDIR)/.dir
550 @$(ECHO) "Compiling $(CONFIGURATION) $*.cpp For Archive"
551 $(CXXCompile) $< -o $@
553 $(OBJDIR)/%.lo: %.c $(OBJDIR)/.dir
554 @$(ECHO) "Compiling $(CONFIGURATION) $*.cpp For Shared Library"
555 $(LTCCompile) $< -o $@
557 $(OBJDIR)/%.o: %.c $(OBJDIR)/.dir
558 @$(ECHO) "Compiling $(CONFIGURATION) $*.cpp For Archive"
561 # Create .bc files in the OBJDIR directory from .cpp and .c files...
562 $(OBJDIR)/%.bc: %.cpp $(OBJDIR)/.dir
563 @$(ECHO) "Compiling $(CONFIGURATION) $*.cpp To Bytecode"
564 $(BCCompileCPP) $< -o $@
566 $(OBJDIR)/%.bc: %.c $(OBJDIR)/.dir
567 @$(ECHO) "Compiling $(CONFIGURATION) $*.c To Bytecode"
568 $(BCCompileC) $< -o $@
572 $(OBJDIR)/%.bc: %.ll $(OBJDIR)/.dir $(LLVMAS)
573 @$(ECHO) "Compiling $*.ll To Bytecode"
574 $(VERB) $(LLVMAS) $< -f -o $@
578 TDFILES := $(strip $(wildcard $(BUILD_SRC_DIR)/*.td) $(LLVM_SRC_ROOT)/lib/Target/Target.td)
580 $(BUILT_SOURCES): $(TDFILES)
582 %GenRegisterNames.inc : %.td
583 @echo "Building $(<F) register names with tblgen"
584 $(VERB) $(TableGen) -gen-register-enums -o $@ $<
586 %GenRegisterInfo.h.inc : %.td
587 @echo "Building $(<F) register information header with tblgen"
588 $(VERB) $(TableGen) -gen-register-desc-header -o $@ $<
590 %GenRegisterInfo.inc : %.td
591 @echo "Building $(<F) register info implementation with tblgen"
592 $(VERB) $(TableGen) -gen-register-desc -o $@ $<
594 %GenInstrNames.inc : %.td
595 @echo "Building $(<F) instruction names with tblgen"
596 $(VERB) $(TableGen) -gen-instr-enums -o $@ $<
598 %GenInstrInfo.inc : %.td
599 @echo "Building $(<F) instruction information with tblgen"
600 $(VERB) $(TableGen) -gen-instr-desc -o $@ $<
602 %GenAsmWriter.inc : %.td
603 @echo "Building $(<F) assembly writer with tblgen"
604 $(VERB) $(TableGen) -gen-asm-writer -o $@ $<
606 %GenATTAsmWriter.inc : %.td
607 @echo "Building $(<F) AT&T assembly writer with tblgen"
608 $(VERB) $(TableGen) -gen-asm-writer -o $@ $<
610 %GenIntelAsmWriter.inc : %.td
611 @echo "Building $(<F) Intel assembly writer with tblgen"
612 $(VERB) $(TableGen) -gen-asm-writer -asmwriternum=1 -o $@ $<
614 %GenInstrSelector.inc: %.td
615 @echo "Building $(<F) instruction selector with tblgen"
616 $(VERB) $(TableGen) -gen-instr-selector -o $@ $<
618 %GenCodeEmitter.inc:: %.td
619 @echo "Building $(<F) code emitter with tblgen"
620 $(VERB) $(TableGen) -gen-emitter -o $@ $<
628 # Rules for building lex/yacc files
630 LEX_FILES = $(filter %.l, $(Source))
631 LEX_OUTPUT = $(LEX_FILES:%.l=%.cpp)
632 YACC_FILES = $(filter %.y, $(Source))
633 YACC_OUTPUT = $(addprefix $(YACC_FILES:%.y=%), .h .cpp .output)
634 .PRECIOUS: $(LEX_OUTPUT) $(YACC_OUTPUT)
636 # Create a .cpp source file from a flex input file... this uses sed to cut down
637 # on the warnings emited by GCC...
639 # The last line is a gross hack to work around flex aparently not being able to
640 # resize the buffer on a large token input. Currently, for uninitialized string
641 # buffers in LLVM we can generate very long tokens, so this is a hack around it.
642 # FIXME. (f.e. char Buffer[10000] )
646 $(VERB) $(FLEX) -t $< | \
647 $(SED) '/^find_rule/d' | \
648 $(SED) 's/void yyunput/inline void yyunput/' | \
649 $(SED) 's/void \*yy_flex_realloc/inline void *yy_flex_realloc/' | \
650 $(SED) 's/#define YY_BUF_SIZE 16384/#define YY_BUF_SIZE (16384*64)/' \
652 $(VERB) cmp -s $@ $@.tmp > /dev/null || $(MV) -f $@.tmp $@
653 @# remove the output of flex if it didn't get moved over...
656 # Rule for building the bison parsers...
657 %.c: %.y # Cancel built-in rules for yacc
658 %.h: %.y # Cancel built-in rules for yacc
660 @$(ECHO) "Bisoning $*.y"
661 $(VERB) $(BISON) -v -d -p $(<F:%Parser.y=%) -o $*.tab.c $<
662 $(VERB) cmp -s $*.tab.c $*.cpp > /dev/null || $(MV) -f $*.tab.c $*.cpp
663 $(VERB) cmp -s $*.tab.h $*.h > /dev/null || $(MV) -f $*.tab.h $*.h
664 @# If the files were not updated, don't leave them lying around...
665 @rm -f $*.tab.c $*.tab.h
667 # To create the directories...
669 $(VERB) $(MKDIR) $* > /dev/null
672 .PRECIOUS: $(OBJDIR)/.dir $(LIBDIR)/.dir $(TOOLDIR)/.dir $(LLVMLIBDIR)/.dir
673 .PRECIOUS: $(LLVMTOOLDIR)/.dir
675 # To create postscript files from dot files...
678 $(DOT) -Tps < $< > $@
681 $(ECHO) "Cannot build $@: The program dot is not installed"
685 # This rules ensures that header files that are removed still have a rule for
686 # which they can be "generated." This allows make to ignore them and
687 # reproduce the dependency lists.
691 # 'make clean' nukes the tree
693 $(VERB) $(RM) -rf $(OBJDIR)
694 $(VERB) $(RM) -f core core.[0-9][0-9]* *.o *.d *~ *.flc
695 ifneq ($(strip $(SHLIBEXT)),) # Extra paranoia - make real sure SHLIBEXT is set
696 $(VERB) $(RM) -f *$(SHLIBEXT)
698 $(VERB) $(RM) -f $(LEX_OUTPUT) $(YACC_OUTPUT)
700 ###########################################################################
702 # Define variables and rules that generate header file dependencies
703 # from C/C++ source files.
704 ###########################################################################
706 ifndef DISABLE_AUTO_DEPENDENCIES
708 # If dependencies were generated for the file that included this file,
709 # include the dependencies now...
712 SourceBaseNames := $(basename $(Source))
713 SourceDepend := $(SourceBaseNames:%=$(BUILD_OBJ_DIR)/$(CONFIGURATION)/%.d)
716 # Include dependencies generated from C/C++ source files, but not if we
717 # are cleaning (this example taken from the GNU Make Manual).
719 ifneq ($(MAKECMDGOALS),clean)
720 ifneq ($(MAKECMDGOALS),distclean)
721 -include /dev/null $(SourceDepend)
725 endif # ifndef DISABLE_AUTO_DEPENDENCIES
727 ###############################################################################
728 # PRECONDITIONS - that which must be built/checked first
729 ###############################################################################
731 OBJMKFILE := $(BUILD_OBJ_DIR)/Makefile
732 SRCMKFILE := $(BUILD_SRC_DIR)/Makefile
733 CONFIGURE := $(LLVM_SRC_ROOT)/configure
734 CONFIG_STATUS := $(LLVM_OBJ_ROOT)/config.status
735 MAKE_CONFIG_IN := $(LLVM_SRC_ROOT)/Makefile.config.in
736 MAKE_CONFIG := $(LLVM_OBJ_ROOT)/Makefile.config
738 #------------------------------------------------------------------------
739 # List of the preconditions
740 preconditions: $(CONFIG_STATUS) $(MAKE_CONFIG) $(OBJMKFILE)
742 all dist distcheck install:: $(BUILT_SOURCES)
745 $(VERB) $(RM) -f $(BUILT_SOURCES)
747 #------------------------------------------------------------------------
748 # Make sure we're not using a stale configuration
749 .PRECIOUS: $(CONFIG_STATUS)
750 $(CONFIG_STATUS): $(CONFIGURE)
751 @$(ECHO) Reconfiguring with $@
752 $(VERB) $(CONFIG_STATUS) --recheck
754 #------------------------------------------------------------------------
755 # Make sure the configuration makefile is up to date
756 $(MAKE_CONFIG): $(MAKE_CONFIG_IN)
757 @$(ECHO) Regenerating $@
758 $(VERB) cd $(LLVM_OBJ_ROOT) ; $(CONFIG_STATUS) Makefile.config
759 $(VERB) $(MAKE) $(MFLAGS) $(MAKECMDGOALS)
762 #------------------------------------------------------------------------
763 # If the Makefile in the source tree has been updated, copy it over into the
765 ifneq ($(OBJMKFILE),$(SRCMKFILE))
766 .PRECIOUS: $(OBJMKFILE)
767 $(OBJMKFILE): $(SRCMKFILE)
768 @$(ECHO) "Updating Makefile from : $(dir $<)"
769 $(VERB) $(MKDIR) $(@D)
771 $(VERB) $(MAKE) $(MFLAGS) $(MAKECMDGOALS)
775 ###############################################################################
776 # MISCELLANEOUS - utility targets
777 ###############################################################################
779 #------------------------------------------------------------------------
780 # Print out the directories used for building
782 @$(ECHO) "BUILD_SRC_ROOT: " $(BUILD_SRC_ROOT)
783 @$(ECHO) "BUILD_SRC_DIR : " $(BUILD_SRC_DIR)
784 @$(ECHO) "BUILD_OBJ_ROOT: " $(BUILD_OBJ_ROOT)
785 @$(ECHO) "BUILD_OBJ_DIR : " $(BUILD_OBJ_DIR)
786 @$(ECHO) "LLVM_SRC_ROOT : " $(LLVM_SRC_ROOT)
787 @$(ECHO) "LLVM_OBJ_ROOT : " $(LLVM_OBJ_ROOT)
788 @$(ECHO) "CONFIGURATION : " $(CONFIGURATION)
789 @$(ECHO) "OBJDIR: " $(OBJDIR)
790 @$(ECHO) "LIBDIR: " $(LIBDIR)
791 @$(ECHO) "TOOLDIR: " $(TOOLDIR)
792 @$(ECHO) "TDFILES:" '$(TDFILES)'
793 @$(ECHO) "CXXCompile: " '$(CXXCompile)'
794 @$(ECHO) "CCompile: " '$(CCompile)'