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 #---------------------------------------------------------
427 $(Verb) $(MKDIR) $(PROJ_bindir)
430 $(Verb) $(MKDIR) $(PROJ_libdir)
433 $(Verb) $(MKDIR) $(PROJ_includedir)
436 $(Verb) $(MKDIR) $(PROJ_etcdir)
438 # To create other directories, as needed, and timestamp their creation
440 $(Verb) $(MKDIR) $* > /dev/null
443 .PRECIOUS: $(ObjDir)/.dir $(LibDir)/.dir $(ToolDir)/.dir $(ExmplDir)/.dir
444 .PRECIOUS: $(LLVMLibDir)/.dir $(LLVMToolDir)/.dir $(LLVMExmplDir)/.dir
446 #---------------------------------------------------------
447 # Handle the DIRS options for sequential construction
448 #---------------------------------------------------------
453 $(RecursiveTargets)::
454 $(Verb) for dir in $(DIRS); do \
455 if [ ! -f $$dir/Makefile ]; then \
457 $(CP) $(PROJ_SRC_DIR)/$$dir/Makefile $$dir/Makefile; \
459 if [ ! -f $$dir/LLVM_DO_NOT_BUILD ]; then \
460 ($(MAKE) -C $$dir $@ ) || exit 1; \
465 #---------------------------------------------------------
466 # Handle the EXPERIMENTAL_DIRS options ensuring success
467 # after each directory is built.
468 #---------------------------------------------------------
469 ifdef EXPERIMENTAL_DIRS
470 $(RecursiveTargets)::
471 $(Verb) for dir in $(EXPERIMENTAL_DIRS); do \
472 if [ ! -f $$dir/Makefile ]; then \
474 $(CP) $(PROJ_SRC_DIR)/$$dir/Makefile $$dir/Makefile; \
476 if [ ! -f $$dir/LLVM_DO_NOT_BUILD ]; then \
477 ($(MAKE) -C $$dir $@ ) || exit 0; \
482 #---------------------------------------------------------
483 # Handle the PARALLEL_DIRS options for parallel construction
484 #---------------------------------------------------------
487 SubDirs += $(PARALLEL_DIRS)
489 # Unfortunately, this list must be maintained if new recursive targets are added
490 all :: $(addsuffix /.makeall ,$(PARALLEL_DIRS))
491 clean :: $(addsuffix /.makeclean ,$(PARALLEL_DIRS))
492 clean-all:: $(addsuffix /.makeclean-all,$(PARALLEL_DIRS))
493 install :: $(addsuffix /.makeinstall ,$(PARALLEL_DIRS))
494 uninstall:: $(addsuffix /.makeuninstall,$(PARALLEL_DIRS))
495 install-bytecode :: $(addsuffix /.makeinstall-bytecode,$(PARALLEL_DIRS))
497 ParallelTargets := $(foreach T,$(RecursiveTargets),%/.make$(T))
500 $(Verb) if [ ! -f $(@D)/Makefile ]; then \
502 $(CP) $(PROJ_SRC_DIR)/$(@D)/Makefile $(@D)/Makefile; \
504 if [ ! -f $$dir/LLVM_DO_NOT_BUILD ]; then \
505 $(MAKE) -C $(@D) $(subst $(@D)/.make,,$@) ; \
509 #---------------------------------------------------------
510 # Handle the OPTIONAL_DIRS options for directores that may
512 #---------------------------------------------------------
515 SubDirs += $(OPTIONAL_DIRS)
517 $(RecursiveTargets)::
518 $(Verb) for dir in $(OPTIONAL_DIRS); do \
519 if [ -d $(PROJ_SRC_DIR)/$$dir ]; then\
520 if [ ! -f $$dir/Makefile ]; then \
522 $(CP) $(PROJ_SRC_DIR)/$$dir/Makefile $$dir/Makefile; \
524 if [ ! -f $$dir/LLVM_DO_NOT_BUILD ]; then \
525 ($(MAKE) -C$$dir $@ ) || exit 1; \
531 #---------------------------------------------------------
532 # Handle the CONFIG_FILES options
533 #---------------------------------------------------------
536 install-local:: $(PROJ_etcdir) $(CONFIG_FILES)
537 $(Echo) Installing Configuration Files To $(PROJ_etcdir)
538 $(Verb)for file in $(CONFIG_FILES); do \
539 if test -f $(PROJ_OBJ_DIR)/$${file} ; then \
540 $(DataInstall) $(PROJ_OBJ_DIR)/$${file} $(PROJ_etcdir) ; \
541 elif test -f $(PROJ_SRC_DIR)/$${file} ; then \
542 $(DataInstall) $(PROJ_SRC_DIR)/$${file} $(PROJ_etcdir) ; \
544 $(ECHO) Error: cannot find config file $${file}. ; \
549 $(Echo) Uninstalling Configuration Files From $(PROJ_etcdir)
550 $(Verb)for file in $(CONFIG_FILES); do \
551 $(RM) -f $(PROJ_etcdir)/$${file} ; \
556 ###############################################################################
557 # Set up variables for building libararies
558 ###############################################################################
560 #---------------------------------------------------------
561 # Handle the special "JIT" value for LLVM_LIBS which is a
562 # shorthand for a bunch of libraries that get the correct
563 # JIT support for a library or a tool that runs JIT.
564 #---------------------------------------------------------
565 ifeq ($(LLVMLIBS),JIT)
567 # Make sure we can get our own symbols in the tool
570 # Generic JIT libraries
571 JIT_LIBS := LLVMInterpreter LLVMJIT LLVMCodeGen LLVMExecutionEngine
573 # You can enable the X86 JIT on a non-X86 host by setting the flag
574 # ENABLE_X86_JIT on the make command line. If not, it will still be
575 # enabled automagically on an X86 host.
580 # What the X86 JIT requires
582 JIT_LIBS += LLVMX86 LLVMSelectionDAG
585 # You can enable the SparcV9 JIT on a non-SparcV9 host by setting the flag
586 # ENABLE_SPARCV9_JIT on the make command line. If not, it will still be
587 # enabled automagically on an SparcV9 host.
588 ifeq ($(ARCH), Sparc)
589 ENABLE_SPARCV9_JIT = 1
592 # What the Sparc JIT requires
593 ifdef ENABLE_SPARCV9_JIT
594 JIT_LIBS += LLVMSparcV9 LLVMSparcV9ModuloSched LLVMSparcV9InstrSched \
595 LLVMSparcV9LiveVar LLVMInstrumentation.a LLVMProfilePaths \
596 LLVMBCWriter LLVMTransforms.a LLVMipo.a LLVMipa.a \
597 LLVMDataStructure.a LLVMSparcV9RegAlloc
600 # You can enable the PowerPC JIT on a non-PowerPC host by setting the flag
601 # ENABLE_PPC_JIT on the make command line. If not, it will still be
602 # enabled automagically on an PowerPC host.
603 ifeq ($(ARCH), PowerPC)
607 # What the PowerPC JIT requires
609 JIT_LIBS += LLVMPowerPC LLVMSelectionDAG
612 LLVMLIBS := $(JIT_LIBS) LLVMScalarOpts LLVMAnalysis.a LLVMTransformUtils.a \
613 LLVMBCReader LLVMCore LLVMSupport.a LLVMTarget.a LLVMbzip2 \
614 LLVMSystem.a $(PLATFORMLIBDL)
617 #---------------------------------------------------------
618 # Define various command line options pertaining to the
619 # libraries needed when linking. There are "Proj" libs
620 # (defined by the user's project) and "LLVM" libs (defined
621 # by the # LLVM project).
622 #---------------------------------------------------------
623 ProjLibsOptions := $(patsubst %.a.o, -l%, $(addsuffix .o, $(USEDLIBS)))
624 ProjLibsOptions := $(patsubst %.o, $(LibDir)/%.o, $(ProjLibsOptions))
625 LLVMLibsOptions := $(patsubst %.a.o, -l%, $(addsuffix .o, $(LLVMLIBS)))
626 LLVMLibsOptions := $(patsubst %.o, $(LLVMLibDir)/%.o, $(LLVMLibsOptions))
627 ProjUsedLibs := $(patsubst %.a.o, lib%.a, $(addsuffix .o, $(USEDLIBS)))
628 LLVMUsedLibs := $(patsubst %.a.o, lib%.a, $(addsuffix .o, $(LLVMLIBS)))
629 ProjLibsPaths := $(addprefix $(LibDir)/,$(ProjUsedLibs))
630 LLVMLibsPaths := $(addprefix $(LLVMLibDir)/,$(LLVMUsedLibs))
632 ###############################################################################
633 # Library Build Rules: Four ways to build a library
634 ###############################################################################
636 #---------------------------------------------------------
637 # Bytecode Module Targets:
638 # If the user set MODULE_NAME then they want to build a
639 # bytecode module from the sources. We compile all the
640 # sources and link it together into a single bytecode
642 #---------------------------------------------------------
645 ifeq ($(strip $(LLVMGCC)),)
646 $(warning Modules require llvm-gcc but no llvm-gcc is available ****)
649 Module := $(LibDir)/$(MODULE_NAME).bc
650 LinkModule := $(LLVMGCCWITHPATH) -shared -nostdlib
652 ifdef EXPORTED_SYMBOL_FILE
653 LinkModule += -Xlinker -internalize-public-api-file=$(EXPORTED_SYMBOL_FILE)
656 $(Module): $(BUILT_SOURCES) $(ObjectsBC) $(LibDir)/.dir $(GCCLD)
657 $(Echo) Building $(BuildMode) Bytecode Module $(notdir $@)
658 $(Verb) $(LinkModule) -o $@ $(ObjectsBC)
660 all-local:: $(Module)
663 ifneq ($(strip $(Module)),)
664 -$(Verb) $(RM) -f $(Module)
667 ifdef BYTECODE_DESTINATION
668 ModuleDestDir := $(BYTECODE_DESTINATION)
670 ModuleDestDir := $(PROJ_libdir)
673 DestModule := $(ModuleDestDir)/$(MODULE_NAME).bc
675 install-module:: $(DestModule)
676 install-local:: $(DestModule)
678 $(DestModule): $(ModuleDestDir) $(Module)
679 $(Echo) Installing $(BuildMode) Bytecode Module $(DestModule)
680 $(Verb) $(DataInstall) $(Module) $(DestModule)
683 $(Echo) Uninstalling $(BuildMode) Bytecode Module $(DestModule)
684 -$(Verb) $(RM) -f $(DestModule)
689 # if we're building a library ...
692 # Make sure there isn't any extranous whitespace on the LIBRARYNAME option
693 LIBRARYNAME := $(strip $(LIBRARYNAME))
694 ifdef LOADABLE_MODULE
695 LibName.LA := $(LibDir)/$(LIBRARYNAME).la
697 LibName.LA := $(LibDir)/lib$(LIBRARYNAME).la
699 LibName.A := $(LibDir)/lib$(LIBRARYNAME).a
700 LibName.O := $(LibDir)/$(LIBRARYNAME).o
701 LibName.BCA:= $(LibDir)/lib$(LIBRARYNAME).bca
703 #---------------------------------------------------------
704 # Shared Library Targets:
705 # If the user asked for a shared library to be built
706 # with the SHARED_LIBRARY variable, then we provide
707 # targets for building them.
708 #---------------------------------------------------------
711 all-local:: $(LibName.LA)
713 ifdef LINK_LIBS_IN_SHARED
714 $(LibName.LA): $(ObjectsLO) $(LibDir)/.dir
715 $(Echo) Linking $(BuildMode) Shared Library $(LIBRARYNAME)$(SHLIBEXT)
716 $(Verb) $(Link) -o $@ $(ObjectsLO) \
717 $(ProjLibsOptions) $(LLVMLibsOptions)
718 $(Verb) $(LTInstall) $@ $(LibDir)
720 $(LibName.LA): $(ObjectsLO) $(LibDir)/.dir
721 $(Echo) Linking $(BuildMode) Shared Library $(LIBRARYNAME)$(SHLIBEXT)
722 $(Verb) $(Link) -o $@ $(ObjectsLO)
723 $(Verb) $(LTInstall) $@ $(LibDir)
727 ifneq ($(strip $(LibName.LA)),)
728 -$(Verb) $(RM) -f $(LibName.LA)
731 DestSharedLib = $(PROJ_libdir)/lib$(LIBRARYNAME)$(SHLIBEXT)
733 install-local:: $(DestSharedLib)
735 $(DestSharedLib): $(PROJ_libdir) $(LibName.LA)
736 $(Echo) Installing $(BuildMode) Shared Library $(DestSharedLib)
737 $(Verb) $(LTInstall) $(LibName.LA) $(DestSharedLib)
738 $(Verb) $(LIBTOOL) --finish $(PROJ_libdir)
741 $(Echo) Uninstalling $(BuildMode) Shared Library $(DestSharedLib)
742 -$(Verb) $(RM) -f $(PROJ_libdir)/lib$(LIBRARYNAME).*
746 #---------------------------------------------------------
747 # Bytecode Library Targets:
748 # If the user asked for a bytecode library to be built
749 # with the BYTECODE_LIBRARY variable, then we provide
750 # targets for building them.
751 #---------------------------------------------------------
752 ifdef BYTECODE_LIBRARY
753 ifeq ($(strip $(LLVMGCC)),)
754 $(warning Bytecode libraries require llvm-gcc which could not be found ****)
757 # make the C and C++ compilers strip debug info out of bytecode libraries.
758 BCCompile.C += -Wa,-strip-debug
759 BCCompile.CXX += -Wa,-strip-debug
761 all-local:: $(LibName.BCA)
763 ifdef EXPORTED_SYMBOL_FILE
764 BCLinkLib = $(LLVMGCCWITHPATH) -shared -nostdlib -Xlinker \
765 -internalize-public-api-file=$(EXPORTED_SYMBOL_FILE)
767 $(LibName.BCA): $(ObjectsBC) $(LibDir)/.dir $(GCCLD) \
768 $(LLVMToolDir)/llvm-ar
769 $(Echo) Building $(BuildMode) Bytecode Archive $(notdir $@) \
771 $(Verb) $(BCLinkLib) -o $(ObjDir)/$(LIBRARYNAME).o $(ObjectsBC)
773 $(Verb) $(LArchive) $@ $(ObjDir)/$(LIBRARYNAME).o
775 $(LibName.BCA): $(ObjectsBC) $(LibDir)/.dir \
776 $(LLVMToolDir)/llvm-ar
777 $(Echo) Building $(BuildMode) Bytecode Archive $(notdir $@)
779 $(Verb) $(LArchive) $@ $(ObjectsBC)
784 ifneq ($(strip $(LibName.BCA)),)
785 -$(Verb) $(RM) -f $(LibName.BCA)
788 ifdef BYTECODE_DESTINATION
789 BytecodeDestDir := $(BYTECODE_DESTINATION)
791 BytecodeDestDir := $(PROJ_libdir)
794 DestBytecodeLib = $(BytecodeDestDir)/lib$(LIBRARYNAME).a
796 install-bytecode-local:: $(DestBytecodeLib)
798 install-local:: $(DestBytecodeLib)
800 $(DestBytecodeLib): $(BytecodeDestDir) $(LibName.BCA)
801 $(Echo) Installing $(BuildMode) Bytecode Archive $(DestBytecodeLib)
802 $(Verb) $(DataInstall) $(LibName.BCA) $(DestBytecodeLib)
805 $(Echo) Uninstalling $(BuildMode) Bytecode Archive $(DestBytecodeLib)
806 -$(Verb) $(RM) -f $(DestBytecodeLib)
811 #---------------------------------------------------------
812 # ReLinked Library Targets:
813 # If the user didn't explicitly forbid building a
814 # relinked then we provide targets for building them.
815 #---------------------------------------------------------
816 ifndef DONT_BUILD_RELINKED
818 all-local:: $(LibName.O)
820 $(LibName.O): $(ObjectsO) $(LibDir)/.dir
821 $(Echo) Linking $(BuildMode) Object Library $(notdir $@)
822 $(Verb) $(Relink) -o $@ $(ObjectsO)
825 ifneq ($(strip $(LibName.O)),)
826 -$(Verb) $(RM) -f $(LibName.O)
829 DestRelinkedLib = $(PROJ_libdir)/$(LIBRARYNAME).o
831 install-local:: $(DestRelinkedLib)
833 $(DestRelinkedLib): $(PROJ_libdir) $(LibName.O)
834 $(Echo) Installing $(BuildMode) Object Library $(DestRelinkedLib)
835 $(Verb) $(LTInstall) $(LibName.O) $(DestRelinkedLib)
838 $(Echo) Uninstalling $(BuildMode) Object Library $(DestRelinkedLib)
839 -$(Verb) $(RM) -f $(DestRelinkedLib)
843 #---------------------------------------------------------
844 # Archive Library Targets:
845 # If the user wanted a regular archive library built,
846 # then we provide targets for building them.
847 #---------------------------------------------------------
850 all-local:: $(LibName.A)
852 $(LibName.A): $(ObjectsO) $(LibDir)/.dir
853 $(Echo) Building $(BuildMode) Archive Library $(notdir $@)
855 $(Verb) $(Archive) $@ $(ObjectsO)
859 ifneq ($(strip $(LibName.A)),)
860 -$(Verb) $(RM) -f $(LibName.A)
863 DestArchiveLib := $(PROJ_libdir)/lib$(LIBRARYNAME).a
865 install-local:: $(DestArchiveLib)
867 $(DestArchiveLib): $(PROJ_libdir) $(LibName.A)
868 $(Echo) Installing $(BuildMode) Archive Library $(DestArchiveLib)
869 $(Verb) $(MKDIR) $(PROJ_libdir)
870 $(Verb) $(LTInstall) $(LibName.A) $(DestArchiveLib)
873 $(Echo) Uninstalling $(BuildMode) Archive Library $(DestArchiveLib)
874 -$(Verb) $(RM) -f $(DestArchiveLib)
881 ###############################################################################
882 # Tool Build Rules: Build executable tool based on TOOLNAME option
883 ###############################################################################
887 #---------------------------------------------------------
888 # Set up variables for building a tool.
889 #---------------------------------------------------------
891 ToolBuildPath := $(ExmplDir)/$(TOOLNAME)$(EXEEXT)
893 ToolBuildPath := $(ToolDir)/$(TOOLNAME)$(EXEEXT)
896 #---------------------------------------------------------
897 # Tell make that we need to rebuild subdirectories before
898 # we can link the tool. This affects things like LLI which
899 # has library subdirectories.
900 #---------------------------------------------------------
901 $(ToolBuildPath): $(addsuffix /.makeall, $(PARALLEL_DIRS))
903 #---------------------------------------------------------
904 # Provide targets for building the tools
905 #---------------------------------------------------------
906 all-local:: $(ToolBuildPath)
909 ifneq ($(strip $(ToolBuildPath)),)
910 -$(Verb) $(RM) -f $(ToolBuildPath)
914 $(ToolBuildPath): $(ExmplDir)/.dir
916 $(ToolBuildPath): $(ToolDir)/.dir
919 $(ToolBuildPath): $(ObjectsO) $(ProjLibsPaths) $(LLVMLibsPaths)
920 $(Echo) Linking $(BuildMode) executable $(TOOLNAME) $(StripWarnMsg)
921 $(Verb) $(Link) -o $@ $(TOOLLINKOPTS) $(ObjectsO) $(ProjLibsOptions) \
922 $(LLVMLibsOptions) $(ExtraLibs) $(TOOLLINKOPTSB) $(LIBS)
923 $(Echo) ======= Finished Linking $(BuildMode) Executable $(TOOLNAME) $(StripWarnMsg)
925 DestTool = $(PROJ_bindir)/$(TOOLNAME)
927 install-local:: $(DestTool)
929 $(DestTool): $(PROJ_bindir) $(ToolBuildPath)
930 $(Echo) Installing $(BuildMode) $(DestTool)
931 $(Verb) $(ProgInstall) $(ToolBuildPath) $(DestTool)
934 $(Echo) Uninstalling $(BuildMode) $(DestTool)
935 -$(Verb) $(RM) -f $(DestTool)
939 ###############################################################################
940 # Object Build Rules: Build object files based on sources
941 ###############################################################################
943 # Provide rule sets for when dependency generation is enabled
944 ifndef DISABLE_AUTO_DEPENDENCIES
946 #---------------------------------------------------------
947 # Create .lo files in the ObjDir directory from the .cpp and .c files...
948 #---------------------------------------------------------
951 $(ObjDir)/%.lo $(ObjDir)/%.o: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES)
952 $(Echo) "Compiling $*.cpp for $(BuildMode) build (PIC)"
953 $(Verb) if $(LTCompile.CXX) -MD -MT $@ -MP -MF $(ObjDir)/$*.LACXXd $< -o $@ ; \
954 then $(MV) -f "$(ObjDir)/$*.LACXXd" "$(ObjDir)/$*.d"; \
955 else $(RM) -f "$(ObjDir)/$*.LACXXd"; exit 1; fi
957 $(ObjDir)/%.lo $(ObjDir)/%.o: %.cc $(ObjDir)/.dir $(BUILT_SOURCES)
958 $(Echo) "Compiling $*.cc for $(BuildMode) build (PIC)"
959 $(Verb) if $(LTCompile.CXX) -MD -MT $@ -MP -MF $(ObjDir)/$*.LACXXd $< -o $@ ; \
960 then $(MV) -f "$(ObjDir)/$*.LACXXd" "$(ObjDir)/$*.d"; \
961 else $(RM) -f "$(ObjDir)/$*.LACXXd"; exit 1; fi
963 $(ObjDir)/%.lo $(ObjDir)/%.o: %.c $(ObjDir)/.dir $(BUILT_SOURCES)
964 $(Echo) "Compiling $*.c for $(BuildMode) build (PIC)"
965 $(Verb) if $(LTCompile.C) -MD -MT $@ -MP -MF $(ObjDir)/$*.LACd $< -o $@ ; \
966 then $(MV) -f "$(ObjDir)/$*.LACd" "$(ObjDir)/$*.d"; \
967 else $(RM) -f "$(ObjDir)/$*.LACd"; exit 1; fi
969 #---------------------------------------------------------
970 # Create .o files in the ObjDir directory from the .cpp and .c files...
971 #---------------------------------------------------------
974 $(ObjDir)/%.o: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES)
975 $(Echo) "Compiling $*.cpp for $(BuildMode) build"
976 $(Verb) if $(Compile.CXX) -MD -MT $@ -MP -MF $(ObjDir)/$*.CXXd $< -o $@ ; \
977 then $(MV) -f "$(ObjDir)/$*.CXXd" "$(ObjDir)/$*.d"; \
978 else $(RM) -f "$(ObjDir)/$*.CXXd"; exit 1; fi
980 $(ObjDir)/%.o: %.cc $(ObjDir)/.dir $(BUILT_SOURCES)
981 $(Echo) "Compiling $*.cc for $(BuildMode) build"
982 $(Verb) if $(Compile.CXX) -MD -MT $@ -MP -MF $(ObjDir)/$*.CXXd $< -o $@ ; \
983 then $(MV) -f "$(ObjDir)/$*.CXXd" "$(ObjDir)/$*.d"; \
984 else $(RM) -f "$(ObjDir)/$*.CXXd"; exit 1; fi
986 $(ObjDir)/%.o: %.c $(ObjDir)/.dir $(BUILT_SOURCES)
987 $(Echo) "Compiling $*.c for $(BuildMode) build"
988 $(Verb) if $(Compile.C) -MD -MT $@ -MP -MF $(ObjDir)/$*.Cd $< -o $@ ; \
989 then $(MV) -f "$(ObjDir)/$*.Cd" "$(ObjDir)/$*.d"; \
990 else $(RM) -f "$(ObjDir)/$*.Cd"; exit 1; fi
994 #---------------------------------------------------------
995 # Create .bc files in the ObjDir directory from .cpp .cc and .c files...
996 #---------------------------------------------------------
997 $(ObjDir)/%.bc: %.cpp $(ObjDir)/.dir $(GCCAS) $(BUILT_SOURCES)
998 $(Echo) "Compiling $*.cpp for $(BuildMode) build (bytecode)"
999 $(Verb) if $(BCCompile.CXX) -MD -MT $@ -MP -MF "$(ObjDir)/$*.BCCXXd" $< -o $@ ; \
1000 then $(MV) -f "$(ObjDir)/$*.BCCXXd" "$(ObjDir)/$*.d"; \
1001 else $(RM) -f "$(ObjDir)/$*.BCCXXd"; exit 1; fi
1003 $(ObjDir)/%.bc: %.cc $(ObjDir)/.dir $(GCCAS) $(BUILT_SOURCES)
1004 $(Echo) "Compiling $*.cc for $(BuildMode) build (bytecode)"
1005 $(Verb) if $(BCCompile.CXX) -MD -MT $@ -MP -MF "$(ObjDir)/$*.BCCXXd" $< -o $@ ; \
1006 then $(MV) -f "$(ObjDir)/$*.BCCXXd" "$(ObjDir)/$*.d"; \
1007 else $(RM) -f "$(ObjDir)/$*.BCCXXd"; exit 1; fi
1009 $(ObjDir)/%.bc: %.c $(ObjDir)/.dir $(GCCAS) $(BUILT_SOURCES)
1010 $(Echo) "Compiling $*.c for $(BuildMode) build (bytecode)"
1011 $(Verb) if $(BCCompile.C) -MD -MT $@ -MP -MF "$(ObjDir)/$*.BCCd" $< -o $@ ; \
1012 then $(MV) -f "$(ObjDir)/$*.BCCd" "$(ObjDir)/$*.d"; \
1013 else $(RM) -f "$(ObjDir)/$*.BCCd"; exit 1; fi
1015 # Provide alternate rule sets if dependencies are disabled
1018 ifdef SHARED_LIBRARY
1020 $(ObjDir)/%.lo $(ObjDir)/%.o: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES)
1021 $(Echo) "Compiling $*.cpp for $(BuildMode) build (PIC)"
1022 $(LTCompile.CXX) $< -o $@
1024 $(ObjDir)/%.lo $(ObjDir)/%.o: %.cc $(ObjDir)/.dir $(BUILT_SOURCES)
1025 $(Echo) "Compiling $*.cc for $(BuildMode) build (PIC)"
1026 $(LTCompile.CXX) $< -o $@
1028 $(ObjDir)/%.lo $(ObjDir)/%.o: %.c $(ObjDir)/.dir $(BUILT_SOURCES)
1029 $(Echo) "Compiling $*.c for $(BuildMode) build (PIC)"
1030 $(LTCompile.C) $< -o $@
1034 $(ObjDir)/%.o: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES)
1035 $(Echo) "Compiling $*.cpp for $(BuildMode) build"
1036 $(Compile.CXX) $< -o $@
1038 $(ObjDir)/%.o: %.cc $(ObjDir)/.dir $(BUILT_SOURCES)
1039 $(Echo) "Compiling $*.cc for $(BuildMode) build"
1040 $(Compile.CXX) $< -o $@
1042 $(ObjDir)/%.o: %.c $(ObjDir)/.dir $(BUILT_SOURCES)
1043 $(Echo) "Compiling $*.c for $(BuildMode) build"
1044 $(Compile.C) $< -o $@
1047 $(ObjDir)/%.bc: %.cpp $(ObjDir)/.dir $(GCCAS) $(BUILT_SOURCES)
1048 $(Echo) "Compiling $*.cpp for $(BuildMode) build (bytecode)"
1049 $(BCCompile.CXX) $< -o $@
1051 $(ObjDir)/%.bc: %.cc $(ObjDir)/.dir $(GCCAS) $(BUILT_SOURCES)
1052 $(Echo) "Compiling $*.cc for $(BuildMode) build (bytecode)"
1053 $(BCCompile.CXX) $< -o $@
1055 $(ObjDir)/%.bc: %.c $(ObjDir)/.dir $(GCCAS) $(BUILT_SOURCES)
1056 $(Echo) "Compiling $*.c for $(BuildMode) build (bytecode)"
1057 $(BCCompile.C) $< -o $@
1061 #---------------------------------------------------------
1062 # Provide rule to build .bc files from .ll sources,
1063 # regardless of dependencies
1064 #---------------------------------------------------------
1065 $(ObjDir)/%.bc: %.ll $(ObjDir)/.dir $(LLVMAS)
1066 $(Echo) "Compiling $*.ll for $(BuildMode) build"
1067 $(Verb) $(LLVMAS) $< -f -o $@
1069 ###############################################################################
1070 # TABLEGEN: Provide rules for running tblgen to produce *.inc files
1071 ###############################################################################
1075 TDFiles := $(strip $(wildcard $(PROJ_SRC_DIR)/*.td) $(LLVM_SRC_ROOT)/lib/Target/Target.td)
1076 INCFiles := $(filter %.inc,$(BUILT_SOURCES))
1077 INCTMPFiles := $(INCFiles:%=$(ObjDir)/%.tmp)
1078 .PRECIOUS: $(INCTMPFiles) $(INCFiles)
1080 # All of these files depend on tblgen and the .td files.
1081 $(INCTMPFiles) : $(TBLGEN) $(TDFiles)
1083 # INCFiles rule: All of the tblgen generated files are emitted to
1084 # $(ObjDir)/%.inc.tmp, instead of emitting them directly to %.inc. This allows
1085 # us to only "touch" the real file if the contents of it change. IOW, if
1086 # tblgen is modified, all of the .inc.tmp files are regereated, but no
1087 # dependencies of the .inc files are, unless the contents of the .inc file
1089 $(INCFiles) : %.inc : $(ObjDir)/%.inc.tmp
1090 $(Verb) $(CMP) -s $@ $< || $(CP) $< $@
1092 $(TARGET:%=$(ObjDir)/%GenRegisterNames.inc.tmp): \
1093 $(ObjDir)/%GenRegisterNames.inc.tmp : %.td $(ObjDir)/.dir
1094 $(Echo) "Building $(<F) register names with tblgen"
1095 $(Verb) $(TableGen) -gen-register-enums -o $@ $<
1097 $(TARGET:%=$(ObjDir)/%GenRegisterInfo.h.inc.tmp): \
1098 $(ObjDir)/%GenRegisterInfo.h.inc.tmp : %.td $(ObjDir)/.dir
1099 $(Echo) "Building $(<F) register information header with tblgen"
1100 $(Verb) $(TableGen) -gen-register-desc-header -o $@ $<
1102 $(TARGET:%=$(ObjDir)/%GenRegisterInfo.inc.tmp): \
1103 $(ObjDir)/%GenRegisterInfo.inc.tmp : %.td $(ObjDir)/.dir
1104 $(Echo) "Building $(<F) register info implementation with tblgen"
1105 $(Verb) $(TableGen) -gen-register-desc -o $@ $<
1107 $(TARGET:%=$(ObjDir)/%GenInstrNames.inc.tmp): \
1108 $(ObjDir)/%GenInstrNames.inc.tmp : %.td $(ObjDir)/.dir
1109 $(Echo) "Building $(<F) instruction names with tblgen"
1110 $(Verb) $(TableGen) -gen-instr-enums -o $@ $<
1112 $(TARGET:%=$(ObjDir)/%GenInstrInfo.inc.tmp): \
1113 $(ObjDir)/%GenInstrInfo.inc.tmp : %.td $(ObjDir)/.dir
1114 $(Echo) "Building $(<F) instruction information with tblgen"
1115 $(Verb) $(TableGen) -gen-instr-desc -o $@ $<
1117 $(TARGET:%=$(ObjDir)/%GenAsmWriter.inc.tmp): \
1118 $(ObjDir)/%GenAsmWriter.inc.tmp : %.td $(ObjDir)/.dir
1119 $(Echo) "Building $(<F) assembly writer with tblgen"
1120 $(Verb) $(TableGen) -gen-asm-writer -o $@ $<
1122 $(TARGET:%=$(ObjDir)/%GenAsmWriter1.inc.tmp): \
1123 $(ObjDir)/%GenAsmWriter1.inc.tmp : %.td $(ObjDir)/.dir
1124 $(Echo) "Building $(<F) assembly writer #1 with tblgen"
1125 $(Verb) $(TableGen) -gen-asm-writer -asmwriternum=1 -o $@ $<
1127 $(TARGET:%=$(ObjDir)/%GenCodeEmitter.inc.tmp): \
1128 $(ObjDir)/%GenCodeEmitter.inc.tmp: %.td $(ObjDir)/.dir
1129 $(Echo) "Building $(<F) code emitter with tblgen"
1130 $(Verb) $(TableGen) -gen-emitter -o $@ $<
1133 -$(Verb) $(RM) -f $(INCFiles)
1137 ###############################################################################
1138 # LEX AND YACC: Provide rules for generating sources with lex and yacc
1139 ###############################################################################
1141 #---------------------------------------------------------
1142 # Provide rules for generating a .cpp source file from
1143 # (f)lex input sources.
1144 #---------------------------------------------------------
1146 LexFiles := $(filter %.l,$(Sources))
1148 ifneq ($(LexFiles),)
1150 LexOutput := $(strip $(patsubst %.l,%.cpp,$(LexFiles)))
1152 .PRECIOUS: $(LexOutput)
1154 # Note the extra sed filtering here, used to cut down on the warnings emited
1155 # by GCC. The last line is a gross hack to work around flex aparently not
1156 # being able to resize the buffer on a large token input. Currently, for
1157 # uninitialized string buffers in LLVM we can generate very long tokens, so
1158 # this is a hack around it.
1159 # FIXME. (f.e. char Buffer[10000] )
1161 $(Echo) Flexing $*.l
1162 $(Verb) $(FLEX) -t $< | \
1163 $(SED) 's/void yyunput/inline void yyunput/' | \
1164 $(SED) 's/void \*yy_flex_realloc/inline void *yy_flex_realloc/' | \
1165 $(SED) 's/#define YY_BUF_SIZE 16384/#define YY_BUF_SIZE (16384*64)/' \
1169 -$(Verb) $(RM) -f $(LexOutput)
1170 $(Verb) $(RM) -f $(LexOutput)
1174 #---------------------------------------------------------
1175 # Provide rules for generating a .cpp and .h source files
1176 # from yacc (bison) input sources.
1177 #---------------------------------------------------------
1179 YaccFiles := $(filter %.y,$(Sources))
1180 ifneq ($(YaccFiles),)
1181 YaccOutput := $(addprefix $(patsubst %.y,%,$(YaccFiles)),.h .cpp .output)
1183 .PRECIOUS: $(YaccOutput)
1185 # Cancel built-in rules for yacc
1190 # Rule for building the bison parsers...
1192 $(Echo) "Bisoning $*.y"
1193 $(Verb) $(BISON) -v -d -p $(<F:%Parser.y=%) -o $*.tab.c $<
1194 $(Verb) $(MV) -f $*.tab.c $*.cpp
1195 $(Verb) $(MV) -f $*.tab.h $*.h
1198 -$(Verb) $(RM) -f $(YaccOutput)
1199 $(Verb) $(RM) -f $(YaccOutput)
1202 ###############################################################################
1203 # OTHER RULES: Other rules needed
1204 ###############################################################################
1206 # To create postscript files from dot files...
1207 ifneq ($(DOT),false)
1209 $(DOT) -Tps < $< > $@
1212 $(Echo) "Cannot build $@: The program dot is not installed"
1215 # This rules ensures that header files that are removed still have a rule for
1216 # which they can be "generated." This allows make to ignore them and
1217 # reproduce the dependency lists.
1221 # Define clean-local to clean the current directory. Note that this uses a
1222 # very conservative approach ensuring that empty variables do not cause
1223 # errors or disastrous removal.
1225 ifneq ($(strip $(ObjDir)),)
1226 -$(Verb) $(RM) -rf $(ObjDir)
1228 -$(Verb) $(RM) -f core core.[0-9][0-9]* *.o *.d *~ *.flc
1229 ifneq ($(strip $(SHLIBEXT)),) # Extra paranoia - make real sure SHLIBEXT is set
1230 -$(Verb) $(RM) -f *$(SHLIBEXT)
1234 -$(Verb) $(RM) -rf Debug Release Profile
1236 # Build tags database for Emacs/Xemacs:
1240 find $(PROJ_SRC_ROOT)/include $(PROJ_SRC_ROOT)/lib \
1241 $(PROJ_SRC_ROOT)/tools $(PROJ_SRC_ROOT)/examples \
1242 $(PROJ_OBJ_ROOT)/include $(PROJ_OBJ_ROOT)/lib \
1243 $(PROJ_OBJ_ROOT)/tools $(PROJ_OBJ_ROOT)/examples \
1244 -name '*.cpp' -o -name '*.h' | \
1245 $(ETAGS) $(ETAGSFLAGS) -
1248 find $(PROJ_SRC_ROOT)/include $(PROJ_SRC_ROOT)/lib \
1249 $(PROJ_SRC_ROOT)/tools $(PROJ_SRC_ROOT)/examples \
1250 $(PROJ_OBJ_ROOT)/include $(PROJ_OBJ_ROOT)/lib \
1251 $(PROJ_OBJ_ROOT)/tools $(PROJ_OBJ_ROOT)/examples \
1252 \( -name '*.cpp' -o -name '*.h' \) -print | \
1253 ctags -ImtT -o $(PROJ_OBJ_ROOT)/CTAGS -L -
1256 ###############################################################################
1257 # DEPENDENCIES: Include the dependency files if we should
1258 ###############################################################################
1259 ifndef DISABLE_AUTO_DEPENDENCIES
1261 # If its not one of the cleaning targets
1262 ifneq ($strip($(filter-out clean clean-local dist-clean,$(MAKECMDGOALS))),)
1264 # Get the list of dependency files
1265 DependFiles := $(basename $(filter %.cpp %.c %.cc, $(Sources)))
1266 DependFiles := $(patsubst %,$(PROJ_OBJ_DIR)/$(BuildMode)/%.d,$(DependFiles))
1268 -include /dev/null $(DependFiles)
1274 ###############################################################################
1275 # CHECK: Running the test suite
1276 ###############################################################################
1279 $(Verb) if test -d "$(PROJ_OBJ_ROOT)/test" ; then \
1280 if test -f "$(PROJ_OBJ_ROOT)/test/Makefile" ; then \
1281 $(EchoCmd) Running test suite ; \
1282 $(MAKE) -C $(PROJ_OBJ_ROOT)/test check-local \
1283 TESTSUITE=$(TESTSUITE) ; \
1285 $(EchoCmd) No Makefile in test directory ; \
1288 $(EchoCmd) No test directory ; \
1291 ###############################################################################
1292 # DISTRIBUTION: Handle construction of a distribution tarball
1293 ###############################################################################
1295 #------------------------------------------------------------------------
1296 # Define distribution related variables
1297 #------------------------------------------------------------------------
1298 DistName := $(PROJECT_NAME)-$(PROJ_VERSION)
1299 DistDir := $(PROJ_OBJ_ROOT)/$(DistName)
1300 TopDistDir := $(PROJ_OBJ_ROOT)/$(DistName)
1301 DistTarGZip := $(PROJ_OBJ_ROOT)/$(DistName).tar.gz
1302 DistZip := $(PROJ_OBJ_ROOT)/$(DistName).zip
1303 DistTarBZ2 := $(PROJ_OBJ_ROOT)/$(DistName).tar.bz2
1304 DistAlways := CREDITS.TXT LICENSE.TXT README.txt README AUTHORS COPYING \
1305 ChangeLog INSTALL NEWS Makefile Makefile.common Makefile.rules \
1306 Makefile.config.in configure autoconf
1307 DistOther := $(notdir $(wildcard \
1308 $(PROJ_SRC_DIR)/*.h \
1309 $(PROJ_SRC_DIR)/*.td \
1310 $(PROJ_SRC_DIR)/*.def \
1311 $(PROJ_SRC_DIR)/*.ll \
1312 $(PROJ_SRC_DIR)/*.in))
1313 DistSubDirs := $(SubDirs)
1314 DistSources = $(Sources) $(EXTRA_DIST)
1315 DistFiles = $(DistAlways) $(DistSources) $(DistOther)
1317 #------------------------------------------------------------------------
1318 # We MUST build distribution with OBJ_DIR != SRC_DIR
1319 #------------------------------------------------------------------------
1320 ifeq ($(PROJ_SRC_DIR),$(PROJ_OBJ_DIR))
1321 dist dist-check dist-clean dist-gzip dist-bzip2 dist-zip ::
1322 $(Echo) ERROR: Target $@ only available with OBJ_DIR != SRC_DIR
1326 #------------------------------------------------------------------------
1327 # Prevent attempt to run dist targets from anywhere but the top level
1328 #------------------------------------------------------------------------
1330 dist dist-check dist-clean dist-gzip dist-bzip2 dist-zip ::
1331 $(Echo) ERROR: You must run $@ from $(PROJ_OBJ_ROOT)
1334 #------------------------------------------------------------------------
1335 # Provide the top level targets
1336 #------------------------------------------------------------------------
1338 dist-gzip:: $(DistTarGZip)
1340 $(DistTarGZip) : $(TopDistDir)/.makedistdir
1341 $(Echo) Packing gzipped distribution tar file.
1342 $(Verb) cd $(PROJ_OBJ_ROOT) ; $(TAR) chf - "$(DistName)" | \
1343 $(GZIP) -c > "$(DistTarGZip)"
1345 dist-bzip2:: $(DistTarBZ2)
1347 $(DistTarBZ2) : $(TopDistDir)/.makedistdir
1348 $(Echo) Packing bzipped distribution tar file.
1349 $(Verb) cd $(PROJ_OBJ_ROOT) ; $(TAR) chf - $(DistName) | \
1350 $(BZIP2) -c >$(DistTarBZ2)
1352 dist-zip:: $(DistZip)
1354 $(DistZip) : $(TopDistDir)/.makedistdir
1355 $(Echo) Packing zipped distribution file.
1356 $(Verb) rm -f $(DistZip)
1357 $(Verb) cd $(PROJ_OBJ_ROOT) ; $(ZIP) -rq $(DistZip) $(DistName)
1359 dist :: $(DistTarGZip) $(DistTarBZ2) $(DistZip)
1360 $(Echo) ===== DISTRIBUTION PACKAGING SUCESSFUL =====
1362 DistCheckDir := $(PROJ_OBJ_ROOT)/_distcheckdir
1364 dist-check:: $(DistTarGZip)
1365 $(Echo) Checking distribution tar file.
1366 $(Verb) if test -d $(DistCheckDir) ; then \
1367 $(RM) -rf $(DistCheckDir) ; \
1369 $(Verb) $(MKDIR) $(DistCheckDir)
1370 $(Verb) cd $(DistCheckDir) && \
1371 $(MKDIR) $(DistCheckDir)/build && \
1372 $(MKDIR) $(DistCheckDir)/install && \
1373 gunzip -c $(DistTarGZip) | $(TAR) xf - && \
1375 ../$(DistName)/configure --prefix="$(DistCheckDir)/install" \
1376 --srcdir=../$(DistName) && \
1379 $(MAKE) install && \
1380 $(MAKE) uninstall && \
1383 $(MAKE) dist-clean && \
1384 $(EchoCmd) ===== $(DistTarGZip) Ready For Distribution =====
1387 $(Echo) Cleaning distribution files
1388 -$(Verb) $(RM) -rf $(DistTarGZip) $(DistTarBZ2) $(DistZip) $(DistName) \
1393 #------------------------------------------------------------------------
1394 # Provide the recursive distdir target for building the distribution directory
1395 #------------------------------------------------------------------------
1396 distdir: $(DistDir)/.makedistdir
1397 $(DistDir)/.makedistdir: $(DistSources)
1398 $(Verb) if test "$(DistDir)" = "$(TopDistDir)" ; then \
1399 if test -d "$(DistDir)" ; then \
1400 find $(DistDir) -type d ! -perm -200 -exec chmod u+w {} ';' || \
1403 $(EchoCmd) Removing old $(DistDir) ; \
1404 $(RM) -rf $(DistDir); \
1405 $(EchoCmd) Making 'all' to verify build ; \
1408 $(Echo) Building Distribution Directory $(DistDir)
1409 $(Verb) $(MKDIR) $(DistDir)
1410 $(Verb) srcdirstrip=`echo "$(PROJ_SRC_DIR)" | sed 's|.|.|g'`; \
1411 srcrootstrip=`echo "$(PROJ_SRC_ROOT)" | sed 's|.|.|g'`; \
1412 for file in $(DistFiles) ; do \
1414 $(PROJ_SRC_DIR)/*) \
1415 file=`echo "$$file" | sed "s#^$$srcdirstrip/##"` \
1417 $(PROJ_SRC_ROOT)/*) \
1418 file=`echo "$$file" | \
1419 sed "s#^$$srcrootstrip/##"` \
1422 if test -f "$(PROJ_SRC_DIR)/$$file" || \
1423 test -d "$(PROJ_SRC_DIR)/$$file" ; then \
1424 from_dir="$(PROJ_SRC_DIR)" ; \
1425 elif test -f "$$file" || test -d "$$file" ; then \
1428 to_dir=`echo "$$file" | sed -e 's#/[^/]*$$##'` ; \
1429 if test "$$to_dir" != "$$file" && test "$$to_dir" != "."; then \
1430 to_dir="$(DistDir)/$$dir"; \
1431 $(MKDIR) "$$to_dir" ; \
1433 to_dir="$(DistDir)"; \
1435 mid_dir=`echo "$$file" | sed -n -e 's#^\(.*\)/[^/]*$$#\1#p'`; \
1436 if test -n "$$mid_dir" ; then \
1437 $(MKDIR) "$$to_dir/$$mid_dir" || exit 1; \
1439 if test -d "$$from_dir/$$file"; then \
1440 if test -d "$(PROJ_SRC_DIR)/$$file" && \
1441 test "$$from_dir" != "$(PROJ_SRC_DIR)" ; then \
1442 $(CP) -pR "$(PROJ_SRC_DIR)/$$file" "$$to_dir" || exit 1; \
1444 $(CP) -pR $$from_dir/$$file $$to_dir || exit 1; \
1445 elif test -f "$$from_dir/$$file" ; then \
1446 $(CP) -p "$$from_dir/$$file" "$(DistDir)/$$file" || exit 1; \
1447 elif test -L "$$from_dir/$$file" ; then \
1448 $(CP) -pd "$$from_dir/$$file" $(DistDir)/$$file || exit 1; \
1449 elif echo "$(DistAlways)" | grep -v "$$file" >/dev/null ; then \
1450 $(EchoCmd) "===== WARNING: Distribution Source " \
1451 "$$from_dir/$$file Not Found!" ; \
1452 elif test "$(Verb)" != '@' ; then \
1453 $(EchoCmd) "Skipping non-existent $$from_dir/$$file" ; \
1456 $(Verb) for subdir in $(DistSubDirs) ; do \
1457 if test "$$subdir" \!= "." ; then \
1458 new_distdir="$(DistDir)/$$subdir" ; \
1459 test -d "$$new_distdir" || $(MKDIR) "$$new_distdir" || exit 1; \
1460 ( cd $$subdir && $(MAKE) DistDir="$$new_distdir" distdir ) || \
1464 $(Verb) if test "$(DistDir)" = "$(TopDistDir)" ; then \
1465 $(EchoCmd) Eliminating CVS directories from distribution ; \
1466 $(RM) -rf `find $(TopDistDir) -type d -name CVS -print` ;\
1467 $(MAKE) dist-hook ; \
1468 $(FIND) $(TopDistDir) -type d ! -perm -777 -exec chmod a+rwx {} \; \
1469 -o ! -type d ! -perm -444 -links 1 -exec chmod a+r {} \; \
1470 -o ! -type d ! -perm -400 -exec chmod a+r {} \; \
1471 -o ! -type d ! -perm -444 -exec \
1472 $(SHELL) $(INSTALL_SH) -c -m a+r {} {} \; \
1473 || chmod -R a+r $(DistDir) ; \
1476 # This is invoked by distdir target, define it as a no-op to avoid errors if not
1482 ###############################################################################
1483 # TOP LEVEL - targets only to apply at the top level directory
1484 ###############################################################################
1488 #------------------------------------------------------------------------
1489 # Install support for the project's include files:
1490 #------------------------------------------------------------------------
1492 $(Echo) Installing include files
1493 $(Verb) $(MKDIR) $(PROJ_includedir)
1494 $(Verb) if test -d "$(PROJ_SRC_ROOT)/include" ; then \
1495 cd $(PROJ_SRC_ROOT)/include && \
1496 for hdr in `find . -type f '!' '(' -name '*~' -o -name '.cvsignore' \
1497 -o -name '.#*' -o -name '*.in' ')' -print | grep -v CVS ` ; do \
1498 instdir=`dirname "$(PROJ_includedir)/$$hdr"` ; \
1499 if test \! -d "$$instdir" ; then \
1500 $(EchoCmd) Making install directory $$instdir ; \
1501 $(MKDIR) $$instdir ;\
1503 $(DataInstall) $$hdr $(PROJ_includedir)/$$hdr ; \
1506 $(Verb) if test -d "$(PROJ_OBJ_ROOT)/include" ; then \
1507 cd $(PROJ_OBJ_ROOT)/include && \
1508 for hdr in `find . -type f -print` ; do \
1509 $(DataInstall) $$hdr $(PROJ_includedir)/$$hdr ; \
1514 $(Echo) Uninstalling include files
1515 $(Verb) if [ -d "$(PROJ_SRC_ROOT)/include" ] ; then \
1516 cd $(PROJ_SRC_ROOT)/include && \
1517 $(RM) -f `find . -path '*/Internal' -prune -o '(' -type f \
1518 '!' '(' -name '*~' -o -name '.cvsignore' -o -name '.#*' -o -name '*.in' ')' \
1519 -print ')' | grep -v CVS | sed 's#^#$(PROJ_includedir)/#'` ; \
1520 cd $(PROJ_SRC_ROOT)/include && \
1521 $(RM) -f `find . -path '*/Internal' -prune -o '(' -type f -name '*.in' -print ')' \
1522 | sed 's#\.in$$##;s#^#$(PROJ_includedir)/#'` ; \
1527 #------------------------------------------------------------------------
1528 # Print out the directories used for building
1529 #------------------------------------------------------------------------
1531 $(Echo) "BuildMode : " '$(BuildMode)'
1532 $(Echo) "PROJ_SRC_ROOT: " '$(PROJ_SRC_ROOT)'
1533 $(Echo) "PROJ_SRC_DIR : " '$(PROJ_SRC_DIR)'
1534 $(Echo) "PROJ_OBJ_ROOT: " '$(PROJ_OBJ_ROOT)'
1535 $(Echo) "PROJ_OBJ_DIR : " '$(PROJ_OBJ_DIR)'
1536 $(Echo) "LLVM_SRC_ROOT: " '$(LLVM_SRC_ROOT)'
1537 $(Echo) "LLVM_OBJ_ROOT: " '$(LLVM_OBJ_ROOT)'
1538 $(Echo) "PROJ_prefix : " '$(PROJ_prefix)'
1539 $(Echo) "PROJ_bindir : " '$(PROJ_bindir)'
1540 $(Echo) "PROJ_libdir : " '$(PROJ_libdir)'
1541 $(Echo) "PROJ_etcdir : " '$(PROJ_etcdir)'
1542 $(Echo) "PROJ_includedir : " '$(PROJ_includedir)'
1543 $(Echo) "UserTargets : " '$(UserTargets)'
1544 $(Echo) "ObjMakefiles : " '$(ObjMakefiles)'
1545 $(Echo) "SrcMakefiles : " '$(SrcMakefiles)'
1546 $(Echo) "ObjDir : " '$(ObjDir)'
1547 $(Echo) "LibDir : " '$(LibDir)'
1548 $(Echo) "ToolDir : " '$(ToolDir)'
1549 $(Echo) "ExmplDir : " '$(ExmplDir)'
1550 $(Echo) "Sources : " '$(Sources)'
1551 $(Echo) "TDFiles : " '$(TDFiles)'
1552 $(Echo) "INCFiles : " '$(INCFiles)'
1553 $(Echo) "INCTMPFiles : " '$(INCTMPFiles)'
1554 $(Echo) "PreConditions: " '$(PreConditions)'
1555 $(Echo) "Compile.CXX : " '$(Compile.CXX)'
1556 $(Echo) "Compile.C : " '$(Compile.C)'
1557 $(Echo) "Archive : " '$(Archive)'
1558 $(Echo) "YaccFiles : " '$(YaccFiles)'
1559 $(Echo) "LexFiles : " '$(LexFiles)'
1560 $(Echo) "Module : " '$(Module)'