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 #--------------------------------------------------------------------
40 #--------------------------------------------------------------------
41 # Reset the list of suffixes we know how to build
42 #--------------------------------------------------------------------
44 .SUFFIXES: .c .cpp .cc .h .hpp .y .l .lo .o .a .bc .td .ps .dot .ll
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 $(PROJ_SRC_DIR)/Makefile*))
65 ObjMakefiles := $(subst $(PROJ_SRC_DIR),$(PROJ_OBJ_DIR),$(SrcMakefiles))
66 ConfigureScript := $(PROJ_SRC_ROOT)/configure
67 ConfigStatusScript := $(PROJ_OBJ_ROOT)/config.status
68 MakefileConfigIn := $(strip $(wildcard $(PROJ_SRC_ROOT)/Makefile.config.in))
69 MakefileCommonIn := $(strip $(wildcard $(PROJ_SRC_ROOT)/Makefile.common.in))
70 MakefileConfig := $(PROJ_OBJ_ROOT)/Makefile.config
71 MakefileCommon := $(PROJ_OBJ_ROOT)/Makefile.common
72 PreConditions := $(ConfigStatusScript) $(ObjMakefiles)
73 ifneq ($(MakefileCommonIn),)
74 PreConditions += $(MakefileCommon)
76 ifneq ($(MakefileConfigIn),)
77 PreConditions += $(MakefileConfig)
80 preconditions: $(PreConditions)
82 #------------------------------------------------------------------------
83 # Make sure the BUILT_SOURCES are built first
84 #------------------------------------------------------------------------
85 $(filter-out clean clean-local,$(UserTargets)):: $(BUILT_SOURCES)
88 ifneq ($(strip $(BUILT_SOURCES)),)
89 -$(Verb) $(RM) -f $(BUILT_SOURCES)
92 ifneq ($(PROJ_OBJ_ROOT),$(PROJ_SRC_ROOT))
94 $(Verb) if test -x config.status ; then \
95 $(EchoCmd) Wiping out $(PROJ_OBJ_ROOT) ; \
96 $(MKDIR) .spotless.save ; \
97 $(MV) config.status .spotless.save ; \
98 $(MV) mklib .spotless.save ; \
99 $(MV) projects .spotless.save ; \
101 $(MV) .spotless.save/config.status . ; \
102 $(MV) .spotless.save/mklib . ; \
103 $(MV) .spotless.save/projects . ; \
104 $(RM) -rf .spotless.save ; \
105 $(EchoCmd) Rebuilding configuration of $(PROJ_OBJ_ROOT) ; \
106 $(ConfigStatusScript) --recheck $(ConfigureScriptFLAGS) && \
107 $(ConfigStatusScript) ; \
109 $(EchoCmd) "make spotless" can only be run from $(PROJ_OBJ_ROOT); \
113 $(EchoCmd) "spotless target not supported for objdir == srcdir"
116 $(BUILT_SOURCES) : $(ObjMakefiles)
118 #------------------------------------------------------------------------
119 # Make sure we're not using a stale configuration
120 #------------------------------------------------------------------------
122 $(Echo) Reconfiguring $(PROJ_OBJ_ROOT)
123 $(Verb) cd $(PROJ_OBJ_ROOT) && \
124 if test -w $(PROJ_OBJ_ROOT)/config.cache ; then \
125 $(RM) $(PROJ_OBJ_ROOT)/config.cache ; \
127 $(ConfigStatusScript) --recheck $(ConfigureScriptFLAGS) && \
128 $(ConfigStatusScript)
130 .PRECIOUS: $(ConfigStatusScript)
131 $(ConfigStatusScript): $(ConfigureScript)
132 $(Echo) Reconfiguring with $<
133 $(Verb) cd $(PROJ_OBJ_ROOT) && \
134 if test -w $(PROJ_OBJ_ROOT)/config.cache ; then \
135 $(RM) $(PROJ_OBJ_ROOT)/config.cache ; \
137 $(ConfigStatusScript) --recheck $(ConfigureScriptFLAGS) && \
138 $(ConfigStatusScript)
140 #------------------------------------------------------------------------
141 # Make sure the configuration makefile is up to date
142 #------------------------------------------------------------------------
143 ifneq ($(MakefileConfigIn),)
144 $(MakefileConfig): $(MakefileConfigIn) $(ConfigStatusScript)
145 $(Echo) Regenerating $@
146 $(Verb) cd $(PROJ_OBJ_ROOT) ; $(ConfigStatusScript) Makefile.config
149 ifneq ($(MakefileCommonIn),)
150 $(MakefileCommon): $(MakefileCommonIn) $(ConfigStatusScript)
151 $(Echo) Regenerating $@
152 $(Verb) cd $(PROJ_OBJ_ROOT) ; $(ConfigStatusScript) Makefile.common
155 #------------------------------------------------------------------------
156 # If the Makefile in the source tree has been updated, copy it over into the
157 # build tree. But, only do this if the source and object makefiles differ
158 #------------------------------------------------------------------------
159 ifneq ($(PROJ_OBJ_DIR),$(PROJ_SRC_DIR))
161 Makefile: $(PROJ_SRC_DIR)/Makefile
162 $(Echo) "Updating Makefile"
163 $(Verb) $(MKDIR) $(@D)
164 $(Verb) $(CP) -f $< $@
166 # Copy the Makefile.* files unless we're in the root directory which avoids
167 # the copying of Makefile.config.in or other things that should be explicitly
169 $(PROJ_OBJ_DIR)/Makefile% : $(PROJ_SRC_DIR)/Makefile%
171 *Makefile.rules) ;; \
173 *) $(Echo) "Updating $(@F)" ; \
180 #------------------------------------------------------------------------
181 # Set up the basic dependencies
182 #------------------------------------------------------------------------
183 $(UserTargets):: $(PreConditions)
187 clean-all:: clean-local clean-all-local
188 install:: install-local
189 uninstall:: uninstall-local
190 install-local:: all-local
191 install-bytecode:: install-bytecode-local
193 ###############################################################################
194 # VARIABLES: Set up various variables based on configuration data
195 ###############################################################################
197 #--------------------------------------------------------------------
198 # Variables derived from configuration we are building
199 #--------------------------------------------------------------------
202 ifdef ENABLE_PROFILING
204 CXX.Flags := -O3 -DNDEBUG -felide-constructors -finline-functions -pg
205 C.Flags := -O3 -DNDEBUG -pg
206 LD.Flags := -O3 -DNDEBUG -pg
208 ifdef ENABLE_OPTIMIZED
210 # Don't use -fomit-frame-pointer on FreeBSD
211 ifneq ($(OS),FreeBSD)
212 OmitFramePointer := -fomit-frame-pointer
214 CXX.Flags := -O3 -DNDEBUG -finline-functions -felide-constructors \
216 C.Flags := -O3 -DNDEBUG $(OmitFramePointer)
217 LD.Flags := -O3 -DNDEBUG
220 CXX.Flags := -g -D_DEBUG
221 C.Flags := -g -D_DEBUG
222 LD.Flags := -g -D_DEBUG
227 CXX.Flags += $(CXXFLAGS)
229 CPP.Flags += $(CPPFLAGS)
230 LD.Flags += $(LDFLAGS)
232 LibTool.Flags := --tag=CXX
234 #Make Floating point ieee complient on alpha
240 #--------------------------------------------------------------------
241 # Directory locations
242 #--------------------------------------------------------------------
243 ObjDir := $(PROJ_OBJ_DIR)/$(BuildMode)
244 LibDir := $(PROJ_OBJ_ROOT)/$(BuildMode)/lib
245 ToolDir := $(PROJ_OBJ_ROOT)/$(BuildMode)/bin
246 ExmplDir := $(PROJ_OBJ_ROOT)/$(BuildMode)/examples
247 LLVMLibDir := $(LLVM_OBJ_ROOT)/$(BuildMode)/lib
248 LLVMToolDir := $(LLVM_OBJ_ROOT)/$(BuildMode)/bin
249 LLVMExmplDir:= $(LLVM_OBJ_ROOT)/$(BuildMode)/examples
250 CFERuntimeLibDir := $(LLVMGCCDIR)/lib
252 #--------------------------------------------------------------------
253 # Full Paths To Compiled Tools and Utilities
254 #--------------------------------------------------------------------
255 EchoCmd = $(ECHO) llvm[$(MAKELEVEL)]:
258 LIBTOOL := $(LLVM_OBJ_ROOT)/mklib
261 LLVMAS := $(LLVMToolDir)/llvm-as$(EXEEXT)
264 BURG := $(LLVMToolDir)/burg$(EXEEXT)
267 TBLGEN := $(LLVMToolDir)/tblgen$(EXEEXT)
270 GCCAS := $(LLVMToolDir)/gccas$(EXEEXT)
273 GCCLD := $(LLVMToolDir)/gccld$(EXEEXT)
276 LLVMDIS := $(LLVMToolDir)/llvm-dis$(EXEEXT)
279 LLI := $(LLVMToolDir)/lli$(EXEEXT)
282 LLC := $(LLVMToolDir)/llc$(EXEEXT)
285 LOPT := $(LLVMToolDir)/opt$(EXEEXT)
288 LBUGPOINT := $(LLVMToolDir)/bugpoint$(EXEEXT)
291 LLVMGCCWITHPATH := PATH="$(LLVMToolDir):$(PATH)" $(LLVMGCC)
292 LLVMGXXWITHPATH := PATH="$(LLVMToolDir):$(PATH)" $(LLVMGXX)
294 #--------------------------------------------------------------------
295 # Adjust to user's request
296 #--------------------------------------------------------------------
298 # Adjust LD.Flags and Libtool.Flags depending on the kind of library that is
299 # to be built. Note that if LOADABLE_MODULE is specified then the resulting
300 # shared library can be opened with dlopen
302 LD.Flags += -rpath $(LibDir)
303 ifdef LOADABLE_MODULE
307 LibTool.Flags += --tag=disable-shared
317 # Adjust settings for verbose mode
320 LibTool.Flags += --silent
321 AR.Flags += >/dev/null 2>/dev/null
322 ConfigureScriptFLAGS += >$(PROJ_OBJ_DIR)/configure.out 2>&1
324 ConfigureScriptFLAGS :=
327 # By default, strip symbol information from executable
329 Strip := $(PLATFORMSTRIPOPTS)
330 StripWarnMsg := "(without symbols)"
331 Install.StripFlag += -s
334 # Adjust linker flags for building an executable
337 LD.Flags += -rpath $(ExmplDir) -export-dynamic
339 LD.Flags += -rpath $(ToolDir) -export-dynamic
343 #----------------------------------------------------------
344 # Options To Invoke Tools
345 #----------------------------------------------------------
347 CompileCommonOpts := -Wall -W -Wwrite-strings -Wno-unused
350 CompileCommonOpts += -D_REENTRANT -D_HPUX_SOURCE
353 LD.Flags += -L$(LibDir) -L$(LLVMLibDir)
354 CPP.Flags += -I$(PROJ_OBJ_DIR) -I$(PROJ_SRC_DIR) \
355 -I$(PROJ_OBJ_ROOT)/include \
356 -I$(PROJ_SRC_ROOT)/include \
357 -I$(LLVM_OBJ_ROOT)/include \
358 -I$(LLVM_SRC_ROOT)/include \
359 -D_GNU_SOURCE -D__STDC_LIMIT_MACROS
361 Compile.C = $(CC) $(CPP.Flags) $(CompileCommonOpts) -c $(C.Flags)
362 LTCompile.C = $(LIBTOOL) $(LibTool.Flags) --mode=compile $(Compile.C)
363 BCCompile.C = $(LLVMGCCWITHPATH) $(CPP.Flags) $(CompileCommonOpts) \
365 Preprocess.C = $(CC) $(CPP.Flags) $(CompileCommonOpts) -E $(C.Flags)
367 Compile.CXX = $(CXX) $(CPP.Flags) $(CompileCommonOpts) $(CXX.Flags) -c
368 LTCompile.CXX = $(LIBTOOL) $(LibTool.Flags) --mode=compile $(Compile.CXX)
369 BCCompile.CXX = $(LLVMGXXWITHPATH) $(CPP.Flags) $(CompileCommonOpts) \
371 Preprocess.CXX= $(CXX) $(CPP.Flags) $(CompileCommonOpts) $(CXX.Flags) -E
372 Link = $(LIBTOOL) $(LibTool.Flags) --mode=link $(CXX) $(CPP.Flags) \
373 $(CompileCommonOpts) $(LD.Flags) $(Strip)
374 Relink = $(LIBTOOL) $(LibTool.Flags) --mode=link $(CXX) $(CPP.Flags) \
376 LTInstall = $(LIBTOOL) $(LibTool.Flags) --mode=install $(INSTALL) \
378 ProgInstall = $(INSTALL) $(Install.StripFlag) -m 0755
379 DataInstall = $(INSTALL) -m 0644
380 Burg = $(BURG) -I $(PROJ_SRC_DIR)
381 TableGen = $(TBLGEN) -I $(PROJ_SRC_DIR)
382 Archive = $(AR) $(AR.Flags)
383 LArchive = $(LLVMToolDir)/llvm-ar rcsf
390 #----------------------------------------------------------
391 # Get the list of source files and compute object file
393 #----------------------------------------------------------
396 Sources := $(notdir $(wildcard $(PROJ_SRC_DIR)/*.cpp \
397 $(PROJ_SRC_DIR)/*.cc $(PROJ_SRC_DIR)/*.c $(PROJ_SRC_DIR)/*.y \
398 $(PROJ_SRC_DIR)/*.l))
400 Sources := $(SOURCES)
404 Sources += $(filter %.cpp %.c %.cc %.y %.l,$(BUILT_SOURCES))
407 BaseNameSources := $(sort $(basename $(Sources)))
409 ObjectsO := $(BaseNameSources:%=$(ObjDir)/%.o)
410 ObjectsLO := $(BaseNameSources:%=$(ObjDir)/%.lo)
411 ObjectsBC := $(BaseNameSources:%=$(ObjDir)/%.bc)
413 ###############################################################################
414 # DIRECTORIES: Handle recursive descent of directory structure
415 ###############################################################################
417 #---------------------------------------------------------
418 # Provide rules to make install dirs. This must be early
419 # in the file so they get built before dependencies
420 #---------------------------------------------------------
422 $(PROJ_bindir): $(PROJ_bindir)/.dir
423 $(PROJ_libdir): $(PROJ_libdir)/.dir
424 $(PROJ_includedir): $(PROJ_includedir)/.dir
425 $(PROJ_etcdir): $(PROJ_etcdir)/.dir
427 # To create other directories, as needed, and timestamp their creation
429 $(Verb) $(MKDIR) $* > /dev/null
432 .PRECIOUS: $(ObjDir)/.dir $(LibDir)/.dir $(ToolDir)/.dir $(ExmplDir)/.dir
433 .PRECIOUS: $(LLVMLibDir)/.dir $(LLVMToolDir)/.dir $(LLVMExmplDir)/.dir
435 #---------------------------------------------------------
436 # Handle the DIRS options for sequential construction
437 #---------------------------------------------------------
442 $(RecursiveTargets)::
443 $(Verb) for dir in $(DIRS); do \
444 if [ ! -f $$dir/Makefile ]; then \
446 $(CP) $(PROJ_SRC_DIR)/$$dir/Makefile $$dir/Makefile; \
448 if [ ! -f $$dir/LLVM_DO_NOT_BUILD ]; then \
449 ($(MAKE) -C $$dir $@ ) || exit 1; \
454 #---------------------------------------------------------
455 # Handle the EXPERIMENTAL_DIRS options ensuring success
456 # after each directory is built.
457 #---------------------------------------------------------
458 ifdef EXPERIMENTAL_DIRS
459 $(RecursiveTargets)::
460 $(Verb) for dir in $(EXPERIMENTAL_DIRS); do \
461 if [ ! -f $$dir/Makefile ]; then \
463 $(CP) $(PROJ_SRC_DIR)/$$dir/Makefile $$dir/Makefile; \
465 if [ ! -f $$dir/LLVM_DO_NOT_BUILD ]; then \
466 ($(MAKE) -C $$dir $@ ) || exit 0; \
471 #-----------------------------------------------------------
472 # Handle the PARALLEL_DIRS options for parallel construction
473 #-----------------------------------------------------------
476 SubDirs += $(PARALLEL_DIRS)
478 # Unfortunately, this list must be maintained if new recursive targets are added
479 all :: $(addsuffix /.makeall ,$(PARALLEL_DIRS))
480 clean :: $(addsuffix /.makeclean ,$(PARALLEL_DIRS))
481 clean-all:: $(addsuffix /.makeclean-all,$(PARALLEL_DIRS))
482 install :: $(addsuffix /.makeinstall ,$(PARALLEL_DIRS))
483 uninstall:: $(addsuffix /.makeuninstall,$(PARALLEL_DIRS))
484 install-bytecode :: $(addsuffix /.makeinstall-bytecode,$(PARALLEL_DIRS))
486 ParallelTargets := $(foreach T,$(RecursiveTargets),%/.make$(T))
489 $(Verb) if [ ! -f $(@D)/Makefile ]; then \
491 $(CP) $(PROJ_SRC_DIR)/$(@D)/Makefile $(@D)/Makefile; \
493 if [ ! -f $$dir/LLVM_DO_NOT_BUILD ]; then \
494 $(MAKE) -C $(@D) $(subst $(@D)/.make,,$@) ; \
498 #---------------------------------------------------------
499 # Handle the OPTIONAL_DIRS options for directores that may
501 #---------------------------------------------------------
504 SubDirs += $(OPTIONAL_DIRS)
506 $(RecursiveTargets)::
507 $(Verb) for dir in $(OPTIONAL_DIRS); do \
508 if [ -d $(PROJ_SRC_DIR)/$$dir ]; then\
509 if [ ! -f $$dir/Makefile ]; then \
511 $(CP) $(PROJ_SRC_DIR)/$$dir/Makefile $$dir/Makefile; \
513 if [ ! -f $$dir/LLVM_DO_NOT_BUILD ]; then \
514 ($(MAKE) -C$$dir $@ ) || exit 1; \
520 #---------------------------------------------------------
521 # Handle the CONFIG_FILES options
522 #---------------------------------------------------------
525 install-local:: $(PROJ_etcdir) $(CONFIG_FILES)
526 $(Echo) Installing Configuration Files To $(PROJ_etcdir)
527 $(Verb)for file in $(CONFIG_FILES); do \
528 if test -f $(PROJ_OBJ_DIR)/$${file} ; then \
529 $(DataInstall) $(PROJ_OBJ_DIR)/$${file} $(PROJ_etcdir) ; \
530 elif test -f $(PROJ_SRC_DIR)/$${file} ; then \
531 $(DataInstall) $(PROJ_SRC_DIR)/$${file} $(PROJ_etcdir) ; \
533 $(ECHO) Error: cannot find config file $${file}. ; \
538 $(Echo) Uninstalling Configuration Files From $(PROJ_etcdir)
539 $(Verb)for file in $(CONFIG_FILES); do \
540 $(RM) -f $(PROJ_etcdir)/$${file} ; \
545 ###############################################################################
546 # Set up variables for building libararies
547 ###############################################################################
549 #---------------------------------------------------------
550 # Handle the special "JIT" value for LLVM_LIBS which is a
551 # shorthand for a bunch of libraries that get the correct
552 # JIT support for a library or a tool that runs JIT.
553 #---------------------------------------------------------
554 ifeq ($(LLVMLIBS),JIT)
556 # Make sure we can get our own symbols in the tool
559 # Generic JIT libraries
560 JIT_LIBS := LLVMInterpreter LLVMJIT LLVMCodeGen LLVMExecutionEngine
562 # You can enable the X86 JIT on a non-X86 host by setting the flag
563 # ENABLE_X86_JIT on the make command line. If not, it will still be
564 # enabled automagically on an X86 host.
569 # What the X86 JIT requires
571 JIT_LIBS += LLVMX86 LLVMSelectionDAG
574 # You can enable the SparcV9 JIT on a non-SparcV9 host by setting the flag
575 # ENABLE_SPARCV9_JIT on the make command line. If not, it will still be
576 # enabled automagically on an SparcV9 host.
577 ifeq ($(ARCH), Sparc)
578 ENABLE_SPARCV9_JIT = 1
581 # What the Sparc JIT requires
582 ifdef ENABLE_SPARCV9_JIT
583 JIT_LIBS += LLVMSparcV9 LLVMSparcV9ModuloSched LLVMSparcV9InstrSched \
584 LLVMSparcV9LiveVar LLVMInstrumentation.a \
585 LLVMBCWriter LLVMTransforms.a LLVMipo.a LLVMipa.a \
586 LLVMDataStructure LLVMSparcV9RegAlloc
589 # You can enable the PowerPC JIT on a non-PowerPC host by setting the flag
590 # ENABLE_PPC_JIT on the make command line. If not, it will still be
591 # enabled automagically on an PowerPC host.
592 ifeq ($(ARCH), PowerPC)
596 # What the PowerPC JIT requires
598 JIT_LIBS += LLVMPowerPC LLVMSelectionDAG
601 # You can enable the Alpha JIT on a non-Alpha host by setting the flag
602 # ENABLE_ALPHA_JIT on the make command line. If not, it will still be
603 # enabled automagically on an Alpha host.
604 ifeq ($(ARCH), Alpha)
608 # What the Alpha JIT requires
609 ifdef ENABLE_ALPHA_JIT
610 JIT_LIBS += LLVMAlpha LLVMSelectionDAG
613 LLVMLIBS := $(JIT_LIBS) LLVMScalarOpts.a LLVMTransformUtils.a LLVMAnalysis.a \
614 LLVMBCReader LLVMCore LLVMSupport.a LLVMTarget.a LLVMbzip2 \
615 LLVMSystem.a $(PLATFORMLIBDL)
618 #---------------------------------------------------------
619 # Define various command line options pertaining to the
620 # libraries needed when linking. There are "Proj" libs
621 # (defined by the user's project) and "LLVM" libs (defined
622 # by the # LLVM project).
623 #---------------------------------------------------------
624 # Some versions of gcc on Alpha produce too many symbols, so use a .a file
626 USEDLIBS := $(subst LLVMCore, LLVMCore.a, $(USEDLIBS))
627 LLVMLIBS := $(subst LLVMCore, LLVMCore.a, $(LLVMLIBS))
630 ProjLibsOptions := $(patsubst %.a.o, -l%, $(addsuffix .o, $(USEDLIBS)))
631 ProjLibsOptions := $(patsubst %.o, $(LibDir)/%.o, $(ProjLibsOptions))
632 LLVMLibsOptions := $(patsubst %.a.o, -l%, $(addsuffix .o, $(LLVMLIBS)))
633 LLVMLibsOptions := $(patsubst %.o, $(LLVMLibDir)/%.o, $(LLVMLibsOptions))
634 ProjUsedLibs := $(patsubst %.a.o, lib%.a, $(addsuffix .o, $(USEDLIBS)))
635 LLVMUsedLibs := $(patsubst %.a.o, lib%.a, $(addsuffix .o, $(LLVMLIBS)))
636 ProjLibsPaths := $(addprefix $(LibDir)/,$(ProjUsedLibs))
637 LLVMLibsPaths := $(addprefix $(LLVMLibDir)/,$(LLVMUsedLibs))
639 ###############################################################################
640 # Library Build Rules: Four ways to build a library
641 ###############################################################################
643 #---------------------------------------------------------
644 # Bytecode Module Targets:
645 # If the user set MODULE_NAME then they want to build a
646 # bytecode module from the sources. We compile all the
647 # sources and link it together into a single bytecode
649 #---------------------------------------------------------
652 ifeq ($(strip $(LLVMGCC)),)
653 $(warning Modules require llvm-gcc but no llvm-gcc is available ****)
656 Module := $(LibDir)/$(MODULE_NAME).bc
657 LinkModule := $(GCCLD)
659 ifdef EXPORTED_SYMBOL_FILE
660 LinkModule += -internalize-public-api-file=$(EXPORTED_SYMBOL_FILE)
663 $(Module): $(BUILT_SOURCES) $(ObjectsBC) $(LibDir)/.dir $(GCCLD)
664 $(Echo) Building $(BuildMode) Bytecode Module $(notdir $@)
665 $(Verb) $(LinkModule) -o $@ $(ObjectsBC)
667 all-local:: $(Module)
670 ifneq ($(strip $(Module)),)
671 -$(Verb) $(RM) -f $(Module)
674 ifdef BYTECODE_DESTINATION
675 ModuleDestDir := $(BYTECODE_DESTINATION)
677 ModuleDestDir := $(PROJ_libdir)
680 DestModule := $(ModuleDestDir)/$(MODULE_NAME).bc
682 install-module:: $(DestModule)
683 install-local:: $(DestModule)
685 $(DestModule): $(ModuleDestDir) $(Module)
686 $(Echo) Installing $(BuildMode) Bytecode Module $(DestModule)
687 $(Verb) $(DataInstall) $(Module) $(DestModule)
690 $(Echo) Uninstalling $(BuildMode) Bytecode Module $(DestModule)
691 -$(Verb) $(RM) -f $(DestModule)
696 # if we're building a library ...
699 # Make sure there isn't any extranous whitespace on the LIBRARYNAME option
700 LIBRARYNAME := $(strip $(LIBRARYNAME))
701 ifdef LOADABLE_MODULE
702 LibName.LA := $(LibDir)/$(LIBRARYNAME).la
704 LibName.LA := $(LibDir)/lib$(LIBRARYNAME).la
706 LibName.A := $(LibDir)/lib$(LIBRARYNAME).a
707 LibName.O := $(LibDir)/$(LIBRARYNAME).o
708 LibName.BCA:= $(LibDir)/lib$(LIBRARYNAME).bca
710 #---------------------------------------------------------
711 # Shared Library Targets:
712 # If the user asked for a shared library to be built
713 # with the SHARED_LIBRARY variable, then we provide
714 # targets for building them.
715 #---------------------------------------------------------
718 all-local:: $(LibName.LA)
720 ifdef LINK_LIBS_IN_SHARED
721 $(LibName.LA): $(ObjectsLO) $(LibDir)/.dir
722 $(Echo) Linking $(BuildMode) Shared Library $(LIBRARYNAME)$(SHLIBEXT)
723 $(Verb) $(Link) -o $@ $(ObjectsLO) \
724 $(ProjLibsOptions) $(LLVMLibsOptions)
725 $(Verb) $(LTInstall) $@ $(LibDir)
727 $(LibName.LA): $(ObjectsLO) $(LibDir)/.dir
728 $(Echo) Linking $(BuildMode) Shared Library $(LIBRARYNAME)$(SHLIBEXT)
729 $(Verb) $(Link) -o $@ $(ObjectsLO)
730 $(Verb) $(LTInstall) $@ $(LibDir)
734 ifneq ($(strip $(LibName.LA)),)
735 -$(Verb) $(RM) -f $(LibName.LA)
738 DestSharedLib = $(PROJ_libdir)/lib$(LIBRARYNAME)$(SHLIBEXT)
740 install-local:: $(DestSharedLib)
742 $(DestSharedLib): $(PROJ_libdir) $(LibName.LA)
743 $(Echo) Installing $(BuildMode) Shared Library $(DestSharedLib)
744 $(Verb) $(LTInstall) $(LibName.LA) $(DestSharedLib)
745 $(Verb) $(LIBTOOL) --finish $(PROJ_libdir)
748 $(Echo) Uninstalling $(BuildMode) Shared Library $(DestSharedLib)
749 -$(Verb) $(RM) -f $(PROJ_libdir)/lib$(LIBRARYNAME).*
753 #---------------------------------------------------------
754 # Bytecode Library Targets:
755 # If the user asked for a bytecode library to be built
756 # with the BYTECODE_LIBRARY variable, then we provide
757 # targets for building them.
758 #---------------------------------------------------------
759 ifdef BYTECODE_LIBRARY
760 ifeq ($(strip $(LLVMGCC)),)
761 $(warning Bytecode libraries require llvm-gcc which could not be found ****)
764 all-local:: $(LibName.BCA)
766 ifdef EXPORTED_SYMBOL_FILE
767 BCLinkLib = $(GCCLD) -internalize-public-api-file=$(EXPORTED_SYMBOL_FILE)
769 $(LibName.BCA): $(ObjectsBC) $(LibDir)/.dir $(GCCLD) \
770 $(LLVMToolDir)/llvm-ar
771 $(Echo) Building $(BuildMode) Bytecode Archive $(notdir $@) \
773 $(Verb) $(BCLinkLib) -o $(ObjDir)/$(LIBRARYNAME).o $(ObjectsBC)
775 $(Verb) $(LArchive) $@ $(ObjDir)/$(LIBRARYNAME).o
777 $(LibName.BCA): $(ObjectsBC) $(LibDir)/.dir \
778 $(LLVMToolDir)/llvm-ar
779 $(Echo) Building $(BuildMode) Bytecode Archive $(notdir $@)
781 $(Verb) $(LArchive) $@ $(ObjectsBC)
786 ifneq ($(strip $(LibName.BCA)),)
787 -$(Verb) $(RM) -f $(LibName.BCA)
790 ifdef BYTECODE_DESTINATION
791 BytecodeDestDir := $(BYTECODE_DESTINATION)
793 BytecodeDestDir := $(PROJ_libdir)
796 DestBytecodeLib = $(BytecodeDestDir)/lib$(LIBRARYNAME).a
798 install-bytecode-local:: $(DestBytecodeLib)
800 install-local:: $(DestBytecodeLib)
802 $(DestBytecodeLib): $(BytecodeDestDir) $(LibName.BCA)
803 $(Echo) Installing $(BuildMode) Bytecode Archive $(DestBytecodeLib)
804 $(Verb) $(DataInstall) $(LibName.BCA) $(DestBytecodeLib)
807 $(Echo) Uninstalling $(BuildMode) Bytecode Archive $(DestBytecodeLib)
808 -$(Verb) $(RM) -f $(DestBytecodeLib)
813 #---------------------------------------------------------
814 # ReLinked Library Targets:
815 # If the user explicitly requests a relinked library with
816 # BUILD_RELINKED, provide it. Otherwise, if they specify
817 # neither of BUILD_ARCHIVE or DONT_BUILD_RELINKED, give
819 #---------------------------------------------------------
821 ifndef DONT_BUILD_RELINKED
828 all-local:: $(LibName.O)
830 $(LibName.O): $(ObjectsO) $(LibDir)/.dir
831 $(Echo) Linking $(BuildMode) Object Library $(notdir $@)
832 $(Verb) $(Relink) -o $@ $(ObjectsO)
835 ifneq ($(strip $(LibName.O)),)
836 -$(Verb) $(RM) -f $(LibName.O)
839 DestRelinkedLib = $(PROJ_libdir)/$(LIBRARYNAME).o
841 install-local:: $(DestRelinkedLib)
843 $(DestRelinkedLib): $(PROJ_libdir) $(LibName.O)
844 $(Echo) Installing $(BuildMode) Object Library $(DestRelinkedLib)
845 $(Verb) $(LTInstall) $(LibName.O) $(DestRelinkedLib)
848 $(Echo) Uninstalling $(BuildMode) Object Library $(DestRelinkedLib)
849 -$(Verb) $(RM) -f $(DestRelinkedLib)
853 #---------------------------------------------------------
854 # Archive Library Targets:
855 # If the user wanted a regular archive library built,
856 # then we provide targets for building them.
857 #---------------------------------------------------------
860 all-local:: $(LibName.A)
862 $(LibName.A): $(ObjectsO) $(LibDir)/.dir
863 $(Echo) Building $(BuildMode) Archive Library $(notdir $@)
865 $(Verb) $(Archive) $@ $(ObjectsO)
869 ifneq ($(strip $(LibName.A)),)
870 -$(Verb) $(RM) -f $(LibName.A)
873 DestArchiveLib := $(PROJ_libdir)/lib$(LIBRARYNAME).a
875 install-local:: $(DestArchiveLib)
877 $(DestArchiveLib): $(PROJ_libdir) $(LibName.A)
878 $(Echo) Installing $(BuildMode) Archive Library $(DestArchiveLib)
879 $(Verb) $(MKDIR) $(PROJ_libdir)
880 $(Verb) $(LTInstall) $(LibName.A) $(DestArchiveLib)
883 $(Echo) Uninstalling $(BuildMode) Archive Library $(DestArchiveLib)
884 -$(Verb) $(RM) -f $(DestArchiveLib)
891 ###############################################################################
892 # Tool Build Rules: Build executable tool based on TOOLNAME option
893 ###############################################################################
897 #---------------------------------------------------------
898 # Set up variables for building a tool.
899 #---------------------------------------------------------
901 ToolBuildPath := $(ExmplDir)/$(strip $(TOOLNAME))$(EXEEXT)
903 ToolBuildPath := $(ToolDir)/$(strip $(TOOLNAME))$(EXEEXT)
906 #---------------------------------------------------------
907 # Tell make that we need to rebuild subdirectories before
908 # we can link the tool. This affects things like LLI which
909 # has library subdirectories.
910 #---------------------------------------------------------
911 $(ToolBuildPath): $(addsuffix /.makeall, $(PARALLEL_DIRS))
913 #---------------------------------------------------------
914 # Provide targets for building the tools
915 #---------------------------------------------------------
916 all-local:: $(ToolBuildPath)
919 ifneq ($(strip $(ToolBuildPath)),)
920 -$(Verb) $(RM) -f $(ToolBuildPath)
924 $(ToolBuildPath): $(ExmplDir)/.dir
926 $(ToolBuildPath): $(ToolDir)/.dir
929 $(ToolBuildPath): $(ObjectsO) $(ProjLibsPaths) $(LLVMLibsPaths)
930 $(Echo) Linking $(BuildMode) executable $(TOOLNAME) $(StripWarnMsg)
931 $(Verb) $(Link) -o $@ $(TOOLLINKOPTS) $(ObjectsO) $(ProjLibsOptions) \
932 $(LLVMLibsOptions) $(ExtraLibs) $(TOOLLINKOPTSB) $(LIBS)
933 $(Echo) ======= Finished Linking $(BuildMode) Executable $(TOOLNAME) \
936 DestTool = $(PROJ_bindir)/$(TOOLNAME)
938 install-local:: $(DestTool)
940 $(DestTool): $(PROJ_bindir) $(ToolBuildPath)
941 $(Echo) Installing $(BuildMode) $(DestTool)
942 $(Verb) $(ProgInstall) $(ToolBuildPath) $(DestTool)
945 $(Echo) Uninstalling $(BuildMode) $(DestTool)
946 -$(Verb) $(RM) -f $(DestTool)
950 ###############################################################################
951 # Object Build Rules: Build object files based on sources
952 ###############################################################################
954 # Provide rule sets for when dependency generation is enabled
955 ifndef DISABLE_AUTO_DEPENDENCIES
957 #---------------------------------------------------------
958 # Create .lo files in the ObjDir directory from the .cpp and .c files...
959 #---------------------------------------------------------
962 $(ObjDir)/%.lo $(ObjDir)/%.o: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES)
963 $(Echo) "Compiling $*.cpp for $(BuildMode) build (PIC)"
964 $(Verb) if $(LTCompile.CXX) -MD -MT $@ -MP -MF $(ObjDir)/$*.LACXXd $< -o $@ ;\
965 then $(MV) -f "$(ObjDir)/$*.LACXXd" "$(ObjDir)/$*.d"; \
966 else $(RM) -f "$(ObjDir)/$*.LACXXd"; exit 1; fi
968 $(ObjDir)/%.lo $(ObjDir)/%.o: %.cc $(ObjDir)/.dir $(BUILT_SOURCES)
969 $(Echo) "Compiling $*.cc for $(BuildMode) build (PIC)"
970 $(Verb) if $(LTCompile.CXX) -MD -MT $@ -MP -MF $(ObjDir)/$*.LACXXd $< -o $@ ;\
971 then $(MV) -f "$(ObjDir)/$*.LACXXd" "$(ObjDir)/$*.d"; \
972 else $(RM) -f "$(ObjDir)/$*.LACXXd"; exit 1; fi
974 $(ObjDir)/%.lo $(ObjDir)/%.o: %.c $(ObjDir)/.dir $(BUILT_SOURCES)
975 $(Echo) "Compiling $*.c for $(BuildMode) build (PIC)"
976 $(Verb) if $(LTCompile.C) -MD -MT $@ -MP -MF $(ObjDir)/$*.LACd $< -o $@ ; \
977 then $(MV) -f "$(ObjDir)/$*.LACd" "$(ObjDir)/$*.d"; \
978 else $(RM) -f "$(ObjDir)/$*.LACd"; exit 1; fi
980 #---------------------------------------------------------
981 # Create .o files in the ObjDir directory from the .cpp and .c files...
982 #---------------------------------------------------------
985 $(ObjDir)/%.o: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES)
986 $(Echo) "Compiling $*.cpp for $(BuildMode) build"
987 $(Verb) if $(Compile.CXX) -MD -MT $@ -MP -MF $(ObjDir)/$*.CXXd $< -o $@ ; \
988 then $(MV) -f "$(ObjDir)/$*.CXXd" "$(ObjDir)/$*.d"; \
989 else $(RM) -f "$(ObjDir)/$*.CXXd"; exit 1; fi
991 $(ObjDir)/%.o: %.cc $(ObjDir)/.dir $(BUILT_SOURCES)
992 $(Echo) "Compiling $*.cc for $(BuildMode) build"
993 $(Verb) if $(Compile.CXX) -MD -MT $@ -MP -MF $(ObjDir)/$*.CXXd $< -o $@ ; \
994 then $(MV) -f "$(ObjDir)/$*.CXXd" "$(ObjDir)/$*.d"; \
995 else $(RM) -f "$(ObjDir)/$*.CXXd"; exit 1; fi
997 $(ObjDir)/%.o: %.c $(ObjDir)/.dir $(BUILT_SOURCES)
998 $(Echo) "Compiling $*.c for $(BuildMode) build"
999 $(Verb) if $(Compile.C) -MD -MT $@ -MP -MF $(ObjDir)/$*.Cd $< -o $@ ; \
1000 then $(MV) -f "$(ObjDir)/$*.Cd" "$(ObjDir)/$*.d"; \
1001 else $(RM) -f "$(ObjDir)/$*.Cd"; exit 1; fi
1005 ## Rules for building preprocessed (.i/.ii) outputs.
1006 $(BuildMode)/%.ii: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES)
1007 $(Echo) "Compiling $*.cpp for $(BuildMode) build to .ii file"
1008 $(Verb) $(Preprocess.CXX) $< -o $@
1010 $(BuildMode)/%.ii: %.cc $(ObjDir)/.dir $(BUILT_SOURCES)
1011 $(Echo) "Compiling $*.cc for $(BuildMode) build to .ii file"
1012 $(Verb) $(Preprocess.CXX) $< -o $@
1014 $(BuildMode)/%.i: %.c $(ObjDir)/.dir $(BUILT_SOURCES)
1015 $(Echo) "Compiling $*.c for $(BuildMode) build to .i file"
1016 $(Verb) $(Preprocess.C) $< -o $@
1019 #---------------------------------------------------------
1020 # Create .bc files in the ObjDir directory from .cpp .cc and .c files...
1021 #---------------------------------------------------------
1023 $(ObjDir)/%.ll: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES)
1024 $(Echo) "Compiling $*.cpp for $(BuildMode) build (bytecode)"
1025 $(Verb) if $(BCCompile.CXX) -MD -MT $@ -MP -MF "$(ObjDir)/$*.BCCXXd" \
1026 $< -o $@ -S -emit-llvm ; \
1027 then $(MV) -f "$(ObjDir)/$*.BCCXXd" "$(ObjDir)/$*.d"; \
1028 else $(RM) -f "$(ObjDir)/$*.BCCXXd"; exit 1; fi
1030 $(ObjDir)/%.ll: %.cc $(ObjDir)/.dir $(BUILT_SOURCES)
1031 $(Echo) "Compiling $*.cc for $(BuildMode) build (bytecode)"
1032 $(Verb) if $(BCCompile.CXX) -MD -MT $@ -MP -MF "$(ObjDir)/$*.BCCXXd" \
1033 $< -o $@ -S -emit-llvm ; \
1034 then $(MV) -f "$(ObjDir)/$*.BCCXXd" "$(ObjDir)/$*.d"; \
1035 else $(RM) -f "$(ObjDir)/$*.BCCXXd"; exit 1; fi
1037 $(ObjDir)/%.ll: %.c $(ObjDir)/.dir $(BUILT_SOURCES)
1038 $(Echo) "Compiling $*.c for $(BuildMode) build (bytecode)"
1039 $(Verb) if $(BCCompile.C) -MD -MT $@ -MP -MF "$(ObjDir)/$*.BCCd" \
1040 $< -o $@ -S -emit-llvm ; \
1041 then $(MV) -f "$(ObjDir)/$*.BCCd" "$(ObjDir)/$*.d"; \
1042 else $(RM) -f "$(ObjDir)/$*.BCCd"; exit 1; fi
1044 # Provide alternate rule sets if dependencies are disabled
1047 ifdef SHARED_LIBRARY
1049 $(ObjDir)/%.lo $(ObjDir)/%.o: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES)
1050 $(Echo) "Compiling $*.cpp for $(BuildMode) build (PIC)"
1051 $(LTCompile.CXX) $< -o $@
1053 $(ObjDir)/%.lo $(ObjDir)/%.o: %.cc $(ObjDir)/.dir $(BUILT_SOURCES)
1054 $(Echo) "Compiling $*.cc for $(BuildMode) build (PIC)"
1055 $(LTCompile.CXX) $< -o $@
1057 $(ObjDir)/%.lo $(ObjDir)/%.o: %.c $(ObjDir)/.dir $(BUILT_SOURCES)
1058 $(Echo) "Compiling $*.c for $(BuildMode) build (PIC)"
1059 $(LTCompile.C) $< -o $@
1063 $(ObjDir)/%.o: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES)
1064 $(Echo) "Compiling $*.cpp for $(BuildMode) build"
1065 $(Compile.CXX) $< -o $@
1067 $(ObjDir)/%.o: %.cc $(ObjDir)/.dir $(BUILT_SOURCES)
1068 $(Echo) "Compiling $*.cc for $(BuildMode) build"
1069 $(Compile.CXX) $< -o $@
1071 $(ObjDir)/%.o: %.c $(ObjDir)/.dir $(BUILT_SOURCES)
1072 $(Echo) "Compiling $*.c for $(BuildMode) build"
1073 $(Compile.C) $< -o $@
1076 $(ObjDir)/%.ll: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES)
1077 $(Echo) "Compiling $*.cpp for $(BuildMode) build (bytecode)"
1078 $(BCCompile.CXX) $< -o $@ -S -emit-llvm
1080 $(ObjDir)/%.ll: %.cc $(ObjDir)/.dir $(BUILT_SOURCES)
1081 $(Echo) "Compiling $*.cc for $(BuildMode) build (bytecode)"
1082 $(BCCompile.CXX) $< -o $@ -S -emit-llvm
1084 $(ObjDir)/%.ll: %.c $(ObjDir)/.dir $(BUILT_SOURCES)
1085 $(Echo) "Compiling $*.c for $(BuildMode) build (bytecode)"
1086 $(BCCompile.C) $< -o $@ -S -emit-llvm
1090 # make the C and C++ compilers strip debug info out of bytecode libraries.
1092 $(ObjectsBC): $(ObjDir)/%.bc: $(ObjDir)/%.ll $(GCCAS)
1093 $(Echo) "Compiling $*.ll to $*.bc for $(BuildMode) build (bytecode)"
1096 $(ObjectsBC): $(ObjDir)/%.bc: $(ObjDir)/%.ll $(GCCAS)
1097 $(Echo) "Compiling $*.ll to $*.bc for $(BuildMode) build (bytecode)"
1098 @$(GCCAS) -strip-debug $< -o $@
1102 #---------------------------------------------------------
1103 # Provide rule to build .bc files from .ll sources,
1104 # regardless of dependencies
1105 #---------------------------------------------------------
1106 $(ObjDir)/%.bc: %.ll $(ObjDir)/.dir $(LLVMAS)
1107 $(Echo) "Compiling $*.ll for $(BuildMode) build"
1108 $(Verb) $(LLVMAS) $< -f -o $@
1110 ###############################################################################
1111 # TABLEGEN: Provide rules for running tblgen to produce *.inc files
1112 ###############################################################################
1116 TDFiles := $(strip $(wildcard $(PROJ_SRC_DIR)/*.td) \
1117 $(LLVM_SRC_ROOT)/lib/Target/Target.td \
1118 $(LLVM_SRC_ROOT)/lib/Target/TargetSelectionDAG.td)
1119 INCFiles := $(filter %.inc,$(BUILT_SOURCES))
1120 INCTMPFiles := $(INCFiles:%=$(ObjDir)/%.tmp)
1121 .PRECIOUS: $(INCTMPFiles) $(INCFiles)
1123 # All of these files depend on tblgen and the .td files.
1124 $(INCTMPFiles) : $(TBLGEN) $(TDFiles)
1126 # INCFiles rule: All of the tblgen generated files are emitted to
1127 # $(ObjDir)/%.inc.tmp, instead of emitting them directly to %.inc. This allows
1128 # us to only "touch" the real file if the contents of it change. IOW, if
1129 # tblgen is modified, all of the .inc.tmp files are regereated, but no
1130 # dependencies of the .inc files are, unless the contents of the .inc file
1132 $(INCFiles) : %.inc : $(ObjDir)/%.inc.tmp
1133 $(Verb) $(CMP) -s $@ $< || $(CP) $< $@
1135 $(TARGET:%=$(ObjDir)/%GenRegisterNames.inc.tmp): \
1136 $(ObjDir)/%GenRegisterNames.inc.tmp : %.td $(ObjDir)/.dir
1137 $(Echo) "Building $(<F) register names with tblgen"
1138 $(Verb) $(TableGen) -gen-register-enums -o $@ $<
1140 $(TARGET:%=$(ObjDir)/%GenRegisterInfo.h.inc.tmp): \
1141 $(ObjDir)/%GenRegisterInfo.h.inc.tmp : %.td $(ObjDir)/.dir
1142 $(Echo) "Building $(<F) register information header with tblgen"
1143 $(Verb) $(TableGen) -gen-register-desc-header -o $@ $<
1145 $(TARGET:%=$(ObjDir)/%GenRegisterInfo.inc.tmp): \
1146 $(ObjDir)/%GenRegisterInfo.inc.tmp : %.td $(ObjDir)/.dir
1147 $(Echo) "Building $(<F) register info implementation with tblgen"
1148 $(Verb) $(TableGen) -gen-register-desc -o $@ $<
1150 $(TARGET:%=$(ObjDir)/%GenInstrNames.inc.tmp): \
1151 $(ObjDir)/%GenInstrNames.inc.tmp : %.td $(ObjDir)/.dir
1152 $(Echo) "Building $(<F) instruction names with tblgen"
1153 $(Verb) $(TableGen) -gen-instr-enums -o $@ $<
1155 $(TARGET:%=$(ObjDir)/%GenInstrInfo.inc.tmp): \
1156 $(ObjDir)/%GenInstrInfo.inc.tmp : %.td $(ObjDir)/.dir
1157 $(Echo) "Building $(<F) instruction information with tblgen"
1158 $(Verb) $(TableGen) -gen-instr-desc -o $@ $<
1160 $(TARGET:%=$(ObjDir)/%GenAsmWriter.inc.tmp): \
1161 $(ObjDir)/%GenAsmWriter.inc.tmp : %.td $(ObjDir)/.dir
1162 $(Echo) "Building $(<F) assembly writer with tblgen"
1163 $(Verb) $(TableGen) -gen-asm-writer -o $@ $<
1165 $(TARGET:%=$(ObjDir)/%GenAsmWriter1.inc.tmp): \
1166 $(ObjDir)/%GenAsmWriter1.inc.tmp : %.td $(ObjDir)/.dir
1167 $(Echo) "Building $(<F) assembly writer #1 with tblgen"
1168 $(Verb) $(TableGen) -gen-asm-writer -asmwriternum=1 -o $@ $<
1170 $(TARGET:%=$(ObjDir)/%GenCodeEmitter.inc.tmp): \
1171 $(ObjDir)/%GenCodeEmitter.inc.tmp: %.td $(ObjDir)/.dir
1172 $(Echo) "Building $(<F) code emitter with tblgen"
1173 $(Verb) $(TableGen) -gen-emitter -o $@ $<
1175 $(TARGET:%=$(ObjDir)/%GenDAGISel.inc.tmp): \
1176 $(ObjDir)/%GenDAGISel.inc.tmp : %.td $(ObjDir)/.dir
1177 $(Echo) "Building $(<F) instruction selector implementation with tblgen"
1178 $(Verb) $(TableGen) -gen-dag-isel -o $@ $<
1180 $(TARGET:%=$(ObjDir)/%GenSubtarget.inc.tmp): \
1181 $(ObjDir)/%GenSubtarget.inc.tmp : %.td $(ObjDir)/.dir
1182 $(Echo) "Building $(<F) subtarget information with tblgen"
1183 $(Verb) $(TableGen) -gen-subtarget -o $@ $<
1186 -$(Verb) $(RM) -f $(INCFiles)
1190 ###############################################################################
1191 # LEX AND YACC: Provide rules for generating sources with lex and yacc
1192 ###############################################################################
1194 #---------------------------------------------------------
1195 # Provide rules for generating a .cpp source file from
1196 # (f)lex input sources.
1197 #---------------------------------------------------------
1199 LexFiles := $(filter %.l,$(Sources))
1201 ifneq ($(LexFiles),)
1203 # Cancel built-in rules for lex
1207 all:: $(LexFiles:%.l=$(PROJ_SRC_DIR)/%.cpp.cvs)
1209 # Note the extra sed filtering here, used to cut down on the warnings emited
1210 # by GCC. The last line is a gross hack to work around flex aparently not
1211 # being able to resize the buffer on a large token input. Currently, for
1212 # uninitialized string buffers in LLVM we can generate very long tokens, so
1213 # this is a hack around it.
1214 # FIXME. (f.e. char Buffer[10000] )
1215 $(PROJ_SRC_DIR)/%.cpp: $(PROJ_SRC_DIR)/%.l
1216 $(Echo) Flexing $*.l
1217 $(Verb) $(FLEX) -t $(PROJ_SRC_DIR)/$*.l | \
1218 $(SED) 's/void yyunput/inline void yyunput/' | \
1219 $(SED) 's/void \*yy_flex_realloc/inline void *yy_flex_realloc/' | \
1220 $(SED) 's/#define YY_BUF_SIZE 16384/#define YY_BUF_SIZE (16384*64)/' \
1221 > $(PROJ_SRC_DIR)/$*.cpp
1223 # IFF the .l file has changed since it was last checked into CVS, copy the .l
1224 # file to .l.cvs and the generated .cpp file to .cpp.cvs. We use this mechanism
1225 # so that people without flex can build LLVM by copying the .cvs files to the
1226 # source location and building them.
1227 $(LexFiles:%.l=$(PROJ_SRC_DIR)/%.cpp.cvs): \
1228 $(PROJ_SRC_DIR)/%.cpp.cvs: $(PROJ_SRC_DIR)/%.cpp
1229 $(Verb) $(CMP) -s $@ $< || \
1230 ($(CP) $< $@; $(CP) $(PROJ_SRC_DIR)/$*.l $(PROJ_SRC_DIR)/$*.l.cvs)
1232 $(LexFiles:%.l=$(ObjDir)/%.o) : \
1233 $(ObjDir)/%.o : $(PROJ_SRC_DIR)/%.cpp
1236 -$(Verb) $(RM) -f $(LexOutput)
1240 #---------------------------------------------------------
1241 # Provide rules for generating a .cpp and .h source files
1242 # from yacc (bison) input sources.
1243 #---------------------------------------------------------
1245 YaccFiles := $(filter %.y,$(Sources))
1246 ifneq ($(YaccFiles),)
1248 .PRECIOUS: $(YaccOutput)
1250 # Cancel built-in rules for yacc
1255 # Rule for building the bison based parsers...
1256 $(PROJ_SRC_DIR)/%.cpp $(PROJ_SRC_DIR)/%.h : $(PROJ_SRC_DIR)/%.y
1257 $(Echo) "Bisoning $*.y"
1258 $(Verb) $(BISON) -v -d -p $(<F:%Parser.y=%) -o $*.tab.c $<
1259 $(Verb) $(MV) -f $*.tab.c $(PROJ_SRC_DIR)/$*.cpp
1260 $(Verb) $(MV) -f $*.tab.h $(PROJ_SRC_DIR)/$*.h
1261 $(Echo) "*** DON'T FORGET TO CHECK IN $*.cpp and $*.h (generated files)"
1263 YaccObjs := $(patsubst %.y,$(ObjDir)/%.o,$(YaccFiles))
1264 $(YaccObjs): $(ObjDir)/%.o : $(PROJ_SRC_DIR)/%.cpp
1266 YaccOutput := $(addprefix $(patsubst %.y,%,$(YaccFiles)),.output)
1269 -$(Verb) $(RM) -f $(YaccOutput)
1272 ###############################################################################
1273 # OTHER RULES: Other rules needed
1274 ###############################################################################
1276 # To create postscript files from dot files...
1277 ifneq ($(DOT),false)
1279 $(DOT) -Tps < $< > $@
1282 $(Echo) "Cannot build $@: The program dot is not installed"
1285 # This rules ensures that header files that are removed still have a rule for
1286 # which they can be "generated." This allows make to ignore them and
1287 # reproduce the dependency lists.
1291 # Define clean-local to clean the current directory. Note that this uses a
1292 # very conservative approach ensuring that empty variables do not cause
1293 # errors or disastrous removal.
1295 ifneq ($(strip $(ObjDir)),)
1296 -$(Verb) $(RM) -rf $(ObjDir)
1298 -$(Verb) $(RM) -f core core.[0-9][0-9]* *.o *.d *~ *.flc
1299 ifneq ($(strip $(SHLIBEXT)),) # Extra paranoia - make real sure SHLIBEXT is set
1300 -$(Verb) $(RM) -f *$(SHLIBEXT)
1304 -$(Verb) $(RM) -rf Debug Release Profile
1306 # Build tags database for Emacs/Xemacs:
1310 find $(PROJ_SRC_ROOT)/include $(PROJ_SRC_ROOT)/lib \
1311 $(PROJ_SRC_ROOT)/tools $(PROJ_SRC_ROOT)/examples \
1312 $(PROJ_OBJ_ROOT)/include $(PROJ_OBJ_ROOT)/lib \
1313 $(PROJ_OBJ_ROOT)/tools $(PROJ_OBJ_ROOT)/examples \
1314 -name '*.cpp' -o -name '*.h' | \
1315 $(ETAGS) $(ETAGSFLAGS) -
1318 find $(PROJ_SRC_ROOT)/include $(PROJ_SRC_ROOT)/lib \
1319 $(PROJ_SRC_ROOT)/tools $(PROJ_SRC_ROOT)/examples \
1320 $(PROJ_OBJ_ROOT)/include $(PROJ_OBJ_ROOT)/lib \
1321 $(PROJ_OBJ_ROOT)/tools $(PROJ_OBJ_ROOT)/examples \
1322 \( -name '*.cpp' -o -name '*.h' \) -print | \
1323 ctags -ImtT -o $(PROJ_OBJ_ROOT)/CTAGS -L -
1326 ###############################################################################
1327 # DEPENDENCIES: Include the dependency files if we should
1328 ###############################################################################
1329 ifndef DISABLE_AUTO_DEPENDENCIES
1331 # If its not one of the cleaning targets
1332 ifneq ($strip($(filter-out clean clean-local dist-clean,$(MAKECMDGOALS))),)
1334 # Get the list of dependency files
1335 DependFiles := $(basename $(filter %.cpp %.c %.cc, $(Sources)))
1336 DependFiles := $(DependFiles:%=$(PROJ_OBJ_DIR)/$(BuildMode)/%.d)
1338 -include /dev/null $(DependFiles)
1344 ###############################################################################
1345 # CHECK: Running the test suite
1346 ###############################################################################
1349 $(Verb) if test -d "$(PROJ_OBJ_ROOT)/test" ; then \
1350 if test -f "$(PROJ_OBJ_ROOT)/test/Makefile" ; then \
1351 $(EchoCmd) Running test suite ; \
1352 $(MAKE) -C $(PROJ_OBJ_ROOT)/test check-local \
1353 TESTSUITE=$(TESTSUITE) ; \
1355 $(EchoCmd) No Makefile in test directory ; \
1358 $(EchoCmd) No test directory ; \
1361 ###############################################################################
1362 # DISTRIBUTION: Handle construction of a distribution tarball
1363 ###############################################################################
1365 #------------------------------------------------------------------------
1366 # Define distribution related variables
1367 #------------------------------------------------------------------------
1368 DistName := $(PROJECT_NAME)-$(PROJ_VERSION)
1369 DistDir := $(PROJ_OBJ_ROOT)/$(DistName)
1370 TopDistDir := $(PROJ_OBJ_ROOT)/$(DistName)
1371 DistTarGZip := $(PROJ_OBJ_ROOT)/$(DistName).tar.gz
1372 DistZip := $(PROJ_OBJ_ROOT)/$(DistName).zip
1373 DistTarBZ2 := $(PROJ_OBJ_ROOT)/$(DistName).tar.bz2
1374 DistAlways := CREDITS.TXT LICENSE.TXT README.txt README AUTHORS COPYING \
1375 ChangeLog INSTALL NEWS Makefile Makefile.common Makefile.rules \
1376 Makefile.config.in configure autoconf
1377 DistOther := $(notdir $(wildcard \
1378 $(PROJ_SRC_DIR)/*.h \
1379 $(PROJ_SRC_DIR)/*.td \
1380 $(PROJ_SRC_DIR)/*.def \
1381 $(PROJ_SRC_DIR)/*.ll \
1382 $(PROJ_SRC_DIR)/*.in))
1383 DistSubDirs := $(SubDirs)
1384 DistSources = $(Sources) $(EXTRA_DIST)
1385 DistFiles = $(DistAlways) $(DistSources) $(DistOther)
1387 #------------------------------------------------------------------------
1388 # We MUST build distribution with OBJ_DIR != SRC_DIR
1389 #------------------------------------------------------------------------
1390 ifeq ($(PROJ_SRC_DIR),$(PROJ_OBJ_DIR))
1391 dist dist-check dist-clean dist-gzip dist-bzip2 dist-zip ::
1392 $(Echo) ERROR: Target $@ only available with OBJ_DIR != SRC_DIR
1396 #------------------------------------------------------------------------
1397 # Prevent attempt to run dist targets from anywhere but the top level
1398 #------------------------------------------------------------------------
1400 dist dist-check dist-clean dist-gzip dist-bzip2 dist-zip ::
1401 $(Echo) ERROR: You must run $@ from $(PROJ_OBJ_ROOT)
1404 #------------------------------------------------------------------------
1405 # Provide the top level targets
1406 #------------------------------------------------------------------------
1408 dist-gzip:: $(DistTarGZip)
1410 $(DistTarGZip) : $(TopDistDir)/.makedistdir
1411 $(Echo) Packing gzipped distribution tar file.
1412 $(Verb) cd $(PROJ_OBJ_ROOT) ; $(TAR) chf - "$(DistName)" | \
1413 $(GZIP) -c > "$(DistTarGZip)"
1415 dist-bzip2:: $(DistTarBZ2)
1417 $(DistTarBZ2) : $(TopDistDir)/.makedistdir
1418 $(Echo) Packing bzipped distribution tar file.
1419 $(Verb) cd $(PROJ_OBJ_ROOT) ; $(TAR) chf - $(DistName) | \
1420 $(BZIP2) -c >$(DistTarBZ2)
1422 dist-zip:: $(DistZip)
1424 $(DistZip) : $(TopDistDir)/.makedistdir
1425 $(Echo) Packing zipped distribution file.
1426 $(Verb) rm -f $(DistZip)
1427 $(Verb) cd $(PROJ_OBJ_ROOT) ; $(ZIP) -rq $(DistZip) $(DistName)
1429 dist :: $(DistTarGZip) $(DistTarBZ2) $(DistZip)
1430 $(Echo) ===== DISTRIBUTION PACKAGING SUCESSFUL =====
1432 DistCheckDir := $(PROJ_OBJ_ROOT)/_distcheckdir
1434 dist-check:: $(DistTarGZip)
1435 $(Echo) Checking distribution tar file.
1436 $(Verb) if test -d $(DistCheckDir) ; then \
1437 $(RM) -rf $(DistCheckDir) ; \
1439 $(Verb) $(MKDIR) $(DistCheckDir)
1440 $(Verb) cd $(DistCheckDir) && \
1441 $(MKDIR) $(DistCheckDir)/build && \
1442 $(MKDIR) $(DistCheckDir)/install && \
1443 gunzip -c $(DistTarGZip) | $(TAR) xf - && \
1445 ../$(DistName)/configure --prefix="$(DistCheckDir)/install" \
1446 --srcdir=../$(DistName) $(DIST_CHECK_CONFIG_OPTIONS) && \
1449 $(MAKE) install && \
1450 $(MAKE) uninstall && \
1453 $(MAKE) dist-clean && \
1454 $(EchoCmd) ===== $(DistTarGZip) Ready For Distribution =====
1457 $(Echo) Cleaning distribution files
1458 -$(Verb) $(RM) -rf $(DistTarGZip) $(DistTarBZ2) $(DistZip) $(DistName) \
1463 #------------------------------------------------------------------------
1464 # Provide the recursive distdir target for building the distribution directory
1465 #------------------------------------------------------------------------
1466 distdir: $(DistDir)/.makedistdir
1467 $(DistDir)/.makedistdir: $(DistSources)
1468 $(Verb) if test "$(DistDir)" = "$(TopDistDir)" ; then \
1469 if test -d "$(DistDir)" ; then \
1470 find $(DistDir) -type d ! -perm -200 -exec chmod u+w {} ';' || \
1473 $(EchoCmd) Removing old $(DistDir) ; \
1474 $(RM) -rf $(DistDir); \
1475 $(EchoCmd) Making 'all' to verify build ; \
1478 $(Echo) Building Distribution Directory $(DistDir)
1479 $(Verb) $(MKDIR) $(DistDir)
1480 $(Verb) srcdirstrip=`echo "$(PROJ_SRC_DIR)" | sed 's|.|.|g'`; \
1481 srcrootstrip=`echo "$(PROJ_SRC_ROOT)" | sed 's|.|.|g'`; \
1482 for file in $(DistFiles) ; do \
1484 $(PROJ_SRC_DIR)/*) \
1485 file=`echo "$$file" | sed "s#^$$srcdirstrip/##"` \
1487 $(PROJ_SRC_ROOT)/*) \
1488 file=`echo "$$file" | \
1489 sed "s#^$$srcrootstrip/##"` \
1492 if test -f "$(PROJ_SRC_DIR)/$$file" || \
1493 test -d "$(PROJ_SRC_DIR)/$$file" ; then \
1494 from_dir="$(PROJ_SRC_DIR)" ; \
1495 elif test -f "$$file" || test -d "$$file" ; then \
1498 to_dir=`echo "$$file" | sed -e 's#/[^/]*$$##'` ; \
1499 if test "$$to_dir" != "$$file" && test "$$to_dir" != "."; then \
1500 to_dir="$(DistDir)/$$dir"; \
1501 $(MKDIR) "$$to_dir" ; \
1503 to_dir="$(DistDir)"; \
1505 mid_dir=`echo "$$file" | sed -n -e 's#^\(.*\)/[^/]*$$#\1#p'`; \
1506 if test -n "$$mid_dir" ; then \
1507 $(MKDIR) "$$to_dir/$$mid_dir" || exit 1; \
1509 if test -d "$$from_dir/$$file"; then \
1510 if test -d "$(PROJ_SRC_DIR)/$$file" && \
1511 test "$$from_dir" != "$(PROJ_SRC_DIR)" ; then \
1512 cd $(PROJ_SRC_DIR) ; \
1513 $(TAR) cf - $$file --exclude .svn --exclude CVS | \
1514 ( cd $$to_dir ; $(TAR) xf - ) ; \
1515 cd $(PROJ_OBJ_DIR) ; \
1518 $(TAR) cf - $$file --exclude .svn --exclude CVS | \
1519 ( cd $$to_dir ; $(TAR) xf - ) ; \
1520 cd $(PROJ_OBJ_DIR) ; \
1522 elif test -f "$$from_dir/$$file" ; then \
1523 $(CP) -p "$$from_dir/$$file" "$(DistDir)/$$file" || exit 1; \
1524 elif test -L "$$from_dir/$$file" ; then \
1525 $(CP) -pd "$$from_dir/$$file" $(DistDir)/$$file || exit 1; \
1526 elif echo "$(DistAlways)" | grep -v "$$file" >/dev/null ; then \
1527 $(EchoCmd) "===== WARNING: Distribution Source " \
1528 "$$from_dir/$$file Not Found!" ; \
1529 elif test "$(Verb)" != '@' ; then \
1530 $(EchoCmd) "Skipping non-existent $$from_dir/$$file" ; \
1533 $(Verb) for subdir in $(DistSubDirs) ; do \
1534 if test "$$subdir" \!= "." ; then \
1535 new_distdir="$(DistDir)/$$subdir" ; \
1536 test -d "$$new_distdir" || $(MKDIR) "$$new_distdir" || exit 1; \
1537 ( cd $$subdir && $(MAKE) DistDir="$$new_distdir" distdir ) || \
1541 $(Verb) if test "$(DistDir)" = "$(TopDistDir)" ; then \
1542 $(EchoCmd) Eliminating CVS/.svn directories from distribution ; \
1543 $(RM) -rf `find $(TopDistDir) -type d \( -name CVS -o \
1544 -name .svn \) -print` ;\
1545 $(MAKE) dist-hook ; \
1546 $(FIND) $(TopDistDir) -type d ! -perm -777 -exec chmod a+rwx {} \; \
1547 -o ! -type d ! -perm -444 -links 1 -exec chmod a+r {} \; \
1548 -o ! -type d ! -perm -400 -exec chmod a+r {} \; \
1549 -o ! -type d ! -perm -444 -exec \
1550 $(SHELL) $(INSTALL_SH) -c -m a+r {} {} \; \
1551 || chmod -R a+r $(DistDir) ; \
1554 # This is invoked by distdir target, define it as a no-op to avoid errors if not
1560 ###############################################################################
1561 # TOP LEVEL - targets only to apply at the top level directory
1562 ###############################################################################
1566 #------------------------------------------------------------------------
1567 # Install support for the project's include files:
1568 #------------------------------------------------------------------------
1570 $(Echo) Installing include files
1571 $(Verb) $(MKDIR) $(PROJ_includedir)
1572 $(Verb) if test -d "$(PROJ_SRC_ROOT)/include" ; then \
1573 cd $(PROJ_SRC_ROOT)/include && \
1574 for hdr in `find . -type f '!' '(' -name '*~' -o -name '.cvsignore' \
1575 -o -name '.#*' -o -name '*.in' ')' -print | grep -v CVS ` ; do \
1576 instdir=`dirname "$(PROJ_includedir)/$$hdr"` ; \
1577 if test \! -d "$$instdir" ; then \
1578 $(EchoCmd) Making install directory $$instdir ; \
1579 $(MKDIR) $$instdir ;\
1581 $(DataInstall) $$hdr $(PROJ_includedir)/$$hdr ; \
1584 ifneq ($(PROJ_SRC_ROOT),$(PROJ_OBJ_ROOT))
1585 $(Verb) if test -d "$(PROJ_OBJ_ROOT)/include" ; then \
1586 cd $(PROJ_OBJ_ROOT)/include && \
1587 for hdr in `find . -type f -print | grep -v CVS` ; do \
1588 $(DataInstall) $$hdr $(PROJ_includedir)/$$hdr ; \
1594 $(Echo) Uninstalling include files
1595 $(Verb) if [ -d "$(PROJ_SRC_ROOT)/include" ] ; then \
1596 cd $(PROJ_SRC_ROOT)/include && \
1597 $(RM) -f `find . -path '*/Internal' -prune -o '(' -type f \
1598 '!' '(' -name '*~' -o -name '.cvsignore' -o -name '.#*' \
1599 -o -name '*.in' ')' -print ')' | \
1600 grep -v CVS | sed 's#^#$(PROJ_includedir)/#'` ; \
1601 cd $(PROJ_SRC_ROOT)/include && \
1602 $(RM) -f `find . -path '*/Internal' -prune -o '(' -type f -name '*.in' \
1603 -print ')' | sed 's#\.in$$##;s#^#$(PROJ_includedir)/#'` ; \
1608 #------------------------------------------------------------------------
1609 # Print out the directories used for building
1610 #------------------------------------------------------------------------
1612 $(Echo) "BuildMode : " '$(BuildMode)'
1613 $(Echo) "PROJ_SRC_ROOT: " '$(PROJ_SRC_ROOT)'
1614 $(Echo) "PROJ_SRC_DIR : " '$(PROJ_SRC_DIR)'
1615 $(Echo) "PROJ_OBJ_ROOT: " '$(PROJ_OBJ_ROOT)'
1616 $(Echo) "PROJ_OBJ_DIR : " '$(PROJ_OBJ_DIR)'
1617 $(Echo) "LLVM_SRC_ROOT: " '$(LLVM_SRC_ROOT)'
1618 $(Echo) "LLVM_OBJ_ROOT: " '$(LLVM_OBJ_ROOT)'
1619 $(Echo) "PROJ_prefix : " '$(PROJ_prefix)'
1620 $(Echo) "PROJ_bindir : " '$(PROJ_bindir)'
1621 $(Echo) "PROJ_libdir : " '$(PROJ_libdir)'
1622 $(Echo) "PROJ_etcdir : " '$(PROJ_etcdir)'
1623 $(Echo) "PROJ_includedir : " '$(PROJ_includedir)'
1624 $(Echo) "UserTargets : " '$(UserTargets)'
1625 $(Echo) "ObjMakefiles : " '$(ObjMakefiles)'
1626 $(Echo) "SrcMakefiles : " '$(SrcMakefiles)'
1627 $(Echo) "ObjDir : " '$(ObjDir)'
1628 $(Echo) "LibDir : " '$(LibDir)'
1629 $(Echo) "ToolDir : " '$(ToolDir)'
1630 $(Echo) "ExmplDir : " '$(ExmplDir)'
1631 $(Echo) "Sources : " '$(Sources)'
1632 $(Echo) "TDFiles : " '$(TDFiles)'
1633 $(Echo) "INCFiles : " '$(INCFiles)'
1634 $(Echo) "INCTMPFiles : " '$(INCTMPFiles)'
1635 $(Echo) "PreConditions: " '$(PreConditions)'
1636 $(Echo) "Compile.CXX : " '$(Compile.CXX)'
1637 $(Echo) "Compile.C : " '$(Compile.C)'
1638 $(Echo) "Archive : " '$(Archive)'
1639 $(Echo) "YaccFiles : " '$(YaccFiles)'
1640 $(Echo) "LexFiles : " '$(LexFiles)'
1641 $(Echo) "Module : " '$(Module)'
1642 $(Echo) "FilesToConfig: " '$(FilesToConfigPATH)'