Skip to content
Makefile.rules 75.6 KiB
Newer Older
#===-- Makefile.rules - Common make rules for LLVM ---------*- Makefile -*--===#
#
#                     The LLVM Compiler Infrastructure
#
# This file is distributed under the University of Illinois Open Source
# License. See LICENSE.TXT for details.
#===------------------------------------------------------------------------===#
Chris Lattner's avatar
Chris Lattner committed
#
Reid Spencer's avatar
Reid Spencer committed
# This file is included by all of the LLVM makefiles.  For details on how to use
# it properly, please see the document MakefileGuide.html in the docs directory.
#===-----------------------------------------------------------------------====#
Chris Lattner's avatar
Chris Lattner committed

################################################################################
Reid Spencer's avatar
Reid Spencer committed
# TARGETS: Define standard targets that can be invoked
################################################################################
Reid Spencer's avatar
Reid Spencer committed
#--------------------------------------------------------------------
# Define the various target sets
#--------------------------------------------------------------------
RecursiveTargets := all clean clean-all install uninstall install-bytecode \
                    unitcheck
LocalTargets     := all-local clean-local clean-all-local check-local \
                    install-local printvars uninstall-local \
TopLevelTargets  := check dist dist-check dist-clean dist-gzip dist-bzip2 \
UserTargets      := $(RecursiveTargets) $(LocalTargets) $(TopLevelTargets)
InternalTargets  := preconditions distdir dist-hook
################################################################################
Reid Spencer's avatar
Reid Spencer committed
# INITIALIZATION: Basic things the makefile needs
################################################################################

#--------------------------------------------------------------------
# Set the VPATH so that we can find source files.
#--------------------------------------------------------------------
Reid Spencer's avatar
Reid Spencer committed
VPATH=$(PROJ_SRC_DIR)
Reid Spencer's avatar
Reid Spencer committed

#--------------------------------------------------------------------
Reid Spencer's avatar
Reid Spencer committed
# Reset the list of suffixes we know how to build.
Reid Spencer's avatar
Reid Spencer committed
#--------------------------------------------------------------------
.SUFFIXES:
.SUFFIXES: .c .cpp .cc .h .hpp .o .a .bc .td .ps .dot .ll .m .mm
.SUFFIXES: $(SHLIBEXT) $(SUFFIXES)
Reid Spencer's avatar
Reid Spencer committed

Reid Spencer's avatar
Reid Spencer committed
#--------------------------------------------------------------------
# Mark all of these targets as phony to avoid implicit rule search
#--------------------------------------------------------------------
.PHONY: $(UserTargets) $(InternalTargets)
Reid Spencer's avatar
Reid Spencer committed
#--------------------------------------------------------------------
# Make sure all the user-target rules are double colon rules and
Reid Spencer's avatar
Reid Spencer committed
# they are defined first.
Reid Spencer's avatar
Reid Spencer committed
#--------------------------------------------------------------------
Reid Spencer's avatar
Reid Spencer committed

################################################################################
# PRECONDITIONS: that which must be built/checked first
################################################################################

SrcMakefiles       := $(filter %Makefile %Makefile.tests,\
Reid Spencer's avatar
Reid Spencer committed
                      $(wildcard $(PROJ_SRC_DIR)/Makefile*))
ObjMakefiles       := $(subst $(PROJ_SRC_DIR),$(PROJ_OBJ_DIR),$(SrcMakefiles))
ConfigureScript    := $(PROJ_SRC_ROOT)/configure
ConfigStatusScript := $(PROJ_OBJ_ROOT)/config.status
MakefileConfigIn   := $(strip $(wildcard $(PROJ_SRC_ROOT)/Makefile.config.in))
MakefileCommonIn   := $(strip $(wildcard $(PROJ_SRC_ROOT)/Makefile.common.in))
MakefileConfig     := $(PROJ_OBJ_ROOT)/Makefile.config
MakefileCommon     := $(PROJ_OBJ_ROOT)/Makefile.common
PreConditions      := $(ConfigStatusScript) $(ObjMakefiles)
ifneq ($(MakefileCommonIn),)
PreConditions      += $(MakefileCommon)
endif
Reid Spencer's avatar
Reid Spencer committed
ifneq ($(MakefileConfigIn),)
PreConditions      += $(MakefileConfig)
endif
Reid Spencer's avatar
Reid Spencer committed

Reid Spencer's avatar
Reid Spencer committed
preconditions: $(PreConditions)
Reid Spencer's avatar
Reid Spencer committed

#------------------------------------------------------------------------
# Make sure the BUILT_SOURCES are built first
#------------------------------------------------------------------------
$(filter-out clean clean-local,$(UserTargets)):: $(BUILT_SOURCES)
Reid Spencer's avatar
Reid Spencer committed

Reid Spencer's avatar
Reid Spencer committed
ifneq ($(strip $(BUILT_SOURCES)),)
Reid Spencer's avatar
Reid Spencer committed
endif

Reid Spencer's avatar
Reid Spencer committed
ifneq ($(PROJ_OBJ_ROOT),$(PROJ_SRC_ROOT))
spotless:
	$(Verb) if test -x config.status ; then \
Reid Spencer's avatar
Reid Spencer committed
	  $(EchoCmd) Wiping out $(PROJ_OBJ_ROOT) ; \
	  $(MKDIR) .spotless.save ; \
	  $(MV) config.status .spotless.save ; \
	  $(MV) mklib  .spotless.save ; \
	  $(MV) projects  .spotless.save ; \
	  $(MV) .spotless.save/config.status . ; \
	  $(MV) .spotless.save/mklib . ; \
	  $(MV) .spotless.save/projects . ; \
	  $(RM) -rf .spotless.save ; \
Reid Spencer's avatar
Reid Spencer committed
	  $(EchoCmd) Rebuilding configuration of $(PROJ_OBJ_ROOT) ; \
	  $(ConfigStatusScript) --recheck $(ConfigureScriptFLAGS) && \
	  $(ConfigStatusScript) ; \
