install-local:: all-local
install-bytecode:: install-bytecode-local
+###############################################################################
+# LLVMC: Provide rules for compiling llvmc plugins
+###############################################################################
+
+ifdef LLVMC_PLUGIN
+
+LIBRARYNAME := $(patsubst %,plugin_llvmc_%,$(LLVMC_PLUGIN))
+REQUIRES_EH := 1
+
+# 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
+endif
+
+endif # LLVMC_PLUGIN
+
###############################################################################
# VARIABLES: Set up various variables based on configuration data
###############################################################################
CPP.Defines :=
# OPTIMIZE_OPTION - The optimization level option we want to build LLVM with
# this can be overridden on the make command line.
-ifneq ($(OS),MingW)
- OPTIMIZE_OPTION := -O3
-else
+# Avoid -O3 on Darwin, there are unresolved issues with
+# -fstrict-aliasing and ipa-type-escape radr://6756684
+ifeq ($(OS), $(filter $(OS), MingW Darwin))
OPTIMIZE_OPTION := -O2
+else
+ OPTIMIZE_OPTION := -O3
endif
ifdef ENABLE_PROFILING
# CXX.Flags += -fno-rtti
endif
+ifdef ENABLE_COVERAGE
+ BuildMode := $(BuildMode)+Coverage
+ # These only go to .NoRelink because otherwise we will end up
+ # linking -lgcov into the .o libraries that get built.
+ CXX.Flags.NoRelink += -ftest-coverage -fprofile-arcs
+ C.Flags.NoRelink += -ftest-coverage -fprofile-arcs
+endif
+
# 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
CPP.Defines += -DNDEBUG
else
endif
ifeq ($(ENABLE_PIC),1)
- ifeq ($(LLVM_ON_WIN32),1)
+ ifeq ($(OS), $(filter $(OS), Cygwin MingW))
# Nothing. Win32 defaults to PIC and warns when given -fPIC
else
ifeq ($(OS),Darwin)
# Adjust to user's request
#--------------------------------------------------------------------
+ifeq ($(OS),Darwin)
+ 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 -mmacosx-version-min=$(DARWIN_VERSION)
+ TargetCommonOpts += -mmacosx-version-min=$(DARWIN_VERSION)
+else
+ ifeq ($(OS),Cygwin)
+ SharedLinkOptions=-shared -nostdlib -Wl,--export-all-symbols \
+ -Wl,--enable-auto-import -Wl,--enable-auto-image-base \
+ -Wl,--enable-runtime-pseudo-relocs
+ else
+ SharedLinkOptions=-shared
+ endif
+endif
+
# 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.
endif
ifdef SHARED_LIBRARY
- LD.Flags += -Wl,-rpath -Wl,$(LibDir)
+ifneq ($(DARWIN_MAJVERS),4)
+ LD.Flags += $(RPATH) -Wl,$(LibDir)
+endif
endif
ifdef TOOL_VERBOSE
# Adjust linker flags for building an executable
ifneq ($(OS),Darwin)
+ifneq ($(DARWIN_MAJVERS),4)
ifdef TOOLNAME
ifdef EXAMPLE_TOOL
- LD.Flags += -Wl,-rpath -Wl,$(ExmplDir) -export-dynamic
+ LD.Flags += $(RPATH) -Wl,$(ExmplDir) $(RDYNAMIC)
else
- LD.Flags += -Wl,-rpath -Wl,$(ToolDir) -export-dynamic
+ LD.Flags += $(RPATH) -Wl,$(ToolDir) $(RDYNAMIC)
endif
endif
endif
-
-ifeq ($(OS),Darwin)
- SharedLinkOptions=-Wl,-flat_namespace -Wl,-undefined -Wl,suppress -bundle
-else
- SharedLinkOptions=-shared
endif
#----------------------------------------------------------
# Options To Invoke Tools
#----------------------------------------------------------
-CompileCommonOpts := -pedantic -Wall -W -Wwrite-strings -Wno-long-long \
+CompileCommonOpts += -pedantic -Wall -W -Wwrite-strings -Wno-long-long \
-Wunused -Wno-unused-parameter $(EXTRA_OPTIONS)
ifeq ($(OS),HP-UX)
endif
UNIVERSAL_ARCH_OPTIONS := $(UNIVERSAL_ARCH:%=-arch %)
CompileCommonOpts += $(UNIVERSAL_ARCH_OPTIONS)
- Relink.Flags := $(UNIVERSAL_ARCH_OPTIONS:%=-XCClinker %)
+ Relink.Flags := $(UNIVERSAL_ARCH_OPTIONS)
ifdef UNIVERSAL_SDK_PATH
CompileCommonOpts += -isysroot $(UNIVERSAL_SDK_PATH)
- Relink.Flags += -XCClinker -isysroot -XCClinker $(UNIVERSAL_SDK_PATH)
+ Relink.Flags += -isysroot $(UNIVERSAL_SDK_PATH)
endif
# Building universal cannot compute dependencies automatically.
DISABLE_AUTO_DEPENDENCIES=1
+else
+ ifeq ($(OS),Darwin)
+ ifeq ($(ARCH),x86_64)
+ TargetCommonOpts = -m64
+ else
+ ifeq ($(ARCH),x86)
+ TargetCommonOpts = -m32
+ endif
+ endif
+ endif
endif
ifeq ($(OS),SunOS)
$(LLVM_OBJ_ROOT) $(LLVM_SRC_ROOT))) \
$(CPP.BaseFlags)
- ifeq ($(BUILD_COMPONENT), 1)
- Compile.C = $(BUILD_CC) $(CPP.Flags) $(C.Flags) $(CompileCommonOpts) -c
- Compile.CXX = $(BUILD_CXX) $(CPP.Flags) $(CXX.Flags) $(CompileCommonOpts) -c
- Preprocess.CXX= $(BUILD_CXX) $(CPP.Flags) $(CompileCommonOpts) $(CXX.Flags) -E
- Link = $(BUILD_CXX) $(CPP.Flags) $(CXX.Flags) $(CompileCommonOpts) \
- $(LD.Flags) $(Strip)
- Relink = $(BUILD_CXX) $(CPP.Flags) $(CXX.Flags) $(CompileCommonOpts) \
- $(Relink.Flags)
+ifeq ($(BUILD_COMPONENT), 1)
+ Compile.C = $(BUILD_CC) $(CPP.Flags) $(C.Flags) $(C.Flags.NoRelink) \
+ $(TargetCommonOpts) $(CompileCommonOpts) -c
+ Compile.CXX = $(BUILD_CXX) $(CPP.Flags) $(CXX.Flags) $(CXX.Flags.NoRelink) \
+ $(TargetCommonOpts) $(CompileCommonOpts) -c
+ Preprocess.CXX= $(BUILD_CXX) $(CPP.Flags) $(TargetCommonOpts) \
+ $(CompileCommonOpts) $(CXX.Flags) $(CXX.Flags.NoRelink) -E
+ Link = $(BUILD_CXX) $(CPP.Flags) $(CXX.Flags) $(CXX.Flags.NoRelink) \
+ $(TargetCommonOpts) $(CompileCommonOpts) $(LD.Flags) $(Strip)
+ Relink = $(BUILD_CXX) $(CPP.Flags) $(CXX.Flags) $(TargetCommonOpts) \
+ $(CompileCommonOpts) $(Relink.Flags)
else
- Compile.C = $(CC) $(CPP.Flags) $(C.Flags) $(CompileCommonOpts) -c
- Compile.CXX = $(CXX) $(CPP.Flags) $(CXX.Flags) $(CompileCommonOpts) -c
- Preprocess.CXX= $(CXX) $(CPP.Flags) $(CompileCommonOpts) $(CXX.Flags) -E
- Link = $(CXX) $(CPP.Flags) $(CXX.Flags) $(CompileCommonOpts) \
- $(LD.Flags) $(Strip)
- Relink = $(CXX) $(CPP.Flags) $(CXX.Flags) $(CompileCommonOpts) \
- $(Relink.Flags)
-endif
-
-BCCompile.C = $(LLVMGCCWITHPATH) $(CPP.Flags) $(C.Flags) $(CompileCommonOpts)
-Preprocess.C = $(CC) $(CPP.Flags) $(C.Flags) $(CompileCommonOpts) -E
+ Compile.C = $(CC) $(CPP.Flags) $(C.Flags) $(C.Flags.NoRelink) \
+ $(TargetCommonOpts) $(CompileCommonOpts) -c
+ Compile.CXX = $(CXX) $(CPP.Flags) $(CXX.Flags) $(CXX.Flags.NoRelink) \
+ $(TargetCommonOpts) $(CompileCommonOpts) -c
+ Preprocess.CXX= $(CXX) $(CPP.Flags) $(TargetCommonOpts) \
+ $(CompileCommonOpts) $(CXX.Flags) $(CXX.Flags.NoRelink) -E
+ Link = $(CXX) $(CPP.Flags) $(CXX.Flags) $(CXX.Flags.NoRelink) \
+ $(TargetCommonOpts) $(CompileCommonOpts) $(LD.Flags) $(Strip)
+ Relink = $(CXX) $(CPP.Flags) $(CXX.Flags) $(TargetCommonOpts) \
+ $(CompileCommonOpts) $(Relink.Flags)
+endif
+
+BCCompile.C = $(LLVMGCCWITHPATH) $(CPP.Flags) $(C.Flags) \
+ $(TargetCommonOpts) $(CompileCommonOpts)
+Preprocess.C = $(CC) $(CPP.Flags) $(C.Flags) \
+ $(TargetCommonOpts) $(CompileCommonOpts) -E
BCCompile.CXX = $(LLVMGXXWITHPATH) $(CPP.Flags) $(CXX.Flags) \
- $(CompileCommonOpts)
+ $(TargetCommonOpts) $(CompileCommonOpts)
ProgInstall = $(INSTALL) $(Install.StripFlag) -m 0755
ScriptInstall = $(INSTALL) -m 0755
$(ToolDir)/$(strip $(TOOLNAME))$(EXEEXT): $(LLVM_CONFIG)
-ProjLibsOptions += $(shell $(LLVM_CONFIG) --libs $(LINK_COMPONENTS))
-ProjLibsPaths += $(LLVM_CONFIG) \
+LLVMLibsOptions += $(shell $(LLVM_CONFIG) --libs $(LINK_COMPONENTS))
+LLVMLibsPaths += $(LLVM_CONFIG) \
$(shell $(LLVM_CONFIG) --libfiles $(LINK_COMPONENTS))
endif
endif
$(LibName.O): $(ObjectsO) $(LibDir)/.dir
$(Echo) Linking $(BuildMode) Object Library $(notdir $@)
- $(Verb) $(Relink) -Wl,-r -nodefaultlibs -nostdlibs -nostartfiles -o $@ $(ObjectsO)
+ $(Verb) $(Relink) -Wl,-r -nodefaultlibs -nostdlib -nostartfiles -o $@ $(ObjectsO)
clean-local::
ifneq ($(strip $(LibName.O)),)
ToolBuildPath := $(ToolDir)/$(strip $(TOOLNAME))$(EXEEXT)
endif
+#---------------------------------------------------------
+# Prune Exports
+#---------------------------------------------------------
+
+# If the tool opts in with TOOL_NO_EXPORTS, optimize startup time of the app by
+# not exporting all of the weak symbols from the binary. This reduces dyld
+# startup time by 4x on darwin in some cases.
+ifdef TOOL_NO_EXPORTS
+ifeq ($(OS),Darwin)
+
+# Tiger tools don't support this.
+ifneq ($(DARWIN_MAJVERS),4)
+LD.Flags += -Wl,-exported_symbol -Wl,_main
+endif
+endif
+
+ifeq ($(OS), $(filter $(OS), Linux NetBSD FreeBSD))
+LD.Flags += -Wl,--version-script=$(LLVM_SRC_ROOT)/autoconf/ExportMap.map
+endif
+endif
+
+
#---------------------------------------------------------
# Provide targets for building the tools
#---------------------------------------------------------
###############################################################################
ifdef TARGET
+TABLEGEN_INC_FILES_COMMON = 1
+endif
+
+ifdef LLVMC_BUILD_AUTOGENERATED_INC
+TABLEGEN_INC_FILES_COMMON = 1
+endif
+
+ifdef CLANG_BUILD_DIAGNOSTICS_INC
+TABLEGEN_INC_FILES_COMMON = 1
+endif
+
+ifdef TABLEGEN_INC_FILES_COMMON
-TDFiles := $(strip $(wildcard $(PROJ_SRC_DIR)/*.td) \
- $(LLVM_SRC_ROOT)/include/llvm/Target/Target.td \
- $(LLVM_SRC_ROOT)/include/llvm/Target/TargetCallingConv.td \
- $(LLVM_SRC_ROOT)/include/llvm/Target/TargetSchedule.td \
- $(LLVM_SRC_ROOT)/include/llvm/Target/TargetSelectionDAG.td \
- $(LLVM_SRC_ROOT)/include/llvm/CodeGen/ValueTypes.td) \
- $(wildcard $(LLVM_SRC_ROOT)/include/llvm/Intrinsics*.td)
INCFiles := $(filter %.inc,$(BUILT_SOURCES))
INCTMPFiles := $(INCFiles:%=$(ObjDir)/%.tmp)
.PRECIOUS: $(INCTMPFiles) $(INCFiles)
-# All of these files depend on tblgen and the .td files.
-$(INCTMPFiles) : $(TBLGEN) $(TDFiles)
-
# INCFiles rule: All of the tblgen generated files are emitted to
# $(ObjDir)/%.inc.tmp, instead of emitting them directly to %.inc. This allows
# us to only "touch" the real file if the contents of it change. IOW, if
$(INCFiles) : %.inc : $(ObjDir)/%.inc.tmp
$(Verb) $(CMP) -s $@ $< || $(CP) $< $@
+endif # TABLEGEN_INC_FILES_COMMON
+
+ifdef TARGET
+
+TDFiles := $(strip $(wildcard $(PROJ_SRC_DIR)/*.td) \
+ $(LLVM_SRC_ROOT)/include/llvm/Target/Target.td \
+ $(LLVM_SRC_ROOT)/include/llvm/Target/TargetCallingConv.td \
+ $(LLVM_SRC_ROOT)/include/llvm/Target/TargetSchedule.td \
+ $(LLVM_SRC_ROOT)/include/llvm/Target/TargetSelectionDAG.td \
+ $(LLVM_SRC_ROOT)/include/llvm/CodeGen/ValueTypes.td) \
+ $(wildcard $(LLVM_SRC_ROOT)/include/llvm/Intrinsics*.td)
+
+# All of these files depend on tblgen and the .td files.
+$(INCTMPFiles) : $(TBLGEN) $(TDFiles)
+
$(TARGET:%=$(ObjDir)/%GenRegisterNames.inc.tmp): \
$(ObjDir)/%GenRegisterNames.inc.tmp : %.td $(ObjDir)/.dir
$(Echo) "Building $(<F) register names with tblgen"
clean-local::
-$(Verb) $(RM) -f $(INCFiles)
+endif # TARGET
+
+ifdef LLVMC_BUILD_AUTOGENERATED_INC
+
+LLVMCPluginSrc := $(strip $(wildcard $(PROJ_SRC_DIR)/*.td))
+
+TDFiles := $(LLVMCPluginSrc) \
+ $(strip $(wildcard $(LLVM_SRC_ROOT)/include/llvm/CompilerDriver/*.td))
+
+$(ObjDir)/AutoGenerated.inc.tmp: $(LLVMCPluginSrc) $(ObjDir)/.dir \
+ $(TBLGEN) $(TD_COMMON)
+ $(Echo) "Building LLVMC configuration library with tblgen"
+ $(Verb) $(TableGen) -gen-llvmc -o $(call SYSPATH, $@) $<
+
+endif # LLVMC_BUILD_AUTOGENERATED_INC
+
+ifdef CLANG_BUILD_DIAGNOSTICS_INC
+
+$(ObjDir)/Diagnostic%Kinds.inc.tmp : Diagnostic.td Diagnostic%Kinds.td $(TBLGEN)
+ $(Echo) "Building Clang $(patsubst Diagnostic%Kinds.inc.tmp,%,$(@F)) diagnostic tables with tblgen"
+ $(Verb) $(MKDIR) $(@D)
+ $(Verb) $(TableGen) -gen-clang-diags-defs -clang-component=$(patsubst Diagnostic%Kinds.inc.tmp,%,$(@F)) -o $(call SYSPATH, $@) $<
+
endif
###############################################################################
###
# Debugging
-# General debugging rule, use 'make print-XXX' to print the
+# General debugging rule, use 'make dbg-print-XXX' to print the
# definition, value and origin of XXX.
-print-%:
+make-print-%:
$(error PRINT: $(value $*) = "$($*)" (from $(origin $*)))