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 check install uninstall
23 LocalTargets := all-local clean-local check-local install-local printvars \
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 install:: install-local
135 uninstall:: uninstall-local
136 check-local:: all-local
137 install-local:: all-local
139 ###############################################################################
140 # VARIABLES: Set up various variables based on configuration data
141 ###############################################################################
143 #--------------------------------------------------------------------
144 # Variables derived from configuration we are building
145 #--------------------------------------------------------------------
147 ifdef ENABLE_PROFILING
149 CXX.Flags := -O3 -DNDEBUG -felide-constructors -finline-functions -pg
150 C.Flags := -O3 -DNDEBUG -pg
151 LD.Flags := -O3 -DNDEBUG -pg
153 ifdef ENABLE_OPTIMIZED
155 CXX.Flags := -O3 -DNDEBUG -finline-functions -felide-constructors -fomit-frame-pointer
156 C.Flags := -O3 -DNDEBUG -fomit-frame-pointer
157 LD.Flags := -O3 -DNDEBUG
160 CXX.Flags := -g -D_DEBUG
161 C.Flags := -g -D_DEBUG
162 LD.Flags := -g -D_DEBUG
167 CXX.Flags += $(CXXFLAGS)
169 CPP.Flags += $(CPPFLAGS)
170 LD.Flags += $(LDFLAGS)
172 LibTool.Flags := --tag=CXX
174 #--------------------------------------------------------------------
175 # Directory locations
176 #--------------------------------------------------------------------
177 ObjDir := $(BUILD_OBJ_DIR)/$(BuildMode)
178 LibDir := $(BUILD_OBJ_ROOT)/lib/$(BuildMode)
179 ToolDir := $(BUILD_OBJ_ROOT)/tools/$(BuildMode)
180 LLVMLibDir := $(LLVM_OBJ_ROOT)/lib/$(BuildMode)
181 LLVMToolDir := $(LLVM_OBJ_ROOT)/tools/$(BuildMode)
183 #--------------------------------------------------------------------
184 # Full Paths To Compiled Tools and Utilities
185 #--------------------------------------------------------------------
186 EchoCmd := $(ECHO) llvm[$(MAKELEVEL)]:
189 LIBTOOL := $(LLVM_OBJ_ROOT)/mklib
192 LLVMAS := $(LLVMToolDir)/llvm-as$(EXEEXT)
195 BURG := $(LLVMToolDir)/burg$(EXEEXT)
198 TBLGEN := $(LLVMToolDir)/tblgen$(EXEEXT)
201 GCCLD := $(LLVMToolDir)/gccld$(EXEEXT)
204 LLVMGCC := PATH=$(LLVMToolDir):$(PATH) $(LLVMGCCDIR)/bin/gcc
207 LLVMGXX := PATH=$(LLVMToolDir):$(PATH) $(LLVMGCCDIR)/bin/g++
210 # Need a better way to compute this.
211 LLVMGCCLibDir := $(dir $(shell $(LLVMGCC) -print-file-name=libgcc.a))/
213 #--------------------------------------------------------------------
214 # Adjust to user's request
215 #--------------------------------------------------------------------
217 # Adjust LIBTOOL flags for shared libraries, or not.
218 ifndef SHARED_LIBRARY
219 LibTool.Flags += --tag=disable-shared
221 LD.Flags += -rpath $(LibDir)
224 # Adjust settings for verbose mode
227 LibTool.Flags += --silent
228 AR.Flags += >/dev/null 2>/dev/null
229 ConfigureScriptFLAGS += >$(BUILD_OBJ_DIR)/configure.out 2>&1
231 ConfigureScriptFLAGS :=
234 # By default, strip symbol information from executable
236 Strip := $(PLATFORMSTRIPOPTS)
237 StripWarnMsg := "(without symbols)"
240 # Adjust linker flags for building an executable
242 LD.Flags += -rpath $(ToolDir) -export-dynamic
245 #----------------------------------------------------------
246 # Options To Invoke Tools
247 #----------------------------------------------------------
249 CompileCommonOpts := -Wall -W -Wwrite-strings -Wno-unused
251 LD.Flags += -L$(LibDir) -L$(LLVMLibDir)
252 CPP.Flags += -I$(BUILD_OBJ_DIR) \
254 -I$(BUILD_SRC_ROOT)/include \
255 -I$(BUILD_OBJ_ROOT)/include \
256 -I$(LLVM_OBJ_ROOT)/include \
257 -I$(LLVM_SRC_ROOT)/include \
258 -D_GNU_SOURCE -D__STDC_LIMIT_MACROS
260 Compile.C = $(CC) $(CPP.Flags) $(CompileCommonOpts) -c $(C.Flags)
261 LTCompile.C = $(LIBTOOL) $(LibTool.Flags) --mode=compile $(Compile.C)
262 BCCompile.C = $(LLVMGCC) $(CPP.Flags) $(CompileCommonOpts) $(C.Flags) -c
263 Compile.CXX = $(CXX) $(CPP.Flags) $(CompileCommonOpts) $(CXX.Flags) -c
264 LTCompile.CXX = $(LIBTOOL) $(LibTool.Flags) --mode=compile $(Compile.CXX)
265 BCCompile.CXX = $(LLVMGXX) $(CPP.Flags) $(CompileCommonOpts) $(CXX.Flags) -c
266 Link = $(LIBTOOL) $(LibTool.Flags) --mode=link $(CXX) $(CPP.Flags) \
267 $(CompileCommonOpts) $(LD.Flags) $(Strip)
268 Relink = $(LIBTOOL) $(LibTool.Flags) --mode=link $(CXX) $(CPP.Flags) \
270 BCLinkLib = $(LLVMGCC) -shared -nostdlib
271 LTInstall = $(LIBTOOL) $(LibTool.Flags) --mode=install $(INSTALL)
272 Burg = $(BURG) -I $(BUILD_SRC_DIR)
273 TableGen = $(TBLGEN) -I $(BUILD_SRC_DIR)
274 Archive = $(AR) $(AR.Flags)
281 #----------------------------------------------------------
282 # Get the list of source files
283 #----------------------------------------------------------
285 Sources := $(notdir $(wildcard $(BUILD_SRC_DIR)/*.cpp \
286 $(BUILD_SRC_DIR)/*.cc $(BUILD_SRC_DIR)/*.c $(BUILD_SRC_DIR)/*.y \
287 $(BUILD_SRC_DIR)/*.l))
289 Sources := $(SOURCES)
293 Sources += $(filter %.cpp %.c %.cc %.y %.l,$(BUILT_SOURCES))
296 #----------------------------------------------------------
297 # Types of objects that can be built from sources
298 #----------------------------------------------------------
299 BaseNameSources := $(sort $(basename $(Sources)))
300 ObjectsO := $(BaseNameSources:%=$(ObjDir)/%.o)
301 ObjectsLO := $(BaseNameSources:%=$(ObjDir)/%.lo)
302 ObjectsBC := $(BaseNameSources:%=$(ObjDir)/%.bc)
304 ###############################################################################
305 # DIRECTORIES: Handle recursive descent of directory structure
306 ###############################################################################
308 #---------------------------------------------------------
309 # Provide rules to make install dirs. This must be early
310 # in the file so they get built before dependencies
311 #---------------------------------------------------------
314 $(Verb) $(MKDIR) $(bindir)
317 $(Verb) $(MKDIR) $(libdir)
320 $(Verb) $(MKDIR) $(bytecode_libdir)
323 $(Verb) $(MKDIR) $(sysconfdir)
325 # To create other directories, as needed, and timestamp their creation
327 $(Verb) $(MKDIR) $* > /dev/null
330 .PRECIOUS: $(ObjDir)/.dir $(LibDir)/.dir $(ToolDir)/.dir $(LLVMLibDir)/.dir
331 .PRECIOUS: $(LLVMToolDir)/.dir
333 #---------------------------------------------------------
334 # Handle the DIRS options for sequential construction
335 #---------------------------------------------------------
340 $(RecursiveTargets)::
341 $(Verb) for dir in $(DIRS); do \
342 if [ ! -f $$dir/Makefile ]; then \
344 cp $(BUILD_SRC_DIR)/$$dir/Makefile $$dir/Makefile; \
346 ($(MAKE) -C $$dir $@ ) || exit 1; \
350 #---------------------------------------------------------
351 # Handle the EXPERIMENTAL_DIRS options ensuring success
352 # after each directory is built.
353 #---------------------------------------------------------
354 ifdef EXPERIMENTAL_DIRS
355 $(RecursiveTargets)::
356 $(Verb) for dir in $(EXPERIMENTAL_DIRS); do \
357 if [ ! -f $$dir/Makefile ]; then \
359 cp $(BUILD_SRC_DIR)/$$dir/Makefile $$dir/Makefile; \
361 ($(MAKE) -C $$dir $@ ) || exit 0; \
365 #---------------------------------------------------------
366 # Handle the PARALLEL_DIRS options for parallel construction
367 #---------------------------------------------------------
370 SubDirs += $(PARALLEL_DIRS)
372 # Unfortunately, this list must be maintained if new
373 # recursive targets are added.
374 all :: $(addsuffix /.makeall ,$(PARALLEL_DIRS))
375 clean :: $(addsuffix /.makeclean ,$(PARALLEL_DIRS))
376 check :: $(addsuffix /.makecheck ,$(PARALLEL_DIRS))
377 install :: $(addsuffix /.makeinstall ,$(PARALLEL_DIRS))
378 uninstall:: $(addsuffix /.makeuninstall,$(PARALLEL_DIRS))
380 Parallel_Targets := $(foreach T,$(RecursiveTargets),%/.make$(T))
382 $(Parallel_Targets) :
383 $(Verb) if [ ! -f $(@D)/Makefile ]; then \
385 cp $(BUILD_SRC_DIR)/$(@D)/Makefile $(@D)/Makefile; \
387 $(MAKE) -C $(@D) $(subst $(@D)/.make,,$@)
390 #---------------------------------------------------------
391 # Handle the OPTIONAL_DIRS options for directores that may
393 #---------------------------------------------------------
396 SubDirs += $(OPTIONAL_DIRS)
398 $(RecursiveTargets)::
399 $(Verb) for dir in $(OPTIONAL_DIRS); do \
400 if [ -d $(BUILD_SRC_DIR)/$$dir ]; then\
401 if [ ! -f $$dir/Makefile ]; then \
403 cp $(BUILD_SRC_DIR)/$$dir/Makefile $$dir/Makefile; \
405 ($(MAKE) -C$$dir $@ ) || exit 1; \
410 #---------------------------------------------------------
411 # Handle the CONFIG_FILES options
412 #---------------------------------------------------------
415 install-local:: $(sysconfdir) $(CONFIG_FILES)
416 $(Echo) Installing Configuration Files To $(sysconfdir)
417 $(Verb)for file in $(CONFIG_FILES); do \
418 $(INSTALL) $(BUILD_SRC_DIR)/$${file} $(sysconfdir) ; \
422 $(Echo) Uninstalling Configuration Files From $(sysconfdir)
423 $(Verb)for file in $(CONFIG_FILES); do \
424 $(RM) -f $(sysconfdir)/$${file} ; \
429 ###############################################################################
430 # Library Build Rules: Four ways to build a library
431 ###############################################################################
434 # if we're building a library ...
437 # Make sure there isn't any extranous whitespace on the LIBRARYNAME option
438 LIBRARYNAME := $(strip $(LIBRARYNAME))
439 LibName.LA := $(LibDir)/lib$(LIBRARYNAME).la
440 LibName.A := $(LibDir)/lib$(LIBRARYNAME).a
441 LibName.O := $(LibDir)/$(LIBRARYNAME).o
442 LibName.BC := $(LibDir)/lib$(LIBRARYNAME).bc
444 #---------------------------------------------------------
445 # Shared Library Targets:
446 # If the user asked for a shared library to be built
447 # with the SHARED_LIBRARY variable, then we provide
448 # targets for building them.
449 #---------------------------------------------------------
452 all-local:: $(LibName.LA)
454 $(LibName.LA): $(BUILT_SOURCES) $(ObjectsLO) $(LibDir)/.dir
455 $(Echo) Linking $(BuildMode) Shared Library $(LIBRARYNAME)$(SHLIBEXT)
456 $(Verb) $(Link) -o $@ $(ObjectsLO)
457 $(Verb) $(LTInstall) $@ $(LibDir)
460 ifneq ($(strip $(LibName.LA)),)
461 $(Verb) $(RM) -f $(LibName.LA)
464 DestSharedLib = $(libdir)/lib$(LIBRARYNAME)$(SHLIBEXT)
466 install-local:: $(DestSharedLib)
468 $(DestSharedLib): $(libdir) $(LibName.LA)
469 $(Echo) Installing $(BuildMode) Shared Library $(DestSharedLib)
470 $(Verb) $(LTInstall) $(LibName.LA) $(DestSharedLib)
471 $(Verb) $(LIBTOOL) --finish $(libdir)
474 $(Echo) Uninstalling $(BuildMode) Shared Library $(DestSharedLib)
475 $(Verb) $(RM) -f $(DestSharedLib)
479 #---------------------------------------------------------
480 # Bytecode Library Targets:
481 # If the user asked for a bytecode library to be built
482 # with the BYTECODE_LIBRARY variable, then we provide
483 # targets for building them.
484 #---------------------------------------------------------
485 ifdef BYTECODE_LIBRARY
487 ifdef EXPORTED_SYMBOL_LIST
488 BCLinkLib += -Xlinker -internalize-public-api-list=$(EXPORTED_SYMBOL_LIST)
490 ifdef EXPORTED_SYMBOL_FILE
491 BCLinkLib += -Xlinker -internalize-public-api-file=$(EXPORTED_SYMBOL_FILE)
493 BCLinkLib += -Xlinker -disable-internalize
497 all-local:: $(LibName.BC)
499 $(LibName.BC): $(BUILT_SOURCES) $(ObjectsBC) $(LibDir)/.dir
500 $(Echo) Linking $(BuildMode) Bytecode Library $(notdir $@)
501 $(Verb) $(BCLinkLib) -o $@ $(ObjectsBC)
504 ifneq ($(strip $(LibName.BC)),)
505 $(Verb) $(RM) -f $(LibName.BC)
508 DestBytecodeLib = $(bytecode_libdir)/lib$(LIBRARYNAME).bc
510 install-local:: $(DestBytecodeLib)
512 $(DestBytecodeLib): $(bytecode_libdir) $(LibName.BC)
513 $(Echo) Installing $(BuildMode) Bytecode Library $(DestBytecodeLib)
514 $(Verb) $(INSTALL) $(LibName.BC) $@
517 $(Echo) Uninstalling $(BuildMode) Bytecode Library $(DestBytecodeLib)
518 $(Verb) $(RM) -f $(DestBytecodeLib)
522 #---------------------------------------------------------
523 # ReLinked Library Targets:
524 # If the user didn't explicitly forbid building a
525 # relinked then we provide targets for building them.
526 #---------------------------------------------------------
527 ifndef DONT_BUILD_RELINKED
529 all-local:: $(LibName.O)
531 $(LibName.O): $(BUILT_SOURCES) $(ObjectsO) $(LibDir)/.dir
532 $(Echo) Linking $(BuildMode) Object Library $(notdir $@)
533 $(Verb) $(Relink) -o $@ $(ObjectsO)
536 ifneq ($(strip $(LibName.O)),)
537 $(Verb) $(RM) -f $(LibName.O)
540 DestRelinkedLib = $(libdir)/$(LIBRARYNAME).o
542 install-local:: $(DestRelinkedLib)
544 $(DestRelinkedLib): $(libdir) $(LibName.O)
545 $(Echo) Installing $(BuildMode) Object Library $(DestRelinkedLib)
546 $(Verb) $(LTInstall) $(LibName.O) $(DestRelinkedLib)
549 $(Echo) Uninstalling $(BuildMode) Object Library $(DestRelinkedLib)
550 $(Verb) $(RM) -f $(DestRelinkedLib)
554 #---------------------------------------------------------
555 # Archive Library Targets:
556 # If the user wanted a regular archive library built,
557 # then we provide targets for building them.
558 #---------------------------------------------------------
561 all-local:: $(LibName.A)
563 $(LibName.A): $(BUILT_SOURCES) $(ObjectsO) $(LibDir)/.dir
564 $(Echo) Building $(BuildMode) Archive Library $(notdir $@)
566 $(Verb) $(Archive) $@ $(ObjectsO)
570 ifneq ($(strip $(LibName.A)),)
571 $(Verb) $(RM) -f $(LibName.A)
574 DestArchiveLib := $(libdir)/lib$(LIBRARYNAME).a
576 install-local:: $(DestArchiveLib)
578 $(DestArchiveLib): $(libdir) $(LibName.A)
579 $(Echo) Installing $(BuildMode) Archive Library $(DestArchiveLib)
580 $(Verb) $(MKDIR) $(libdir)
581 $(Verb) $(LTInstall) $(LibName.A) $(DestArchiveLib)
584 $(Echo) Uninstalling $(BuildMode) Archive Library $(DestArchiveLib)
585 $(Verb) $(RM) -f $(DestArchiveLib)
592 ###############################################################################
593 # Tool Build Rules: Build executable tool based on TOOLNAME option
594 ###############################################################################
598 #---------------------------------------------------------
599 # Set up variables for building a tool.
600 #---------------------------------------------------------
601 ToolBuildPath := $(ToolDir)/$(TOOLNAME)$(EXEEXT)
602 ProjLibsOptions := $(patsubst %.a.o, -l%, $(addsuffix .o, $(USEDLIBS)))
603 ProjLibsOptions := $(patsubst %.o, $(LibDir)/%.o, $(ProjLibsOptions))
604 LLVMLibsOptions := $(patsubst %.a.o, -l%, $(addsuffix .o, $(LLVMLIBS)))
605 LLVMLibsOptions := $(patsubst %.o, $(LLVMLibDir)/%.o, $(LLVMLibsOptions))
606 ProjUsedLibs := $(patsubst %.a.o, lib%.a, $(addsuffix .o, $(USEDLIBS)))
607 LLVMUsedLibs := $(patsubst %.a.o, lib%.a, $(addsuffix .o, $(LLVMLIBS)))
608 ProjLibsPaths := $(addprefix $(LibDir)/,$(ProjUsedLibs))
609 LLVMLibsPaths := $(addprefix $(LLVMLibDir)/,$(LLVMUsedLibs))
611 #---------------------------------------------------------
612 # Handle optional compression libraries automatically
613 #---------------------------------------------------------
615 ifeq ($(HAVE_BZIP2),1)
618 ifeq ($(HAVE_ZLIB),1)
622 #---------------------------------------------------------
623 # Tell make that we need to rebuild subdirectories before
624 # we can link the tool. This affects things like LLI which
625 # has library subdirectories.
626 #---------------------------------------------------------
627 $(ToolBuildPath): $(addsuffix /.makeall, $(PARALLEL_DIRS))
629 #---------------------------------------------------------
630 # Provide targets for building the tools
631 #---------------------------------------------------------
632 all-local:: $(ToolBuildPath)
635 ifneq ($(strip $(ToolBuildPath)),)
636 $(Verb) $(RM) -f $(ToolBuildPath)
639 $(ToolBuildPath): $(BUILT_SOURCES) $(ObjectsO) $(ProjLibsPaths) $(LLVMLibsPaths)\
641 $(Echo) Linking $(BuildMode) executable $(TOOLNAME) $(StripWarnMsg)
642 $(Verb) $(Link) -o $@ $(TOOLLINKOPTS) $(ObjectsO) $(ProjLibsOptions) \
643 $(LLVMLibsOptions) $(ExtraLibs) $(TOOLLINKOPTSB)
644 $(Echo) ======= Finished Linking $(BuildMode) Executable $(TOOLNAME) $(StripWarnMsg)
646 DestTool = $(bindir)/$(TOOLNAME)
648 install-local:: $(DestTool)
650 $(DestTool): $(bindir) $(ToolBuildPath)
651 $(Echo) Installing $(BuildMode) $(DestTool)
652 $(Verb) $(INSTALL) $(ToolBuildPath) $(DestTool)
655 $(Echo) Uninstalling $(BuildMode) $(DestTool)
656 $(Verb) $(RM) -f $(DestTool)
660 ###############################################################################
661 # Object Build Rules: Build object files based on sources
662 ###############################################################################
664 # Provide rule sets for when dependency generation is enabled
665 ifndef DISABLE_AUTO_DEPENDENCIES
667 #---------------------------------------------------------
668 # Create .lo files in the ObjDir directory from the .cpp and .c files...
669 #---------------------------------------------------------
672 $(ObjDir)/%.lo $(ObjDir)/%.o: %.cpp $(ObjDir)/.dir
673 $(Echo) "Compiling $*.cpp for $(BuildMode) build (PIC)"
674 $(Verb) if $(LTCompile.CXX) -MD -MT $@ -MP -MF $(ObjDir)/$*.LACXXd $< -o $@ ; \
675 then $(MV) -f "$(ObjDir)/$*.LACXXd" "$(ObjDir)/$*.d"; \
676 else $(RM) -f "$(ObjDir)/$*.LACXXd"; exit 1; fi
678 $(ObjDir)/%.lo $(ObjDir)/%.o: %.c $(ObjDir)/.dir
679 $(Echo) "Compiling $*.c for $(BuildMode) build (PIC)"
680 $(Verb) if $(LTCompile.C) -MD -MT $@ -MP -MF $(ObjDir)/$*.LACd $< -o $@ ; \
681 then $(MV) -f "$(ObjDir)/$*.LACd" "$(ObjDir)/$*.d"; \
682 else $(RM) -f "$(ObjDir)/$*.LACd"; exit 1; fi
684 #---------------------------------------------------------
685 # Create .o files in the ObjDir directory from the .cpp and .c files...
686 #---------------------------------------------------------
689 $(ObjDir)/%.o: %.cpp $(ObjDir)/.dir
690 $(Echo) "Compiling $*.cpp for $(BuildMode) build"
691 $(Verb) if $(Compile.CXX) -MD -MT $@ -MP -MF $(ObjDir)/$*.CXXd $< -o $@ ; \
692 then $(MV) -f "$(ObjDir)/$*.CXXd" "$(ObjDir)/$*.d"; \
693 else $(RM) -f "$(ObjDir)/$*.CXXd"; exit 1; fi
695 $(ObjDir)/%.o: %.c $(ObjDir)/.dir
696 $(Echo) "Compiling $*.c for $(BuildMode) build"
697 $(Verb) if $(Compile.C) -MD -MT $@ -MP -MF $(ObjDir)/$*.Cd $< -o $@ ; \
698 then $(MV) -f "$(ObjDir)/$*.Cd" "$(ObjDir)/$*.d"; \
699 else $(RM) -f "$(ObjDir)/$*.Cd"; exit 1; fi
703 #---------------------------------------------------------
704 # Create .bc files in the ObjDir directory from .cpp and .c files...
705 #---------------------------------------------------------
706 $(ObjDir)/%.bc: %.cpp $(ObjDir)/.dir
707 $(Echo) "Compiling $*.cpp for $(BuildMode) build (bytecode)"
708 $(Verb) if $(BCCompile.CXX) -MD -MT $@ -MP -MF "$(ObjDir)/$*.BCCXXd" $< -o $@ ; \
709 then $(MV) -f "$(ObjDir)/$*.BCCXXd" "$(ObjDir)/$*.d"; \
710 else $(RM) -f "$(ObjDir)/$*.BCCXXd"; exit 1; fi
712 $(ObjDir)/%.bc: %.c $(ObjDir)/.dir
713 $(Echo) "Compiling $*.c for $(BuildMode) build (bytecode)"
714 $(Verb) if $(BCCompile.C) -MD -MT $@ -MP -MF "$(ObjDir)/$*.BCCd" $< -o $@ ; \
715 then $(MV) -f "$(ObjDir)/$*.BCCd" "$(ObjDir)/$*.d"; \
716 else $(RM) -f "$(ObjDir)/$*.BCCd"; exit 1; fi
718 # Provide alternate rule sets if dependencies are disabled
723 $(ObjDir)/%.lo $(ObjDir)/%.o: %.cpp $(ObjDir)/.dir
724 $(Echo) "Compiling $*.cpp for $(BuildMode) build (PIC)"
725 $(LTCompile.CXX) $< -o $@
727 $(ObjDir)/%.lo $(ObjDir)/%.o: %.c $(ObjDir)/.dir
728 $(Echo) "Compiling $*.cpp for $(BuildMode) build (PIC)"
729 $(LTCompile.C) $< -o $@
733 $(ObjDir)/%.o: %.cpp $(ObjDir)/.dir
734 $(Echo) "Compiling $*.cpp for $(BuildMode) build"
735 $(Compile.CXX) $< -o $@
737 $(ObjDir)/%.o: %.c $(ObjDir)/.dir
738 $(Echo) "Compiling $*.cpp for $(BuildMode) build"
739 $(Compile.C) $< -o $@
742 $(ObjDir)/%.bc: %.cpp $(ObjDir)/.dir
743 $(Echo) "Compiling $*.cpp for $(BuildMode) build (bytecode)"
744 $(BCCompile.CXX) $< -o $@
746 $(ObjDir)/%.bc: %.c $(ObjDir)/.dir
747 $(Echo) "Compiling $*.c for $(BuildMode) build (bytecode)"
748 $(BCCompile.C) $< -o $@
752 #---------------------------------------------------------
753 # Provide rule to build .bc files from .ll sources,
754 # regardless of dependencies
755 #---------------------------------------------------------
756 $(ObjDir)/%.bc: %.ll $(ObjDir)/.dir $(LLVMAS)
757 $(Echo) "Compiling $*.ll for $(BuildMode) build"
758 $(Verb) $(LLVMAS) $< -f -o $@
760 ###############################################################################
761 # TABLEGEN: Provide rules for running tblgen to produce *.inc files
762 ###############################################################################
766 TDFiles := $(strip $(wildcard $(BUILD_SRC_DIR)/*.td) $(LLVM_SRC_ROOT)/lib/Target/Target.td)
767 INCFiles := $(filter %.inc,$(BUILT_SOURCES))
769 $(INCFiles) : $(TBLGEN) $(TDFiles)
771 %GenRegisterNames.inc : %.td
772 $(Echo) "Building $(<F) register names with tblgen"
773 $(Verb) $(TableGen) -gen-register-enums -o $@ $<
775 %GenRegisterInfo.h.inc : %.td
776 $(Echo) "Building $(<F) register information header with tblgen"
777 $(Verb) $(TableGen) -gen-register-desc-header -o $@ $<
779 %GenRegisterInfo.inc : %.td
780 $(Echo) "Building $(<F) register info implementation with tblgen"
781 $(Verb) $(TableGen) -gen-register-desc -o $@ $<
783 %GenInstrNames.inc : %.td
784 $(Echo) "Building $(<F) instruction names with tblgen"
785 $(Verb) $(TableGen) -gen-instr-enums -o $@ $<
787 %GenInstrInfo.inc : %.td
788 $(Echo) "Building $(<F) instruction information with tblgen"
789 $(Verb) $(TableGen) -gen-instr-desc -o $@ $<
791 %GenAsmWriter.inc : %.td
792 $(Echo) "Building $(<F) assembly writer with tblgen"
793 $(Verb) $(TableGen) -gen-asm-writer -o $@ $<
795 %GenATTAsmWriter.inc : %.td
796 $(Echo) "Building $(<F) AT&T assembly writer with tblgen"
797 $(Verb) $(TableGen) -gen-asm-writer -o $@ $<
799 %GenIntelAsmWriter.inc : %.td
800 $(Echo) "Building $(<F) Intel assembly writer with tblgen"
801 $(Verb) $(TableGen) -gen-asm-writer -asmwriternum=1 -o $@ $<
803 %GenInstrSelector.inc: %.td
804 $(Echo) "Building $(<F) instruction selector with tblgen"
805 $(Verb) $(TableGen) -gen-instr-selector -o $@ $<
807 %GenCodeEmitter.inc:: %.td
808 $(Echo) "Building $(<F) code emitter with tblgen"
809 $(Verb) $(TableGen) -gen-emitter -o $@ $<
812 $(Verb) $(RM) -f $(INCFiles)
816 ###############################################################################
817 # LEX AND YACC: Provide rules for generating sources with lex and yacc
818 ###############################################################################
820 #---------------------------------------------------------
821 # Provide rules for generating a .cpp source file from
822 # (f)lex input sources.
823 #---------------------------------------------------------
825 LexOutput := $(strip $(subst %.l,%.cpp,$(filter %.l,$(Sources))))
827 ifneq ($(LexOutput),)
829 .PRECIOUS: $(LexOutput)
831 # Note the extra sed filtering here, used to cut down on the warnings emited
832 # by GCC. The last line is a gross hack to work around flex aparently not
833 # being able to resize the buffer on a large token input. Currently, for
834 # uninitialized string buffers in LLVM we can generate very long tokens, so
835 # this is a hack around it.
836 # FIXME. (f.e. char Buffer[10000] )
839 $(Verb) $(FLEX) -t $< | \
840 $(SED) 's/void yyunput/inline void yyunput/' | \
841 $(SED) 's/void \*yy_flex_realloc/inline void *yy_flex_realloc/' | \
842 $(SED) 's/#define YY_BUF_SIZE 16384/#define YY_BUF_SIZE (16384*64)/' \
846 $(RM) -f $(LexOutput)
850 #---------------------------------------------------------
851 # Provide rules for generating a .cpp and .h source files
852 # from yacc (bison) input sources.
853 #---------------------------------------------------------
855 YaccOutput := $(strip $(addprefix $(subst %.y,%,$(filter %.y,$(Sources))),\
858 ifneq ($(YaccOutput),)
860 .PRECIOUS: $(YaccOutput)
862 # Cancel built-in rules for yacc
867 # Rule for building the bison parsers...
869 $(Echo) "Bisoning $*.y"
870 $(Verb) $(BISON) -v -d -p $(<F:%Parser.y=%) -o $*.tab.c $<
871 $(Verb) $(MV) -f $*.tab.c $*.cpp
872 $(Verb) $(MV) -f $*.tab.h $*.h
875 $(RM) -f $(YaccOutput)
878 ###############################################################################
879 # OTHER RULES: Other rules needed
880 ###############################################################################
882 # To create postscript files from dot files...
885 $(DOT) -Tps < $< > $@
888 $(Echo) "Cannot build $@: The program dot is not installed"
891 # This rules ensures that header files that are removed still have a rule for
892 # which they can be "generated." This allows make to ignore them and
893 # reproduce the dependency lists.
896 # Define clean-local to clean the current directory. Note that this uses a
897 # very conservative approach ensuring that empty variables do not cause
898 # errors or disastrous removal.
900 ifneq ($(strip $(ObjDir)),)
901 $(Verb) $(RM) -rf $(ObjDir)
903 $(Verb) $(RM) -f core core.[0-9][0-9]* *.o *.d *~ *.flc
904 ifneq ($(strip $(SHLIBEXT)),) # Extra paranoia - make real sure SHLIBEXT is set
905 $(Verb) $(RM) -f *$(SHLIBEXT)
908 # Build tags database for Emacs/Xemacs:
911 find include lib tools examples -name '*.cpp' -o -name '*.h' | \
912 $(ETAGS) $(ETAGSFLAGS) -
914 ###############################################################################
915 # DEPENDENCIES: Include the dependency files if we should
916 ###############################################################################
917 ifndef DISABLE_AUTO_DEPENDENCIES
919 # If its not one of the cleaning targets
920 ifneq ($strip($(filter-out clean clean-local dist-clean,$(MAKECMDGOALS))),)
922 # Get the list of dependency files
923 DependFiles := $(basename $(filter %.cpp %.c %.cc, $(Sources)))
924 DependFiles := $(patsubst %,$(BUILD_OBJ_DIR)/$(BuildMode)/%.d,$(DependFiles))
926 -include /dev/null $(DependFiles)
932 ###############################################################################
933 # DISTRIBUTION: Handle construction of a distribution tarball
934 ###############################################################################
936 #------------------------------------------------------------------------
937 # Define distribution related variables
938 #------------------------------------------------------------------------
939 DistName := $(LLVM_TARBALL_NAME)
940 DistDir := $(BUILD_OBJ_ROOT)/$(DistName)
941 TopDistDir := $(BUILD_OBJ_ROOT)/$(DistName)
942 DistTarGZip := $(BUILD_OBJ_ROOT)/$(DistName).tar.gz
943 DistZip := $(BUILD_OBJ_ROOT)/$(DistName).zip
944 DistTarBZ2 := $(BUILD_OBJ_ROOT)/$(DistName).tar.bz2
945 DistAlways := CREDITS.TXT LICENSE.TXT README.txt README AUTHORS COPYING \
946 ChangeLog INSTALL NEWS Makefile Makefile.common Makefile.rules \
947 Makefile.config.in configure autoconf
948 DistOther := $(notdir $(wildcard \
949 $(BUILD_SRC_DIR)/*.h \
950 $(BUILD_SRC_DIR)/*.td \
951 $(BUILD_SRC_DIR)/*.def \
952 $(BUILD_SRC_DIR)/*.ll \
953 $(BUILD_SRC_DIR)/*.in))
954 DistSources := $(Sources) $(EXTRA_DIST)
955 DistSubDirs := $(SubDirs)
956 DistFiles := $(DistAlways) $(DistSources) $(DistOther)
958 #------------------------------------------------------------------------
959 # We MUST build distribution with OBJ_DIR != SRC_DIR
960 #------------------------------------------------------------------------
961 ifeq ($(BUILD_SRC_DIR),$(BUILD_OBJ_DIR))
962 dist dist-check dist-clean dist-gzip dist-bzip2 dist-zip ::
963 $(Echo) ERROR: Target $@ only available with OBJ_DIR != SRC_DIR
968 DistCheckTop := check
970 #------------------------------------------------------------------------
971 # Prevent catastrophic remove
972 #------------------------------------------------------------------------
973 ifeq ($(LLVM_TARBALL_NAME),)
974 $(error LLVM_TARBALL_NAME is empty. Please rerun configure)
977 #------------------------------------------------------------------------
978 # Prevent attempt to run dist targets from anywhere but the top level
979 #------------------------------------------------------------------------
982 dist dist-check dist-clean dist-gzip dist-bzip2 dist-zip ::
983 $(Echo) ERROR: You must run $@ from $(BUILD_OBJ_ROOT)
987 #------------------------------------------------------------------------
988 # Provide the top level targets
989 #------------------------------------------------------------------------
991 dist-gzip:: $(DistTarGZip)
993 $(DistTarGZip) : distdir
994 $(Echo) Packing gzipped distribution tar file.
995 $(Verb) cd $(BUILD_OBJ_ROOT) ; $(TAR) chf - "$(DistName)" | gzip -c > "$(DistTarGZip)"
997 dist-bzip2:: $(DistTarBZ2)
999 $(DistTarBZ2) : distdir
1000 $(Echo) Packing bzipped distribution tar file.
1001 $(Verb) cd $(BUILD_OBJ_ROOT) ; $(TAR) chf - $(DistName) | $(BZIP2) -c >$(DistTarBZ2)
1003 dist-zip:: $(DistZip)
1005 $(DistZip) : distdir
1006 $(Echo) Packing zipped distribution file.
1007 $(Verb) rm -f $(DistZip)
1008 $(Verb) cd $(BUILD_OBJ_ROOT) ; $(ZIP) -rq $(DistZip) $(DistName)
1010 dist :: $(DistTarGZip) $(DistTarBZ2) $(DistZip)
1011 $(Echo) ===== DISTRIBUTION PACKAGING SUCESSFUL =====
1013 DistCheckDir := $(LLVM_OBJ_ROOT)/_distcheckdir
1015 dist-check:: $(DistCheckTop) $(DistTarGZip)
1016 $(Echo) Checking distribution tar file.
1017 $(Verb) if test -d $(DistCheckDir) ; then \
1018 $(RM) -rf $(DistCheckDir) ; \
1020 $(Verb) $(MKDIR) $(DistCheckDir)
1021 $(Verb) cd $(DistCheckDir) && \
1022 $(MKDIR) $(DistCheckDir)/build && \
1023 $(MKDIR) $(DistCheckDir)/install && \
1024 gunzip -c $(DistTarGZip) | $(TAR) xf - && \
1026 ../$(DistName)/configure --prefix="$(DistCheckDir)/install" \
1027 --srcdir=../$(DistName) --with-llvmgccdir="$(LLVMGCCDIR)" && \
1029 $(MAKE) install && \
1030 $(MAKE) uninstall && \
1033 $(MAKE) dist-clean && \
1034 $(EchoCmd) ===== $(DistTarGZip) Ready For Distribution =====
1037 $(Echo) Cleaning distribution files
1038 $(Verb) $(RM) -rf $(DistTarGZip) $(DistTarBZ2) $(DistZip) $(DistName) $(DistCheckDir)
1042 #------------------------------------------------------------------------
1043 # Provide the recursive distdir target for building the distribution directory
1044 #------------------------------------------------------------------------
1045 distdir : $(DistSources)
1046 $(Echo) Building Distribution Directory $(DistDir)
1047 $(Verb) if test "$(DistDir)" = "$(TopDistDir)" ; then \
1048 if test -d "$(DistDir)" ; then \
1049 find $(DistDir) -type d ! -perm -200 -exec chmod u+w {} ';' || \
1052 $(EchoCmd) Removing $(DistDir) ; \
1053 $(RM) -rf $(DistDir); \
1055 $(Verb) $(MKDIR) $(DistDir)
1056 $(Verb) srcdirstrip=`echo "$(BUILD_SRC_DIR)" | sed 's|.|.|g'`; \
1057 srcrootstrip=`echo "$(BUILD_SRC_ROOT)" | sed 's|.|.|g'`; \
1058 for file in $(DistFiles) ; do \
1060 $(BUILD_SRC_DIR)/*) file=`echo "$$file" | sed "s#^$$srcdirstrip/##"`;; \
1061 $(BUILD_SRC_ROOT)/*) file=`echo "$$file" | sed "s#^$$srcrootstrip/#$(BUILD_OBJ_ROOT)/#"`;; \
1063 if test -f "$$file" || test -d "$$file" ; then \
1066 from_dir=$(BUILD_SRC_DIR); \
1068 to_dir=`echo "$$file" | sed -e 's#/[^/]*$$##'`; \
1069 if test "$$to_dir" != "$$file" && test "$$to_dir" != "."; then \
1070 to_dir="$(DistDir)/$$dir"; \
1071 $(MKDIR) "$$to_dir" ; \
1073 to_dir="$(DistDir)"; \
1075 mid_dir=`echo "$$file" | sed -n -e 's#^\(.*\)/[^/]*$$#\1#p'`; \
1076 if test -n "$$mid_dir" ; then \
1077 $(MKDIR) "$$to_dir/$$mid_dir" || exit 1; \
1079 if test -d "$$from_dir/$$file"; then \
1080 if test -d "$(BUILD_SRC_DIR)/$$file" && \
1081 test "$$from_dir" != "$(BUILD_SRC_DIR)" ; then \
1082 cp -pR "$(BUILD_SRC_DIR)/$$file" "$$to_dir" || exit 1; \
1084 cp -pR $$from_dir/$$file $$to_dir || exit 1; \
1085 elif test -f "$$from_dir/$$file" ; then \
1086 cp -p "$$from_dir/$$file" "$(DistDir)/$$file" || exit 1; \
1087 elif test -L "$$from_dir/$$file" ; then \
1088 cp -pd "$$from_dir/$$file" $(DistDir)/$$file || exit 1; \
1089 elif echo "$(DistAlways)" | grep -v "$$file" >/dev/null ; then \
1090 $(EchoCmd) "===== WARNING: Distribution Source $$from_dir/$$file Not Found!" ; \
1091 elif test "$(Verb)" != '@' ; then \
1092 $(EchoCmd) "Skipping non-existent $$from_dir/$$file" ; \
1095 $(Verb) for subdir in $(DistSubDirs) ; do \
1096 if test "$$subdir" \!= "." ; then \
1097 new_distdir="$(DistDir)/$$subdir" ; \
1098 test -d "$$new_distdir" || $(MKDIR) "$$new_distdir" || exit 1; \
1099 ( cd $$subdir && $(MAKE) DistDir="$$new_distdir" distdir ) || exit 1; \
1102 $(Verb) $(MAKE) DistDir="$(DistDir)" dist-hook || exit 1
1103 -$(Verb) find $(DistDir) -type d ! -perm -777 -exec chmod a+rwx {} \; -o \
1104 ! -type d ! -perm -444 -links 1 -exec chmod a+r {} \; -o \
1105 ! -type d ! -perm -400 -exec chmod a+r {} \; -o \
1106 ! -type d ! -perm -444 -exec $(SHELL) $(INSTALL_SH) -c -m a+r {} {} \; \
1107 || chmod -R a+r $(DistDir)
1109 # This is invoked by distdir target, define it as a no-op to avoid errors if not
1115 ###############################################################################
1116 # TOP LEVEL - targets only to apply at the top level directory
1117 ###############################################################################
1121 #------------------------------------------------------------------------
1122 # Install support for project's include files:
1123 #------------------------------------------------------------------------
1125 $(Echo) Installing include files
1126 $(Verb) $(MKDIR) $(includedir)
1127 $(Verb) if [ -d "$(BUILD_SRC_ROOT)/include" ] ; then \
1128 cd $(BUILD_SRC_ROOT)/include && \
1129 find . -path '*/Internal' -prune -o '(' -type f \
1130 '!' '(' -name '*~' -o -name '.cvsignore' -o -name '.#*' ')' \
1131 -print ')' | grep -v CVS | pax -rwdvpe $(includedir) ; \
1135 $(Echo) Uninstalling include files
1136 $(Verb) if [ -d "$(BUILD_SRC_ROOT)/include" ] ; then \
1137 cd $(BUILD_SRC_ROOT)/include && \
1138 $(RM) -f `find . -path '*/Internal' -prune -o '(' -type f \
1139 '!' '(' -name '*~' -o -name '.cvsignore' -o -name '.#*' ')' \
1140 -print ')' | grep -v CVS | sed 's#^#$(includedir)/#'` ; \
1145 #------------------------------------------------------------------------
1146 # Print out the directories used for building
1147 #------------------------------------------------------------------------
1149 $(Echo) "BuildMode : " '$(BuildMode)'
1150 $(Echo) "BUILD_SRC_ROOT : " '$(BUILD_SRC_ROOT)'
1151 $(Echo) "BUILD_SRC_DIR : " '$(BUILD_SRC_DIR)'
1152 $(Echo) "BUILD_OBJ_ROOT : " '$(BUILD_OBJ_ROOT)'
1153 $(Echo) "BUILD_OBJ_DIR : " '$(BUILD_OBJ_DIR)'
1154 $(Echo) "LLVM_SRC_ROOT : " '$(LLVM_SRC_ROOT)'
1155 $(Echo) "LLVM_OBJ_ROOT : " '$(LLVM_OBJ_ROOT)'
1156 $(Echo) "libdir : " '$(libdir)'
1157 $(Echo) "bindir : " '$(bindir)'
1158 $(Echo) "sysconfdir : " '$(sysconfdir)'
1159 $(Echo) "bytecode_libdir: " '$(bytecode_libdir)'
1160 $(Echo) "UserTargets : " '$(UserTargets)'
1161 $(Echo) "ObjMakefiles : " '$(ObjMakefiles)'
1162 $(Echo) "SrcMakefiles : " '$(SrcMakefiles)'
1163 $(Echo) "ObjDir : " '$(ObjDir)'
1164 $(Echo) "LibDir : " '$(LibDir)'
1165 $(Echo) "ToolDir : " '$(ToolDir)'
1166 $(Echo) "TDFiles : " '$(TDFiles)'
1167 $(Echo) "INCFiles : " '$(INCFiles)'
1168 $(Echo) "Compile.CXX : " '$(Compile.CXX)'
1169 $(Echo) "Compile.C : " '$(Compile.C)'
1170 $(Echo) "Archive : " '$(Archive)'