Reid Spencer's avatar
Reid Spencer committed
	  $(EchoCmd) "make spotless" can only be run from $(PROJ_OBJ_ROOT); \
Reid Spencer's avatar
Reid Spencer committed
else
spotless:
	$(EchoCmd) "spotless target not supported for objdir == srcdir"
Reid Spencer's avatar
Reid Spencer committed

Reid Spencer's avatar
Reid Spencer committed
#------------------------------------------------------------------------
# Make sure we're not using a stale configuration
#------------------------------------------------------------------------
Reid Spencer's avatar
Reid Spencer committed
reconfigure:
Reid Spencer's avatar
Reid Spencer committed
	$(Echo) Reconfiguring $(PROJ_OBJ_ROOT)
	$(Verb) cd $(PROJ_OBJ_ROOT) && \
	  if test -w $(PROJ_OBJ_ROOT)/config.cache ; then \
	    $(RM) $(PROJ_OBJ_ROOT)/config.cache ; \
Reid Spencer's avatar
Reid Spencer committed
	  fi ; \
Reid Spencer's avatar
Reid Spencer committed
	  $(ConfigStatusScript) --recheck $(ConfigureScriptFLAGS) && \
	  $(ConfigStatusScript)

$(ConfigStatusScript): $(ConfigureScript)
Reid Spencer's avatar
Reid Spencer committed
	$(Verb) cd $(PROJ_OBJ_ROOT) && \
	  if test -w $(PROJ_OBJ_ROOT)/config.cache ; then \
	    $(RM) $(PROJ_OBJ_ROOT)/config.cache ; \
Reid Spencer's avatar
Reid Spencer committed
	  fi ; \
	  $(ConfigStatusScript) --recheck $(ConfigureScriptFLAGS) && \
	  $(ConfigStatusScript)
Reid Spencer's avatar
Reid Spencer committed

#------------------------------------------------------------------------
# Make sure the configuration makefile is up to date
#------------------------------------------------------------------------
Reid Spencer's avatar
Reid Spencer committed
ifneq ($(MakefileConfigIn),)
$(MakefileConfig): $(MakefileConfigIn) $(ConfigStatusScript)
	$(Echo) Regenerating $@
	$(Verb) cd $(PROJ_OBJ_ROOT) ; $(ConfigStatusScript) Makefile.config
endif

ifneq ($(MakefileCommonIn),)
$(MakefileCommon): $(MakefileCommonIn) $(ConfigStatusScript)
Reid Spencer's avatar
Reid Spencer committed
	$(Verb) cd $(PROJ_OBJ_ROOT) ; $(ConfigStatusScript) Makefile.common
endif
Reid Spencer's avatar
Reid Spencer committed

#------------------------------------------------------------------------
# If the Makefile in the source tree has been updated, copy it over into the
# build tree. But, only do this if the source and object makefiles differ
#------------------------------------------------------------------------
ifndef PROJ_MAKEFILE
PROJ_MAKEFILE := $(PROJ_SRC_DIR)/Makefile
endif

Reid Spencer's avatar
Reid Spencer committed
ifneq ($(PROJ_OBJ_DIR),$(PROJ_SRC_DIR))
Reid Spencer's avatar
Reid Spencer committed

Makefile: $(PROJ_MAKEFILE) $(ExtraMakefiles)
	$(Echo) "Updating Makefile"
	$(Verb) $(MKDIR) $(@D)
Reid Spencer's avatar
Reid Spencer committed
	$(Verb) $(CP) -f $< $@
Reid Spencer's avatar
Reid Spencer committed

# Copy the Makefile.* files unless we're in the root directory which avoids
# the copying of Makefile.config.in or other things that should be explicitly
# taken care of.
$(PROJ_OBJ_DIR)/Makefile% : $(PROJ_MAKEFILE)%
	@case '$?' in \
          *Makefile.rules) ;; \
          *.in) ;; \
          *) $(EchoCmd) "Updating $(@F)" ; \
Reid Spencer's avatar
Reid Spencer committed
	     $(CP) -f $< $@ ;; \
Reid Spencer's avatar
Reid Spencer committed
endif
Reid Spencer's avatar
Reid Spencer committed
#------------------------------------------------------------------------
# Set up the basic dependencies
#------------------------------------------------------------------------
Reid Spencer's avatar
Reid Spencer committed

all:: all-local
clean-all:: clean-local clean-all-local
Reid Spencer's avatar
Reid Spencer committed
install:: install-local
uninstall:: uninstall-local
install-local:: all-local
install-bytecode:: install-bytecode-local
Reid Spencer's avatar
Reid Spencer committed

###############################################################################
# LLVMC: Provide rules for compiling llvmc-based driver
###############################################################################

Mikhail Glushenkov's avatar
Mikhail Glushenkov committed
ifdef LLVMC_BASED_DRIVER

TOOLNAME = $(LLVMC_BASED_DRIVER)
LLVMLIBS = CompilerDriver.a
Mikhail Glushenkov's avatar
Mikhail Glushenkov committed

endif # LLVMC_BASED_DRIVER

Reid Spencer's avatar
Reid Spencer committed
###############################################################################
# VARIABLES: Set up various variables based on configuration data
###############################################################################
# Variable for if this make is for a "cleaning" target
ifneq ($(strip $(filter clean clean-local dist-clean,$(MAKECMDGOALS))),)
  IS_CLEANING_TARGET=1
endif

Chris Lattner's avatar
Chris Lattner committed
#--------------------------------------------------------------------
Reid Spencer's avatar
Reid Spencer committed
# Variables derived from configuration we are building
Chris Lattner's avatar
Chris Lattner committed
#--------------------------------------------------------------------

David Greene's avatar
 
