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