--- a/make/common/NativeCompilation.gmk Fri Apr 17 10:43:28 2015 +0200
+++ b/make/common/NativeCompilation.gmk Fri Apr 17 13:54:50 2015 +0200
@@ -34,6 +34,73 @@
$(error You must include MakeBase.gmk prior to including NativeCompilation.gmk)
endif
+################################################################################
+# Define a native toolchain configuration that can be used by
+# SetupNativeCompilation calls
+#
+# Parameter 1 is the name of the toolchain definition
+#
+# Remaining parameters are named arguments:
+# EXTENDS - Optional parent definition to get defaults from
+# CC - The C compiler
+# CXX - The C++ compiler
+# LD - The Linker
+# AR - Static linker
+# AS - Assembler
+# MT - Windows MT tool
+# RC - Windows RC tool
+# SYSROOT_CFLAGS - Compiler flags for using the specific sysroot
+# SYSROOT_LDFLAGS - Linker flags for using the specific sysroot
+DefineNativeToolchain = $(NamedParamsMacroTemplate)
+define DefineNativeToolchainBody
+ # If extending another definition, get default values from that,
+ # otherwise, nothing more needs to be done as variable assignments
+ # already happened in NamedParamsMacroTemplate.
+ ifneq ($$($1_EXTENDS), )
+ $$(call SetIfEmpty, $1_CC, $$($$($1_EXTENDS)_CC))
+ $$(call SetIfEmpty, $1_CXX, $$($$($1_EXTENDS)_CXX))
+ $$(call SetIfEmpty, $1_LD, $$($$($1_EXTENDS)_LD))
+ $$(call SetIfEmpty, $1_AR, $$($$($1_EXTENDS)_AR))
+ $$(call SetIfEmpty, $1_AS, $$($$($1_EXTENDS)_AS))
+ $$(call SetIfEmpty, $1_MT, $$($$($1_EXTENDS)_MT))
+ $$(call SetIfEmpty, $1_RC, $$($$($1_EXTENDS)_RC))
+ $$(call SetIfEmpty, $1_SYSROOT_CFLAGS, $$($$($1_EXTENDS)_SYSROOT_CFLAGS))
+ $$(call SetIfEmpty, $1_SYSROOT_LDFLAGS, $$($$($1_EXTENDS)_SYSROOT_LDFLAGS))
+ endif
+endef
+
+# Create a default toolchain with the main compiler and linker
+$(eval $(call DefineNativeToolchain, TOOLCHAIN_DEFAULT, \
+ CC := $(CC), \
+ CXX := $(CXX), \
+ LD := $(LD), \
+ AR := $(AR), \
+ AS := $(AS), \
+ MT := $(MT), \
+ RC := $(RC), \
+ SYSROOT_CFLAGS := $(SYSROOT_CFLAGS), \
+ SYSROOT_LDFLAGS := $(SYSROOT_LDFLAGS), \
+))
+
+# Create a toolchain where linking is done with the C++ linker
+$(eval $(call DefineNativeToolchain, TOOLCHAIN_LINK_CXX, \
+ EXTENDS := TOOLCHAIN_DEFAULT, \
+ LD := $(LDCXX), \
+))
+
+# Create a toolchain with the BUILD compiler, used for build tools that
+# are to be run during the build.
+# The BUILD_SYSROOT_*FLAGS variables are empty for now.
+$(eval $(call DefineNativeToolchain, TOOLCHAIN_BUILD, \
+ EXTENDS := TOOLCHAIN_DEFAULT, \
+ CC := $(BUILD_CC), \
+ LD := $(BUILD_LD), \
+ SYSROOT_CFLAGS := $(BUILD_SYSROOT_CFLAGS), \
+ SYSROOT_LDFLAGS := $(BUILD_SYSROOT_LDFLAGS), \
+))
+
+################################################################################
+
# Extensions of files handled by this macro.
NATIVE_SOURCE_EXTENSIONS := %.s %.c %.cpp %.m %.mm
@@ -171,8 +238,8 @@
# and the targets generated are listed in a variable by that name.
#
# Remaining parameters are named arguments. These include:
+# TOOLCHAIN Name of toolchain setup to use. Defaults to TOOLCHAIN_DEFAULT.
# SRC one or more directory roots to scan for C/C++ files.
-# LANG C or C++
# CFLAGS the compiler flags to be used, used both for C and C++.
# CXXFLAGS the compiler flags to be used for c++, if set overrides CFLAGS.
# LDFLAGS the linker flags to be used, used both for C and C++.
@@ -193,7 +260,7 @@
# REORDER reorder file
# DEBUG_SYMBOLS add debug symbols (if configured on)
# CC the compiler to use, default is $(CC)
-# LDEXE the linker to use for linking executables, default is $(LDEXE)
+# LD the linker to use, default is $(LD)
# OPTIMIZATION sets optimization level to NONE, LOW, HIGH, HIGHEST
# DISABLED_WARNINGS_<toolchain> Disable the given warnings for the specified toolchain
SetupNativeCompilation = $(NamedParamsMacroTemplate)
@@ -289,35 +356,17 @@
$$(error Neither PROGRAM, LIBRARY nor STATIC_LIBRARY has been specified for SetupNativeCompilation)
endif
- ifeq (,$$($1_LANG))
- $$(error You have to specify LANG for native compilation $1)
- endif
- ifeq (C,$$($1_LANG))
- ifeq ($$($1_LDEXE),)
- $1_LDEXE:=$(LDEXE)
- endif
- ifeq ($$($1_LD),)
- $1_LD:=$(LD)
- endif
- else
- ifeq (C++,$$($1_LANG))
- ifeq ($$($1_LD),)
- $1_LD:=$(LDCXX)
- endif
- ifeq ($$($1_LDEXE),)
- $1_LDEXE:=$(LDEXECXX)
- endif
- else
- $$(error Unknown native language $$($1_LANG) for $1)
- endif
- endif
-
- ifeq ($$($1_CC),)
- $1_CC:=$(CC)
- endif
- ifeq ($$($1_CXX),)
- $1_CXX:=$(CXX)
- endif
+ # Setup the toolchain to be used
+ $$(call SetIfEmpty, $1_TOOLCHAIN, TOOLCHAIN_DEFAULT)
+ $$(call SetIfEmpty, $1_CC, $$($$($1_TOOLCHAIN)_CC))
+ $$(call SetIfEmpty, $1_CXX, $$($$($1_TOOLCHAIN)_CXX))
+ $$(call SetIfEmpty, $1_LD, $$($$($1_TOOLCHAIN)_LD))
+ $$(call SetIfEmpty, $1_AR, $$($$($1_TOOLCHAIN)_AR))
+ $$(call SetIfEmpty, $1_AS, $$($$($1_TOOLCHAIN)_AS))
+ $$(call SetIfEmpty, $1_MT, $$($$($1_TOOLCHAIN)_MT))
+ $$(call SetIfEmpty, $1_RC, $$($$($1_TOOLCHAIN)_RC))
+ $$(call SetIfEmpty, $1_SYSROOT_CFLAGS, $$($$($1_TOOLCHAIN)_SYSROOT_CFLAGS))
+ $$(call SetIfEmpty, $1_SYSROOT_LDFLAGS, $$($$($1_TOOLCHAIN)_SYSROOT_LDFLAGS))
ifneq ($$($1_MANIFEST), )
ifeq ($$($1_MANIFEST_VERSION), )
@@ -327,7 +376,8 @@
# Make sure the dirs exist.
$$(call MakeDir,$$($1_OBJECT_DIR) $$($1_OUTPUT_DIR))
- $$(foreach d,$$($1_SRC), $$(if $$(wildcard $$d),,$$(error SRC specified to SetupNativeCompilation $1 contains missing directory $$d)))
+ $$(foreach d,$$($1_SRC), $$(if $$(wildcard $$d),, \
+ $$(error SRC specified to SetupNativeCompilation $1 contains missing directory $$d)))
# Find all files in the source trees. Sort to remove duplicates.
$1_ALL_SRCS := $$(sort $$(call CacheFind,$$($1_SRC)))
@@ -458,9 +508,9 @@
# Track variable changes for all variables that affect the compilation command
# lines for all object files in this setup. This includes at least all the
# variables used in the call to add_native_source below.
- $1_COMPILE_VARDEPS := $$($1_CFLAGS) $$($1_EXTRA_CFLAGS) $(SYSROOT_CFLAGS) \
+ $1_COMPILE_VARDEPS := $$($1_CFLAGS) $$($1_EXTRA_CFLAGS) $$($1_SYSROOT_CFLAGS) \
$$($1_CXXFLAGS) $$($1_EXTRA_CXXFLAGS) \
- $$($1_CC) $$($1_CXX) $$($1_ASFLAGS) \
+ $$($1_CC) $$($1_CXX) $$($1_AS) $$($1_ASFLAGS) \
$$(foreach s, $$($1_SRCS), \
$$($1_$$(notdir $$s)_CFLAGS) $$($1_$$(notdir $$s)_CXXFLAGS))
$1_COMPILE_VARDEPS_FILE := $$(call DependOnVariable, $1_COMPILE_VARDEPS, \
@@ -469,9 +519,9 @@
# Now call add_native_source for each source file we are going to compile.
$$(foreach p,$$($1_SRCS), \
$$(eval $$(call add_native_source,$1,$$p,$$($1_OBJECT_DIR), \
- $$($1_CFLAGS) $$($1_EXTRA_CFLAGS) $(SYSROOT_CFLAGS), \
+ $$($1_CFLAGS) $$($1_EXTRA_CFLAGS) $$($1_SYSROOT_CFLAGS), \
$$($1_CC), \
- $$($1_CXXFLAGS) $$($1_EXTRA_CXXFLAGS) $(SYSROOT_CFLAGS), \
+ $$($1_CXXFLAGS) $$($1_EXTRA_CXXFLAGS) $$($1_SYSROOT_CFLAGS), \
$$($1_CXX), $$($1_ASFLAGS))))
# Setup rule for printing progress info when compiling source files.
@@ -496,16 +546,16 @@
-include $$($1_RES_DEP)
-include $$($1_RES_DEP_TARGETS)
- $1_RES_VARDEPS := $(RC) $$($1_RC_FLAGS)
+ $1_RES_VARDEPS := $$($1_RC) $$($1_RC_FLAGS)
$1_RES_VARDEPS_FILE := $$(call DependOnVariable, $1_RES_VARDEPS, \
$$($1_RES).vardeps)
$$($1_RES): $$($1_VERSIONINFO_RESOURCE) $$($1_RES_VARDEPS_FILE)
$(ECHO) $(LOG_INFO) "Compiling resource $$(notdir $$($1_VERSIONINFO_RESOURCE)) (for $$(notdir $$($1_TARGET)))"
- $(RC) $$($1_RC_FLAGS) $(SYSROOT_CFLAGS) $(CC_OUT_OPTION)$$@ \
+ $$($1_RC) $$($1_RC_FLAGS) $$($1_SYSROOT_CFLAGS) $(CC_OUT_OPTION)$$@ \
$$($1_VERSIONINFO_RESOURCE)
# Windows RC compiler does not support -showIncludes, so we mis-use CL for this.
- $(CC) $$($1_RC_FLAGS) $(SYSROOT_CFLAGS) -showIncludes -nologo -TC \
+ $$($1_CC) $$($1_RC_FLAGS) $$($1_SYSROOT_CFLAGS) -showIncludes -nologo -TC \
$(CC_OUT_OPTION)$$($1_RES_DEP).obj $$($1_VERSIONINFO_RESOURCE) > $$($1_RES_DEP).raw 2>&1 || exit 0
($(ECHO) $$($1_RES): \\ \
&& $(SED) $(WINDOWS_SHOWINCLUDE_SED_PATTERN) $$($1_RES_DEP).raw) > $$($1_RES_DEP)
@@ -621,15 +671,15 @@
$1_EXTRA_LDFLAGS_SUFFIX += $(GLOBAL_LDFLAGS_SUFFIX)
- $1_VARDEPS := $$($1_LD) $(SYSROOT_LDFLAGS) $$($1_LDFLAGS) $$($1_EXTRA_LDFLAGS) \
- $$($1_LDFLAGS_SUFFIX) $$($1_EXTRA_LDFLAGS_SUFFIX)
+ $1_VARDEPS := $$($1_LD) $$($1_SYSROOT_LDFLAGS) $$($1_LDFLAGS) $$($1_EXTRA_LDFLAGS) \
+ $$($1_LDFLAGS_SUFFIX) $$($1_EXTRA_LDFLAGS_SUFFIX) $$($1_CREATE_DEBUGINFO_CMDS)
$1_VARDEPS_FILE := $$(call DependOnVariable, $1_VARDEPS, \
$$($1_OBJECT_DIR)/$$($1_NOSUFFIX).vardeps)
$$($1_TARGET): $$($1_EXPECTED_OBJS) $$($1_RES) $$($1_REAL_MAPFILE) \
$$($1_DEBUGINFO_EXTRA_DEPS) $$($1_VARDEPS_FILE)
$(ECHO) $(LOG_INFO) "Linking $$($1_BASENAME)"
- $$($1_LD) $$($1_LDFLAGS) $$($1_EXTRA_LDFLAGS) $(SYSROOT_LDFLAGS) \
+ $$($1_LD) $$($1_LDFLAGS) $$($1_EXTRA_LDFLAGS) $$($1_SYSROOT_LDFLAGS) \
$(LD_OUT_OPTION)$$@ \
$$($1_EXPECTED_OBJS) $$($1_RES) \
$$($1_LDFLAGS_SUFFIX) $$($1_EXTRA_LDFLAGS_SUFFIX)
@@ -643,14 +693,15 @@
endif
ifneq (,$$($1_STATIC_LIBRARY))
- $1_VARDEPS := $(AR) $$($1_ARFLAGS) $$($1_LDFLAGS_SUFFIX) $$($1_EXTRA_LDFLAGS_SUFFIX)
+ $1_VARDEPS := $$($1_AR) $$($1_ARFLAGS) $$($1_LDFLAGS_SUFFIX) \
+ $$($1_EXTRA_LDFLAGS_SUFFIX)
$1_VARDEPS_FILE := $$(call DependOnVariable, $1_VARDEPS, \
$$($1_OBJECT_DIR)/$$($1_NOSUFFIX).vardeps)
# Generating a static library, ie object file archive.
$$($1_TARGET): $$($1_EXPECTED_OBJS) $$($1_RES) $$($1_VARDEPS_FILE)
$(ECHO) $(LOG_INFO) "Archiving $$($1_STATIC_LIBRARY)"
- $(AR) $$($1_ARFLAGS) $(AR_OUT_OPTION)$$($1_TARGET) $$($1_EXPECTED_OBJS) \
+ $$($1_AR) $$($1_ARFLAGS) $(AR_OUT_OPTION)$$($1_TARGET) $$($1_EXPECTED_OBJS) \
$$($1_RES) $$($1_LDFLAGS_SUFFIX) $$($1_EXTRA_LDFLAGS_SUFFIX)
endif
@@ -658,21 +709,22 @@
# A executable binary has been specified, setup the target for it.
$1_EXTRA_LDFLAGS_SUFFIX += $(GLOBAL_LDFLAGS_SUFFIX)
- $1_VARDEPS := $$($1_LDEXE) $(SYSROOT_LDFLAGS) $$($1_LDFLAGS) $$($1_EXTRA_LDFLAGS) \
- $$($1_LDFLAGS_SUFFIX) $$($1_EXTRA_LDFLAGS_SUFFIX) $$($1_MANIFEST_VERSION)
+ $1_VARDEPS := $$($1_LD) $$($1_SYSROOT_LDFLAGS) $$($1_LDFLAGS) $$($1_EXTRA_LDFLAGS) \
+ $$($1_LDFLAGS_SUFFIX) $$($1_EXTRA_LDFLAGS_SUFFIX) $$($1_MT) \
+ $$($1_CODESIGN) $$($1_CREATE_DEBUGINFO_CMDS) $$($1_MANIFEST_VERSION)
$1_VARDEPS_FILE := $$(call DependOnVariable, $1_VARDEPS, \
$$($1_OBJECT_DIR)/$$($1_NOSUFFIX).vardeps)
$$($1_TARGET): $$($1_EXPECTED_OBJS) $$($1_RES) $$($1_MANIFEST) \
$$($1_DEBUGINFO_EXTRA_DEPS) $$($1_VARDEPS_FILE)
$(ECHO) $(LOG_INFO) "Linking executable $$($1_BASENAME)"
- $$($1_LDEXE) $$($1_LDFLAGS) $$($1_EXTRA_LDFLAGS) $(SYSROOT_LDFLAGS) \
+ $$($1_LD) $$($1_LDFLAGS) $$($1_EXTRA_LDFLAGS) $$($1_SYSROOT_LDFLAGS) \
$(EXE_OUT_OPTION)$$($1_TARGET) \
$$($1_EXPECTED_OBJS) $$($1_RES) \
$$($1_LDFLAGS_SUFFIX) $$($1_EXTRA_LDFLAGS_SUFFIX)
ifeq ($(OPENJDK_TARGET_OS), windows)
ifneq ($$($1_MANIFEST), )
- $(MT) -nologo -manifest $$($1_MANIFEST) -identity:"$$($1_PROGRAM).exe, version=$$($1_MANIFEST_VERSION)" -outputresource:$$@;#1
+ $$($1_MT) -nologo -manifest $$($1_MANIFEST) -identity:"$$($1_PROGRAM).exe, version=$$($1_MANIFEST_VERSION)" -outputresource:$$@;#1
endif
endif
# This only works if the openjdk_codesign identity is present on the system. Let