David Greene committed
ifeq ($(ENABLE_OPTIMIZED),1)
  BuildMode := Release
  # Don't use -fomit-frame-pointer on Darwin or FreeBSD.
  ifneq ($(HOST_OS),FreeBSD)
  ifneq ($(HOST_OS),Darwin)
David Greene's avatar
 
David Greene committed
    OmitFramePointer := -fomit-frame-pointer
  endif
  endif

  # Darwin requires -fstrict-aliasing to be explicitly enabled.
  # Avoid -fstrict-aliasing on Darwin for now, there are unresolved issues
  # with -fstrict-aliasing and ipa-type-escape radr://6756684
  #  EXTRA_OPTIONS += -fstrict-aliasing -Wstrict-aliasing
  #endif
David Greene's avatar
 
David Greene committed
  CXX.Flags += $(OPTIMIZE_OPTION) $(OmitFramePointer)
  C.Flags   += $(OPTIMIZE_OPTION) $(OmitFramePointer)
  LD.Flags  += $(OPTIMIZE_OPTION)
    BuildMode := $(BuildMode)+Debug
    CXX.Flags += -g
    C.Flags   += -g
    LD.Flags  += -g
    KEEP_SYMBOLS := 1
  endif
David Greene's avatar
 
David Greene committed
else
  ifdef NO_DEBUG_SYMBOLS
    BuildMode := Unoptimized
    CXX.Flags +=
    C.Flags   +=
    LD.Flags  +=
    KEEP_SYMBOLS := 1
  else
    BuildMode := Debug
    CXX.Flags += -g
    C.Flags   += -g
    LD.Flags  += -g
    KEEP_SYMBOLS := 1
  endif
David Greene's avatar
 
David Greene committed
endif

ifeq ($(ENABLE_PROFILING),1)
  BuildMode := $(BuildMode)+Profile
  CXX.Flags := $(filter-out -fomit-frame-pointer,$(CXX.Flags)) -pg -g
  C.Flags   := $(filter-out -fomit-frame-pointer,$(C.Flags)) -pg -g
  LD.Flags  := $(filter-out -fomit-frame-pointer,$(LD.Flags)) -pg -g
  KEEP_SYMBOLS := 1
#ifeq ($(ENABLE_VISIBILITY_INLINES_HIDDEN),1)
#    CXX.Flags += -fvisibility-inlines-hidden
#endif

ifdef ENABLE_EXPENSIVE_CHECKS
  # GNU libstdc++ uses RTTI if you define _GLIBCXX_DEBUG, which we did above.
  # See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40160
  REQUIRES_RTTI := 1
endif

Reid Spencer's avatar
Reid Spencer committed
# IF REQUIRES_EH=1 is specified then don't disable exceptions
ifndef REQUIRES_EH
  CXX.Flags += -fno-exceptions
else
  # If the library requires EH, it also requires RTTI.
  REQUIRES_RTTI := 1
Reid Spencer's avatar
Reid Spencer committed

ifdef REQUIRES_FRAME_POINTER
  CXX.Flags := $(filter-out -fomit-frame-pointer,$(CXX.Flags))
  C.Flags   := $(filter-out -fomit-frame-pointer,$(C.Flags))
  LD.Flags  := $(filter-out -fomit-frame-pointer,$(LD.Flags))
endif

# If REQUIRES_RTTI=1 is specified then don't disable run-time type id.
ifneq ($(REQUIRES_RTTI), 1)
  CXX.Flags += -fno-rtti
  BuildMode := $(BuildMode)+Coverage
  CXX.Flags += -ftest-coverage -fprofile-arcs
  C.Flags   += -ftest-coverage -fprofile-arcs
# If DISABLE_ASSERTIONS=1 is specified (make command line or configured),
# then disable assertions by defining the appropriate preprocessor symbols.
ifeq ($(DISABLE_ASSERTIONS),1)
  CPP.Defines += -DNDEBUG
else
  BuildMode := $(BuildMode)+Asserts
# If ENABLE_EXPENSIVE_CHECKS=1 is specified (make command line or
# configured), then enable expensive checks by defining the
# appropriate preprocessor symbols.
ifeq ($(ENABLE_EXPENSIVE_CHECKS),1)
  BuildMode := $(BuildMode)+Checks
  CPP.Defines += -D_GLIBCXX_DEBUG -DXDEBUG
Nick Lewycky's avatar
Nick Lewycky committed
# LOADABLE_MODULE implies several other things so we force them to be
# defined/on.
ifdef LOADABLE_MODULE
  SHARED_LIBRARY := 1
  LINK_LIBS_IN_SHARED := 1
endif

ifdef SHARED_LIBRARY
  ENABLE_PIC := 1
  PIC_FLAG = "(PIC)"
endif

  ifeq ($(HOST_OS), $(filter $(HOST_OS), Cygwin MingW))
    # Nothing. Win32 defaults to PIC and warns when given -fPIC
  else
Nick Lewycky's avatar
Nick Lewycky committed
      # Common symbols not allowed in dylib files
      CXX.Flags += -fno-common
      C.Flags   += -fno-common
    else
      # Linux and others; pass -fPIC
      CXX.Flags += -fPIC
      C.Flags   += -fPIC
    endif
  endif
      CXX.Flags += -mdynamic-no-pic
      C.Flags   += -mdynamic-no-pic
  endif
# Support makefile variable to disable any kind of timestamp/non-deterministic
# info from being used in the build.
ifeq ($(ENABLE_TIMESTAMPS),1)
  DOTDIR_TIMESTAMP_COMMAND := $(DATE)
else
  DOTDIR_TIMESTAMP_COMMAND := echo 'Created.'
endif

ifeq ($(HOST_OS),MingW)
  # Work around PR4957
  CPP.Defines += -D__NO_CTYPE_INLINE
  ifeq ($(LLVM_CROSS_COMPILING),1)
    # Work around http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=525016
    ifdef TOOLNAME
      LD.Flags += -Wl,--allow-multiple-definition
    endif
  endif
