8077824: Introduce DefineNativeToolchain to handle toolchain configurations

Reviewed-by: ihse, tbell
This commit is contained in:
Erik Joelsson 2015-04-17 13:54:50 +02:00
parent 6e76eef82a
commit 4ad9ac199d
5 changed files with 108 additions and 72 deletions

@ -745,8 +745,6 @@ JT_HOME
JTREGEXE
USING_BROKEN_SUSE_LD
PACKAGE_PATH
LDEXECXX
LDEXE
USE_CLANG
HOTSPOT_LD
HOTSPOT_CXX
@ -4365,7 +4363,7 @@ VS_SDK_PLATFORM_NAME_2013=
#CUSTOM_AUTOCONF_INCLUDE
# Do not change or remove the following line, it is needed for consistency checks:
DATE_WHEN_GENERATED=1429260097
DATE_WHEN_GENERATED=1429271657
###############################################################################
#
@ -40888,13 +40886,6 @@ $as_echo "$as_me: Rewriting BUILD_LD to \"$new_complete\"" >&6;}
fi
# LDEXE is the linker to use, when creating executables. Not really used.
# FIXME: These should just be removed!
LDEXE="$LD"
LDEXECXX="$LDCXX"

@ -355,10 +355,6 @@ USING_BROKEN_SUSE_LD:=@USING_BROKEN_SUSE_LD@
LDFLAGS_JDKLIB:=@LDFLAGS_JDKLIB@
LDFLAGS_JDKLIB_SUFFIX:=@LDFLAGS_JDKLIB_SUFFIX@
# On some platforms the linker cannot be used to create executables, thus
# the need for a separate LDEXE command.
LDEXE:=@FIXPATH@ @LDEXE@
# LDFLAGS used to link the jdk native launchers (C-code)
LDFLAGS_JDKEXE:=@LDFLAGS_JDKEXE@
LDFLAGS_JDKEXE_SUFFIX:=@LDFLAGS_JDKEXE_SUFFIX@
@ -371,9 +367,6 @@ LDCXX:=@FIXPATH@ @LDCXX@
# The flags for linking libstdc++ linker.
LIBCXX:=@LIBCXX@
# Sometimes a different linker is needed for c++ executables
LDEXECXX:=@FIXPATH@ @LDEXECXX@
# Compiler and linker flags used when building native tests
CFLAGS_TESTLIB:=@CFLAGS_TESTLIB@
CXXFLAGS_TESTLIB:=@CXXFLAGS_TESTLIB@

@ -662,13 +662,6 @@ AC_DEFUN_ONCE([TOOLCHAIN_SETUP_LEGACY],
USE_CLANG=true
fi
AC_SUBST(USE_CLANG)
# LDEXE is the linker to use, when creating executables. Not really used.
# FIXME: These should just be removed!
LDEXE="$LD"
LDEXECXX="$LDCXX"
AC_SUBST(LDEXE)
AC_SUBST(LDEXECXX)
])
# Do some additional checks on the detected tools.

@ -487,6 +487,13 @@ MakeDir = \
$(strip $(if $(subst $(wildcard $1 $2 $3 $4 $5 $6 $7 $8 $9),,$(strip $1 $2 $3 $4 $5 $6 $7 $8 $9)),\
$(shell $(MKDIR) -p $1 $2 $3 $4 $5 $6 $7 $8 $9)))
################################################################################
# Assign a variable only if it is empty
# Param 1 - Variable to assign
# Param 2 - Value to assign
SetIfEmpty = \
$(if $($(strip $1)),,$(eval $(strip $1) := $2))
################################################################################
ifeq ($(OPENJDK_TARGET_OS),solaris)

@ -34,6 +34,73 @@ ifeq (,$(_MAKEBASE_GMK))
$(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 @@ endef
# 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 @@ endef
# 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 @@ define SetupNativeCompilationBody
$$(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 @@ define SetupNativeCompilationBody
# 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 @@ define SetupNativeCompilationBody
# 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 @@ define SetupNativeCompilationBody
# 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 @@ define SetupNativeCompilationBody
-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 @@ define SetupNativeCompilationBody
$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 @@ define SetupNativeCompilationBody
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 @@ define SetupNativeCompilationBody
# 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