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 Compile.CXX = $(CXX) $(CPP.Flags) $(CompileCommonOpts) $(CXX.Flags) -c
363 LTCompile.CXX = $(LIBTOOL) $(LibTool.Flags) --mode=compile $(Compile.CXX)
364 BCCompile.CXX = $(LLVMGXXWITHPATH) $(CPP.Flags) $(CompileCommonOpts) \
366 Link = $(LIBTOOL) $(LibTool.Flags) --mode=link $(CXX) $(CPP.Flags) \
367 $(CompileCommonOpts) $(LD.Flags) $(Strip)
368 Relink = $(LIBTOOL) $(LibTool.Flags) --mode=link $(CXX) $(CPP.Flags) \
370 LTInstall = $(LIBTOOL) $(LibTool.Flags) --mode=install $(INSTALL) \
372 ProgInstall = $(INSTALL) $(Install.StripFlag) -m 0755
373 DataInstall = $(INSTALL) -m 0644
374 Burg = $(BURG) -I $(PROJ_SRC_DIR)
375 TableGen = $(TBLGEN) -I $(PROJ_SRC_DIR)
376 Archive = $(AR) $(AR.Flags)
377 LArchive = $(LLVMToolDir)/llvm-ar rcsf
384 #----------------------------------------------------------
385 # Get the list of source files and compute object file
387 #----------------------------------------------------------
390 FakeSources := $(FAKE_SOURCES)
392 FakeSources += $(filter %.cpp %.c %.cc %.y %.l,$(BUILT_SOURCES))
394 BaseNameSources := $(sort $(basename $(FakeSources)))
395 ObjectsO := $(BaseNameSources:%=$(ObjDir)/%.o)
396 ObjectsLO := $(BaseNameSources:%=$(ObjDir)/%.lo)
397 ObjectsBC := $(BaseNameSources:%=$(ObjDir)/%.bc)
400 Sources := $(notdir $(wildcard $(PROJ_SRC_DIR)/*.cpp \
401 $(PROJ_SRC_DIR)/*.cc $(PROJ_SRC_DIR)/*.c $(PROJ_SRC_DIR)/*.y \
402 $(PROJ_SRC_DIR)/*.l))
404 Sources := $(SOURCES)
408 Sources += $(filter %.cpp %.c %.cc %.y %.l,$(BUILT_SOURCES))
411 BaseNameSources := $(sort $(basename $(Sources)))
412 ObjectsO := $(BaseNameSources:%=$(ObjDir)/%.o)
413 ObjectsLO := $(BaseNameSources:%=$(ObjDir)/%.lo)
414 ObjectsBC := $(BaseNameSources:%=$(ObjDir)/%.bc)
417 ###############################################################################
418 # DIRECTORIES: Handle recursive descent of directory structure
419 ###############################################################################
421 #---------------------------------------------------------
422 # Provide rules to make install dirs. This must be early
423 # in the file so they get built before dependencies
424 #---------------------------------------------------------
426 $(PROJ_bindir): $(PROJ_bindir)/.dir
427 $(PROJ_libdir): $(PROJ_libdir)/.dir
428 $(PROJ_includedir): $(PROJ_includedir)/.dir
429 $(PROJ_etcdir): $(PROJ_etcdir)/.dir
431 # To create other directories, as needed, and timestamp their creation
433 $(Verb) $(MKDIR) $* > /dev/null
436 .PRECIOUS: $(ObjDir)/.dir $(LibDir)/.dir $(ToolDir)/.dir $(ExmplDir)/.dir
437 .PRECIOUS: $(LLVMLibDir)/.dir $(LLVMToolDir)/.dir $(LLVMExmplDir)/.dir
439 #---------------------------------------------------------
440 # Handle the DIRS options for sequential construction
441 #---------------------------------------------------------
446 $(RecursiveTargets)::
447 $(Verb) for dir in $(DIRS); do \
448 if [ ! -f $$dir/Makefile ]; then \
450 $(CP) $(PROJ_SRC_DIR)/$$dir/Makefile $$dir/Makefile; \
452 if [ ! -f $$dir/LLVM_DO_NOT_BUILD ]; then \
453 ($(MAKE) -C $$dir $@ ) || exit 1; \
458 #---------------------------------------------------------
459 # Handle the EXPERIMENTAL_DIRS options ensuring success
460 # after each directory is built.
461 #---------------------------------------------------------
462 ifdef EXPERIMENTAL_DIRS
463 $(RecursiveTargets)::
464 $(Verb) for dir in $(EXPERIMENTAL_DIRS); do \
465 if [ ! -f $$dir/Makefile ]; then \
467 $(CP) $(PROJ_SRC_DIR)/$$dir/Makefile $$dir/Makefile; \
469 if [ ! -f $$dir/LLVM_DO_NOT_BUILD ]; then \
470 ($(MAKE) -C $$dir $@ ) || exit 0; \
475 #---------------------------------------------------------
476 # Handle the PARALLEL_DIRS options for parallel construction
477 #---------------------------------------------------------
480 SubDirs += $(PARALLEL_DIRS)
482 # Unfortunately, this list must be maintained if new recursive targets are added
483 all :: $(addsuffix /.makeall ,$(PARALLEL_DIRS))
484 clean :: $(addsuffix /.makeclean ,$(PARALLEL_DIRS))
485 clean-all:: $(addsuffix /.makeclean-all,$(PARALLEL_DIRS))
486 install :: $(addsuffix /.makeinstall ,$(PARALLEL_DIRS))
487 uninstall:: $(addsuffix /.makeuninstall,$(PARALLEL_DIRS))
488 install-bytecode :: $(addsuffix /.makeinstall-bytecode,$(PARALLEL_DIRS))
490 ParallelTargets := $(foreach T,$(RecursiveTargets),%/.make$(T))
493 $(Verb) if [ ! -f $(@D)/Makefile ]; then \
495 $(CP) $(PROJ_SRC_DIR)/$(@D)/Makefile $(@D)/Makefile; \
497 if [ ! -f $$dir/LLVM_DO_NOT_BUILD ]; then \
498 $(MAKE) -C $(@D) $(subst $(@D)/.make,,$@) ; \
502 #---------------------------------------------------------
503 # Handle the OPTIONAL_DIRS options for directores that may
505 #---------------------------------------------------------
508 SubDirs += $(OPTIONAL_DIRS)
510 $(RecursiveTargets)::
511 $(Verb) for dir in $(OPTIONAL_DIRS); do \
512 if [ -d $(PROJ_SRC_DIR)/$$dir ]; then\
513 if [ ! -f $$dir/Makefile ]; then \
515 $(CP) $(PROJ_SRC_DIR)/$$dir/Makefile $$dir/Makefile; \
517 if [ ! -f $$dir/LLVM_DO_NOT_BUILD ]; then \
518 ($(MAKE) -C$$dir $@ ) || exit 1; \
524 #---------------------------------------------------------
525 # Handle the CONFIG_FILES options
526 #---------------------------------------------------------
529 install-local:: $(PROJ_etcdir) $(CONFIG_FILES)
530 $(Echo) Installing Configuration Files To $(PROJ_etcdir)
531 $(Verb)for file in $(CONFIG_FILES); do \
532 if test -f $(PROJ_OBJ_DIR)/$${file} ; then \
533 $(DataInstall) $(PROJ_OBJ_DIR)/$${file} $(PROJ_etcdir) ; \
534 elif test -f $(PROJ_SRC_DIR)/$${file} ; then \
535 $(DataInstall) $(PROJ_SRC_DIR)/$${file} $(PROJ_etcdir) ; \
537 $(ECHO) Error: cannot find config file $${file}. ; \
542 $(Echo) Uninstalling Configuration Files From $(PROJ_etcdir)
543 $(Verb)for file in $(CONFIG_FILES); do \
544 $(RM) -f $(PROJ_etcdir)/$${file} ; \
549 ###############################################################################
550 # Set up variables for building libararies
551 ###############################################################################
553 #---------------------------------------------------------
554 # Handle the special "JIT" value for LLVM_LIBS which is a
555 # shorthand for a bunch of libraries that get the correct
556 # JIT support for a library or a tool that runs JIT.
557 #---------------------------------------------------------
558 ifeq ($(LLVMLIBS),JIT)
560 # Make sure we can get our own symbols in the tool
563 # Generic JIT libraries
564 JIT_LIBS := LLVMInterpreter LLVMJIT LLVMCodeGen LLVMExecutionEngine
566 # You can enable the X86 JIT on a non-X86 host by setting the flag
567 # ENABLE_X86_JIT on the make command line. If not, it will still be
568 # enabled automagically on an X86 host.
573 # What the X86 JIT requires
575 JIT_LIBS += LLVMX86 LLVMSelectionDAG
578 # You can enable the SparcV9 JIT on a non-SparcV9 host by setting the flag
579 # ENABLE_SPARCV9_JIT on the make command line. If not, it will still be
580 # enabled automagically on an SparcV9 host.
581 ifeq ($(ARCH), Sparc)
582 ENABLE_SPARCV9_JIT = 1
585 # What the Sparc JIT requires
586 ifdef ENABLE_SPARCV9_JIT
587 JIT_LIBS += LLVMSparcV9 LLVMSparcV9ModuloSched LLVMSparcV9InstrSched \
588 LLVMSparcV9LiveVar LLVMInstrumentation.a LLVMProfilePaths \
589 LLVMBCWriter LLVMTransforms.a LLVMipo.a LLVMipa.a \
590 LLVMDataStructure.a LLVMSparcV9RegAlloc
593 # You can enable the PowerPC JIT on a non-PowerPC host by setting the flag
594 # ENABLE_PPC_JIT on the make command line. If not, it will still be
595 # enabled automagically on an PowerPC host.
596 ifeq ($(ARCH), PowerPC)
600 # What the PowerPC JIT requires
602 JIT_LIBS += LLVMPowerPC LLVMSelectionDAG
605 # You can enable the Alpha JIT on a non-Alpha host by setting the flag
606 # ENABLE_ALPHA_JIT on the make command line. If not, it will still be
607 # enabled automagically on an Alpha host.
608 ifeq ($(ARCH), Alpha)
612 # What the Alpha JIT requires
613 ifdef ENABLE_ALPHA_JIT
614 JIT_LIBS += LLVMAlpha LLVMSelectionDAG
617 LLVMLIBS := $(JIT_LIBS) LLVMScalarOpts LLVMAnalysis.a LLVMTransformUtils.a \
618 LLVMBCReader LLVMCore LLVMSupport.a LLVMTarget.a LLVMbzip2 \
619 LLVMSystem.a $(PLATFORMLIBDL)
622 #---------------------------------------------------------
623 # Define various command line options pertaining to the
624 # libraries needed when linking. There are "Proj" libs
625 # (defined by the user's project) and "LLVM" libs (defined
626 # by the # LLVM project).
627 #---------------------------------------------------------
628 ProjLibsOptions := $(patsubst %.a.o, -l%, $(addsuffix .o, $(USEDLIBS)))
629 ProjLibsOptions := $(patsubst %.o, $(LibDir)/%.o, $(ProjLibsOptions))
630 LLVMLibsOptions := $(patsubst %.a.o, -l%, $(addsuffix .o, $(LLVMLIBS)))
631 LLVMLibsOptions := $(patsubst %.o, $(LLVMLibDir)/%.o, $(LLVMLibsOptions))
632 ProjUsedLibs := $(patsubst %.a.o, lib%.a, $(addsuffix .o, $(USEDLIBS)))
633 LLVMUsedLibs := $(patsubst %.a.o, lib%.a, $(addsuffix .o, $(LLVMLIBS)))
634 ProjLibsPaths := $(addprefix $(LibDir)/,$(ProjUsedLibs))
635 LLVMLibsPaths := $(addprefix $(LLVMLibDir)/,$(LLVMUsedLibs))
637 ###############################################################################
638 # Library Build Rules: Four ways to build a library
639 ###############################################################################
641 #---------------------------------------------------------
642 # Bytecode Module Targets:
643 # If the user set MODULE_NAME then they want to build a
644 # bytecode module from the sources. We compile all the
645 # sources and link it together into a single bytecode
647 #---------------------------------------------------------
650 ifeq ($(strip $(LLVMGCC)),)
651 $(warning Modules require llvm-gcc but no llvm-gcc is available ****)
654 Module := $(LibDir)/$(MODULE_NAME).bc
655 LinkModule := $(LLVMGCCWITHPATH) -shared -nostdlib
657 ifdef EXPORTED_SYMBOL_FILE
658 LinkModule += -Xlinker -internalize-public-api-file=$(EXPORTED_SYMBOL_FILE)
661 $(Module): $(BUILT_SOURCES) $(ObjectsBC) $(LibDir)/.dir $(GCCLD)
662 $(Echo) Building $(BuildMode) Bytecode Module $(notdir $@)
663 $(Verb) $(LinkModule) -o $@ $(ObjectsBC)
665 all-local:: $(Module)
668 ifneq ($(strip $(Module)),)
669 -$(Verb) $(RM) -f $(Module)
672 ifdef BYTECODE_DESTINATION
673 ModuleDestDir := $(BYTECODE_DESTINATION)
675 ModuleDestDir := $(PROJ_libdir)
678 DestModule := $(ModuleDestDir)/$(MODULE_NAME).bc
680 install-module:: $(DestModule)
681 install-local:: $(DestModule)
683 $(DestModule): $(ModuleDestDir) $(Module)
684 $(Echo) Installing $(BuildMode) Bytecode Module $(DestModule)
685 $(Verb) $(DataInstall) $(Module) $(DestModule)
688 $(Echo) Uninstalling $(BuildMode) Bytecode Module $(DestModule)
689 -$(Verb) $(RM) -f $(DestModule)
694 # if we're building a library ...
697 # Make sure there isn't any extranous whitespace on the LIBRARYNAME option
698 LIBRARYNAME := $(strip $(LIBRARYNAME))
699 ifdef LOADABLE_MODULE
700 LibName.LA := $(LibDir)/$(LIBRARYNAME).la
702 LibName.LA := $(LibDir)/lib$(LIBRARYNAME).la
704 LibName.A := $(LibDir)/lib$(LIBRARYNAME).a
705 LibName.O := $(LibDir)/$(LIBRARYNAME).o
706 LibName.BCA:= $(LibDir)/lib$(LIBRARYNAME).bca
708 #---------------------------------------------------------
709 # Shared Library Targets:
710 # If the user asked for a shared library to be built
711 # with the SHARED_LIBRARY variable, then we provide
712 # targets for building them.
713 #---------------------------------------------------------
716 all-local:: $(LibName.LA)
718 ifdef LINK_LIBS_IN_SHARED
719 $(LibName.LA): $(ObjectsLO) $(LibDir)/.dir
720 $(Echo) Linking $(BuildMode) Shared Library $(LIBRARYNAME)$(SHLIBEXT)
721 $(Verb) $(Link) -o $@ $(ObjectsLO) \
722 $(ProjLibsOptions) $(LLVMLibsOptions)
723 $(Verb) $(LTInstall) $@ $(LibDir)
725 $(LibName.LA): $(ObjectsLO) $(LibDir)/.dir
726 $(Echo) Linking $(BuildMode) Shared Library $(LIBRARYNAME)$(SHLIBEXT)
727 $(Verb) $(Link) -o $@ $(ObjectsLO)
728 $(Verb) $(LTInstall) $@ $(LibDir)
732 ifneq ($(strip $(LibName.LA)),)
733 -$(Verb) $(RM) -f $(LibName.LA)
736 DestSharedLib = $(PROJ_libdir)/lib$(LIBRARYNAME)$(SHLIBEXT)
738 install-local:: $(DestSharedLib)
740 $(DestSharedLib): $(PROJ_libdir) $(LibName.LA)
741 $(Echo) Installing $(BuildMode) Shared Library $(DestSharedLib)
742 $(Verb) $(LTInstall) $(LibName.LA) $(DestSharedLib)
743 $(Verb) $(LIBTOOL) --finish $(PROJ_libdir)
746 $(Echo) Uninstalling $(BuildMode) Shared Library $(DestSharedLib)
747 -$(Verb) $(RM) -f $(PROJ_libdir)/lib$(LIBRARYNAME).*
751 #---------------------------------------------------------
752 # Bytecode Library Targets:
753 # If the user asked for a bytecode library to be built
754 # with the BYTECODE_LIBRARY variable, then we provide
755 # targets for building them.
756 #---------------------------------------------------------
757 ifdef BYTECODE_LIBRARY
758 ifeq ($(strip $(LLVMGCC)),)
759 $(warning Bytecode libraries require llvm-gcc which could not be found ****)
762 # make the C and C++ compilers strip debug info out of bytecode libraries.
763 BCCompile.C += -Wa,-strip-debug
764 BCCompile.CXX += -Wa,-strip-debug
766 all-local:: $(LibName.BCA)
768 ifdef EXPORTED_SYMBOL_FILE
769 BCLinkLib = $(LLVMGCCWITHPATH) -shared -nostdlib -Xlinker \
770 -internalize-public-api-file=$(EXPORTED_SYMBOL_FILE)
772 $(LibName.BCA): $(ObjectsBC) $(LibDir)/.dir $(GCCLD) \
773 $(LLVMToolDir)/llvm-ar
774 $(Echo) Building $(BuildMode) Bytecode Archive $(notdir $@) \
776 $(Verb) $(BCLinkLib) -o $(ObjDir)/$(LIBRARYNAME).o $(ObjectsBC)
778 $(Verb) $(LArchive) $@ $(ObjDir)/$(LIBRARYNAME).o
780 $(LibName.BCA): $(ObjectsBC) $(LibDir)/.dir \
781 $(LLVMToolDir)/llvm-ar
782 $(Echo) Building $(BuildMode) Bytecode Archive $(notdir $@)
784 $(Verb) $(LArchive) $@ $(ObjectsBC)
789 ifneq ($(strip $(LibName.BCA)),)
790 -$(Verb) $(RM) -f $(LibName.BCA)
793 ifdef BYTECODE_DESTINATION
794 BytecodeDestDir := $(BYTECODE_DESTINATION)
796 BytecodeDestDir := $(PROJ_libdir)
799 DestBytecodeLib = $(BytecodeDestDir)/lib$(LIBRARYNAME).a
801 install-bytecode-local:: $(DestBytecodeLib)
803 install-local:: $(DestBytecodeLib)
805 $(DestBytecodeLib): $(BytecodeDestDir) $(LibName.BCA)
806 $(Echo) Installing $(BuildMode) Bytecode Archive $(DestBytecodeLib)
807 $(Verb) $(DataInstall) $(LibName.BCA) $(DestBytecodeLib)
810 $(Echo) Uninstalling $(BuildMode) Bytecode Archive $(DestBytecodeLib)
811 -$(Verb) $(RM) -f $(DestBytecodeLib)
816 #---------------------------------------------------------
817 # ReLinked Library Targets:
818 # If the user didn't explicitly forbid building a
819 # relinked then we provide targets for building them.
820 #---------------------------------------------------------
821 ifndef DONT_BUILD_RELINKED
823 all-local:: $(LibName.O)
825 $(LibName.O): $(ObjectsO) $(LibDir)/.dir
826 $(Echo) Linking $(BuildMode) Object Library $(notdir $@)
827 $(Verb) $(Relink) -o $@ $(ObjectsO)
830 ifneq ($(strip $(LibName.O)),)
831 -$(Verb) $(RM) -f $(LibName.O)
834 DestRelinkedLib = $(PROJ_libdir)/$(LIBRARYNAME).o
836 install-local:: $(DestRelinkedLib)
838 $(DestRelinkedLib): $(PROJ_libdir) $(LibName.O)
839 $(Echo) Installing $(BuildMode) Object Library $(DestRelinkedLib)
840 $(Verb) $(LTInstall) $(LibName.O) $(DestRelinkedLib)
843 $(Echo) Uninstalling $(BuildMode) Object Library $(DestRelinkedLib)
844 -$(Verb) $(RM) -f $(DestRelinkedLib)
848 #---------------------------------------------------------
849 # Archive Library Targets:
850 # If the user wanted a regular archive library built,
851 # then we provide targets for building them.
852 #---------------------------------------------------------
855 all-local:: $(LibName.A)
857 $(LibName.A): $(ObjectsO) $(LibDir)/.dir
858 $(Echo) Building $(BuildMode) Archive Library $(notdir $@)
860 $(Verb) $(Archive) $@ $(ObjectsO)
864 ifneq ($(strip $(LibName.A)),)
865 -$(Verb) $(RM) -f $(LibName.A)
868 DestArchiveLib := $(PROJ_libdir)/lib$(LIBRARYNAME).a
870 install-local:: $(DestArchiveLib)
872 $(DestArchiveLib): $(PROJ_libdir) $(LibName.A)
873 $(Echo) Installing $(BuildMode) Archive Library $(DestArchiveLib)
874 $(Verb) $(MKDIR) $(PROJ_libdir)
875 $(Verb) $(LTInstall) $(LibName.A) $(DestArchiveLib)
878 $(Echo) Uninstalling $(BuildMode) Archive Library $(DestArchiveLib)
879 -$(Verb) $(RM) -f $(DestArchiveLib)
886 ###############################################################################
887 # Tool Build Rules: Build executable tool based on TOOLNAME option
888 ###############################################################################
892 #---------------------------------------------------------
893 # Set up variables for building a tool.
894 #---------------------------------------------------------
896 ToolBuildPath := $(ExmplDir)/$(strip $(TOOLNAME))$(EXEEXT)
898 ToolBuildPath := $(ToolDir)/$(strip $(TOOLNAME))$(EXEEXT)
901 #---------------------------------------------------------
902 # Tell make that we need to rebuild subdirectories before
903 # we can link the tool. This affects things like LLI which
904 # has library subdirectories.
905 #---------------------------------------------------------
906 $(ToolBuildPath): $(addsuffix /.makeall, $(PARALLEL_DIRS))
908 #---------------------------------------------------------
909 # Provide targets for building the tools
910 #---------------------------------------------------------
911 all-local:: $(ToolBuildPath)
914 ifneq ($(strip $(ToolBuildPath)),)
915 -$(Verb) $(RM) -f $(ToolBuildPath)
919 $(ToolBuildPath): $(ExmplDir)/.dir
921 $(ToolBuildPath): $(ToolDir)/.dir
924 $(ToolBuildPath): $(ObjectsO) $(ProjLibsPaths) $(LLVMLibsPaths)
925 $(Echo) Linking $(BuildMode) executable $(TOOLNAME) $(StripWarnMsg)
926 $(Verb) $(Link) -o $@ $(TOOLLINKOPTS) $(ObjectsO) $(ProjLibsOptions) \
927 $(LLVMLibsOptions) $(ExtraLibs) $(TOOLLINKOPTSB) $(LIBS)
928 $(Echo) ======= Finished Linking $(BuildMode) Executable $(TOOLNAME) $(StripWarnMsg)
930 DestTool = $(PROJ_bindir)/$(TOOLNAME)
932 install-local:: $(DestTool)
934 $(DestTool): $(PROJ_bindir) $(ToolBuildPath)
935 $(Echo) Installing $(BuildMode) $(DestTool)
936 $(Verb) $(ProgInstall) $(ToolBuildPath) $(DestTool)
939 $(Echo) Uninstalling $(BuildMode) $(DestTool)
940 -$(Verb) $(RM) -f $(DestTool)
944 ###############################################################################
945 # Object Build Rules: Build object files based on sources
946 ###############################################################################
948 # Provide rule sets for when dependency generation is enabled
949 ifndef DISABLE_AUTO_DEPENDENCIES
951 #---------------------------------------------------------
952 # Create .lo files in the ObjDir directory from the .cpp and .c files...
953 #---------------------------------------------------------
956 $(ObjDir)/%.lo $(ObjDir)/%.o: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES)
957 $(Echo) "Compiling $*.cpp for $(BuildMode) build (PIC)"
958 $(Verb) if $(LTCompile.CXX) -MD -MT $@ -MP -MF $(ObjDir)/$*.LACXXd $< -o $@ ; \
959 then $(MV) -f "$(ObjDir)/$*.LACXXd" "$(ObjDir)/$*.d"; \
960 else $(RM) -f "$(ObjDir)/$*.LACXXd"; exit 1; fi
962 $(ObjDir)/%.lo $(ObjDir)/%.o: %.cc $(ObjDir)/.dir $(BUILT_SOURCES)
963 $(Echo) "Compiling $*.cc for $(BuildMode) build (PIC)"
964 $(Verb) if $(LTCompile.CXX) -MD -MT $@ -MP -MF $(ObjDir)/$*.LACXXd $< -o $@ ; \
965 then $(MV) -f "$(ObjDir)/$*.LACXXd" "$(ObjDir)/$*.d"; \
966 else $(RM) -f "$(ObjDir)/$*.LACXXd"; exit 1; fi
968 $(ObjDir)/%.lo $(ObjDir)/%.o: %.c $(ObjDir)/.dir $(BUILT_SOURCES)
969 $(Echo) "Compiling $*.c for $(BuildMode) build (PIC)"
970 $(Verb) if $(LTCompile.C) -MD -MT $@ -MP -MF $(ObjDir)/$*.LACd $< -o $@ ; \
971 then $(MV) -f "$(ObjDir)/$*.LACd" "$(ObjDir)/$*.d"; \
972 else $(RM) -f "$(ObjDir)/$*.LACd"; exit 1; fi
974 #---------------------------------------------------------
975 # Create .o files in the ObjDir directory from the .cpp and .c files...
976 #---------------------------------------------------------
979 $(ObjDir)/%.o: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES)
980 $(Echo) "Compiling $*.cpp for $(BuildMode) build"
981 $(Verb) if $(Compile.CXX) -MD -MT $@ -MP -MF $(ObjDir)/$*.CXXd $< -o $@ ; \
982 then $(MV) -f "$(ObjDir)/$*.CXXd" "$(ObjDir)/$*.d"; \
983 else $(RM) -f "$(ObjDir)/$*.CXXd"; exit 1; fi
985 $(ObjDir)/%.o: %.cc $(ObjDir)/.dir $(BUILT_SOURCES)
986 $(Echo) "Compiling $*.cc for $(BuildMode) build"
987 $(Verb) if $(Compile.CXX) -MD -MT $@ -MP -MF $(ObjDir)/$*.CXXd $< -o $@ ; \
988 then $(MV) -f "$(ObjDir)/$*.CXXd" "$(ObjDir)/$*.d"; \
989 else $(RM) -f "$(ObjDir)/$*.CXXd"; exit 1; fi
991 $(ObjDir)/%.o: %.c $(ObjDir)/.dir $(BUILT_SOURCES)
992 $(Echo) "Compiling $*.c for $(BuildMode) build"
993 $(Verb) if $(Compile.C) -MD -MT $@ -MP -MF $(ObjDir)/$*.Cd $< -o $@ ; \
994 then $(MV) -f "$(ObjDir)/$*.Cd" "$(ObjDir)/$*.d"; \
995 else $(RM) -f "$(ObjDir)/$*.Cd"; exit 1; fi
999 #---------------------------------------------------------
1000 # Create .bc files in the ObjDir directory from .cpp .cc and .c files...
1001 #---------------------------------------------------------
1002 $(ObjDir)/%.bc: %.cpp $(ObjDir)/.dir $(GCCAS) $(BUILT_SOURCES)
1003 $(Echo) "Compiling $*.cpp for $(BuildMode) build (bytecode)"
1004 $(Verb) if $(BCCompile.CXX) -MD -MT $@ -MP -MF "$(ObjDir)/$*.BCCXXd" $< -o $@ ; \
1005 then $(MV) -f "$(ObjDir)/$*.BCCXXd" "$(ObjDir)/$*.d"; \
1006 else $(RM) -f "$(ObjDir)/$*.BCCXXd"; exit 1; fi
1008 $(ObjDir)/%.bc: %.cc $(ObjDir)/.dir $(GCCAS) $(BUILT_SOURCES)
1009 $(Echo) "Compiling $*.cc for $(BuildMode) build (bytecode)"
1010 $(Verb) if $(BCCompile.CXX) -MD -MT $@ -MP -MF "$(ObjDir)/$*.BCCXXd" $< -o $@ ; \
1011 then $(MV) -f "$(ObjDir)/$*.BCCXXd" "$(ObjDir)/$*.d"; \
1012 else $(RM) -f "$(ObjDir)/$*.BCCXXd"; exit 1; fi
1014 $(ObjDir)/%.bc: %.c $(ObjDir)/.dir $(GCCAS) $(BUILT_SOURCES)
1015 $(Echo) "Compiling $*.c for $(BuildMode) build (bytecode)"
1016 $(Verb) if $(BCCompile.C) -MD -MT $@ -MP -MF "$(ObjDir)/$*.BCCd" $< -o $@ ; \
1017 then $(MV) -f "$(ObjDir)/$*.BCCd" "$(ObjDir)/$*.d"; \
1018 else $(RM) -f "$(ObjDir)/$*.BCCd"; exit 1; fi
1020 # Provide alternate rule sets if dependencies are disabled
1023 ifdef SHARED_LIBRARY
1025 $(ObjDir)/%.lo $(ObjDir)/%.o: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES)
1026 $(Echo) "Compiling $*.cpp for $(BuildMode) build (PIC)"
1027 $(LTCompile.CXX) $< -o $@
1029 $(ObjDir)/%.lo $(ObjDir)/%.o: %.cc $(ObjDir)/.dir $(BUILT_SOURCES)
1030 $(Echo) "Compiling $*.cc for $(BuildMode) build (PIC)"
1031 $(LTCompile.CXX) $< -o $@
1033 $(ObjDir)/%.lo $(ObjDir)/%.o: %.c $(ObjDir)/.dir $(BUILT_SOURCES)
1034 $(Echo) "Compiling $*.c for $(BuildMode) build (PIC)"
1035 $(LTCompile.C) $< -o $@
1039 $(ObjDir)/%.o: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES)
1040 $(Echo) "Compiling $*.cpp for $(BuildMode) build"
1041 $(Compile.CXX) $< -o $@
1043 $(ObjDir)/%.o: %.cc $(ObjDir)/.dir $(BUILT_SOURCES)
1044 $(Echo) "Compiling $*.cc for $(BuildMode) build"
1045 $(Compile.CXX) $< -o $@
1047 $(ObjDir)/%.o: %.c $(ObjDir)/.dir $(BUILT_SOURCES)
1048 $(Echo) "Compiling $*.c for $(BuildMode) build"
1049 $(Compile.C) $< -o $@
1052 $(ObjDir)/%.bc: %.cpp $(ObjDir)/.dir $(GCCAS) $(BUILT_SOURCES)
1053 $(Echo) "Compiling $*.cpp for $(BuildMode) build (bytecode)"
1054 $(BCCompile.CXX) $< -o $@
1056 $(ObjDir)/%.bc: %.cc $(ObjDir)/.dir $(GCCAS) $(BUILT_SOURCES)
1057 $(Echo) "Compiling $*.cc for $(BuildMode) build (bytecode)"
1058 $(BCCompile.CXX) $< -o $@
1060 $(ObjDir)/%.bc: %.c $(ObjDir)/.dir $(GCCAS) $(BUILT_SOURCES)
1061 $(Echo) "Compiling $*.c for $(BuildMode) build (bytecode)"
1062 $(BCCompile.C) $< -o $@
1066 #---------------------------------------------------------
1067 # Provide rule to build .bc files from .ll sources,
1068 # regardless of dependencies
1069 #---------------------------------------------------------
1070 $(ObjDir)/%.bc: %.ll $(ObjDir)/.dir $(LLVMAS)
1071 $(Echo) "Compiling $*.ll for $(BuildMode) build"
1072 $(Verb) $(LLVMAS) $< -f -o $@
1074 ###############################################################################
1075 # TABLEGEN: Provide rules for running tblgen to produce *.inc files
1076 ###############################################################################
1080 TDFiles := $(strip $(wildcard $(PROJ_SRC_DIR)/*.td) $(LLVM_SRC_ROOT)/lib/Target/Target.td)
1081 INCFiles := $(filter %.inc,$(BUILT_SOURCES))
1082 INCTMPFiles := $(INCFiles:%=$(ObjDir)/%.tmp)
1083 .PRECIOUS: $(INCTMPFiles) $(INCFiles)
1085 # All of these files depend on tblgen and the .td files.
1086 $(INCTMPFiles) : $(TBLGEN) $(TDFiles)
1088 # INCFiles rule: All of the tblgen generated files are emitted to
1089 # $(ObjDir)/%.inc.tmp, instead of emitting them directly to %.inc. This allows
1090 # us to only "touch" the real file if the contents of it change. IOW, if
1091 # tblgen is modified, all of the .inc.tmp files are regereated, but no
1092 # dependencies of the .inc files are, unless the contents of the .inc file
1094 $(INCFiles) : %.inc : $(ObjDir)/%.inc.tmp
1095 $(Verb) $(CMP) -s $@ $< || $(CP) $< $@
1097 $(TARGET:%=$(ObjDir)/%GenRegisterNames.inc.tmp): \
1098 $(ObjDir)/%GenRegisterNames.inc.tmp : %.td $(ObjDir)/.dir
1099 $(Echo) "Building $(<F) register names with tblgen"
1100 $(Verb) $(TableGen) -gen-register-enums -o $@ $<
1102 $(TARGET:%=$(ObjDir)/%GenRegisterInfo.h.inc.tmp): \
1103 $(ObjDir)/%GenRegisterInfo.h.inc.tmp : %.td $(ObjDir)/.dir
1104 $(Echo) "Building $(<F) register information header with tblgen"
1105 $(Verb) $(TableGen) -gen-register-desc-header -o $@ $<
1107 $(TARGET:%=$(ObjDir)/%GenRegisterInfo.inc.tmp): \
1108 $(ObjDir)/%GenRegisterInfo.inc.tmp : %.td $(ObjDir)/.dir
1109 $(Echo) "Building $(<F) register info implementation with tblgen"
1110 $(Verb) $(TableGen) -gen-register-desc -o $@ $<
1112 $(TARGET:%=$(ObjDir)/%GenInstrNames.inc.tmp): \
1113 $(ObjDir)/%GenInstrNames.inc.tmp : %.td $(ObjDir)/.dir
1114 $(Echo) "Building $(<F) instruction names with tblgen"
1115 $(Verb) $(TableGen) -gen-instr-enums -o $@ $<
1117 $(TARGET:%=$(ObjDir)/%GenInstrInfo.inc.tmp): \
1118 $(ObjDir)/%GenInstrInfo.inc.tmp : %.td $(ObjDir)/.dir
1119 $(Echo) "Building $(<F) instruction information with tblgen"
1120 $(Verb) $(TableGen) -gen-instr-desc -o $@ $<
1122 $(TARGET:%=$(ObjDir)/%GenAsmWriter.inc.tmp): \
1123 $(ObjDir)/%GenAsmWriter.inc.tmp : %.td $(ObjDir)/.dir
1124 $(Echo) "Building $(<F) assembly writer with tblgen"
1125 $(Verb) $(TableGen) -gen-asm-writer -o $@ $<
1127 $(TARGET:%=$(ObjDir)/%GenAsmWriter1.inc.tmp): \
1128 $(ObjDir)/%GenAsmWriter1.inc.tmp : %.td $(ObjDir)/.dir
1129 $(Echo) "Building $(<F) assembly writer #1 with tblgen"
1130 $(Verb) $(TableGen) -gen-asm-writer -asmwriternum=1 -o $@ $<
1132 $(TARGET:%=$(ObjDir)/%GenCodeEmitter.inc.tmp): \
1133 $(ObjDir)/%GenCodeEmitter.inc.tmp: %.td $(ObjDir)/.dir
1134 $(Echo) "Building $(<F) code emitter with tblgen"
1135 $(Verb) $(TableGen) -gen-emitter -o $@ $<
1138 -$(Verb) $(RM) -f $(INCFiles)
1142 ###############################################################################
1143 # LEX AND YACC: Provide rules for generating sources with lex and yacc
1144 ###############################################################################
1146 #---------------------------------------------------------
1147 # Provide rules for generating a .cpp source file from
1148 # (f)lex input sources.
1149 #---------------------------------------------------------
1151 LexFiles := $(filter %.l,$(Sources))
1153 ifneq ($(LexFiles),)
1155 LexOutput := $(strip $(patsubst %.l,%.cpp,$(LexFiles)))
1157 .PRECIOUS: $(LexOutput)
1159 # Note the extra sed filtering here, used to cut down on the warnings emited
1160 # by GCC. The last line is a gross hack to work around flex aparently not
1161 # being able to resize the buffer on a large token input. Currently, for
1162 # uninitialized string buffers in LLVM we can generate very long tokens, so
1163 # this is a hack around it.
1164 # FIXME. (f.e. char Buffer[10000] )
1166 $(Echo) Flexing $*.l
1167 $(Verb) $(FLEX) -t $< | \
1168 $(SED) 's/void yyunput/inline void yyunput/' | \
1169 $(SED) 's/void \*yy_flex_realloc/inline void *yy_flex_realloc/' | \
1170 $(SED) 's/#define YY_BUF_SIZE 16384/#define YY_BUF_SIZE (16384*64)/' \
1174 -$(Verb) $(RM) -f $(LexOutput)
1175 $(Verb) $(RM) -f $(LexOutput)
1179 #---------------------------------------------------------
1180 # Provide rules for generating a .cpp and .h source files
1181 # from yacc (bison) input sources.
1182 #---------------------------------------------------------
1184 YaccFiles := $(filter %.y,$(Sources))
1185 ifneq ($(YaccFiles),)
1186 YaccOutput := $(addprefix $(patsubst %.y,%,$(YaccFiles)),.h .cpp .output)
1188 .PRECIOUS: $(YaccOutput)
1190 # Cancel built-in rules for yacc
1195 # Rule for building the bison parsers...
1197 $(Echo) "Bisoning $*.y"
1198 $(Verb) $(BISON) -v -d -p $(<F:%Parser.y=%) -o $*.tab.c $<
1199 $(Verb) $(MV) -f $*.tab.c $*.cpp
1200 $(Verb) $(MV) -f $*.tab.h $*.h
1203 -$(Verb) $(RM) -f $(YaccOutput)
1204 $(Verb) $(RM) -f $(YaccOutput)
1207 ###############################################################################
1208 # OTHER RULES: Other rules needed
1209 ###############################################################################
1211 # To create postscript files from dot files...
1212 ifneq ($(DOT),false)
1214 $(DOT) -Tps < $< > $@
1217 $(Echo) "Cannot build $@: The program dot is not installed"
1220 # This rules ensures that header files that are removed still have a rule for
1221 # which they can be "generated." This allows make to ignore them and
1222 # reproduce the dependency lists.
1226 # Define clean-local to clean the current directory. Note that this uses a
1227 # very conservative approach ensuring that empty variables do not cause
1228 # errors or disastrous removal.
1230 ifneq ($(strip $(ObjDir)),)
1231 -$(Verb) $(RM) -rf $(ObjDir)
1233 -$(Verb) $(RM) -f core core.[0-9][0-9]* *.o *.d *~ *.flc
1234 ifneq ($(strip $(SHLIBEXT)),) # Extra paranoia - make real sure SHLIBEXT is set
1235 -$(Verb) $(RM) -f *$(SHLIBEXT)
1239 -$(Verb) $(RM) -rf Debug Release Profile
1241 # Build tags database for Emacs/Xemacs:
1245 find $(PROJ_SRC_ROOT)/include $(PROJ_SRC_ROOT)/lib \
1246 $(PROJ_SRC_ROOT)/tools $(PROJ_SRC_ROOT)/examples \
1247 $(PROJ_OBJ_ROOT)/include $(PROJ_OBJ_ROOT)/lib \
1248 $(PROJ_OBJ_ROOT)/tools $(PROJ_OBJ_ROOT)/examples \
1249 -name '*.cpp' -o -name '*.h' | \
1250 $(ETAGS) $(ETAGSFLAGS) -
1253 find $(PROJ_SRC_ROOT)/include $(PROJ_SRC_ROOT)/lib \
1254 $(PROJ_SRC_ROOT)/tools $(PROJ_SRC_ROOT)/examples \
1255 $(PROJ_OBJ_ROOT)/include $(PROJ_OBJ_ROOT)/lib \
1256 $(PROJ_OBJ_ROOT)/tools $(PROJ_OBJ_ROOT)/examples \
1257 \( -name '*.cpp' -o -name '*.h' \) -print | \
1258 ctags -ImtT -o $(PROJ_OBJ_ROOT)/CTAGS -L -
1261 ###############################################################################
1262 # DEPENDENCIES: Include the dependency files if we should
1263 ###############################################################################
1264 ifndef DISABLE_AUTO_DEPENDENCIES
1266 # If its not one of the cleaning targets
1267 ifneq ($strip($(filter-out clean clean-local dist-clean,$(MAKECMDGOALS))),)
1269 # Get the list of dependency files
1270 DependFiles := $(basename $(filter %.cpp %.c %.cc, $(Sources)))
1271 DependFiles := $(patsubst %,$(PROJ_OBJ_DIR)/$(BuildMode)/%.d,$(DependFiles))
1273 -include /dev/null $(DependFiles)
1279 ###############################################################################
1280 # CHECK: Running the test suite
1281 ###############################################################################
1284 $(Verb) if test -d "$(PROJ_OBJ_ROOT)/test" ; then \
1285 if test -f "$(PROJ_OBJ_ROOT)/test/Makefile" ; then \
1286 $(EchoCmd) Running test suite ; \
1287 $(MAKE) -C $(PROJ_OBJ_ROOT)/test check-local \
1288 TESTSUITE=$(TESTSUITE) ; \
1290 $(EchoCmd) No Makefile in test directory ; \
1293 $(EchoCmd) No test directory ; \
1296 ###############################################################################
1297 # DISTRIBUTION: Handle construction of a distribution tarball
1298 ###############################################################################
1300 #------------------------------------------------------------------------
1301 # Define distribution related variables
1302 #------------------------------------------------------------------------
1303 DistName := $(PROJECT_NAME)-$(PROJ_VERSION)
1304 DistDir := $(PROJ_OBJ_ROOT)/$(DistName)
1305 TopDistDir := $(PROJ_OBJ_ROOT)/$(DistName)
1306 DistTarGZip := $(PROJ_OBJ_ROOT)/$(DistName).tar.gz
1307 DistZip := $(PROJ_OBJ_ROOT)/$(DistName).zip
1308 DistTarBZ2 := $(PROJ_OBJ_ROOT)/$(DistName).tar.bz2
1309 DistAlways := CREDITS.TXT LICENSE.TXT README.txt README AUTHORS COPYING \
1310 ChangeLog INSTALL NEWS Makefile Makefile.common Makefile.rules \
1311 Makefile.config.in configure autoconf
1312 DistOther := $(notdir $(wildcard \
1313 $(PROJ_SRC_DIR)/*.h \
1314 $(PROJ_SRC_DIR)/*.td \
1315 $(PROJ_SRC_DIR)/*.def \
1316 $(PROJ_SRC_DIR)/*.ll \
1317 $(PROJ_SRC_DIR)/*.in))
1318 DistSubDirs := $(SubDirs)
1319 DistSources = $(Sources) $(EXTRA_DIST)
1320 DistFiles = $(DistAlways) $(DistSources) $(DistOther)
1322 #------------------------------------------------------------------------
1323 # We MUST build distribution with OBJ_DIR != SRC_DIR
1324 #------------------------------------------------------------------------
1325 ifeq ($(PROJ_SRC_DIR),$(PROJ_OBJ_DIR))
1326 dist dist-check dist-clean dist-gzip dist-bzip2 dist-zip ::
1327 $(Echo) ERROR: Target $@ only available with OBJ_DIR != SRC_DIR
1331 #------------------------------------------------------------------------
1332 # Prevent attempt to run dist targets from anywhere but the top level
1333 #------------------------------------------------------------------------
1335 dist dist-check dist-clean dist-gzip dist-bzip2 dist-zip ::
1336 $(Echo) ERROR: You must run $@ from $(PROJ_OBJ_ROOT)
1339 #------------------------------------------------------------------------
1340 # Provide the top level targets
1341 #------------------------------------------------------------------------
1343 dist-gzip:: $(DistTarGZip)
1345 $(DistTarGZip) : $(TopDistDir)/.makedistdir
1346 $(Echo) Packing gzipped distribution tar file.
1347 $(Verb) cd $(PROJ_OBJ_ROOT) ; $(TAR) chf - "$(DistName)" | \
1348 $(GZIP) -c > "$(DistTarGZip)"
1350 dist-bzip2:: $(DistTarBZ2)
1352 $(DistTarBZ2) : $(TopDistDir)/.makedistdir
1353 $(Echo) Packing bzipped distribution tar file.
1354 $(Verb) cd $(PROJ_OBJ_ROOT) ; $(TAR) chf - $(DistName) | \
1355 $(BZIP2) -c >$(DistTarBZ2)
1357 dist-zip:: $(DistZip)
1359 $(DistZip) : $(TopDistDir)/.makedistdir
1360 $(Echo) Packing zipped distribution file.
1361 $(Verb) rm -f $(DistZip)
1362 $(Verb) cd $(PROJ_OBJ_ROOT) ; $(ZIP) -rq $(DistZip) $(DistName)
1364 dist :: $(DistTarGZip) $(DistTarBZ2) $(DistZip)
1365 $(Echo) ===== DISTRIBUTION PACKAGING SUCESSFUL =====
1367 DistCheckDir := $(PROJ_OBJ_ROOT)/_distcheckdir
1369 dist-check:: $(DistTarGZip)
1370 $(Echo) Checking distribution tar file.
1371 $(Verb) if test -d $(DistCheckDir) ; then \
1372 $(RM) -rf $(DistCheckDir) ; \
1374 $(Verb) $(MKDIR) $(DistCheckDir)
1375 $(Verb) cd $(DistCheckDir) && \
1376 $(MKDIR) $(DistCheckDir)/build && \
1377 $(MKDIR) $(DistCheckDir)/install && \
1378 gunzip -c $(DistTarGZip) | $(TAR) xf - && \
1380 ../$(DistName)/configure --prefix="$(DistCheckDir)/install" \
1381 --srcdir=../$(DistName) $(DIST_CHECK_CONFIG_OPTIONS) && \
1384 $(MAKE) install && \
1385 $(MAKE) uninstall && \
1388 $(MAKE) dist-clean && \
1389 $(EchoCmd) ===== $(DistTarGZip) Ready For Distribution =====
1392 $(Echo) Cleaning distribution files
1393 -$(Verb) $(RM) -rf $(DistTarGZip) $(DistTarBZ2) $(DistZip) $(DistName) \
1398 #------------------------------------------------------------------------
1399 # Provide the recursive distdir target for building the distribution directory
1400 #------------------------------------------------------------------------
1401 distdir: $(DistDir)/.makedistdir
1402 $(DistDir)/.makedistdir: $(DistSources)
1403 $(Verb) if test "$(DistDir)" = "$(TopDistDir)" ; then \
1404 if test -d "$(DistDir)" ; then \
1405 find $(DistDir) -type d ! -perm -200 -exec chmod u+w {} ';' || \
1408 $(EchoCmd) Removing old $(DistDir) ; \
1409 $(RM) -rf $(DistDir); \
1410 $(EchoCmd) Making 'all' to verify build ; \
1413 $(Echo) Building Distribution Directory $(DistDir)
1414 $(Verb) $(MKDIR) $(DistDir)
1415 $(Verb) srcdirstrip=`echo "$(PROJ_SRC_DIR)" | sed 's|.|.|g'`; \
1416 srcrootstrip=`echo "$(PROJ_SRC_ROOT)" | sed 's|.|.|g'`; \
1417 for file in $(DistFiles) ; do \
1419 $(PROJ_SRC_DIR)/*) \
1420 file=`echo "$$file" | sed "s#^$$srcdirstrip/##"` \
1422 $(PROJ_SRC_ROOT)/*) \
1423 file=`echo "$$file" | \
1424 sed "s#^$$srcrootstrip/##"` \
1427 if test -f "$(PROJ_SRC_DIR)/$$file" || \
1428 test -d "$(PROJ_SRC_DIR)/$$file" ; then \
1429 from_dir="$(PROJ_SRC_DIR)" ; \
1430 elif test -f "$$file" || test -d "$$file" ; then \
1433 to_dir=`echo "$$file" | sed -e 's#/[^/]*$$##'` ; \
1434 if test "$$to_dir" != "$$file" && test "$$to_dir" != "."; then \
1435 to_dir="$(DistDir)/$$dir"; \
1436 $(MKDIR) "$$to_dir" ; \
1438 to_dir="$(DistDir)"; \
1440 mid_dir=`echo "$$file" | sed -n -e 's#^\(.*\)/[^/]*$$#\1#p'`; \
1441 if test -n "$$mid_dir" ; then \
1442 $(MKDIR) "$$to_dir/$$mid_dir" || exit 1; \
1444 if test -d "$$from_dir/$$file"; then \
1445 if test -d "$(PROJ_SRC_DIR)/$$file" && \
1446 test "$$from_dir" != "$(PROJ_SRC_DIR)" ; then \
1447 cd $(PROJ_SRC_DIR) ; \
1448 $(TAR) cf - $$file --exclude .svn --exclude CVS | \
1449 ( cd $$to_dir ; $(TAR) xf - ) ; \
1450 cd $(PROJ_OBJ_DIR) ; \
1453 $(TAR) cf - $$file --exclude .svn --exclude CVS | \
1454 ( cd $$to_dir ; $(TAR) xf - ) ; \
1455 cd $(PROJ_OBJ_DIR) ; \
1457 elif test -f "$$from_dir/$$file" ; then \
1458 $(CP) -p "$$from_dir/$$file" "$(DistDir)/$$file" || exit 1; \
1459 elif test -L "$$from_dir/$$file" ; then \
1460 $(CP) -pd "$$from_dir/$$file" $(DistDir)/$$file || exit 1; \
1461 elif echo "$(DistAlways)" | grep -v "$$file" >/dev/null ; then \
1462 $(EchoCmd) "===== WARNING: Distribution Source " \
1463 "$$from_dir/$$file Not Found!" ; \
1464 elif test "$(Verb)" != '@' ; then \
1465 $(EchoCmd) "Skipping non-existent $$from_dir/$$file" ; \
1468 $(Verb) for subdir in $(DistSubDirs) ; do \
1469 if test "$$subdir" \!= "." ; then \
1470 new_distdir="$(DistDir)/$$subdir" ; \
1471 test -d "$$new_distdir" || $(MKDIR) "$$new_distdir" || exit 1; \
1472 ( cd $$subdir && $(MAKE) DistDir="$$new_distdir" distdir ) || \
1476 $(Verb) if test "$(DistDir)" = "$(TopDistDir)" ; then \
1477 $(EchoCmd) Eliminating CVS/.svn directories from distribution ; \
1478 $(RM) -rf `find $(TopDistDir) -type d \( -name CVS -o -name .svn \) -print` ;\
1479 $(MAKE) dist-hook ; \
1480 $(FIND) $(TopDistDir) -type d ! -perm -777 -exec chmod a+rwx {} \; \
1481 -o ! -type d ! -perm -444 -links 1 -exec chmod a+r {} \; \
1482 -o ! -type d ! -perm -400 -exec chmod a+r {} \; \
1483 -o ! -type d ! -perm -444 -exec \
1484 $(SHELL) $(INSTALL_SH) -c -m a+r {} {} \; \
1485 || chmod -R a+r $(DistDir) ; \
1488 # This is invoked by distdir target, define it as a no-op to avoid errors if not
1494 ###############################################################################
1495 # TOP LEVEL - targets only to apply at the top level directory
1496 ###############################################################################
1500 #------------------------------------------------------------------------
1501 # Install support for the project's include files:
1502 #------------------------------------------------------------------------
1504 $(Echo) Installing include files
1505 $(Verb) $(MKDIR) $(PROJ_includedir)
1506 $(Verb) if test -d "$(PROJ_SRC_ROOT)/include" ; then \
1507 cd $(PROJ_SRC_ROOT)/include && \
1508 for hdr in `find . -type f '!' '(' -name '*~' -o -name '.cvsignore' \
1509 -o -name '.#*' -o -name '*.in' ')' -print | grep -v CVS ` ; do \
1510 instdir=`dirname "$(PROJ_includedir)/$$hdr"` ; \
1511 if test \! -d "$$instdir" ; then \
1512 $(EchoCmd) Making install directory $$instdir ; \
1513 $(MKDIR) $$instdir ;\
1515 $(DataInstall) $$hdr $(PROJ_includedir)/$$hdr ; \
1518 $(Verb) if test -d "$(PROJ_OBJ_ROOT)/include" ; then \
1519 cd $(PROJ_OBJ_ROOT)/include && \
1520 for hdr in `find . -type f -print` ; do \
1521 $(DataInstall) $$hdr $(PROJ_includedir)/$$hdr ; \
1526 $(Echo) Uninstalling include files
1527 $(Verb) if [ -d "$(PROJ_SRC_ROOT)/include" ] ; then \
1528 cd $(PROJ_SRC_ROOT)/include && \
1529 $(RM) -f `find . -path '*/Internal' -prune -o '(' -type f \
1530 '!' '(' -name '*~' -o -name '.cvsignore' -o -name '.#*' -o -name '*.in' ')' \
1531 -print ')' | grep -v CVS | sed 's#^#$(PROJ_includedir)/#'` ; \
1532 cd $(PROJ_SRC_ROOT)/include && \
1533 $(RM) -f `find . -path '*/Internal' -prune -o '(' -type f -name '*.in' -print ')' \
1534 | sed 's#\.in$$##;s#^#$(PROJ_includedir)/#'` ; \
1539 #------------------------------------------------------------------------
1540 # Print out the directories used for building
1541 #------------------------------------------------------------------------
1543 $(Echo) "BuildMode : " '$(BuildMode)'
1544 $(Echo) "PROJ_SRC_ROOT: " '$(PROJ_SRC_ROOT)'
1545 $(Echo) "PROJ_SRC_DIR : " '$(PROJ_SRC_DIR)'
1546 $(Echo) "PROJ_OBJ_ROOT: " '$(PROJ_OBJ_ROOT)'
1547 $(Echo) "PROJ_OBJ_DIR : " '$(PROJ_OBJ_DIR)'
1548 $(Echo) "LLVM_SRC_ROOT: " '$(LLVM_SRC_ROOT)'
1549 $(Echo) "LLVM_OBJ_ROOT: " '$(LLVM_OBJ_ROOT)'
1550 $(Echo) "PROJ_prefix : " '$(PROJ_prefix)'
1551 $(Echo) "PROJ_bindir : " '$(PROJ_bindir)'
1552 $(Echo) "PROJ_libdir : " '$(PROJ_libdir)'
1553 $(Echo) "PROJ_etcdir : " '$(PROJ_etcdir)'
1554 $(Echo) "PROJ_includedir : " '$(PROJ_includedir)'
1555 $(Echo) "UserTargets : " '$(UserTargets)'
1556 $(Echo) "ObjMakefiles : " '$(ObjMakefiles)'
1557 $(Echo) "SrcMakefiles : " '$(SrcMakefiles)'
1558 $(Echo) "ObjDir : " '$(ObjDir)'
1559 $(Echo) "LibDir : " '$(LibDir)'
1560 $(Echo) "ToolDir : " '$(ToolDir)'
1561 $(Echo) "ExmplDir : " '$(ExmplDir)'
1562 $(Echo) "Sources : " '$(Sources)'
1563 $(Echo) "TDFiles : " '$(TDFiles)'
1564 $(Echo) "INCFiles : " '$(INCFiles)'
1565 $(Echo) "INCTMPFiles : " '$(INCTMPFiles)'
1566 $(Echo) "PreConditions: " '$(PreConditions)'
1567 $(Echo) "Compile.CXX : " '$(Compile.CXX)'
1568 $(Echo) "Compile.C : " '$(Compile.C)'
1569 $(Echo) "Archive : " '$(Archive)'
1570 $(Echo) "YaccFiles : " '$(YaccFiles)'
1571 $(Echo) "LexFiles : " '$(LexFiles)'
1572 $(Echo) "Module : " '$(Module)'