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) $(StripWarnMsg)
935 DestTool = $(PROJ_bindir)/$(TOOLNAME)
937 install-local:: $(DestTool)
939 $(DestTool): $(PROJ_bindir) $(ToolBuildPath)
940 $(Echo) Installing $(BuildMode) $(DestTool)
941 $(Verb) $(ProgInstall) $(ToolBuildPath) $(DestTool)
944 $(Echo) Uninstalling $(BuildMode) $(DestTool)
945 -$(Verb) $(RM) -f $(DestTool)
949 ###############################################################################
950 # Object Build Rules: Build object files based on sources
951 ###############################################################################
953 # Provide rule sets for when dependency generation is enabled
954 ifndef DISABLE_AUTO_DEPENDENCIES
956 #---------------------------------------------------------
957 # Create .lo files in the ObjDir directory from the .cpp and .c files...
958 #---------------------------------------------------------
961 $(ObjDir)/%.lo $(ObjDir)/%.o: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES)
962 $(Echo) "Compiling $*.cpp for $(BuildMode) build (PIC)"
963 $(Verb) if $(LTCompile.CXX) -MD -MT $@ -MP -MF $(ObjDir)/$*.LACXXd $< -o $@ ; \
964 then $(MV) -f "$(ObjDir)/$*.LACXXd" "$(ObjDir)/$*.d"; \
965 else $(RM) -f "$(ObjDir)/$*.LACXXd"; exit 1; fi
967 $(ObjDir)/%.lo $(ObjDir)/%.o: %.cc $(ObjDir)/.dir $(BUILT_SOURCES)
968 $(Echo) "Compiling $*.cc for $(BuildMode) build (PIC)"
969 $(Verb) if $(LTCompile.CXX) -MD -MT $@ -MP -MF $(ObjDir)/$*.LACXXd $< -o $@ ; \
970 then $(MV) -f "$(ObjDir)/$*.LACXXd" "$(ObjDir)/$*.d"; \
971 else $(RM) -f "$(ObjDir)/$*.LACXXd"; exit 1; fi
973 $(ObjDir)/%.lo $(ObjDir)/%.o: %.c $(ObjDir)/.dir $(BUILT_SOURCES)
974 $(Echo) "Compiling $*.c for $(BuildMode) build (PIC)"
975 $(Verb) if $(LTCompile.C) -MD -MT $@ -MP -MF $(ObjDir)/$*.LACd $< -o $@ ; \
976 then $(MV) -f "$(ObjDir)/$*.LACd" "$(ObjDir)/$*.d"; \
977 else $(RM) -f "$(ObjDir)/$*.LACd"; exit 1; fi
979 #---------------------------------------------------------
980 # Create .o files in the ObjDir directory from the .cpp and .c files...
981 #---------------------------------------------------------
984 $(ObjDir)/%.o: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES)
985 $(Echo) "Compiling $*.cpp for $(BuildMode) build"
986 $(Verb) if $(Compile.CXX) -MD -MT $@ -MP -MF $(ObjDir)/$*.CXXd $< -o $@ ; \
987 then $(MV) -f "$(ObjDir)/$*.CXXd" "$(ObjDir)/$*.d"; \
988 else $(RM) -f "$(ObjDir)/$*.CXXd"; exit 1; fi
990 $(ObjDir)/%.o: %.cc $(ObjDir)/.dir $(BUILT_SOURCES)
991 $(Echo) "Compiling $*.cc for $(BuildMode) build"
992 $(Verb) if $(Compile.CXX) -MD -MT $@ -MP -MF $(ObjDir)/$*.CXXd $< -o $@ ; \
993 then $(MV) -f "$(ObjDir)/$*.CXXd" "$(ObjDir)/$*.d"; \
994 else $(RM) -f "$(ObjDir)/$*.CXXd"; exit 1; fi
996 $(ObjDir)/%.o: %.c $(ObjDir)/.dir $(BUILT_SOURCES)
997 $(Echo) "Compiling $*.c for $(BuildMode) build"
998 $(Verb) if $(Compile.C) -MD -MT $@ -MP -MF $(ObjDir)/$*.Cd $< -o $@ ; \
999 then $(MV) -f "$(ObjDir)/$*.Cd" "$(ObjDir)/$*.d"; \
1000 else $(RM) -f "$(ObjDir)/$*.Cd"; exit 1; fi
1004 ## Rules for building preprocessed (.i/.ii) outputs.
1005 $(BuildMode)/%.ii: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES)
1006 $(Echo) "Compiling $*.cpp for $(BuildMode) build to .ii file"
1007 $(Verb) $(Preprocess.CXX) $< -o $@
1009 $(BuildMode)/%.ii: %.cc $(ObjDir)/.dir $(BUILT_SOURCES)
1010 $(Echo) "Compiling $*.cc for $(BuildMode) build to .ii file"
1011 $(Verb) $(Preprocess.CXX) $< -o $@
1013 $(BuildMode)/%.i: %.c $(ObjDir)/.dir $(BUILT_SOURCES)
1014 $(Echo) "Compiling $*.c for $(BuildMode) build to .i file"
1015 $(Verb) $(Preprocess.C) $< -o $@
1018 #---------------------------------------------------------
1019 # Create .bc files in the ObjDir directory from .cpp .cc and .c files...
1020 #---------------------------------------------------------
1022 $(ObjDir)/%.ll: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES)
1023 $(Echo) "Compiling $*.cpp for $(BuildMode) build (bytecode)"
1024 $(Verb) if $(BCCompile.CXX) -MD -MT $@ -MP -MF "$(ObjDir)/$*.BCCXXd" $< -o $@ -S -emit-llvm ; \
1025 then $(MV) -f "$(ObjDir)/$*.BCCXXd" "$(ObjDir)/$*.d"; \
1026 else $(RM) -f "$(ObjDir)/$*.BCCXXd"; exit 1; fi
1028 $(ObjDir)/%.ll: %.cc $(ObjDir)/.dir $(BUILT_SOURCES)
1029 $(Echo) "Compiling $*.cc for $(BuildMode) build (bytecode)"
1030 $(Verb) if $(BCCompile.CXX) -MD -MT $@ -MP -MF "$(ObjDir)/$*.BCCXXd" $< -o $@ -S -emit-llvm ; \
1031 then $(MV) -f "$(ObjDir)/$*.BCCXXd" "$(ObjDir)/$*.d"; \
1032 else $(RM) -f "$(ObjDir)/$*.BCCXXd"; exit 1; fi
1034 $(ObjDir)/%.ll: %.c $(ObjDir)/.dir $(BUILT_SOURCES)
1035 $(Echo) "Compiling $*.c for $(BuildMode) build (bytecode)"
1036 $(Verb) if $(BCCompile.C) -MD -MT $@ -MP -MF "$(ObjDir)/$*.BCCd" $< -o $@ -S -emit-llvm ; \
1037 then $(MV) -f "$(ObjDir)/$*.BCCd" "$(ObjDir)/$*.d"; \
1038 else $(RM) -f "$(ObjDir)/$*.BCCd"; exit 1; fi
1040 # Provide alternate rule sets if dependencies are disabled
1043 ifdef SHARED_LIBRARY
1045 $(ObjDir)/%.lo $(ObjDir)/%.o: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES)
1046 $(Echo) "Compiling $*.cpp for $(BuildMode) build (PIC)"
1047 $(LTCompile.CXX) $< -o $@
1049 $(ObjDir)/%.lo $(ObjDir)/%.o: %.cc $(ObjDir)/.dir $(BUILT_SOURCES)
1050 $(Echo) "Compiling $*.cc for $(BuildMode) build (PIC)"
1051 $(LTCompile.CXX) $< -o $@
1053 $(ObjDir)/%.lo $(ObjDir)/%.o: %.c $(ObjDir)/.dir $(BUILT_SOURCES)
1054 $(Echo) "Compiling $*.c for $(BuildMode) build (PIC)"
1055 $(LTCompile.C) $< -o $@
1059 $(ObjDir)/%.o: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES)
1060 $(Echo) "Compiling $*.cpp for $(BuildMode) build"
1061 $(Compile.CXX) $< -o $@
1063 $(ObjDir)/%.o: %.cc $(ObjDir)/.dir $(BUILT_SOURCES)
1064 $(Echo) "Compiling $*.cc for $(BuildMode) build"
1065 $(Compile.CXX) $< -o $@
1067 $(ObjDir)/%.o: %.c $(ObjDir)/.dir $(BUILT_SOURCES)
1068 $(Echo) "Compiling $*.c for $(BuildMode) build"
1069 $(Compile.C) $< -o $@
1072 $(ObjDir)/%.ll: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES)
1073 $(Echo) "Compiling $*.cpp for $(BuildMode) build (bytecode)"
1074 $(BCCompile.CXX) $< -o $@ -S -emit-llvm
1076 $(ObjDir)/%.ll: %.cc $(ObjDir)/.dir $(BUILT_SOURCES)
1077 $(Echo) "Compiling $*.cc for $(BuildMode) build (bytecode)"
1078 $(BCCompile.CXX) $< -o $@ -S -emit-llvm
1080 $(ObjDir)/%.ll: %.c $(ObjDir)/.dir $(BUILT_SOURCES)
1081 $(Echo) "Compiling $*.c for $(BuildMode) build (bytecode)"
1082 $(BCCompile.C) $< -o $@ -S -emit-llvm
1086 # make the C and C++ compilers strip debug info out of bytecode libraries.
1088 $(ObjectsBC): $(ObjDir)/%.bc: $(ObjDir)/%.ll $(GCCAS)
1089 $(Echo) "Compiling $*.ll to $*.bc for $(BuildMode) build (bytecode)"
1092 $(ObjectsBC): $(ObjDir)/%.bc: $(ObjDir)/%.ll $(GCCAS)
1093 $(Echo) "Compiling $*.ll to $*.bc for $(BuildMode) build (bytecode)"
1094 @$(GCCAS) -strip-debug $< -o $@
1098 #---------------------------------------------------------
1099 # Provide rule to build .bc files from .ll sources,
1100 # regardless of dependencies
1101 #---------------------------------------------------------
1102 $(ObjDir)/%.bc: %.ll $(ObjDir)/.dir $(LLVMAS)
1103 $(Echo) "Compiling $*.ll for $(BuildMode) build"
1104 $(Verb) $(LLVMAS) $< -f -o $@
1106 ###############################################################################
1107 # TABLEGEN: Provide rules for running tblgen to produce *.inc files
1108 ###############################################################################
1112 TDFiles := $(strip $(wildcard $(PROJ_SRC_DIR)/*.td) $(LLVM_SRC_ROOT)/lib/Target/Target.td $(LLVM_SRC_ROOT)/lib/Target/TargetSelectionDAG.td)
1113 INCFiles := $(filter %.inc,$(BUILT_SOURCES))
1114 INCTMPFiles := $(INCFiles:%=$(ObjDir)/%.tmp)
1115 .PRECIOUS: $(INCTMPFiles) $(INCFiles)
1117 # All of these files depend on tblgen and the .td files.
1118 $(INCTMPFiles) : $(TBLGEN) $(TDFiles)
1120 # INCFiles rule: All of the tblgen generated files are emitted to
1121 # $(ObjDir)/%.inc.tmp, instead of emitting them directly to %.inc. This allows
1122 # us to only "touch" the real file if the contents of it change. IOW, if
1123 # tblgen is modified, all of the .inc.tmp files are regereated, but no
1124 # dependencies of the .inc files are, unless the contents of the .inc file
1126 $(INCFiles) : %.inc : $(ObjDir)/%.inc.tmp
1127 $(Verb) $(CMP) -s $@ $< || $(CP) $< $@
1129 $(TARGET:%=$(ObjDir)/%GenRegisterNames.inc.tmp): \
1130 $(ObjDir)/%GenRegisterNames.inc.tmp : %.td $(ObjDir)/.dir
1131 $(Echo) "Building $(<F) register names with tblgen"
1132 $(Verb) $(TableGen) -gen-register-enums -o $@ $<
1134 $(TARGET:%=$(ObjDir)/%GenRegisterInfo.h.inc.tmp): \
1135 $(ObjDir)/%GenRegisterInfo.h.inc.tmp : %.td $(ObjDir)/.dir
1136 $(Echo) "Building $(<F) register information header with tblgen"
1137 $(Verb) $(TableGen) -gen-register-desc-header -o $@ $<
1139 $(TARGET:%=$(ObjDir)/%GenRegisterInfo.inc.tmp): \
1140 $(ObjDir)/%GenRegisterInfo.inc.tmp : %.td $(ObjDir)/.dir
1141 $(Echo) "Building $(<F) register info implementation with tblgen"
1142 $(Verb) $(TableGen) -gen-register-desc -o $@ $<
1144 $(TARGET:%=$(ObjDir)/%GenInstrNames.inc.tmp): \
1145 $(ObjDir)/%GenInstrNames.inc.tmp : %.td $(ObjDir)/.dir
1146 $(Echo) "Building $(<F) instruction names with tblgen"
1147 $(Verb) $(TableGen) -gen-instr-enums -o $@ $<
1149 $(TARGET:%=$(ObjDir)/%GenInstrInfo.inc.tmp): \
1150 $(ObjDir)/%GenInstrInfo.inc.tmp : %.td $(ObjDir)/.dir
1151 $(Echo) "Building $(<F) instruction information with tblgen"
1152 $(Verb) $(TableGen) -gen-instr-desc -o $@ $<
1154 $(TARGET:%=$(ObjDir)/%GenAsmWriter.inc.tmp): \
1155 $(ObjDir)/%GenAsmWriter.inc.tmp : %.td $(ObjDir)/.dir
1156 $(Echo) "Building $(<F) assembly writer with tblgen"
1157 $(Verb) $(TableGen) -gen-asm-writer -o $@ $<
1159 $(TARGET:%=$(ObjDir)/%GenAsmWriter1.inc.tmp): \
1160 $(ObjDir)/%GenAsmWriter1.inc.tmp : %.td $(ObjDir)/.dir
1161 $(Echo) "Building $(<F) assembly writer #1 with tblgen"
1162 $(Verb) $(TableGen) -gen-asm-writer -asmwriternum=1 -o $@ $<
1164 $(TARGET:%=$(ObjDir)/%GenCodeEmitter.inc.tmp): \
1165 $(ObjDir)/%GenCodeEmitter.inc.tmp: %.td $(ObjDir)/.dir
1166 $(Echo) "Building $(<F) code emitter with tblgen"
1167 $(Verb) $(TableGen) -gen-emitter -o $@ $<
1169 $(TARGET:%=$(ObjDir)/%GenDAGISel.inc.tmp): \
1170 $(ObjDir)/%GenDAGISel.inc.tmp : %.td $(ObjDir)/.dir
1171 $(Echo) "Building $(<F) instruction selector implementation with tblgen"
1172 $(Verb) $(TableGen) -gen-dag-isel -o $@ $<
1174 $(TARGET:%=$(ObjDir)/%GenSubtarget.inc.tmp): \
1175 $(ObjDir)/%GenSubtarget.inc.tmp : %.td $(ObjDir)/.dir
1176 $(Echo) "Building $(<F) subtarget information with tblgen"
1177 $(Verb) $(TableGen) -gen-subtarget -o $@ $<
1180 -$(Verb) $(RM) -f $(INCFiles)
1184 ###############################################################################
1185 # LEX AND YACC: Provide rules for generating sources with lex and yacc
1186 ###############################################################################
1188 #---------------------------------------------------------
1189 # Provide rules for generating a .cpp source file from
1190 # (f)lex input sources.
1191 #---------------------------------------------------------
1193 LexFiles := $(filter %.l,$(Sources))
1195 ifneq ($(LexFiles),)
1197 # Cancel built-in rules for lex
1201 # Note the extra sed filtering here, used to cut down on the warnings emited
1202 # by GCC. The last line is a gross hack to work around flex aparently not
1203 # being able to resize the buffer on a large token input. Currently, for
1204 # uninitialized string buffers in LLVM we can generate very long tokens, so
1205 # this is a hack around it.
1206 # FIXME. (f.e. char Buffer[10000] )
1207 $(PROJ_SRC_DIR)/%.cpp: $(PROJ_SRC_DIR)/%.l
1208 $(Echo) Flexing $*.l
1209 $(Verb) $(FLEX) -t $(PROJ_SRC_DIR)/$*.l | \
1210 $(SED) 's/void yyunput/inline void yyunput/' | \
1211 $(SED) 's/void \*yy_flex_realloc/inline void *yy_flex_realloc/' | \
1212 $(SED) 's/#define YY_BUF_SIZE 16384/#define YY_BUF_SIZE (16384*64)/' \
1213 > $(PROJ_SRC_DIR)/$*.cpp
1214 $(Echo) "*** DON'T FORGET TO CHECK IN $*.cpp (generated file)"
1216 LexObjs := $(patsubst %.l,$(ObjDir)/%.o,$(LexFiles))
1217 $(LexObjs): $(ObjDir)/%.o : $(PROJ_SRC_DIR)/%.cpp
1220 -$(Verb) $(RM) -f $(LexOutput)
1224 #---------------------------------------------------------
1225 # Provide rules for generating a .cpp and .h source files
1226 # from yacc (bison) input sources.
1227 #---------------------------------------------------------
1229 YaccFiles := $(filter %.y,$(Sources))
1230 ifneq ($(YaccFiles),)
1232 .PRECIOUS: $(YaccOutput)
1234 # Cancel built-in rules for yacc
1239 # Rule for building the bison based parsers...
1240 $(PROJ_SRC_DIR)/%.cpp $(PROJ_SRC_DIR)/%.h : $(PROJ_SRC_DIR)/%.y
1241 $(Echo) "Bisoning $*.y"
1242 $(Verb) $(BISON) -v -d -p $(<F:%Parser.y=%) -o $*.tab.c $<
1243 $(Verb) $(MV) -f $*.tab.c $(PROJ_SRC_DIR)/$*.cpp
1244 $(Verb) $(MV) -f $*.tab.h $(PROJ_SRC_DIR)/$*.h
1245 $(Echo) "*** DON'T FORGET TO CHECK IN $*.cpp and $*.h (generated files)"
1247 YaccObjs := $(patsubst %.y,$(ObjDir)/%.o,$(YaccFiles))
1248 $(YaccObjs): $(ObjDir)/%.o : $(PROJ_SRC_DIR)/%.cpp
1250 YaccOutput := $(addprefix $(patsubst %.y,%,$(YaccFiles)),.output)
1253 -$(Verb) $(RM) -f $(YaccOutput)
1256 ###############################################################################
1257 # OTHER RULES: Other rules needed
1258 ###############################################################################
1260 # To create postscript files from dot files...
1261 ifneq ($(DOT),false)
1263 $(DOT) -Tps < $< > $@
1266 $(Echo) "Cannot build $@: The program dot is not installed"
1269 # This rules ensures that header files that are removed still have a rule for
1270 # which they can be "generated." This allows make to ignore them and
1271 # reproduce the dependency lists.
1275 # Define clean-local to clean the current directory. Note that this uses a
1276 # very conservative approach ensuring that empty variables do not cause
1277 # errors or disastrous removal.
1279 ifneq ($(strip $(ObjDir)),)
1280 -$(Verb) $(RM) -rf $(ObjDir)
1282 -$(Verb) $(RM) -f core core.[0-9][0-9]* *.o *.d *~ *.flc
1283 ifneq ($(strip $(SHLIBEXT)),) # Extra paranoia - make real sure SHLIBEXT is set
1284 -$(Verb) $(RM) -f *$(SHLIBEXT)
1288 -$(Verb) $(RM) -rf Debug Release Profile
1290 # Build tags database for Emacs/Xemacs:
1294 find $(PROJ_SRC_ROOT)/include $(PROJ_SRC_ROOT)/lib \
1295 $(PROJ_SRC_ROOT)/tools $(PROJ_SRC_ROOT)/examples \
1296 $(PROJ_OBJ_ROOT)/include $(PROJ_OBJ_ROOT)/lib \
1297 $(PROJ_OBJ_ROOT)/tools $(PROJ_OBJ_ROOT)/examples \
1298 -name '*.cpp' -o -name '*.h' | \
1299 $(ETAGS) $(ETAGSFLAGS) -
1302 find $(PROJ_SRC_ROOT)/include $(PROJ_SRC_ROOT)/lib \
1303 $(PROJ_SRC_ROOT)/tools $(PROJ_SRC_ROOT)/examples \
1304 $(PROJ_OBJ_ROOT)/include $(PROJ_OBJ_ROOT)/lib \
1305 $(PROJ_OBJ_ROOT)/tools $(PROJ_OBJ_ROOT)/examples \
1306 \( -name '*.cpp' -o -name '*.h' \) -print | \
1307 ctags -ImtT -o $(PROJ_OBJ_ROOT)/CTAGS -L -
1310 ###############################################################################
1311 # DEPENDENCIES: Include the dependency files if we should
1312 ###############################################################################
1313 ifndef DISABLE_AUTO_DEPENDENCIES
1315 # If its not one of the cleaning targets
1316 ifneq ($strip($(filter-out clean clean-local dist-clean,$(MAKECMDGOALS))),)
1318 # Get the list of dependency files
1319 DependFiles := $(basename $(filter %.cpp %.c %.cc, $(Sources)))
1320 DependFiles := $(patsubst %,$(PROJ_OBJ_DIR)/$(BuildMode)/%.d,$(DependFiles))
1322 -include /dev/null $(DependFiles)
1328 ###############################################################################
1329 # CHECK: Running the test suite
1330 ###############################################################################
1333 $(Verb) if test -d "$(PROJ_OBJ_ROOT)/test" ; then \
1334 if test -f "$(PROJ_OBJ_ROOT)/test/Makefile" ; then \
1335 $(EchoCmd) Running test suite ; \
1336 $(MAKE) -C $(PROJ_OBJ_ROOT)/test check-local \
1337 TESTSUITE=$(TESTSUITE) ; \
1339 $(EchoCmd) No Makefile in test directory ; \
1342 $(EchoCmd) No test directory ; \
1345 ###############################################################################
1346 # DISTRIBUTION: Handle construction of a distribution tarball
1347 ###############################################################################
1349 #------------------------------------------------------------------------
1350 # Define distribution related variables
1351 #------------------------------------------------------------------------
1352 DistName := $(PROJECT_NAME)-$(PROJ_VERSION)
1353 DistDir := $(PROJ_OBJ_ROOT)/$(DistName)
1354 TopDistDir := $(PROJ_OBJ_ROOT)/$(DistName)
1355 DistTarGZip := $(PROJ_OBJ_ROOT)/$(DistName).tar.gz
1356 DistZip := $(PROJ_OBJ_ROOT)/$(DistName).zip
1357 DistTarBZ2 := $(PROJ_OBJ_ROOT)/$(DistName).tar.bz2
1358 DistAlways := CREDITS.TXT LICENSE.TXT README.txt README AUTHORS COPYING \
1359 ChangeLog INSTALL NEWS Makefile Makefile.common Makefile.rules \
1360 Makefile.config.in configure autoconf
1361 DistOther := $(notdir $(wildcard \
1362 $(PROJ_SRC_DIR)/*.h \
1363 $(PROJ_SRC_DIR)/*.td \
1364 $(PROJ_SRC_DIR)/*.def \
1365 $(PROJ_SRC_DIR)/*.ll \
1366 $(PROJ_SRC_DIR)/*.in))
1367 DistSubDirs := $(SubDirs)
1368 DistSources = $(Sources) $(EXTRA_DIST)
1369 DistFiles = $(DistAlways) $(DistSources) $(DistOther)
1371 #------------------------------------------------------------------------
1372 # We MUST build distribution with OBJ_DIR != SRC_DIR
1373 #------------------------------------------------------------------------
1374 ifeq ($(PROJ_SRC_DIR),$(PROJ_OBJ_DIR))
1375 dist dist-check dist-clean dist-gzip dist-bzip2 dist-zip ::
1376 $(Echo) ERROR: Target $@ only available with OBJ_DIR != SRC_DIR
1380 #------------------------------------------------------------------------
1381 # Prevent attempt to run dist targets from anywhere but the top level
1382 #------------------------------------------------------------------------
1384 dist dist-check dist-clean dist-gzip dist-bzip2 dist-zip ::
1385 $(Echo) ERROR: You must run $@ from $(PROJ_OBJ_ROOT)
1388 #------------------------------------------------------------------------
1389 # Provide the top level targets
1390 #------------------------------------------------------------------------
1392 dist-gzip:: $(DistTarGZip)
1394 $(DistTarGZip) : $(TopDistDir)/.makedistdir
1395 $(Echo) Packing gzipped distribution tar file.
1396 $(Verb) cd $(PROJ_OBJ_ROOT) ; $(TAR) chf - "$(DistName)" | \
1397 $(GZIP) -c > "$(DistTarGZip)"
1399 dist-bzip2:: $(DistTarBZ2)
1401 $(DistTarBZ2) : $(TopDistDir)/.makedistdir
1402 $(Echo) Packing bzipped distribution tar file.
1403 $(Verb) cd $(PROJ_OBJ_ROOT) ; $(TAR) chf - $(DistName) | \
1404 $(BZIP2) -c >$(DistTarBZ2)
1406 dist-zip:: $(DistZip)
1408 $(DistZip) : $(TopDistDir)/.makedistdir
1409 $(Echo) Packing zipped distribution file.
1410 $(Verb) rm -f $(DistZip)
1411 $(Verb) cd $(PROJ_OBJ_ROOT) ; $(ZIP) -rq $(DistZip) $(DistName)
1413 dist :: $(DistTarGZip) $(DistTarBZ2) $(DistZip)
1414 $(Echo) ===== DISTRIBUTION PACKAGING SUCESSFUL =====
1416 DistCheckDir := $(PROJ_OBJ_ROOT)/_distcheckdir
1418 dist-check:: $(DistTarGZip)
1419 $(Echo) Checking distribution tar file.
1420 $(Verb) if test -d $(DistCheckDir) ; then \
1421 $(RM) -rf $(DistCheckDir) ; \
1423 $(Verb) $(MKDIR) $(DistCheckDir)
1424 $(Verb) cd $(DistCheckDir) && \
1425 $(MKDIR) $(DistCheckDir)/build && \
1426 $(MKDIR) $(DistCheckDir)/install && \
1427 gunzip -c $(DistTarGZip) | $(TAR) xf - && \
1429 ../$(DistName)/configure --prefix="$(DistCheckDir)/install" \
1430 --srcdir=../$(DistName) $(DIST_CHECK_CONFIG_OPTIONS) && \
1433 $(MAKE) install && \
1434 $(MAKE) uninstall && \
1437 $(MAKE) dist-clean && \
1438 $(EchoCmd) ===== $(DistTarGZip) Ready For Distribution =====
1441 $(Echo) Cleaning distribution files
1442 -$(Verb) $(RM) -rf $(DistTarGZip) $(DistTarBZ2) $(DistZip) $(DistName) \
1447 #------------------------------------------------------------------------
1448 # Provide the recursive distdir target for building the distribution directory
1449 #------------------------------------------------------------------------
1450 distdir: $(DistDir)/.makedistdir
1451 $(DistDir)/.makedistdir: $(DistSources)
1452 $(Verb) if test "$(DistDir)" = "$(TopDistDir)" ; then \
1453 if test -d "$(DistDir)" ; then \
1454 find $(DistDir) -type d ! -perm -200 -exec chmod u+w {} ';' || \
1457 $(EchoCmd) Removing old $(DistDir) ; \
1458 $(RM) -rf $(DistDir); \
1459 $(EchoCmd) Making 'all' to verify build ; \
1462 $(Echo) Building Distribution Directory $(DistDir)
1463 $(Verb) $(MKDIR) $(DistDir)
1464 $(Verb) srcdirstrip=`echo "$(PROJ_SRC_DIR)" | sed 's|.|.|g'`; \
1465 srcrootstrip=`echo "$(PROJ_SRC_ROOT)" | sed 's|.|.|g'`; \
1466 for file in $(DistFiles) ; do \
1468 $(PROJ_SRC_DIR)/*) \
1469 file=`echo "$$file" | sed "s#^$$srcdirstrip/##"` \
1471 $(PROJ_SRC_ROOT)/*) \
1472 file=`echo "$$file" | \
1473 sed "s#^$$srcrootstrip/##"` \
1476 if test -f "$(PROJ_SRC_DIR)/$$file" || \
1477 test -d "$(PROJ_SRC_DIR)/$$file" ; then \
1478 from_dir="$(PROJ_SRC_DIR)" ; \
1479 elif test -f "$$file" || test -d "$$file" ; then \
1482 to_dir=`echo "$$file" | sed -e 's#/[^/]*$$##'` ; \
1483 if test "$$to_dir" != "$$file" && test "$$to_dir" != "."; then \
1484 to_dir="$(DistDir)/$$dir"; \
1485 $(MKDIR) "$$to_dir" ; \
1487 to_dir="$(DistDir)"; \
1489 mid_dir=`echo "$$file" | sed -n -e 's#^\(.*\)/[^/]*$$#\1#p'`; \
1490 if test -n "$$mid_dir" ; then \
1491 $(MKDIR) "$$to_dir/$$mid_dir" || exit 1; \
1493 if test -d "$$from_dir/$$file"; then \
1494 if test -d "$(PROJ_SRC_DIR)/$$file" && \
1495 test "$$from_dir" != "$(PROJ_SRC_DIR)" ; then \
1496 cd $(PROJ_SRC_DIR) ; \
1497 $(TAR) cf - $$file --exclude .svn --exclude CVS | \
1498 ( cd $$to_dir ; $(TAR) xf - ) ; \
1499 cd $(PROJ_OBJ_DIR) ; \
1502 $(TAR) cf - $$file --exclude .svn --exclude CVS | \
1503 ( cd $$to_dir ; $(TAR) xf - ) ; \
1504 cd $(PROJ_OBJ_DIR) ; \
1506 elif test -f "$$from_dir/$$file" ; then \
1507 $(CP) -p "$$from_dir/$$file" "$(DistDir)/$$file" || exit 1; \
1508 elif test -L "$$from_dir/$$file" ; then \
1509 $(CP) -pd "$$from_dir/$$file" $(DistDir)/$$file || exit 1; \
1510 elif echo "$(DistAlways)" | grep -v "$$file" >/dev/null ; then \
1511 $(EchoCmd) "===== WARNING: Distribution Source " \
1512 "$$from_dir/$$file Not Found!" ; \
1513 elif test "$(Verb)" != '@' ; then \
1514 $(EchoCmd) "Skipping non-existent $$from_dir/$$file" ; \
1517 $(Verb) for subdir in $(DistSubDirs) ; do \
1518 if test "$$subdir" \!= "." ; then \
1519 new_distdir="$(DistDir)/$$subdir" ; \
1520 test -d "$$new_distdir" || $(MKDIR) "$$new_distdir" || exit 1; \
1521 ( cd $$subdir && $(MAKE) DistDir="$$new_distdir" distdir ) || \
1525 $(Verb) if test "$(DistDir)" = "$(TopDistDir)" ; then \
1526 $(EchoCmd) Eliminating CVS/.svn directories from distribution ; \
1527 $(RM) -rf `find $(TopDistDir) -type d \( -name CVS -o -name .svn \) -print` ;\
1528 $(MAKE) dist-hook ; \
1529 $(FIND) $(TopDistDir) -type d ! -perm -777 -exec chmod a+rwx {} \; \
1530 -o ! -type d ! -perm -444 -links 1 -exec chmod a+r {} \; \
1531 -o ! -type d ! -perm -400 -exec chmod a+r {} \; \
1532 -o ! -type d ! -perm -444 -exec \
1533 $(SHELL) $(INSTALL_SH) -c -m a+r {} {} \; \
1534 || chmod -R a+r $(DistDir) ; \
1537 # This is invoked by distdir target, define it as a no-op to avoid errors if not
1543 ###############################################################################
1544 # TOP LEVEL - targets only to apply at the top level directory
1545 ###############################################################################
1549 #------------------------------------------------------------------------
1550 # Install support for the project's include files:
1551 #------------------------------------------------------------------------
1553 $(Echo) Installing include files
1554 $(Verb) $(MKDIR) $(PROJ_includedir)
1555 $(Verb) if test -d "$(PROJ_SRC_ROOT)/include" ; then \
1556 cd $(PROJ_SRC_ROOT)/include && \
1557 for hdr in `find . -type f '!' '(' -name '*~' -o -name '.cvsignore' \
1558 -o -name '.#*' -o -name '*.in' ')' -print | grep -v CVS ` ; do \
1559 instdir=`dirname "$(PROJ_includedir)/$$hdr"` ; \
1560 if test \! -d "$$instdir" ; then \
1561 $(EchoCmd) Making install directory $$instdir ; \
1562 $(MKDIR) $$instdir ;\
1564 $(DataInstall) $$hdr $(PROJ_includedir)/$$hdr ; \
1567 ifneq ($(PROJ_SRC_ROOT),$(PROJ_OBJ_ROOT))
1568 $(Verb) if test -d "$(PROJ_OBJ_ROOT)/include" ; then \
1569 cd $(PROJ_OBJ_ROOT)/include && \
1570 for hdr in `find . -type f -print | grep -v CVS` ; do \
1571 $(DataInstall) $$hdr $(PROJ_includedir)/$$hdr ; \
1577 $(Echo) Uninstalling include files
1578 $(Verb) if [ -d "$(PROJ_SRC_ROOT)/include" ] ; then \
1579 cd $(PROJ_SRC_ROOT)/include && \
1580 $(RM) -f `find . -path '*/Internal' -prune -o '(' -type f \
1581 '!' '(' -name '*~' -o -name '.cvsignore' -o -name '.#*' -o -name '*.in' ')' \
1582 -print ')' | grep -v CVS | sed 's#^#$(PROJ_includedir)/#'` ; \
1583 cd $(PROJ_SRC_ROOT)/include && \
1584 $(RM) -f `find . -path '*/Internal' -prune -o '(' -type f -name '*.in' -print ')' \
1585 | sed 's#\.in$$##;s#^#$(PROJ_includedir)/#'` ; \
1590 #------------------------------------------------------------------------
1591 # Print out the directories used for building
1592 #------------------------------------------------------------------------
1594 $(Echo) "BuildMode : " '$(BuildMode)'
1595 $(Echo) "PROJ_SRC_ROOT: " '$(PROJ_SRC_ROOT)'
1596 $(Echo) "PROJ_SRC_DIR : " '$(PROJ_SRC_DIR)'
1597 $(Echo) "PROJ_OBJ_ROOT: " '$(PROJ_OBJ_ROOT)'
1598 $(Echo) "PROJ_OBJ_DIR : " '$(PROJ_OBJ_DIR)'
1599 $(Echo) "LLVM_SRC_ROOT: " '$(LLVM_SRC_ROOT)'
1600 $(Echo) "LLVM_OBJ_ROOT: " '$(LLVM_OBJ_ROOT)'
1601 $(Echo) "PROJ_prefix : " '$(PROJ_prefix)'
1602 $(Echo) "PROJ_bindir : " '$(PROJ_bindir)'
1603 $(Echo) "PROJ_libdir : " '$(PROJ_libdir)'
1604 $(Echo) "PROJ_etcdir : " '$(PROJ_etcdir)'
1605 $(Echo) "PROJ_includedir : " '$(PROJ_includedir)'
1606 $(Echo) "UserTargets : " '$(UserTargets)'
1607 $(Echo) "ObjMakefiles : " '$(ObjMakefiles)'
1608 $(Echo) "SrcMakefiles : " '$(SrcMakefiles)'
1609 $(Echo) "ObjDir : " '$(ObjDir)'
1610 $(Echo) "LibDir : " '$(LibDir)'
1611 $(Echo) "ToolDir : " '$(ToolDir)'
1612 $(Echo) "ExmplDir : " '$(ExmplDir)'
1613 $(Echo) "Sources : " '$(Sources)'
1614 $(Echo) "TDFiles : " '$(TDFiles)'
1615 $(Echo) "INCFiles : " '$(INCFiles)'
1616 $(Echo) "INCTMPFiles : " '$(INCTMPFiles)'
1617 $(Echo) "PreConditions: " '$(PreConditions)'
1618 $(Echo) "Compile.CXX : " '$(Compile.CXX)'
1619 $(Echo) "Compile.C : " '$(Compile.C)'
1620 $(Echo) "Archive : " '$(Archive)'
1621 $(Echo) "YaccFiles : " '$(YaccFiles)'
1622 $(Echo) "LexFiles : " '$(LexFiles)'
1623 $(Echo) "Module : " '$(Module)'
1624 $(Echo) "FilesToConfig: " '$(FilesToConfigPATH)'