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. For details on how to use
11 # it properly, please see the document MakefileGuide.html in the docs directory.
13 #===-----------------------------------------------------------------------====
15 ################################################################################
16 # TARGETS: Define standard targets that can be invoked
17 ################################################################################
19 #--------------------------------------------------------------------
20 # Define the various target sets
21 #--------------------------------------------------------------------
22 RecursiveTargets := all clean clean-all check install uninstall
23 LocalTargets := all-local clean-local clean-all-local check-local \
24 install-local printvars uninstall-local
25 TopLevelTargets := dist dist-check dist-clean tags dist-gzip dist-bzip2 \
27 UserTargets := $(RecursiveTargets) $(LocalTargets) $(TopLevelTargets)
28 InternalTargets := preconditions distdir dist-hook
30 ################################################################################
31 # INITIALIZATION: Basic things the makefile needs
32 ################################################################################
34 #--------------------------------------------------------------------
35 # Set the VPATH so that we can find source files.
36 #--------------------------------------------------------------------
37 VPATH=$(BUILD_SRC_DIR)
39 #--------------------------------------------------------------------
40 # Reset the list of suffixes we know how to build
41 #--------------------------------------------------------------------
43 .SUFFIXES: .c .cpp .h .hpp .y .l .lo .o .a .bc .td .ps .dot
44 .SUFFIXES: $(SHLIBEXT) $(SUFFIXES)
46 #--------------------------------------------------------------------
47 # Mark all of these targets as phony to avoid implicit rule search
48 #--------------------------------------------------------------------
49 .PHONY: $(UserTargets) $(InternalTargets)
51 #--------------------------------------------------------------------
52 # Make sure all the user-target rules are double colon rules and
53 # they are defined first.
54 #--------------------------------------------------------------------
58 ################################################################################
59 # PRECONDITIONS: that which must be built/checked first
60 ################################################################################
62 SrcMakefiles := $(filter %Makefile %Makefile.rules %Makefile.tests \
63 %Makefile.JIT,$(wildcard $(BUILD_SRC_DIR)/Makefile*))
64 ObjMakefiles := $(subst $(BUILD_SRC_DIR),$(BUILD_OBJ_DIR),$(SrcMakefiles))
65 ConfigureScript := $(LLVM_SRC_ROOT)/configure
66 ConfigStatusScript := $(LLVM_OBJ_ROOT)/config.status
67 MakefileConfigIn := $(LLVM_SRC_ROOT)/Makefile.config.in
68 MakefileConfig := $(LLVM_OBJ_ROOT)/Makefile.config
69 PreConditions := $(ConfigStatusScript) $(MakefileConfig) $(ObjMakefiles)
71 preconditions : $(PreConditions)
73 #------------------------------------------------------------------------
74 # Make sure the BUILT_SOURCES are built first
75 #------------------------------------------------------------------------
76 $(filter-out clean clean-local,UserTargets):: $(BUILT_SOURCES)
79 ifneq ($(strip $(BUILT_SOURCES)),)
80 -$(Verb) $(RM) -f $(BUILT_SOURCES)
83 $(BUILT_SOURCES) : $(ObjMakefiles)
85 #------------------------------------------------------------------------
86 # Make sure we're not using a stale configuration
87 #------------------------------------------------------------------------
88 .PRECIOUS: $(ConfigStatusScript)
89 $(ConfigStatusScript): $(ConfigureScript)
90 $(Echo) Reconfiguring with $<
91 $(Verb) $(ConfigStatusScript) --recheck $(ConfigureScriptFLAGS)
92 $(Verb) $(ConfigStatusScript)
94 #------------------------------------------------------------------------
95 # Make sure the configuration makefile is up to date
96 #------------------------------------------------------------------------
97 $(MakefileConfig): $(MakefileConfigIn) $(ConfigStatusScript)
98 $(Echo) Regenerating $@
99 $(Verb) cd $(LLVM_OBJ_ROOT) ; $(ConfigStatusScript) Makefile.config
101 #------------------------------------------------------------------------
102 # If the Makefile in the source tree has been updated, copy it over into the
103 # build tree. But, only do this if the source and object makefiles differ
104 #------------------------------------------------------------------------
105 ifneq ($(BUILD_OBJ_DIR),$(BUILD_SRC_DIR))
107 $(BUILD_OBJ_DIR)/Makefile : $(BUILD_SRC_DIR)/Makefile
108 $(Echo) "Updating Makefile"
109 $(Verb) $(MKDIR) $(@D)
112 # Copy the Makefile.* files unless we're in the root directory which avoids
113 # the copying of Makefile.config.in or other things that should be explicitly
115 $(BUILD_OBJ_DIR)/Makefile% : $(BUILD_SRC_DIR)/Makefile%
117 *Makefile.rules) ;; \
119 *) $(Echo) "Updating $(@F)" ; \
126 #------------------------------------------------------------------------
127 # Set up the basic dependencies
128 #------------------------------------------------------------------------
129 $(UserTargets):: $(PreConditions)
134 clean-all:: clean-local clean-all-local
135 install:: install-local
136 uninstall:: uninstall-local
137 check-local:: all-local
138 install-local:: all-local
140 ###############################################################################
141 # VARIABLES: Set up various variables based on configuration data
142 ###############################################################################
144 #--------------------------------------------------------------------
145 # Variables derived from configuration we are building
146 #--------------------------------------------------------------------
148 ifdef ENABLE_PROFILING
150 CXX.Flags := -O3 -DNDEBUG -felide-constructors -finline-functions -pg
151 C.Flags := -O3 -DNDEBUG -pg
152 LD.Flags := -O3 -DNDEBUG -pg
154 ifdef ENABLE_OPTIMIZED
156 CXX.Flags := -O3 -DNDEBUG -finline-functions -felide-constructors -fomit-frame-pointer
157 C.Flags := -O3 -DNDEBUG -fomit-frame-pointer
158 LD.Flags := -O3 -DNDEBUG
161 CXX.Flags := -g -D_DEBUG
162 C.Flags := -g -D_DEBUG
163 LD.Flags := -g -D_DEBUG
168 CXX.Flags += $(CXXFLAGS)
170 CPP.Flags += $(CPPFLAGS)
171 LD.Flags += $(LDFLAGS)
173 LibTool.Flags := --tag=CXX
175 #--------------------------------------------------------------------
176 # Directory locations
177 #--------------------------------------------------------------------
178 ObjDir := $(BUILD_OBJ_DIR)/$(BuildMode)
179 LibDir := $(BUILD_OBJ_ROOT)/lib/$(BuildMode)
180 ToolDir := $(BUILD_OBJ_ROOT)/tools/$(BuildMode)
181 LLVMLibDir := $(LLVM_OBJ_ROOT)/lib/$(BuildMode)
182 LLVMToolDir := $(LLVM_OBJ_ROOT)/tools/$(BuildMode)
184 #--------------------------------------------------------------------
185 # Full Paths To Compiled Tools and Utilities
186 #--------------------------------------------------------------------
187 EchoCmd := $(ECHO) llvm[$(MAKELEVEL)]:
190 LIBTOOL := $(LLVM_OBJ_ROOT)/mklib
193 LLVMAS := $(LLVMToolDir)/llvm-as$(EXEEXT)
196 BURG := $(LLVMToolDir)/burg$(EXEEXT)
199 TBLGEN := $(LLVMToolDir)/tblgen$(EXEEXT)
202 GCCLD := $(LLVMToolDir)/gccld$(EXEEXT)
205 LLVMGCC := PATH=$(LLVMToolDir):$(PATH) $(LLVMGCCDIR)/bin/gcc
208 LLVMGXX := PATH=$(LLVMToolDir):$(PATH) $(LLVMGCCDIR)/bin/g++
211 # Need a better way to compute this.
212 LLVMGCCLibDir := $(dir $(shell $(LLVMGCC) -print-file-name=libgcc.a))/
214 #--------------------------------------------------------------------
215 # Adjust to user's request
216 #--------------------------------------------------------------------
218 # Adjust LIBTOOL flags for shared libraries, or not.
219 ifndef SHARED_LIBRARY
220 LibTool.Flags += --tag=disable-shared
222 LD.Flags += -rpath $(LibDir)
225 # Adjust settings for verbose mode
228 LibTool.Flags += --silent
229 AR.Flags += >/dev/null 2>/dev/null
230 ConfigureScriptFLAGS += >$(BUILD_OBJ_DIR)/configure.out 2>&1
232 ConfigureScriptFLAGS :=
235 # By default, strip symbol information from executable
237 Strip := $(PLATFORMSTRIPOPTS)
238 StripWarnMsg := "(without symbols)"
241 # Adjust linker flags for building an executable
243 LD.Flags += -rpath $(ToolDir) -export-dynamic
246 #----------------------------------------------------------
247 # Options To Invoke Tools
248 #----------------------------------------------------------
250 CompileCommonOpts := -Wall -W -Wwrite-strings -Wno-unused
252 LD.Flags += -L$(LibDir) -L$(LLVMLibDir)
253 CPP.Flags += -I$(BUILD_OBJ_DIR) \
255 -I$(BUILD_SRC_ROOT)/include \
256 -I$(BUILD_OBJ_ROOT)/include \
257 -I$(LLVM_OBJ_ROOT)/include \
258 -I$(LLVM_SRC_ROOT)/include \
259 -D_GNU_SOURCE -D__STDC_LIMIT_MACROS
261 Compile.C = $(CC) $(CPP.Flags) $(CompileCommonOpts) -c $(C.Flags)
262 LTCompile.C = $(LIBTOOL) $(LibTool.Flags) --mode=compile $(Compile.C)
263 BCCompile.C = $(LLVMGCC) $(CPP.Flags) $(CompileCommonOpts) $(C.Flags) -c
264 Compile.CXX = $(CXX) $(CPP.Flags) $(CompileCommonOpts) $(CXX.Flags) -c
265 LTCompile.CXX = $(LIBTOOL) $(LibTool.Flags) --mode=compile $(Compile.CXX)
266 BCCompile.CXX = $(LLVMGXX) $(CPP.Flags) $(CompileCommonOpts) $(CXX.Flags) -c
267 Link = $(LIBTOOL) $(LibTool.Flags) --mode=link $(CXX) $(CPP.Flags) \
268 $(CompileCommonOpts) $(LD.Flags) $(Strip)
269 Relink = $(LIBTOOL) $(LibTool.Flags) --mode=link $(CXX) $(CPP.Flags) \
271 BCLinkLib = $(LLVMGCC) -shared -nostdlib
272 LTInstall = $(LIBTOOL) $(LibTool.Flags) --mode=install $(INSTALL)
273 Burg = $(BURG) -I $(BUILD_SRC_DIR)
274 TableGen = $(TBLGEN) -I $(BUILD_SRC_DIR)
275 Archive = $(AR) $(AR.Flags)
282 #----------------------------------------------------------
283 # Get the list of source files
284 #----------------------------------------------------------
286 Sources := $(notdir $(wildcard $(BUILD_SRC_DIR)/*.cpp \
287 $(BUILD_SRC_DIR)/*.cc $(BUILD_SRC_DIR)/*.c $(BUILD_SRC_DIR)/*.y \
288 $(BUILD_SRC_DIR)/*.l))
290 Sources := $(SOURCES)
294 Sources += $(filter %.cpp %.c %.cc %.y %.l,$(BUILT_SOURCES))
297 #----------------------------------------------------------
298 # Types of objects that can be built from sources
299 #----------------------------------------------------------
300 BaseNameSources := $(sort $(basename $(Sources)))
301 ObjectsO := $(BaseNameSources:%=$(ObjDir)/%.o)
302 ObjectsLO := $(BaseNameSources:%=$(ObjDir)/%.lo)
303 ObjectsBC := $(BaseNameSources:%=$(ObjDir)/%.bc)
305 ###############################################################################
306 # DIRECTORIES: Handle recursive descent of directory structure
307 ###############################################################################
309 #---------------------------------------------------------
310 # Provide rules to make install dirs. This must be early
311 # in the file so they get built before dependencies
312 #---------------------------------------------------------
315 $(Verb) $(MKDIR) $(bindir)
318 $(Verb) $(MKDIR) $(libdir)
321 $(Verb) $(MKDIR) $(bytecode_libdir)
324 $(Verb) $(MKDIR) $(sysconfdir)
326 # To create other directories, as needed, and timestamp their creation
328 $(Verb) $(MKDIR) $* > /dev/null
331 .PRECIOUS: $(ObjDir)/.dir $(LibDir)/.dir $(ToolDir)/.dir $(LLVMLibDir)/.dir
332 .PRECIOUS: $(LLVMToolDir)/.dir
334 #---------------------------------------------------------
335 # Handle the DIRS options for sequential construction
336 #---------------------------------------------------------
341 $(RecursiveTargets)::
342 $(Verb) for dir in $(DIRS); do \
343 if [ ! -f $$dir/Makefile ]; then \
345 cp $(BUILD_SRC_DIR)/$$dir/Makefile $$dir/Makefile; \
347 ($(MAKE) -C $$dir $@ ) || exit 1; \
351 #---------------------------------------------------------
352 # Handle the EXPERIMENTAL_DIRS options ensuring success
353 # after each directory is built.
354 #---------------------------------------------------------
355 ifdef EXPERIMENTAL_DIRS
356 $(RecursiveTargets)::
357 $(Verb) for dir in $(EXPERIMENTAL_DIRS); do \
358 if [ ! -f $$dir/Makefile ]; then \
360 cp $(BUILD_SRC_DIR)/$$dir/Makefile $$dir/Makefile; \
362 ($(MAKE) -C $$dir $@ ) || exit 0; \
366 #---------------------------------------------------------
367 # Handle the PARALLEL_DIRS options for parallel construction
368 #---------------------------------------------------------
371 SubDirs += $(PARALLEL_DIRS)
373 # Unfortunately, this list must be maintained if new
374 # recursive targets are added.
375 all :: $(addsuffix /.makeall ,$(PARALLEL_DIRS))
376 clean :: $(addsuffix /.makeclean ,$(PARALLEL_DIRS))
377 clean-all:: $(addsuffix /.makeclean-all,$(PARALLEL_DIRS))
378 check :: $(addsuffix /.makecheck ,$(PARALLEL_DIRS))
379 install :: $(addsuffix /.makeinstall ,$(PARALLEL_DIRS))
380 uninstall:: $(addsuffix /.makeuninstall,$(PARALLEL_DIRS))
382 Parallel_Targets := $(foreach T,$(RecursiveTargets),%/.make$(T))
384 $(Parallel_Targets) :
385 $(Verb) if [ ! -f $(@D)/Makefile ]; then \
387 cp $(BUILD_SRC_DIR)/$(@D)/Makefile $(@D)/Makefile; \
389 $(MAKE) -C $(@D) $(subst $(@D)/.make,,$@)
392 #---------------------------------------------------------
393 # Handle the OPTIONAL_DIRS options for directores that may
395 #---------------------------------------------------------
398 SubDirs += $(OPTIONAL_DIRS)
400 $(RecursiveTargets)::
401 $(Verb) for dir in $(OPTIONAL_DIRS); do \
402 if [ -d $(BUILD_SRC_DIR)/$$dir ]; then\
403 if [ ! -f $$dir/Makefile ]; then \
405 cp $(BUILD_SRC_DIR)/$$dir/Makefile $$dir/Makefile; \
407 ($(MAKE) -C$$dir $@ ) || exit 1; \
412 #---------------------------------------------------------
413 # Handle the CONFIG_FILES options
414 #---------------------------------------------------------
417 install-local:: $(sysconfdir) $(CONFIG_FILES)
418 $(Echo) Installing Configuration Files To $(sysconfdir)
419 $(Verb)for file in $(CONFIG_FILES); do \
420 $(INSTALL) $(BUILD_SRC_DIR)/$${file} $(sysconfdir) ; \
424 $(Echo) Uninstalling Configuration Files From $(sysconfdir)
425 $(Verb)for file in $(CONFIG_FILES); do \
426 $(RM) -f $(sysconfdir)/$${file} ; \
431 ###############################################################################
432 # Library Build Rules: Four ways to build a library
433 ###############################################################################
436 # if we're building a library ...
439 # Make sure there isn't any extranous whitespace on the LIBRARYNAME option
440 LIBRARYNAME := $(strip $(LIBRARYNAME))
441 LibName.LA := $(LibDir)/lib$(LIBRARYNAME).la
442 LibName.A := $(LibDir)/lib$(LIBRARYNAME).a
443 LibName.O := $(LibDir)/$(LIBRARYNAME).o
444 LibName.BC := $(LibDir)/lib$(LIBRARYNAME).bc
446 #---------------------------------------------------------
447 # Shared Library Targets:
448 # If the user asked for a shared library to be built
449 # with the SHARED_LIBRARY variable, then we provide
450 # targets for building them.
451 #---------------------------------------------------------
454 all-local:: $(LibName.LA)
456 $(LibName.LA): $(BUILT_SOURCES) $(ObjectsLO) $(LibDir)/.dir
457 $(Echo) Linking $(BuildMode) Shared Library $(LIBRARYNAME)$(SHLIBEXT)
458 $(Verb) $(Link) -o $@ $(ObjectsLO)
459 $(Verb) $(LTInstall) $@ $(LibDir)
462 ifneq ($(strip $(LibName.LA)),)
463 -$(Verb) $(RM) -f $(LibName.LA)
466 DestSharedLib = $(libdir)/lib$(LIBRARYNAME)$(SHLIBEXT)
468 install-local:: $(DestSharedLib)
470 $(DestSharedLib): $(libdir) $(LibName.LA)
471 $(Echo) Installing $(BuildMode) Shared Library $(DestSharedLib)
472 $(Verb) $(LTInstall) $(LibName.LA) $(DestSharedLib)
473 $(Verb) $(LIBTOOL) --finish $(libdir)
476 $(Echo) Uninstalling $(BuildMode) Shared Library $(DestSharedLib)
477 -$(Verb) $(RM) -f $(DestSharedLib)
481 #---------------------------------------------------------
482 # Bytecode Library Targets:
483 # If the user asked for a bytecode library to be built
484 # with the BYTECODE_LIBRARY variable, then we provide
485 # targets for building them.
486 #---------------------------------------------------------
487 ifdef BYTECODE_LIBRARY
489 ifdef EXPORTED_SYMBOL_LIST
490 BCLinkLib += -Xlinker -internalize-public-api-list=$(EXPORTED_SYMBOL_LIST)
492 ifdef EXPORTED_SYMBOL_FILE
493 BCLinkLib += -Xlinker -internalize-public-api-file=$(EXPORTED_SYMBOL_FILE)
495 BCLinkLib += -Xlinker -disable-internalize
499 all-local:: $(LibName.BC)
501 $(LibName.BC): $(BUILT_SOURCES) $(ObjectsBC) $(LibDir)/.dir
502 $(Echo) Linking $(BuildMode) Bytecode Library $(notdir $@)
503 $(Verb) $(BCLinkLib) -o $@ $(ObjectsBC)
506 ifneq ($(strip $(LibName.BC)),)
507 -$(Verb) $(RM) -f $(LibName.BC)
510 DestBytecodeLib = $(bytecode_libdir)/lib$(LIBRARYNAME).bc
512 install-local:: $(DestBytecodeLib)
514 $(DestBytecodeLib): $(bytecode_libdir) $(LibName.BC)
515 $(Echo) Installing $(BuildMode) Bytecode Library $(DestBytecodeLib)
516 $(Verb) $(INSTALL) $(LibName.BC) $@
519 $(Echo) Uninstalling $(BuildMode) Bytecode Library $(DestBytecodeLib)
520 -$(Verb) $(RM) -f $(DestBytecodeLib)
524 #---------------------------------------------------------
525 # ReLinked Library Targets:
526 # If the user didn't explicitly forbid building a
527 # relinked then we provide targets for building them.
528 #---------------------------------------------------------
529 ifndef DONT_BUILD_RELINKED
531 all-local:: $(LibName.O)
533 $(LibName.O): $(BUILT_SOURCES) $(ObjectsO) $(LibDir)/.dir
534 $(Echo) Linking $(BuildMode) Object Library $(notdir $@)
535 $(Verb) $(Relink) -o $@ $(ObjectsO)
538 ifneq ($(strip $(LibName.O)),)
539 -$(Verb) $(RM) -f $(LibName.O)
542 DestRelinkedLib = $(libdir)/$(LIBRARYNAME).o
544 install-local:: $(DestRelinkedLib)
546 $(DestRelinkedLib): $(libdir) $(LibName.O)
547 $(Echo) Installing $(BuildMode) Object Library $(DestRelinkedLib)
548 $(Verb) $(LTInstall) $(LibName.O) $(DestRelinkedLib)
551 $(Echo) Uninstalling $(BuildMode) Object Library $(DestRelinkedLib)
552 -$(Verb) $(RM) -f $(DestRelinkedLib)
556 #---------------------------------------------------------
557 # Archive Library Targets:
558 # If the user wanted a regular archive library built,
559 # then we provide targets for building them.
560 #---------------------------------------------------------
563 all-local:: $(LibName.A)
565 $(LibName.A): $(BUILT_SOURCES) $(ObjectsO) $(LibDir)/.dir
566 $(Echo) Building $(BuildMode) Archive Library $(notdir $@)
568 $(Verb) $(Archive) $@ $(ObjectsO)
572 ifneq ($(strip $(LibName.A)),)
573 -$(Verb) $(RM) -f $(LibName.A)
576 DestArchiveLib := $(libdir)/lib$(LIBRARYNAME).a
578 install-local:: $(DestArchiveLib)
580 $(DestArchiveLib): $(libdir) $(LibName.A)
581 $(Echo) Installing $(BuildMode) Archive Library $(DestArchiveLib)
582 $(Verb) $(MKDIR) $(libdir)
583 $(Verb) $(LTInstall) $(LibName.A) $(DestArchiveLib)
586 $(Echo) Uninstalling $(BuildMode) Archive Library $(DestArchiveLib)
587 -$(Verb) $(RM) -f $(DestArchiveLib)
594 ###############################################################################
595 # Tool Build Rules: Build executable tool based on TOOLNAME option
596 ###############################################################################
600 #---------------------------------------------------------
601 # Set up variables for building a tool.
602 #---------------------------------------------------------
603 ToolBuildPath := $(ToolDir)/$(TOOLNAME)$(EXEEXT)
604 ProjLibsOptions := $(patsubst %.a.o, -l%, $(addsuffix .o, $(USEDLIBS)))
605 ProjLibsOptions := $(patsubst %.o, $(LibDir)/%.o, $(ProjLibsOptions))
606 LLVMLibsOptions := $(patsubst %.a.o, -l%, $(addsuffix .o, $(LLVMLIBS)))
607 LLVMLibsOptions := $(patsubst %.o, $(LLVMLibDir)/%.o, $(LLVMLibsOptions))
608 ProjUsedLibs := $(patsubst %.a.o, lib%.a, $(addsuffix .o, $(USEDLIBS)))
609 LLVMUsedLibs := $(patsubst %.a.o, lib%.a, $(addsuffix .o, $(LLVMLIBS)))
610 ProjLibsPaths := $(addprefix $(LibDir)/,$(ProjUsedLibs))
611 LLVMLibsPaths := $(addprefix $(LLVMLibDir)/,$(LLVMUsedLibs))
613 #---------------------------------------------------------
614 # Handle optional compression libraries automatically
615 #---------------------------------------------------------
617 ifeq ($(HAVE_BZIP2),1)
620 ifeq ($(HAVE_ZLIB),1)
624 #---------------------------------------------------------
625 # Tell make that we need to rebuild subdirectories before
626 # we can link the tool. This affects things like LLI which
627 # has library subdirectories.
628 #---------------------------------------------------------
629 $(ToolBuildPath): $(addsuffix /.makeall, $(PARALLEL_DIRS))
631 #---------------------------------------------------------
632 # Provide targets for building the tools
633 #---------------------------------------------------------
634 all-local:: $(ToolBuildPath)
637 ifneq ($(strip $(ToolBuildPath)),)
638 -$(Verb) $(RM) -f $(ToolBuildPath)
641 $(ToolBuildPath): $(BUILT_SOURCES) $(ObjectsO) $(ProjLibsPaths) $(LLVMLibsPaths)\
643 $(Echo) Linking $(BuildMode) executable $(TOOLNAME) $(StripWarnMsg)
644 $(Verb) $(Link) -o $@ $(TOOLLINKOPTS) $(ObjectsO) $(ProjLibsOptions) \
645 $(LLVMLibsOptions) $(ExtraLibs) $(TOOLLINKOPTSB)
646 $(Echo) ======= Finished Linking $(BuildMode) Executable $(TOOLNAME) $(StripWarnMsg)
648 DestTool = $(bindir)/$(TOOLNAME)
650 install-local:: $(DestTool)
652 $(DestTool): $(bindir) $(ToolBuildPath)
653 $(Echo) Installing $(BuildMode) $(DestTool)
654 $(Verb) $(INSTALL) $(ToolBuildPath) $(DestTool)
657 $(Echo) Uninstalling $(BuildMode) $(DestTool)
658 -$(Verb) $(RM) -f $(DestTool)
662 ###############################################################################
663 # Object Build Rules: Build object files based on sources
664 ###############################################################################
666 # Provide rule sets for when dependency generation is enabled
667 ifndef DISABLE_AUTO_DEPENDENCIES
669 #---------------------------------------------------------
670 # Create .lo files in the ObjDir directory from the .cpp and .c files...
671 #---------------------------------------------------------
674 $(ObjDir)/%.lo $(ObjDir)/%.o: %.cpp $(ObjDir)/.dir
675 $(Echo) "Compiling $*.cpp for $(BuildMode) build (PIC)"
676 $(Verb) if $(LTCompile.CXX) -MD -MT $@ -MP -MF $(ObjDir)/$*.LACXXd $< -o $@ ; \
677 then $(MV) -f "$(ObjDir)/$*.LACXXd" "$(ObjDir)/$*.d"; \
678 else $(RM) -f "$(ObjDir)/$*.LACXXd"; exit 1; fi
680 $(ObjDir)/%.lo $(ObjDir)/%.o: %.c $(ObjDir)/.dir
681 $(Echo) "Compiling $*.c for $(BuildMode) build (PIC)"
682 $(Verb) if $(LTCompile.C) -MD -MT $@ -MP -MF $(ObjDir)/$*.LACd $< -o $@ ; \
683 then $(MV) -f "$(ObjDir)/$*.LACd" "$(ObjDir)/$*.d"; \
684 else $(RM) -f "$(ObjDir)/$*.LACd"; exit 1; fi
686 #---------------------------------------------------------
687 # Create .o files in the ObjDir directory from the .cpp and .c files...
688 #---------------------------------------------------------
691 $(ObjDir)/%.o: %.cpp $(ObjDir)/.dir
692 $(Echo) "Compiling $*.cpp for $(BuildMode) build"
693 $(Verb) if $(Compile.CXX) -MD -MT $@ -MP -MF $(ObjDir)/$*.CXXd $< -o $@ ; \
694 then $(MV) -f "$(ObjDir)/$*.CXXd" "$(ObjDir)/$*.d"; \
695 else $(RM) -f "$(ObjDir)/$*.CXXd"; exit 1; fi
697 $(ObjDir)/%.o: %.c $(ObjDir)/.dir
698 $(Echo) "Compiling $*.c for $(BuildMode) build"
699 $(Verb) if $(Compile.C) -MD -MT $@ -MP -MF $(ObjDir)/$*.Cd $< -o $@ ; \
700 then $(MV) -f "$(ObjDir)/$*.Cd" "$(ObjDir)/$*.d"; \
701 else $(RM) -f "$(ObjDir)/$*.Cd"; exit 1; fi
705 #---------------------------------------------------------
706 # Create .bc files in the ObjDir directory from .cpp and .c files...
707 #---------------------------------------------------------
708 $(ObjDir)/%.bc: %.cpp $(ObjDir)/.dir
709 $(Echo) "Compiling $*.cpp for $(BuildMode) build (bytecode)"
710 $(Verb) if $(BCCompile.CXX) -MD -MT $@ -MP -MF "$(ObjDir)/$*.BCCXXd" $< -o $@ ; \
711 then $(MV) -f "$(ObjDir)/$*.BCCXXd" "$(ObjDir)/$*.d"; \
712 else $(RM) -f "$(ObjDir)/$*.BCCXXd"; exit 1; fi
714 $(ObjDir)/%.bc: %.c $(ObjDir)/.dir
715 $(Echo) "Compiling $*.c for $(BuildMode) build (bytecode)"
716 $(Verb) if $(BCCompile.C) -MD -MT $@ -MP -MF "$(ObjDir)/$*.BCCd" $< -o $@ ; \
717 then $(MV) -f "$(ObjDir)/$*.BCCd" "$(ObjDir)/$*.d"; \
718 else $(RM) -f "$(ObjDir)/$*.BCCd"; exit 1; fi
720 # Provide alternate rule sets if dependencies are disabled
725 $(ObjDir)/%.lo $(ObjDir)/%.o: %.cpp $(ObjDir)/.dir
726 $(Echo) "Compiling $*.cpp for $(BuildMode) build (PIC)"
727 $(LTCompile.CXX) $< -o $@
729 $(ObjDir)/%.lo $(ObjDir)/%.o: %.c $(ObjDir)/.dir
730 $(Echo) "Compiling $*.cpp for $(BuildMode) build (PIC)"
731 $(LTCompile.C) $< -o $@
735 $(ObjDir)/%.o: %.cpp $(ObjDir)/.dir
736 $(Echo) "Compiling $*.cpp for $(BuildMode) build"
737 $(Compile.CXX) $< -o $@
739 $(ObjDir)/%.o: %.c $(ObjDir)/.dir
740 $(Echo) "Compiling $*.cpp for $(BuildMode) build"
741 $(Compile.C) $< -o $@
744 $(ObjDir)/%.bc: %.cpp $(ObjDir)/.dir
745 $(Echo) "Compiling $*.cpp for $(BuildMode) build (bytecode)"
746 $(BCCompile.CXX) $< -o $@
748 $(ObjDir)/%.bc: %.c $(ObjDir)/.dir
749 $(Echo) "Compiling $*.c for $(BuildMode) build (bytecode)"
750 $(BCCompile.C) $< -o $@
754 #---------------------------------------------------------
755 # Provide rule to build .bc files from .ll sources,
756 # regardless of dependencies
757 #---------------------------------------------------------
758 $(ObjDir)/%.bc: %.ll $(ObjDir)/.dir $(LLVMAS)
759 $(Echo) "Compiling $*.ll for $(BuildMode) build"
760 $(Verb) $(LLVMAS) $< -f -o $@
762 ###############################################################################
763 # TABLEGEN: Provide rules for running tblgen to produce *.inc files
764 ###############################################################################
768 TDFiles := $(strip $(wildcard $(BUILD_SRC_DIR)/*.td) $(LLVM_SRC_ROOT)/lib/Target/Target.td)
769 INCFiles := $(filter %.inc,$(BUILT_SOURCES))
771 $(INCFiles) : $(TBLGEN) $(TDFiles)
773 %GenRegisterNames.inc : %.td
774 $(Echo) "Building $(<F) register names with tblgen"
775 $(Verb) $(TableGen) -gen-register-enums -o $@ $<
777 %GenRegisterInfo.h.inc : %.td
778 $(Echo) "Building $(<F) register information header with tblgen"
779 $(Verb) $(TableGen) -gen-register-desc-header -o $@ $<
781 %GenRegisterInfo.inc : %.td
782 $(Echo) "Building $(<F) register info implementation with tblgen"
783 $(Verb) $(TableGen) -gen-register-desc -o $@ $<
785 %GenInstrNames.inc : %.td
786 $(Echo) "Building $(<F) instruction names with tblgen"
787 $(Verb) $(TableGen) -gen-instr-enums -o $@ $<
789 %GenInstrInfo.inc : %.td
790 $(Echo) "Building $(<F) instruction information with tblgen"
791 $(Verb) $(TableGen) -gen-instr-desc -o $@ $<
793 %GenAsmWriter.inc : %.td
794 $(Echo) "Building $(<F) assembly writer with tblgen"
795 $(Verb) $(TableGen) -gen-asm-writer -o $@ $<
797 %GenATTAsmWriter.inc : %.td
798 $(Echo) "Building $(<F) AT&T assembly writer with tblgen"
799 $(Verb) $(TableGen) -gen-asm-writer -o $@ $<
801 %GenIntelAsmWriter.inc : %.td
802 $(Echo) "Building $(<F) Intel assembly writer with tblgen"
803 $(Verb) $(TableGen) -gen-asm-writer -asmwriternum=1 -o $@ $<
805 %GenInstrSelector.inc: %.td
806 $(Echo) "Building $(<F) instruction selector with tblgen"
807 $(Verb) $(TableGen) -gen-instr-selector -o $@ $<
809 %GenCodeEmitter.inc:: %.td
810 $(Echo) "Building $(<F) code emitter with tblgen"
811 $(Verb) $(TableGen) -gen-emitter -o $@ $<
814 -$(Verb) $(RM) -f $(INCFiles)
818 ###############################################################################
819 # LEX AND YACC: Provide rules for generating sources with lex and yacc
820 ###############################################################################
822 #---------------------------------------------------------
823 # Provide rules for generating a .cpp source file from
824 # (f)lex input sources.
825 #---------------------------------------------------------
827 LexFiles := $(filter %.l,$(Sources))
831 LexOutput := $(strip $(patsubst %.l,%.cpp,$(LexFiles)))
833 .PRECIOUS: $(LexOutput)
835 # Note the extra sed filtering here, used to cut down on the warnings emited
836 # by GCC. The last line is a gross hack to work around flex aparently not
837 # being able to resize the buffer on a large token input. Currently, for
838 # uninitialized string buffers in LLVM we can generate very long tokens, so
839 # this is a hack around it.
840 # FIXME. (f.e. char Buffer[10000] )
843 $(Verb) $(FLEX) -t $< | \
844 $(SED) 's/void yyunput/inline void yyunput/' | \
845 $(SED) 's/void \*yy_flex_realloc/inline void *yy_flex_realloc/' | \
846 $(SED) 's/#define YY_BUF_SIZE 16384/#define YY_BUF_SIZE (16384*64)/' \
850 -$(Verb) $(RM) -f $(LexOutput)
851 $(Verb) $(RM) -f $(LexOutput)
855 #---------------------------------------------------------
856 # Provide rules for generating a .cpp and .h source files
857 # from yacc (bison) input sources.
858 #---------------------------------------------------------
860 YaccFiles := $(filter %.y,$(Sources))
861 ifneq ($(YaccFiles),)
862 YaccOutput := $(addprefix $(patsubst %.y,%,$(YaccFiles)),.h .cpp .output)
864 .PRECIOUS: $(YaccOutput)
866 # Cancel built-in rules for yacc
871 # Rule for building the bison parsers...
873 $(Echo) "Bisoning $*.y"
874 $(Verb) $(BISON) -v -d -p $(<F:%Parser.y=%) -o $*.tab.c $<
875 $(Verb) $(MV) -f $*.tab.c $*.cpp
876 $(Verb) $(MV) -f $*.tab.h $*.h
879 -$(Verb) $(RM) -f $(YaccOutput)
880 $(Verb) $(RM) -f $(YaccOutput)
883 ###############################################################################
884 # OTHER RULES: Other rules needed
885 ###############################################################################
887 # To create postscript files from dot files...
890 $(DOT) -Tps < $< > $@
893 $(Echo) "Cannot build $@: The program dot is not installed"
896 # This rules ensures that header files that are removed still have a rule for
897 # which they can be "generated." This allows make to ignore them and
898 # reproduce the dependency lists.
901 # Define clean-local to clean the current directory. Note that this uses a
902 # very conservative approach ensuring that empty variables do not cause
903 # errors or disastrous removal.
905 ifneq ($(strip $(ObjDir)),)
906 -$(Verb) $(RM) -rf $(ObjDir)
908 -$(Verb) $(RM) -f core core.[0-9][0-9]* *.o *.d *~ *.flc
909 ifneq ($(strip $(SHLIBEXT)),) # Extra paranoia - make real sure SHLIBEXT is set
910 -$(Verb) $(RM) -f *$(SHLIBEXT)
914 -$(Verb) $(RM) -rf Debug Release Profile
916 # Build tags database for Emacs/Xemacs:
919 find include lib tools examples -name '*.cpp' -o -name '*.h' | \
920 $(ETAGS) $(ETAGSFLAGS) -
922 ###############################################################################
923 # DEPENDENCIES: Include the dependency files if we should
924 ###############################################################################
925 ifndef DISABLE_AUTO_DEPENDENCIES
927 # If its not one of the cleaning targets
928 ifneq ($strip($(filter-out clean clean-local dist-clean,$(MAKECMDGOALS))),)
930 # Get the list of dependency files
931 DependFiles := $(basename $(filter %.cpp %.c %.cc, $(Sources)))
932 DependFiles := $(patsubst %,$(BUILD_OBJ_DIR)/$(BuildMode)/%.d,$(DependFiles))
934 -include /dev/null $(DependFiles)
940 ###############################################################################
941 # DISTRIBUTION: Handle construction of a distribution tarball
942 ###############################################################################
944 #------------------------------------------------------------------------
945 # Define distribution related variables
946 #------------------------------------------------------------------------
947 DistName := $(LLVM_TARBALL_NAME)
948 DistDir := $(BUILD_OBJ_ROOT)/$(DistName)
949 TopDistDir := $(BUILD_OBJ_ROOT)/$(DistName)
950 DistTarGZip := $(BUILD_OBJ_ROOT)/$(DistName).tar.gz
951 DistZip := $(BUILD_OBJ_ROOT)/$(DistName).zip
952 DistTarBZ2 := $(BUILD_OBJ_ROOT)/$(DistName).tar.bz2
953 DistAlways := CREDITS.TXT LICENSE.TXT README.txt README AUTHORS COPYING \
954 ChangeLog INSTALL NEWS Makefile Makefile.common Makefile.rules \
955 Makefile.config.in configure autoconf
956 DistOther := $(notdir $(wildcard \
957 $(BUILD_SRC_DIR)/*.h \
958 $(BUILD_SRC_DIR)/*.td \
959 $(BUILD_SRC_DIR)/*.def \
960 $(BUILD_SRC_DIR)/*.ll \
961 $(BUILD_SRC_DIR)/*.in))
962 DistSources := $(Sources) $(EXTRA_DIST)
963 DistSubDirs := $(SubDirs)
964 DistFiles := $(DistAlways) $(DistSources) $(DistOther)
966 #------------------------------------------------------------------------
967 # We MUST build distribution with OBJ_DIR != SRC_DIR
968 #------------------------------------------------------------------------
969 ifeq ($(BUILD_SRC_DIR),$(BUILD_OBJ_DIR))
970 dist dist-check dist-clean dist-gzip dist-bzip2 dist-zip ::
971 $(Echo) ERROR: Target $@ only available with OBJ_DIR != SRC_DIR
976 DistCheckTop := check
978 #------------------------------------------------------------------------
979 # Prevent catastrophic remove
980 #------------------------------------------------------------------------
981 ifeq ($(LLVM_TARBALL_NAME),)
982 $(error LLVM_TARBALL_NAME is empty. Please rerun configure)
985 #------------------------------------------------------------------------
986 # Prevent attempt to run dist targets from anywhere but the top level
987 #------------------------------------------------------------------------
990 dist dist-check dist-clean dist-gzip dist-bzip2 dist-zip ::
991 $(Echo) ERROR: You must run $@ from $(BUILD_OBJ_ROOT)
995 #------------------------------------------------------------------------
996 # Provide the top level targets
997 #------------------------------------------------------------------------
999 dist-gzip:: $(DistTarGZip)
1001 $(DistTarGZip) : distdir
1002 $(Echo) Packing gzipped distribution tar file.
1003 $(Verb) cd $(BUILD_OBJ_ROOT) ; $(TAR) chf - "$(DistName)" | gzip -c > "$(DistTarGZip)"
1005 dist-bzip2:: $(DistTarBZ2)
1007 $(DistTarBZ2) : distdir
1008 $(Echo) Packing bzipped distribution tar file.
1009 $(Verb) cd $(BUILD_OBJ_ROOT) ; $(TAR) chf - $(DistName) | $(BZIP2) -c >$(DistTarBZ2)
1011 dist-zip:: $(DistZip)
1013 $(DistZip) : distdir
1014 $(Echo) Packing zipped distribution file.
1015 $(Verb) rm -f $(DistZip)
1016 $(Verb) cd $(BUILD_OBJ_ROOT) ; $(ZIP) -rq $(DistZip) $(DistName)
1018 dist :: $(DistTarGZip) $(DistTarBZ2) $(DistZip)
1019 $(Echo) ===== DISTRIBUTION PACKAGING SUCESSFUL =====
1021 DistCheckDir := $(LLVM_OBJ_ROOT)/_distcheckdir
1023 dist-check:: $(DistCheckTop) $(DistTarGZip)
1024 $(Echo) Checking distribution tar file.
1025 $(Verb) if test -d $(DistCheckDir) ; then \
1026 $(RM) -rf $(DistCheckDir) ; \
1028 $(Verb) $(MKDIR) $(DistCheckDir)
1029 $(Verb) cd $(DistCheckDir) && \
1030 $(MKDIR) $(DistCheckDir)/build && \
1031 $(MKDIR) $(DistCheckDir)/install && \
1032 gunzip -c $(DistTarGZip) | $(TAR) xf - && \
1034 ../$(DistName)/configure --prefix="$(DistCheckDir)/install" \
1035 --srcdir=../$(DistName) --with-llvmgccdir="$(LLVMGCCDIR)" && \
1037 $(MAKE) install && \
1038 $(MAKE) uninstall && \
1041 $(MAKE) dist-clean && \
1042 $(EchoCmd) ===== $(DistTarGZip) Ready For Distribution =====
1045 $(Echo) Cleaning distribution files
1046 -$(Verb) $(RM) -rf $(DistTarGZip) $(DistTarBZ2) $(DistZip) $(DistName) $(DistCheckDir)
1050 #------------------------------------------------------------------------
1051 # Provide the recursive distdir target for building the distribution directory
1052 #------------------------------------------------------------------------
1053 distdir : $(DistSources)
1054 $(Echo) Building Distribution Directory $(DistDir)
1055 $(Verb) if test "$(DistDir)" = "$(TopDistDir)" ; then \
1056 if test -d "$(DistDir)" ; then \
1057 find $(DistDir) -type d ! -perm -200 -exec chmod u+w {} ';' || \
1060 $(EchoCmd) Removing $(DistDir) ; \
1061 $(RM) -rf $(DistDir); \
1063 $(Verb) $(MKDIR) $(DistDir)
1064 $(Verb) srcdirstrip=`echo "$(BUILD_SRC_DIR)" | sed 's|.|.|g'`; \
1065 srcrootstrip=`echo "$(BUILD_SRC_ROOT)" | sed 's|.|.|g'`; \
1066 for file in $(DistFiles) ; do \
1068 $(BUILD_SRC_DIR)/*) file=`echo "$$file" | sed "s#^$$srcdirstrip/##"`;; \
1069 $(BUILD_SRC_ROOT)/*) file=`echo "$$file" | sed "s#^$$srcrootstrip/#$(BUILD_OBJ_ROOT)/#"`;; \
1071 if test -f "$$file" || test -d "$$file" ; then \
1074 from_dir=$(BUILD_SRC_DIR); \
1076 to_dir=`echo "$$file" | sed -e 's#/[^/]*$$##'`; \
1077 if test "$$to_dir" != "$$file" && test "$$to_dir" != "."; then \
1078 to_dir="$(DistDir)/$$dir"; \
1079 $(MKDIR) "$$to_dir" ; \
1081 to_dir="$(DistDir)"; \
1083 mid_dir=`echo "$$file" | sed -n -e 's#^\(.*\)/[^/]*$$#\1#p'`; \
1084 if test -n "$$mid_dir" ; then \
1085 $(MKDIR) "$$to_dir/$$mid_dir" || exit 1; \
1087 if test -d "$$from_dir/$$file"; then \
1088 if test -d "$(BUILD_SRC_DIR)/$$file" && \
1089 test "$$from_dir" != "$(BUILD_SRC_DIR)" ; then \
1090 cp -pR "$(BUILD_SRC_DIR)/$$file" "$$to_dir" || exit 1; \
1092 cp -pR $$from_dir/$$file $$to_dir || exit 1; \
1093 elif test -f "$$from_dir/$$file" ; then \
1094 cp -p "$$from_dir/$$file" "$(DistDir)/$$file" || exit 1; \
1095 elif test -L "$$from_dir/$$file" ; then \
1096 cp -pd "$$from_dir/$$file" $(DistDir)/$$file || exit 1; \
1097 elif echo "$(DistAlways)" | grep -v "$$file" >/dev/null ; then \
1098 $(EchoCmd) "===== WARNING: Distribution Source $$from_dir/$$file Not Found!" ; \
1099 elif test "$(Verb)" != '@' ; then \
1100 $(EchoCmd) "Skipping non-existent $$from_dir/$$file" ; \
1103 $(Verb) for subdir in $(DistSubDirs) ; do \
1104 if test "$$subdir" \!= "." ; then \
1105 new_distdir="$(DistDir)/$$subdir" ; \
1106 test -d "$$new_distdir" || $(MKDIR) "$$new_distdir" || exit 1; \
1107 ( cd $$subdir && $(MAKE) DistDir="$$new_distdir" distdir ) || exit 1; \
1110 $(Verb) $(MAKE) DistDir="$(DistDir)" dist-hook || exit 1
1111 -$(Verb) find $(DistDir) -type d ! -perm -777 -exec chmod a+rwx {} \; -o \
1112 ! -type d ! -perm -444 -links 1 -exec chmod a+r {} \; -o \
1113 ! -type d ! -perm -400 -exec chmod a+r {} \; -o \
1114 ! -type d ! -perm -444 -exec $(SHELL) $(INSTALL_SH) -c -m a+r {} {} \; \
1115 || chmod -R a+r $(DistDir)
1117 # This is invoked by distdir target, define it as a no-op to avoid errors if not
1123 ###############################################################################
1124 # TOP LEVEL - targets only to apply at the top level directory
1125 ###############################################################################
1129 #------------------------------------------------------------------------
1130 # Install support for project's include files:
1131 #------------------------------------------------------------------------
1133 $(Echo) Installing include files
1134 $(Verb) $(MKDIR) $(includedir)
1135 $(Verb) if [ -d "$(BUILD_SRC_ROOT)/include" ] ; then \
1136 cd $(BUILD_SRC_ROOT)/include && \
1137 find . -path '*/Internal' -prune -o '(' -type f \
1138 '!' '(' -name '*~' -o -name '.cvsignore' -o -name '.#*' ')' \
1139 -print ')' | grep -v CVS | pax -rwdvpe $(includedir) ; \
1143 $(Echo) Uninstalling include files
1144 $(Verb) if [ -d "$(BUILD_SRC_ROOT)/include" ] ; then \
1145 cd $(BUILD_SRC_ROOT)/include && \
1146 $(RM) -f `find . -path '*/Internal' -prune -o '(' -type f \
1147 '!' '(' -name '*~' -o -name '.cvsignore' -o -name '.#*' ')' \
1148 -print ')' | grep -v CVS | sed 's#^#$(includedir)/#'` ; \
1153 #------------------------------------------------------------------------
1154 # Print out the directories used for building
1155 #------------------------------------------------------------------------
1157 $(Echo) "BuildMode : " '$(BuildMode)'
1158 $(Echo) "BUILD_SRC_ROOT : " '$(BUILD_SRC_ROOT)'
1159 $(Echo) "BUILD_SRC_DIR : " '$(BUILD_SRC_DIR)'
1160 $(Echo) "BUILD_OBJ_ROOT : " '$(BUILD_OBJ_ROOT)'
1161 $(Echo) "BUILD_OBJ_DIR : " '$(BUILD_OBJ_DIR)'
1162 $(Echo) "LLVM_SRC_ROOT : " '$(LLVM_SRC_ROOT)'
1163 $(Echo) "LLVM_OBJ_ROOT : " '$(LLVM_OBJ_ROOT)'
1164 $(Echo) "libdir : " '$(libdir)'
1165 $(Echo) "bindir : " '$(bindir)'
1166 $(Echo) "sysconfdir : " '$(sysconfdir)'
1167 $(Echo) "bytecode_libdir: " '$(bytecode_libdir)'
1168 $(Echo) "UserTargets : " '$(UserTargets)'
1169 $(Echo) "ObjMakefiles : " '$(ObjMakefiles)'
1170 $(Echo) "SrcMakefiles : " '$(SrcMakefiles)'
1171 $(Echo) "ObjDir : " '$(ObjDir)'
1172 $(Echo) "LibDir : " '$(LibDir)'
1173 $(Echo) "ToolDir : " '$(ToolDir)'
1174 $(Echo) "TDFiles : " '$(TDFiles)'
1175 $(Echo) "INCFiles : " '$(INCFiles)'
1176 $(Echo) "Compile.CXX : " '$(Compile.CXX)'
1177 $(Echo) "Compile.C : " '$(Compile.C)'
1178 $(Echo) "Archive : " '$(Archive)'
1179 $(Echo) "YaccFiles : " '$(YaccFiles)'
1180 $(Echo) "LexFiles : " '$(LexFiles)'