endif

Chris Lattner's avatar
Chris Lattner committed
CXX.Flags     += -Woverloaded-virtual
CPP.BaseFlags += $(CPP.Defines)
Reid Spencer's avatar
Reid Spencer committed

# Make Floating point IEEE compliant on Alpha.
ifeq ($(ARCH),Alpha)
  CXX.Flags     += -mieee
  CPP.BaseFlags += -mieee
ifeq ($(ENABLE_PIC),0)
  CXX.Flags     += -fPIC
  CPP.BaseFlags += -fPIC
endif
  LD.Flags += -Wl,--no-relax
endif

# GNU ld/PECOFF accepts but ignores them below;
#   --version-script
#   --export-dynamic
#   --rpath
# FIXME: autoconf should be aware of them.
ifneq (,$(filter $(HOST_OS),Cygwin MingW))
  HAVE_LINK_VERSION_SCRIPT := 0
  RPATH :=
  RDYNAMIC := -Wl,--export-all-symbols
endif

Reid Spencer's avatar
Reid Spencer committed
#--------------------------------------------------------------------
Reid Spencer's avatar
Reid Spencer committed
#--------------------------------------------------------------------
TargetMode :=
ifeq ($(LLVM_CROSS_COMPILING),1)
  BuildLLVMToolDir := $(LLVM_OBJ_ROOT)/BuildTools/$(BuildMode)/bin
endif

ObjRootDir  := $(PROJ_OBJ_DIR)/$(BuildMode)
ObjDir      := $(ObjRootDir)
LibDir      := $(PROJ_OBJ_ROOT)/$(BuildMode)/lib
ToolDir     := $(PROJ_OBJ_ROOT)/$(BuildMode)/bin
ExmplDir    := $(PROJ_OBJ_ROOT)/$(BuildMode)/examples
LLVMLibDir  := $(LLVM_OBJ_ROOT)/$(BuildMode)/lib
LLVMToolDir := $(LLVM_OBJ_ROOT)/$(BuildMode)/bin
LLVMExmplDir:= $(LLVM_OBJ_ROOT)/$(BuildMode)/examples
#--------------------------------------------------------------------
# Locations of shared libraries
#--------------------------------------------------------------------

SharedPrefix     := lib
SharedLibDir     := $(LibDir)
LLVMSharedLibDir := $(LLVMLibDir)

# Win32.DLL prefers to be located on the "PATH" of binaries.
ifeq ($(HOST_OS), $(filter $(HOST_OS), Cygwin MingW))
  SharedLibDir     := $(ToolDir)
  LLVMSharedLibDir := $(LLVMToolDir)

  ifeq ($(HOST_OS),Cygwin)
    SharedPrefix  := cyg
  else
    SharedPrefix  :=
  endif
endif

#--------------------------------------------------------------------
# LLVM Capable Compiler
#--------------------------------------------------------------------

ifneq ($(findstring llvm-gcc,$(LLVMCC_OPTION)),)
  LLVMCC := $(LLVMGCC)
  LLVMCXX := $(LLVMGXX)
else
  ifneq ($(findstring clang,$(LLVMCC_OPTION)),)
    ifneq ($(CLANGPATH),)
      LLVMCC := $(CLANGPATH)
      LLVMCXX := $(CLANGXXPATH)
    else
      ifeq ($(ENABLE_BUILT_CLANG),1)
        LLVMCC := $(LLVMToolDir)/clang
        LLVMCXX := $(LLVMToolDir)/clang++
      endif
    endif
  endif
endif

Reid Spencer's avatar
Reid Spencer committed
#--------------------------------------------------------------------
# Full Paths To Compiled Tools and Utilities
Reid Spencer's avatar
Reid Spencer committed
#--------------------------------------------------------------------
EchoCmd  = $(ECHO) llvm[$(MAKELEVEL)]:
Echo     = @$(EchoCmd)
ifndef LLVMAS
LLVMAS   := $(LLVMToolDir)/llvm-as$(EXEEXT)
endif
ifndef TBLGEN
Reid Spencer's avatar
Reid Spencer committed
  ifeq ($(LLVM_CROSS_COMPILING),1)
    TBLGEN   := $(BuildLLVMToolDir)/tblgen$(BUILD_EXEEXT)
Reid Spencer's avatar
Reid Spencer committed
  else
    TBLGEN   := $(LLVMToolDir)/tblgen$(EXEEXT)
  endif
LLVM_CONFIG := $(LLVMToolDir)/llvm-config
Reid Spencer's avatar
Reid Spencer committed
ifndef LLVMLD
LLVMLD    := $(LLVMToolDir)/llvm-ld$(EXEEXT)
ifndef LLVMDIS
LLVMDIS  := $(LLVMToolDir)/llvm-dis$(EXEEXT)
endif
ifndef LLI
LLI      := $(LLVMToolDir)/lli$(EXEEXT)
endif
Alkis Evlogimenos's avatar
Alkis Evlogimenos committed
ifndef LLC
LLC      := $(LLVMToolDir)/llc$(EXEEXT)
endif
ifndef LOPT
Alkis Evlogimenos's avatar
Alkis Evlogimenos committed
LOPT     := $(LLVMToolDir)/opt$(EXEEXT)
endif
ifndef LBUGPOINT
LBUGPOINT := $(LLVMToolDir)/bugpoint$(EXEEXT)
endif
Reid Spencer's avatar
Reid Spencer committed
#--------------------------------------------------------------------
Reid Spencer's avatar
Reid Spencer committed
#--------------------------------------------------------------------
  DARWIN_VERSION := `sw_vers -productVersion`
  # Strip a number like 10.4.7 to 10.4
  DARWIN_VERSION := $(shell echo $(DARWIN_VERSION)| sed -E 's/(10.[0-9]).*/\1/')
  # Get "4" out of 10.4 for later pieces in the makefile.
  DARWIN_MAJVERS := $(shell echo $(DARWIN_VERSION)| sed -E 's/10.([0-9]).*/\1/')
  LoadableModuleOptions := -Wl,-flat_namespace -Wl,-undefined,suppress
  SharedLinkOptions := -dynamiclib
  ifneq ($(ARCH),ARM)
    SharedLinkOptions += -mmacosx-version-min=$(DARWIN_VERSION)
  endif
  ifneq ($(ARCH),ARM)
    TargetCommonOpts += -mmacosx-version-min=$(DARWIN_VERSION)
  endif
