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
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 $(BUILT_SOURCES) : $(ObjMakefiles)
115 #------------------------------------------------------------------------
116 # Make sure we're not using a stale configuration
117 #------------------------------------------------------------------------
119 $(Echo) Reconfiguring $(PROJ_OBJ_ROOT)
120 $(Verb) cd $(PROJ_OBJ_ROOT) && \
121 if test -w $(PROJ_OBJ_ROOT)/config.cache ; then \
122 $(RM) $(PROJ_OBJ_ROOT)/config.cache ; \
124 $(ConfigStatusScript) --recheck $(ConfigureScriptFLAGS) && \
125 $(ConfigStatusScript)
127 .PRECIOUS: $(ConfigStatusScript)
128 $(ConfigStatusScript): $(ConfigureScript)
129 $(Echo) Reconfiguring with $<
130 $(Verb) cd $(PROJ_OBJ_ROOT) && \
131 if test -w $(PROJ_OBJ_ROOT)/config.cache ; then \
132 $(RM) $(PROJ_OBJ_ROOT)/config.cache ; \
134 $(ConfigStatusScript) --recheck $(ConfigureScriptFLAGS) && \
135 $(ConfigStatusScript)
137 #------------------------------------------------------------------------
138 # Make sure the configuration makefile is up to date
139 #------------------------------------------------------------------------
140 ifneq ($(MakefileConfigIn),)
141 $(MakefileConfig): $(MakefileConfigIn) $(ConfigStatusScript)
142 $(Echo) Regenerating $@
143 $(Verb) cd $(PROJ_OBJ_ROOT) ; $(ConfigStatusScript) Makefile.config
146 ifneq ($(MakefileCommonIn),)
147 $(MakefileCommon): $(MakefileCommonIn) $(ConfigStatusScript)
148 $(Echo) Regenerating $@
149 $(Verb) cd $(PROJ_OBJ_ROOT) ; $(ConfigStatusScript) Makefile.common
152 #------------------------------------------------------------------------
153 # If the Makefile in the source tree has been updated, copy it over into the
154 # build tree. But, only do this if the source and object makefiles differ
155 #------------------------------------------------------------------------
156 ifneq ($(PROJ_OBJ_DIR),$(PROJ_SRC_DIR))
158 Makefile: $(PROJ_SRC_DIR)/Makefile
159 $(Echo) "Updating Makefile"
160 $(Verb) $(MKDIR) $(@D)
161 $(Verb) $(CP) -f $< $@
163 # Copy the Makefile.* files unless we're in the root directory which avoids
164 # the copying of Makefile.config.in or other things that should be explicitly
166 $(PROJ_OBJ_DIR)/Makefile% : $(PROJ_SRC_DIR)/Makefile%
168 *Makefile.rules) ;; \
170 *) $(Echo) "Updating $(@F)" ; \
177 #------------------------------------------------------------------------
178 # Set up the basic dependencies
179 #------------------------------------------------------------------------
180 $(UserTargets):: $(PreConditions)
184 clean-all:: clean-local clean-all-local
185 install:: install-local
186 uninstall:: uninstall-local
187 install-local:: all-local
188 install-bytecode:: install-bytecode-local
190 ###############################################################################
191 # VARIABLES: Set up various variables based on configuration data
192 ###############################################################################
194 #--------------------------------------------------------------------
195 # Variables derived from configuration we are building
196 #--------------------------------------------------------------------
199 ifdef ENABLE_PROFILING
201 CXX.Flags := -O3 -DNDEBUG -felide-constructors -finline-functions -pg
202 C.Flags := -O3 -DNDEBUG -pg
203 LD.Flags := -O3 -DNDEBUG -pg
205 ifdef ENABLE_OPTIMIZED
207 # Don't use -fomit-frame-pointer on FreeBSD
208 ifneq ($(OS),FreeBSD)
209 OmitFramePointer := -fomit-frame-pointer
211 CXX.Flags := -O3 -DNDEBUG -finline-functions -felide-constructors \
213 C.Flags := -O3 -DNDEBUG $(OmitFramePointer)
214 LD.Flags := -O3 -DNDEBUG
217 CXX.Flags := -g -D_DEBUG
218 C.Flags := -g -D_DEBUG
219 LD.Flags := -g -D_DEBUG
224 CXX.Flags += $(CXXFLAGS)
226 CPP.Flags += $(CPPFLAGS)
227 LD.Flags += $(LDFLAGS)
229 LibTool.Flags := --tag=CXX
231 #Make Floating point ieee complient on alpha
237 #--------------------------------------------------------------------
238 # Directory locations
239 #--------------------------------------------------------------------
240 ObjDir := $(PROJ_OBJ_DIR)/$(BuildMode)
241 LibDir := $(PROJ_OBJ_ROOT)/$(BuildMode)/lib
242 ToolDir := $(PROJ_OBJ_ROOT)/$(BuildMode)/bin
243 ExmplDir := $(PROJ_OBJ_ROOT)/$(BuildMode)/examples
244 LLVMLibDir := $(LLVM_OBJ_ROOT)/$(BuildMode)/lib
245 LLVMToolDir := $(LLVM_OBJ_ROOT)/$(BuildMode)/bin
246 LLVMExmplDir:= $(LLVM_OBJ_ROOT)/$(BuildMode)/examples
247 CFERuntimeLibDir := $(LLVMGCCDIR)/lib
249 #--------------------------------------------------------------------
250 # Full Paths To Compiled Tools and Utilities
251 #--------------------------------------------------------------------
252 EchoCmd = $(ECHO) llvm[$(MAKELEVEL)]:
255 LIBTOOL := $(LLVM_OBJ_ROOT)/mklib
258 LLVMAS := $(LLVMToolDir)/llvm-as$(EXEEXT)
261 BURG := $(LLVMToolDir)/burg$(EXEEXT)
264 TBLGEN := $(LLVMToolDir)/tblgen$(EXEEXT)
267 GCCAS := $(LLVMToolDir)/gccas$(EXEEXT)
270 GCCLD := $(LLVMToolDir)/gccld$(EXEEXT)
273 LLVMDIS := $(LLVMToolDir)/llvm-dis$(EXEEXT)
276 LLI := $(LLVMToolDir)/lli$(EXEEXT)
279 LLC := $(LLVMToolDir)/llc$(EXEEXT)
282 LOPT := $(LLVMToolDir)/opt$(EXEEXT)
285 LBUGPOINT := $(LLVMToolDir)/bugpoint$(EXEEXT)
288 LLVMGCCWITHPATH := PATH="$(LLVMToolDir):$(PATH)" $(LLVMGCC)
289 LLVMGXXWITHPATH := PATH="$(LLVMToolDir):$(PATH)" $(LLVMGXX)
291 #--------------------------------------------------------------------
292 # Adjust to user's request
293 #--------------------------------------------------------------------
295 # Adjust LD.Flags and Libtool.Flags depending on the kind of library that is
296 # to be built. Note that if LOADABLE_MODULE is specified then the resulting
297 # shared library can be opened with dlopen
299 LD.Flags += -rpath $(LibDir)
300 ifdef LOADABLE_MODULE
304 LibTool.Flags += --tag=disable-shared
314 # Adjust settings for verbose mode
317 LibTool.Flags += --silent
318 AR.Flags += >/dev/null 2>/dev/null
319 ConfigureScriptFLAGS += >$(PROJ_OBJ_DIR)/configure.out 2>&1
321 ConfigureScriptFLAGS :=
324 # By default, strip symbol information from executable
326 Strip := $(PLATFORMSTRIPOPTS)
327 StripWarnMsg := "(without symbols)"
328 Install.StripFlag += -s
331 # Adjust linker flags for building an executable
334 LD.Flags += -rpath $(ExmplDir) -export-dynamic
336 LD.Flags += -rpath $(ToolDir) -export-dynamic
340 #----------------------------------------------------------
341 # Options To Invoke Tools
342 #----------------------------------------------------------
344 CompileCommonOpts := -Wall -W -Wwrite-strings -Wno-unused
347 CompileCommonOpts += -D_REENTRANT -D_HPUX_SOURCE
350 LD.Flags += -L$(LibDir) -L$(LLVMLibDir)
351 CPP.Flags += -I$(PROJ_OBJ_DIR) -I$(PROJ_SRC_DIR) \
352 -I$(PROJ_OBJ_ROOT)/include \
353 -I$(PROJ_SRC_ROOT)/include \
354 -I$(LLVM_OBJ_ROOT)/include \
355 -I$(LLVM_SRC_ROOT)/include \
356 -D_GNU_SOURCE -D__STDC_LIMIT_MACROS
358 Compile.C = $(CC) $(CPP.Flags) $(CompileCommonOpts) -c $(C.Flags)
359 LTCompile.C = $(LIBTOOL) $(LibTool.Flags) --mode=compile $(Compile.C)
360 BCCompile.C = $(LLVMGCCWITHPATH) $(CPP.Flags) $(CompileCommonOpts) \
362 Preprocess.C = $(CC) $(CPP.Flags) $(CompileCommonOpts) -E $(C.Flags)
364 Compile.CXX = $(CXX) $(CPP.Flags) $(CompileCommonOpts) $(CXX.Flags) -c
365 LTCompile.CXX = $(LIBTOOL) $(LibTool.Flags) --mode=compile $(Compile.CXX)
366 BCCompile.CXX = $(LLVMGXXWITHPATH) $(CPP.Flags) $(CompileCommonOpts) \
368 Preprocess.CXX= $(CXX) $(CPP.Flags) $(CompileCommonOpts) $(CXX.Flags) -E
369 Link = $(LIBTOOL) $(LibTool.Flags) --mode=link $(CXX) $(CPP.Flags) \
370 $(CompileCommonOpts) $(LD.Flags) $(Strip)
371 Relink = $(LIBTOOL) $(LibTool.Flags) --mode=link $(CXX) $(CPP.Flags) \
373 LTInstall = $(LIBTOOL) $(LibTool.Flags) --mode=install $(INSTALL) \
375 ProgInstall = $(INSTALL) $(Install.StripFlag) -m 0755
376 DataInstall = $(INSTALL) -m 0644
377 Burg = $(BURG) -I $(PROJ_SRC_DIR)
378 TableGen = $(TBLGEN) -I $(PROJ_SRC_DIR)
379 Archive = $(AR) $(AR.Flags)
380 LArchive = $(LLVMToolDir)/llvm-ar rcsf
387 #----------------------------------------------------------
388 # Get the list of source files and compute object file
390 #----------------------------------------------------------
393 FakeSources := $(FAKE_SOURCES)
395 FakeSources += $(filter %.cpp %.c %.cc %.y %.l,$(BUILT_SOURCES))
397 BaseNameSources := $(sort $(basename $(FakeSources)))
398 ObjectsO := $(BaseNameSources:%=$(ObjDir)/%.o)
399 ObjectsLO := $(BaseNameSources:%=$(ObjDir)/%.lo)
400 ObjectsBC := $(BaseNameSources:%=$(ObjDir)/%.bc)
403 Sources := $(notdir $(wildcard $(PROJ_SRC_DIR)/*.cpp \
404 $(PROJ_SRC_DIR)/*.cc $(PROJ_SRC_DIR)/*.c $(PROJ_SRC_DIR)/*.y \
405 $(PROJ_SRC_DIR)/*.l))
407 Sources := $(SOURCES)
411 Sources += $(filter %.cpp %.c %.cc %.y %.l,$(BUILT_SOURCES))
414 BaseNameSources := $(sort $(basename $(Sources)))
415 ObjectsO := $(BaseNameSources:%=$(ObjDir)/%.o)
416 ObjectsLO := $(BaseNameSources:%=$(ObjDir)/%.lo)
417 ObjectsBC := $(BaseNameSources:%=$(ObjDir)/%.bc)
420 ###############################################################################
421 # DIRECTORIES: Handle recursive descent of directory structure
422 ###############################################################################
424 #---------------------------------------------------------
425 # Provide rules to make install dirs. This must be early
426 # in the file so they get built before dependencies
427 #---------------------------------------------------------
429 $(PROJ_bindir): $(PROJ_bindir)/.dir
430 $(PROJ_libdir): $(PROJ_libdir)/.dir
431 $(PROJ_includedir): $(PROJ_includedir)/.dir
432 $(PROJ_etcdir): $(PROJ_etcdir)/.dir
434 # To create other directories, as needed, and timestamp their creation
436 $(Verb) $(MKDIR) $* > /dev/null
439 .PRECIOUS: $(ObjDir)/.dir $(LibDir)/.dir $(ToolDir)/.dir $(ExmplDir)/.dir
440 .PRECIOUS: $(LLVMLibDir)/.dir $(LLVMToolDir)/.dir $(LLVMExmplDir)/.dir
442 #---------------------------------------------------------
443 # Handle the DIRS options for sequential construction
444 #---------------------------------------------------------
449 $(RecursiveTargets)::
450 $(Verb) for dir in $(DIRS); do \
451 if [ ! -f $$dir/Makefile ]; then \
453 $(CP) $(PROJ_SRC_DIR)/$$dir/Makefile $$dir/Makefile; \
455 if [ ! -f $$dir/LLVM_DO_NOT_BUILD ]; then \
456 ($(MAKE) -C $$dir $@ ) || exit 1; \
461 #---------------------------------------------------------
462 # Handle the EXPERIMENTAL_DIRS options ensuring success
463 # after each directory is built.
464 #---------------------------------------------------------
465 ifdef EXPERIMENTAL_DIRS
466 $(RecursiveTargets)::
467 $(Verb) for dir in $(EXPERIMENTAL_DIRS); do \
468 if [ ! -f $$dir/Makefile ]; then \
470 $(CP) $(PROJ_SRC_DIR)/$$dir/Makefile $$dir/Makefile; \
472 if [ ! -f $$dir/LLVM_DO_NOT_BUILD ]; then \
473 ($(MAKE) -C $$dir $@ ) || exit 0; \
478 #---------------------------------------------------------
479 # Handle the PARALLEL_DIRS options for parallel construction
480 #---------------------------------------------------------
483 SubDirs += $(PARALLEL_DIRS)
485 # Unfortunately, this list must be maintained if new recursive targets are added
486 all :: $(addsuffix /.makeall ,$(PARALLEL_DIRS))
487 clean :: $(addsuffix /.makeclean ,$(PARALLEL_DIRS))
488 clean-all:: $(addsuffix /.makeclean-all,$(PARALLEL_DIRS))
489 install :: $(addsuffix /.makeinstall ,$(PARALLEL_DIRS))
490 uninstall:: $(addsuffix /.makeuninstall,$(PARALLEL_DIRS))
491 install-bytecode :: $(addsuffix /.makeinstall-bytecode,$(PARALLEL_DIRS))
493 ParallelTargets := $(foreach T,$(RecursiveTargets),%/.make$(T))
496 $(Verb) if [ ! -f $(@D)/Makefile ]; then \
498 $(CP) $(PROJ_SRC_DIR)/$(@D)/Makefile $(@D)/Makefile; \
500 if [ ! -f $$dir/LLVM_DO_NOT_BUILD ]; then \
501 $(MAKE) -C $(@D) $(subst $(@D)/.make,,$@) ; \
505 #---------------------------------------------------------
506 # Handle the OPTIONAL_DIRS options for directores that may
508 #---------------------------------------------------------
511 SubDirs += $(OPTIONAL_DIRS)
513 $(RecursiveTargets)::
514 $(Verb) for dir in $(OPTIONAL_DIRS); do \
515 if [ -d $(PROJ_SRC_DIR)/$$dir ]; then\
516 if [ ! -f $$dir/Makefile ]; then \
518 $(CP) $(PROJ_SRC_DIR)/$$dir/Makefile $$dir/Makefile; \
520 if [ ! -f $$dir/LLVM_DO_NOT_BUILD ]; then \
521 ($(MAKE) -C$$dir $@ ) || exit 1; \
527 #---------------------------------------------------------
528 # Handle the CONFIG_FILES options
529 #---------------------------------------------------------
532 install-local:: $(PROJ_etcdir) $(CONFIG_FILES)
533 $(Echo) Installing Configuration Files To $(PROJ_etcdir)
534 $(Verb)for file in $(CONFIG_FILES); do \
535 if test -f $(PROJ_OBJ_DIR)/$${file} ; then \
536 $(DataInstall) $(PROJ_OBJ_DIR)/$${file} $(PROJ_etcdir) ; \
537 elif test -f $(PROJ_SRC_DIR)/$${file} ; then \
538 $(DataInstall) $(PROJ_SRC_DIR)/$${file} $(PROJ_etcdir) ; \
540 $(ECHO) Error: cannot find config file $${file}. ; \
545 $(Echo) Uninstalling Configuration Files From $(PROJ_etcdir)
546 $(Verb)for file in $(CONFIG_FILES); do \
547 $(RM) -f $(PROJ_etcdir)/$${file} ; \
552 ###############################################################################
553 # Set up variables for building libararies
554 ###############################################################################
556 #---------------------------------------------------------
557 # Handle the special "JIT" value for LLVM_LIBS which is a
558 # shorthand for a bunch of libraries that get the correct
559 # JIT support for a library or a tool that runs JIT.
560 #---------------------------------------------------------
561 ifeq ($(LLVMLIBS),JIT)
563 # Make sure we can get our own symbols in the tool
566 # Generic JIT libraries
567 JIT_LIBS := LLVMInterpreter LLVMJIT LLVMCodeGen LLVMExecutionEngine
569 # You can enable the X86 JIT on a non-X86 host by setting the flag
570 # ENABLE_X86_JIT on the make command line. If not, it will still be
571 # enabled automagically on an X86 host.
576 # What the X86 JIT requires
578 JIT_LIBS += LLVMX86 LLVMSelectionDAG
581 # You can enable the SparcV9 JIT on a non-SparcV9 host by setting the flag
582 # ENABLE_SPARCV9_JIT on the make command line. If not, it will still be
583 # enabled automagically on an SparcV9 host.
584 ifeq ($(ARCH), Sparc)
585 ENABLE_SPARCV9_JIT = 1
588 # What the Sparc JIT requires
589 ifdef ENABLE_SPARCV9_JIT
590 JIT_LIBS += LLVMSparcV9 LLVMSparcV9ModuloSched LLVMSparcV9InstrSched \
591 LLVMSparcV9LiveVar LLVMInstrumentation.a \
592 LLVMBCWriter LLVMTransforms.a LLVMipo.a LLVMipa.a \
593 LLVMDataStructure LLVMSparcV9RegAlloc
596 # You can enable the PowerPC JIT on a non-PowerPC host by setting the flag
597 # ENABLE_PPC_JIT on the make command line. If not, it will still be
598 # enabled automagically on an PowerPC host.
599 ifeq ($(ARCH), PowerPC)
603 # What the PowerPC JIT requires
605 JIT_LIBS += LLVMPowerPC LLVMSelectionDAG
608 # You can enable the Alpha JIT on a non-Alpha host by setting the flag
609 # ENABLE_ALPHA_JIT on the make command line. If not, it will still be
610 # enabled automagically on an Alpha host.
611 ifeq ($(ARCH), Alpha)
615 # What the Alpha JIT requires
616 ifdef ENABLE_ALPHA_JIT
617 JIT_LIBS += LLVMAlpha LLVMSelectionDAG
620 LLVMLIBS := $(JIT_LIBS) LLVMScalarOpts.a LLVMTransformUtils.a LLVMAnalysis.a \
621 LLVMBCReader LLVMCore LLVMSupport.a LLVMTarget.a LLVMbzip2 \
622 LLVMSystem.a $(PLATFORMLIBDL)
625 #---------------------------------------------------------
626 # Define various command line options pertaining to the
627 # libraries needed when linking. There are "Proj" libs
628 # (defined by the user's project) and "LLVM" libs (defined
629 # by the # LLVM project).
630 #---------------------------------------------------------
631 # Some versions of gcc on Alpha produce too many symbols, so use a .a file
633 USEDLIBS := $(subst LLVMCore, LLVMCore.a, $(USEDLIBS))
634 LLVMLIBS := $(subst LLVMCore, LLVMCore.a, $(LLVMLIBS))
637 ProjLibsOptions := $(patsubst %.a.o, -l%, $(addsuffix .o, $(USEDLIBS)))
638 ProjLibsOptions := $(patsubst %.o, $(LibDir)/%.o, $(ProjLibsOptions))
639 LLVMLibsOptions := $(patsubst %.a.o, -l%, $(addsuffix .o, $(LLVMLIBS)))
640 LLVMLibsOptions := $(patsubst %.o, $(LLVMLibDir)/%.o, $(LLVMLibsOptions))
641 ProjUsedLibs := $(patsubst %.a.o, lib%.a, $(addsuffix .o, $(USEDLIBS)))
642 LLVMUsedLibs := $(patsubst %.a.o, lib%.a, $(addsuffix .o, $(LLVMLIBS)))
643 ProjLibsPaths := $(addprefix $(LibDir)/,$(ProjUsedLibs))
644 LLVMLibsPaths := $(addprefix $(LLVMLibDir)/,$(LLVMUsedLibs))
646 ###############################################################################
647 # Library Build Rules: Four ways to build a library
648 ###############################################################################
650 #---------------------------------------------------------
651 # Bytecode Module Targets:
652 # If the user set MODULE_NAME then they want to build a
653 # bytecode module from the sources. We compile all the
654 # sources and link it together into a single bytecode
656 #---------------------------------------------------------
659 ifeq ($(strip $(LLVMGCC)),)
660 $(warning Modules require llvm-gcc but no llvm-gcc is available ****)
663 Module := $(LibDir)/$(MODULE_NAME).bc
664 LinkModule := $(LLVMGCCWITHPATH) -shared -nostdlib
666 ifdef EXPORTED_SYMBOL_FILE
667 LinkModule += -Xlinker -internalize-public-api-file=$(EXPORTED_SYMBOL_FILE)
670 $(Module): $(BUILT_SOURCES) $(ObjectsBC) $(LibDir)/.dir $(GCCLD)
671 $(Echo) Building $(BuildMode) Bytecode Module $(notdir $@)
672 $(Verb) $(LinkModule) -o $@ $(ObjectsBC)
674 all-local:: $(Module)
677 ifneq ($(strip $(Module)),)
678 -$(Verb) $(RM) -f $(Module)
681 ifdef BYTECODE_DESTINATION
682 ModuleDestDir := $(BYTECODE_DESTINATION)
684 ModuleDestDir := $(PROJ_libdir)
687 DestModule := $(ModuleDestDir)/$(MODULE_NAME).bc
689 install-module:: $(DestModule)
690 install-local:: $(DestModule)
692 $(DestModule): $(ModuleDestDir) $(Module)
693 $(Echo) Installing $(BuildMode) Bytecode Module $(DestModule)
694 $(Verb) $(DataInstall) $(Module) $(DestModule)
697 $(Echo) Uninstalling $(BuildMode) Bytecode Module $(DestModule)
698 -$(Verb) $(RM) -f $(DestModule)
703 # if we're building a library ...
706 # Make sure there isn't any extranous whitespace on the LIBRARYNAME option
707 LIBRARYNAME := $(strip $(LIBRARYNAME))
708 ifdef LOADABLE_MODULE
709 LibName.LA := $(LibDir)/$(LIBRARYNAME).la
711 LibName.LA := $(LibDir)/lib$(LIBRARYNAME).la
713 LibName.A := $(LibDir)/lib$(LIBRARYNAME).a
714 LibName.O := $(LibDir)/$(LIBRARYNAME).o
715 LibName.BCA:= $(LibDir)/lib$(LIBRARYNAME).bca
717 #---------------------------------------------------------
718 # Shared Library Targets:
719 # If the user asked for a shared library to be built
720 # with the SHARED_LIBRARY variable, then we provide
721 # targets for building them.
722 #---------------------------------------------------------
725 all-local:: $(LibName.LA)
727 ifdef LINK_LIBS_IN_SHARED
728 $(LibName.LA): $(ObjectsLO) $(LibDir)/.dir
729 $(Echo) Linking $(BuildMode) Shared Library $(LIBRARYNAME)$(SHLIBEXT)
730 $(Verb) $(Link) -o $@ $(ObjectsLO) \
731 $(ProjLibsOptions) $(LLVMLibsOptions)
732 $(Verb) $(LTInstall) $@ $(LibDir)
734 $(LibName.LA): $(ObjectsLO) $(LibDir)/.dir
735 $(Echo) Linking $(BuildMode) Shared Library $(LIBRARYNAME)$(SHLIBEXT)
736 $(Verb) $(Link) -o $@ $(ObjectsLO)
737 $(Verb) $(LTInstall) $@ $(LibDir)
741 ifneq ($(strip $(LibName.LA)),)
742 -$(Verb) $(RM) -f $(LibName.LA)
745 DestSharedLib = $(PROJ_libdir)/lib$(LIBRARYNAME)$(SHLIBEXT)
747 install-local:: $(DestSharedLib)
749 $(DestSharedLib): $(PROJ_libdir) $(LibName.LA)
750 $(Echo) Installing $(BuildMode) Shared Library $(DestSharedLib)
751 $(Verb) $(LTInstall) $(LibName.LA) $(DestSharedLib)
752 $(Verb) $(LIBTOOL) --finish $(PROJ_libdir)
755 $(Echo) Uninstalling $(BuildMode) Shared Library $(DestSharedLib)
756 -$(Verb) $(RM) -f $(PROJ_libdir)/lib$(LIBRARYNAME).*
760 #---------------------------------------------------------
761 # Bytecode Library Targets:
762 # If the user asked for a bytecode library to be built
763 # with the BYTECODE_LIBRARY variable, then we provide
764 # targets for building them.
765 #---------------------------------------------------------
766 ifdef BYTECODE_LIBRARY
767 ifeq ($(strip $(LLVMGCC)),)
768 $(warning Bytecode libraries require llvm-gcc which could not be found ****)
771 # make the C and C++ compilers strip debug info out of bytecode libraries.
772 BCCompile.C += -Wa,-strip-debug
773 BCCompile.CXX += -Wa,-strip-debug
775 all-local:: $(LibName.BCA)
777 ifdef EXPORTED_SYMBOL_FILE
778 BCLinkLib = $(LLVMGCCWITHPATH) -shared -nostdlib -Xlinker \
779 -internalize-public-api-file=$(EXPORTED_SYMBOL_FILE)
781 $(LibName.BCA): $(ObjectsBC) $(LibDir)/.dir $(GCCLD) \
782 $(LLVMToolDir)/llvm-ar
783 $(Echo) Building $(BuildMode) Bytecode Archive $(notdir $@) \
785 $(Verb) $(BCLinkLib) -o $(ObjDir)/$(LIBRARYNAME).o $(ObjectsBC)
787 $(Verb) $(LArchive) $@ $(ObjDir)/$(LIBRARYNAME).o
789 $(LibName.BCA): $(ObjectsBC) $(LibDir)/.dir \
790 $(LLVMToolDir)/llvm-ar
791 $(Echo) Building $(BuildMode) Bytecode Archive $(notdir $@)
793 $(Verb) $(LArchive) $@ $(ObjectsBC)
798 ifneq ($(strip $(LibName.BCA)),)
799 -$(Verb) $(RM) -f $(LibName.BCA)
802 ifdef BYTECODE_DESTINATION
803 BytecodeDestDir := $(BYTECODE_DESTINATION)
805 BytecodeDestDir := $(PROJ_libdir)
808 DestBytecodeLib = $(BytecodeDestDir)/lib$(LIBRARYNAME).a
810 install-bytecode-local:: $(DestBytecodeLib)
812 install-local:: $(DestBytecodeLib)
814 $(DestBytecodeLib): $(BytecodeDestDir) $(LibName.BCA)
815 $(Echo) Installing $(BuildMode) Bytecode Archive $(DestBytecodeLib)
816 $(Verb) $(DataInstall) $(LibName.BCA) $(DestBytecodeLib)
819 $(Echo) Uninstalling $(BuildMode) Bytecode Archive $(DestBytecodeLib)
820 -$(Verb) $(RM) -f $(DestBytecodeLib)
825 #---------------------------------------------------------
826 # ReLinked Library Targets:
827 # If the user explicitly requests a relinked library with
828 # BUILD_RELINKED, provide it. Otherwise, if they specify
829 # neither of BUILD_ARCHIVE or DONT_BUILD_RELINKED, give
831 #---------------------------------------------------------
833 ifndef DONT_BUILD_RELINKED
840 all-local:: $(LibName.O)
842 $(LibName.O): $(ObjectsO) $(LibDir)/.dir
843 $(Echo) Linking $(BuildMode) Object Library $(notdir $@)
844 $(Verb) $(Relink) -o $@ $(ObjectsO)
847 ifneq ($(strip $(LibName.O)),)
848 -$(Verb) $(RM) -f $(LibName.O)
851 DestRelinkedLib = $(PROJ_libdir)/$(LIBRARYNAME).o
853 install-local:: $(DestRelinkedLib)
855 $(DestRelinkedLib): $(PROJ_libdir) $(LibName.O)
856 $(Echo) Installing $(BuildMode) Object Library $(DestRelinkedLib)
857 $(Verb) $(LTInstall) $(LibName.O) $(DestRelinkedLib)
860 $(Echo) Uninstalling $(BuildMode) Object Library $(DestRelinkedLib)
861 -$(Verb) $(RM) -f $(DestRelinkedLib)
865 #---------------------------------------------------------
866 # Archive Library Targets:
867 # If the user wanted a regular archive library built,
868 # then we provide targets for building them.
869 #---------------------------------------------------------
872 all-local:: $(LibName.A)
874 $(LibName.A): $(ObjectsO) $(LibDir)/.dir
875 $(Echo) Building $(BuildMode) Archive Library $(notdir $@)
877 $(Verb) $(Archive) $@ $(ObjectsO)
881 ifneq ($(strip $(LibName.A)),)
882 -$(Verb) $(RM) -f $(LibName.A)
885 DestArchiveLib := $(PROJ_libdir)/lib$(LIBRARYNAME).a
887 install-local:: $(DestArchiveLib)
889 $(DestArchiveLib): $(PROJ_libdir) $(LibName.A)
890 $(Echo) Installing $(BuildMode) Archive Library $(DestArchiveLib)
891 $(Verb) $(MKDIR) $(PROJ_libdir)
892 $(Verb) $(LTInstall) $(LibName.A) $(DestArchiveLib)
895 $(Echo) Uninstalling $(BuildMode) Archive Library $(DestArchiveLib)
896 -$(Verb) $(RM) -f $(DestArchiveLib)
903 ###############################################################################
904 # Tool Build Rules: Build executable tool based on TOOLNAME option
905 ###############################################################################
909 #---------------------------------------------------------
910 # Set up variables for building a tool.
911 #---------------------------------------------------------
913 ToolBuildPath := $(ExmplDir)/$(strip $(TOOLNAME))$(EXEEXT)
915 ToolBuildPath := $(ToolDir)/$(strip $(TOOLNAME))$(EXEEXT)
918 #---------------------------------------------------------
919 # Tell make that we need to rebuild subdirectories before
920 # we can link the tool. This affects things like LLI which
921 # has library subdirectories.
922 #---------------------------------------------------------
923 $(ToolBuildPath): $(addsuffix /.makeall, $(PARALLEL_DIRS))
925 #---------------------------------------------------------
926 # Provide targets for building the tools
927 #---------------------------------------------------------
928 all-local:: $(ToolBuildPath)
931 ifneq ($(strip $(ToolBuildPath)),)
932 -$(Verb) $(RM) -f $(ToolBuildPath)
936 $(ToolBuildPath): $(ExmplDir)/.dir
938 $(ToolBuildPath): $(ToolDir)/.dir
941 $(ToolBuildPath): $(ObjectsO) $(ProjLibsPaths) $(LLVMLibsPaths)
942 $(Echo) Linking $(BuildMode) executable $(TOOLNAME) $(StripWarnMsg)
943 $(Verb) $(Link) -o $@ $(TOOLLINKOPTS) $(ObjectsO) $(ProjLibsOptions) \
944 $(LLVMLibsOptions) $(ExtraLibs) $(TOOLLINKOPTSB) $(LIBS)
945 $(Echo) ======= Finished Linking $(BuildMode) Executable $(TOOLNAME) $(StripWarnMsg)
947 DestTool = $(PROJ_bindir)/$(TOOLNAME)
949 install-local:: $(DestTool)
951 $(DestTool): $(PROJ_bindir) $(ToolBuildPath)
952 $(Echo) Installing $(BuildMode) $(DestTool)
953 $(Verb) $(ProgInstall) $(ToolBuildPath) $(DestTool)
956 $(Echo) Uninstalling $(BuildMode) $(DestTool)
957 -$(Verb) $(RM) -f $(DestTool)
961 ###############################################################################
962 # Object Build Rules: Build object files based on sources
963 ###############################################################################
965 # Provide rule sets for when dependency generation is enabled
966 ifndef DISABLE_AUTO_DEPENDENCIES
968 #---------------------------------------------------------
969 # Create .lo files in the ObjDir directory from the .cpp and .c files...
970 #---------------------------------------------------------
973 $(ObjDir)/%.lo $(ObjDir)/%.o: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES)
974 $(Echo) "Compiling $*.cpp for $(BuildMode) build (PIC)"
975 $(Verb) if $(LTCompile.CXX) -MD -MT $@ -MP -MF $(ObjDir)/$*.LACXXd $< -o $@ ; \
976 then $(MV) -f "$(ObjDir)/$*.LACXXd" "$(ObjDir)/$*.d"; \
977 else $(RM) -f "$(ObjDir)/$*.LACXXd"; exit 1; fi
979 $(ObjDir)/%.lo $(ObjDir)/%.o: %.cc $(ObjDir)/.dir $(BUILT_SOURCES)
980 $(Echo) "Compiling $*.cc for $(BuildMode) build (PIC)"
981 $(Verb) if $(LTCompile.CXX) -MD -MT $@ -MP -MF $(ObjDir)/$*.LACXXd $< -o $@ ; \
982 then $(MV) -f "$(ObjDir)/$*.LACXXd" "$(ObjDir)/$*.d"; \
983 else $(RM) -f "$(ObjDir)/$*.LACXXd"; exit 1; fi
985 $(ObjDir)/%.lo $(ObjDir)/%.o: %.c $(ObjDir)/.dir $(BUILT_SOURCES)
986 $(Echo) "Compiling $*.c for $(BuildMode) build (PIC)"
987 $(Verb) if $(LTCompile.C) -MD -MT $@ -MP -MF $(ObjDir)/$*.LACd $< -o $@ ; \
988 then $(MV) -f "$(ObjDir)/$*.LACd" "$(ObjDir)/$*.d"; \
989 else $(RM) -f "$(ObjDir)/$*.LACd"; exit 1; fi
991 #---------------------------------------------------------
992 # Create .o files in the ObjDir directory from the .cpp and .c files...
993 #---------------------------------------------------------
996 $(ObjDir)/%.o: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES)
997 $(Echo) "Compiling $*.cpp for $(BuildMode) build"
998 $(Verb) if $(Compile.CXX) -MD -MT $@ -MP -MF $(ObjDir)/$*.CXXd $< -o $@ ; \
999 then $(MV) -f "$(ObjDir)/$*.CXXd" "$(ObjDir)/$*.d"; \
1000 else $(RM) -f "$(ObjDir)/$*.CXXd"; exit 1; fi
1002 $(ObjDir)/%.o: %.cc $(ObjDir)/.dir $(BUILT_SOURCES)
1003 $(Echo) "Compiling $*.cc for $(BuildMode) build"
1004 $(Verb) if $(Compile.CXX) -MD -MT $@ -MP -MF $(ObjDir)/$*.CXXd $< -o $@ ; \
1005 then $(MV) -f "$(ObjDir)/$*.CXXd" "$(ObjDir)/$*.d"; \
1006 else $(RM) -f "$(ObjDir)/$*.CXXd"; exit 1; fi
1008 $(ObjDir)/%.o: %.c $(ObjDir)/.dir $(BUILT_SOURCES)
1009 $(Echo) "Compiling $*.c for $(BuildMode) build"
1010 $(Verb) if $(Compile.C) -MD -MT $@ -MP -MF $(ObjDir)/$*.Cd $< -o $@ ; \
1011 then $(MV) -f "$(ObjDir)/$*.Cd" "$(ObjDir)/$*.d"; \
1012 else $(RM) -f "$(ObjDir)/$*.Cd"; exit 1; fi
1016 ## Rules for building preprocessed (.i/.ii) outputs.
1017 $(BuildMode)/%.ii: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES)
1018 $(Echo) "Compiling $*.cpp for $(BuildMode) build to .ii file"
1019 $(Verb) $(Preprocess.CXX) $< -o $@
1021 $(BuildMode)/%.ii: %.cc $(ObjDir)/.dir $(BUILT_SOURCES)
1022 $(Echo) "Compiling $*.cc for $(BuildMode) build to .ii file"
1023 $(Verb) $(Preprocess.CXX) $< -o $@
1025 $(BuildMode)/%.i: %.c $(ObjDir)/.dir $(BUILT_SOURCES)
1026 $(Echo) "Compiling $*.c for $(BuildMode) build to .i file"
1027 $(Verb) $(Preprocess.C) $< -o $@
1030 #---------------------------------------------------------
1031 # Create .bc files in the ObjDir directory from .cpp .cc and .c files...
1032 #---------------------------------------------------------
1033 $(ObjDir)/%.bc: %.cpp $(ObjDir)/.dir $(GCCAS) $(BUILT_SOURCES)
1034 $(Echo) "Compiling $*.cpp for $(BuildMode) build (bytecode)"
1035 $(Verb) if $(BCCompile.CXX) -MD -MT $@ -MP -MF "$(ObjDir)/$*.BCCXXd" $< -o $@ ; \
1036 then $(MV) -f "$(ObjDir)/$*.BCCXXd" "$(ObjDir)/$*.d"; \
1037 else $(RM) -f "$(ObjDir)/$*.BCCXXd"; exit 1; fi
1039 $(ObjDir)/%.bc: %.cc $(ObjDir)/.dir $(GCCAS) $(BUILT_SOURCES)
1040 $(Echo) "Compiling $*.cc for $(BuildMode) build (bytecode)"
1041 $(Verb) if $(BCCompile.CXX) -MD -MT $@ -MP -MF "$(ObjDir)/$*.BCCXXd" $< -o $@ ; \
1042 then $(MV) -f "$(ObjDir)/$*.BCCXXd" "$(ObjDir)/$*.d"; \
1043 else $(RM) -f "$(ObjDir)/$*.BCCXXd"; exit 1; fi
1045 $(ObjDir)/%.bc: %.c $(ObjDir)/.dir $(GCCAS) $(BUILT_SOURCES)
1046 $(Echo) "Compiling $*.c for $(BuildMode) build (bytecode)"
1047 $(Verb) if $(BCCompile.C) -MD -MT $@ -MP -MF "$(ObjDir)/$*.BCCd" $< -o $@ ; \
1048 then $(MV) -f "$(ObjDir)/$*.BCCd" "$(ObjDir)/$*.d"; \
1049 else $(RM) -f "$(ObjDir)/$*.BCCd"; exit 1; fi
1051 # Provide alternate rule sets if dependencies are disabled
1054 ifdef SHARED_LIBRARY
1056 $(ObjDir)/%.lo $(ObjDir)/%.o: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES)
1057 $(Echo) "Compiling $*.cpp for $(BuildMode) build (PIC)"
1058 $(LTCompile.CXX) $< -o $@
1060 $(ObjDir)/%.lo $(ObjDir)/%.o: %.cc $(ObjDir)/.dir $(BUILT_SOURCES)
1061 $(Echo) "Compiling $*.cc for $(BuildMode) build (PIC)"
1062 $(LTCompile.CXX) $< -o $@
1064 $(ObjDir)/%.lo $(ObjDir)/%.o: %.c $(ObjDir)/.dir $(BUILT_SOURCES)
1065 $(Echo) "Compiling $*.c for $(BuildMode) build (PIC)"
1066 $(LTCompile.C) $< -o $@
1070 $(ObjDir)/%.o: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES)
1071 $(Echo) "Compiling $*.cpp for $(BuildMode) build"
1072 $(Compile.CXX) $< -o $@
1074 $(ObjDir)/%.o: %.cc $(ObjDir)/.dir $(BUILT_SOURCES)
1075 $(Echo) "Compiling $*.cc for $(BuildMode) build"
1076 $(Compile.CXX) $< -o $@
1078 $(ObjDir)/%.o: %.c $(ObjDir)/.dir $(BUILT_SOURCES)
1079 $(Echo) "Compiling $*.c for $(BuildMode) build"
1080 $(Compile.C) $< -o $@
1083 $(ObjDir)/%.bc: %.cpp $(ObjDir)/.dir $(GCCAS) $(BUILT_SOURCES)
1084 $(Echo) "Compiling $*.cpp for $(BuildMode) build (bytecode)"
1085 $(BCCompile.CXX) $< -o $@
1087 $(ObjDir)/%.bc: %.cc $(ObjDir)/.dir $(GCCAS) $(BUILT_SOURCES)
1088 $(Echo) "Compiling $*.cc for $(BuildMode) build (bytecode)"
1089 $(BCCompile.CXX) $< -o $@
1091 $(ObjDir)/%.bc: %.c $(ObjDir)/.dir $(GCCAS) $(BUILT_SOURCES)
1092 $(Echo) "Compiling $*.c for $(BuildMode) build (bytecode)"
1093 $(BCCompile.C) $< -o $@
1097 #---------------------------------------------------------
1098 # Provide rule to build .bc files from .ll sources,
1099 # regardless of dependencies
1100 #---------------------------------------------------------
1101 $(ObjDir)/%.bc: %.ll $(ObjDir)/.dir $(LLVMAS)
1102 $(Echo) "Compiling $*.ll for $(BuildMode) build"
1103 $(Verb) $(LLVMAS) $< -f -o $@
1105 ###############################################################################
1106 # TABLEGEN: Provide rules for running tblgen to produce *.inc files
1107 ###############################################################################
1111 TDFiles := $(strip $(wildcard $(PROJ_SRC_DIR)/*.td) $(LLVM_SRC_ROOT)/lib/Target/Target.td $(LLVM_SRC_ROOT)/lib/Target/TargetSelectionDAG.td)
1112 INCFiles := $(filter %.inc,$(BUILT_SOURCES))
1113 INCTMPFiles := $(INCFiles:%=$(ObjDir)/%.tmp)
1114 .PRECIOUS: $(INCTMPFiles) $(INCFiles)
1116 # All of these files depend on tblgen and the .td files.
1117 $(INCTMPFiles) : $(TBLGEN) $(TDFiles)
1119 # INCFiles rule: All of the tblgen generated files are emitted to
1120 # $(ObjDir)/%.inc.tmp, instead of emitting them directly to %.inc. This allows
1121 # us to only "touch" the real file if the contents of it change. IOW, if
1122 # tblgen is modified, all of the .inc.tmp files are regereated, but no
1123 # dependencies of the .inc files are, unless the contents of the .inc file
1125 $(INCFiles) : %.inc : $(ObjDir)/%.inc.tmp
1126 $(Verb) $(CMP) -s $@ $< || $(CP) $< $@
1128 $(TARGET:%=$(ObjDir)/%GenRegisterNames.inc.tmp): \
1129 $(ObjDir)/%GenRegisterNames.inc.tmp : %.td $(ObjDir)/.dir
1130 $(Echo) "Building $(<F) register names with tblgen"
1131 $(Verb) $(TableGen) -gen-register-enums -o $@ $<
1133 $(TARGET:%=$(ObjDir)/%GenRegisterInfo.h.inc.tmp): \
1134 $(ObjDir)/%GenRegisterInfo.h.inc.tmp : %.td $(ObjDir)/.dir
1135 $(Echo) "Building $(<F) register information header with tblgen"
1136 $(Verb) $(TableGen) -gen-register-desc-header -o $@ $<
1138 $(TARGET:%=$(ObjDir)/%GenRegisterInfo.inc.tmp): \
1139 $(ObjDir)/%GenRegisterInfo.inc.tmp : %.td $(ObjDir)/.dir
1140 $(Echo) "Building $(<F) register info implementation with tblgen"
1141 $(Verb) $(TableGen) -gen-register-desc -o $@ $<
1143 $(TARGET:%=$(ObjDir)/%GenInstrNames.inc.tmp): \
1144 $(ObjDir)/%GenInstrNames.inc.tmp : %.td $(ObjDir)/.dir
1145 $(Echo) "Building $(<F) instruction names with tblgen"
1146 $(Verb) $(TableGen) -gen-instr-enums -o $@ $<
1148 $(TARGET:%=$(ObjDir)/%GenInstrInfo.inc.tmp): \
1149 $(ObjDir)/%GenInstrInfo.inc.tmp : %.td $(ObjDir)/.dir
1150 $(Echo) "Building $(<F) instruction information with tblgen"
1151 $(Verb) $(TableGen) -gen-instr-desc -o $@ $<
1153 $(TARGET:%=$(ObjDir)/%GenAsmWriter.inc.tmp): \
1154 $(ObjDir)/%GenAsmWriter.inc.tmp : %.td $(ObjDir)/.dir
1155 $(Echo) "Building $(<F) assembly writer with tblgen"
1156 $(Verb) $(TableGen) -gen-asm-writer -o $@ $<
1158 $(TARGET:%=$(ObjDir)/%GenAsmWriter1.inc.tmp): \
1159 $(ObjDir)/%GenAsmWriter1.inc.tmp : %.td $(ObjDir)/.dir
1160 $(Echo) "Building $(<F) assembly writer #1 with tblgen"
1161 $(Verb) $(TableGen) -gen-asm-writer -asmwriternum=1 -o $@ $<
1163 $(TARGET:%=$(ObjDir)/%GenCodeEmitter.inc.tmp): \
1164 $(ObjDir)/%GenCodeEmitter.inc.tmp: %.td $(ObjDir)/.dir
1165 $(Echo) "Building $(<F) code emitter with tblgen"
1166 $(Verb) $(TableGen) -gen-emitter -o $@ $<
1168 $(TARGET:%=$(ObjDir)/%GenDAGISel.inc.tmp): \
1169 $(ObjDir)/%GenDAGISel.inc.tmp : %.td $(ObjDir)/.dir
1170 $(Echo) "Building $(<F) instruction selector implementation with tblgen"
1171 $(Verb) $(TableGen) -gen-dag-isel -o $@ $<
1173 $(TARGET:%=$(ObjDir)/%GenSubtarget.inc.tmp): \
1174 $(ObjDir)/%GenSubtarget.inc.tmp : %.td $(ObjDir)/.dir
1175 $(Echo) "Building $(<F) subtarget information with tblgen"
1176 $(Verb) $(TableGen) -gen-subtarget -o $@ $<
1179 -$(Verb) $(RM) -f $(INCFiles)
1183 ###############################################################################
1184 # LEX AND YACC: Provide rules for generating sources with lex and yacc
1185 ###############################################################################
1187 #---------------------------------------------------------
1188 # Provide rules for generating a .cpp source file from
1189 # (f)lex input sources.
1190 #---------------------------------------------------------
1192 LexFiles := $(filter %.l,$(Sources))
1194 ifneq ($(LexFiles),)
1196 # Cancel built-in rules for lex
1200 # Note the extra sed filtering here, used to cut down on the warnings emited
1201 # by GCC. The last line is a gross hack to work around flex aparently not
1202 # being able to resize the buffer on a large token input. Currently, for
1203 # uninitialized string buffers in LLVM we can generate very long tokens, so
1204 # this is a hack around it.
1205 # FIXME. (f.e. char Buffer[10000] )
1206 $(PROJ_SRC_DIR)/%.cpp: $(PROJ_SRC_DIR)/%.l
1207 $(Echo) Flexing $*.l
1208 $(Verb) $(FLEX) -t $(PROJ_SRC_DIR)/$*.l | \
1209 $(SED) 's/void yyunput/inline void yyunput/' | \
1210 $(SED) 's/void \*yy_flex_realloc/inline void *yy_flex_realloc/' | \
1211 $(SED) 's/#define YY_BUF_SIZE 16384/#define YY_BUF_SIZE (16384*64)/' \
1212 > $(PROJ_SRC_DIR)/$*.cpp
1213 $(Echo) "*** DON'T FORGET TO CHECK IN $*.cpp (generated file)"
1215 LexObjs := $(patsubst %.l,$(ObjDir)/%.o,$(LexFiles))
1216 $(LexObjs): $(ObjDir)/%.o : $(PROJ_SRC_DIR)/%.cpp
1219 -$(Verb) $(RM) -f $(LexOutput)
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),)
1231 YaccOutput := $(addprefix $(patsubst %.y,%,$(YaccFiles)),.output)
1233 .PRECIOUS: $(YaccOutput)
1235 # Cancel built-in rules for yacc
1240 # Rule for building the bison parsers...
1241 $(PROJ_SRC_DIR)/%.cpp $(PROJ_SRC_DIR)/%.h : $(PROJ_SRC_DIR)/%.y
1242 $(Echo) "Bisoning $*.y"
1243 $(Verb) $(BISON) -v -d -p $(<F:%Parser.y=%) -o $*.tab.c $<
1244 $(Verb) $(MV) -f $*.tab.c $(PROJ_SRC_DIR)/$*.cpp
1245 $(Verb) $(MV) -f $*.tab.h $(PROJ_SRC_DIR)/$*.h
1246 $(Echo) "*** DON'T FORGET TO CHECK IN $*.cpp and $*.h (generated files)"
1249 $(Verb) $(RM) -f $(YaccOutput)
1252 ###############################################################################
1253 # OTHER RULES: Other rules needed
1254 ###############################################################################
1256 # To create postscript files from dot files...
1257 ifneq ($(DOT),false)
1259 $(DOT) -Tps < $< > $@
1262 $(Echo) "Cannot build $@: The program dot is not installed"
1265 # This rules ensures that header files that are removed still have a rule for
1266 # which they can be "generated." This allows make to ignore them and
1267 # reproduce the dependency lists.
1271 # Define clean-local to clean the current directory. Note that this uses a
1272 # very conservative approach ensuring that empty variables do not cause
1273 # errors or disastrous removal.
1275 ifneq ($(strip $(ObjDir)),)
1276 -$(Verb) $(RM) -rf $(ObjDir)
1278 -$(Verb) $(RM) -f core core.[0-9][0-9]* *.o *.d *~ *.flc
1279 ifneq ($(strip $(SHLIBEXT)),) # Extra paranoia - make real sure SHLIBEXT is set
1280 -$(Verb) $(RM) -f *$(SHLIBEXT)
1284 -$(Verb) $(RM) -rf Debug Release Profile
1286 # Build tags database for Emacs/Xemacs:
1290 find $(PROJ_SRC_ROOT)/include $(PROJ_SRC_ROOT)/lib \
1291 $(PROJ_SRC_ROOT)/tools $(PROJ_SRC_ROOT)/examples \
1292 $(PROJ_OBJ_ROOT)/include $(PROJ_OBJ_ROOT)/lib \
1293 $(PROJ_OBJ_ROOT)/tools $(PROJ_OBJ_ROOT)/examples \
1294 -name '*.cpp' -o -name '*.h' | \
1295 $(ETAGS) $(ETAGSFLAGS) -
1298 find $(PROJ_SRC_ROOT)/include $(PROJ_SRC_ROOT)/lib \
1299 $(PROJ_SRC_ROOT)/tools $(PROJ_SRC_ROOT)/examples \
1300 $(PROJ_OBJ_ROOT)/include $(PROJ_OBJ_ROOT)/lib \
1301 $(PROJ_OBJ_ROOT)/tools $(PROJ_OBJ_ROOT)/examples \
1302 \( -name '*.cpp' -o -name '*.h' \) -print | \
1303 ctags -ImtT -o $(PROJ_OBJ_ROOT)/CTAGS -L -
1306 ###############################################################################
1307 # DEPENDENCIES: Include the dependency files if we should
1308 ###############################################################################
1309 ifndef DISABLE_AUTO_DEPENDENCIES
1311 # If its not one of the cleaning targets
1312 ifneq ($strip($(filter-out clean clean-local dist-clean,$(MAKECMDGOALS))),)
1314 # Get the list of dependency files
1315 DependFiles := $(basename $(filter %.cpp %.c %.cc, $(Sources)))
1316 DependFiles := $(patsubst %,$(PROJ_OBJ_DIR)/$(BuildMode)/%.d,$(DependFiles))
1318 -include /dev/null $(DependFiles)
1324 ###############################################################################
1325 # CHECK: Running the test suite
1326 ###############################################################################
1329 $(Verb) if test -d "$(PROJ_OBJ_ROOT)/test" ; then \
1330 if test -f "$(PROJ_OBJ_ROOT)/test/Makefile" ; then \
1331 $(EchoCmd) Running test suite ; \
1332 $(MAKE) -C $(PROJ_OBJ_ROOT)/test check-local \
1333 TESTSUITE=$(TESTSUITE) ; \
1335 $(EchoCmd) No Makefile in test directory ; \
1338 $(EchoCmd) No test directory ; \
1341 ###############################################################################
1342 # DISTRIBUTION: Handle construction of a distribution tarball
1343 ###############################################################################
1345 #------------------------------------------------------------------------
1346 # Define distribution related variables
1347 #------------------------------------------------------------------------
1348 DistName := $(PROJECT_NAME)-$(PROJ_VERSION)
1349 DistDir := $(PROJ_OBJ_ROOT)/$(DistName)
1350 TopDistDir := $(PROJ_OBJ_ROOT)/$(DistName)
1351 DistTarGZip := $(PROJ_OBJ_ROOT)/$(DistName).tar.gz
1352 DistZip := $(PROJ_OBJ_ROOT)/$(DistName).zip
1353 DistTarBZ2 := $(PROJ_OBJ_ROOT)/$(DistName).tar.bz2
1354 DistAlways := CREDITS.TXT LICENSE.TXT README.txt README AUTHORS COPYING \
1355 ChangeLog INSTALL NEWS Makefile Makefile.common Makefile.rules \
1356 Makefile.config.in configure autoconf
1357 DistOther := $(notdir $(wildcard \
1358 $(PROJ_SRC_DIR)/*.h \
1359 $(PROJ_SRC_DIR)/*.td \
1360 $(PROJ_SRC_DIR)/*.def \
1361 $(PROJ_SRC_DIR)/*.ll \
1362 $(PROJ_SRC_DIR)/*.in))
1363 DistSubDirs := $(SubDirs)
1364 DistSources = $(Sources) $(EXTRA_DIST)
1365 DistFiles = $(DistAlways) $(DistSources) $(DistOther)
1367 #------------------------------------------------------------------------
1368 # We MUST build distribution with OBJ_DIR != SRC_DIR
1369 #------------------------------------------------------------------------
1370 ifeq ($(PROJ_SRC_DIR),$(PROJ_OBJ_DIR))
1371 dist dist-check dist-clean dist-gzip dist-bzip2 dist-zip ::
1372 $(Echo) ERROR: Target $@ only available with OBJ_DIR != SRC_DIR
1376 #------------------------------------------------------------------------
1377 # Prevent attempt to run dist targets from anywhere but the top level
1378 #------------------------------------------------------------------------
1380 dist dist-check dist-clean dist-gzip dist-bzip2 dist-zip ::
1381 $(Echo) ERROR: You must run $@ from $(PROJ_OBJ_ROOT)
1384 #------------------------------------------------------------------------
1385 # Provide the top level targets
1386 #------------------------------------------------------------------------
1388 dist-gzip:: $(DistTarGZip)
1390 $(DistTarGZip) : $(TopDistDir)/.makedistdir
1391 $(Echo) Packing gzipped distribution tar file.
1392 $(Verb) cd $(PROJ_OBJ_ROOT) ; $(TAR) chf - "$(DistName)" | \
1393 $(GZIP) -c > "$(DistTarGZip)"
1395 dist-bzip2:: $(DistTarBZ2)
1397 $(DistTarBZ2) : $(TopDistDir)/.makedistdir
1398 $(Echo) Packing bzipped distribution tar file.
1399 $(Verb) cd $(PROJ_OBJ_ROOT) ; $(TAR) chf - $(DistName) | \
1400 $(BZIP2) -c >$(DistTarBZ2)
1402 dist-zip:: $(DistZip)
1404 $(DistZip) : $(TopDistDir)/.makedistdir
1405 $(Echo) Packing zipped distribution file.
1406 $(Verb) rm -f $(DistZip)
1407 $(Verb) cd $(PROJ_OBJ_ROOT) ; $(ZIP) -rq $(DistZip) $(DistName)
1409 dist :: $(DistTarGZip) $(DistTarBZ2) $(DistZip)
1410 $(Echo) ===== DISTRIBUTION PACKAGING SUCESSFUL =====
1412 DistCheckDir := $(PROJ_OBJ_ROOT)/_distcheckdir
1414 dist-check:: $(DistTarGZip)
1415 $(Echo) Checking distribution tar file.
1416 $(Verb) if test -d $(DistCheckDir) ; then \
1417 $(RM) -rf $(DistCheckDir) ; \
1419 $(Verb) $(MKDIR) $(DistCheckDir)
1420 $(Verb) cd $(DistCheckDir) && \
1421 $(MKDIR) $(DistCheckDir)/build && \
1422 $(MKDIR) $(DistCheckDir)/install && \
1423 gunzip -c $(DistTarGZip) | $(TAR) xf - && \
1425 ../$(DistName)/configure --prefix="$(DistCheckDir)/install" \
1426 --srcdir=../$(DistName) $(DIST_CHECK_CONFIG_OPTIONS) && \
1429 $(MAKE) install && \
1430 $(MAKE) uninstall && \
1433 $(MAKE) dist-clean && \
1434 $(EchoCmd) ===== $(DistTarGZip) Ready For Distribution =====
1437 $(Echo) Cleaning distribution files
1438 -$(Verb) $(RM) -rf $(DistTarGZip) $(DistTarBZ2) $(DistZip) $(DistName) \
1443 #------------------------------------------------------------------------
1444 # Provide the recursive distdir target for building the distribution directory
1445 #------------------------------------------------------------------------
1446 distdir: $(DistDir)/.makedistdir
1447 $(DistDir)/.makedistdir: $(DistSources)
1448 $(Verb) if test "$(DistDir)" = "$(TopDistDir)" ; then \
1449 if test -d "$(DistDir)" ; then \
1450 find $(DistDir) -type d ! -perm -200 -exec chmod u+w {} ';' || \
1453 $(EchoCmd) Removing old $(DistDir) ; \
1454 $(RM) -rf $(DistDir); \
1455 $(EchoCmd) Making 'all' to verify build ; \
1458 $(Echo) Building Distribution Directory $(DistDir)
1459 $(Verb) $(MKDIR) $(DistDir)
1460 $(Verb) srcdirstrip=`echo "$(PROJ_SRC_DIR)" | sed 's|.|.|g'`; \
1461 srcrootstrip=`echo "$(PROJ_SRC_ROOT)" | sed 's|.|.|g'`; \
1462 for file in $(DistFiles) ; do \
1464 $(PROJ_SRC_DIR)/*) \
1465 file=`echo "$$file" | sed "s#^$$srcdirstrip/##"` \
1467 $(PROJ_SRC_ROOT)/*) \
1468 file=`echo "$$file" | \
1469 sed "s#^$$srcrootstrip/##"` \
1472 if test -f "$(PROJ_SRC_DIR)/$$file" || \
1473 test -d "$(PROJ_SRC_DIR)/$$file" ; then \
1474 from_dir="$(PROJ_SRC_DIR)" ; \
1475 elif test -f "$$file" || test -d "$$file" ; then \
1478 to_dir=`echo "$$file" | sed -e 's#/[^/]*$$##'` ; \
1479 if test "$$to_dir" != "$$file" && test "$$to_dir" != "."; then \
1480 to_dir="$(DistDir)/$$dir"; \
1481 $(MKDIR) "$$to_dir" ; \
1483 to_dir="$(DistDir)"; \
1485 mid_dir=`echo "$$file" | sed -n -e 's#^\(.*\)/[^/]*$$#\1#p'`; \
1486 if test -n "$$mid_dir" ; then \
1487 $(MKDIR) "$$to_dir/$$mid_dir" || exit 1; \
1489 if test -d "$$from_dir/$$file"; then \
1490 if test -d "$(PROJ_SRC_DIR)/$$file" && \
1491 test "$$from_dir" != "$(PROJ_SRC_DIR)" ; then \
1492 cd $(PROJ_SRC_DIR) ; \
1493 $(TAR) cf - $$file --exclude .svn --exclude CVS | \
1494 ( cd $$to_dir ; $(TAR) xf - ) ; \
1495 cd $(PROJ_OBJ_DIR) ; \
1498 $(TAR) cf - $$file --exclude .svn --exclude CVS | \
1499 ( cd $$to_dir ; $(TAR) xf - ) ; \
1500 cd $(PROJ_OBJ_DIR) ; \
1502 elif test -f "$$from_dir/$$file" ; then \
1503 $(CP) -p "$$from_dir/$$file" "$(DistDir)/$$file" || exit 1; \
1504 elif test -L "$$from_dir/$$file" ; then \
1505 $(CP) -pd "$$from_dir/$$file" $(DistDir)/$$file || exit 1; \
1506 elif echo "$(DistAlways)" | grep -v "$$file" >/dev/null ; then \
1507 $(EchoCmd) "===== WARNING: Distribution Source " \
1508 "$$from_dir/$$file Not Found!" ; \
1509 elif test "$(Verb)" != '@' ; then \
1510 $(EchoCmd) "Skipping non-existent $$from_dir/$$file" ; \
1513 $(Verb) for subdir in $(DistSubDirs) ; do \
1514 if test "$$subdir" \!= "." ; then \
1515 new_distdir="$(DistDir)/$$subdir" ; \
1516 test -d "$$new_distdir" || $(MKDIR) "$$new_distdir" || exit 1; \
1517 ( cd $$subdir && $(MAKE) DistDir="$$new_distdir" distdir ) || \
1521 $(Verb) if test "$(DistDir)" = "$(TopDistDir)" ; then \
1522 $(EchoCmd) Eliminating CVS/.svn directories from distribution ; \
1523 $(RM) -rf `find $(TopDistDir) -type d \( -name CVS -o -name .svn \) -print` ;\
1524 $(MAKE) dist-hook ; \
1525 $(FIND) $(TopDistDir) -type d ! -perm -777 -exec chmod a+rwx {} \; \
1526 -o ! -type d ! -perm -444 -links 1 -exec chmod a+r {} \; \
1527 -o ! -type d ! -perm -400 -exec chmod a+r {} \; \
1528 -o ! -type d ! -perm -444 -exec \
1529 $(SHELL) $(INSTALL_SH) -c -m a+r {} {} \; \
1530 || chmod -R a+r $(DistDir) ; \
1533 # This is invoked by distdir target, define it as a no-op to avoid errors if not
1539 ###############################################################################
1540 # TOP LEVEL - targets only to apply at the top level directory
1541 ###############################################################################
1545 #------------------------------------------------------------------------
1546 # Install support for the project's include files:
1547 #------------------------------------------------------------------------
1549 $(Echo) Installing include files
1550 $(Verb) $(MKDIR) $(PROJ_includedir)
1551 $(Verb) if test -d "$(PROJ_SRC_ROOT)/include" ; then \
1552 cd $(PROJ_SRC_ROOT)/include && \
1553 for hdr in `find . -type f '!' '(' -name '*~' -o -name '.cvsignore' \
1554 -o -name '.#*' -o -name '*.in' ')' -print | grep -v CVS ` ; do \
1555 instdir=`dirname "$(PROJ_includedir)/$$hdr"` ; \
1556 if test \! -d "$$instdir" ; then \
1557 $(EchoCmd) Making install directory $$instdir ; \
1558 $(MKDIR) $$instdir ;\
1560 $(DataInstall) $$hdr $(PROJ_includedir)/$$hdr ; \
1563 $(Verb) if test -d "$(PROJ_OBJ_ROOT)/include" ; then \
1564 cd $(PROJ_OBJ_ROOT)/include && \
1565 for hdr in `find . -type f -print` ; do \
1566 $(DataInstall) $$hdr $(PROJ_includedir)/$$hdr ; \
1571 $(Echo) Uninstalling include files
1572 $(Verb) if [ -d "$(PROJ_SRC_ROOT)/include" ] ; then \
1573 cd $(PROJ_SRC_ROOT)/include && \
1574 $(RM) -f `find . -path '*/Internal' -prune -o '(' -type f \
1575 '!' '(' -name '*~' -o -name '.cvsignore' -o -name '.#*' -o -name '*.in' ')' \
1576 -print ')' | grep -v CVS | sed 's#^#$(PROJ_includedir)/#'` ; \
1577 cd $(PROJ_SRC_ROOT)/include && \
1578 $(RM) -f `find . -path '*/Internal' -prune -o '(' -type f -name '*.in' -print ')' \
1579 | sed 's#\.in$$##;s#^#$(PROJ_includedir)/#'` ; \
1584 #------------------------------------------------------------------------
1585 # Print out the directories used for building
1586 #------------------------------------------------------------------------
1588 $(Echo) "BuildMode : " '$(BuildMode)'
1589 $(Echo) "PROJ_SRC_ROOT: " '$(PROJ_SRC_ROOT)'
1590 $(Echo) "PROJ_SRC_DIR : " '$(PROJ_SRC_DIR)'
1591 $(Echo) "PROJ_OBJ_ROOT: " '$(PROJ_OBJ_ROOT)'
1592 $(Echo) "PROJ_OBJ_DIR : " '$(PROJ_OBJ_DIR)'
1593 $(Echo) "LLVM_SRC_ROOT: " '$(LLVM_SRC_ROOT)'
1594 $(Echo) "LLVM_OBJ_ROOT: " '$(LLVM_OBJ_ROOT)'
1595 $(Echo) "PROJ_prefix : " '$(PROJ_prefix)'
1596 $(Echo) "PROJ_bindir : " '$(PROJ_bindir)'
1597 $(Echo) "PROJ_libdir : " '$(PROJ_libdir)'
1598 $(Echo) "PROJ_etcdir : " '$(PROJ_etcdir)'
1599 $(Echo) "PROJ_includedir : " '$(PROJ_includedir)'
1600 $(Echo) "UserTargets : " '$(UserTargets)'
1601 $(Echo) "ObjMakefiles : " '$(ObjMakefiles)'
1602 $(Echo) "SrcMakefiles : " '$(SrcMakefiles)'
1603 $(Echo) "ObjDir : " '$(ObjDir)'
1604 $(Echo) "LibDir : " '$(LibDir)'
1605 $(Echo) "ToolDir : " '$(ToolDir)'
1606 $(Echo) "ExmplDir : " '$(ExmplDir)'
1607 $(Echo) "Sources : " '$(Sources)'
1608 $(Echo) "TDFiles : " '$(TDFiles)'
1609 $(Echo) "INCFiles : " '$(INCFiles)'
1610 $(Echo) "INCTMPFiles : " '$(INCTMPFiles)'
1611 $(Echo) "PreConditions: " '$(PreConditions)'
1612 $(Echo) "Compile.CXX : " '$(Compile.CXX)'
1613 $(Echo) "Compile.C : " '$(Compile.C)'
1614 $(Echo) "Archive : " '$(Archive)'
1615 $(Echo) "YaccFiles : " '$(YaccFiles)'
1616 $(Echo) "LexFiles : " '$(LexFiles)'
1617 $(Echo) "Module : " '$(Module)'
1618 $(Echo) "FilesToConfig: " '$(FilesToConfigPATH)'