1 #
   2 # Copyright (c) 2011, 2021, Oracle and/or its affiliates. All rights reserved.
   3 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4 #
   5 # This code is free software; you can redistribute it and/or modify it
   6 # under the terms of the GNU General Public License version 2 only, as
   7 # published by the Free Software Foundation.  Oracle designates this
   8 # particular file as subject to the "Classpath" exception as provided
   9 # by Oracle in the LICENSE file that accompanied this code.
  10 #
  11 # This code is distributed in the hope that it will be useful, but WITHOUT
  12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13 # FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14 # version 2 for more details (a copy is included in the LICENSE file that
  15 # accompanied this code).
  16 #
  17 # You should have received a copy of the GNU General Public License version
  18 # 2 along with this work; if not, write to the Free Software Foundation,
  19 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20 #
  21 # Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22 # or visit www.oracle.com if you need additional information or have any
  23 # questions.
  24 #
  25 
  26 ########################################################################
  27 # This file is responsible for detecting, verifying and setting up the
  28 # toolchain, i.e. the compiler, linker and related utilities. It will setup
  29 # proper paths to the binaries, but it will not setup any flags.
  30 #
  31 # The binaries used is determined by the toolchain type, which is the family of
  32 # compilers and related tools that are used.
  33 ########################################################################
  34 
  35 m4_include([toolchain_microsoft.m4])
  36 
  37 # All valid toolchains, regardless of platform (used by help.m4)
  38 VALID_TOOLCHAINS_all="gcc clang xlc microsoft"
  39 
  40 # These toolchains are valid on different platforms
  41 VALID_TOOLCHAINS_linux="gcc clang"
  42 VALID_TOOLCHAINS_macosx="gcc clang"
  43 VALID_TOOLCHAINS_aix="xlc"
  44 VALID_TOOLCHAINS_windows="microsoft"
  45 
  46 # Toolchain descriptions
  47 TOOLCHAIN_DESCRIPTION_clang="clang/LLVM"
  48 TOOLCHAIN_DESCRIPTION_gcc="GNU Compiler Collection"
  49 TOOLCHAIN_DESCRIPTION_microsoft="Microsoft Visual Studio"
  50 TOOLCHAIN_DESCRIPTION_xlc="IBM XL C/C++"
  51 
  52 # Minimum supported versions, empty means unspecified
  53 TOOLCHAIN_MINIMUM_VERSION_clang="3.5"
  54 TOOLCHAIN_MINIMUM_VERSION_gcc="6.0"
  55 TOOLCHAIN_MINIMUM_VERSION_microsoft="19.10.0.0" # VS2017
  56 TOOLCHAIN_MINIMUM_VERSION_xlc=""
  57 
  58 # Minimum supported linker versions, empty means unspecified
  59 TOOLCHAIN_MINIMUM_LD_VERSION_gcc="2.18"
  60 
  61 # Prepare the system so that TOOLCHAIN_CHECK_COMPILER_VERSION can be called.
  62 # Must have CC_VERSION_NUMBER and CXX_VERSION_NUMBER.
  63 # $1 - optional variable prefix for compiler and version variables (BUILD_)
  64 # $2 - optional variable prefix for comparable variable (OPENJDK_BUILD_)
  65 # $3 - optional human readable description for the type of compilers ("build " or "")
  66 AC_DEFUN([TOOLCHAIN_PREPARE_FOR_VERSION_COMPARISONS],
  67 [
  68   if test "x[$]$1CC_VERSION_NUMBER" != "x[$]$1CXX_VERSION_NUMBER"; then
  69     AC_MSG_WARN([The $3C and C++ compilers have different version numbers, [$]$1CC_VERSION_NUMBER vs [$]$1CXX_VERSION_NUMBER.])
  70     AC_MSG_WARN([This typically indicates a broken setup, and is not supported])
  71   fi
  72 
  73   # We only check CC_VERSION_NUMBER since we assume CXX_VERSION_NUMBER is equal.
  74   if [ [[ "[$]$1CC_VERSION_NUMBER" =~ (.*\.){4} ]] ]; then
  75     AC_MSG_WARN([C compiler version number has more than four parts (W.X.Y.Z): [$]$1CC_VERSION_NUMBER. Comparisons might be wrong.])
  76   fi
  77 
  78   if [ [[  "[$]$1CC_VERSION_NUMBER" =~ [0-9]{6} ]] ]; then
  79     AC_MSG_WARN([C compiler version number has a part larger than 99999: [$]$1CC_VERSION_NUMBER. Comparisons might be wrong.])
  80   fi
  81 
  82   $2COMPARABLE_ACTUAL_VERSION=`$AWK -F. '{ printf("%05d%05d%05d%05d\n", [$]1, [$]2, [$]3, [$]4) }' <<< "[$]$1CC_VERSION_NUMBER"`
  83 ])
  84 
  85 # Check if the configured compiler (C and C++) is of a specific version or
  86 # newer. TOOLCHAIN_PREPARE_FOR_VERSION_COMPARISONS must have been called before.
  87 #
  88 # Arguments:
  89 #   VERSION:   The version string to check against the found version
  90 #   IF_AT_LEAST:   block to run if the compiler is at least this version (>=)
  91 #   IF_OLDER_THAN:   block to run if the compiler is older than this version (<)
  92 #   PREFIX:   Optional variable prefix for compiler to compare version for (OPENJDK_BUILD_)
  93 UTIL_DEFUN_NAMED([TOOLCHAIN_CHECK_COMPILER_VERSION],
  94     [*VERSION PREFIX IF_AT_LEAST IF_OLDER_THAN], [$@],
  95 [
  96   # Need to assign to a variable since m4 is blocked from modifying parts in [].
  97   REFERENCE_VERSION=ARG_VERSION
  98 
  99   if [ [[ "$REFERENCE_VERSION" =~ (.*\.){4} ]] ]; then
 100     AC_MSG_ERROR([Internal error: Cannot compare to ARG_VERSION, only four parts (W.X.Y.Z) is supported])
 101   fi
 102 
 103   if [ [[ "$REFERENCE_VERSION" =~ [0-9]{6} ]] ]; then
 104     AC_MSG_ERROR([Internal error: Cannot compare to ARG_VERSION, only parts < 99999 is supported])
 105   fi
 106 
 107   # Version comparison method inspired by http://stackoverflow.com/a/24067243
 108   COMPARABLE_REFERENCE_VERSION=`$AWK -F. '{ printf("%05d%05d%05d%05d\n", [$]1, [$]2, [$]3, [$]4) }' <<< "$REFERENCE_VERSION"`
 109 
 110   if test [$]ARG_PREFIX[COMPARABLE_ACTUAL_VERSION] -ge $COMPARABLE_REFERENCE_VERSION ; then
 111     :
 112     ARG_IF_AT_LEAST
 113   else
 114     :
 115     ARG_IF_OLDER_THAN
 116   fi
 117 ])
 118 
 119 # Prepare the system so that TOOLCHAIN_CHECK_COMPILER_VERSION can be called.
 120 # Must have LD_VERSION_NUMBER.
 121 # $1 - optional variable prefix for compiler and version variables (BUILD_)
 122 # $2 - optional variable prefix for comparable variable (OPENJDK_BUILD_)
 123 AC_DEFUN([TOOLCHAIN_PREPARE_FOR_LD_VERSION_COMPARISONS],
 124 [
 125   if [ [[ "[$]$1LD_VERSION_NUMBER" =~ (.*\.){4} ]] ]; then
 126     AC_MSG_WARN([Linker version number has more than four parts (W.X.Y.Z): [$]$1LD_VERSION_NUMBER. Comparisons might be wrong.])
 127   fi
 128 
 129   if [ [[  "[$]$1LD_VERSION_NUMBER" =~ [0-9]{6} ]] ]; then
 130     AC_MSG_WARN([Linker version number has a part larger than 99999: [$]$1LD_VERSION_NUMBER. Comparisons might be wrong.])
 131   fi
 132 
 133   $2COMPARABLE_ACTUAL_LD_VERSION=`$AWK -F. '{ printf("%05d%05d%05d%05d\n", [$]1, [$]2, [$]3, [$]4) }' <<< "[$]$1LD_VERSION_NUMBER"`
 134 ])
 135 
 136 # Check if the configured linker is of a specific version or
 137 # newer. TOOLCHAIN_PREPARE_FOR_LD_VERSION_COMPARISONS must have been called before.
 138 #
 139 # Arguments:
 140 #   VERSION:   The version string to check against the found version
 141 #   IF_AT_LEAST:   block to run if the compiler is at least this version (>=)
 142 #   IF_OLDER_THAN:   block to run if the compiler is older than this version (<)
 143 #   PREFIX:   Optional variable prefix for compiler to compare version for (OPENJDK_BUILD_)
 144 UTIL_DEFUN_NAMED([TOOLCHAIN_CHECK_LINKER_VERSION],
 145     [*VERSION PREFIX IF_AT_LEAST IF_OLDER_THAN], [$@],
 146 [
 147   # Need to assign to a variable since m4 is blocked from modifying parts in [].
 148   REFERENCE_VERSION=ARG_VERSION
 149 
 150   if [ [[ "$REFERENCE_VERSION" =~ (.*\.){4} ]] ]; then
 151     AC_MSG_ERROR([Internal error: Cannot compare to ARG_VERSION, only four parts (W.X.Y.Z) is supported])
 152   fi
 153 
 154   if [ [[ "$REFERENCE_VERSION" =~ [0-9]{6} ]] ]; then
 155     AC_MSG_ERROR([Internal error: Cannot compare to ARG_VERSION, only parts < 99999 is supported])
 156   fi
 157 
 158   # Version comparison method inspired by http://stackoverflow.com/a/24067243
 159   COMPARABLE_REFERENCE_VERSION=`$AWK -F. '{ printf("%05d%05d%05d%05d\n", [$]1, [$]2, [$]3, [$]4) }' <<< "$REFERENCE_VERSION"`
 160 
 161   if test [$]ARG_PREFIX[COMPARABLE_ACTUAL_LD_VERSION] -ge $COMPARABLE_REFERENCE_VERSION ; then
 162     :
 163     ARG_IF_AT_LEAST
 164   else
 165     :
 166     ARG_IF_OLDER_THAN
 167   fi
 168 ])
 169 
 170 # Setup a number of variables describing how native output files are
 171 # named on this platform/toolchain.
 172 AC_DEFUN([TOOLCHAIN_SETUP_FILENAME_PATTERNS],
 173 [
 174   # Define filename patterns
 175   if test "x$OPENJDK_TARGET_OS" = xwindows; then
 176     LIBRARY_PREFIX=
 177     SHARED_LIBRARY_SUFFIX='.dll'
 178     STATIC_LIBRARY_SUFFIX='.lib'
 179     SHARED_LIBRARY='[$]1.dll'
 180     STATIC_LIBRARY='[$]1.lib'
 181     OBJ_SUFFIX='.obj'
 182     EXECUTABLE_SUFFIX='.exe'
 183   else
 184     LIBRARY_PREFIX=lib
 185     SHARED_LIBRARY_SUFFIX='.so'
 186     STATIC_LIBRARY_SUFFIX='.a'
 187     SHARED_LIBRARY='lib[$]1.so'
 188     STATIC_LIBRARY='lib[$]1.a'
 189     OBJ_SUFFIX='.o'
 190     EXECUTABLE_SUFFIX=''
 191     if test "x$OPENJDK_TARGET_OS" = xmacosx; then
 192       # For full static builds, we're overloading the SHARED_LIBRARY
 193       # variables in order to limit the amount of changes required.
 194       # It would be better to remove SHARED and just use LIBRARY and
 195       # LIBRARY_SUFFIX for libraries that can be built either
 196       # shared or static and use STATIC_* for libraries that are
 197       # always built statically.
 198       if test "x$STATIC_BUILD" = xtrue; then
 199         SHARED_LIBRARY='lib[$]1.a'
 200         SHARED_LIBRARY_SUFFIX='.a'
 201       else
 202         SHARED_LIBRARY='lib[$]1.dylib'
 203         SHARED_LIBRARY_SUFFIX='.dylib'
 204       fi
 205     fi
 206   fi
 207 
 208   AC_SUBST(LIBRARY_PREFIX)
 209   AC_SUBST(SHARED_LIBRARY_SUFFIX)
 210   AC_SUBST(STATIC_LIBRARY_SUFFIX)
 211   AC_SUBST(SHARED_LIBRARY)
 212   AC_SUBST(STATIC_LIBRARY)
 213   AC_SUBST(OBJ_SUFFIX)
 214   AC_SUBST(EXECUTABLE_SUFFIX)
 215 ])
 216 
 217 # Determine which toolchain type to use, and make sure it is valid for this
 218 # platform. Setup various information about the selected toolchain.
 219 AC_DEFUN_ONCE([TOOLCHAIN_DETERMINE_TOOLCHAIN_TYPE],
 220 [
 221   AC_ARG_WITH(toolchain-type, [AS_HELP_STRING([--with-toolchain-type],
 222       [the toolchain type (or family) to use, use '--help' to show possible values @<:@platform dependent@:>@])])
 223 
 224   # Linux x86_64 needs higher binutils after 8265783
 225   # (this really is a dependency on as version, but we take ld as a check for a general binutils version)
 226   if test "x$OPENJDK_TARGET_CPU" = "xx86_64"; then
 227     TOOLCHAIN_MINIMUM_LD_VERSION_gcc="2.25"
 228   fi
 229 
 230   # Use indirect variable referencing
 231   toolchain_var_name=VALID_TOOLCHAINS_$OPENJDK_BUILD_OS
 232   VALID_TOOLCHAINS=${!toolchain_var_name}
 233 
 234   if test "x$OPENJDK_TARGET_OS" = xmacosx; then
 235     if test -n "$XCODEBUILD"; then
 236       # On Mac OS X, default toolchain to clang after Xcode 5
 237       XCODE_VERSION_OUTPUT=`"$XCODEBUILD" -version 2>&1 | $HEAD -n 1`
 238       $ECHO "$XCODE_VERSION_OUTPUT" | $GREP "Xcode " > /dev/null
 239       if test $? -ne 0; then
 240         AC_MSG_NOTICE([xcodebuild output: $XCODE_VERSION_OUTPUT])
 241         AC_MSG_ERROR([Failed to determine Xcode version.])
 242       fi
 243       XCODE_MAJOR_VERSION=`$ECHO $XCODE_VERSION_OUTPUT | \
 244           $SED -e 's/^Xcode \(@<:@1-9@:>@@<:@0-9.@:>@*\)/\1/' | \
 245           $CUT -f 1 -d .`
 246       AC_MSG_NOTICE([Xcode major version: $XCODE_MAJOR_VERSION])
 247       if test $XCODE_MAJOR_VERSION -ge 5; then
 248           DEFAULT_TOOLCHAIN="clang"
 249       else
 250           DEFAULT_TOOLCHAIN="gcc"
 251       fi
 252     else
 253       # If Xcode is not installed, but the command line tools are
 254       # then we can't run xcodebuild. On these systems we should
 255       # default to clang
 256       DEFAULT_TOOLCHAIN="clang"
 257     fi
 258   else
 259     # First toolchain type in the list is the default
 260     DEFAULT_TOOLCHAIN=${VALID_TOOLCHAINS%% *}
 261   fi
 262 
 263   if test "x$with_toolchain_type" = xlist; then
 264     # List all toolchains
 265     AC_MSG_NOTICE([The following toolchains are valid on this platform:])
 266     for toolchain in $VALID_TOOLCHAINS; do
 267       toolchain_var_name=TOOLCHAIN_DESCRIPTION_$toolchain
 268       TOOLCHAIN_DESCRIPTION=${!toolchain_var_name}
 269       $PRINTF "  %-10s  %s\n" $toolchain "$TOOLCHAIN_DESCRIPTION"
 270     done
 271 
 272     exit 0
 273   elif test "x$with_toolchain_type" != x; then
 274     # User override; check that it is valid
 275     if test "x${VALID_TOOLCHAINS/$with_toolchain_type/}" = "x${VALID_TOOLCHAINS}"; then
 276       AC_MSG_NOTICE([Toolchain type $with_toolchain_type is not valid on this platform.])
 277       AC_MSG_NOTICE([Valid toolchains: $VALID_TOOLCHAINS.])
 278       AC_MSG_ERROR([Cannot continue.])
 279     fi
 280     TOOLCHAIN_TYPE=$with_toolchain_type
 281   else
 282     # No flag given, use default
 283     TOOLCHAIN_TYPE=$DEFAULT_TOOLCHAIN
 284   fi
 285   AC_SUBST(TOOLCHAIN_TYPE)
 286 
 287   # on AIX, check for xlclang++ on the PATH and TOOLCHAIN_PATH and use it if it is available
 288   if test "x$OPENJDK_TARGET_OS" = xaix; then
 289     if test "x$TOOLCHAIN_PATH" != x; then
 290       XLC_TEST_PATH=${TOOLCHAIN_PATH}/
 291     fi
 292 
 293     XLCLANG_VERSION_OUTPUT=`${XLC_TEST_PATH}xlclang++ -qversion 2>&1 | $HEAD -n 1`
 294     $ECHO "$XLCLANG_VERSION_OUTPUT" | $GREP "IBM XL C/C++ for AIX" > /dev/null
 295     if test $? -eq 0; then
 296       AC_MSG_NOTICE([xlclang++ output: $XLCLANG_VERSION_OUTPUT])
 297     else
 298       AC_MSG_ERROR([xlclang++ version output check failed, output: $XLCLANG_VERSION_OUTPUT])
 299     fi
 300   fi
 301 
 302   TOOLCHAIN_CC_BINARY_clang="clang"
 303   TOOLCHAIN_CC_BINARY_gcc="gcc"
 304   TOOLCHAIN_CC_BINARY_microsoft="cl"
 305   TOOLCHAIN_CC_BINARY_xlc="xlclang"
 306 
 307   TOOLCHAIN_CXX_BINARY_clang="clang++"
 308   TOOLCHAIN_CXX_BINARY_gcc="g++"
 309   TOOLCHAIN_CXX_BINARY_microsoft="cl"
 310   TOOLCHAIN_CXX_BINARY_xlc="xlclang++"
 311 
 312   # Use indirect variable referencing
 313   toolchain_var_name=TOOLCHAIN_DESCRIPTION_$TOOLCHAIN_TYPE
 314   TOOLCHAIN_DESCRIPTION=${!toolchain_var_name}
 315   toolchain_var_name=TOOLCHAIN_MINIMUM_VERSION_$TOOLCHAIN_TYPE
 316   TOOLCHAIN_MINIMUM_VERSION=${!toolchain_var_name}
 317   toolchain_var_name=TOOLCHAIN_MINIMUM_LD_VERSION_$TOOLCHAIN_TYPE
 318   TOOLCHAIN_MINIMUM_LD_VERSION=${!toolchain_var_name}
 319   toolchain_var_name=TOOLCHAIN_CC_BINARY_$TOOLCHAIN_TYPE
 320   TOOLCHAIN_CC_BINARY=${!toolchain_var_name}
 321   toolchain_var_name=TOOLCHAIN_CXX_BINARY_$TOOLCHAIN_TYPE
 322   TOOLCHAIN_CXX_BINARY=${!toolchain_var_name}
 323 
 324   TOOLCHAIN_SETUP_FILENAME_PATTERNS
 325 
 326   if test "x$TOOLCHAIN_TYPE" = "x$DEFAULT_TOOLCHAIN"; then
 327     AC_MSG_NOTICE([Using default toolchain $TOOLCHAIN_TYPE ($TOOLCHAIN_DESCRIPTION)])
 328   else
 329     AC_MSG_NOTICE([Using user selected toolchain $TOOLCHAIN_TYPE ($TOOLCHAIN_DESCRIPTION). Default toolchain is $DEFAULT_TOOLCHAIN.])
 330   fi
 331 ])
 332 
 333 # Before we start detecting the toolchain executables, we might need some
 334 # special setup, e.g. additional paths etc.
 335 AC_DEFUN_ONCE([TOOLCHAIN_PRE_DETECTION],
 336 [
 337   # Store the CFLAGS etc passed to the configure script.
 338   ORG_CFLAGS="$CFLAGS"
 339   ORG_CXXFLAGS="$CXXFLAGS"
 340 
 341   # autoconf magic only relies on PATH, so update it if tools dir is specified
 342   OLD_PATH="$PATH"
 343 
 344   if test "x$XCODE_VERSION_OUTPUT" != x; then
 345     # For Xcode, we set the Xcode version as TOOLCHAIN_VERSION
 346     TOOLCHAIN_VERSION=`$ECHO $XCODE_VERSION_OUTPUT | $CUT -f 2 -d ' '`
 347     TOOLCHAIN_DESCRIPTION="$TOOLCHAIN_DESCRIPTION from Xcode $TOOLCHAIN_VERSION"
 348   fi
 349   AC_SUBST(TOOLCHAIN_VERSION)
 350 
 351   # Finally prepend TOOLCHAIN_PATH to the PATH, to allow --with-tools-dir to
 352   # override all other locations.
 353   if test "x$TOOLCHAIN_PATH" != x; then
 354     export PATH=$TOOLCHAIN_PATH:$PATH
 355   fi
 356 ])
 357 
 358 # Restore path, etc
 359 AC_DEFUN_ONCE([TOOLCHAIN_POST_DETECTION],
 360 [
 361   # Restore old path, except for the microsoft toolchain, which requires the
 362   # toolchain path to remain in place. Otherwise the compiler will not work in
 363   # some siutations in later configure checks.
 364   if test "x$TOOLCHAIN_TYPE" != "xmicrosoft"; then
 365     PATH="$OLD_PATH"
 366   fi
 367 
 368   # Restore the flags to the user specified values.
 369   # This is necessary since AC_PROG_CC defaults CFLAGS to "-g -O2"
 370   CFLAGS="$ORG_CFLAGS"
 371   CXXFLAGS="$ORG_CXXFLAGS"
 372 ])
 373 
 374 # Check if a compiler is of the toolchain type we expect, and save the version
 375 # information from it. If the compiler does not match the expected type,
 376 # this function will abort using AC_MSG_ERROR. If it matches, the version will
 377 # be stored in CC_VERSION_NUMBER/CXX_VERSION_NUMBER (as a dotted number), and
 378 # the full version string in CC_VERSION_STRING/CXX_VERSION_STRING.
 379 #
 380 # $1 = compiler to test (CC or CXX)
 381 # $2 = human readable name of compiler (C or C++)
 382 AC_DEFUN([TOOLCHAIN_EXTRACT_COMPILER_VERSION],
 383 [
 384   COMPILER=[$]$1
 385   COMPILER_NAME=$2
 386 
 387   if test  "x$TOOLCHAIN_TYPE" = xxlc; then
 388     # xlc -qversion output typically looks like
 389     #     IBM XL C/C++ for AIX, V11.1 (5724-X13)
 390     #     Version: 11.01.0000.0015
 391     COMPILER_VERSION_OUTPUT=`$COMPILER -qversion 2>&1`
 392     # Check that this is likely to be the IBM XL C compiler.
 393     $ECHO "$COMPILER_VERSION_OUTPUT" | $GREP "IBM XL C" > /dev/null
 394     if test $? -ne 0; then
 395       ALT_VERSION_OUTPUT=`$COMPILER --version 2>&1`
 396       AC_MSG_NOTICE([The $COMPILER_NAME compiler (located as $COMPILER) does not seem to be the required $TOOLCHAIN_TYPE compiler.])
 397       AC_MSG_NOTICE([The result from running with -qversion was: "$COMPILER_VERSION_OUTPUT"])
 398       AC_MSG_NOTICE([The result from running with --version was: "$ALT_VERSION_OUTPUT"])
 399       AC_MSG_ERROR([A $TOOLCHAIN_TYPE compiler is required. Try setting --with-tools-dir.])
 400     fi
 401     # Collapse compiler output into a single line
 402     COMPILER_VERSION_STRING=`$ECHO $COMPILER_VERSION_OUTPUT`
 403     COMPILER_VERSION_NUMBER=`$ECHO $COMPILER_VERSION_OUTPUT | \
 404         $SED -e 's/^.*, V\(@<:@1-9@:>@@<:@0-9.@:>@*\).*$/\1/'`
 405   elif test  "x$TOOLCHAIN_TYPE" = xmicrosoft; then
 406     # There is no specific version flag, but all output starts with a version string.
 407     # First line typically looks something like:
 408     # Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 16.00.40219.01 for 80x86
 409     # but the compiler name may vary depending on locale.
 410     COMPILER_VERSION_OUTPUT=`$COMPILER 2>&1 1>/dev/null | $HEAD -n 1 | $TR -d '\r'`
 411     # Check that this is likely to be Microsoft CL.EXE.
 412     $ECHO "$COMPILER_VERSION_OUTPUT" | $GREP "Microsoft" > /dev/null
 413     if test $? -ne 0; then
 414       AC_MSG_NOTICE([The $COMPILER_NAME compiler (located as $COMPILER) does not seem to be the required $TOOLCHAIN_TYPE compiler.])
 415       AC_MSG_NOTICE([The result from running it was: "$COMPILER_VERSION_OUTPUT"])
 416       AC_MSG_ERROR([A $TOOLCHAIN_TYPE compiler is required. Try setting --with-tools-dir.])
 417     fi
 418     # Collapse compiler output into a single line
 419     COMPILER_VERSION_STRING=`$ECHO $COMPILER_VERSION_OUTPUT`
 420     COMPILER_VERSION_NUMBER=`$ECHO $COMPILER_VERSION_OUTPUT | \
 421         $SED -e 's/^.*ersion.\(@<:@1-9@:>@@<:@0-9.@:>@*\) .*$/\1/'`
 422   elif test  "x$TOOLCHAIN_TYPE" = xgcc; then
 423     # gcc --version output typically looks like
 424     #     gcc (Ubuntu/Linaro 4.8.1-10ubuntu9) 4.8.1
 425     #     Copyright (C) 2013 Free Software Foundation, Inc.
 426     #     This is free software; see the source for copying conditions.  There is NO
 427     #     warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 428     COMPILER_VERSION_OUTPUT=`$COMPILER --version 2>&1`
 429     # Check that this is likely to be GCC.
 430     $ECHO "$COMPILER_VERSION_OUTPUT" | $GREP "Free Software Foundation" > /dev/null
 431     if test $? -ne 0; then
 432       AC_MSG_NOTICE([The $COMPILER_NAME compiler (located as $COMPILER) does not seem to be the required $TOOLCHAIN_TYPE compiler.])
 433       AC_MSG_NOTICE([The result from running with --version was: "$COMPILER_VERSION"])
 434       AC_MSG_ERROR([A $TOOLCHAIN_TYPE compiler is required. Try setting --with-tools-dir.])
 435     fi
 436     # Remove Copyright and legalese from version string, and
 437     # collapse into a single line
 438     COMPILER_VERSION_STRING=`$ECHO $COMPILER_VERSION_OUTPUT | \
 439         $SED -e 's/ *Copyright .*//'`
 440     COMPILER_VERSION_NUMBER=`$ECHO $COMPILER_VERSION_OUTPUT | \
 441         $SED -e 's/^.* \(@<:@1-9@:>@<:@0-9@:>@*\.@<:@0-9.@:>@*\)@<:@^0-9.@:>@.*$/\1/'`
 442   elif test  "x$TOOLCHAIN_TYPE" = xclang; then
 443     # clang --version output typically looks like
 444     #    Apple LLVM version 5.0 (clang-500.2.79) (based on LLVM 3.3svn)
 445     #    clang version 3.3 (tags/RELEASE_33/final)
 446     # or
 447     #    Debian clang version 3.2-7ubuntu1 (tags/RELEASE_32/final) (based on LLVM 3.2)
 448     #    Target: x86_64-pc-linux-gnu
 449     #    Thread model: posix
 450     COMPILER_VERSION_OUTPUT=`$COMPILER --version 2>&1`
 451     # Check that this is likely to be clang
 452     $ECHO "$COMPILER_VERSION_OUTPUT" | $GREP "clang" > /dev/null
 453     if test $? -ne 0; then
 454       AC_MSG_NOTICE([The $COMPILER_NAME compiler (located as $COMPILER) does not seem to be the required $TOOLCHAIN_TYPE compiler.])
 455       AC_MSG_NOTICE([The result from running with --version was: "$COMPILER_VERSION_OUTPUT"])
 456       AC_MSG_ERROR([A $TOOLCHAIN_TYPE compiler is required. Try setting --with-tools-dir.])
 457     fi
 458     # Collapse compiler output into a single line
 459     COMPILER_VERSION_STRING=`$ECHO $COMPILER_VERSION_OUTPUT`
 460     COMPILER_VERSION_NUMBER=`$ECHO $COMPILER_VERSION_OUTPUT | \
 461         $SED -e 's/^.* version \(@<:@1-9@:>@@<:@0-9.@:>@*\).*$/\1/'`
 462   else
 463       AC_MSG_ERROR([Unknown toolchain type $TOOLCHAIN_TYPE.])
 464   fi
 465   # This sets CC_VERSION_NUMBER or CXX_VERSION_NUMBER. (This comment is a grep marker)
 466   $1_VERSION_NUMBER="$COMPILER_VERSION_NUMBER"
 467   # This sets CC_VERSION_STRING or CXX_VERSION_STRING. (This comment is a grep marker)
 468   $1_VERSION_STRING="$COMPILER_VERSION_STRING"
 469 
 470   AC_MSG_NOTICE([Using $TOOLCHAIN_TYPE $COMPILER_NAME compiler version $COMPILER_VERSION_NUMBER @<:@$COMPILER_VERSION_STRING@:>@])
 471 ])
 472 
 473 # Try to locate the given C or C++ compiler in the path, or otherwise.
 474 #
 475 # $1 = compiler to test (CC or CXX)
 476 # $2 = human readable name of compiler (C or C++)
 477 # $3 = compiler name to search for
 478 AC_DEFUN([TOOLCHAIN_FIND_COMPILER],
 479 [
 480   COMPILER_NAME=$2
 481   SEARCH_LIST="$3"
 482 
 483   if test "x[$]$1" != x; then
 484     # User has supplied compiler name already, always let that override.
 485     AC_MSG_NOTICE([Will use user supplied compiler $1=[$]$1])
 486     if test "x`basename [$]$1`" = "x[$]$1"; then
 487       # A command without a complete path is provided, search $PATH.
 488 
 489       UTIL_LOOKUP_PROGS(POTENTIAL_$1, [$]$1)
 490       if test "x$POTENTIAL_$1" != x; then
 491         $1=$POTENTIAL_$1
 492       else
 493         AC_MSG_ERROR([User supplied compiler $1=[$]$1 could not be found])
 494       fi
 495     else
 496       # Otherwise it might already be a complete path
 497       if test ! -x "[$]$1"; then
 498         AC_MSG_ERROR([User supplied compiler $1=[$]$1 does not exist])
 499       fi
 500     fi
 501   else
 502     # No user supplied value. Locate compiler ourselves.
 503 
 504     # If we are cross compiling, assume cross compilation tools follows the
 505     # cross compilation standard where they are prefixed with the autoconf
 506     # standard name for the target. For example the binary
 507     # i686-sun-solaris2.10-gcc will cross compile for i686-sun-solaris2.10.
 508     # If we are not cross compiling, then the default compiler name will be
 509     # used.
 510 
 511     UTIL_LOOKUP_TOOLCHAIN_PROGS(POTENTIAL_$1, $SEARCH_LIST)
 512     if test "x$POTENTIAL_$1" != x; then
 513       $1=$POTENTIAL_$1
 514     else
 515       HELP_MSG_MISSING_DEPENDENCY([devkit])
 516       AC_MSG_ERROR([Could not find a $COMPILER_NAME compiler. $HELP_MSG])
 517     fi
 518   fi
 519 
 520   # Now we have a compiler binary in $1. Make sure it's okay.
 521   TEST_COMPILER="[$]$1"
 522 
 523   AC_MSG_CHECKING([resolved symbolic links for $1])
 524   SYMLINK_ORIGINAL="$TEST_COMPILER"
 525   UTIL_REMOVE_SYMBOLIC_LINKS(SYMLINK_ORIGINAL)
 526   if test "x$TEST_COMPILER" = "x$SYMLINK_ORIGINAL"; then
 527     AC_MSG_RESULT([no symlink])
 528   else
 529     AC_MSG_RESULT([$SYMLINK_ORIGINAL])
 530 
 531     # We can't handle ccache by gcc wrappers, since we need to know if we're
 532     # using ccache. Instead ccache usage must be controlled by a configure option.
 533     COMPILER_BASENAME=`$BASENAME "$SYMLINK_ORIGINAL"`
 534     if test "x$COMPILER_BASENAME" = "xccache"; then
 535       AC_MSG_NOTICE([Please use --enable-ccache instead of providing a wrapped compiler.])
 536       AC_MSG_ERROR([$TEST_COMPILER is a symbolic link to ccache. This is not supported.])
 537     fi
 538   fi
 539 
 540   TOOLCHAIN_EXTRACT_COMPILER_VERSION([$1], [$COMPILER_NAME])
 541 ])
 542 
 543 # Retrieve the linker version number and store it in LD_VERSION_NUMBER
 544 # (as a dotted number), and
 545 # the full version string in LD_VERSION_STRING.
 546 #
 547 # $1 = linker to test (LD or BUILD_LD)
 548 # $2 = human readable name of linker (Linker or BuildLinker)
 549 AC_DEFUN([TOOLCHAIN_EXTRACT_LD_VERSION],
 550 [
 551   LINKER=[$]$1
 552   LINKER_NAME="$2"
 553 
 554   if test  "x$TOOLCHAIN_TYPE" = xxlc; then
 555     LINKER_VERSION_STRING="Unknown"
 556     LINKER_VERSION_NUMBER="0.0"
 557   elif test  "x$TOOLCHAIN_TYPE" = xmicrosoft; then
 558     # There is no specific version flag, but all output starts with a version string.
 559     # First line typically looks something like:
 560     #   Microsoft (R) Incremental Linker Version 12.00.31101.0
 561     LINKER_VERSION_STRING=`$LINKER 2>&1 | $HEAD -n 1 | $TR -d '\r'`
 562     # Extract version number
 563     [ LINKER_VERSION_NUMBER=`$ECHO $LINKER_VERSION_STRING | \
 564         $SED -e 's/.* \([0-9][0-9]*\(\.[0-9][0-9]*\)*\).*/\1/'` ]
 565   elif test  "x$TOOLCHAIN_TYPE" = xgcc; then
 566     # gcc -Wl,-version output typically looks like:
 567     #   GNU ld (GNU Binutils for Ubuntu) 2.26.1
 568     #   Copyright (C) 2015 Free Software Foundation, Inc.
 569     #   This program is free software; [...]
 570     # If using gold it will look like:
 571     #   GNU gold (GNU Binutils 2.30) 1.15
 572     LINKER_VERSION_STRING=`$LINKER -Wl,--version 2> /dev/null | $HEAD -n 1`
 573     # Extract version number
 574     if [ [[ "$LINKER_VERSION_STRING" == *gold* ]] ]; then
 575       [ LINKER_VERSION_NUMBER=`$ECHO $LINKER_VERSION_STRING | \
 576           $SED -e 's/.* \([0-9][0-9]*\(\.[0-9][0-9]*\)*\).*) .*/\1/'` ]
 577     else
 578       [ LINKER_VERSION_NUMBER=`$ECHO $LINKER_VERSION_STRING | \
 579           $SED -e 's/.* \([0-9][0-9]*\(\.[0-9][0-9]*\)*\).*/\1/'` ]
 580     fi
 581   elif test  "x$TOOLCHAIN_TYPE" = xclang; then
 582     # clang -Wl,-v output typically looks like
 583     #   @(#)PROGRAM:ld  PROJECT:ld64-305
 584     #   configured to support archs: armv6 armv7 armv7s arm64 i386 x86_64 x86_64h armv6m armv7k armv7m armv7em (tvOS)
 585     #   Library search paths: [...]
 586     # or
 587     #   GNU ld (GNU Binutils for Ubuntu) 2.26.1
 588 
 589     LINKER_VERSION_STRING=`$LINKER -Wl,-v 2>&1 | $HEAD -n 1`
 590     # Check if we're using the GNU ld
 591     $ECHO "$LINKER_VERSION_STRING" | $GREP "GNU" > /dev/null
 592     if test $? -eq 0; then
 593       # Extract version number
 594       [ LINKER_VERSION_NUMBER=`$ECHO $LINKER_VERSION_STRING | \
 595           $SED -e 's/.* \([0-9][0-9]*\(\.[0-9][0-9]*\)*\).*/\1/'` ]
 596     else
 597       # Extract version number
 598       [ LINKER_VERSION_NUMBER=`$ECHO $LINKER_VERSION_STRING | \
 599           $SED -e 's/.*-\([0-9][0-9]*\)/\1/'` ]
 600     fi
 601   fi
 602 
 603   $1_VERSION_NUMBER="$LINKER_VERSION_NUMBER"
 604   $1_VERSION_STRING="$LINKER_VERSION_STRING"
 605 
 606   AC_MSG_NOTICE([Using $TOOLCHAIN_TYPE $LINKER_NAME version $LINKER_VERSION_NUMBER @<:@$LINKER_VERSION_STRING@:>@])
 607 ])
 608 
 609 # Make sure we did not pick up /usr/bin/link, which is the unix-style link
 610 # executable.
 611 #
 612 # $1 = linker to test (LD or BUILD_LD)
 613 AC_DEFUN(TOOLCHAIN_VERIFY_LINK_BINARY,
 614 [
 615   LINKER=[$]$1
 616 
 617   AC_MSG_CHECKING([if the found link.exe is actually the Visual Studio linker])
 618   $LINKER --version > /dev/null
 619   if test $? -eq 0 ; then
 620     AC_MSG_RESULT([no])
 621     AC_MSG_ERROR([$LINKER is the winenv link tool. Please check your PATH and rerun configure.])
 622   else
 623     AC_MSG_RESULT([yes])
 624   fi
 625 ])
 626 # Detect the core components of the toolchain, i.e. the compilers (CC and CXX),
 627 # preprocessor (CPP and CXXCPP), the linker (LD), the assembler (AS) and the
 628 # archiver (AR). Verify that the compilers are correct according to the
 629 # toolchain type.
 630 AC_DEFUN_ONCE([TOOLCHAIN_DETECT_TOOLCHAIN_CORE],
 631 [
 632   #
 633   # Setup the compilers (CC and CXX)
 634   #
 635   TOOLCHAIN_FIND_COMPILER([CC], [C], $TOOLCHAIN_CC_BINARY)
 636   # Now that we have resolved CC ourself, let autoconf have its go at it
 637   AC_PROG_CC([$CC])
 638 
 639   TOOLCHAIN_FIND_COMPILER([CXX], [C++], $TOOLCHAIN_CXX_BINARY)
 640   # Now that we have resolved CXX ourself, let autoconf have its go at it
 641   AC_PROG_CXX([$CXX])
 642 
 643   # This is the compiler version number on the form X.Y[.Z]
 644   AC_SUBST(CC_VERSION_NUMBER)
 645   AC_SUBST(CXX_VERSION_NUMBER)
 646 
 647   TOOLCHAIN_PREPARE_FOR_VERSION_COMPARISONS
 648 
 649   if test "x$TOOLCHAIN_MINIMUM_VERSION" != x; then
 650     TOOLCHAIN_CHECK_COMPILER_VERSION(VERSION: $TOOLCHAIN_MINIMUM_VERSION,
 651         IF_OLDER_THAN: [
 652           AC_MSG_WARN([You are using $TOOLCHAIN_TYPE older than $TOOLCHAIN_MINIMUM_VERSION. This is not a supported configuration.])
 653         ]
 654     )
 655   fi
 656 
 657   #
 658   # Setup the preprocessor (CPP and CXXCPP)
 659   #
 660   AC_PROG_CPP
 661   UTIL_FIXUP_EXECUTABLE(CPP)
 662   AC_PROG_CXXCPP
 663   UTIL_FIXUP_EXECUTABLE(CXXCPP)
 664 
 665   #
 666   # Setup the linker (LD)
 667   #
 668   if test "x$TOOLCHAIN_TYPE" = xmicrosoft; then
 669     # In the Microsoft toolchain we have a separate LD command "link".
 670     UTIL_LOOKUP_TOOLCHAIN_PROGS(LD, link)
 671     TOOLCHAIN_VERIFY_LINK_BINARY(LD)
 672     LDCXX="$LD"
 673   else
 674     # All other toolchains use the compiler to link.
 675     LD="$CC"
 676     LDCXX="$CXX"
 677   fi
 678   AC_SUBST(LD)
 679   # FIXME: it should be CXXLD, according to standard (cf CXXCPP)
 680   AC_SUBST(LDCXX)
 681 
 682   TOOLCHAIN_EXTRACT_LD_VERSION([LD], [linker])
 683   TOOLCHAIN_PREPARE_FOR_LD_VERSION_COMPARISONS
 684 
 685   if test "x$TOOLCHAIN_MINIMUM_LD_VERSION" != x; then
 686     AC_MSG_NOTICE([comparing linker version to minimum version $TOOLCHAIN_MINIMUM_LD_VERSION])
 687     TOOLCHAIN_CHECK_LINKER_VERSION(VERSION: $TOOLCHAIN_MINIMUM_LD_VERSION,
 688         IF_OLDER_THAN: [
 689           AC_MSG_ERROR([You are using a linker older than $TOOLCHAIN_MINIMUM_LD_VERSION. This is not a supported configuration.])
 690         ]
 691     )
 692   fi
 693 
 694   #
 695   # Setup the assembler (AS)
 696   #
 697   if test "x$TOOLCHAIN_TYPE" != xmicrosoft; then
 698     AS="$CC -c"
 699   else
 700     if test "x$OPENJDK_TARGET_CPU_BITS" = "x64"; then
 701       # On 64 bit windows, the assember is "ml64.exe"
 702       UTIL_LOOKUP_TOOLCHAIN_PROGS(AS, ml64)
 703     else
 704       # otherwise, the assember is "ml.exe"
 705       UTIL_LOOKUP_TOOLCHAIN_PROGS(AS, ml)
 706     fi
 707   fi
 708   AC_SUBST(AS)
 709 
 710   #
 711   # Setup the archiver (AR)
 712   #
 713   if test "x$TOOLCHAIN_TYPE" = xmicrosoft; then
 714     # The corresponding ar tool is lib.exe (used to create static libraries)
 715     UTIL_LOOKUP_TOOLCHAIN_PROGS(AR, lib)
 716   elif test "x$TOOLCHAIN_TYPE" = xgcc; then
 717     UTIL_LOOKUP_TOOLCHAIN_PROGS(AR, ar gcc-ar)
 718   else
 719     UTIL_LOOKUP_TOOLCHAIN_PROGS(AR, ar)
 720   fi
 721 ])
 722 
 723 # Setup additional tools that is considered a part of the toolchain, but not the
 724 # core part. Many of these are highly platform-specific and do not exist,
 725 # and/or are not needed on all platforms.
 726 AC_DEFUN_ONCE([TOOLCHAIN_DETECT_TOOLCHAIN_EXTRA],
 727 [
 728   if test "x$OPENJDK_TARGET_OS" = "xmacosx"; then
 729     UTIL_LOOKUP_PROGS(LIPO, lipo)
 730     UTIL_REQUIRE_PROGS(OTOOL, otool)
 731     UTIL_REQUIRE_PROGS(INSTALL_NAME_TOOL, install_name_tool)
 732 
 733     UTIL_LOOKUP_TOOLCHAIN_PROGS(METAL, metal)
 734     if test "x$METAL" = x; then
 735       AC_MSG_CHECKING([if metal can be run using xcrun])
 736       METAL="xcrun -sdk macosx metal"
 737       test_metal=`$METAL --version 2>&1`
 738       if test $? -ne 0; then
 739         AC_MSG_RESULT([no])
 740         AC_MSG_ERROR([XCode tool 'metal' neither found in path nor with xcrun])
 741       else
 742         AC_MSG_RESULT([yes, will be using '$METAL'])
 743       fi
 744     fi
 745 
 746     UTIL_LOOKUP_TOOLCHAIN_PROGS(METALLIB, metallib)
 747     if test "x$METALLIB" = x; then
 748       AC_MSG_CHECKING([if metallib can be run using xcrun])
 749       METALLIB="xcrun -sdk macosx metallib"
 750       test_metallib=`$METALLIB --version 2>&1`
 751       if test $? -ne 0; then
 752         AC_MSG_RESULT([no])
 753         AC_MSG_ERROR([XCode tool 'metallib' neither found in path nor with xcrun])
 754       else
 755         AC_MSG_RESULT([yes, will be using '$METALLIB'])
 756       fi
 757     fi
 758   fi
 759 
 760   if test "x$TOOLCHAIN_TYPE" = xmicrosoft; then
 761     # Setup the manifest tool (MT)
 762     UTIL_LOOKUP_TOOLCHAIN_PROGS(MT, mt)
 763     # Setup the resource compiler (RC)
 764     UTIL_LOOKUP_TOOLCHAIN_PROGS(RC, rc)
 765     UTIL_LOOKUP_TOOLCHAIN_PROGS(DUMPBIN, dumpbin)
 766   fi
 767 
 768   if test "x$OPENJDK_TARGET_OS" != xwindows; then
 769     UTIL_LOOKUP_TOOLCHAIN_PROGS(STRIP, strip)
 770     if test "x$TOOLCHAIN_TYPE" = xgcc; then
 771       UTIL_LOOKUP_TOOLCHAIN_PROGS(NM, nm gcc-nm)
 772     else
 773       UTIL_LOOKUP_TOOLCHAIN_PROGS(NM, nm)
 774     fi
 775     GNM="$NM"
 776     AC_SUBST(GNM)
 777   fi
 778 
 779   # objcopy is used for moving debug symbols to separate files when
 780   # full debug symbols are enabled.
 781   if test "x$OPENJDK_TARGET_OS" = xlinux; then
 782     UTIL_LOOKUP_TOOLCHAIN_PROGS(OBJCOPY, gobjcopy objcopy)
 783   fi
 784 
 785   UTIL_LOOKUP_TOOLCHAIN_PROGS(OBJDUMP, gobjdump objdump)
 786 
 787   case $TOOLCHAIN_TYPE in
 788     gcc|clang)
 789       UTIL_REQUIRE_TOOLCHAIN_PROGS(CXXFILT, c++filt)
 790       ;;
 791   esac
 792 ])
 793 
 794 # Setup the build tools (i.e, the compiler and linker used to build programs
 795 # that should be run on the build platform, not the target platform, as a build
 796 # helper). Since the non-cross-compile case uses the normal, target compilers
 797 # for this, we can only do this after these have been setup.
 798 AC_DEFUN_ONCE([TOOLCHAIN_SETUP_BUILD_COMPILERS],
 799 [
 800   if test "x$COMPILE_TYPE" = "xcross"; then
 801     # Now we need to find a C/C++ compiler that can build executables for the
 802     # build platform. We can't use the AC_PROG_CC macro, since it can only be
 803     # used once. Also, we need to do this without adding a tools dir to the
 804     # path, otherwise we might pick up cross-compilers which don't use standard
 805     # naming.
 806 
 807     OLDPATH="$PATH"
 808 
 809     AC_ARG_WITH(build-devkit, [AS_HELP_STRING([--with-build-devkit],
 810         [Devkit to use for the build platform toolchain])])
 811     if test "x$with_build_devkit" = "xyes"; then
 812       AC_MSG_ERROR([--with-build-devkit must have a value])
 813     elif test -n "$with_build_devkit"; then
 814       if test ! -d "$with_build_devkit"; then
 815         AC_MSG_ERROR([--with-build-devkit points to non existing dir: $with_build_devkit])
 816       else
 817         UTIL_FIXUP_PATH([with_build_devkit])
 818         BUILD_DEVKIT_ROOT="$with_build_devkit"
 819         # Check for a meta data info file in the root of the devkit
 820         if test -f "$BUILD_DEVKIT_ROOT/devkit.info"; then
 821           # Process devkit.info so that existing devkit variables are not
 822           # modified by this
 823           $SED -e "s/^DEVKIT_/BUILD_DEVKIT_/g" \
 824               -e "s/\$DEVKIT_ROOT/\$BUILD_DEVKIT_ROOT/g" \
 825               -e "s/\$host/\$build/g" \
 826               $BUILD_DEVKIT_ROOT/devkit.info \
 827               > $CONFIGURESUPPORT_OUTPUTDIR/build-devkit.info
 828           . $CONFIGURESUPPORT_OUTPUTDIR/build-devkit.info
 829           # This potentially sets the following:
 830           # A descriptive name of the devkit
 831           BASIC_EVAL_BUILD_DEVKIT_VARIABLE([BUILD_DEVKIT_NAME])
 832           # Corresponds to --with-extra-path
 833           BASIC_EVAL_BUILD_DEVKIT_VARIABLE([BUILD_DEVKIT_EXTRA_PATH])
 834           # Corresponds to --with-toolchain-path
 835           BASIC_EVAL_BUILD_DEVKIT_VARIABLE([BUILD_DEVKIT_TOOLCHAIN_PATH])
 836           # Corresponds to --with-sysroot
 837           BASIC_EVAL_BUILD_DEVKIT_VARIABLE([BUILD_DEVKIT_SYSROOT])
 838 
 839           if test "x$TOOLCHAIN_TYPE" = xmicrosoft; then
 840             BASIC_EVAL_BUILD_DEVKIT_VARIABLE([BUILD_DEVKIT_VS_INCLUDE])
 841             BASIC_EVAL_BUILD_DEVKIT_VARIABLE([BUILD_DEVKIT_VS_LIB])
 842           fi
 843         fi
 844 
 845         AC_MSG_CHECKING([for build platform devkit])
 846         if test "x$BUILD_DEVKIT_NAME" != x; then
 847           AC_MSG_RESULT([$BUILD_DEVKIT_NAME in $BUILD_DEVKIT_ROOT])
 848         else
 849           AC_MSG_RESULT([$BUILD_DEVKIT_ROOT])
 850         fi
 851 
 852         # Fallback default of just /bin if DEVKIT_PATH is not defined
 853         if test "x$BUILD_DEVKIT_TOOLCHAIN_PATH" = x; then
 854           BUILD_DEVKIT_TOOLCHAIN_PATH="$BUILD_DEVKIT_ROOT/bin"
 855         fi
 856         PATH="$BUILD_DEVKIT_TOOLCHAIN_PATH:$BUILD_DEVKIT_EXTRA_PATH"
 857 
 858         BUILD_SYSROOT="$BUILD_DEVKIT_SYSROOT"
 859 
 860         if test "x$TOOLCHAIN_TYPE" = xmicrosoft; then
 861           # For historical reasons, paths are separated by ; in devkit.info
 862           BUILD_VS_INCLUDE="${BUILD_DEVKIT_VS_INCLUDE//;/:}"
 863           BUILD_VS_LIB="${BUILD_DEVKIT_VS_LIB//;/:}"
 864 
 865           TOOLCHAIN_SETUP_VISUAL_STUDIO_SYSROOT_FLAGS(BUILD_, BUILD_)
 866         fi
 867       fi
 868     else
 869       if test "x$TOOLCHAIN_TYPE" = xmicrosoft; then
 870         # If we got no devkit, we need to go hunting for the proper env
 871         TOOLCHAIN_FIND_VISUAL_STUDIO_BAT_FILE($OPENJDK_BUILD_CPU, [$TOOLCHAIN_VERSION])
 872         TOOLCHAIN_EXTRACT_VISUAL_STUDIO_ENV($OPENJDK_BUILD_CPU, BUILD_)
 873 
 874         # We cannot currently export the VS_PATH to spec.gmk. This is probably
 875         # strictly not correct, but seems to work anyway.
 876 
 877         # Convert VS_INCLUDE and VS_LIB into sysroot flags
 878         TOOLCHAIN_SETUP_VISUAL_STUDIO_SYSROOT_FLAGS(BUILD_)
 879       fi
 880     fi
 881 
 882     if test "x$TOOLCHAIN_TYPE" = xmicrosoft; then
 883       UTIL_REQUIRE_PROGS(BUILD_CC, cl, [$VS_PATH])
 884       UTIL_REQUIRE_PROGS(BUILD_CXX, cl, [$VS_PATH])
 885 
 886       # On windows, the assember is "ml.exe". We currently don't need this so
 887       # do not require.
 888       if test "x$OPENJDK_BUILD_CPU_BITS" = "x64"; then
 889         # On 64 bit windows, the assember is "ml64.exe"
 890         UTIL_LOOKUP_PROGS(BUILD_AS, ml64, [$VS_PATH])
 891       else
 892         # otherwise the assember is "ml.exe"
 893         UTIL_LOOKUP_PROGS(BUILD_AS, ml, [$VS_PATH])
 894       fi
 895 
 896       # On windows, the ar tool is lib.exe (used to create static libraries).
 897       # We currently don't need this so do not require.
 898       UTIL_LOOKUP_PROGS(BUILD_AR, lib, [$VS_PATH])
 899 
 900       # In the Microsoft toolchain we have a separate LD command "link".
 901       UTIL_REQUIRE_PROGS(BUILD_LD, link, [$VS_PATH])
 902       TOOLCHAIN_VERIFY_LINK_BINARY(BUILD_LD)
 903       BUILD_LDCXX="$BUILD_LD"
 904     else
 905       if test "x$OPENJDK_BUILD_OS" = xmacosx; then
 906         UTIL_REQUIRE_PROGS(BUILD_CC, clang cc gcc)
 907         UTIL_REQUIRE_PROGS(BUILD_CXX, clang++ CC g++)
 908       else
 909         UTIL_REQUIRE_PROGS(BUILD_CC, cc gcc)
 910         UTIL_REQUIRE_PROGS(BUILD_CXX, CC g++)
 911       fi
 912       UTIL_LOOKUP_PROGS(BUILD_NM, nm gcc-nm)
 913       UTIL_LOOKUP_PROGS(BUILD_AR, ar gcc-ar lib)
 914       UTIL_LOOKUP_PROGS(BUILD_OBJCOPY, objcopy)
 915       UTIL_LOOKUP_PROGS(BUILD_STRIP, strip)
 916       # Assume the C compiler is the assembler
 917       BUILD_AS="$BUILD_CC -c"
 918       # Just like for the target compiler, use the compiler as linker
 919       BUILD_LD="$BUILD_CC"
 920       BUILD_LDCXX="$BUILD_CXX"
 921     fi
 922 
 923     PATH="$OLDPATH"
 924 
 925     TOOLCHAIN_EXTRACT_COMPILER_VERSION(BUILD_CC, [BuildC])
 926     TOOLCHAIN_EXTRACT_COMPILER_VERSION(BUILD_CXX, [BuildC++])
 927     TOOLCHAIN_PREPARE_FOR_VERSION_COMPARISONS([BUILD_], [OPENJDK_BUILD_], [build ])
 928     TOOLCHAIN_EXTRACT_LD_VERSION(BUILD_LD, [build linker])
 929     TOOLCHAIN_PREPARE_FOR_LD_VERSION_COMPARISONS([BUILD_], [OPENJDK_BUILD_])
 930   else
 931     # If we are not cross compiling, use the normal target compilers for
 932     # building the build platform executables.
 933     BUILD_CC="$CC"
 934     BUILD_CXX="$CXX"
 935     BUILD_LD="$LD"
 936     BUILD_LDCXX="$LDCXX"
 937     BUILD_NM="$NM"
 938     BUILD_AS="$AS"
 939     BUILD_OBJCOPY="$OBJCOPY"
 940     BUILD_STRIP="$STRIP"
 941     BUILD_AR="$AR"
 942 
 943     TOOLCHAIN_PREPARE_FOR_VERSION_COMPARISONS([], [OPENJDK_BUILD_], [build ])
 944     TOOLCHAIN_PREPARE_FOR_LD_VERSION_COMPARISONS([BUILD_], [OPENJDK_BUILD_])
 945   fi
 946 
 947   AC_SUBST(BUILD_CC)
 948   AC_SUBST(BUILD_CXX)
 949   AC_SUBST(BUILD_LD)
 950   AC_SUBST(BUILD_LDCXX)
 951   AC_SUBST(BUILD_NM)
 952   AC_SUBST(BUILD_AS)
 953   AC_SUBST(BUILD_AR)
 954 ])
 955 
 956 # Do some additional checks on the detected tools.
 957 AC_DEFUN_ONCE([TOOLCHAIN_MISC_CHECKS],
 958 [
 959   # Check for extra potential brokenness.
 960   if test  "x$TOOLCHAIN_TYPE" = xmicrosoft; then
 961     # On Windows, double-check that we got the right compiler.
 962     CC_VERSION_OUTPUT=`$CC 2>&1 1>/dev/null | $HEAD -n 1 | $TR -d '\r'`
 963     COMPILER_CPU_TEST=`$ECHO $CC_VERSION_OUTPUT | $SED -n "s/^.* \(.*\)$/\1/p"`
 964     if test "x$OPENJDK_TARGET_CPU" = "xx86"; then
 965       if test "x$COMPILER_CPU_TEST" != "x80x86" -a "x$COMPILER_CPU_TEST" != "xx86"; then
 966         AC_MSG_ERROR([Target CPU mismatch. We are building for $OPENJDK_TARGET_CPU but CL is for "$COMPILER_CPU_TEST"; expected "80x86" or "x86".])
 967       fi
 968     elif test "x$OPENJDK_TARGET_CPU" = "xx86_64"; then
 969       if test "x$COMPILER_CPU_TEST" != "xx64"; then
 970         AC_MSG_ERROR([Target CPU mismatch. We are building for $OPENJDK_TARGET_CPU but CL is for "$COMPILER_CPU_TEST"; expected "x64".])
 971       fi
 972     elif test "x$OPENJDK_TARGET_CPU" = "xaarch64"; then
 973       if test "x$COMPILER_CPU_TEST" != "xARM64"; then
 974         AC_MSG_ERROR([Target CPU mismatch. We are building for $OPENJDK_TARGET_CPU but CL is for "$COMPILER_CPU_TEST"; expected "arm64".])
 975       fi
 976     fi
 977   fi
 978 
 979   if test "x$TOOLCHAIN_TYPE" = xgcc || test "x$TOOLCHAIN_TYPE" = xclang; then
 980     # Check if linker has -z noexecstack.
 981     HAS_NOEXECSTACK=`$CC -Wl,--help 2>/dev/null | $GREP 'z noexecstack'`
 982     # This is later checked when setting flags.
 983   fi
 984 
 985   # Setup hotspot lecagy names for toolchains
 986   HOTSPOT_TOOLCHAIN_TYPE=$TOOLCHAIN_TYPE
 987   if test "x$TOOLCHAIN_TYPE" = xclang; then
 988     HOTSPOT_TOOLCHAIN_TYPE=gcc
 989   elif test "x$TOOLCHAIN_TYPE" = xmicrosoft; then
 990     HOTSPOT_TOOLCHAIN_TYPE=visCPP
 991   fi
 992   AC_SUBST(HOTSPOT_TOOLCHAIN_TYPE)
 993 ])
 994 
 995 # Setup the JTReg Regression Test Harness.
 996 AC_DEFUN_ONCE([TOOLCHAIN_SETUP_JTREG],
 997 [
 998   AC_ARG_WITH(jtreg, [AS_HELP_STRING([--with-jtreg],
 999       [Regression Test Harness @<:@probed@:>@])])
1000 
1001   if test "x$with_jtreg" = xno; then
1002     # jtreg disabled
1003     AC_MSG_CHECKING([for jtreg test harness])
1004     AC_MSG_RESULT([no, disabled])
1005   elif test "x$with_jtreg" != xyes && test "x$with_jtreg" != x; then
1006     if test -d "$with_jtreg"; then
1007       # An explicit path is specified, use it.
1008       JT_HOME="$with_jtreg"
1009     else
1010       case "$with_jtreg" in
1011         *.zip )
1012           JTREG_SUPPORT_DIR=$CONFIGURESUPPORT_OUTPUTDIR/jtreg
1013           $RM -rf $JTREG_SUPPORT_DIR
1014           $MKDIR -p $JTREG_SUPPORT_DIR
1015           $UNZIP -qq -d $JTREG_SUPPORT_DIR $with_jtreg
1016 
1017           # Try to find jtreg to determine JT_HOME path
1018           JTREG_PATH=`$FIND $JTREG_SUPPORT_DIR | $GREP "/bin/jtreg"`
1019           if test "x$JTREG_PATH" != x; then
1020             JT_HOME=$($DIRNAME $($DIRNAME $JTREG_PATH))
1021           fi
1022           ;;
1023         * )
1024           ;;
1025       esac
1026     fi
1027     UTIL_FIXUP_PATH([JT_HOME])
1028     if test ! -d "$JT_HOME"; then
1029       AC_MSG_ERROR([jtreg home directory from --with-jtreg=$with_jtreg does not exist])
1030     fi
1031 
1032     if test ! -e "$JT_HOME/lib/jtreg.jar"; then
1033       AC_MSG_ERROR([jtreg home directory from --with-jtreg=$with_jtreg is not a valid jtreg home])
1034     fi
1035 
1036     AC_MSG_CHECKING([for jtreg test harness])
1037     AC_MSG_RESULT([$JT_HOME])
1038   else
1039     # Try to locate jtreg using the JT_HOME environment variable
1040     if test "x$JT_HOME" != x; then
1041       # JT_HOME set in environment, use it
1042       if test ! -d "$JT_HOME"; then
1043         AC_MSG_WARN([Ignoring JT_HOME pointing to invalid directory: $JT_HOME])
1044         JT_HOME=
1045       else
1046         if test ! -e "$JT_HOME/lib/jtreg.jar"; then
1047           AC_MSG_WARN([Ignoring JT_HOME which is not a valid jtreg home: $JT_HOME])
1048           JT_HOME=
1049         else
1050           AC_MSG_NOTICE([Located jtreg using JT_HOME from environment])
1051         fi
1052       fi
1053     fi
1054 
1055     if test "x$JT_HOME" = x; then
1056       # JT_HOME is not set in environment, or was deemed invalid.
1057       # Try to find jtreg on path
1058       UTIL_LOOKUP_PROGS(JTREGEXE, jtreg)
1059       if test "x$JTREGEXE" != x; then
1060         # That's good, now try to derive JT_HOME
1061         JT_HOME=`(cd $($DIRNAME $JTREGEXE)/.. && pwd)`
1062         if test ! -e "$JT_HOME/lib/jtreg.jar"; then
1063           AC_MSG_WARN([Ignoring jtreg from path since a valid jtreg home cannot be found])
1064           JT_HOME=
1065         else
1066           AC_MSG_NOTICE([Located jtreg using jtreg executable in path])
1067         fi
1068       fi
1069     fi
1070 
1071     AC_MSG_CHECKING([for jtreg test harness])
1072     if test "x$JT_HOME" != x; then
1073       AC_MSG_RESULT([$JT_HOME])
1074     else
1075       AC_MSG_RESULT([no, not found])
1076 
1077       if test "x$with_jtreg" = xyes; then
1078         AC_MSG_ERROR([--with-jtreg was specified, but no jtreg found.])
1079       fi
1080     fi
1081   fi
1082 
1083   UTIL_FIXUP_PATH(JT_HOME)
1084   AC_SUBST(JT_HOME)
1085 ])
1086 
1087 # Setup the JIB dependency resolver
1088 AC_DEFUN_ONCE([TOOLCHAIN_SETUP_JIB],
1089 [
1090   AC_ARG_WITH(jib, [AS_HELP_STRING([--with-jib],
1091       [Jib dependency management tool @<:@not used@:>@])])
1092 
1093   if test "x$with_jib" = xno || test "x$with_jib" = x; then
1094     # jib disabled
1095     AC_MSG_CHECKING([for jib])
1096     AC_MSG_RESULT(no)
1097   elif test "x$with_jib" = xyes; then
1098     AC_MSG_ERROR([Must supply a value to --with-jib])
1099   else
1100     JIB_HOME="${with_jib}"
1101     AC_MSG_CHECKING([for jib])
1102     AC_MSG_RESULT(${JIB_HOME})
1103     if test ! -d "${JIB_HOME}"; then
1104       AC_MSG_ERROR([--with-jib must be a directory])
1105     fi
1106     JIB_JAR=$(ls ${JIB_HOME}/lib/jib-*.jar)
1107     if test ! -f "${JIB_JAR}"; then
1108       AC_MSG_ERROR([Could not find jib jar file in ${JIB_HOME}])
1109     fi
1110   fi
1111 
1112   AC_SUBST(JIB_HOME)
1113 ])