ifneq ($(HOST_OS), $(filter $(HOST_OS), Cygwin MingW))
ifneq ($(HOST_OS),Darwin)
  LD.Flags += $(RPATH) -Wl,'$$ORIGIN'
ifdef TOOL_VERBOSE
  C.Flags += -v
  CXX.Flags += -v
  LD.Flags += -v
  VERBOSE := 1
endif

Reid Spencer's avatar
Reid Spencer committed
# Adjust settings for verbose mode
  AR.Flags += >/dev/null 2>/dev/null
Reid Spencer's avatar
Reid Spencer committed
  ConfigureScriptFLAGS += >$(PROJ_OBJ_DIR)/configure.out 2>&1
Reid Spencer's avatar
Reid Spencer committed
else
  ConfigureScriptFLAGS :=
# By default, strip symbol information from executable
  Strip := $(PLATFORMSTRIPOPTS)
  StripWarnMsg := "(without symbols)"
ifdef TOOL_NO_EXPORTS
  DynamicFlags :=
else
  DynamicFlag := $(RDYNAMIC)
endif

Reid Spencer's avatar
Reid Spencer committed
# Adjust linker flags for building an executable
ifneq ($(HOST_OS), $(filter $(HOST_OS), Cygwin MingW))
ifneq ($(HOST_OS), Darwin)
  LD.Flags += $(RPATH) -Wl,'$$ORIGIN/../lib'
  ifdef EXAMPLE_TOOL
    LD.Flags += $(RPATH) -Wl,$(ExmplDir) $(DynamicFlag)
    LD.Flags += $(RPATH) -Wl,$(ToolDir) $(DynamicFlag)
else
ifneq ($(DARWIN_MAJVERS),4)
  LD.Flags += $(RPATH) -Wl,@executable_path/../lib
Nick Lewycky's avatar
Nick Lewycky committed
endif
Nick Lewycky's avatar
Nick Lewycky committed

Reid Spencer's avatar
Reid Spencer committed
#----------------------------------------------------------
Reid Spencer's avatar
Reid Spencer committed
#----------------------------------------------------------
CompileCommonOpts += -pedantic -Wno-long-long
CompileCommonOpts += -Wall -W -Wno-unused-parameter -Wwrite-strings \
                     $(EXTRA_OPTIONS)
# Enable cast-qual for C++; the workaround is to use const_cast.
CXX.Flags += -Wcast-qual
Chris Lattner's avatar
Chris Lattner committed

Duraid Madina's avatar
Duraid Madina committed
  CompileCommonOpts := -D_REENTRANT -D_HPUX_SOURCE
# If we are building a universal binary on Mac OS/X, pass extra options.  This
# is useful to people that want to link the LLVM libraries into their universal
# apps.
#
# The following can be optionally specified:
#   UNIVERSAL_SDK_PATH variable can be specified as a path to the SDK to use.
#      For Mac OS/X 10.4 Intel machines, the traditional one is:
#      UNIVERSAL_SDK_PATH=/Developer/SDKs/MacOSX10.4u.sdk/
#   UNIVERSAL_ARCH can be optionally specified to be a list of architectures
#      to build for, e.g. UNIVERSAL_ARCH="i386 ppc ppc64".  This defaults to
#      i386/ppc only.
  ifndef UNIVERSAL_ARCH
    UNIVERSAL_ARCH := i386 ppc
  endif
  UNIVERSAL_ARCH_OPTIONS := $(UNIVERSAL_ARCH:%=-arch %)
  CompileCommonOpts += $(UNIVERSAL_ARCH_OPTIONS)
  ifdef UNIVERSAL_SDK_PATH
    CompileCommonOpts += -isysroot $(UNIVERSAL_SDK_PATH)
  endif

  # Building universal cannot compute dependencies automatically.
      TargetCommonOpts = -m64
        TargetCommonOpts = -m32
CPP.BaseFlags += -include llvm/Support/Solaris.h
ifeq ($(HOST_OS),AuroraUX)
CPP.BaseFlags += -include llvm/Support/Solaris.h
endif # !HOST_OS - AuroraUX.

LD.Flags      += -L$(LibDir) -L$(LLVMLibDir)
CPP.BaseFlags += -D_GNU_SOURCE -D__STDC_LIMIT_MACROS -D__STDC_CONSTANT_MACROS
# All -I flags should go here, so that they don't confuse llvm-config.
CPP.Flags     += $(sort -I$(PROJ_OBJ_DIR) -I$(PROJ_SRC_DIR) \
	         $(patsubst %,-I%/include,\
	         $(PROJ_OBJ_ROOT) $(PROJ_SRC_ROOT) \
	         $(LLVM_OBJ_ROOT) $(LLVM_SRC_ROOT))) \
	         $(CPP.BaseFlags)
# SHOW_DIAGNOSTICS support.
ifeq ($(SHOW_DIAGNOSTICS),1)
  Compile.Wrapper := env CC_LOG_DIAGNOSTICS=1 \
	                  CC_LOG_DIAGNOSTICS_FILE="$(LLVM_OBJ_ROOT)/$(BuildMode)/diags"
else
  Compile.Wrapper :=
