Skip to content
Makefile.rules 67.8 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:
Nick Lewycky's avatar
Nick Lewycky committed
.SUFFIXES: .c .cpp .cc .h .hpp .o .a .bc .td .ps .dot .ll
.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)

Anton Korobeynikov's avatar
Anton Korobeynikov committed
# FIXME: The {PIC16,MSP430}/AsmPrinter line here is a hack to force a reconfigure to pick
# up AsmPrinter changes. Remove it after a reasonable delay from 2009-08-13.

Anton Korobeynikov's avatar
Anton Korobeynikov committed
$(ConfigStatusScript): $(ConfigureScript) $(LLVM_SRC_ROOT)/lib/Target/PIC16/AsmPrinter/Makefile $(LLVM_SRC_ROOT)/lib/Target/MSP430/AsmPrinter/Makefile
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
#------------------------------------------------------------------------
Reid Spencer's avatar
Reid Spencer committed
ifneq ($(PROJ_OBJ_DIR),$(PROJ_SRC_DIR))
Reid Spencer's avatar
Reid Spencer committed

Makefile: $(PROJ_SRC_DIR)/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.
Reid Spencer's avatar
Reid Spencer committed
$(PROJ_OBJ_DIR)/Makefile% : $(PROJ_SRC_DIR)/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 plugins
###############################################################################

ifdef LLVMC_PLUGIN

LIBRARYNAME := $(patsubst %,plugin_llvmc_%,$(LLVMC_PLUGIN))
CPP.Flags += -DLLVMC_PLUGIN_NAME=$(LLVMC_PLUGIN)

ifeq ($(ENABLE_LLVMC_DYNAMIC),1)
  LD.Flags += -lCompilerDriver
endif

# Build a dynamic library if the user runs `make` directly from the plugin
# directory.
ifndef LLVMC_BUILTIN_PLUGIN
  LOADABLE_MODULE = 1
endif

# TableGen stuff...
ifneq ($(BUILT_SOURCES),)
  LLVMC_BUILD_AUTOGENERATED_INC=1
Mikhail Glushenkov's avatar
Mikhail Glushenkov committed
ifdef LLVMC_BASED_DRIVER

TOOLNAME = $(LLVMC_BASED_DRIVER)
Mikhail Glushenkov's avatar
Mikhail Glushenkov committed
REQUIRES_EH := 1

ifeq ($(ENABLE_LLVMC_DYNAMIC),1)
  LD.Flags += -lCompilerDriver
else
  LLVMLIBS = CompilerDriver.a
  LINK_COMPONENTS = support system
endif
Mikhail Glushenkov's avatar
Mikhail Glushenkov committed

# Preprocessor magic that generates references to static variables in built-in
# plugins.
ifneq ($(LLVMC_BUILTIN_PLUGINS),)

USEDLIBS += $(patsubst %,plugin_llvmc_%.a,$(LLVMC_BUILTIN_PLUGINS))

LLVMC_BUILTIN_PLUGIN_1 = $(word 1, $(LLVMC_BUILTIN_PLUGINS))
LLVMC_BUILTIN_PLUGIN_2 = $(word 2, $(LLVMC_BUILTIN_PLUGINS))
LLVMC_BUILTIN_PLUGIN_3 = $(word 3, $(LLVMC_BUILTIN_PLUGINS))
LLVMC_BUILTIN_PLUGIN_4 = $(word 4, $(LLVMC_BUILTIN_PLUGINS))
LLVMC_BUILTIN_PLUGIN_5 = $(word 5, $(LLVMC_BUILTIN_PLUGINS))
LLVMC_BUILTIN_PLUGIN_6 = $(word 6, $(LLVMC_BUILTIN_PLUGINS))
LLVMC_BUILTIN_PLUGIN_7 = $(word 7, $(LLVMC_BUILTIN_PLUGINS))
LLVMC_BUILTIN_PLUGIN_8 = $(word 8, $(LLVMC_BUILTIN_PLUGINS))
LLVMC_BUILTIN_PLUGIN_9 = $(word 9, $(LLVMC_BUILTIN_PLUGINS))
LLVMC_BUILTIN_PLUGIN_10 = $(word 10, $(LLVMC_BUILTIN_PLUGINS))

