8077824: Introduce DefineNativeToolchain to handle toolchain configurations
authorerikj
Fri, 17 Apr 2015 13:54:50 +0200
changeset 29866 6cecef2d84ab
parent 29865 60e4eefce6e4
child 29867 a074643872c1
8077824: Introduce DefineNativeToolchain to handle toolchain configurations Reviewed-by: ihse, tbell
common/autoconf/generated-configure.sh
common/autoconf/spec.gmk.in
common/autoconf/toolchain.m4
make/common/MakeBase.gmk
make/common/NativeCompilation.gmk
--- a/common/autoconf/generated-configure.sh	Fri Apr 17 10:43:28 2015 +0200
+++ b/common/autoconf/generated-configure.sh	Fri Apr 17 13:54:50 2015 +0200
@@ -745,8 +745,6 @@
 JTREGEXE
 USING_BROKEN_SUSE_LD
 PACKAGE_PATH
-LDEXECXX
-LDEXE
 USE_CLANG
 HOTSPOT_LD
 HOTSPOT_CXX
@@ -4365,7 +4363,7 @@
 #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 @@
   fi
 
 
-  # LDEXE is the linker to use, when creating executables. Not really used.
-  # FIXME: These should just be removed!
-  LDEXE="$LD"
-  LDEXECXX="$LDCXX"
-
-
-
 
 
 
--- a/common/autoconf/spec.gmk.in	Fri Apr 17 10:43:28 2015 +0200
+++ b/common/autoconf/spec.gmk.in	Fri Apr 17 13:54:50 2015 +0200
@@ -355,10 +355,6 @@
 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 @@
 # 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@
--- a/common/autoconf/toolchain.m4	Fri Apr 17 10:43:28 2015 +0200
+++ b/common/autoconf/toolchain.m4	Fri Apr 17 13:54:50 2015 +0200
@@ -662,13 +662,6 @@
     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.
--- a/make/common/MakeBase.gmk	Fri Apr 17 10:43:28 2015 +0200
+++ b/make/common/MakeBase.gmk	Fri Apr 17 13:54:50 2015 +0200
@@ -488,6 +488,13 @@
       $(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)
   # On Solaris, if the target is a symlink and exists, cp won't overwrite.
--- 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