endif

  Compile.C     = $(Compile.Wrapper) \
	          $(BUILD_CC) $(CPP.Flags) $(C.Flags) $(CFLAGS) $(CPPFLAGS) \
                  $(TargetCommonOpts) $(CompileCommonOpts) -c
  Compile.CXX   = $(Compile.Wrapper) \
	          $(BUILD_CXX) $(CPP.Flags) $(CXX.Flags) $(CXXFLAGS) \
                  $(TargetCommonOpts) $(CompileCommonOpts) -c
  Preprocess.CXX= $(Compile.Wrapper) \
	          $(BUILD_CXX) $(CPP.Flags) $(CPPFLAGS) $(TargetCommonOpts) \
                  $(CompileCommonOpts) $(CXX.Flags) -E
  Link          = $(Compile.Wrapper) \
	          $(BUILD_CXX) $(CPP.Flags) $(CXX.Flags) $(CXXFLAGS) \
		  $(LD.Flags) $(LDFLAGS) \
                  $(TargetCommonOpts) $(CompileCommonOpts) $(Strip)
  Compile.C     = $(Compile.Wrapper) \
	          $(CC) $(CPP.Flags) $(C.Flags) $(CFLAGS) $(CPPFLAGS) \
                  $(TargetCommonOpts) $(CompileCommonOpts) -c
  Compile.CXX   = $(Compile.Wrapper) \
	          $(CXX) $(CPP.Flags) $(CXX.Flags) $(CXXFLAGS) $(CPPFLAGS) \
                  $(TargetCommonOpts) $(CompileCommonOpts) -c
  Preprocess.CXX= $(Compile.Wrapper) \
	          $(CXX) $(CPP.Flags) $(TargetCommonOpts) $(CPPFLAGS) \
                  $(CompileCommonOpts) $(CXX.Flags) -E
  Link          = $(Compile.Wrapper) \
	          $(CXX) $(CPP.Flags) $(CXX.Flags) $(CXXFLAGS) $(LD.Flags) \
                  $(LDFLAGS) $(TargetCommonOpts)  $(CompileCommonOpts) $(Strip)
BCCompile.C   = $(LLVMCC) $(CPP.Flags) $(C.Flags) $(CFLAGS) $(CPPFLAGS) \
                $(TargetCommonOpts) $(CompileCommonOpts)
Preprocess.C  = $(CC) $(CPP.Flags) $(C.Flags) $(CPPFLAGS) \
                $(TargetCommonOpts) $(CompileCommonOpts) -E
BCCompile.CXX = $(LLVMCXX) $(CPP.Flags) $(CXX.Flags) $(CXXFLAGS) $(CPPFLAGS) \
                $(TargetCommonOpts) $(CompileCommonOpts)
ProgInstall   = $(INSTALL) $(Install.StripFlag) -m 0755
ScriptInstall = $(INSTALL) -m 0755
DataInstall   = $(INSTALL) -m 0644

# When compiling under Mingw/Cygwin, the tblgen tool expects Windows
# paths. In this case, the SYSPATH function (defined in
# Makefile.config) transforms Unix paths into Windows paths.
TableGen      = $(TBLGEN) -I $(call SYSPATH, $(PROJ_SRC_DIR)) \
                -I $(call SYSPATH, $(LLVM_SRC_ROOT)/include) \
                -I $(call SYSPATH, $(PROJ_SRC_ROOT)/include) \
                -I $(call SYSPATH, $(PROJ_SRC_ROOT)/lib/Target)

Reid Spencer's avatar
Reid Spencer committed
LArchive      = $(LLVMToolDir)/llvm-ar rcsf
Reid Spencer's avatar
Reid Spencer committed
Ranlib        = $(RANLIB)
Reid Spencer's avatar
Reid Spencer committed
Ranlib        = ranlib
Chris Lattner's avatar
Chris Lattner committed

