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 install uninstall install-bytecode
23 LocalTargets := all-local clean-local clean-all-local check-local \
24 install-local printvars uninstall-local \
25 install-bytecode-local
26 TopLevelTargets := check dist dist-check dist-clean tags dist-gzip dist-bzip2 \
28 UserTargets := $(RecursiveTargets) $(LocalTargets) $(TopLevelTargets)
29 InternalTargets := preconditions distdir dist-hook
31 ################################################################################
32 # INITIALIZATION: Basic things the makefile needs
33 ################################################################################
35 #--------------------------------------------------------------------
36 # Set the VPATH so that we can find source files.
37 #--------------------------------------------------------------------
38 VPATH=$(BUILD_SRC_DIR)
40 #--------------------------------------------------------------------
41 # Reset the list of suffixes we know how to build
42 #--------------------------------------------------------------------
44 .SUFFIXES: .c .cpp .h .hpp .y .l .lo .o .a .bc .td .ps .dot
45 .SUFFIXES: $(SHLIBEXT) $(SUFFIXES)
47 #--------------------------------------------------------------------
48 # Mark all of these targets as phony to avoid implicit rule search
49 #--------------------------------------------------------------------
50 .PHONY: $(UserTargets) $(InternalTargets)
52 #--------------------------------------------------------------------
53 # Make sure all the user-target rules are double colon rules and
54 # they are defined first.
55 #--------------------------------------------------------------------
59 ################################################################################
60 # PRECONDITIONS: that which must be built/checked first
61 ################################################################################
63 SrcMakefiles := $(filter %Makefile %Makefile.tests,\
64 $(wildcard $(BUILD_SRC_DIR)/Makefile*))
65 ObjMakefiles := $(subst $(BUILD_SRC_DIR),$(BUILD_OBJ_DIR),$(SrcMakefiles))
66 ConfigureScript := $(BUILD_SRC_ROOT)/configure
67 ConfigStatusScript := $(BUILD_OBJ_ROOT)/config.status
68 LConfigStatusScript:= $(LLVM_OBJ_ROOT)/config.status
69 MakefileConfigIn := $(LLVM_SRC_ROOT)/Makefile.config.in
70 MakefileConfig := $(LLVM_OBJ_ROOT)/Makefile.config
71 PreConditions := $(ConfigStatusScript) $(MakefileConfig) $(ObjMakefiles)
73 preconditions : $(PreConditions)
75 #------------------------------------------------------------------------
76 # Make sure the BUILT_SOURCES are built first
77 #------------------------------------------------------------------------
78 $(filter-out clean clean-local,$(UserTargets)):: $(BUILT_SOURCES)
81 ifneq ($(strip $(BUILT_SOURCES)),)
82 -$(Verb) $(RM) -f $(BUILT_SOURCES)
85 ifneq ($(BUILD_OBJ_ROOT),$(BUILD_SRC_ROOT))
87 $(Verb) if test -x config.status ; then \
88 $(EchoCmd) Wiping out $(BUILD_OBJ_ROOT) ; \
89 $(MKDIR) .spotless.save ; \
90 $(MV) config.status .spotless.save ; \
91 $(MV) mklib .spotless.save ; \
92 $(MV) projects .spotless.save ; \
94 $(MV) .spotless.save/config.status . ; \
95 $(MV) .spotless.save/mklib . ; \
96 $(MV) .spotless.save/projects . ; \
97 $(RM) -rf .spotless.save ; \
98 $(EchoCmd) Rebuilding configuration of $(BUILD_OBJ_ROOT) ; \
99 $(ConfigStatusScript) --recheck $(ConfigureScriptFLAGS) && \
100 $(ConfigStatusScript) ; \
102 $(EchoCmd) "make spotless" can only be run from $(BUILD_OBJ_ROOT); \
106 $(BUILT_SOURCES) : $(ObjMakefiles)
108 #------------------------------------------------------------------------
109 # Make sure we're not using a stale configuration
110 #------------------------------------------------------------------------
112 $(Echo) Reconfiguring $(BUILD_OBJ_ROOT)
113 $(Verb) cd $(BUILD_OBJ_ROOT) && \
114 if test -w $(BUILD_OBJ_ROOT)/config.cache ; then \
115 $(RM) $(BUILD_OBJ_ROOT)/config.cache ; \
117 $(ConfigStatusScript) --recheck $(ConfigureScriptFLAGS) && \
118 $(ConfigStatusScript)
120 .PRECIOUS: $(ConfigStatusScript)
121 $(ConfigStatusScript): $(ConfigureScript)
122 $(Echo) Reconfiguring with $<
123 $(Verb) cd $(BUILD_OBJ_ROOT) && \
124 if test -w $(BUILD_OBJ_ROOT)/config.cache ; then \
125 $(RM) $(BUILD_OBJ_ROOT)/config.cache ; \
127 $(ConfigStatusScript) --recheck $(ConfigureScriptFLAGS) && \
128 $(ConfigStatusScript)
130 #------------------------------------------------------------------------
131 # Make sure the configuration makefile is up to date
132 #------------------------------------------------------------------------
133 $(MakefileConfig): $(MakefileConfigIn) $(LConfigStatusScript)
134 $(Echo) Regenerating $@
135 $(Verb) cd $(LLVM_OBJ_ROOT) ; $(LConfigStatusScript) Makefile.config
137 #------------------------------------------------------------------------
138 # If the Makefile in the source tree has been updated, copy it over into the
139 # build tree. But, only do this if the source and object makefiles differ
140 #------------------------------------------------------------------------
141 ifneq ($(BUILD_OBJ_DIR),$(BUILD_SRC_DIR))
143 Makefile: $(BUILD_SRC_DIR)/Makefile
144 $(Echo) "Updating Makefile"
145 $(Verb) $(MKDIR) $(@D)
146 $(Verb) $(CP) -f $< $@
148 # Copy the Makefile.* files unless we're in the root directory which avoids
149 # the copying of Makefile.config.in or other things that should be explicitly
151 $(BUILD_OBJ_DIR)/Makefile% : $(BUILD_SRC_DIR)/Makefile%
153 *Makefile.rules) ;; \
155 *) $(Echo) "Updating $(@F)" ; \
162 #------------------------------------------------------------------------
163 # Set up the basic dependencies
164 #------------------------------------------------------------------------
165 $(UserTargets):: $(PreConditions)
169 clean-all:: clean-local clean-all-local
170 install:: install-local
171 uninstall:: uninstall-local
172 install-local:: all-local
173 install-bytecode:: install-bytecode-local
175 ###############################################################################
176 # VARIABLES: Set up various variables based on configuration data
177 ###############################################################################
179 #--------------------------------------------------------------------
180 # Variables derived from configuration we are building
181 #--------------------------------------------------------------------
184 ifdef ENABLE_PROFILING
186 CXX.Flags := -O3 -DNDEBUG -felide-constructors -finline-functions -pg
187 C.Flags := -O3 -DNDEBUG -pg
188 LD.Flags := -O3 -DNDEBUG -pg
190 ifdef ENABLE_OPTIMIZED
192 # Don't use -fomit-frame-pointer on FreeBSD
193 ifneq ($(OS),FreeBSD)
194 OmitFramePointer := -fomit-frame-pointer
196 CXX.Flags := -O3 -DNDEBUG -finline-functions -felide-constructors \
198 C.Flags := -O3 -DNDEBUG $(OmitFramePointer)
199 LD.Flags := -O3 -DNDEBUG
202 CXX.Flags := -g -D_DEBUG
203 C.Flags := -g -D_DEBUG
204 LD.Flags := -g -D_DEBUG
209 CXX.Flags += $(CXXFLAGS)
211 CPP.Flags += $(CPPFLAGS)
212 LD.Flags += $(LDFLAGS)
214 LibTool.Flags := --tag=CXX
216 #--------------------------------------------------------------------
217 # Directory locations
218 #--------------------------------------------------------------------
219 ObjDir := $(BUILD_OBJ_DIR)/$(BuildMode)
220 LibDir := $(BUILD_OBJ_ROOT)/$(BuildMode)/lib
221 ToolDir := $(BUILD_OBJ_ROOT)/$(BuildMode)/bin
222 ExmplDir := $(BUILD_OBJ_ROOT)/$(BuildMode)/examples
223 LLVMLibDir := $(LLVM_OBJ_ROOT)/$(BuildMode)/lib
224 LLVMToolDir := $(LLVM_OBJ_ROOT)/$(BuildMode)/bin
225 LLVMExmplDir:= $(LLVM_OBJ_ROOT)/$(BuildMode)/examples
226 CFERuntimeLibDir := $(LLVMGCCDIR)/lib
228 #--------------------------------------------------------------------
229 # Full Paths To Compiled Tools and Utilities
230 #--------------------------------------------------------------------
231 EchoCmd := $(ECHO) llvm[$(MAKELEVEL)]:
234 LIBTOOL := $(LLVM_OBJ_ROOT)/mklib
237 LLVMAS := $(LLVMToolDir)/llvm-as$(EXEEXT)
240 BURG := $(LLVMToolDir)/burg$(EXEEXT)
243 TBLGEN := $(LLVMToolDir)/tblgen$(EXEEXT)
246 GCCAS := $(LLVMToolDir)/gccas$(EXEEXT)
249 GCCLD := $(LLVMToolDir)/gccld$(EXEEXT)
252 LLVMDIS := $(LLVMToolDir)/llvm-dis$(EXEEXT)
255 LLI := $(LLVMToolDir)/lli$(EXEEXT)
258 LOPT := $(LLVMToolDir)/opt$(EXEEXT)
260 LLVMGCCWITHPATH := PATH="$(LLVMToolDir):$(PATH)" $(LLVMGCC)
261 LLVMGXXWITHPATH := PATH="$(LLVMToolDir):$(PATH)" $(LLVMGXX)
263 #--------------------------------------------------------------------
264 # Adjust to user's request
265 #--------------------------------------------------------------------
267 # Adjust LD.Flags and Libtool.Flags depending on the kind of library that is
268 # to be built. Note that if LOADABLE_MODULE is specified then the resulting
269 # shared library can be opened with dlopen
271 LD.Flags += -rpath $(LibDir)
272 ifdef LOADABLE_MODULE
276 LibTool.Flags += --tag=disable-shared
286 # Adjust settings for verbose mode
289 LibTool.Flags += --silent
290 AR.Flags += >/dev/null 2>/dev/null
291 ConfigureScriptFLAGS += >$(BUILD_OBJ_DIR)/configure.out 2>&1
293 ConfigureScriptFLAGS :=
296 # By default, strip symbol information from executable
298 Strip := $(PLATFORMSTRIPOPTS)
299 StripWarnMsg := "(without symbols)"
302 # Adjust linker flags for building an executable
305 LD.Flags += -rpath $(ExmplDir) -export-dynamic
307 LD.Flags += -rpath $(ToolDir) -export-dynamic
311 #----------------------------------------------------------
312 # Options To Invoke Tools
313 #----------------------------------------------------------
315 CompileCommonOpts := -Wall -W -Wwrite-strings -Wno-unused
317 LD.Flags += -L$(LibDir) -L$(LLVMLibDir)
318 CPP.Flags += -I$(BUILD_OBJ_DIR) \
320 -I$(BUILD_SRC_ROOT)/include \
321 -I$(BUILD_OBJ_ROOT)/include \
322 -I$(LLVM_OBJ_ROOT)/include \
323 -I$(LLVM_SRC_ROOT)/include \
324 -D_GNU_SOURCE -D__STDC_LIMIT_MACROS
326 Compile.C = $(CC) $(CPP.Flags) $(CompileCommonOpts) -c $(C.Flags)
327 LTCompile.C = $(LIBTOOL) $(LibTool.Flags) --mode=compile $(Compile.C)
328 BCCompile.C = $(LLVMGCCWITHPATH) $(CPP.Flags) $(CompileCommonOpts) \
330 Compile.CXX = $(CXX) $(CPP.Flags) $(CompileCommonOpts) $(CXX.Flags) -c
331 LTCompile.CXX = $(LIBTOOL) $(LibTool.Flags) --mode=compile $(Compile.CXX)
332 BCCompile.CXX = $(LLVMGXXWITHPATH) $(CPP.Flags) $(CompileCommonOpts) \
334 Link = $(LIBTOOL) $(LibTool.Flags) --mode=link $(CXX) $(CPP.Flags) \
335 $(CompileCommonOpts) $(LD.Flags) $(Strip)
336 Relink = $(LIBTOOL) $(LibTool.Flags) --mode=link $(CXX) $(CPP.Flags) \
338 LTInstall = $(LIBTOOL) $(LibTool.Flags) --mode=install $(INSTALL)
339 Burg = $(BURG) -I $(BUILD_SRC_DIR)
340 TableGen = $(TBLGEN) -I $(BUILD_SRC_DIR)
341 Archive = $(AR) $(AR.Flags)
342 LArchive = $(LLVMToolDir)/llvm-ar rcsf
349 #----------------------------------------------------------
350 # Get the list of source files and compute object file
352 #----------------------------------------------------------
355 FakeSources := $(FAKE_SOURCES)
357 FakeSources += $(filter %.cpp %.c %.cc %.y %.l,$(BUILT_SOURCES))
359 BaseNameSources := $(sort $(basename $(FakeSources)))
360 ObjectsO := $(BaseNameSources:%=$(ObjDir)/%.o)
361 ObjectsLO := $(BaseNameSources:%=$(ObjDir)/%.lo)
362 ObjectsBC := $(BaseNameSources:%=$(ObjDir)/%.bc)
365 Sources := $(notdir $(wildcard $(BUILD_SRC_DIR)/*.cpp \
366 $(BUILD_SRC_DIR)/*.cc $(BUILD_SRC_DIR)/*.c $(BUILD_SRC_DIR)/*.y \
367 $(BUILD_SRC_DIR)/*.l))
369 Sources := $(SOURCES)
373 Sources += $(filter %.cpp %.c %.cc %.y %.l,$(BUILT_SOURCES))
376 BaseNameSources := $(sort $(basename $(Sources)))
377 ObjectsO := $(BaseNameSources:%=$(ObjDir)/%.o)
378 ObjectsLO := $(BaseNameSources:%=$(ObjDir)/%.lo)
379 ObjectsBC := $(BaseNameSources:%=$(ObjDir)/%.bc)
382 ###############################################################################
383 # DIRECTORIES: Handle recursive descent of directory structure
384 ###############################################################################
386 #---------------------------------------------------------
387 # Provide rules to make install dirs. This must be early
388 # in the file so they get built before dependencies
389 #---------------------------------------------------------
392 $(Verb) $(MKDIR) $(bindir)
395 $(Verb) $(MKDIR) $(libdir)
398 $(Verb) $(MKDIR) $(includedir)
401 $(Verb) $(MKDIR) $(sysconfdir)
403 # To create other directories, as needed, and timestamp their creation
405 $(Verb) $(MKDIR) $* > /dev/null
408 .PRECIOUS: $(ObjDir)/.dir $(LibDir)/.dir $(ToolDir)/.dir $(ExmplDir)/.dir
409 .PRECIOUS: $(LLVMLibDir)/.dir $(LLVMToolDir)/.dir $(LLVMExmplDir)/.dir
411 #---------------------------------------------------------
412 # Handle the DIRS options for sequential construction
413 #---------------------------------------------------------
418 $(RecursiveTargets)::
419 $(Verb) for dir in $(DIRS); do \
420 if [ ! -f $$dir/Makefile ]; then \
422 $(CP) $(BUILD_SRC_DIR)/$$dir/Makefile $$dir/Makefile; \
424 if [ ! -f $$dir/LLVM_DO_NOT_BUILD ]; then \
425 ($(MAKE) -C $$dir $@ ) || exit 1; \
430 #---------------------------------------------------------
431 # Handle the EXPERIMENTAL_DIRS options ensuring success
432 # after each directory is built.
433 #---------------------------------------------------------
434 ifdef EXPERIMENTAL_DIRS
435 $(RecursiveTargets)::
436 $(Verb) for dir in $(EXPERIMENTAL_DIRS); do \
437 if [ ! -f $$dir/Makefile ]; then \
439 $(CP) $(BUILD_SRC_DIR)/$$dir/Makefile $$dir/Makefile; \
441 if [ ! -f $$dir/LLVM_DO_NOT_BUILD ]; then \
442 ($(MAKE) -C $$dir $@ ) || exit 0; \
447 #---------------------------------------------------------
448 # Handle the PARALLEL_DIRS options for parallel construction
449 #---------------------------------------------------------
452 SubDirs += $(PARALLEL_DIRS)
454 # Unfortunately, this list must be maintained if new recursive targets are added
455 all :: $(addsuffix /.makeall ,$(PARALLEL_DIRS))
456 clean :: $(addsuffix /.makeclean ,$(PARALLEL_DIRS))
457 clean-all:: $(addsuffix /.makeclean-all,$(PARALLEL_DIRS))
458 install :: $(addsuffix /.makeinstall ,$(PARALLEL_DIRS))
459 uninstall:: $(addsuffix /.makeuninstall,$(PARALLEL_DIRS))
460 install-bytecode :: $(addsuffix /.makeinstall-bytecode,$(PARALLEL_DIRS))
462 ParallelTargets := $(foreach T,$(RecursiveTargets),%/.make$(T))
465 $(Verb) if [ ! -f $(@D)/Makefile ]; then \
467 $(CP) $(BUILD_SRC_DIR)/$(@D)/Makefile $(@D)/Makefile; \
469 if [ ! -f $$dir/LLVM_DO_NOT_BUILD ]; then \
470 $(MAKE) -C $(@D) $(subst $(@D)/.make,,$@) ; \
474 #---------------------------------------------------------
475 # Handle the OPTIONAL_DIRS options for directores that may
477 #---------------------------------------------------------
480 SubDirs += $(OPTIONAL_DIRS)
482 $(RecursiveTargets)::
483 $(Verb) for dir in $(OPTIONAL_DIRS); do \
484 if [ -d $(BUILD_SRC_DIR)/$$dir ]; then\
485 if [ ! -f $$dir/Makefile ]; then \
487 $(CP) $(BUILD_SRC_DIR)/$$dir/Makefile $$dir/Makefile; \
489 if [ ! -f $$dir/LLVM_DO_NOT_BUILD ]; then \
490 ($(MAKE) -C$$dir $@ ) || exit 1; \
496 #---------------------------------------------------------
497 # Handle the CONFIG_FILES options
498 #---------------------------------------------------------
501 install-local:: $(sysconfdir) $(CONFIG_FILES)
502 $(Echo) Installing Configuration Files To $(sysconfdir)
503 $(Verb)for file in $(CONFIG_FILES); do \
504 if test -f $(BUILD_OBJ_DIR)/$${file} ; then \
505 $(INSTALL) $(BUILD_OBJ_DIR)/$${file} $(sysconfdir) ; \
506 elif test -f $(BUILD_SRC_DIR)/$${file} ; then \
507 $(INSTALL) $(BUILD_SRC_DIR)/$${file} $(sysconfdir) ; \
509 $(ECHO) Error: cannot find config file $${file}. ; \
514 $(Echo) Uninstalling Configuration Files From $(sysconfdir)
515 $(Verb)for file in $(CONFIG_FILES); do \
516 $(RM) -f $(sysconfdir)/$${file} ; \
521 ###############################################################################
522 # Library Build Rules: Four ways to build a library
523 ###############################################################################
525 #---------------------------------------------------------
526 # Bytecode Module Targets:
527 # If the user set MODULE_NAME then they want to build a
528 # bytecode module from the sources. We compile all the
529 # sources and link it together into a single bytecode
531 #---------------------------------------------------------
535 Module := $(LibDir)/$(MODULE_NAME).bc
536 LinkModule := $(LLVMGCCWITHPATH) -shared -nostdlib
538 ifdef EXPORTED_SYMBOL_FILE
539 LinkMOdule += -Xlinker -internalize-public-api-file=$(EXPORTED_SYMBOL_FILE)
542 $(Module): $(BUILT_SOURCES) $(ObjectsBC) $(LibDir)/.dir $(GCCLD)
543 $(Echo) Building $(BuildMOde) Bytecode Module $(notdir $@)
544 $(Verb) $(LinkModule) -o $@ $(ObjectsBC)
546 all-local:: $(Module)
549 ifneq ($(strip $(Module)),)
550 -$(Verb) $(RM) -f $(Module)
553 ifdef BYTECODE_DESTINATION
554 ModuleDestDir := $(BYTECODE_DESTINATION)
556 ModuleDestDir := $(libdir)
559 DestModule := $(ModuleDestDir)/$(MODULE_NAME).bc
561 install-module:: $(DestModule)
562 install-local:: $(DestModule)
564 $(DestModule): $(ModuleDestDir) $(Module)
565 $(Echo) Installing $(BuildMode) Bytecode Module $(DestModule)
566 $(Verb) $(INSTALL) $(Module) $@
569 $(Echo) Uninstalling $(BuildMode) Bytecode Module $(DestModule)
570 -$(Verb) $(RM) -f $(DestModule)
574 # if we're building a library ...
577 # Make sure there isn't any extranous whitespace on the LIBRARYNAME option
578 LIBRARYNAME := $(strip $(LIBRARYNAME))
579 ifdef LOADABLE_MODULE
580 LibName.LA := $(LibDir)/$(LIBRARYNAME).la
582 LibName.LA := $(LibDir)/lib$(LIBRARYNAME).la
584 LibName.A := $(LibDir)/lib$(LIBRARYNAME).a
585 LibName.O := $(LibDir)/$(LIBRARYNAME).o
586 LibName.BCA:= $(LibDir)/lib$(LIBRARYNAME).bca
588 #---------------------------------------------------------
589 # Shared Library Targets:
590 # If the user asked for a shared library to be built
591 # with the SHARED_LIBRARY variable, then we provide
592 # targets for building them.
593 #---------------------------------------------------------
596 all-local:: $(LibName.LA)
598 $(LibName.LA): $(ObjectsLO) $(LibDir)/.dir
599 $(Echo) Linking $(BuildMode) Shared Library $(LIBRARYNAME)$(SHLIBEXT)
600 $(Verb) $(Link) -o $@ $(ObjectsLO)
601 $(Verb) $(LTInstall) $@ $(LibDir)
604 ifneq ($(strip $(LibName.LA)),)
605 -$(Verb) $(RM) -f $(LibName.LA)
608 DestSharedLib = $(libdir)/lib$(LIBRARYNAME)$(SHLIBEXT)
610 install-local:: $(DestSharedLib)
612 $(DestSharedLib): $(libdir) $(LibName.LA)
613 $(Echo) Installing $(BuildMode) Shared Library $(DestSharedLib)
614 $(Verb) $(LTInstall) $(LibName.LA) $(DestSharedLib)
615 $(Verb) $(LIBTOOL) --finish $(libdir)
618 $(Echo) Uninstalling $(BuildMode) Shared Library $(DestSharedLib)
619 -$(Verb) $(RM) -f $(libdir)/lib$(LIBRARYNAME).*
623 #---------------------------------------------------------
624 # Bytecode Library Targets:
625 # If the user asked for a bytecode library to be built
626 # with the BYTECODE_LIBRARY variable, then we provide
627 # targets for building them.
628 #---------------------------------------------------------
629 ifdef BYTECODE_LIBRARY
631 # make the C and C++ compilers strip debug info out of bytecode libraries.
632 BCCompile.C += -Wa,-strip-debug
633 BCCompile.CXX += -Wa,-strip-debug
635 all-local:: $(LibName.BCA)
637 ifdef EXPORTED_SYMBOL_FILE
638 BCLinkLib = $(LLVMGCCWITHPATH) -shared -nostdlib -Xlinker \
639 -internalize-public-api-file=$(EXPORTED_SYMBOL_FILE)
641 $(LibName.BCA): $(ObjectsBC) $(LibDir)/.dir $(GCCLD) \
642 $(LLVMToolDir)/llvm-ar
643 $(Echo) Building $(BuildMode) Bytecode Archive $(notdir $@) \
645 $(Verb) $(BCLinkLib) -o $(ObjDir)/$(LIBRARYNAME).o $(ObjectsBC)
647 $(Verb) $(LArchive) $@ $(ObjDir)/$(LIBRARYNAME).o
649 $(LibName.BCA): $(ObjectsBC) $(LibDir)/.dir \
650 $(LLVMToolDir)/llvm-ar
651 $(Echo) Building $(BuildMode) Bytecode Archive $(notdir $@)
653 $(Verb) $(LArchive) $@ $(ObjectsBC)
658 ifneq ($(strip $(LibName.BCA)),)
659 -$(Verb) $(RM) -f $(LibName.BCA)
662 ifdef BYTECODE_DESTINATION
663 BytecodeDestDir := $(BYTECODE_DESTINATION)
665 BytecodeDestDir := $(libdir)
668 DestBytecodeLib = $(BytecodeDestDir)/lib$(LIBRARYNAME).a
670 install-bytecode-local:: $(DestBytecodeLib)
672 install-local:: $(DestBytecodeLib)
674 $(DestBytecodeLib): $(BytecodeDestDir) $(LibName.BCA)
675 $(Echo) Installing $(BuildMode) Bytecode Archive $(DestBytecodeLib)
676 $(Verb) $(INSTALL) $(LibName.BCA) $@
679 $(Echo) Uninstalling $(BuildMode) Bytecode Archive $(DestBytecodeLib)
680 -$(Verb) $(RM) -f $(DestBytecodeLib)
684 #---------------------------------------------------------
685 # ReLinked Library Targets:
686 # If the user didn't explicitly forbid building a
687 # relinked then we provide targets for building them.
688 #---------------------------------------------------------
689 ifndef DONT_BUILD_RELINKED
691 all-local:: $(LibName.O)
693 $(LibName.O): $(ObjectsO) $(LibDir)/.dir
694 $(Echo) Linking $(BuildMode) Object Library $(notdir $@)
695 $(Verb) $(Relink) -o $@ $(ObjectsO)
698 ifneq ($(strip $(LibName.O)),)
699 -$(Verb) $(RM) -f $(LibName.O)
702 DestRelinkedLib = $(libdir)/$(LIBRARYNAME).o
704 install-local:: $(DestRelinkedLib)
706 $(DestRelinkedLib): $(libdir) $(LibName.O)
707 $(Echo) Installing $(BuildMode) Object Library $(DestRelinkedLib)
708 $(Verb) $(LTInstall) $(LibName.O) $(DestRelinkedLib)
711 $(Echo) Uninstalling $(BuildMode) Object Library $(DestRelinkedLib)
712 -$(Verb) $(RM) -f $(DestRelinkedLib)
716 #---------------------------------------------------------
717 # Archive Library Targets:
718 # If the user wanted a regular archive library built,
719 # then we provide targets for building them.
720 #---------------------------------------------------------
723 all-local:: $(LibName.A)
725 $(LibName.A): $(ObjectsO) $(LibDir)/.dir
726 $(Echo) Building $(BuildMode) Archive Library $(notdir $@)
728 $(Verb) $(Archive) $@ $(ObjectsO)
732 ifneq ($(strip $(LibName.A)),)
733 -$(Verb) $(RM) -f $(LibName.A)
736 DestArchiveLib := $(libdir)/lib$(LIBRARYNAME).a
738 install-local:: $(DestArchiveLib)
740 $(DestArchiveLib): $(libdir) $(LibName.A)
741 $(Echo) Installing $(BuildMode) Archive Library $(DestArchiveLib)
742 $(Verb) $(MKDIR) $(libdir)
743 $(Verb) $(LTInstall) $(LibName.A) $(DestArchiveLib)
746 $(Echo) Uninstalling $(BuildMode) Archive Library $(DestArchiveLib)
747 -$(Verb) $(RM) -f $(DestArchiveLib)
754 ###############################################################################
755 # Tool Build Rules: Build executable tool based on TOOLNAME option
756 ###############################################################################
760 #---------------------------------------------------------
761 # Handle the special "JIT" value for LLVM_LIBS which is a
762 # shorthand for a bunch of libraries that get the correct
763 # JIT support for a tool that runs JIT.
764 #---------------------------------------------------------
765 ifeq ($(LLVMLIBS),JIT)
767 # Make sure we can get our own symbols in the tool
770 # Generic JIT libraries
771 JIT_LIBS := LLVMInterpreter LLVMJIT LLVMCodeGen LLVMExecutionEngine
773 # You can enable the X86 JIT on a non-X86 host by setting the flag
774 # ENABLE_X86_JIT on the make command line. If not, it will still be
775 # enabled automagically on an X86 host.
780 # What the X86 JIT requires
782 JIT_LIBS += LLVMX86 LLVMSelectionDAG
785 # You can enable the SparcV9 JIT on a non-SparcV9 host by setting the flag
786 # ENABLE_SPARCV9_JIT on the make command line. If not, it will still be
787 # enabled automagically on an SparcV9 host.
788 ifeq ($(ARCH), Sparc)
789 ENABLE_SPARCV9_JIT = 1
792 # What the Sparc JIT requires
793 ifdef ENABLE_SPARCV9_JIT
794 JIT_LIBS += LLVMSparcV9 LLVMSparcV9ModuloSched LLVMSparcV9InstrSched \
795 LLVMSparcV9LiveVar LLVMInstrumentation.a LLVMProfilePaths \
796 LLVMBCWriter LLVMTransforms.a LLVMipo.a LLVMipa.a \
797 LLVMDataStructure.a LLVMSparcV9RegAlloc
800 # You can enable the PowerPC JIT on a non-PowerPC host by setting the flag
801 # ENABLE_PPC_JIT on the make command line. If not, it will still be
802 # enabled automagically on an PowerPC host.
803 ifeq ($(ARCH), PowerPC)
807 # What the PowerPC JIT requires
809 JIT_LIBS += LLVMPowerPC
812 LLVMLIBS := $(JIT_LIBS) LLVMScalarOpts LLVMAnalysis.a LLVMTransformUtils.a \
813 LLVMBCReader LLVMCore LLVMSupport.a LLVMTarget.a LLVMbzip2 \
814 LLVMSystem.a $(PLATFORMLIBDL)
817 #---------------------------------------------------------
818 # Set up variables for building a tool.
819 #---------------------------------------------------------
821 ToolBuildPath := $(ExmplDir)/$(TOOLNAME)$(EXEEXT)
823 ToolBuildPath := $(ToolDir)/$(TOOLNAME)$(EXEEXT)
825 ProjLibsOptions := $(patsubst %.a.o, -l%, $(addsuffix .o, $(USEDLIBS)))
826 ProjLibsOptions := $(patsubst %.o, $(LibDir)/%.o, $(ProjLibsOptions))
827 LLVMLibsOptions := $(patsubst %.a.o, -l%, $(addsuffix .o, $(LLVMLIBS)))
828 LLVMLibsOptions := $(patsubst %.o, $(LLVMLibDir)/%.o, $(LLVMLibsOptions))
829 ProjUsedLibs := $(patsubst %.a.o, lib%.a, $(addsuffix .o, $(USEDLIBS)))
830 LLVMUsedLibs := $(patsubst %.a.o, lib%.a, $(addsuffix .o, $(LLVMLIBS)))
831 ProjLibsPaths := $(addprefix $(LibDir)/,$(ProjUsedLibs))
832 LLVMLibsPaths := $(addprefix $(LLVMLibDir)/,$(LLVMUsedLibs))
834 #---------------------------------------------------------
835 # Tell make that we need to rebuild subdirectories before
836 # we can link the tool. This affects things like LLI which
837 # has library subdirectories.
838 #---------------------------------------------------------
839 $(ToolBuildPath): $(addsuffix /.makeall, $(PARALLEL_DIRS))
841 #---------------------------------------------------------
842 # Provide targets for building the tools
843 #---------------------------------------------------------
844 all-local:: $(ToolBuildPath)
847 ifneq ($(strip $(ToolBuildPath)),)
848 -$(Verb) $(RM) -f $(ToolBuildPath)
852 $(ToolBuildPath): $(ExmplDir)/.dir
854 $(ToolBuildPath): $(ToolDir)/.dir
857 $(ToolBuildPath): $(ObjectsO) $(ProjLibsPaths) $(LLVMLibsPaths)
858 $(Echo) Linking $(BuildMode) executable $(TOOLNAME) $(StripWarnMsg)
859 $(Verb) $(Link) -o $@ $(TOOLLINKOPTS) $(ObjectsO) $(ProjLibsOptions) \
860 $(LLVMLibsOptions) $(ExtraLibs) $(TOOLLINKOPTSB)
861 $(Echo) ======= Finished Linking $(BuildMode) Executable $(TOOLNAME) $(StripWarnMsg)
863 DestTool = $(bindir)/$(TOOLNAME)
865 install-local:: $(DestTool)
867 $(DestTool): $(bindir) $(ToolBuildPath)
868 $(Echo) Installing $(BuildMode) $(DestTool)
869 $(Verb) $(INSTALL) $(ToolBuildPath) $(DestTool)
872 $(Echo) Uninstalling $(BuildMode) $(DestTool)
873 -$(Verb) $(RM) -f $(DestTool)
877 ###############################################################################
878 # Object Build Rules: Build object files based on sources
879 ###############################################################################
881 # Provide rule sets for when dependency generation is enabled
882 ifndef DISABLE_AUTO_DEPENDENCIES
884 #---------------------------------------------------------
885 # Create .lo files in the ObjDir directory from the .cpp and .c files...
886 #---------------------------------------------------------
889 $(ObjDir)/%.lo $(ObjDir)/%.o: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES)
890 $(Echo) "Compiling $*.cpp for $(BuildMode) build (PIC)"
891 $(Verb) if $(LTCompile.CXX) -MD -MT $@ -MP -MF $(ObjDir)/$*.LACXXd $< -o $@ ; \
892 then $(MV) -f "$(ObjDir)/$*.LACXXd" "$(ObjDir)/$*.d"; \
893 else $(RM) -f "$(ObjDir)/$*.LACXXd"; exit 1; fi
895 $(ObjDir)/%.lo $(ObjDir)/%.o: %.c $(ObjDir)/.dir $(BUILT_SOURCES)
896 $(Echo) "Compiling $*.c for $(BuildMode) build (PIC)"
897 $(Verb) if $(LTCompile.C) -MD -MT $@ -MP -MF $(ObjDir)/$*.LACd $< -o $@ ; \
898 then $(MV) -f "$(ObjDir)/$*.LACd" "$(ObjDir)/$*.d"; \
899 else $(RM) -f "$(ObjDir)/$*.LACd"; exit 1; fi
901 #---------------------------------------------------------
902 # Create .o files in the ObjDir directory from the .cpp and .c files...
903 #---------------------------------------------------------
906 $(ObjDir)/%.o: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES)
907 $(Echo) "Compiling $*.cpp for $(BuildMode) build"
908 $(Verb) if $(Compile.CXX) -MD -MT $@ -MP -MF $(ObjDir)/$*.CXXd $< -o $@ ; \
909 then $(MV) -f "$(ObjDir)/$*.CXXd" "$(ObjDir)/$*.d"; \
910 else $(RM) -f "$(ObjDir)/$*.CXXd"; exit 1; fi
912 $(ObjDir)/%.o: %.c $(ObjDir)/.dir $(BUILT_SOURCES)
913 $(Echo) "Compiling $*.c for $(BuildMode) build"
914 $(Verb) if $(Compile.C) -MD -MT $@ -MP -MF $(ObjDir)/$*.Cd $< -o $@ ; \
915 then $(MV) -f "$(ObjDir)/$*.Cd" "$(ObjDir)/$*.d"; \
916 else $(RM) -f "$(ObjDir)/$*.Cd"; exit 1; fi
920 #---------------------------------------------------------
921 # Create .bc files in the ObjDir directory from .cpp and .c files...
922 #---------------------------------------------------------
923 $(ObjDir)/%.bc: %.cpp $(ObjDir)/.dir $(GCCAS) $(BUILT_SOURCES)
924 $(Echo) "Compiling $*.cpp for $(BuildMode) build (bytecode)"
925 $(Verb) if $(BCCompile.CXX) -MD -MT $@ -MP -MF "$(ObjDir)/$*.BCCXXd" $< -o $@ ; \
926 then $(MV) -f "$(ObjDir)/$*.BCCXXd" "$(ObjDir)/$*.d"; \
927 else $(RM) -f "$(ObjDir)/$*.BCCXXd"; exit 1; fi
929 $(ObjDir)/%.bc: %.c $(ObjDir)/.dir $(GCCAS) $(BUILT_SOURCES)
930 $(Echo) "Compiling $*.c for $(BuildMode) build (bytecode)"
931 $(Verb) if $(BCCompile.C) -MD -MT $@ -MP -MF "$(ObjDir)/$*.BCCd" $< -o $@ ; \
932 then $(MV) -f "$(ObjDir)/$*.BCCd" "$(ObjDir)/$*.d"; \
933 else $(RM) -f "$(ObjDir)/$*.BCCd"; exit 1; fi
935 # Provide alternate rule sets if dependencies are disabled
940 $(ObjDir)/%.lo $(ObjDir)/%.o: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES)
941 $(Echo) "Compiling $*.cpp for $(BuildMode) build (PIC)"
942 $(LTCompile.CXX) $< -o $@
944 $(ObjDir)/%.lo $(ObjDir)/%.o: %.c $(ObjDir)/.dir $(BUILT_SOURCES)
945 $(Echo) "Compiling $*.c for $(BuildMode) build (PIC)"
946 $(LTCompile.C) $< -o $@
950 $(ObjDir)/%.o: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES)
951 $(Echo) "Compiling $*.cpp for $(BuildMode) build"
952 $(Compile.CXX) $< -o $@
954 $(ObjDir)/%.o: %.c $(ObjDir)/.dir $(BUILT_SOURCES)
955 $(Echo) "Compiling $*.c for $(BuildMode) build"
956 $(Compile.C) $< -o $@
959 $(ObjDir)/%.bc: %.cpp $(ObjDir)/.dir $(GCCAS) $(BUILT_SOURCES)
960 $(Echo) "Compiling $*.cpp for $(BuildMode) build (bytecode)"
961 $(BCCompile.CXX) $< -o $@
963 $(ObjDir)/%.bc: %.c $(ObjDir)/.dir $(GCCAS) $(BUILT_SOURCES)
964 $(Echo) "Compiling $*.c for $(BuildMode) build (bytecode)"
965 $(BCCompile.C) $< -o $@
969 #---------------------------------------------------------
970 # Provide rule to build .bc files from .ll sources,
971 # regardless of dependencies
972 #---------------------------------------------------------
973 $(ObjDir)/%.bc: %.ll $(ObjDir)/.dir $(LLVMAS)
974 $(Echo) "Compiling $*.ll for $(BuildMode) build"
975 $(Verb) $(LLVMAS) $< -f -o $@
977 ###############################################################################
978 # TABLEGEN: Provide rules for running tblgen to produce *.inc files
979 ###############################################################################
983 TDFiles := $(strip $(wildcard $(BUILD_SRC_DIR)/*.td) $(LLVM_SRC_ROOT)/lib/Target/Target.td)
984 INCFiles := $(filter %.inc,$(BUILT_SOURCES))
985 INCTMPFiles := $(INCFiles:%=$(ObjDir)/%.tmp)
986 .PRECIOUS: $(INCTMPFiles) $(INCFiles)
988 # All of these files depend on tblgen and the .td files.
989 $(INCTMPFiles) : $(TBLGEN) $(TDFiles)
991 # INCFiles rule: All of the tblgen generated files are emitted to
992 # $(ObjDir)/%.inc.tmp, instead of emitting them directly to %.inc. This allows
993 # us to only "touch" the real file if the contents of it change. IOW, if
994 # tblgen is modified, all of the .inc.tmp files are regereated, but no
995 # dependencies of the .inc files are, unless the contents of the .inc file
997 $(INCFiles) : %.inc : $(ObjDir)/%.inc.tmp
998 $(Verb) $(CMP) -s $@ $< || $(CP) $< $@
1000 $(TARGET:%=$(ObjDir)/%GenRegisterNames.inc.tmp): \
1001 $(ObjDir)/%GenRegisterNames.inc.tmp : %.td $(ObjDir)/.dir
1002 $(Echo) "Building $(<F) register names with tblgen"
1003 $(Verb) $(TableGen) -gen-register-enums -o $@ $<
1005 $(TARGET:%=$(ObjDir)/%GenRegisterInfo.h.inc.tmp): \
1006 $(ObjDir)/%GenRegisterInfo.h.inc.tmp : %.td $(ObjDir)/.dir
1007 $(Echo) "Building $(<F) register information header with tblgen"
1008 $(Verb) $(TableGen) -gen-register-desc-header -o $@ $<
1010 $(TARGET:%=$(ObjDir)/%GenRegisterInfo.inc.tmp): \
1011 $(ObjDir)/%GenRegisterInfo.inc.tmp : %.td $(ObjDir)/.dir
1012 $(Echo) "Building $(<F) register info implementation with tblgen"
1013 $(Verb) $(TableGen) -gen-register-desc -o $@ $<
1015 $(TARGET:%=$(ObjDir)/%GenInstrNames.inc.tmp): \
1016 $(ObjDir)/%GenInstrNames.inc.tmp : %.td $(ObjDir)/.dir
1017 $(Echo) "Building $(<F) instruction names with tblgen"
1018 $(Verb) $(TableGen) -gen-instr-enums -o $@ $<
1020 $(TARGET:%=$(ObjDir)/%GenInstrInfo.inc.tmp): \
1021 $(ObjDir)/%GenInstrInfo.inc.tmp : %.td $(ObjDir)/.dir
1022 $(Echo) "Building $(<F) instruction information with tblgen"
1023 $(Verb) $(TableGen) -gen-instr-desc -o $@ $<
1025 $(TARGET:%=$(ObjDir)/%GenAsmWriter.inc.tmp): \
1026 $(ObjDir)/%GenAsmWriter.inc.tmp : %.td $(ObjDir)/.dir
1027 $(Echo) "Building $(<F) assembly writer with tblgen"
1028 $(Verb) $(TableGen) -gen-asm-writer -o $@ $<
1030 $(TARGET:%=$(ObjDir)/%GenAsmWriter1.inc.tmp): \
1031 $(ObjDir)/%GenAsmWriter1.inc.tmp : %.td $(ObjDir)/.dir
1032 $(Echo) "Building $(<F) assembly writer #1 with tblgen"
1033 $(Verb) $(TableGen) -gen-asm-writer -asmwriternum=1 -o $@ $<
1035 $(TARGET:%=$(ObjDir)/%GenCodeEmitter.inc.tmp): \
1036 $(ObjDir)/%GenCodeEmitter.inc.tmp: %.td $(ObjDir)/.dir
1037 $(Echo) "Building $(<F) code emitter with tblgen"
1038 $(Verb) $(TableGen) -gen-emitter -o $@ $<
1041 -$(Verb) $(RM) -f $(INCFiles)
1045 ###############################################################################
1046 # LEX AND YACC: Provide rules for generating sources with lex and yacc
1047 ###############################################################################
1049 #---------------------------------------------------------
1050 # Provide rules for generating a .cpp source file from
1051 # (f)lex input sources.
1052 #---------------------------------------------------------
1054 LexFiles := $(filter %.l,$(Sources))
1056 ifneq ($(LexFiles),)
1058 LexOutput := $(strip $(patsubst %.l,%.cpp,$(LexFiles)))
1060 .PRECIOUS: $(LexOutput)
1062 # Note the extra sed filtering here, used to cut down on the warnings emited
1063 # by GCC. The last line is a gross hack to work around flex aparently not
1064 # being able to resize the buffer on a large token input. Currently, for
1065 # uninitialized string buffers in LLVM we can generate very long tokens, so
1066 # this is a hack around it.
1067 # FIXME. (f.e. char Buffer[10000] )
1069 $(Echo) Flexing $*.l
1070 $(Verb) $(FLEX) -t $< | \
1071 $(SED) 's/void yyunput/inline void yyunput/' | \
1072 $(SED) 's/void \*yy_flex_realloc/inline void *yy_flex_realloc/' | \
1073 $(SED) 's/#define YY_BUF_SIZE 16384/#define YY_BUF_SIZE (16384*64)/' \
1077 -$(Verb) $(RM) -f $(LexOutput)
1078 $(Verb) $(RM) -f $(LexOutput)
1082 #---------------------------------------------------------
1083 # Provide rules for generating a .cpp and .h source files
1084 # from yacc (bison) input sources.
1085 #---------------------------------------------------------
1087 YaccFiles := $(filter %.y,$(Sources))
1088 ifneq ($(YaccFiles),)
1089 YaccOutput := $(addprefix $(patsubst %.y,%,$(YaccFiles)),.h .cpp .output)
1091 .PRECIOUS: $(YaccOutput)
1093 # Cancel built-in rules for yacc
1098 # Rule for building the bison parsers...
1100 $(Echo) "Bisoning $*.y"
1101 $(Verb) $(BISON) -v -d -p $(<F:%Parser.y=%) -o $*.tab.c $<
1102 $(Verb) $(MV) -f $*.tab.c $*.cpp
1103 $(Verb) $(MV) -f $*.tab.h $*.h
1106 -$(Verb) $(RM) -f $(YaccOutput)
1107 $(Verb) $(RM) -f $(YaccOutput)
1110 ###############################################################################
1111 # OTHER RULES: Other rules needed
1112 ###############################################################################
1114 # To create postscript files from dot files...
1115 ifneq ($(DOT),false)
1117 $(DOT) -Tps < $< > $@
1120 $(Echo) "Cannot build $@: The program dot is not installed"
1123 # This rules ensures that header files that are removed still have a rule for
1124 # which they can be "generated." This allows make to ignore them and
1125 # reproduce the dependency lists.
1128 # Define clean-local to clean the current directory. Note that this uses a
1129 # very conservative approach ensuring that empty variables do not cause
1130 # errors or disastrous removal.
1132 ifneq ($(strip $(ObjDir)),)
1133 -$(Verb) $(RM) -rf $(ObjDir)
1135 -$(Verb) $(RM) -f core core.[0-9][0-9]* *.o *.d *~ *.flc
1136 ifneq ($(strip $(SHLIBEXT)),) # Extra paranoia - make real sure SHLIBEXT is set
1137 -$(Verb) $(RM) -f *$(SHLIBEXT)
1141 -$(Verb) $(RM) -rf Debug Release Profile
1143 # Build tags database for Emacs/Xemacs:
1147 find $(BUILD_SRC_ROOT)/include $(BUILD_SRC_ROOT)/lib \
1148 $(BUILD_SRC_ROOT)/tools $(BUILD_SRC_ROOT)/examples \
1149 $(BUILD_OBJ_ROOT)/include $(BUILD_OBJ_ROOT)/lib \
1150 $(BUILD_OBJ_ROOT)/tools $(BUILD_OBJ_ROOT)/examples \
1151 -name '*.cpp' -o -name '*.h' | \
1152 $(ETAGS) $(ETAGSFLAGS) -
1155 find $(BUILD_SRC_ROOT)/include $(BUILD_SRC_ROOT)/lib \
1156 $(BUILD_SRC_ROOT)/tools $(BUILD_SRC_ROOT)/examples \
1157 $(BUILD_OBJ_ROOT)/include $(BUILD_OBJ_ROOT)/lib \
1158 $(BUILD_OBJ_ROOT)/tools $(BUILD_OBJ_ROOT)/examples \
1159 \( -name '*.cpp' -o -name '*.h' \) -print | \
1160 ctags -ImtT -o $(BUILD_OBJ_ROOT)/CTAGS -L -
1163 ###############################################################################
1164 # DEPENDENCIES: Include the dependency files if we should
1165 ###############################################################################
1166 ifndef DISABLE_AUTO_DEPENDENCIES
1168 # If its not one of the cleaning targets
1169 ifneq ($strip($(filter-out clean clean-local dist-clean,$(MAKECMDGOALS))),)
1171 # Get the list of dependency files
1172 DependFiles := $(basename $(filter %.cpp %.c %.cc, $(Sources)))
1173 DependFiles := $(patsubst %,$(BUILD_OBJ_DIR)/$(BuildMode)/%.d,$(DependFiles))
1175 -include /dev/null $(DependFiles)
1181 ###############################################################################
1182 # CHECK: Running the test suite
1183 ###############################################################################
1186 $(Verb) if test -d "$(BUILD_OBJ_ROOT)/test" ; then \
1187 if test -f "$(BUILD_OBJ_ROOT)/test/Makefile" ; then \
1188 $(EchoCmd) Running test suite ; \
1189 $(MAKE) -C $(BUILD_OBJ_ROOT)/test check-local \
1190 TESTSUITE=$(TESTSUITE) ; \
1192 $(EchoCmd) No Makefile in test directory ; \
1195 $(EchoCmd) No test directory ; \
1198 ###############################################################################
1199 # DISTRIBUTION: Handle construction of a distribution tarball
1200 ###############################################################################
1202 #------------------------------------------------------------------------
1203 # Define distribution related variables
1204 #------------------------------------------------------------------------
1205 DistName := $(LLVM_TARBALL_NAME)
1206 DistDir := $(BUILD_OBJ_ROOT)/$(DistName)
1207 TopDistDir := $(BUILD_OBJ_ROOT)/$(DistName)
1208 DistTarGZip := $(BUILD_OBJ_ROOT)/$(DistName).tar.gz
1209 DistZip := $(BUILD_OBJ_ROOT)/$(DistName).zip
1210 DistTarBZ2 := $(BUILD_OBJ_ROOT)/$(DistName).tar.bz2
1211 DistAlways := CREDITS.TXT LICENSE.TXT README.txt README AUTHORS COPYING \
1212 ChangeLog INSTALL NEWS Makefile Makefile.common Makefile.rules \
1213 Makefile.config.in configure autoconf
1214 DistOther := $(notdir $(wildcard \
1215 $(BUILD_SRC_DIR)/*.h \
1216 $(BUILD_SRC_DIR)/*.td \
1217 $(BUILD_SRC_DIR)/*.def \
1218 $(BUILD_SRC_DIR)/*.ll \
1219 $(BUILD_SRC_DIR)/*.in))
1220 DistSubDirs := $(SubDirs)
1221 DistSources = $(Sources) $(EXTRA_DIST)
1222 DistFiles = $(DistAlways) $(DistSources) $(DistOther)
1224 #------------------------------------------------------------------------
1225 # We MUST build distribution with OBJ_DIR != SRC_DIR
1226 #------------------------------------------------------------------------
1227 ifeq ($(BUILD_SRC_DIR),$(BUILD_OBJ_DIR))
1228 dist dist-check dist-clean dist-gzip dist-bzip2 dist-zip ::
1229 $(Echo) ERROR: Target $@ only available with OBJ_DIR != SRC_DIR
1233 #------------------------------------------------------------------------
1234 # Prevent catastrophic remove
1235 #------------------------------------------------------------------------
1236 ifeq ($(LLVM_TARBALL_NAME),)
1237 $(error LLVM_TARBALL_NAME is empty. Please rerun configure)
1240 #------------------------------------------------------------------------
1241 # Prevent attempt to run dist targets from anywhere but the top level
1242 #------------------------------------------------------------------------
1245 dist dist-check dist-clean dist-gzip dist-bzip2 dist-zip ::
1246 $(Echo) ERROR: You must run $@ from $(BUILD_OBJ_ROOT)
1250 #------------------------------------------------------------------------
1251 # Provide the top level targets
1252 #------------------------------------------------------------------------
1254 dist-gzip:: $(DistTarGZip)
1256 $(DistTarGZip) : $(TopDistDir)/.makedistdir
1257 $(Echo) Packing gzipped distribution tar file.
1258 $(Verb) cd $(BUILD_OBJ_ROOT) ; $(TAR) chf - "$(DistName)" | \
1259 $(GZIP) -c > "$(DistTarGZip)"
1261 dist-bzip2:: $(DistTarBZ2)
1263 $(DistTarBZ2) : $(TopDistDir)/.makedistdir
1264 $(Echo) Packing bzipped distribution tar file.
1265 $(Verb) cd $(BUILD_OBJ_ROOT) ; $(TAR) chf - $(DistName) | \
1266 $(BZIP2) -c >$(DistTarBZ2)
1268 dist-zip:: $(DistZip)
1270 $(DistZip) : $(TopDistDir)/.makedistdir
1271 $(Echo) Packing zipped distribution file.
1272 $(Verb) rm -f $(DistZip)
1273 $(Verb) cd $(BUILD_OBJ_ROOT) ; $(ZIP) -rq $(DistZip) $(DistName)
1275 dist :: $(DistTarGZip) $(DistTarBZ2) $(DistZip)
1276 $(Echo) ===== DISTRIBUTION PACKAGING SUCESSFUL =====
1278 DistCheckDir := $(LLVM_OBJ_ROOT)/_distcheckdir
1280 dist-check:: $(DistTarGZip)
1281 $(Echo) Checking distribution tar file.
1282 $(Verb) if test -d $(DistCheckDir) ; then \
1283 $(RM) -rf $(DistCheckDir) ; \
1285 $(Verb) $(MKDIR) $(DistCheckDir)
1286 $(Verb) cd $(DistCheckDir) && \
1287 $(MKDIR) $(DistCheckDir)/build && \
1288 $(MKDIR) $(DistCheckDir)/install && \
1289 gunzip -c $(DistTarGZip) | $(TAR) xf - && \
1291 ../$(DistName)/configure --prefix="$(DistCheckDir)/install" \
1292 --srcdir=../$(DistName) && \
1295 $(MAKE) install && \
1296 $(MAKE) uninstall && \
1299 $(MAKE) dist-clean && \
1300 $(EchoCmd) ===== $(DistTarGZip) Ready For Distribution =====
1303 $(Echo) Cleaning distribution files
1304 -$(Verb) $(RM) -rf $(DistTarGZip) $(DistTarBZ2) $(DistZip) $(DistName) \
1309 #------------------------------------------------------------------------
1310 # Provide the recursive distdir target for building the distribution directory
1311 #------------------------------------------------------------------------
1312 distdir: $(DistDir)/.makedistdir
1313 $(DistDir)/.makedistdir: $(DistSources)
1314 $(Verb) if test "$(DistDir)" = "$(TopDistDir)" ; then \
1315 if test -d "$(DistDir)" ; then \
1316 find $(DistDir) -type d ! -perm -200 -exec chmod u+w {} ';' || \
1319 $(EchoCmd) Removing old $(DistDir) ; \
1320 $(RM) -rf $(DistDir); \
1321 $(EchoCmd) Making 'all' to verify build ; \
1324 $(Echo) Building Distribution Directory $(DistDir)
1325 $(Verb) $(MKDIR) $(DistDir)
1326 $(Verb) srcdirstrip=`echo "$(BUILD_SRC_DIR)" | sed 's|.|.|g'`; \
1327 srcrootstrip=`echo "$(BUILD_SRC_ROOT)" | sed 's|.|.|g'`; \
1328 for file in $(DistFiles) ; do \
1330 $(BUILD_SRC_DIR)/*) \
1331 file=`echo "$$file" | sed "s#^$$srcdirstrip/##"` \
1333 $(BUILD_SRC_ROOT)/*) \
1334 file=`echo "$$file" | \
1335 sed "s#^$$srcrootstrip/##"` \
1338 if test -f "$(BUILD_SRC_DIR)/$$file" || \
1339 test -d "$(BUILD_SRC_DIR)/$$file" ; then \
1340 from_dir="$(BUILD_SRC_DIR)" ; \
1341 elif test -f "$$file" || test -d "$$file" ; then \
1344 to_dir=`echo "$$file" | sed -e 's#/[^/]*$$##'` ; \
1345 if test "$$to_dir" != "$$file" && test "$$to_dir" != "."; then \
1346 to_dir="$(DistDir)/$$dir"; \
1347 $(MKDIR) "$$to_dir" ; \
1349 to_dir="$(DistDir)"; \
1351 mid_dir=`echo "$$file" | sed -n -e 's#^\(.*\)/[^/]*$$#\1#p'`; \
1352 if test -n "$$mid_dir" ; then \
1353 $(MKDIR) "$$to_dir/$$mid_dir" || exit 1; \
1355 if test -d "$$from_dir/$$file"; then \
1356 if test -d "$(BUILD_SRC_DIR)/$$file" && \
1357 test "$$from_dir" != "$(BUILD_SRC_DIR)" ; then \
1358 $(CP) -pR "$(BUILD_SRC_DIR)/$$file" "$$to_dir" || exit 1; \
1360 $(CP) -pR $$from_dir/$$file $$to_dir || exit 1; \
1361 elif test -f "$$from_dir/$$file" ; then \
1362 $(CP) -p "$$from_dir/$$file" "$(DistDir)/$$file" || exit 1; \
1363 elif test -L "$$from_dir/$$file" ; then \
1364 $(CP) -pd "$$from_dir/$$file" $(DistDir)/$$file || exit 1; \
1365 elif echo "$(DistAlways)" | grep -v "$$file" >/dev/null ; then \
1366 $(EchoCmd) "===== WARNING: Distribution Source " \
1367 "$$from_dir/$$file Not Found!" ; \
1368 elif test "$(Verb)" != '@' ; then \
1369 $(EchoCmd) "Skipping non-existent $$from_dir/$$file" ; \
1372 $(Verb) for subdir in $(DistSubDirs) ; do \
1373 if test "$$subdir" \!= "." ; then \
1374 new_distdir="$(DistDir)/$$subdir" ; \
1375 test -d "$$new_distdir" || $(MKDIR) "$$new_distdir" || exit 1; \
1376 ( cd $$subdir && $(MAKE) DistDir="$$new_distdir" distdir ) || \
1380 $(Verb) if test "$(DistDir)" = "$(TopDistDir)" ; then \
1381 $(EchoCmd) Eliminating CVS directories from distribution ; \
1382 $(RM) -rf `find $(TopDistDir) -type d -name CVS -print` ;\
1383 $(MAKE) dist-hook ; \
1384 $(FIND) $(TopDistDir) -type d ! -perm -777 -exec chmod a+rwx {} \; \
1385 -o ! -type d ! -perm -444 -links 1 -exec chmod a+r {} \; \
1386 -o ! -type d ! -perm -400 -exec chmod a+r {} \; \
1387 -o ! -type d ! -perm -444 -exec \
1388 $(SHELL) $(INSTALL_SH) -c -m a+r {} {} \; \
1389 || chmod -R a+r $(DistDir) ; \
1392 # This is invoked by distdir target, define it as a no-op to avoid errors if not
1398 ###############################################################################
1399 # TOP LEVEL - targets only to apply at the top level directory
1400 ###############################################################################
1404 #------------------------------------------------------------------------
1405 # Install support for the project's include files:
1406 #------------------------------------------------------------------------
1408 $(Echo) Installing include files
1409 $(Verb) $(MKDIR) $(includedir)
1410 $(Verb) if [ -d "$(BUILD_SRC_ROOT)/include" ] ; then \
1411 cd $(BUILD_SRC_ROOT)/include && \
1412 find . -path '*/Internal' -prune -o '(' -type f \
1413 '!' '(' -name '*~' -o -name '.cvsignore' -o -name '.#*' ')' \
1414 -print ')' | grep -v CVS | pax -rwdvpe $(includedir) ; \
1418 $(Echo) Uninstalling include files
1419 $(Verb) if [ -d "$(BUILD_SRC_ROOT)/include" ] ; then \
1420 cd $(BUILD_SRC_ROOT)/include && \
1421 $(RM) -f `find . -path '*/Internal' -prune -o '(' -type f \
1422 '!' '(' -name '*~' -o -name '.cvsignore' -o -name '.#*' ')' \
1423 -print ')' | grep -v CVS | sed 's#^#$(includedir)/#'` ; \
1428 #------------------------------------------------------------------------
1429 # Print out the directories used for building
1430 #------------------------------------------------------------------------
1432 $(Echo) "BuildMode : " '$(BuildMode)'
1433 $(Echo) "BUILD_SRC_ROOT : " '$(BUILD_SRC_ROOT)'
1434 $(Echo) "BUILD_SRC_DIR : " '$(BUILD_SRC_DIR)'
1435 $(Echo) "BUILD_OBJ_ROOT : " '$(BUILD_OBJ_ROOT)'
1436 $(Echo) "BUILD_OBJ_DIR : " '$(BUILD_OBJ_DIR)'
1437 $(Echo) "LLVM_SRC_ROOT : " '$(LLVM_SRC_ROOT)'
1438 $(Echo) "LLVM_OBJ_ROOT : " '$(LLVM_OBJ_ROOT)'
1439 $(Echo) "libdir : " '$(libdir)'
1440 $(Echo) "bindir : " '$(bindir)'
1441 $(Echo) "sysconfdir : " '$(sysconfdir)'
1442 $(Echo) "UserTargets : " '$(UserTargets)'
1443 $(Echo) "ObjMakefiles : " '$(ObjMakefiles)'
1444 $(Echo) "SrcMakefiles : " '$(SrcMakefiles)'
1445 $(Echo) "ObjDir : " '$(ObjDir)'
1446 $(Echo) "LibDir : " '$(LibDir)'
1447 $(Echo) "ToolDir : " '$(ToolDir)'
1448 $(Echo) "ExmplDir : " '$(ExmplDir)'
1449 $(Echo) "Sources : " '$(Sources)'
1450 $(Echo) "TDFiles : " '$(TDFiles)'
1451 $(Echo) "INCFiles : " '$(INCFiles)'
1452 $(Echo) "INCTMPFiles : " '$(INCTMPFiles)'
1453 $(Echo) "Compile.CXX : " '$(Compile.CXX)'
1454 $(Echo) "Compile.C : " '$(Compile.C)'
1455 $(Echo) "Archive : " '$(Archive)'
1456 $(Echo) "YaccFiles : " '$(YaccFiles)'
1457 $(Echo) "LexFiles : " '$(LexFiles)'
1458 $(Echo) "Module : " '$(Module)'