Mikhail Glushenkov's avatar
Mikhail Glushenkov committed

ifneq ($(LLVMC_BUILTIN_PLUGIN_1),)
CPP.Flags += -DLLVMC_BUILTIN_PLUGIN_1=$(LLVMC_BUILTIN_PLUGIN_1)
endif

ifneq ($(LLVMC_BUILTIN_PLUGIN_2),)
CPP.Flags += -DLLVMC_BUILTIN_PLUGIN_2=$(LLVMC_BUILTIN_PLUGIN_2)
endif

ifneq ($(LLVMC_BUILTIN_PLUGIN_3),)
CPP.Flags += -DLLVMC_BUILTIN_PLUGIN_3=$(LLVMC_BUILTIN_PLUGIN_3)
endif

ifneq ($(LLVMC_BUILTIN_PLUGIN_4),)
CPP.Flags += -DLLVMC_BUILTIN_PLUGIN_4=$(LLVMC_BUILTIN_PLUGIN_4)
endif

ifneq ($(LLVMC_BUILTIN_PLUGIN_5),)
CPP.Flags += -DLLVMC_BUILTIN_PLUGIN_5=$(LLVMC_BUILTIN_PLUGIN_5)
endif

ifneq ($(LLVMC_BUILTIN_PLUGIN_6),)
CPP.Flags += -DLLVMC_BUILTIN_PLUGIN_5=$(LLVMC_BUILTIN_PLUGIN_6)
endif

ifneq ($(LLVMC_BUILTIN_PLUGIN_7),)
CPP.Flags += -DLLVMC_BUILTIN_PLUGIN_5=$(LLVMC_BUILTIN_PLUGIN_7)
endif

ifneq ($(LLVMC_BUILTIN_PLUGIN_8),)
CPP.Flags += -DLLVMC_BUILTIN_PLUGIN_5=$(LLVMC_BUILTIN_PLUGIN_8)
endif

ifneq ($(LLVMC_BUILTIN_PLUGIN_9),)
CPP.Flags += -DLLVMC_BUILTIN_PLUGIN_5=$(LLVMC_BUILTIN_PLUGIN_9)
endif

ifneq ($(LLVMC_BUILTIN_PLUGIN_10),)
CPP.Flags += -DLLVMC_BUILTIN_PLUGIN_5=$(LLVMC_BUILTIN_PLUGIN_10)
endif


Mikhail Glushenkov's avatar
Mikhail Glushenkov committed
endif

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.
ifeq ($(REQUIRES_RTTI), 1)
  CXX.Flags := $(filter-out -fno-rtti,$(CXX.Flags))
  CXXFLAGS := $(filter-out -fno-rtti,$(CXXFLAGS))
ifdef ENABLE_COVERAGE
  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.
ifdef DISABLE_ASSERTIONS
  # Indicate that assertions are turned off using a minus sign
  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.
ifdef ENABLE_EXPENSIVE_CHECKS
  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
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

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
ifeq ($(ARCH),Alpha)
  LD.Flags += -Wl,--no-relax
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
Reid Spencer's avatar
Reid Spencer committed
CFERuntimeLibDir := $(LLVMGCCDIR)/lib
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
ifndef LUPGRADE
LUPGRADE := $(LLVMToolDir)/llvm-upgrade$(EXEEXT)
endif
ifeq ($(LLVMGCC_MAJVERS),3)
LLVMGCCWITHPATH  := PATH="$(LLVMToolDir):$(PATH)" $(LLVMGCC)
LLVMGXXWITHPATH  := PATH="$(LLVMToolDir):$(PATH)" $(LLVMGXX)
LLVMGCCWITHPATH  := $(LLVMGCC)
LLVMGXXWITHPATH  := $(LLVMGXX)
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/')
  SharedLinkOptions=-Wl,-flat_namespace -Wl,-undefined -Wl,suppress \
                    -dynamiclib
  ifneq ($(ARCH),ARM)
    SharedLinkOptions += -mmacosx-version-min=$(DARWIN_VERSION)
  endif
    SharedLinkOptions=-shared -nostdlib -Wl,--export-all-symbols \
                      -Wl,--enable-auto-import -Wl,--enable-auto-image-base
  ifneq ($(ARCH),ARM)
    TargetCommonOpts += -mmacosx-version-min=$(DARWIN_VERSION)
  else
    TargetCommonOpts += -marm