Chris Lattner's avatar
Chris Lattner committed
#----------------------------------------------------------
# Get the list of source files and compute object file
# names from them.
Reid Spencer's avatar
Reid Spencer committed
#----------------------------------------------------------
Chris Lattner's avatar
Chris Lattner committed
ifndef SOURCES
  Sources := $(notdir $(wildcard $(PROJ_SRC_DIR)/*.cpp \
             $(PROJ_SRC_DIR)/*.cc $(PROJ_SRC_DIR)/*.c))
Chris Lattner's avatar
Chris Lattner committed
else
  Sources := $(SOURCES)
endif
Chris Lattner's avatar
Chris Lattner committed
ifdef BUILT_SOURCES
Sources += $(filter %.cpp %.c %.cc,$(BUILT_SOURCES))
endif
Reid Spencer's avatar
Reid Spencer committed

Chris Lattner's avatar
Chris Lattner committed
BaseNameSources := $(sort $(basename $(Sources)))

ObjectsO  := $(BaseNameSources:%=$(ObjDir)/%.o)
ObjectsBC := $(BaseNameSources:%=$(ObjDir)/%.bc)

#----------------------------------------------------------
# For Mingw MSYS bash and Python/w32:
#
# $(ECHOPATH) prints DOSish pathstring.
#   ex) $(ECHOPATH) /include/sys/types.h
#   --> C:/mingw/include/sys/types.h
# built-in "echo" does not transform path to DOSish path.
#
# FIXME: It would not be needed when MSYS's python
# were provided.
#----------------------------------------------------------

ifeq (-mingw32,$(findstring -mingw32,$(BUILD_TRIPLE)))
  ECHOPATH := $(Verb)python -u -c "import sys;print ' '.join(sys.argv[1:])"
else
  ECHOPATH := $(Verb)$(ECHO)
endif

Reid Spencer's avatar
Reid Spencer committed
###############################################################################
# DIRECTORIES: Handle recursive descent of directory structure
###############################################################################
Reid Spencer's avatar
Reid Spencer committed
#---------------------------------------------------------
# Provide rules to make install dirs. This must be early
# in the file so they get built before dependencies
#---------------------------------------------------------

$(DESTDIR)$(PROJ_bindir) $(DESTDIR)$(PROJ_libdir) $(DESTDIR)$(PROJ_includedir) $(DESTDIR)$(PROJ_etcdir)::
Reid Spencer's avatar
Reid Spencer committed

# To create other directories, as needed, and timestamp their creation
%/.dir:
	$(Verb) $(MKDIR) $* > /dev/null
	$(Verb) $(DOTDIR_TIMESTAMP_COMMAND) > $@
Reid Spencer's avatar
Reid Spencer committed
.PRECIOUS: $(ObjDir)/.dir $(LibDir)/.dir $(ToolDir)/.dir $(ExmplDir)/.dir
.PRECIOUS: $(LLVMLibDir)/.dir $(LLVMToolDir)/.dir $(LLVMExmplDir)/.dir
Reid Spencer's avatar
Reid Spencer committed

Chris Lattner's avatar
Chris Lattner committed
#---------------------------------------------------------
Reid Spencer's avatar
Reid Spencer committed
# Handle the DIRS options for sequential construction
Chris Lattner's avatar
Chris Lattner committed
#---------------------------------------------------------

SubDirs :=

ifneq ($(PROJ_SRC_ROOT),$(PROJ_OBJ_ROOT))
$(RecursiveTargets)::
	$(Verb) for dir in $(DIRS); do \
	      command test $$dir/Makefile -ot $(PROJ_SRC_DIR)/$$dir/Makefile ); then \
Reid Spencer's avatar
Reid Spencer committed
	    $(CP) $(PROJ_SRC_DIR)/$$dir/Makefile $$dir/Makefile; \
	  ($(MAKE) -C $$dir $@ ) || exit 1; \
else
$(RecursiveTargets)::
	$(Verb) for dir in $(DIRS); do \
	  ($(MAKE) -C $$dir $@ ) || exit 1; \
	done
endif

Reid Spencer's avatar
Reid Spencer committed
#---------------------------------------------------------
# Handle the EXPERIMENTAL_DIRS options ensuring success
# after each directory is built.
#---------------------------------------------------------
ifdef EXPERIMENTAL_DIRS
$(RecursiveTargets)::
	$(Verb) for dir in $(EXPERIMENTAL_DIRS); do \
	      command test $$dir/Makefile -ot $(PROJ_SRC_DIR)/$$dir/Makefile ); then \
Reid Spencer's avatar
Reid Spencer committed
	    $(MKDIR) $$dir; \
Reid Spencer's avatar
Reid Spencer committed
	    $(CP) $(PROJ_SRC_DIR)/$$dir/Makefile $$dir/Makefile; \
Reid Spencer's avatar
Reid Spencer committed
	  fi; \
	  ($(MAKE) -C $$dir $@ ) || exit 0; \
Reid Spencer's avatar
Reid Spencer committed
	done
endif

#-----------------------------------------------------------
# Handle the OPTIONAL_PARALLEL_DIRS options for optional parallel construction
#-----------------------------------------------------------
ifdef OPTIONAL_PARALLEL_DIRS
  PARALLEL_DIRS += $(foreach T,$(OPTIONAL_PARALLEL_DIRS),$(shell test -d $(PROJ_SRC_DIR)/$(T) && echo "$(T)"))
endif

Reid Spencer's avatar
Reid Spencer committed
#-----------------------------------------------------------
Reid Spencer's avatar
Reid Spencer committed
# Handle the PARALLEL_DIRS options for parallel construction
Reid Spencer's avatar
Reid Spencer committed
#-----------------------------------------------------------
ifdef PARALLEL_DIRS
Reid Spencer's avatar
Reid Spencer committed

# Unfortunately, this list must be maintained if new recursive targets are added
all      :: $(addsuffix /.makeall      ,$(PARALLEL_DIRS))
clean    :: $(addsuffix /.makeclean    ,$(PARALLEL_DIRS))
clean-all:: $(addsuffix /.makeclean-all,$(PARALLEL_DIRS))
install  :: $(addsuffix /.makeinstall  ,$(PARALLEL_DIRS))
Reid Spencer's avatar
Reid Spencer committed
uninstall:: $(addsuffix /.makeuninstall,$(PARALLEL_DIRS))
install-bytecode  :: $(addsuffix /.makeinstall-bytecode,$(PARALLEL_DIRS))
unitcheck:: $(addsuffix /.makeunitcheck,$(PARALLEL_DIRS))
ParallelTargets := $(foreach T,$(RecursiveTargets),%/.make$(T))
Reid Spencer's avatar
Reid Spencer committed

$(ParallelTargets) :
	$(Verb) if ([ ! -f $(@D)/Makefile ] || \
	            command test $(@D)/Makefile -ot \
                      $(PROJ_SRC_DIR)/$(@D)/Makefile ); then \
Reid Spencer's avatar
Reid Spencer committed
	  $(CP) $(PROJ_SRC_DIR)/$(@D)/Makefile $(@D)/Makefile; \
Reid Spencer's avatar
Reid Spencer committed
	$(MAKE) -C $(@D) $(subst $(@D)/.make,,$@)
Chris Lattner's avatar
Chris Lattner committed
endif

Reid Spencer's avatar
Reid Spencer committed
#---------------------------------------------------------
# Handle the OPTIONAL_DIRS options for directores that may
# or may not exist.
#---------------------------------------------------------
ifneq ($(PROJ_SRC_ROOT),$(PROJ_OBJ_ROOT))
$(RecursiveTargets)::
	$(Verb) for dir in $(OPTIONAL_DIRS); do \
Reid Spencer's avatar
Reid Spencer committed
	  if [ -d $(PROJ_SRC_DIR)/$$dir ]; then\
	        command test $$dir/Makefile -ot $(PROJ_SRC_DIR)/$$dir/Makefile ); then \
Reid Spencer's avatar
Reid Spencer committed
	      $(CP) $(PROJ_SRC_DIR)/$$dir/Makefile $$dir/Makefile; \
	    ($(MAKE) -C$$dir $@ ) || exit 1; \
else
$(RecursiveTargets)::
	$(Verb) for dir in $(OPTIONAL_DIRS); do \
Stephen Wilson's avatar
 
Stephen Wilson committed
	  if [ -d $(PROJ_SRC_DIR)/$$dir ]; then\
	    ($(MAKE) -C$$dir $@ ) || exit 1; \
	  fi \
#---------------------------------------------------------
# Handle the CONFIG_FILES options
#---------------------------------------------------------
ifdef CONFIG_FILES

ifdef NO_INSTALL
install-local::
	$(Echo) Install circumvented with NO_INSTALL
uninstall-local::
	$(Echo) UnInstall circumvented with NO_INSTALL
else
install-local:: $(DESTDIR)$(PROJ_etcdir) $(CONFIG_FILES)
	$(Echo) Installing Configuration Files To $(DESTDIR)$(PROJ_etcdir)
	$(Verb)for file in $(CONFIG_FILES); do \
Reid Spencer's avatar
Reid Spencer committed
          if test -f $(PROJ_OBJ_DIR)/$${file} ; then \
            $(DataInstall) $(PROJ_OBJ_DIR)/$${file} $(DESTDIR)$(PROJ_etcdir) ; \
Reid Spencer's avatar
Reid Spencer committed
          elif test -f $(PROJ_SRC_DIR)/$${file} ; then \
            $(DataInstall) $(PROJ_SRC_DIR)/$${file} $(DESTDIR)$(PROJ_etcdir) ; \
          else \
            $(ECHO) Error: cannot find config file $${file}. ; \
          fi \
Reid Spencer's avatar
Reid Spencer committed

	$(Echo) Uninstalling Configuration Files From $(DESTDIR)$(PROJ_etcdir)
	$(Verb)for file in $(CONFIG_FILES); do \
	  $(RM) -f $(DESTDIR)$(PROJ_etcdir)/$${file} ; \
Reid Spencer's avatar
Reid Spencer committed
	done
###############################################################################
Eric Christopher's avatar
Eric Christopher committed
# Set up variables for building libraries
###############################################################################

#---------------------------------------------------------
# Define various command line options pertaining to the
# libraries needed when linking. There are "Proj" libs
# (defined by the user's project) and "LLVM" libs (defined
#---------------------------------------------------------
ProjLibsOptions := $(patsubst %.a.o, -l%, $(addsuffix .o, $(USEDLIBS)))
ProjLibsOptions := $(patsubst %.o, $(LibDir)/%.o,  $(ProjLibsOptions))
ProjUsedLibs    := $(patsubst %.a.o, lib%.a, $(addsuffix .o, $(USEDLIBS)))
ProjLibsPaths   := $(addprefix $(LibDir)/,$(ProjUsedLibs))
endif

ifdef LLVMLIBS
LLVMLibsOptions := $(patsubst %.a.o, -l%, $(addsuffix .o, $(LLVMLIBS)))
LLVMLibsOptions := $(patsubst %.o, $(LLVMLibDir)/%.o, $(LLVMLibsOptions))
LLVMUsedLibs    := $(patsubst %.a.o, lib%.a, $(addsuffix .o, $(LLVMLIBS)))
LLVMLibsPaths   := $(addprefix $(LLVMLibDir)/,$(LLVMUsedLibs))
# Loadable module for Win32 requires all symbols resolved for linking.
# Then all symbols in LLVM.dll will be available.
ifeq ($(ENABLE_SHARED),1)
    ifneq (,$(filter $(HOST_OS),Cygwin MingW))
      LINK_COMPONENTS += all
    endif
ifndef IS_CLEANING_TARGET

# If LLVM_CONFIG doesn't exist, build it.  This can happen if you do a make
# clean in tools, then do a make in tools (instead of at the top level).
$(LLVM_CONFIG):
	@echo "*** llvm-config doesn't exist - rebuilding it."
	@$(MAKE) -C $(PROJ_OBJ_ROOT)/tools/llvm-config
$(ToolDir)/$(strip $(TOOLNAME))$(EXEEXT): $(LLVM_CONFIG)

# We can take the "auto-import" feature to get rid of using dllimport.
ifeq ($(HOST_OS), $(filter $(HOST_OS), Cygwin MingW))
LLVMLibsOptions += -Wl,--enable-auto-import,--enable-runtime-pseudo-reloc \
                   -L $(SharedLibDir)
endif
LLVMLibsOptions += -lLLVM-$(LLVMVersion)
LLVMLibsPaths += $(SharedLibDir)/$(SharedPrefix)LLVM-$(LLVMVersion)$(SHLIBEXT)

ifndef NO_LLVM_CONFIG
LLVMConfigLibs := $(shell $(LLVM_CONFIG) --libs $(LINK_COMPONENTS) || echo Error)
ifeq ($(LLVMConfigLibs),Error)
$(error llvm-config --libs failed)
endif
LLVMLibsOptions += $(LLVMConfigLibs)
LLVMConfigLibfiles := $(shell $(LLVM_CONFIG) --libfiles $(LINK_COMPONENTS) || echo Error)
ifeq ($(LLVMConfigLibfiles),Error)
$(error llvm-config --libfiles failed)
endif
LLVMLibsPaths += $(LLVM_CONFIG) $(LLVMConfigLibfiles)
endif

# Set up the library exports file.
ifdef EXPORTED_SYMBOL_FILE

# First, set up the native export file, which may differ from the source
# export file.

ifeq ($(HOST_OS),Darwin)
# Darwin convention prefixes symbols with underscores.
NativeExportsFile := $(ObjDir)/$(notdir $(EXPORTED_SYMBOL_FILE)).sed
$(NativeExportsFile): $(EXPORTED_SYMBOL_FILE) $(ObjDir)/.dir
	$(Verb) sed -e 's/^/_/' < $< > $@