]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - opencl/llvm.git/blob - Makefile.rules
build/Make: Add missing dependency, LLVMBuild makefile fragment implicitly depends...
[opencl/llvm.git] / Makefile.rules
1 #===-- Makefile.rules - Common make rules for LLVM ---------*- Makefile -*--===#
2 #
3 #                     The LLVM Compiler Infrastructure
4 #
5 # This file is distributed under the University of Illinois Open Source
6 # License. See LICENSE.TXT for details.
7 #
8 #===------------------------------------------------------------------------===#
9 #
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.
12 #
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                     unitcheck
24 LocalTargets     := all-local clean-local clean-all-local check-local \
25                     install-local printvars uninstall-local \
26                     install-bytecode-local
27 TopLevelTargets  := check dist dist-check dist-clean dist-gzip dist-bzip2 \
28                     dist-zip unittests
29 UserTargets      := $(RecursiveTargets) $(LocalTargets) $(TopLevelTargets)
30 InternalTargets  := preconditions distdir dist-hook
32 ################################################################################
33 # INITIALIZATION: Basic things the makefile needs
34 ################################################################################
36 #--------------------------------------------------------------------
37 # Set the VPATH so that we can find source files.
38 #--------------------------------------------------------------------
39 VPATH=$(PROJ_SRC_DIR)
41 #--------------------------------------------------------------------
42 # Reset the list of suffixes we know how to build.
43 #--------------------------------------------------------------------
44 .SUFFIXES:
45 .SUFFIXES: .c .cpp .cc .h .hpp .o .a .bc .td .ps .dot .ll .m .mm
46 .SUFFIXES: $(SHLIBEXT) $(SUFFIXES)
48 #--------------------------------------------------------------------
49 # Mark all of these targets as phony to avoid implicit rule search
50 #--------------------------------------------------------------------
51 .PHONY: $(UserTargets) $(InternalTargets)
53 #--------------------------------------------------------------------
54 # Make sure all the user-target rules are double colon rules and
55 # they are defined first.
56 #--------------------------------------------------------------------
58 $(UserTargets)::
60 #------------------------------------------------------------------------
61 # LLVMBuild Integration
62 #------------------------------------------------------------------------
63 #
64 # We use llvm-build to generate all the data required by the Makefile based
65 # build system in one swoop:
66 #
67 #  - We generate a file (a Makefile fragment) in the object root which contains
68 #    all the definitions that are required by Makefiles across the entire
69 #    project.
70 #
71 #  - We generate the library table used by llvm-config.
72 #
73 #  - We generate the dependencies for the Makefile fragment, so that we will
74 #    automatically reconfigure outselves.
76 # The path to the llvm-build tool itself.
77 LLVMBuildTool   := $(PROJ_SRC_ROOT)/utils/llvm-build/llvm-build
79 # The files we are going to generate using llvm-build.
80 LLVMBuildMakeFrag := $(PROJ_OBJ_ROOT)/Makefile.llvmbuild
81 LLVMConfigLibraryDependenciesInc := \
82         $(PROJ_OBJ_ROOT)/tools/llvm-config/LibraryDependencies.inc
84 # This is for temporary backwards compatibility.
85 ifndef TARGET_NATIVE_ARCH
86 TARGET_NATIVE_ARCH := $(ARCH)
87 endif
89 # The rule to create the LLVMBuild Makefile fragment as well as the llvm-config
90 # library table.
91 #
92 # Note that this target gets its real dependencies generated for us by
93 # llvm-build.
94 #
95 # We include a dependency on this Makefile to ensure that changes to the
96 # generation command get picked up.
97 $(LLVMBuildMakeFrag): $(PROJ_SRC_ROOT)/Makefile.rules \
98                       $(PROJ_OBJ_ROOT)/Makefile.config
99         $(Echo) Constructing LLVMBuild project information.
100         $(Verb) $(LLVMBuildTool) \
101           --native-target "$(TARGET_NATIVE_ARCH)" \
102           --enable-targets "$(TARGETS_TO_BUILD)" \
103           --write-library-table $(LLVMConfigLibraryDependenciesInc) \
104           --write-make-fragment $(LLVMBuildMakeFrag)
106 # For completeness, let Make know how the extra files are generated.
107 $(LLVMConfigLibraryDependenciesInc): $(LLVMBuildMakeFrag)
109 # Include the generated Makefile fragment.
111 # We currently only include the dependencies for the fragment itself if we are
112 # at the top-level. Otherwise, recursive invocations would ends up doing
113 # substantially more redundant stat'ing.
115 # This means that we won't properly regenerate things for developers used to
116 # building from a subdirectory, but that is always somewhat unreliable.
117 ifeq ($(LEVEL),.)
118 LLVMBUILD_INCLUDE_DEPENDENCIES := 1
119 endif
120 -include $(LLVMBuildMakeFrag)
122 ################################################################################
123 # PRECONDITIONS: that which must be built/checked first
124 ################################################################################
126 SrcMakefiles       := $(filter %Makefile %Makefile.tests,\
127                       $(wildcard $(PROJ_SRC_DIR)/Makefile*))
128 ObjMakefiles       := $(subst $(PROJ_SRC_DIR),$(PROJ_OBJ_DIR),$(SrcMakefiles))
129 ConfigureScript    := $(PROJ_SRC_ROOT)/configure
130 ConfigStatusScript := $(PROJ_OBJ_ROOT)/config.status
131 MakefileConfigIn   := $(strip $(wildcard $(PROJ_SRC_ROOT)/Makefile.config.in))
132 MakefileCommonIn   := $(strip $(wildcard $(PROJ_SRC_ROOT)/Makefile.common.in))
133 MakefileConfig     := $(PROJ_OBJ_ROOT)/Makefile.config
134 MakefileCommon     := $(PROJ_OBJ_ROOT)/Makefile.common
135 PreConditions      := $(ConfigStatusScript) $(ObjMakefiles)
136 ifneq ($(MakefileCommonIn),)
137 PreConditions      += $(MakefileCommon)
138 endif
140 ifneq ($(MakefileConfigIn),)
141 PreConditions      += $(MakefileConfig)
142 endif
144 preconditions: $(PreConditions)
146 #------------------------------------------------------------------------
147 # Make sure the BUILT_SOURCES are built first
148 #------------------------------------------------------------------------
149 $(filter-out clean clean-local,$(UserTargets)):: $(BUILT_SOURCES)
151 clean-all-local::
152 ifneq ($(strip $(BUILT_SOURCES)),)
153         -$(Verb) $(RM) -f $(BUILT_SOURCES)
154 endif
156 ifneq ($(PROJ_OBJ_ROOT),$(PROJ_SRC_ROOT))
157 spotless:
158         $(Verb) if test -x config.status ; then \
159           $(EchoCmd) Wiping out $(PROJ_OBJ_ROOT) ; \
160           $(MKDIR) .spotless.save ; \
161           $(MV) config.status .spotless.save ; \
162           $(MV) mklib  .spotless.save ; \
163           $(MV) projects  .spotless.save ; \
164           $(RM) -rf * ; \
165           $(MV) .spotless.save/config.status . ; \
166           $(MV) .spotless.save/mklib . ; \
167           $(MV) .spotless.save/projects . ; \
168           $(RM) -rf .spotless.save ; \
169           $(EchoCmd) Rebuilding configuration of $(PROJ_OBJ_ROOT) ; \
170           $(ConfigStatusScript) --recheck $(ConfigureScriptFLAGS) && \
171           $(ConfigStatusScript) ; \
172         else \
173           $(EchoCmd) "make spotless" can only be run from $(PROJ_OBJ_ROOT); \
174         fi
175 else
176 spotless:
177         $(EchoCmd) "spotless target not supported for objdir == srcdir"
178 endif
180 $(BUILT_SOURCES) : $(ObjMakefiles)
182 #------------------------------------------------------------------------
183 # Make sure we're not using a stale configuration
184 #------------------------------------------------------------------------
185 reconfigure:
186         $(Echo) Reconfiguring $(PROJ_OBJ_ROOT)
187         $(Verb) cd $(PROJ_OBJ_ROOT) && \
188           $(ConfigStatusScript) --recheck $(ConfigureScriptFLAGS) && \
189           $(ConfigStatusScript)
191 .PRECIOUS: $(ConfigStatusScript)
192 $(ConfigStatusScript): $(ConfigureScript)
193         $(Echo) Reconfiguring with $<
194         $(Verb) cd $(PROJ_OBJ_ROOT) && \
195           $(ConfigStatusScript) --recheck $(ConfigureScriptFLAGS) && \
196           $(ConfigStatusScript)
198 #------------------------------------------------------------------------
199 # Make sure the configuration makefile is up to date
200 #------------------------------------------------------------------------
201 ifneq ($(MakefileConfigIn),)
202 $(MakefileConfig): $(MakefileConfigIn) $(ConfigStatusScript)
203         $(Echo) Regenerating $@
204         $(Verb) cd $(PROJ_OBJ_ROOT) ; $(ConfigStatusScript) Makefile.config
205 endif
207 ifneq ($(MakefileCommonIn),)
208 $(MakefileCommon): $(MakefileCommonIn) $(ConfigStatusScript)
209         $(Echo) Regenerating $@
210         $(Verb) cd $(PROJ_OBJ_ROOT) ; $(ConfigStatusScript) Makefile.common
211 endif
213 #------------------------------------------------------------------------
214 # If the Makefile in the source tree has been updated, copy it over into the
215 # build tree. But, only do this if the source and object makefiles differ
216 #------------------------------------------------------------------------
217 ifndef PROJ_MAKEFILE
218 PROJ_MAKEFILE := $(PROJ_SRC_DIR)/Makefile
219 endif
221 ifneq ($(PROJ_OBJ_DIR),$(PROJ_SRC_DIR))
223 Makefile: $(PROJ_MAKEFILE) $(ExtraMakefiles)
224         $(Echo) "Updating Makefile"
225         $(Verb) $(MKDIR) $(@D)
226         $(Verb) $(CP) -f $< $@
228 # Copy the Makefile.* files unless we're in the root directory which avoids
229 # the copying of Makefile.config.in or other things that should be explicitly
230 # taken care of.
231 $(PROJ_OBJ_DIR)/Makefile% : $(PROJ_MAKEFILE)%
232         @case '$?' in \
233           *Makefile.rules) ;; \
234           *.in) ;; \
235           *) $(EchoCmd) "Updating $(@F)" ; \
236              $(MKDIR) $(@D) ; \
237              $(CP) -f $< $@ ;; \
238         esac
240 endif
242 #------------------------------------------------------------------------
243 # Set up the basic dependencies
244 #------------------------------------------------------------------------
245 $(UserTargets):: $(PreConditions)
247 all:: all-local
248 clean:: clean-local
249 clean-all:: clean-local clean-all-local
250 install:: install-local
251 uninstall:: uninstall-local
252 install-local:: all-local
253 install-bytecode:: install-bytecode-local
255 ###############################################################################
256 # VARIABLES: Set up various variables based on configuration data
257 ###############################################################################
259 # Variable for if this make is for a "cleaning" target
260 ifneq ($(strip $(filter clean clean-local dist-clean,$(MAKECMDGOALS))),)
261   IS_CLEANING_TARGET=1
262 endif
264 #--------------------------------------------------------------------
265 # Variables derived from configuration we are building
266 #--------------------------------------------------------------------
268 CPP.Defines :=
269 ifeq ($(ENABLE_OPTIMIZED),1)
270   BuildMode := Release
271   # Don't use -fomit-frame-pointer on Darwin or FreeBSD.
272   ifneq ($(HOST_OS),FreeBSD)
273   ifneq ($(HOST_OS),Darwin)
274     OmitFramePointer := -fomit-frame-pointer
275   endif
276   endif
278   # Darwin requires -fstrict-aliasing to be explicitly enabled.
279   # Avoid -fstrict-aliasing on Darwin for now, there are unresolved issues
280   # with -fstrict-aliasing and ipa-type-escape radr://6756684
281   #ifeq ($(HOST_OS),Darwin)
282   #  EXTRA_OPTIONS += -fstrict-aliasing -Wstrict-aliasing
283   #endif
284   CXX.Flags += $(OPTIMIZE_OPTION) $(OmitFramePointer)
285   C.Flags   += $(OPTIMIZE_OPTION) $(OmitFramePointer)
286   LD.Flags  += $(OPTIMIZE_OPTION)
287   ifdef DEBUG_SYMBOLS
288     BuildMode := $(BuildMode)+Debug
289     CXX.Flags += -g
290     C.Flags   += -g
291     LD.Flags  += -g
292     KEEP_SYMBOLS := 1
293   endif
294 else
295   ifdef NO_DEBUG_SYMBOLS
296     BuildMode := Unoptimized
297     CXX.Flags +=
298     C.Flags   +=
299     LD.Flags  +=
300     KEEP_SYMBOLS := 1
301   else
302     BuildMode := Debug
303     CXX.Flags += -g
304     C.Flags   += -g
305     LD.Flags  += -g
306     KEEP_SYMBOLS := 1
307   endif
308 endif
310 ifeq ($(ENABLE_LIBCPP),1)
311   CXX.Flags +=  -stdlib=libc++
312   LD.Flags +=  -stdlib=libc++
313 endif
315 ifeq ($(ENABLE_PROFILING),1)
316   BuildMode := $(BuildMode)+Profile
317   CXX.Flags := $(filter-out -fomit-frame-pointer,$(CXX.Flags)) -pg -g
318   C.Flags   := $(filter-out -fomit-frame-pointer,$(C.Flags)) -pg -g
319   LD.Flags  := $(filter-out -fomit-frame-pointer,$(LD.Flags)) -pg -g
320   KEEP_SYMBOLS := 1
321 endif
323 ifeq ($(ENABLE_VISIBILITY_INLINES_HIDDEN),1)
324     CXX.Flags += -fvisibility-inlines-hidden
325 endif
327 ifdef ENABLE_EXPENSIVE_CHECKS
328   # GNU libstdc++ uses RTTI if you define _GLIBCXX_DEBUG, which we did above.
329   # See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40160
330   REQUIRES_RTTI := 1
331 endif
333 # IF REQUIRES_EH=1 is specified then don't disable exceptions
334 ifndef REQUIRES_EH
335   CXX.Flags += -fno-exceptions
336 else
337   # If the library requires EH, it also requires RTTI.
338   REQUIRES_RTTI := 1
339 endif
341 ifdef REQUIRES_FRAME_POINTER
342   CXX.Flags := $(filter-out -fomit-frame-pointer,$(CXX.Flags))
343   C.Flags   := $(filter-out -fomit-frame-pointer,$(C.Flags))
344   LD.Flags  := $(filter-out -fomit-frame-pointer,$(LD.Flags))
345 endif
347 # If REQUIRES_RTTI=1 is specified then don't disable run-time type id.
348 ifneq ($(REQUIRES_RTTI), 1)
349   CXX.Flags += -fno-rtti
350 endif
352 ifeq ($(ENABLE_COVERAGE),1)
353   BuildMode := $(BuildMode)+Coverage
354   CXX.Flags += -ftest-coverage -fprofile-arcs
355   C.Flags   += -ftest-coverage -fprofile-arcs
356 endif
358 # If DISABLE_ASSERTIONS=1 is specified (make command line or configured),
359 # then disable assertions by defining the appropriate preprocessor symbols.
360 ifeq ($(DISABLE_ASSERTIONS),1)
361   CPP.Defines += -DNDEBUG
362 else
363   BuildMode := $(BuildMode)+Asserts
364   CPP.Defines += -D_DEBUG
365 endif
367 # If ENABLE_EXPENSIVE_CHECKS=1 is specified (make command line or
368 # configured), then enable expensive checks by defining the
369 # appropriate preprocessor symbols.
370 ifeq ($(ENABLE_EXPENSIVE_CHECKS),1)
371   BuildMode := $(BuildMode)+Checks
372   CPP.Defines += -D_GLIBCXX_DEBUG -DXDEBUG
373 endif
375 # LOADABLE_MODULE implies several other things so we force them to be
376 # defined/on.
377 ifdef LOADABLE_MODULE
378   SHARED_LIBRARY := 1
379   LINK_LIBS_IN_SHARED := 1
380 endif
382 ifdef SHARED_LIBRARY
383   ENABLE_PIC := 1
384   PIC_FLAG = "(PIC)"
385 endif
387 ifeq ($(ENABLE_PIC),1)
388   ifeq ($(HOST_OS), $(filter $(HOST_OS), Cygwin MingW))
389     # Nothing. Win32 defaults to PIC and warns when given -fPIC
390   else
391     ifeq ($(HOST_OS),Darwin)
392       # Common symbols not allowed in dylib files
393       CXX.Flags += -fno-common
394       C.Flags   += -fno-common
395     else
396       # Linux and others; pass -fPIC
397       CXX.Flags += -fPIC
398       C.Flags   += -fPIC
399     endif
400   endif
401 else
402   ifeq ($(HOST_OS),Darwin)
403       CXX.Flags += -mdynamic-no-pic
404       C.Flags   += -mdynamic-no-pic
405   endif
406 endif
408 # Support makefile variable to disable any kind of timestamp/non-deterministic
409 # info from being used in the build.
410 ifeq ($(ENABLE_TIMESTAMPS),1)
411   DOTDIR_TIMESTAMP_COMMAND := $(DATE)
412 else
413   DOTDIR_TIMESTAMP_COMMAND := echo 'Created.'
414 endif
416 ifeq ($(HOST_OS),MingW)
417   # Work around PR4957
418   CPP.Defines += -D__NO_CTYPE_INLINE
419   ifeq ($(LLVM_CROSS_COMPILING),1)
420     # Work around http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=525016
421     ifdef TOOLNAME
422       LD.Flags += -Wl,--allow-multiple-definition
423     endif
424   endif
425 endif
427 CXX.Flags     += -Woverloaded-virtual
428 CPP.BaseFlags += $(CPP.Defines)
429 AR.Flags      := cru
431 # Make Floating point IEEE compliant on Alpha.
432 ifeq ($(ARCH),Alpha)
433   CXX.Flags     += -mieee
434   CPP.BaseFlags += -mieee
435 ifeq ($(ENABLE_PIC),0)
436   CXX.Flags     += -fPIC
437   CPP.BaseFlags += -fPIC
438 endif
440   LD.Flags += -Wl,--no-relax
441 endif
443 # GNU ld/PECOFF accepts but ignores them below;
444 #   --version-script
445 #   --export-dynamic
446 #   --rpath
447 # FIXME: autoconf should be aware of them.
448 ifneq (,$(filter $(HOST_OS),Cygwin MingW))
449   HAVE_LINK_VERSION_SCRIPT := 0
450   RPATH :=
451   RDYNAMIC := -Wl,--export-all-symbols
452 endif
454 #--------------------------------------------------------------------
455 # Directory locations
456 #--------------------------------------------------------------------
457 TargetMode :=
458 ifeq ($(LLVM_CROSS_COMPILING),1)
459   BuildLLVMToolDir := $(LLVM_OBJ_ROOT)/BuildTools/$(BuildMode)/bin
460 endif
462 ObjRootDir  := $(PROJ_OBJ_DIR)/$(BuildMode)
463 ObjDir      := $(ObjRootDir)
464 LibDir      := $(PROJ_OBJ_ROOT)/$(BuildMode)/lib
465 ToolDir     := $(PROJ_OBJ_ROOT)/$(BuildMode)/bin
466 ExmplDir    := $(PROJ_OBJ_ROOT)/$(BuildMode)/examples
467 LLVMLibDir  := $(LLVM_OBJ_ROOT)/$(BuildMode)/lib
468 LLVMToolDir := $(LLVM_OBJ_ROOT)/$(BuildMode)/bin
469 LLVMExmplDir:= $(LLVM_OBJ_ROOT)/$(BuildMode)/examples
471 #--------------------------------------------------------------------
472 # Locations of shared libraries
473 #--------------------------------------------------------------------
475 SharedPrefix     := lib
476 SharedLibDir     := $(LibDir)
477 LLVMSharedLibDir := $(LLVMLibDir)
479 # Win32.DLL prefers to be located on the "PATH" of binaries.
480 ifeq ($(HOST_OS), $(filter $(HOST_OS), Cygwin MingW))
481   SharedLibDir     := $(ToolDir)
482   LLVMSharedLibDir := $(LLVMToolDir)
484   ifeq ($(HOST_OS),Cygwin)
485     SharedPrefix  := cyg
486   else
487     SharedPrefix  :=
488   endif
489 endif
491 #--------------------------------------------------------------------
492 # LLVM Capable Compiler
493 #--------------------------------------------------------------------
495 ifneq ($(findstring llvm-gcc,$(LLVMCC_OPTION)),)
496   LLVMCC := $(LLVMGCC)
497   LLVMCXX := $(LLVMGXX)
498 else
499   ifneq ($(findstring clang,$(LLVMCC_OPTION)),)
500     ifneq ($(CLANGPATH),)
501       LLVMCC := $(CLANGPATH)
502       LLVMCXX := $(CLANGXXPATH)
503     else
504       ifeq ($(ENABLE_BUILT_CLANG),1)
505         LLVMCC := $(LLVMToolDir)/clang
506         LLVMCXX := $(LLVMToolDir)/clang++
507       endif
508     endif
509   endif
510 endif
512 #--------------------------------------------------------------------
513 # Full Paths To Compiled Tools and Utilities
514 #--------------------------------------------------------------------
515 EchoCmd  := $(ECHO) llvm[$(MAKELEVEL)]:
516 ifdef BUILD_DIRS_ONLY
517 EchoCmd  := $(EchoCmd) "(build tools)":
518 endif
520 Echo     := @$(EchoCmd)
521 ifndef LLVMAS
522 LLVMAS   := $(LLVMToolDir)/llvm-as$(EXEEXT)
523 endif
524 ifndef LLVM_TBLGEN
525   ifeq ($(LLVM_CROSS_COMPILING),1)
526     LLVM_TBLGEN   := $(BuildLLVMToolDir)/llvm-tblgen$(BUILD_EXEEXT)
527   else
528     LLVM_TBLGEN   := $(LLVMToolDir)/llvm-tblgen$(EXEEXT)
529   endif
530 endif
531 ifeq ($(LLVM_CROSS_COMPILING),1)
532   LLVM_CONFIG := $(BuildLLVMToolDir)/llvm-config$(BUILD_EXEEXT)
533 else
534   LLVM_CONFIG := $(LLVMToolDir)/llvm-config$(EXEEXT)
535 endif
536 ifndef LLVMLD
537 LLVMLD    := $(LLVMToolDir)/llvm-ld$(EXEEXT)
538 endif
539 ifndef LLVMDIS
540 LLVMDIS  := $(LLVMToolDir)/llvm-dis$(EXEEXT)
541 endif
542 ifndef LLI
543 LLI      := $(LLVMToolDir)/lli$(EXEEXT)
544 endif
545 ifndef LLC
546 LLC      := $(LLVMToolDir)/llc$(EXEEXT)
547 endif
548 ifndef LOPT
549 LOPT     := $(LLVMToolDir)/opt$(EXEEXT)
550 endif
551 ifndef LBUGPOINT
552 LBUGPOINT := $(LLVMToolDir)/bugpoint$(EXEEXT)
553 endif
555 #--------------------------------------------------------------------
556 # Adjust to user's request
557 #--------------------------------------------------------------------
559 ifeq ($(HOST_OS),Darwin)
560   DARWIN_VERSION := `sw_vers -productVersion`
561   # Strip a number like 10.4.7 to 10.4
562   DARWIN_VERSION := $(shell echo $(DARWIN_VERSION)| sed -E 's/(10.[0-9]).*/\1/')
563   # Get "4" out of 10.4 for later pieces in the makefile.
564   DARWIN_MAJVERS := $(shell echo $(DARWIN_VERSION)| sed -E 's/10.([0-9]).*/\1/')
566   LoadableModuleOptions := -Wl,-flat_namespace -Wl,-undefined,suppress
567   SharedLinkOptions := -dynamiclib
568   ifneq ($(ARCH),ARM)
569     SharedLinkOptions += -mmacosx-version-min=$(DARWIN_VERSION)
570   endif
571 else
572   SharedLinkOptions=-shared
573 endif
575 ifeq ($(TARGET_OS),Darwin)
576   ifneq ($(ARCH),ARM)
577     TargetCommonOpts += -mmacosx-version-min=$(DARWIN_VERSION)
578   endif
579 endif
581 ifdef SHARED_LIBRARY
582 ifneq ($(HOST_OS), $(filter $(HOST_OS), Cygwin MingW))
583 ifneq ($(HOST_OS),Darwin)
584   LD.Flags += $(RPATH) -Wl,'$$ORIGIN'
585 endif
586 endif
587 endif
589 ifdef TOOL_VERBOSE
590   C.Flags += -v
591   CXX.Flags += -v
592   LD.Flags += -v
593   VERBOSE := 1
594 endif
596 # Adjust settings for verbose mode
597 ifndef VERBOSE
598   Verb := @
599   AR.Flags += >/dev/null 2>/dev/null
600   ConfigureScriptFLAGS += >$(PROJ_OBJ_DIR)/configure.out 2>&1
601 else
602   ConfigureScriptFLAGS :=
603 endif
605 # By default, strip symbol information from executable
606 ifndef KEEP_SYMBOLS
607   Strip := $(PLATFORMSTRIPOPTS)
608   StripWarnMsg := "(without symbols)"
609   Install.StripFlag += -s
610 endif
612 ifdef TOOL_NO_EXPORTS
613   DynamicFlags :=
614 else
615   DynamicFlag := $(RDYNAMIC)
616 endif
618 # Adjust linker flags for building an executable
619 ifneq ($(HOST_OS), $(filter $(HOST_OS), Cygwin MingW))
620 ifneq ($(HOST_OS), Darwin)
621 ifdef TOOLNAME
622   LD.Flags += $(RPATH) -Wl,'$$ORIGIN/../lib'
623   ifdef EXAMPLE_TOOL
624     LD.Flags += $(RPATH) -Wl,$(ExmplDir) $(DynamicFlag)
625   else
626     LD.Flags += $(RPATH) -Wl,$(ToolDir) $(DynamicFlag)
627   endif
628 endif
629 else
630 ifneq ($(DARWIN_MAJVERS),4)
631   LD.Flags += $(RPATH) -Wl,@executable_path/../lib
632 endif
633 endif
634 endif
637 #----------------------------------------------------------
638 # Options To Invoke Tools
639 #----------------------------------------------------------
641 ifdef EXTRA_LD_OPTIONS
642 LD.Flags += $(EXTRA_LD_OPTIONS)
643 endif
645 ifndef NO_PEDANTIC
646 CompileCommonOpts += -pedantic -Wno-long-long
647 endif
648 CompileCommonOpts += -Wall -W -Wno-unused-parameter -Wwrite-strings \
649                      $(EXTRA_OPTIONS)
650 # Enable cast-qual for C++; the workaround is to use const_cast.
651 CXX.Flags += -Wcast-qual
653 ifeq ($(HOST_OS),HP-UX)
654   CompileCommonOpts := -D_REENTRANT -D_HPUX_SOURCE
655 endif
657 # If we are building a universal binary on Mac OS/X, pass extra options.  This
658 # is useful to people that want to link the LLVM libraries into their universal
659 # apps.
661 # The following can be optionally specified:
662 #   UNIVERSAL_SDK_PATH variable can be specified as a path to the SDK to use.
663 #      For Mac OS/X 10.4 Intel machines, the traditional one is:
664 #      UNIVERSAL_SDK_PATH=/Developer/SDKs/MacOSX10.4u.sdk/
665 #   UNIVERSAL_ARCH can be optionally specified to be a list of architectures
666 #      to build for, e.g. UNIVERSAL_ARCH="i386 ppc ppc64".  This defaults to
667 #      i386/ppc only.
668 ifdef UNIVERSAL
669   ifndef UNIVERSAL_ARCH
670     UNIVERSAL_ARCH := i386 ppc
671   endif
672   UNIVERSAL_ARCH_OPTIONS := $(UNIVERSAL_ARCH:%=-arch %)
673   CompileCommonOpts += $(UNIVERSAL_ARCH_OPTIONS)
674   ifdef UNIVERSAL_SDK_PATH
675     CompileCommonOpts += -isysroot $(UNIVERSAL_SDK_PATH)
676   endif
678   # Building universal cannot compute dependencies automatically.
679   DISABLE_AUTO_DEPENDENCIES=1
680 else
681   ifeq ($(TARGET_OS),Darwin)
682     ifeq ($(ARCH),x86_64)
683       TargetCommonOpts = -m64
684     else
685       ifeq ($(ARCH),x86)
686         TargetCommonOpts = -m32
687       endif
688     endif
689   endif
690 endif
692 ifeq ($(HOST_OS),SunOS)
693 CPP.BaseFlags += -include llvm/Support/Solaris.h
694 endif
696 ifeq ($(HOST_OS),AuroraUX)
697 CPP.BaseFlags += -include llvm/Support/Solaris.h
698 endif # !HOST_OS - AuroraUX.
700 LD.Flags      += -L$(LibDir) -L$(LLVMLibDir)
701 CPP.BaseFlags += -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS
702 # All -I flags should go here, so that they don't confuse llvm-config.
703 CPP.Flags     += $(sort -I$(PROJ_OBJ_DIR) -I$(PROJ_SRC_DIR) \
704                  $(patsubst %,-I%/include,\
705                  $(PROJ_OBJ_ROOT) $(PROJ_SRC_ROOT) \
706                  $(LLVM_OBJ_ROOT) $(LLVM_SRC_ROOT))) \
707                  $(CPP.BaseFlags)
709 ifeq ($(INCLUDE_BUILD_DIR),1)
710   CPP.Flags   += -I$(ObjDir)
711 endif
713 # SHOW_DIAGNOSTICS support.
714 ifeq ($(SHOW_DIAGNOSTICS),1)
715   Compile.Wrapper := env CC_LOG_DIAGNOSTICS=1 \
716                           CC_LOG_DIAGNOSTICS_FILE="$(LLVM_OBJ_ROOT)/$(BuildMode)/diags"
717 else
718   Compile.Wrapper :=
719 endif
721 Compile.C     = $(Compile.Wrapper) \
722                   $(CC) $(CPP.Flags) $(C.Flags) $(CFLAGS) $(CPPFLAGS) \
723                 $(TargetCommonOpts) $(CompileCommonOpts) -c
724 Compile.CXX   = $(Compile.Wrapper) \
725                   $(CXX) $(CPP.Flags) $(CXX.Flags) $(CXXFLAGS) $(CPPFLAGS) \
726                 $(TargetCommonOpts) $(CompileCommonOpts) -c
727 Preprocess.CXX= $(Compile.Wrapper) \
728                   $(CXX) $(CPP.Flags) $(TargetCommonOpts) $(CPPFLAGS) \
729                 $(CompileCommonOpts) $(CXX.Flags) -E
730 Link          = $(Compile.Wrapper) \
731                   $(CXX) $(CPP.Flags) $(CXX.Flags) $(CXXFLAGS) $(LD.Flags) \
732                 $(LDFLAGS) $(TargetCommonOpts)  $(CompileCommonOpts) $(Strip)
734 BCCompile.C   = $(LLVMCC) $(CPP.Flags) $(C.Flags) $(CFLAGS) $(CPPFLAGS) \
735                 $(TargetCommonOpts) $(CompileCommonOpts)
736 Preprocess.C  = $(CC) $(CPP.Flags) $(C.Flags) $(CPPFLAGS) \
737                 $(TargetCommonOpts) $(CompileCommonOpts) -E
739 BCCompile.CXX = $(LLVMCXX) $(CPP.Flags) $(CXX.Flags) $(CXXFLAGS) $(CPPFLAGS) \
740                 $(TargetCommonOpts) $(CompileCommonOpts)
742 ProgInstall   = $(INSTALL) $(Install.StripFlag) -m 0755
743 ScriptInstall = $(INSTALL) -m 0755
744 DataInstall   = $(INSTALL) -m 0644
746 # When compiling under Mingw/Cygwin, the tblgen tool expects Windows
747 # paths. In this case, the SYSPATH function (defined in
748 # Makefile.config) transforms Unix paths into Windows paths.
749 TableGen.Flags= -I $(call SYSPATH, $(PROJ_SRC_DIR)) \
750                 -I $(call SYSPATH, $(LLVM_SRC_ROOT)/include) \
751                 -I $(call SYSPATH, $(PROJ_SRC_ROOT)/include) \
752                 -I $(call SYSPATH, $(PROJ_SRC_ROOT)/lib/Target)
753 LLVMTableGen  = $(LLVM_TBLGEN) $(TableGen.Flags)
755 Archive       = $(AR) $(AR.Flags)
756 LArchive      = $(LLVMToolDir)/llvm-ar rcsf
757 ifdef RANLIB
758 Ranlib        = $(RANLIB)
759 else
760 Ranlib        = ranlib
761 endif
763 AliasTool     = ln -s
765 #----------------------------------------------------------
766 # Get the list of source files and compute object file
767 # names from them.
768 #----------------------------------------------------------
770 ifndef SOURCES
771   Sources := $(notdir $(wildcard $(PROJ_SRC_DIR)/*.cpp \
772              $(PROJ_SRC_DIR)/*.cc $(PROJ_SRC_DIR)/*.c))
773 else
774   Sources := $(SOURCES)
775 endif
777 ifdef BUILT_SOURCES
778 Sources += $(filter %.cpp %.c %.cc,$(BUILT_SOURCES))
779 endif
781 BaseNameSources := $(sort $(basename $(Sources)))
783 ObjectsO  := $(BaseNameSources:%=$(ObjDir)/%.o)
784 ObjectsBC := $(BaseNameSources:%=$(ObjDir)/%.bc)
786 #----------------------------------------------------------
787 # For Mingw MSYS bash and Python/w32:
789 # $(ECHOPATH) prints DOSish pathstring.
790 #   ex) $(ECHOPATH) /include/sys/types.h
791 #   --> C:/mingw/include/sys/types.h
792 # built-in "echo" does not transform path to DOSish path.
794 # FIXME: It would not be needed when MSYS's python
795 # were provided.
796 #----------------------------------------------------------
798 ifeq (-mingw32,$(findstring -mingw32,$(BUILD_TRIPLE)))
799   ECHOPATH := $(Verb)python -u -c "import sys;print ' '.join(sys.argv[1:])"
800 else
801   ECHOPATH := $(Verb)$(ECHO)
802 endif
804 ###############################################################################
805 # DIRECTORIES: Handle recursive descent of directory structure
806 ###############################################################################
808 #---------------------------------------------------------
809 # Provide rules to make install dirs. This must be early
810 # in the file so they get built before dependencies
811 #---------------------------------------------------------
813 $(DESTDIR)$(PROJ_bindir) $(DESTDIR)$(PROJ_libdir) $(DESTDIR)$(PROJ_includedir) $(DESTDIR)$(PROJ_etcdir)::
814         $(Verb) $(MKDIR) $@
816 # To create other directories, as needed, and timestamp their creation
817 %/.dir:
818         $(Verb) $(MKDIR) $* > /dev/null
819         $(Verb) $(DOTDIR_TIMESTAMP_COMMAND) > $@
821 .PRECIOUS: $(ObjDir)/.dir $(LibDir)/.dir $(ToolDir)/.dir $(ExmplDir)/.dir
822 .PRECIOUS: $(LLVMLibDir)/.dir $(LLVMToolDir)/.dir $(LLVMExmplDir)/.dir
824 #---------------------------------------------------------
825 # Handle the DIRS options for sequential construction
826 #---------------------------------------------------------
828 SubDirs :=
829 ifdef DIRS
830 SubDirs += $(DIRS)
832 ifneq ($(PROJ_SRC_ROOT),$(PROJ_OBJ_ROOT))
833 $(RecursiveTargets)::
834         $(Verb) for dir in $(DIRS); do \
835           if ([ ! -f $$dir/Makefile ] || \
836               command test $$dir/Makefile -ot $(PROJ_SRC_DIR)/$$dir/Makefile ); then \
837             $(MKDIR) $$dir; \
838             $(CP) $(PROJ_SRC_DIR)/$$dir/Makefile $$dir/Makefile; \
839           fi; \
840           ($(MAKE) -C $$dir $@ ) || exit 1; \
841         done
842 else
843 $(RecursiveTargets)::
844         $(Verb) for dir in $(DIRS); do \
845           ($(MAKE) -C $$dir $@ ) || exit 1; \
846         done
847 endif
849 endif
851 #---------------------------------------------------------
852 # Handle the EXPERIMENTAL_DIRS options ensuring success
853 # after each directory is built.
854 #---------------------------------------------------------
855 ifdef EXPERIMENTAL_DIRS
856 $(RecursiveTargets)::
857         $(Verb) for dir in $(EXPERIMENTAL_DIRS); do \
858           if ([ ! -f $$dir/Makefile ] || \
859               command test $$dir/Makefile -ot $(PROJ_SRC_DIR)/$$dir/Makefile ); then \
860             $(MKDIR) $$dir; \
861             $(CP) $(PROJ_SRC_DIR)/$$dir/Makefile $$dir/Makefile; \
862           fi; \
863           ($(MAKE) -C $$dir $@ ) || exit 0; \
864         done
865 endif
867 #-----------------------------------------------------------
868 # Handle the OPTIONAL_PARALLEL_DIRS options for optional parallel construction
869 #-----------------------------------------------------------
870 ifdef OPTIONAL_PARALLEL_DIRS
871   PARALLEL_DIRS += $(foreach T,$(OPTIONAL_PARALLEL_DIRS),$(shell test -d $(PROJ_SRC_DIR)/$(T) -o -f $(T)/Makefile && echo "$(T)"))
872 endif
874 #-----------------------------------------------------------
875 # Handle the PARALLEL_DIRS options for parallel construction
876 #-----------------------------------------------------------
877 ifdef PARALLEL_DIRS
879 SubDirs += $(PARALLEL_DIRS)
881 # Unfortunately, this list must be maintained if new recursive targets are added
882 all      :: $(addsuffix /.makeall      ,$(PARALLEL_DIRS))
883 clean    :: $(addsuffix /.makeclean    ,$(PARALLEL_DIRS))
884 clean-all:: $(addsuffix /.makeclean-all,$(PARALLEL_DIRS))
885 install  :: $(addsuffix /.makeinstall  ,$(PARALLEL_DIRS))
886 uninstall:: $(addsuffix /.makeuninstall,$(PARALLEL_DIRS))
887 install-bytecode  :: $(addsuffix /.makeinstall-bytecode,$(PARALLEL_DIRS))
888 unitcheck:: $(addsuffix /.makeunitcheck,$(PARALLEL_DIRS))
890 ParallelTargets := $(foreach T,$(RecursiveTargets),%/.make$(T))
892 $(ParallelTargets) :
893         $(Verb) \
894           SD=$(PROJ_SRC_DIR)/$(@D); \
895           DD=$(@D); \
896           if [ ! -f $$SD/Makefile ]; then \
897             SD=$(@D); \
898             DD=$(notdir $(@D)); \
899           fi; \
900           if ([ ! -f $$DD/Makefile ] || \
901                     command test $$DD/Makefile -ot \
902                       $$SD/Makefile ); then \
903           $(MKDIR) $$DD; \
904           $(CP) $$SD/Makefile $$DD/Makefile; \
905         fi; \
906         $(MAKE) -C $$DD $(subst $(@D)/.make,,$@)
907 endif
909 #---------------------------------------------------------
910 # Handle the OPTIONAL_DIRS options for directores that may
911 # or may not exist.
912 #---------------------------------------------------------
913 ifdef OPTIONAL_DIRS
915 SubDirs += $(OPTIONAL_DIRS)
917 ifneq ($(PROJ_SRC_ROOT),$(PROJ_OBJ_ROOT))
918 $(RecursiveTargets)::
919         $(Verb) for dir in $(OPTIONAL_DIRS); do \
920           if [ -d $(PROJ_SRC_DIR)/$$dir ]; then\
921             if ([ ! -f $$dir/Makefile ] || \
922                 command test $$dir/Makefile -ot $(PROJ_SRC_DIR)/$$dir/Makefile ); then \
923               $(MKDIR) $$dir; \
924               $(CP) $(PROJ_SRC_DIR)/$$dir/Makefile $$dir/Makefile; \
925             fi; \
926             ($(MAKE) -C$$dir $@ ) || exit 1; \
927           fi \
928         done
929 else
930 $(RecursiveTargets)::
931         $(Verb) for dir in $(OPTIONAL_DIRS); do \
932           if [ -d $(PROJ_SRC_DIR)/$$dir ]; then\
933             ($(MAKE) -C$$dir $@ ) || exit 1; \
934           fi \
935         done
936 endif
937 endif
939 #---------------------------------------------------------
940 # Handle the CONFIG_FILES options
941 #---------------------------------------------------------
942 ifdef CONFIG_FILES
944 ifdef NO_INSTALL
945 install-local::
946         $(Echo) Install circumvented with NO_INSTALL
947 uninstall-local::
948         $(Echo) UnInstall circumvented with NO_INSTALL
949 else
950 install-local:: $(DESTDIR)$(PROJ_etcdir) $(CONFIG_FILES)
951         $(Echo) Installing Configuration Files To $(DESTDIR)$(PROJ_etcdir)
952         $(Verb)for file in $(CONFIG_FILES); do \
953           if test -f $(PROJ_OBJ_DIR)/$${file} ; then \
954             $(DataInstall) $(PROJ_OBJ_DIR)/$${file} $(DESTDIR)$(PROJ_etcdir) ; \
955           elif test -f $(PROJ_SRC_DIR)/$${file} ; then \
956             $(DataInstall) $(PROJ_SRC_DIR)/$${file} $(DESTDIR)$(PROJ_etcdir) ; \
957           else \
958             $(ECHO) Error: cannot find config file $${file}. ; \
959           fi \
960         done
962 uninstall-local::
963         $(Echo) Uninstalling Configuration Files From $(DESTDIR)$(PROJ_etcdir)
964         $(Verb)for file in $(CONFIG_FILES); do \
965           $(RM) -f $(DESTDIR)$(PROJ_etcdir)/$${file} ; \
966         done
967 endif
969 endif
971 ###############################################################################
972 # Set up variables for building libraries
973 ###############################################################################
975 #---------------------------------------------------------
976 # Define various command line options pertaining to the
977 # libraries needed when linking. There are "Proj" libs
978 # (defined by the user's project) and "LLVM" libs (defined
979 # by the LLVM project).
980 #---------------------------------------------------------
982 ifdef USEDLIBS
983 ProjLibsOptions := $(patsubst %.a.o, -l%, $(addsuffix .o, $(USEDLIBS)))
984 ProjLibsOptions := $(patsubst %.o, $(LibDir)/%.o,  $(ProjLibsOptions))
985 ProjUsedLibs    := $(patsubst %.a.o, lib%.a, $(addsuffix .o, $(USEDLIBS)))
986 ProjLibsPaths   := $(addprefix $(LibDir)/,$(ProjUsedLibs))
987 endif
989 ifdef LLVMLIBS
990 LLVMLibsOptions := $(patsubst %.a.o, -l%, $(addsuffix .o, $(LLVMLIBS)))
991 LLVMLibsOptions := $(patsubst %.o, $(LLVMLibDir)/%.o, $(LLVMLibsOptions))
992 LLVMUsedLibs    := $(patsubst %.a.o, lib%.a, $(addsuffix .o, $(LLVMLIBS)))
993 LLVMLibsPaths   := $(addprefix $(LLVMLibDir)/,$(LLVMUsedLibs))
994 endif
996 # Loadable module for Win32 requires all symbols resolved for linking.
997 # Then all symbols in LLVM.dll will be available.
998 ifeq ($(ENABLE_SHARED),1)
999   ifdef LOADABLE_MODULE
1000     ifneq (,$(filter $(HOST_OS),Cygwin MingW))
1001       LINK_COMPONENTS += all
1002     endif
1003   endif
1004 endif
1006 ifndef IS_CLEANING_TARGET
1007 ifdef LINK_COMPONENTS
1009 # If LLVM_CONFIG doesn't exist, build it.  This can happen if you do a make
1010 # clean in tools, then do a make in tools (instead of at the top level).
1011 $(LLVM_CONFIG):
1012         @echo "*** llvm-config doesn't exist - rebuilding it."
1013         @$(MAKE) -C $(PROJ_OBJ_ROOT)/tools/llvm-config
1015 $(ToolDir)/$(strip $(TOOLNAME))$(EXEEXT): $(LLVM_CONFIG)
1017 ifeq ($(ENABLE_SHARED), 1)
1018 # We can take the "auto-import" feature to get rid of using dllimport.
1019 ifeq ($(HOST_OS), $(filter $(HOST_OS), Cygwin MingW))
1020 LLVMLibsOptions += -Wl,--enable-auto-import,--enable-runtime-pseudo-reloc \
1021                    -L $(SharedLibDir)
1022 endif
1023 LLVMLibsOptions += -lLLVM-$(LLVMVersion)
1024 LLVMLibsPaths += $(SharedLibDir)/$(SharedPrefix)LLVM-$(LLVMVersion)$(SHLIBEXT)
1025 else
1027 ifndef NO_LLVM_CONFIG
1028 LLVMConfigLibs := $(shell $(LLVM_CONFIG) --libs $(LINK_COMPONENTS) || echo Error)
1029 ifeq ($(LLVMConfigLibs),Error)
1030 $(error llvm-config --libs failed)
1031 endif
1032 LLVMLibsOptions += $(LLVMConfigLibs)
1033 LLVMConfigLibfiles := $(shell $(LLVM_CONFIG) --libfiles $(LINK_COMPONENTS) || echo Error)
1034 ifeq ($(LLVMConfigLibfiles),Error)
1035 $(error llvm-config --libfiles failed)
1036 endif
1037 LLVMLibsPaths += $(LLVM_CONFIG) $(LLVMConfigLibfiles)
1038 endif
1040 endif
1041 endif
1042 endif
1044 # Set up the library exports file.
1045 ifdef EXPORTED_SYMBOL_FILE
1047 # First, set up the native export file, which may differ from the source
1048 # export file.
1050 ifeq ($(HOST_OS),Darwin)
1051 # Darwin convention prefixes symbols with underscores.
1052 NativeExportsFile := $(ObjDir)/$(notdir $(EXPORTED_SYMBOL_FILE)).sed
1053 $(NativeExportsFile): $(EXPORTED_SYMBOL_FILE) $(ObjDir)/.dir
1054         $(Verb) sed -e 's/^/_/' < $< > $@
1055 clean-local::
1056         -$(Verb) $(RM) -f $(NativeExportsFile)
1057 else
1058 ifeq ($(HAVE_LINK_VERSION_SCRIPT),1)
1059 # Gold and BFD ld require a version script rather than a plain list.
1060 NativeExportsFile := $(ObjDir)/$(notdir $(EXPORTED_SYMBOL_FILE)).map
1061 $(NativeExportsFile): $(EXPORTED_SYMBOL_FILE) $(ObjDir)/.dir
1062         $(Verb) echo "{" > $@
1063         $(Verb) grep -q "\<" $< && echo "  global:" >> $@ || :
1064         $(Verb) sed -e 's/$$/;/' -e 's/^/    /' < $< >> $@
1065 ifneq ($(HOST_OS),OpenBSD)
1066         $(Verb) echo "  local: *;" >> $@
1067 endif
1068         $(Verb) echo "};" >> $@
1069 clean-local::
1070         -$(Verb) $(RM) -f $(NativeExportsFile)
1071 else
1072 ifeq ($(HOST_OS), $(filter $(HOST_OS), Cygwin MingW))
1073 # GNU ld Win32 accepts .DEF files that contain "DATA" entries.
1074 NativeExportsFile := $(ObjDir)/$(notdir $(EXPORTED_SYMBOL_FILE:.exports=.def))
1075 $(NativeExportsFile): $(EXPORTED_SYMBOL_FILE) $(ObjDir)/.dir
1076         $(Echo) Generating $(notdir $@)
1077         $(Verb) $(ECHO) "EXPORTS" > $@
1078         $(Verb) $(CAT) $< >> $@
1079 clean-local::
1080         -$(Verb) $(RM) -f $(NativeExportsFile)
1081 else
1082 # Default behavior: just use the exports file verbatim.
1083 NativeExportsFile := $(EXPORTED_SYMBOL_FILE)
1084 endif
1085 endif
1086 endif
1088 # Now add the linker command-line options to use the native export file.
1090 # Darwin
1091 ifeq ($(HOST_OS),Darwin)
1092 LLVMLibsOptions += -Wl,-exported_symbols_list,$(NativeExportsFile)
1093 endif
1095 # gold, bfd ld, etc.
1096 ifeq ($(HAVE_LINK_VERSION_SCRIPT),1)
1097 LLVMLibsOptions += -Wl,--version-script,$(NativeExportsFile)
1098 endif
1100 # Windows
1101 ifeq ($(HOST_OS), $(filter $(HOST_OS), Cygwin MingW))
1102 # LLVMLibsOptions is invalidated at processing tools/llvm-shlib.
1103 SharedLinkOptions += $(NativeExportsFile)
1104 endif
1106 endif
1108 ###############################################################################
1109 # Library Build Rules: Four ways to build a library
1110 ###############################################################################
1112 #---------------------------------------------------------
1113 # Bytecode Module Targets:
1114 #   If the user set MODULE_NAME then they want to build a
1115 #   bytecode module from the sources. We compile all the
1116 #   sources and link it together into a single bytecode
1117 #   module.
1118 #---------------------------------------------------------
1120 ifdef MODULE_NAME
1121 ifeq ($(strip $(LLVMCC)),)
1122 $(warning Modules require LLVM capable compiler but none is available ****)
1123 else
1125 Module     := $(LibDir)/$(MODULE_NAME).bc
1126 LinkModule := $(LLVMLD) -r
1129 ifdef EXPORTED_SYMBOL_FILE
1130 LinkModule += -internalize-public-api-file=$(EXPORTED_SYMBOL_FILE)
1131 endif
1133 $(Module): $(BUILT_SOURCES) $(ObjectsBC) $(LibDir)/.dir $(LLVMLD)
1134         $(Echo) Building $(BuildMode) Bytecode Module $(notdir $@)
1135         $(Verb) $(LinkModule) -o $@ $(ObjectsBC)
1137 all-local:: $(Module)
1139 clean-local::
1140 ifneq ($(strip $(Module)),)
1141         -$(Verb) $(RM) -f $(Module)
1142 endif
1144 ifdef BYTECODE_DESTINATION
1145 ModuleDestDir := $(BYTECODE_DESTINATION)
1146 else
1147 ModuleDestDir := $(DESTDIR)$(PROJ_libdir)
1148 endif
1150 ifdef NO_INSTALL
1151 install-local::
1152         $(Echo) Install circumvented with NO_INSTALL
1153 uninstall-local::
1154         $(Echo) Uninstall circumvented with NO_INSTALL
1155 else
1156 DestModule := $(ModuleDestDir)/$(MODULE_NAME).bc
1158 install-module:: $(DestModule)
1159 install-local:: $(DestModule)
1161 $(DestModule): $(ModuleDestDir) $(Module)
1162         $(Echo) Installing $(BuildMode) Bytecode Module $(DestModule)
1163         $(Verb) $(DataInstall) $(Module) $(DestModule)
1165 uninstall-local::
1166         $(Echo) Uninstalling $(BuildMode) Bytecode Module $(DestModule)
1167         -$(Verb) $(RM) -f $(DestModule)
1168 endif
1170 endif
1171 endif
1173 # if we're building a library ...
1174 ifdef LIBRARYNAME
1176 # Make sure there isn't any extraneous whitespace on the LIBRARYNAME option
1177 LIBRARYNAME := $(strip $(LIBRARYNAME))
1178 ifdef LOADABLE_MODULE
1179 BaseLibName.A  := $(LIBRARYNAME).a
1180 BaseLibName.SO := $(LIBRARYNAME)$(SHLIBEXT)
1181 else
1182 BaseLibName.A  := lib$(LIBRARYNAME).a
1183 BaseLibName.SO := $(SharedPrefix)$(LIBRARYNAME)$(SHLIBEXT)
1184 endif
1185 LibName.A  := $(LibDir)/$(BaseLibName.A)
1186 LibName.SO := $(SharedLibDir)/$(BaseLibName.SO)
1187 LibName.O  := $(LibDir)/$(LIBRARYNAME).o
1188 LibName.BCA:= $(LibDir)/lib$(LIBRARYNAME).bca
1190 #---------------------------------------------------------
1191 # Shared Library Targets:
1192 #   If the user asked for a shared library to be built
1193 #   with the SHARED_LIBRARY variable, then we provide
1194 #   targets for building them.
1195 #---------------------------------------------------------
1196 ifdef SHARED_LIBRARY
1198 all-local:: $(LibName.SO)
1200 ifdef EXPORTED_SYMBOL_FILE
1201 $(LibName.SO): $(NativeExportsFile)
1202 endif
1204 ifdef LINK_LIBS_IN_SHARED
1205 ifdef LOADABLE_MODULE
1206 SharedLibKindMessage := "Loadable Module"
1207 SharedLinkOptions := $(LoadableModuleOptions) $(SharedLinkOptions)
1208 else
1209 SharedLibKindMessage := "Shared Library"
1210 endif
1211 $(LibName.SO): $(ObjectsO) $(ProjLibsPaths) $(LLVMLibsPaths) $(SharedLibDir)/.dir
1212         $(Echo) Linking $(BuildMode) $(SharedLibKindMessage) \
1213           $(notdir $@)
1214         $(Verb) $(Link) $(SharedLinkOptions) -o $@ $(ObjectsO) \
1215           $(ProjLibsOptions) $(LLVMLibsOptions) $(LIBS)
1216 else
1217 $(LibName.SO): $(ObjectsO) $(SharedLibDir)/.dir
1218         $(Echo) Linking $(BuildMode) Shared Library $(notdir $@)
1219         $(Verb) $(Link) $(SharedLinkOptions) -o $@ $(ObjectsO)
1220 endif
1222 clean-local::
1223 ifneq ($(strip $(LibName.SO)),)
1224         -$(Verb) $(RM) -f $(LibName.SO)
1225 endif
1227 ifdef NO_INSTALL
1228 install-local::
1229         $(Echo) Install circumvented with NO_INSTALL
1230 uninstall-local::
1231         $(Echo) Uninstall circumvented with NO_INSTALL
1232 else
1234 # Win32.DLL prefers to be located on the "PATH" of binaries.
1235 ifeq ($(HOST_OS), $(filter $(HOST_OS), Cygwin MingW))
1236 DestSharedLibDir := $(DESTDIR)$(PROJ_bindir)
1237 else
1238 DestSharedLibDir := $(DESTDIR)$(PROJ_libdir)
1239 endif
1240 DestSharedLib := $(DestSharedLibDir)/$(BaseLibName.SO)
1242 install-local:: $(DestSharedLib)
1244 $(DestSharedLib): $(LibName.SO) $(DestSharedLibDir)
1245         $(Echo) Installing $(BuildMode) Shared Library $(DestSharedLib)
1246         $(Verb) $(INSTALL) $(LibName.SO) $(DestSharedLib)
1248 uninstall-local::
1249         $(Echo) Uninstalling $(BuildMode) Shared Library $(DestSharedLib)
1250         -$(Verb) $(RM) -f $(DestSharedLibDir)/$(SharedPrefix)$(LIBRARYNAME).*
1251 endif
1252 endif
1254 #---------------------------------------------------------
1255 # Bytecode Library Targets:
1256 #   If the user asked for a bytecode library to be built
1257 #   with the BYTECODE_LIBRARY variable, then we provide
1258 #   targets for building them.
1259 #---------------------------------------------------------
1260 ifdef BYTECODE_LIBRARY
1261 ifeq ($(strip $(LLVMCC)),)
1262 $(warning Bytecode libraries require LLVM capable compiler but none is available ****)
1263 else
1265 all-local:: $(LibName.BCA)
1267 ifdef EXPORTED_SYMBOL_FILE
1268 BCLinkLib = $(LLVMLD) -internalize-public-api-file=$(EXPORTED_SYMBOL_FILE)
1270 $(LibName.BCA): $(ObjectsBC) $(LibDir)/.dir $(LLVMLD) \
1271                 $(LLVMToolDir)/llvm-ar
1272         $(Echo) Building $(BuildMode) Bytecode Archive $(notdir $@) \
1273           "(internalize)"
1274         $(Verb) $(BCLinkLib) -o $(ObjDir)/$(LIBRARYNAME).internalize $(ObjectsBC)
1275         $(Verb) $(RM) -f $@
1276         $(Verb) $(LArchive) $@ $(ObjDir)/$(LIBRARYNAME).internalize.bc
1277 else
1278 $(LibName.BCA): $(ObjectsBC) $(LibDir)/.dir \
1279                 $(LLVMToolDir)/llvm-ar
1280         $(Echo) Building $(BuildMode) Bytecode Archive $(notdir $@)
1281         $(Verb) $(RM) -f $@
1282         $(Verb) $(LArchive) $@ $(ObjectsBC)
1284 endif
1286 clean-local::
1287 ifneq ($(strip $(LibName.BCA)),)
1288         -$(Verb) $(RM) -f $(LibName.BCA)
1289 endif
1291 ifdef BYTECODE_DESTINATION
1292 BytecodeDestDir := $(BYTECODE_DESTINATION)
1293 else
1294 BytecodeDestDir := $(DESTDIR)$(PROJ_libdir)
1295 endif
1297 DestBytecodeLib = $(BytecodeDestDir)/lib$(LIBRARYNAME).bca
1299 install-bytecode-local:: $(DestBytecodeLib)
1301 ifdef NO_INSTALL
1302 install-local::
1303         $(Echo) Install circumvented with NO_INSTALL
1304 uninstall-local::
1305         $(Echo) Uninstall circumvented with NO_INSTALL
1306 else
1307 install-local:: $(DestBytecodeLib)
1309 $(DestBytecodeLib): $(LibName.BCA) $(BytecodeDestDir)
1310         $(Echo) Installing $(BuildMode) Bytecode Archive $(DestBytecodeLib)
1311         $(Verb) $(DataInstall) $(LibName.BCA) $(DestBytecodeLib)
1313 uninstall-local::
1314         $(Echo) Uninstalling $(BuildMode) Bytecode Archive $(DestBytecodeLib)
1315         -$(Verb) $(RM) -f $(DestBytecodeLib)
1316 endif
1317 endif
1318 endif
1320 #---------------------------------------------------------
1321 # Library Targets:
1322 #   If neither BUILD_ARCHIVE or LOADABLE_MODULE are specified, default to
1323 #   building an archive.
1324 #---------------------------------------------------------
1325 ifndef NO_BUILD_ARCHIVE
1326 ifndef BUILD_ARCHIVE
1327 ifndef LOADABLE_MODULE
1328 BUILD_ARCHIVE = 1
1329 endif
1330 endif
1331 endif
1333 #---------------------------------------------------------
1334 # Archive Library Targets:
1335 #   If the user wanted a regular archive library built,
1336 #   then we provide targets for building them.
1337 #---------------------------------------------------------
1338 ifdef BUILD_ARCHIVE
1340 all-local:: $(LibName.A)
1342 $(LibName.A): $(ObjectsO) $(LibDir)/.dir
1343         $(Echo) Building $(BuildMode) Archive Library $(notdir $@)
1344         -$(Verb) $(RM) -f $@
1345         $(Verb) $(Archive) $@ $(ObjectsO)
1346         $(Verb) $(Ranlib) $@
1348 clean-local::
1349 ifneq ($(strip $(LibName.A)),)
1350         -$(Verb) $(RM) -f $(LibName.A)
1351 endif
1353 ifdef NO_INSTALL
1354 install-local::
1355         $(Echo) Install circumvented with NO_INSTALL
1356 uninstall-local::
1357         $(Echo) Uninstall circumvented with NO_INSTALL
1358 else
1359 ifdef NO_INSTALL_ARCHIVES
1360 install-local::
1361         $(Echo) Install circumvented with NO_INSTALL
1362 uninstall-local::
1363         $(Echo) Uninstall circumvented with NO_INSTALL
1364 else
1365 DestArchiveLib := $(DESTDIR)$(PROJ_libdir)/lib$(LIBRARYNAME).a
1367 install-local:: $(DestArchiveLib)
1369 $(DestArchiveLib): $(LibName.A) $(DESTDIR)$(PROJ_libdir)
1370         $(Echo) Installing $(BuildMode) Archive Library $(DestArchiveLib)
1371         $(Verb) $(MKDIR) $(DESTDIR)$(PROJ_libdir)
1372         $(Verb) $(INSTALL) $(LibName.A) $(DestArchiveLib)
1374 uninstall-local::
1375         $(Echo) Uninstalling $(BuildMode) Archive Library $(DestArchiveLib)
1376         -$(Verb) $(RM) -f $(DestArchiveLib)
1377 endif
1378 endif
1379 endif
1381 # endif LIBRARYNAME
1382 endif
1384 ###############################################################################
1385 # Tool Build Rules: Build executable tool based on TOOLNAME option
1386 ###############################################################################
1388 ifdef TOOLNAME
1390 #---------------------------------------------------------
1391 # Set up variables for building a tool.
1392 #---------------------------------------------------------
1393 TOOLEXENAME := $(strip $(TOOLNAME))$(EXEEXT)
1394 ifdef EXAMPLE_TOOL
1395 ToolBuildPath   := $(ExmplDir)/$(TOOLEXENAME)
1396 else
1397 ToolBuildPath   := $(ToolDir)/$(TOOLEXENAME)
1398 endif
1400 # TOOLALIAS is a name to symlink (or copy) the tool to.
1401 ifdef TOOLALIAS
1402 ifdef EXAMPLE_TOOL
1403 ToolAliasBuildPath   := $(ExmplDir)/$(strip $(TOOLALIAS))$(EXEEXT)
1404 else
1405 ToolAliasBuildPath   := $(ToolDir)/$(strip $(TOOLALIAS))$(EXEEXT)
1406 endif
1407 endif
1409 #---------------------------------------------------------
1410 # Prune Exports
1411 #---------------------------------------------------------
1413 # If the tool opts in with TOOL_NO_EXPORTS, optimize startup time of the app by
1414 # not exporting all of the weak symbols from the binary.  This reduces dyld
1415 # startup time by 4x on darwin in some cases.
1416 ifdef TOOL_NO_EXPORTS
1417 ifeq ($(HOST_OS),Darwin)
1419 # Tiger tools don't support this.
1420 ifneq ($(DARWIN_MAJVERS),4)
1421 LD.Flags += -Wl,-exported_symbol,_main
1422 endif
1423 endif
1425 ifeq ($(HOST_OS), $(filter $(HOST_OS), Linux NetBSD FreeBSD))
1426 ifneq ($(ARCH), Mips)
1427   LD.Flags += -Wl,--version-script=$(LLVM_SRC_ROOT)/autoconf/ExportMap.map
1428 endif
1429 endif
1430 endif
1432 #---------------------------------------------------------
1433 # Tool Order File Support
1434 #---------------------------------------------------------
1436 ifeq ($(HOST_OS),Darwin)
1437 ifdef TOOL_ORDER_FILE
1439 LD.Flags += -Wl,-order_file,$(TOOL_ORDER_FILE)
1441 endif
1442 endif
1444 #---------------------------------------------------------
1445 # Tool Version Info Support
1446 #---------------------------------------------------------
1448 ifeq ($(HOST_OS),Darwin)
1449 ifdef TOOL_INFO_PLIST
1451 LD.Flags += -Wl,-sectcreate,__TEXT,__info_plist,$(ObjDir)/$(TOOL_INFO_PLIST)
1453 $(ToolBuildPath): $(ObjDir)/$(TOOL_INFO_PLIST)
1455 $(ObjDir)/$(TOOL_INFO_PLIST): $(PROJ_SRC_DIR)/$(TOOL_INFO_PLIST).in $(ObjDir)/.dir
1456         $(Echo) "Creating $(TOOLNAME) '$(TOOL_INFO_PLIST)' file..."
1457         $(Verb)sed -e "s#@TOOL_INFO_UTI@#$(TOOL_INFO_UTI)#g" \
1458                    -e "s#@TOOL_INFO_NAME@#$(TOOL_INFO_NAME)#g" \
1459                    -e "s#@TOOL_INFO_VERSION@#$(TOOL_INFO_VERSION)#g" \
1460                  -e "s#@TOOL_INFO_BUILD_VERSION@#$(TOOL_INFO_BUILD_VERSION)#g" \
1461                    $< > $@
1463 endif
1464 endif
1466 #---------------------------------------------------------
1467 # Provide targets for building the tools
1468 #---------------------------------------------------------
1469 all-local:: $(ToolBuildPath) $(ToolAliasBuildPath)
1471 clean-local::
1472 ifneq ($(strip $(ToolBuildPath)),)
1473         -$(Verb) $(RM) -f $(ToolBuildPath)
1474 endif
1475 ifneq ($(strip $(ToolAliasBuildPath)),)
1476         -$(Verb) $(RM) -f $(ToolAliasBuildPath)
1477 endif
1479 ifdef EXAMPLE_TOOL
1480 $(ToolBuildPath): $(ExmplDir)/.dir
1481 else
1482 $(ToolBuildPath): $(ToolDir)/.dir
1483 endif
1485 $(ToolBuildPath): $(ObjectsO) $(ProjLibsPaths) $(LLVMLibsPaths)
1486         $(Echo) Linking $(BuildMode) executable $(TOOLNAME) $(StripWarnMsg)
1487         $(Verb) $(Link) -o $@ $(TOOLLINKOPTS) $(ObjectsO) $(ProjLibsOptions) \
1488         $(LLVMLibsOptions) $(ExtraLibs) $(TOOLLINKOPTSB) $(LIBS)
1489         $(Echo) ======= Finished Linking $(BuildMode) Executable $(TOOLNAME) \
1490           $(StripWarnMsg)
1492 ifneq ($(strip $(ToolAliasBuildPath)),)
1493 $(ToolAliasBuildPath): $(ToolBuildPath)
1494         $(Echo) Creating $(BuildMode) Alias $(TOOLALIAS) $(StripWarnMsg)
1495         $(Verb) $(RM) -f $(ToolAliasBuildPath)
1496         $(Verb) $(AliasTool) $(TOOLEXENAME) $(ToolAliasBuildPath)
1497         $(Echo) ======= Finished Creating $(BuildMode) Alias $(TOOLALIAS) \
1498           $(StripWarnMsg)
1499 endif
1501 ifdef NO_INSTALL
1502 install-local::
1503         $(Echo) Install circumvented with NO_INSTALL
1504 uninstall-local::
1505         $(Echo) Uninstall circumvented with NO_INSTALL
1506 else
1508 ifdef INTERNAL_TOOL
1509 ToolBinDir = $(DESTDIR)$(PROJ_internal_prefix)/bin
1510 else
1511 ToolBinDir = $(DESTDIR)$(PROJ_bindir)
1512 endif
1513 DestTool = $(ToolBinDir)/$(TOOLEXENAME)
1515 install-local:: $(DestTool)
1517 $(DestTool): $(ToolBuildPath)
1518         $(Echo) Installing $(BuildMode) $(DestTool)
1519         $(Verb) $(MKDIR) $(ToolBinDir)
1520         $(Verb) $(ProgInstall) $(ToolBuildPath) $(DestTool)
1522 uninstall-local::
1523         $(Echo) Uninstalling $(BuildMode) $(DestTool)
1524         -$(Verb) $(RM) -f $(DestTool)
1526 # TOOLALIAS install.
1527 ifdef TOOLALIAS
1528 DestToolAlias = $(ToolBinDir)/$(TOOLALIAS)$(EXEEXT)
1530 install-local:: $(DestToolAlias)
1532 $(DestToolAlias): $(DestTool)
1533         $(Echo) Installing $(BuildMode) $(DestToolAlias)
1534         $(Verb) $(RM) -f $(DestToolAlias)
1535         $(Verb) $(AliasTool) $(TOOLEXENAME) $(DestToolAlias)
1537 uninstall-local::
1538         $(Echo) Uninstalling $(BuildMode) $(DestToolAlias)
1539         -$(Verb) $(RM) -f $(DestToolAlias)
1540 endif
1542 endif
1543 endif
1545 ###############################################################################
1546 # Object Build Rules: Build object files based on sources
1547 ###############################################################################
1549 # FIXME: This should be checking for "if not GCC or ICC", not for "if HP-UX"
1550 ifeq ($(HOST_OS),HP-UX)
1551   DISABLE_AUTO_DEPENDENCIES=1
1552 endif
1554 # Provide rule sets for when dependency generation is enabled
1555 ifndef DISABLE_AUTO_DEPENDENCIES
1557 #---------------------------------------------------------
1558 # Create .o files in the ObjDir directory from the .cpp and .c files...
1559 #---------------------------------------------------------
1561 DEPEND_OPTIONS = -MMD -MP -MF "$(ObjDir)/$*.d.tmp" \
1562          -MT "$(ObjDir)/$*.o" -MT "$(ObjDir)/$*.d"
1564 # If the build succeeded, move the dependency file over, otherwise
1565 # remove it.
1566 DEPEND_MOVEFILE = then $(MV) -f "$(ObjDir)/$*.d.tmp" "$(ObjDir)/$*.d"; \
1567                   else $(RM) "$(ObjDir)/$*.d.tmp"; exit 1; fi
1569 $(ObjDir)/%.o: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES) $(PROJ_MAKEFILE)
1570         $(Echo) "Compiling $*.cpp for $(BuildMode) build" $(PIC_FLAG)
1571         $(Verb) if $(Compile.CXX) $(DEPEND_OPTIONS) $< -o $(ObjDir)/$*.o ; \
1572                 $(DEPEND_MOVEFILE)
1574 $(ObjDir)/%.o: %.mm $(ObjDir)/.dir $(BUILT_SOURCES) $(PROJ_MAKEFILE)
1575         $(Echo) "Compiling $*.mm for $(BuildMode) build" $(PIC_FLAG)
1576         $(Verb) if $(Compile.CXX) $(DEPEND_OPTIONS) $< -o $(ObjDir)/$*.o ; \
1577                 $(DEPEND_MOVEFILE)
1579 $(ObjDir)/%.o: %.cc $(ObjDir)/.dir $(BUILT_SOURCES) $(PROJ_MAKEFILE)
1580         $(Echo) "Compiling $*.cc for $(BuildMode) build" $(PIC_FLAG)
1581         $(Verb) if $(Compile.CXX) $(DEPEND_OPTIONS) $< -o $(ObjDir)/$*.o ; \
1582                 $(DEPEND_MOVEFILE)
1584 $(ObjDir)/%.o: %.c $(ObjDir)/.dir $(BUILT_SOURCES) $(PROJ_MAKEFILE)
1585         $(Echo) "Compiling $*.c for $(BuildMode) build" $(PIC_FLAG)
1586         $(Verb) if $(Compile.C) $(DEPEND_OPTIONS) $< -o $(ObjDir)/$*.o ; \
1587                 $(DEPEND_MOVEFILE)
1589 $(ObjDir)/%.o: %.m $(ObjDir)/.dir $(BUILT_SOURCES) $(PROJ_MAKEFILE)
1590         $(Echo) "Compiling $*.m for $(BuildMode) build" $(PIC_FLAG)
1591         $(Verb) if $(Compile.C) $(DEPEND_OPTIONS) $< -o $(ObjDir)/$*.o ; \
1592                 $(DEPEND_MOVEFILE)
1594 #---------------------------------------------------------
1595 # Create .bc files in the ObjDir directory from .cpp .cc and .c files...
1596 #---------------------------------------------------------
1598 BC_DEPEND_OPTIONS = -MMD -MP -MF "$(ObjDir)/$*.bc.d.tmp" \
1599         -MT "$(ObjDir)/$*.ll" -MT "$(ObjDir)/$*.bc.d"
1601 # If the build succeeded, move the dependency file over, otherwise
1602 # remove it.
1603 BC_DEPEND_MOVEFILE = then $(MV) -f "$(ObjDir)/$*.bc.d.tmp" "$(ObjDir)/$*.bc.d"; \
1604                      else $(RM) "$(ObjDir)/$*.bc.d.tmp"; exit 1; fi
1606 $(ObjDir)/%.ll: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES) $(LLVMCXX)
1607         $(Echo) "Compiling $*.cpp for $(BuildMode) build (bytecode)"
1608         $(Verb) if $(BCCompile.CXX) $(BC_DEPEND_OPTIONS) \
1609                         $< -o $(ObjDir)/$*.ll -S $(LLVMCC_EMITIR_FLAG) ; \
1610                 $(BC_DEPEND_MOVEFILE)
1612 $(ObjDir)/%.ll: %.mm $(ObjDir)/.dir $(BUILT_SOURCES) $(LLVMCXX)
1613         $(Echo) "Compiling $*.mm for $(BuildMode) build (bytecode)"
1614         $(Verb) if $(BCCompile.CXX) $(BC_DEPEND_OPTIONS) \
1615                         $< -o $(ObjDir)/$*.ll -S $(LLVMCC_EMITIR_FLAG) ; \
1616                 $(BC_DEPEND_MOVEFILE)
1618 $(ObjDir)/%.ll: %.cc $(ObjDir)/.dir $(BUILT_SOURCES) $(LLVMCXX)
1619         $(Echo) "Compiling $*.cc for $(BuildMode) build (bytecode)"
1620         $(Verb) if $(BCCompile.CXX) $(BC_DEPEND_OPTIONS) \
1621                         $< -o $(ObjDir)/$*.ll -S $(LLVMCC_EMITIR_FLAG) ; \
1622                 $(BC_DEPEND_MOVEFILE)
1624 $(ObjDir)/%.ll: %.c $(ObjDir)/.dir $(BUILT_SOURCES) $(LLVMCC)
1625         $(Echo) "Compiling $*.c for $(BuildMode) build (bytecode)"
1626         $(Verb) if $(BCCompile.C) $(BC_DEPEND_OPTIONS) \
1627                         $< -o $(ObjDir)/$*.ll -S $(LLVMCC_EMITIR_FLAG) ; \
1628                 $(BC_DEPEND_MOVEFILE)
1630 $(ObjDir)/%.ll: %.m $(ObjDir)/.dir $(BUILT_SOURCES) $(LLVMCC)
1631         $(Echo) "Compiling $*.m for $(BuildMode) build (bytecode)"
1632         $(Verb) if $(BCCompile.C) $(BC_DEPEND_OPTIONS) \
1633                         $< -o $(ObjDir)/$*.ll -S $(LLVMCC_EMITIR_FLAG) ; \
1634                 $(BC_DEPEND_MOVEFILE)
1636 # Provide alternate rule sets if dependencies are disabled
1637 else
1639 $(ObjDir)/%.o: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES)
1640         $(Echo) "Compiling $*.cpp for $(BuildMode) build" $(PIC_FLAG)
1641         $(Compile.CXX) $< -o $@
1643 $(ObjDir)/%.o: %.mm $(ObjDir)/.dir $(BUILT_SOURCES)
1644         $(Echo) "Compiling $*.mm for $(BuildMode) build" $(PIC_FLAG)
1645         $(Compile.CXX) $< -o $@
1647 $(ObjDir)/%.o: %.cc $(ObjDir)/.dir $(BUILT_SOURCES)
1648         $(Echo) "Compiling $*.cc for $(BuildMode) build" $(PIC_FLAG)
1649         $(Compile.CXX) $< -o $@
1651 $(ObjDir)/%.o: %.c $(ObjDir)/.dir $(BUILT_SOURCES)
1652         $(Echo) "Compiling $*.c for $(BuildMode) build" $(PIC_FLAG)
1653         $(Compile.C) $< -o $@
1655 $(ObjDir)/%.o: %.m $(ObjDir)/.dir $(BUILT_SOURCES)
1656         $(Echo) "Compiling $*.m for $(BuildMode) build" $(PIC_FLAG)
1657         $(Compile.C) $< -o $@
1659 $(ObjDir)/%.ll: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES) $(LLVMCXX)
1660         $(Echo) "Compiling $*.cpp for $(BuildMode) build (bytecode)"
1661         $(BCCompile.CXX) $< -o $@ -S $(LLVMCC_EMITIR_FLAG)
1663 $(ObjDir)/%.ll: %.mm $(ObjDir)/.dir $(BUILT_SOURCES) $(LLVMCXX)
1664         $(Echo) "Compiling $*.mm for $(BuildMode) build (bytecode)"
1665         $(BCCompile.CXX) $< -o $@ -S $(LLVMCC_EMITIR_FLAG)
1667 $(ObjDir)/%.ll: %.cc $(ObjDir)/.dir $(BUILT_SOURCES) $(LLVMCXX)
1668         $(Echo) "Compiling $*.cc for $(BuildMode) build (bytecode)"
1669         $(BCCompile.CXX) $< -o $@ -S $(LLVMCC_EMITIR_FLAG)
1671 $(ObjDir)/%.ll: %.c $(ObjDir)/.dir $(BUILT_SOURCES) $(LLVMCC)
1672         $(Echo) "Compiling $*.c for $(BuildMode) build (bytecode)"
1673         $(BCCompile.C) $< -o $@ -S $(LLVMCC_EMITIR_FLAG)
1675 $(ObjDir)/%.ll: %.m $(ObjDir)/.dir $(BUILT_SOURCES) $(LLVMCC)
1676         $(Echo) "Compiling $*.m for $(BuildMode) build (bytecode)"
1677         $(BCCompile.C) $< -o $@ -S $(LLVMCC_EMITIR_FLAG)
1679 endif
1682 ## Rules for building preprocessed (.i/.ii) outputs.
1683 $(BuildMode)/%.ii: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES)
1684         $(Echo) "Compiling $*.cpp for $(BuildMode) build to .ii file"
1685         $(Verb) $(Preprocess.CXX) $< -o $@
1687 $(BuildMode)/%.ii: %.mm $(ObjDir)/.dir $(BUILT_SOURCES)
1688         $(Echo) "Compiling $*.mm for $(BuildMode) build to .ii file"
1689         $(Verb) $(Preprocess.CXX) $< -o $@
1691 $(BuildMode)/%.ii: %.cc $(ObjDir)/.dir $(BUILT_SOURCES)
1692         $(Echo) "Compiling $*.cc for $(BuildMode) build to .ii file"
1693         $(Verb) $(Preprocess.CXX) $< -o $@
1695 $(BuildMode)/%.i: %.c $(ObjDir)/.dir $(BUILT_SOURCES)
1696         $(Echo) "Compiling $*.c for $(BuildMode) build to .i file"
1697         $(Verb) $(Preprocess.C) $< -o $@
1699 $(BuildMode)/%.i: %.m $(ObjDir)/.dir $(BUILT_SOURCES)
1700         $(Echo) "Compiling $*.m for $(BuildMode) build to .i file"
1701         $(Verb) $(Preprocess.C) $< -o $@
1704 $(ObjDir)/%.s: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES)
1705         $(Echo) "Compiling $*.cpp to asm for $(BuildMode) build" $(PIC_FLAG)
1706         $(Compile.CXX) $< -o $@ -S
1708 $(ObjDir)/%.s: %.mm $(ObjDir)/.dir $(BUILT_SOURCES)
1709         $(Echo) "Compiling $*.mm to asm for $(BuildMode) build" $(PIC_FLAG)
1710         $(Compile.CXX) $< -o $@ -S
1712 $(ObjDir)/%.s: %.cc $(ObjDir)/.dir $(BUILT_SOURCES)
1713         $(Echo) "Compiling $*.cc to asm for $(BuildMode) build" $(PIC_FLAG)
1714         $(Compile.CXX) $< -o $@ -S
1716 $(ObjDir)/%.s: %.c $(ObjDir)/.dir $(BUILT_SOURCES)
1717         $(Echo) "Compiling $*.c to asm for $(BuildMode) build" $(PIC_FLAG)
1718         $(Compile.C) $< -o $@ -S
1720 $(ObjDir)/%.s: %.m $(ObjDir)/.dir $(BUILT_SOURCES)
1721         $(Echo) "Compiling $*.m to asm for $(BuildMode) build" $(PIC_FLAG)
1722         $(Compile.C) $< -o $@ -S
1725 # make the C and C++ compilers strip debug info out of bytecode libraries.
1726 ifdef DEBUG_RUNTIME
1727 $(ObjectsBC): $(ObjDir)/%.bc: $(ObjDir)/%.ll $(LOPT)
1728         $(Echo) "Compiling $*.ll to $*.bc for $(BuildMode) build (bytecode)"
1729         $(Verb) $(LOPT) $< -std-compile-opts -o $@
1730 else
1731 $(ObjectsBC): $(ObjDir)/%.bc: $(ObjDir)/%.ll $(LOPT)
1732         $(Echo) "Compiling $*.ll to $*.bc for $(BuildMode) build (bytecode)"
1733         $(Verb) $(LOPT) $< -std-compile-opts -strip-debug -o $@
1734 endif
1737 #---------------------------------------------------------
1738 # Provide rule to build .bc files from .ll sources,
1739 # regardless of dependencies
1740 #---------------------------------------------------------
1741 $(ObjDir)/%.bc: %.ll $(ObjDir)/.dir $(LLVMAS)
1742         $(Echo) "Compiling $*.ll for $(BuildMode) build"
1743         $(Verb) $(LLVMAS) $< -f -o $@
1745 ###############################################################################
1746 # TABLEGEN: Provide rules for running tblgen to produce *.inc files
1747 ###############################################################################
1749 ifdef TARGET
1750 TABLEGEN_INC_FILES_COMMON = 1
1751 endif
1753 ifdef TABLEGEN_INC_FILES_COMMON
1755 INCFiles := $(filter %.inc,$(BUILT_SOURCES))
1756 INCTMPFiles := $(INCFiles:%=$(ObjDir)/%.tmp)
1757 .PRECIOUS: $(INCTMPFiles) $(INCFiles)
1759 # INCFiles rule: All of the tblgen generated files are emitted to
1760 # $(ObjDir)/%.inc.tmp, instead of emitting them directly to %.inc.  This allows
1761 # us to only "touch" the real file if the contents of it change.  IOW, if
1762 # tblgen is modified, all of the .inc.tmp files are regenerated, but no
1763 # dependencies of the .inc files are, unless the contents of the .inc file
1764 # changes.
1765 $(INCFiles) : %.inc : $(ObjDir)/%.inc.tmp
1766         $(Verb) $(CMP) -s $@ $< || $(CP) $< $@
1768 endif # TABLEGEN_INC_FILES_COMMON
1770 ifdef TARGET
1772 TDFiles := $(strip $(wildcard $(PROJ_SRC_DIR)/*.td) \
1773            $(LLVM_SRC_ROOT)/include/llvm/Target/Target.td \
1774            $(LLVM_SRC_ROOT)/include/llvm/Target/TargetCallingConv.td \
1775            $(LLVM_SRC_ROOT)/include/llvm/Target/TargetSchedule.td \
1776            $(LLVM_SRC_ROOT)/include/llvm/Target/TargetSelectionDAG.td \
1777            $(LLVM_SRC_ROOT)/include/llvm/CodeGen/ValueTypes.td) \
1778            $(wildcard $(LLVM_SRC_ROOT)/include/llvm/Intrinsics*.td)
1780 # All .inc.tmp files depend on the .td files.
1781 $(INCTMPFiles) : $(TDFiles)
1783 $(TARGET:%=$(ObjDir)/%GenRegisterInfo.inc.tmp): \
1784 $(ObjDir)/%GenRegisterInfo.inc.tmp : %.td $(ObjDir)/.dir $(LLVM_TBLGEN)
1785         $(Echo) "Building $(<F) register info implementation with tblgen"
1786         $(Verb) $(LLVMTableGen) -gen-register-info -o $(call SYSPATH, $@) $<
1788 $(TARGET:%=$(ObjDir)/%GenInstrInfo.inc.tmp): \
1789 $(ObjDir)/%GenInstrInfo.inc.tmp : %.td $(ObjDir)/.dir $(LLVM_TBLGEN)
1790         $(Echo) "Building $(<F) instruction information with tblgen"
1791         $(Verb) $(LLVMTableGen) -gen-instr-info -o $(call SYSPATH, $@) $<
1793 $(TARGET:%=$(ObjDir)/%GenAsmWriter.inc.tmp): \
1794 $(ObjDir)/%GenAsmWriter.inc.tmp : %.td $(ObjDir)/.dir $(LLVM_TBLGEN)
1795         $(Echo) "Building $(<F) assembly writer with tblgen"
1796         $(Verb) $(LLVMTableGen) -gen-asm-writer -o $(call SYSPATH, $@) $<
1798 $(TARGET:%=$(ObjDir)/%GenAsmWriter1.inc.tmp): \
1799 $(ObjDir)/%GenAsmWriter1.inc.tmp : %.td $(ObjDir)/.dir $(LLVM_TBLGEN)
1800         $(Echo) "Building $(<F) assembly writer #1 with tblgen"
1801         $(Verb) $(LLVMTableGen) -gen-asm-writer -asmwriternum=1 -o $(call SYSPATH, $@) $<
1803 $(TARGET:%=$(ObjDir)/%GenAsmMatcher.inc.tmp): \
1804 $(ObjDir)/%GenAsmMatcher.inc.tmp : %.td $(ObjDir)/.dir $(LLVM_TBLGEN)
1805         $(Echo) "Building $(<F) assembly matcher with tblgen"
1806         $(Verb) $(LLVMTableGen) -gen-asm-matcher -o $(call SYSPATH, $@) $<
1808 $(TARGET:%=$(ObjDir)/%GenMCCodeEmitter.inc.tmp): \
1809 $(ObjDir)/%GenMCCodeEmitter.inc.tmp: %.td $(ObjDir)/.dir $(LLVM_TBLGEN)
1810         $(Echo) "Building $(<F) MC code emitter with tblgen"
1811         $(Verb) $(LLVMTableGen) -gen-emitter -mc-emitter -o $(call SYSPATH, $@) $<
1813 $(TARGET:%=$(ObjDir)/%GenMCPseudoLowering.inc.tmp): \
1814 $(ObjDir)/%GenMCPseudoLowering.inc.tmp: %.td $(ObjDir)/.dir $(LLVM_TBLGEN)
1815         $(Echo) "Building $(<F) MC Pseudo instruction expander with tblgen"
1816         $(Verb) $(LLVMTableGen) -gen-pseudo-lowering -o $(call SYSPATH, $@) $<
1818 $(TARGET:%=$(ObjDir)/%GenCodeEmitter.inc.tmp): \
1819 $(ObjDir)/%GenCodeEmitter.inc.tmp: %.td $(ObjDir)/.dir $(LLVM_TBLGEN)
1820         $(Echo) "Building $(<F) code emitter with tblgen"
1821         $(Verb) $(LLVMTableGen) -gen-emitter -o $(call SYSPATH, $@) $<
1823 $(TARGET:%=$(ObjDir)/%GenDAGISel.inc.tmp): \
1824 $(ObjDir)/%GenDAGISel.inc.tmp : %.td $(ObjDir)/.dir $(LLVM_TBLGEN)
1825         $(Echo) "Building $(<F) DAG instruction selector implementation with tblgen"
1826         $(Verb) $(LLVMTableGen) -gen-dag-isel -o $(call SYSPATH, $@) $<
1828 $(TARGET:%=$(ObjDir)/%GenDisassemblerTables.inc.tmp): \
1829 $(ObjDir)/%GenDisassemblerTables.inc.tmp : %.td $(ObjDir)/.dir $(LLVM_TBLGEN)
1830         $(Echo) "Building $(<F) disassembly tables with tblgen"
1831         $(Verb) $(LLVMTableGen) -gen-disassembler -o $(call SYSPATH, $@) $<
1833 $(TARGET:%=$(ObjDir)/%GenEDInfo.inc.tmp): \
1834 $(ObjDir)/%GenEDInfo.inc.tmp : %.td $(ObjDir)/.dir $(LLVM_TBLGEN)
1835         $(Echo) "Building $(<F) enhanced disassembly information with tblgen"
1836         $(Verb) $(LLVMTableGen) -gen-enhanced-disassembly-info -o $(call SYSPATH, $@) $<
1838 $(TARGET:%=$(ObjDir)/%GenFastISel.inc.tmp): \
1839 $(ObjDir)/%GenFastISel.inc.tmp : %.td $(ObjDir)/.dir $(LLVM_TBLGEN)
1840         $(Echo) "Building $(<F) \"fast\" instruction selector implementation with tblgen"
1841         $(Verb) $(LLVMTableGen) -gen-fast-isel -o $(call SYSPATH, $@) $<
1843 $(TARGET:%=$(ObjDir)/%GenSubtargetInfo.inc.tmp): \
1844 $(ObjDir)/%GenSubtargetInfo.inc.tmp : %.td $(ObjDir)/.dir $(LLVM_TBLGEN)
1845         $(Echo) "Building $(<F) subtarget information with tblgen"
1846         $(Verb) $(LLVMTableGen) -gen-subtarget -o $(call SYSPATH, $@) $<
1848 $(TARGET:%=$(ObjDir)/%GenCallingConv.inc.tmp): \
1849 $(ObjDir)/%GenCallingConv.inc.tmp : %.td $(ObjDir)/.dir $(LLVM_TBLGEN)
1850         $(Echo) "Building $(<F) calling convention information with tblgen"
1851         $(Verb) $(LLVMTableGen) -gen-callingconv -o $(call SYSPATH, $@) $<
1853 $(TARGET:%=$(ObjDir)/%GenIntrinsics.inc.tmp): \
1854 $(ObjDir)/%GenIntrinsics.inc.tmp : %.td $(ObjDir)/.dir $(LLVM_TBLGEN)
1855         $(Echo) "Building $(<F) intrinsics information with tblgen"
1856         $(Verb) $(LLVMTableGen) -gen-tgt-intrinsic -o $(call SYSPATH, $@) $<
1858 $(ObjDir)/ARMGenDecoderTables.inc.tmp : ARM.td $(ObjDir)/.dir $(LLVM_TBLGEN)
1859         $(Echo) "Building $(<F) decoder tables with tblgen"
1860         $(Verb) $(LLVMTableGen) -gen-arm-decoder -o $(call SYSPATH, $@) $<
1862 $(ObjDir)/%GenDFAPacketizer.inc.tmp : %.td $(ObjDir)/.dir $(LLVM_TBLGEN)
1863         $(Echo) "Building $(<F) DFA packetizer tables with tblgen"
1864         $(Verb) $(LLVMTableGen) -gen-dfa-packetizer -o $(call SYSPATH, $@) $<
1866 clean-local::
1867         -$(Verb) $(RM) -f $(INCFiles)
1869 endif # TARGET
1871 ###############################################################################
1872 # OTHER RULES: Other rules needed
1873 ###############################################################################
1875 # To create postscript files from dot files...
1876 ifneq ($(DOT),false)
1877 %.ps: %.dot
1878         $(DOT) -Tps < $< > $@
1879 else
1880 %.ps: %.dot
1881         $(Echo) "Cannot build $@: The program dot is not installed"
1882 endif
1884 # This rules ensures that header files that are removed still have a rule for
1885 # which they can be "generated."  This allows make to ignore them and
1886 # reproduce the dependency lists.
1887 %.h:: ;
1888 %.hpp:: ;
1890 # Define clean-local to clean the current directory. Note that this uses a
1891 # very conservative approach ensuring that empty variables do not cause
1892 # errors or disastrous removal.
1893 clean-local::
1894 ifneq ($(strip $(ObjRootDir)),)
1895         -$(Verb) $(RM) -rf $(ObjRootDir)
1896 endif
1897 ifneq ($(strip $(SHLIBEXT)),) # Extra paranoia - make real sure SHLIBEXT is set
1898         -$(Verb) $(RM) -f *$(SHLIBEXT)
1899 endif
1901 clean-all-local::
1902         -$(Verb) $(RM) -rf Debug Release Profile
1905 ###############################################################################
1906 # DEPENDENCIES: Include the dependency files if we should
1907 ###############################################################################
1908 ifndef DISABLE_AUTO_DEPENDENCIES
1910 # If its not one of the cleaning targets
1911 ifndef IS_CLEANING_TARGET
1913 # Get the list of dependency files
1914 DependSourceFiles := $(basename $(filter %.cpp %.c %.cc %.m %.mm, $(Sources)))
1915 DependFiles := $(DependSourceFiles:%=$(PROJ_OBJ_DIR)/$(BuildMode)/%.d)
1917 # Include bitcode dependency files if using bitcode libraries
1918 ifdef BYTECODE_LIBRARY
1919 DependFiles += $(DependSourceFiles:%=$(PROJ_OBJ_DIR)/$(BuildMode)/%.bc.d)
1920 endif
1922 -include $(DependFiles) ""
1924 endif
1926 endif
1928 ###############################################################################
1929 # CHECK: Running the test suite
1930 ###############################################################################
1932 check::
1933         $(Verb) if test -d "$(PROJ_OBJ_ROOT)/test" ; then \
1934           if test -f "$(PROJ_OBJ_ROOT)/test/Makefile" ; then \
1935             $(EchoCmd) Running test suite ; \
1936             $(MAKE) -C $(PROJ_OBJ_ROOT)/test check-local \
1937               TESTSUITE=$(TESTSUITE) ; \
1938           else \
1939             $(EchoCmd) No Makefile in test directory ; \
1940           fi ; \
1941         else \
1942           $(EchoCmd) No test directory ; \
1943         fi
1945 check-lit:: check
1947 check-dg::
1948         $(Verb) if test -d "$(PROJ_OBJ_ROOT)/test" ; then \
1949           if test -f "$(PROJ_OBJ_ROOT)/test/Makefile" ; then \
1950             $(EchoCmd) Running test suite ; \
1951             $(MAKE) -C $(PROJ_OBJ_ROOT)/test check-local-dg ; \
1952           else \
1953             $(EchoCmd) No Makefile in test directory ; \
1954           fi ; \
1955         else \
1956           $(EchoCmd) No test directory ; \
1957         fi
1959 check-all::
1960         $(Verb) if test -d "$(PROJ_OBJ_ROOT)/test" ; then \
1961           if test -f "$(PROJ_OBJ_ROOT)/test/Makefile" ; then \
1962             $(EchoCmd) Running test suite ; \
1963             $(MAKE) -C $(PROJ_OBJ_ROOT)/test check-local-all ; \
1964           else \
1965             $(EchoCmd) No Makefile in test directory ; \
1966           fi ; \
1967         else \
1968           $(EchoCmd) No test directory ; \
1969         fi
1971 ###############################################################################
1972 # UNITTESTS: Running the unittests test suite
1973 ###############################################################################
1975 unittests::
1976         $(Verb) if test -d "$(PROJ_OBJ_ROOT)/unittests" ; then \
1977           if test -f "$(PROJ_OBJ_ROOT)/unittests/Makefile" ; then \
1978             $(EchoCmd) Running unittests test suite ; \
1979             $(MAKE) -C $(PROJ_OBJ_ROOT)/unittests unitcheck; \
1980           else \
1981             $(EchoCmd) No Makefile in unittests directory ; \
1982           fi ; \
1983         else \
1984           $(EchoCmd) No unittests directory ; \
1985         fi
1987 ###############################################################################
1988 # DISTRIBUTION: Handle construction of a distribution tarball
1989 ###############################################################################
1991 #------------------------------------------------------------------------
1992 # Define distribution related variables
1993 #------------------------------------------------------------------------
1994 DistName    := $(PROJECT_NAME)-$(PROJ_VERSION)
1995 DistDir     := $(PROJ_OBJ_ROOT)/$(DistName)
1996 TopDistDir  := $(PROJ_OBJ_ROOT)/$(DistName)
1997 DistTarGZip := $(PROJ_OBJ_ROOT)/$(DistName).tar.gz
1998 DistZip     := $(PROJ_OBJ_ROOT)/$(DistName).zip
1999 DistTarBZ2  := $(PROJ_OBJ_ROOT)/$(DistName).tar.bz2
2000 DistAlways  := CREDITS.TXT LICENSE.TXT README.txt README AUTHORS COPYING \
2001                ChangeLog INSTALL NEWS Makefile Makefile.common Makefile.rules \
2002                Makefile.config.in configure autoconf
2003 DistOther   := $(notdir $(wildcard \
2004                $(PROJ_SRC_DIR)/*.h \
2005                $(PROJ_SRC_DIR)/*.td \
2006                $(PROJ_SRC_DIR)/*.def \
2007                $(PROJ_SRC_DIR)/*.ll \
2008                $(PROJ_SRC_DIR)/*.in))
2009 DistSubDirs := $(SubDirs)
2010 DistSources  = $(Sources) $(EXTRA_DIST)
2011 DistFiles    = $(DistAlways) $(DistSources) $(DistOther)
2013 #------------------------------------------------------------------------
2014 # We MUST build distribution with OBJ_DIR != SRC_DIR
2015 #------------------------------------------------------------------------
2016 ifeq ($(PROJ_SRC_DIR),$(PROJ_OBJ_DIR))
2017 dist dist-check dist-clean dist-gzip dist-bzip2 dist-zip ::
2018         $(Echo) ERROR: Target $@ only available with OBJ_DIR != SRC_DIR
2020 else
2022 #------------------------------------------------------------------------
2023 # Prevent attempt to run dist targets from anywhere but the top level
2024 #------------------------------------------------------------------------
2025 ifneq ($(LEVEL),.)
2026 dist dist-check dist-clean dist-gzip dist-bzip2 dist-zip ::
2027         $(Echo) ERROR: You must run $@ from $(PROJ_OBJ_ROOT)
2028 else
2030 #------------------------------------------------------------------------
2031 # Provide the top level targets
2032 #------------------------------------------------------------------------
2034 dist-gzip:: $(DistTarGZip)
2036 $(DistTarGZip) : $(TopDistDir)/.makedistdir
2037         $(Echo) Packing gzipped distribution tar file.
2038         $(Verb) cd $(PROJ_OBJ_ROOT) ; $(TAR) chf - "$(DistName)" | \
2039           $(GZIP) -c > "$(DistTarGZip)"
2041 dist-bzip2:: $(DistTarBZ2)
2043 $(DistTarBZ2) : $(TopDistDir)/.makedistdir
2044         $(Echo) Packing bzipped distribution tar file.
2045         $(Verb) cd $(PROJ_OBJ_ROOT) ; $(TAR) chf - $(DistName) | \
2046           $(BZIP2) -c >$(DistTarBZ2)
2048 dist-zip:: $(DistZip)
2050 $(DistZip) : $(TopDistDir)/.makedistdir
2051         $(Echo) Packing zipped distribution file.
2052         $(Verb) rm -f $(DistZip)
2053         $(Verb) cd $(PROJ_OBJ_ROOT) ; $(ZIP) -rq $(DistZip) $(DistName)
2055 dist :: $(DistTarGZip) $(DistTarBZ2) $(DistZip)
2056         $(Echo) ===== DISTRIBUTION PACKAGING SUCCESSFUL =====
2058 DistCheckDir := $(PROJ_OBJ_ROOT)/_distcheckdir
2060 dist-check:: $(DistTarGZip)
2061         $(Echo) Checking distribution tar file.
2062         $(Verb) if test -d $(DistCheckDir) ; then \
2063           $(RM) -rf $(DistCheckDir) ; \
2064         fi
2065         $(Verb) $(MKDIR) $(DistCheckDir)
2066         $(Verb) cd $(DistCheckDir) && \
2067           $(MKDIR) $(DistCheckDir)/build && \
2068           $(MKDIR) $(DistCheckDir)/install && \
2069           gunzip -c $(DistTarGZip) | $(TAR) xf - && \
2070           cd build && \
2071           ../$(DistName)/configure --prefix="$(DistCheckDir)/install" \
2072             --srcdir=../$(DistName) $(DIST_CHECK_CONFIG_OPTIONS) && \
2073           $(MAKE) all && \
2074           $(MAKE) check && \
2075           $(MAKE) unittests && \
2076           $(MAKE) install && \
2077           $(MAKE) uninstall && \
2078           $(MAKE) dist-clean && \
2079           $(EchoCmd) ===== $(DistTarGZip) Ready For Distribution =====
2081 dist-clean::
2082         $(Echo) Cleaning distribution files
2083         -$(Verb) $(RM) -rf $(DistTarGZip) $(DistTarBZ2) $(DistZip) $(DistName) \
2084           $(DistCheckDir)
2086 endif
2088 #------------------------------------------------------------------------
2089 # Provide the recursive distdir target for building the distribution directory
2090 #------------------------------------------------------------------------
2091 distdir: $(DistDir)/.makedistdir
2092 $(DistDir)/.makedistdir: $(DistSources)
2093         $(Verb) if test "$(DistDir)" = "$(TopDistDir)" ; then \
2094           if test -d "$(DistDir)" ; then \
2095             find $(DistDir) -type d ! -perm -200 -exec chmod u+w {} ';'  || \
2096               exit 1 ; \
2097           fi ; \
2098           $(EchoCmd) Removing old $(DistDir) ; \
2099           $(RM) -rf $(DistDir); \
2100           $(EchoCmd) Making 'all' to verify build ; \
2101           $(MAKE) ENABLE_OPTIMIZED=1 all ; \
2102         fi
2103         $(Echo) Building Distribution Directory $(DistDir)
2104         $(Verb) $(MKDIR) $(DistDir)
2105         $(Verb) srcdirstrip=`echo "$(PROJ_SRC_DIR)" | sed 's|.|.|g'`; \
2106         srcrootstrip=`echo "$(PROJ_SRC_ROOT)" | sed 's|.|.|g'`; \
2107         for file in $(DistFiles) ; do \
2108           case "$$file" in \
2109             $(PROJ_SRC_DIR)/*) \
2110               file=`echo "$$file" | sed "s#^$$srcdirstrip/##"` \
2111               ;; \
2112             $(PROJ_SRC_ROOT)/*) \
2113               file=`echo "$$file" | \
2114                 sed "s#^$$srcrootstrip/##"` \
2115               ;; \
2116           esac; \
2117           if test -f "$(PROJ_SRC_DIR)/$$file" || \
2118              test -d "$(PROJ_SRC_DIR)/$$file" ; then \
2119             from_dir="$(PROJ_SRC_DIR)" ; \
2120           elif test -f "$$file" || test -d "$$file" ; then \
2121             from_dir=. ; \
2122           fi ; \
2123           to_dir=`echo "$$file" | sed -e 's#/[^/]*$$##'` ; \
2124           if test "$$to_dir" != "$$file" && test "$$to_dir" != "."; then \
2125             to_dir="$(DistDir)/$$dir"; \
2126             $(MKDIR) "$$to_dir" ; \
2127           else \
2128             to_dir="$(DistDir)"; \
2129           fi; \
2130           mid_dir=`echo "$$file" | sed -n -e 's#^\(.*\)/[^/]*$$#\1#p'`; \
2131           if test -n "$$mid_dir" ; then \
2132             $(MKDIR) "$$to_dir/$$mid_dir" || exit 1; \
2133           fi ; \
2134           if test -d "$$from_dir/$$file"; then \
2135             if test -d "$(PROJ_SRC_DIR)/$$file" && \
2136                test "$$from_dir" != "$(PROJ_SRC_DIR)" ; then \
2137                cd $(PROJ_SRC_DIR) ; \
2138                $(TAR) cf - $$file --exclude .svn --exclude CVS | \
2139                  ( cd $$to_dir ; $(TAR) xf - ) ; \
2140                cd $(PROJ_OBJ_DIR) ; \
2141             else \
2142                cd $$from_dir ; \
2143                $(TAR) cf - $$file --exclude .svn --exclude CVS | \
2144                  ( cd $$to_dir ; $(TAR) xf - ) ; \
2145                cd $(PROJ_OBJ_DIR) ; \
2146             fi; \
2147           elif test -f "$$from_dir/$$file" ; then \
2148             $(CP) -p "$$from_dir/$$file" "$(DistDir)/$$file" || exit 1; \
2149           elif test -L "$$from_dir/$$file" ; then \
2150             $(CP) -pd "$$from_dir/$$file" $(DistDir)/$$file || exit 1; \
2151           elif echo "$(DistAlways)" | grep -v "$$file" >/dev/null ; then \
2152             $(EchoCmd) "===== WARNING: Distribution Source " \
2153               "$$from_dir/$$file Not Found!" ; \
2154           elif test "$(Verb)" != '@' ; then \
2155             $(EchoCmd) "Skipping non-existent $$from_dir/$$file" ; \
2156           fi; \
2157         done
2158         $(Verb) for subdir in $(DistSubDirs) ; do \
2159           if test "$$subdir" \!= "." ; then \
2160             new_distdir="$(DistDir)/$$subdir" ; \
2161             test -d "$$new_distdir" || $(MKDIR) "$$new_distdir" || exit 1; \
2162             ( cd $$subdir && $(MAKE) ENABLE_OPTIMIZED=1 \
2163               DistDir="$$new_distdir" distdir ) || exit 1; \
2164           fi; \
2165         done
2166         $(Verb) if test "$(DistDir)" = "$(TopDistDir)" ; then \
2167           $(EchoCmd) Eliminating CVS/.svn directories from distribution ; \
2168           $(RM) -rf `find $(TopDistDir) -type d \( -name CVS -o \
2169                                   -name .svn \) -print` ;\
2170           $(MAKE) dist-hook ; \
2171           $(FIND) $(TopDistDir) -type d ! -perm -777 -exec chmod a+rwx {} \; \
2172             -o ! -type d ! -perm -444 -links 1 -exec chmod a+r {} \; \
2173             -o ! -type d ! -perm -400 -exec chmod a+r {} \; \
2174             -o ! -type d ! -perm -444 -exec \
2175               $(SHELL) $(INSTALL_SH) -c -m a+r {} {} \; \
2176             || chmod -R a+r $(DistDir) ; \
2177         fi
2179 # This is invoked by distdir target, define it as a no-op to avoid errors if not
2180 # defined by user.
2181 dist-hook::
2183 endif
2185 ###############################################################################
2186 # TOP LEVEL - targets only to apply at the top level directory
2187 ###############################################################################
2189 ifeq ($(LEVEL),.)
2191 #------------------------------------------------------------------------
2192 # Install support for the project's include files:
2193 #------------------------------------------------------------------------
2194 ifdef NO_INSTALL
2195 install-local::
2196         $(Echo) Install circumvented with NO_INSTALL
2197 uninstall-local::
2198         $(Echo) Uninstall circumvented with NO_INSTALL
2199 else
2200 install-local::
2201         $(Echo) Installing include files
2202         $(Verb) $(MKDIR) $(DESTDIR)$(PROJ_includedir)
2203         $(Verb) if test -d "$(PROJ_SRC_ROOT)/include" ; then \
2204           cd $(PROJ_SRC_ROOT)/include && \
2205           for hdr in `find . -type f \
2206               '(' -name LICENSE.TXT \
2207                -o -name '*.def' \
2208                -o -name '*.h' \
2209                -o -name '*.inc' \
2210                -o -name '*.td' \
2211               ')' -print | grep -v CVS | \
2212               grep -v .svn` ; do \
2213             instdir=`dirname "$(DESTDIR)$(PROJ_includedir)/$$hdr"` ; \
2214             if test \! -d "$$instdir" ; then \
2215               $(EchoCmd) Making install directory $$instdir ; \
2216               $(MKDIR) $$instdir ;\
2217             fi ; \
2218             $(DataInstall) $$hdr $(DESTDIR)$(PROJ_includedir)/$$hdr ; \
2219           done ; \
2220         fi
2221 ifneq ($(PROJ_SRC_ROOT),$(PROJ_OBJ_ROOT))
2222         $(Verb) if test -d "$(PROJ_OBJ_ROOT)/include" ; then \
2223           cd $(PROJ_OBJ_ROOT)/include && \
2224           for hdr in `find . -type f \
2225               '(' -name LICENSE.TXT \
2226                -o -name '*.def' \
2227                -o -name '*.h' \
2228                -o -name '*.inc' \
2229                -o -name '*.td' \
2230               ')' -print | grep -v CVS | \
2231               grep -v .svn` ; do \
2232             instdir=`dirname "$(DESTDIR)$(PROJ_includedir)/$$hdr"` ; \
2233             if test \! -d "$$instdir" ; then \
2234               $(EchoCmd) Making install directory $$instdir ; \
2235               $(MKDIR) $$instdir ;\
2236             fi ; \
2237             $(DataInstall) $$hdr $(DESTDIR)$(PROJ_includedir)/$$hdr ; \
2238           done ; \
2239         fi
2240 endif
2242 uninstall-local::
2243         $(Echo) Uninstalling include files
2244         $(Verb) if [ -d "$(PROJ_SRC_ROOT)/include" ] ; then \
2245           cd $(PROJ_SRC_ROOT)/include && \
2246             $(RM) -f `find . -path '*/Internal' -prune -o '(' -type f \
2247               '!' '(' -name '*~' -o -name '.#*' \
2248         -o -name '*.in' ')' -print ')' | \
2249         grep -v CVS | sed 's#^#$(DESTDIR)$(PROJ_includedir)/#'` ; \
2250           cd $(PROJ_SRC_ROOT)/include && \
2251             $(RM) -f `find . -path '*/Internal' -prune -o '(' -type f -name '*.in' \
2252       -print ')' | sed 's#\.in$$##;s#^#$(DESTDIR)$(PROJ_includedir)/#'` ; \
2253         fi
2254 endif
2255 endif
2257 check-line-length:
2258         @echo searching for overlength lines in files: $(Sources)
2259         @echo
2260         @echo
2261         egrep -n '.{81}' $(Sources) /dev/null
2263 check-for-tabs:
2264         @echo searching for tabs in files: $(Sources)
2265         @echo
2266         @echo
2267         egrep -n '      ' $(Sources) /dev/null
2269 check-footprint:
2270         @ls -l $(LibDir) | awk '\
2271           BEGIN { sum = 0; } \
2272                 { sum += $$5; } \
2273           END   { printf("Libraries: %6.3f MBytes\n", sum/(1024.0*1024.0)); }'
2274         @ls -l $(ToolDir) | awk '\
2275           BEGIN { sum = 0; } \
2276                 { sum += $$5; } \
2277           END   { printf("Programs:  %6.3f MBytes\n", sum/(1024.0*1024.0)); }'
2278 #------------------------------------------------------------------------
2279 # Print out the directories used for building
2280 #------------------------------------------------------------------------
2281 printvars::
2282         $(Echo) "BuildMode    : " '$(BuildMode)'
2283         $(Echo) "PROJ_SRC_ROOT: " '$(PROJ_SRC_ROOT)'
2284         $(Echo) "PROJ_SRC_DIR : " '$(PROJ_SRC_DIR)'
2285         $(Echo) "PROJ_OBJ_ROOT: " '$(PROJ_OBJ_ROOT)'
2286         $(Echo) "PROJ_OBJ_DIR : " '$(PROJ_OBJ_DIR)'
2287         $(Echo) "LLVM_SRC_ROOT: " '$(LLVM_SRC_ROOT)'
2288         $(Echo) "LLVM_OBJ_ROOT: " '$(LLVM_OBJ_ROOT)'
2289         $(Echo) "PROJ_prefix  : " '$(PROJ_prefix)'
2290         $(Echo) "PROJ_internal_prefix  : " '$(PROJ_internal_prefix)'
2291         $(Echo) "PROJ_bindir  : " '$(PROJ_bindir)'
2292         $(Echo) "PROJ_libdir  : " '$(PROJ_libdir)'
2293         $(Echo) "PROJ_etcdir  : " '$(PROJ_etcdir)'
2294         $(Echo) "PROJ_includedir  : " '$(PROJ_includedir)'
2295         $(Echo) "UserTargets  : " '$(UserTargets)'
2296         $(Echo) "ObjMakefiles : " '$(ObjMakefiles)'
2297         $(Echo) "SrcMakefiles : " '$(SrcMakefiles)'
2298         $(Echo) "ObjDir       : " '$(ObjDir)'
2299         $(Echo) "LibDir       : " '$(LibDir)'
2300         $(Echo) "ToolDir      : " '$(ToolDir)'
2301         $(Echo) "ExmplDir     : " '$(ExmplDir)'
2302         $(Echo) "Sources      : " '$(Sources)'
2303         $(Echo) "TDFiles      : " '$(TDFiles)'
2304         $(Echo) "INCFiles     : " '$(INCFiles)'
2305         $(Echo) "INCTMPFiles  : " '$(INCTMPFiles)'
2306         $(Echo) "PreConditions: " '$(PreConditions)'
2307         $(Echo) "Compile.CXX  : " '$(Compile.CXX)'
2308         $(Echo) "Compile.C    : " '$(Compile.C)'
2309         $(Echo) "Archive      : " '$(Archive)'
2310         $(Echo) "YaccFiles    : " '$(YaccFiles)'
2311         $(Echo) "LexFiles     : " '$(LexFiles)'
2312         $(Echo) "Module       : " '$(Module)'
2313         $(Echo) "FilesToConfig: " '$(FilesToConfigPATH)'
2314         $(Echo) "SubDirs      : " '$(SubDirs)'
2315         $(Echo) "ProjLibsPaths: " '$(ProjLibsPaths)'
2316         $(Echo) "ProjLibsOptions: " '$(ProjLibsOptions)'
2318 ###
2319 # Debugging
2321 # General debugging rule, use 'make dbg-print-XXX' to print the
2322 # definition, value and origin of XXX.
2323 make-print-%:
2324         $(error PRINT: $(value $*) = "$($*)" (from $(origin $*)))