Nick Lewycky's avatar
Nick Lewycky committed
# Adjust LD.Flags depending on the kind of library that is to be built. Note
# that if LOADABLE_MODULE is specified then the resulting shared library can
# be opened with dlopen.
Reid Spencer's avatar
Reid Spencer committed
ifdef LOADABLE_MODULE
  LD.Flags += -module
endif

  LD.Flags += $(RPATH) -Wl,$(LibDir)
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)"
Reid Spencer's avatar
Reid Spencer committed
# Adjust linker flags for building an executable
Reid Spencer's avatar
Reid Spencer committed
ifdef EXAMPLE_TOOL
  LD.Flags += $(RPATH) -Wl,$(ExmplDir) $(RDYNAMIC)
Reid Spencer's avatar
Reid Spencer committed
else
  LD.Flags += $(RPATH) -Wl,$(ToolDir) $(RDYNAMIC)
Nick Lewycky's avatar
Nick Lewycky committed
endif
Reid Spencer's avatar
Reid Spencer committed
endif
Nick Lewycky's avatar
Nick Lewycky committed
endif

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)
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/System/Solaris.h
endif

ifeq ($(HOST_OS),AuroraUX)
CPP.BaseFlags += -include llvm/System/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)
  Compile.C     = $(BUILD_CC) $(CPP.Flags) $(C.Flags) $(CFLAGS) $(CPPFLAGS) \
                  $(TargetCommonOpts) $(CompileCommonOpts) -c
  Compile.CXX   = $(BUILD_CXX) $(CPP.Flags) $(CXX.Flags) $(CXXFLAGS) \
		  $(CPPFLAGS) \
                  $(TargetCommonOpts) $(CompileCommonOpts) -c
  Preprocess.CXX= $(BUILD_CXX) $(CPP.Flags) $(CPPFLAGS) $(TargetCommonOpts) \
                  $(CompileCommonOpts) $(CXX.Flags) -E
  Link          = $(BUILD_CXX) $(CPP.Flags) $(CXX.Flags) $(CXXFLAGS) \
		  $(LDFLAGS) \
                  $(TargetCommonOpts) $(CompileCommonOpts) $(LD.Flags) $(Strip)
  Compile.C     = $(CC) $(CPP.Flags) $(C.Flags) $(CFLAGS) $(CPPFLAGS) \
                  $(TargetCommonOpts) $(CompileCommonOpts) -c
  Compile.CXX   = $(CXX) $(CPP.Flags) $(CXX.Flags) $(CXXFLAGS) $(CPPFLAGS) \
                  $(TargetCommonOpts) $(CompileCommonOpts) -c
  Preprocess.CXX= $(CXX) $(CPP.Flags) $(TargetCommonOpts) $(CPPFLAGS) \
                  $(CompileCommonOpts) $(CXX.Flags) -E
  Link          = $(CXX) $(CPP.Flags) $(CXX.Flags) $(CXXFLAGS) $(LDFLAGS) \
                  $(TargetCommonOpts)  $(CompileCommonOpts) $(LD.Flags) $(Strip)
BCCompile.C   = $(LLVMGCCWITHPATH) $(CPP.Flags) $(C.Flags) $(CFLAGS) \
		$(CPPFLAGS) \
                $(TargetCommonOpts) $(CompileCommonOpts)
Preprocess.C  = $(CC) $(CPP.Flags) $(C.Flags) $(CPPFLAGS) \
                $(TargetCommonOpts) $(CompileCommonOpts) -E
BCCompile.CXX = $(LLVMGXXWITHPATH) $(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)

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
#---------------------------------------------------------

$(PROJ_bindir) $(PROJ_libdir) $(PROJ_includedir) $(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) $(DATE) > $@
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 \
	  if [ ! -f $$dir/Makefile ]; then \
	    $(MKDIR) $$dir; \
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 \
Reid Spencer's avatar
Reid Spencer committed
	  if [ ! -f $$dir/Makefile ]; then \
	    $(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 ]; 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\
	    if [ ! -f $$dir/Makefile ]; then \
	      $(MKDIR) $$dir; \
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 \
	  ($(MAKE) -C$$dir $@ ) || exit 1; \
	done
endif
#---------------------------------------------------------
# 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
Reid Spencer's avatar
Reid Spencer committed
install-local:: $(PROJ_etcdir) $(CONFIG_FILES)
	$(Echo) Installing Configuration Files To $(PROJ_etcdir)
	$(Verb)for file in $(CONFIG_FILES); do \
Reid Spencer's avatar
Reid Spencer committed
          if test -f $(PROJ_OBJ_DIR)/$${file} ; then \
Reid Spencer's avatar
Reid Spencer committed
            $(DataInstall) $(PROJ_OBJ_DIR)/$${file} $(PROJ_etcdir) ; \
Reid Spencer's avatar
Reid Spencer committed
          elif test -f $(PROJ_SRC_DIR)/$${file} ; then \
Reid Spencer's avatar
Reid Spencer committed
            $(DataInstall) $(PROJ_SRC_DIR)/$${file} $(PROJ_etcdir) ; \
          else \
            $(ECHO) Error: cannot find config file $${file}. ; \
          fi \
Reid Spencer's avatar
Reid Spencer committed

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

#---------------------------------------------------------
# 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))
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)

LLVMLibsOptions += $(shell $(LLVM_CONFIG) --libs     $(LINK_COMPONENTS))
LLVMLibsPaths   += $(LLVM_CONFIG) \
                   $(shell $(LLVM_CONFIG) --libfiles $(LINK_COMPONENTS))
Reid Spencer's avatar
Reid Spencer committed
###############################################################################
# Library Build Rules: Four ways to build a library
###############################################################################
Chris Lattner's avatar
Chris Lattner committed

#---------------------------------------------------------
# Bytecode Module Targets:
#   If the user set MODULE_NAME then they want to build a
#   bytecode module from the sources. We compile all the
#   sources and link it together into a single bytecode
#   module.
#---------------------------------------------------------

ifdef MODULE_NAME
Reid Spencer's avatar
Reid Spencer committed
ifeq ($(strip $(LLVMGCC)),)
$(warning Modules require llvm-gcc but no llvm-gcc is available ****)
Reid Spencer's avatar
Reid Spencer committed
else

Module     := $(LibDir)/$(MODULE_NAME).bc
LinkModule := $(LLVMLD) -L$(CFERuntimeLibDir) -r
Chris Lattner's avatar
Chris Lattner committed
LinkModule += -internalize-public-api-file=$(EXPORTED_SYMBOL_FILE)
Reid Spencer's avatar
Reid Spencer committed
$(Module): $(BUILT_SOURCES) $(ObjectsBC) $(LibDir)/.dir $(LLVMLD)
	$(Echo) Building $(BuildMode) Bytecode Module $(notdir $@)
	$(Verb) $(LinkModule) -o $@ $(ObjectsBC)

all-local:: $(Module)

clean-local::
ifneq ($(strip $(Module)),)
	-$(Verb) $(RM) -f $(Module)
endif

ifdef BYTECODE_DESTINATION
ModuleDestDir := $(BYTECODE_DESTINATION)
else
Reid Spencer's avatar
Reid Spencer committed
ModuleDestDir := $(PROJ_libdir)