1 #
   2 # Copyright (c) 2011, 2022, 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="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   # First toolchain type in the list is the default
 235   DEFAULT_TOOLCHAIN=${VALID_TOOLCHAINS%% *}
 236 
 237   if test "x$with_toolchain_type" = xlist; then
 238     # List all toolchains
 239     AC_MSG_NOTICE([The following toolchains are valid on this platform:])
 240     for toolchain in $VALID_TOOLCHAINS; do
 241       toolchain_var_name=TOOLCHAIN_DESCRIPTION_$toolchain
 242       TOOLCHAIN_DESCRIPTION=${!toolchain_var_name}
 243       $PRINTF "  %-10s  %s\n" $toolchain "$TOOLCHAIN_DESCRIPTION"
 244     done
 245 
 246     exit 0
 247   elif test "x$with_toolchain_type" != x; then
 248     # User override; check that it is valid
 249     if test "x${VALID_TOOLCHAINS/$with_toolchain_type/}" = "x${VALID_TOOLCHAINS}"; then
 250       AC_MSG_NOTICE([Toolchain type $with_toolchain_type is not valid on this platform.])
 251       AC_MSG_NOTICE([Valid toolchains: $VALID_TOOLCHAINS.])
 252       AC_MSG_ERROR([Cannot continue.])
 253     fi
 254     TOOLCHAIN_TYPE=$with_toolchain_type
 255   else
 256     # No flag given, use default
 257     TOOLCHAIN_TYPE=$DEFAULT_TOOLCHAIN
 258   fi
 259   AC_SUBST(TOOLCHAIN_TYPE)
 260 
 261   # on AIX, check for xlclang++ on the PATH and TOOLCHAIN_PATH and use it if it is available
 262   if test "x$OPENJDK_TARGET_OS" = xaix; then
 263     if test "x$TOOLCHAIN_PATH" != x; then
 264       XLC_TEST_PATH=${TOOLCHAIN_PATH}/
 265     fi
 266 
 267     XLCLANG_VERSION_OUTPUT=`${XLC_TEST_PATH}xlclang++ -qversion 2>&1 | $HEAD -n 1`
 268     $ECHO "$XLCLANG_VERSION_OUTPUT" | $GREP "IBM XL C/C++ for AIX" > /dev/null
 269     if test $? -eq 0; then
 270       AC_MSG_NOTICE([xlclang++ output: $XLCLANG_VERSION_OUTPUT])
 271     else
 272       AC_MSG_ERROR([xlclang++ version output check failed, output: $XLCLANG_VERSION_OUTPUT])
 273     fi
 274   fi
 275 
 276   TOOLCHAIN_CC_BINARY_clang="clang"
 277   TOOLCHAIN_CC_BINARY_gcc="gcc"
 278   TOOLCHAIN_CC_BINARY_microsoft="cl"
 279   TOOLCHAIN_CC_BINARY_xlc="xlclang"
 280 
 281   TOOLCHAIN_CXX_BINARY_clang="clang++"
 282   TOOLCHAIN_CXX_BINARY_gcc="g++"
 283   TOOLCHAIN_CXX_BINARY_microsoft="cl"
 284   TOOLCHAIN_CXX_BINARY_xlc="xlclang++"
 285 
 286   # Use indirect variable referencing
 287   toolchain_var_name=TOOLCHAIN_DESCRIPTION_$TOOLCHAIN_TYPE
 288   TOOLCHAIN_DESCRIPTION=${!toolchain_var_name}
 289   toolchain_var_name=TOOLCHAIN_MINIMUM_VERSION_$TOOLCHAIN_TYPE
 290   TOOLCHAIN_MINIMUM_VERSION=${!toolchain_var_name}
 291   toolchain_var_name=TOOLCHAIN_MINIMUM_LD_VERSION_$TOOLCHAIN_TYPE
 292   TOOLCHAIN_MINIMUM_LD_VERSION=${!toolchain_var_name}
 293   toolchain_var_name=TOOLCHAIN_CC_BINARY_$TOOLCHAIN_TYPE
 294   TOOLCHAIN_CC_BINARY=${!toolchain_var_name}
 295   toolchain_var_name=TOOLCHAIN_CXX_BINARY_$TOOLCHAIN_TYPE
 296   TOOLCHAIN_CXX_BINARY=${!toolchain_var_name}
 297 
 298   TOOLCHAIN_SETUP_FILENAME_PATTERNS
 299 
 300   if test "x$TOOLCHAIN_TYPE" = "x$DEFAULT_TOOLCHAIN"; then
 301     AC_MSG_NOTICE([Using default toolchain $TOOLCHAIN_TYPE ($TOOLCHAIN_DESCRIPTION)])
 302   else
 303     AC_MSG_NOTICE([Using user selected toolchain $TOOLCHAIN_TYPE ($TOOLCHAIN_DESCRIPTION). Default toolchain is $DEFAULT_TOOLCHAIN.])
 304   fi
 305 ])
 306 
 307 # Before we start detecting the toolchain executables, we might need some
 308 # special setup, e.g. additional paths etc.
 309 AC_DEFUN_ONCE([TOOLCHAIN_PRE_DETECTION],
 310 [
 311   # Store the CFLAGS etc passed to the configure script.
 312   ORG_CFLAGS="$CFLAGS"
 313   ORG_CXXFLAGS="$CXXFLAGS"
 314 
 315   # autoconf magic only relies on PATH, so update it if tools dir is specified
 316   OLD_PATH="$PATH"
 317 
 318   if test "x$OPENJDK_BUILD_OS" = "xmacosx"; then
 319     if test "x$XCODEBUILD" != x; then
 320       XCODE_VERSION_OUTPUT=`"$XCODEBUILD" -version 2> /dev/null | $HEAD -n 1`
 321       $ECHO "$XCODE_VERSION_OUTPUT" | $GREP "^Xcode " > /dev/null
 322       if test $? -ne 0; then
 323         AC_MSG_NOTICE([xcodebuild -version output: $XCODE_VERSION_OUTPUT])
 324         AC_MSG_ERROR([Failed to determine Xcode version])
 325       fi
 326 
 327       # For Xcode, we set the Xcode version as TOOLCHAIN_VERSION
 328       TOOLCHAIN_VERSION=`$ECHO $XCODE_VERSION_OUTPUT | $CUT -f 2 -d ' '`
 329       TOOLCHAIN_DESCRIPTION="$TOOLCHAIN_DESCRIPTION from Xcode $TOOLCHAIN_VERSION"
 330     fi
 331   fi
 332   AC_SUBST(TOOLCHAIN_VERSION)
 333 
 334   # Finally prepend TOOLCHAIN_PATH to the PATH, to allow --with-tools-dir to
 335   # override all other locations.
 336   if test "x$TOOLCHAIN_PATH" != x; then
 337     export PATH=$TOOLCHAIN_PATH:$PATH
 338   fi
 339 ])
 340 
 341 # Restore path, etc
 342 AC_DEFUN_ONCE([TOOLCHAIN_POST_DETECTION],
 343 [
 344   # Restore old path, except for the microsoft toolchain, which requires the
 345   # toolchain path to remain in place. Otherwise the compiler will not work in
 346   # some siutations in later configure checks.
 347   if test "x$TOOLCHAIN_TYPE" != "xmicrosoft"; then
 348     PATH="$OLD_PATH"
 349   fi
 350 
 351   # Restore the flags to the user specified values.
 352   # This is necessary since AC_PROG_CC defaults CFLAGS to "-g -O2"
 353   CFLAGS="$ORG_CFLAGS"
 354   CXXFLAGS="$ORG_CXXFLAGS"
 355 ])
 356 
 357 # Check if a compiler is of the toolchain type we expect, and save the version
 358 # information from it. If the compiler does not match the expected type,
 359 # this function will abort using AC_MSG_ERROR. If it matches, the version will
 360 # be stored in CC_VERSION_NUMBER/CXX_VERSION_NUMBER (as a dotted number), and
 361 # the full version string in CC_VERSION_STRING/CXX_VERSION_STRING.
 362 #
 363 # $1 = compiler to test (CC or CXX)
 364 # $2 = human readable name of compiler (C or C++)
 365 AC_DEFUN([TOOLCHAIN_EXTRACT_COMPILER_VERSION],
 366 [
 367   COMPILER=[$]$1
 368   COMPILER_NAME=$2
 369 
 370   if test  "x$TOOLCHAIN_TYPE" = xxlc; then
 371     # xlc -qversion output typically looks like
 372     #     IBM XL C/C++ for AIX, V11.1 (5724-X13)
 373     #     Version: 11.01.0000.0015
 374     COMPILER_VERSION_OUTPUT=`$COMPILER -qversion 2>&1`
 375     # Check that this is likely to be the IBM XL C compiler.
 376     $ECHO "$COMPILER_VERSION_OUTPUT" | $GREP "IBM XL C" > /dev/null
 377     if test $? -ne 0; then
 378       ALT_VERSION_OUTPUT=`$COMPILER --version 2>&1`
 379       AC_MSG_NOTICE([The $COMPILER_NAME compiler (located as $COMPILER) does not seem to be the required $TOOLCHAIN_TYPE compiler.])
 380       AC_MSG_NOTICE([The result from running with -qversion was: "$COMPILER_VERSION_OUTPUT"])
 381       AC_MSG_NOTICE([The result from running with --version was: "$ALT_VERSION_OUTPUT"])
 382       AC_MSG_ERROR([A $TOOLCHAIN_TYPE compiler is required. Try setting --with-tools-dir.])
 383     fi
 384     # Collapse compiler output into a single line
 385     COMPILER_VERSION_STRING=`$ECHO $COMPILER_VERSION_OUTPUT`
 386     COMPILER_VERSION_NUMBER=`$ECHO $COMPILER_VERSION_OUTPUT | \
 387         $SED -e 's/^.*, V\(@<:@1-9@:>@@<:@0-9.@:>@*\).*$/\1/'`
 388   elif test  "x$TOOLCHAIN_TYPE" = xmicrosoft; then
 389     # There is no specific version flag, but all output starts with a version string.
 390     # First line typically looks something like:
 391     # Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 16.00.40219.01 for 80x86
 392     # but the compiler name may vary depending on locale.
 393     COMPILER_VERSION_OUTPUT=`$COMPILER 2>&1 1>/dev/null | $HEAD -n 1 | $TR -d '\r'`
 394     # Check that this is likely to be Microsoft CL.EXE.
 395     $ECHO "$COMPILER_VERSION_OUTPUT" | $GREP "Microsoft" > /dev/null
 396     if test $? -ne 0; then
 397       AC_MSG_NOTICE([The $COMPILER_NAME compiler (located as $COMPILER) does not seem to be the required $TOOLCHAIN_TYPE compiler.])
 398       AC_MSG_NOTICE([The result from running it was: "$COMPILER_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/^.*ersion.\(@<:@1-9@:>@@<:@0-9.@:>@*\) .*$/\1/'`
 405   elif test  "x$TOOLCHAIN_TYPE" = xgcc; then
 406     # gcc --version output typically looks like
 407     #     gcc (Ubuntu/Linaro 4.8.1-10ubuntu9) 4.8.1
 408     #     Copyright (C) 2013 Free Software Foundation, Inc.
 409     #     This is free software; see the source for copying conditions.  There is NO
 410     #     warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 411     COMPILER_VERSION_OUTPUT=`$COMPILER --version 2>&1`
 412     # Check that this is likely to be GCC.
 413     $ECHO "$COMPILER_VERSION_OUTPUT" | $GREP "Free Software Foundation" > /dev/null
 414     if test $? -ne 0; then
 415       AC_MSG_NOTICE([The $COMPILER_NAME compiler (located as $COMPILER) does not seem to be the required $TOOLCHAIN_TYPE compiler.])
 416       AC_MSG_NOTICE([The result from running with --version was: "$COMPILER_VERSION"])
 417       AC_MSG_ERROR([A $TOOLCHAIN_TYPE compiler is required. Try setting --with-tools-dir.])
 418     fi
 419     # Remove Copyright and legalese from version string, and
 420     # collapse into a single line
 421     COMPILER_VERSION_STRING=`$ECHO $COMPILER_VERSION_OUTPUT | \
 422         $SED -e 's/ *Copyright .*//'`
 423     COMPILER_VERSION_NUMBER=`$ECHO $COMPILER_VERSION_OUTPUT | \
 424         $SED -e 's/^.* \(@<:@1-9@:>@<:@0-9@:>@*\.@<:@0-9.@:>@*\)@<:@^0-9.@:>@.*$/\1/'`
 425   elif test  "x$TOOLCHAIN_TYPE" = xclang; then
 426     # clang --version output typically looks like
 427     #    Apple LLVM version 5.0 (clang-500.2.79) (based on LLVM 3.3svn)
 428     #    clang version 3.3 (tags/RELEASE_33/final)
 429     # or
 430     #    Debian clang version 3.2-7ubuntu1 (tags/RELEASE_32/final) (based on LLVM 3.2)
 431     #    Target: x86_64-pc-linux-gnu
 432     #    Thread model: posix
 433     COMPILER_VERSION_OUTPUT=`$COMPILER --version 2>&1`
 434     # Check that this is likely to be clang
 435     $ECHO "$COMPILER_VERSION_OUTPUT" | $GREP "clang" > /dev/null
 436     if test $? -ne 0; then
 437       AC_MSG_NOTICE([The $COMPILER_NAME compiler (located as $COMPILER) does not seem to be the required $TOOLCHAIN_TYPE compiler.])
 438       AC_MSG_NOTICE([The result from running with --version was: "$COMPILER_VERSION_OUTPUT"])
 439       AC_MSG_ERROR([A $TOOLCHAIN_TYPE compiler is required. Try setting --with-tools-dir.])
 440     fi
 441     # Collapse compiler output into a single line
 442     COMPILER_VERSION_STRING=`$ECHO $COMPILER_VERSION_OUTPUT`
 443     COMPILER_VERSION_NUMBER=`$ECHO $COMPILER_VERSION_OUTPUT | \
 444         $SED -e 's/^.* version \(@<:@1-9@:>@@<:@0-9.@:>@*\).*$/\1/'`
 445   else
 446       AC_MSG_ERROR([Unknown toolchain type $TOOLCHAIN_TYPE.])
 447   fi
 448   # This sets CC_VERSION_NUMBER or CXX_VERSION_NUMBER. (This comment is a grep marker)
 449   $1_VERSION_NUMBER="$COMPILER_VERSION_NUMBER"
 450   # This sets CC_VERSION_STRING or CXX_VERSION_STRING. (This comment is a grep marker)
 451   $1_VERSION_STRING="$COMPILER_VERSION_STRING"
 452 
 453   AC_MSG_NOTICE([Using $TOOLCHAIN_TYPE $COMPILER_NAME compiler version $COMPILER_VERSION_NUMBER @<:@$COMPILER_VERSION_STRING@:>@])
 454 ])
 455 
 456 # Try to locate the given C or C++ compiler in the path, or otherwise.
 457 #
 458 # $1 = compiler to test (CC or CXX)
 459 # $2 = human readable name of compiler (C or C++)
 460 # $3 = compiler name to search for
 461 AC_DEFUN([TOOLCHAIN_FIND_COMPILER],
 462 [
 463   COMPILER_NAME=$2
 464   SEARCH_LIST="$3"
 465 
 466   if test "x[$]$1" != x; then
 467     # User has supplied compiler name already, always let that override.
 468     AC_MSG_NOTICE([Will use user supplied compiler $1=[$]$1])
 469     if test "x`basename [$]$1`" = "x[$]$1"; then
 470       # A command without a complete path is provided, search $PATH.
 471 
 472       UTIL_LOOKUP_PROGS(POTENTIAL_$1, [$]$1)
 473       if test "x$POTENTIAL_$1" != x; then
 474         $1=$POTENTIAL_$1
 475       else
 476         AC_MSG_ERROR([User supplied compiler $1=[$]$1 could not be found])
 477       fi
 478     else
 479       # Otherwise it might already be a complete path
 480       if test ! -x "[$]$1"; then
 481         AC_MSG_ERROR([User supplied compiler $1=[$]$1 does not exist])
 482       fi
 483     fi
 484   else
 485     # No user supplied value. Locate compiler ourselves.
 486 
 487     # If we are cross compiling, assume cross compilation tools follows the
 488     # cross compilation standard where they are prefixed with the autoconf
 489     # standard name for the target. For example the binary
 490     # i686-sun-solaris2.10-gcc will cross compile for i686-sun-solaris2.10.
 491     # If we are not cross compiling, then the default compiler name will be
 492     # used.
 493 
 494     UTIL_LOOKUP_TOOLCHAIN_PROGS(POTENTIAL_$1, $SEARCH_LIST)
 495     if test "x$POTENTIAL_$1" != x; then
 496       $1=$POTENTIAL_$1
 497     else
 498       HELP_MSG_MISSING_DEPENDENCY([devkit])
 499       AC_MSG_ERROR([Could not find a $COMPILER_NAME compiler. $HELP_MSG])
 500     fi
 501   fi
 502 
 503   # Now we have a compiler binary in $1. Make sure it's okay.
 504   TEST_COMPILER="[$]$1"
 505 
 506   AC_MSG_CHECKING([resolved symbolic links for $1])
 507   SYMLINK_ORIGINAL="$TEST_COMPILER"
 508   UTIL_REMOVE_SYMBOLIC_LINKS(SYMLINK_ORIGINAL)
 509   if test "x$TEST_COMPILER" = "x$SYMLINK_ORIGINAL"; then
 510     AC_MSG_RESULT([no symlink])
 511   else
 512     AC_MSG_RESULT([$SYMLINK_ORIGINAL])
 513 
 514     # We can't handle ccache by gcc wrappers, since we need to know if we're
 515     # using ccache. Instead ccache usage must be controlled by a configure option.
 516     COMPILER_BASENAME=`$BASENAME "$SYMLINK_ORIGINAL"`
 517     if test "x$COMPILER_BASENAME" = "xccache"; then
 518       AC_MSG_NOTICE([Please use --enable-ccache instead of providing a wrapped compiler.])
 519       AC_MSG_ERROR([$TEST_COMPILER is a symbolic link to ccache. This is not supported.])
 520     fi
 521   fi
 522 
 523   TOOLCHAIN_EXTRACT_COMPILER_VERSION([$1], [$COMPILER_NAME])
 524 ])
 525 
 526 # Retrieve the linker version number and store it in LD_VERSION_NUMBER
 527 # (as a dotted number), and
 528 # the full version string in LD_VERSION_STRING.
 529 #
 530 # $1 = linker to test (LD or BUILD_LD)
 531 # $2 = human readable name of linker (Linker or BuildLinker)
 532 AC_DEFUN([TOOLCHAIN_EXTRACT_LD_VERSION],
 533 [
 534   LINKER=[$]$1
 535   LINKER_NAME="$2"
 536 
 537   if test  "x$TOOLCHAIN_TYPE" = xxlc; then
 538     LINKER_VERSION_STRING="Unknown"
 539     LINKER_VERSION_NUMBER="0.0"
 540   elif test  "x$TOOLCHAIN_TYPE" = xmicrosoft; then
 541     # There is no specific version flag, but all output starts with a version string.
 542     # First line typically looks something like:
 543     #   Microsoft (R) Incremental Linker Version 12.00.31101.0
 544     LINKER_VERSION_STRING=`$LINKER 2>&1 | $HEAD -n 1 | $TR -d '\r'`
 545     # Extract version number
 546     [ LINKER_VERSION_NUMBER=`$ECHO $LINKER_VERSION_STRING | \
 547         $SED -e 's/.* \([0-9][0-9]*\(\.[0-9][0-9]*\)*\).*/\1/'` ]
 548   elif test  "x$TOOLCHAIN_TYPE" = xgcc; then
 549     # gcc -Wl,-version output typically looks like:
 550     #   GNU ld (GNU Binutils for Ubuntu) 2.26.1
 551     #   Copyright (C) 2015 Free Software Foundation, Inc.
 552     #   This program is free software; [...]
 553     # If using gold it will look like:
 554     #   GNU gold (GNU Binutils 2.30) 1.15
 555     LINKER_VERSION_STRING=`$LINKER -Wl,--version 2> /dev/null | $HEAD -n 1`
 556     # Extract version number
 557     if [ [[ "$LINKER_VERSION_STRING" == *gold* ]] ]; then
 558       [ LINKER_VERSION_NUMBER=`$ECHO $LINKER_VERSION_STRING | \
 559           $SED -e 's/.* \([0-9][0-9]*\(\.[0-9][0-9]*\)*\).*) .*/\1/'` ]
 560     else
 561       [ LINKER_VERSION_NUMBER=`$ECHO $LINKER_VERSION_STRING | \
 562           $SED -e 's/.* \([0-9][0-9]*\(\.[0-9][0-9]*\)*\).*/\1/'` ]
 563     fi
 564   elif test  "x$TOOLCHAIN_TYPE" = xclang; then
 565     # clang -Wl,-v output typically looks like
 566     #   @(#)PROGRAM:ld  PROJECT:ld64-305
 567     #   configured to support archs: armv6 armv7 armv7s arm64 i386 x86_64 x86_64h armv6m armv7k armv7m armv7em (tvOS)
 568     #   Library search paths: [...]
 569     # or
 570     #   GNU ld (GNU Binutils for Ubuntu) 2.26.1
 571 
 572     LINKER_VERSION_STRING=`$LINKER -Wl,-v 2>&1 | $HEAD -n 1`
 573     # Check if we're using the GNU ld
 574     $ECHO "$LINKER_VERSION_STRING" | $GREP "GNU" > /dev/null
 575     if test $? -eq 0; then
 576       # Extract version number
 577       [ LINKER_VERSION_NUMBER=`$ECHO $LINKER_VERSION_STRING | \
 578           $SED -e 's/.* \([0-9][0-9]*\(\.[0-9][0-9]*\)*\).*/\1/'` ]
 579     else
 580       # Extract version number
 581       [ LINKER_VERSION_NUMBER=`$ECHO $LINKER_VERSION_STRING | \
 582           $SED -e 's/.*-\([0-9][0-9]*\)/\1/'` ]
 583     fi
 584   fi
 585 
 586   $1_VERSION_NUMBER="$LINKER_VERSION_NUMBER"
 587   $1_VERSION_STRING="$LINKER_VERSION_STRING"
 588 
 589   AC_MSG_NOTICE([Using $TOOLCHAIN_TYPE $LINKER_NAME version $LINKER_VERSION_NUMBER @<:@$LINKER_VERSION_STRING@:>@])
 590 ])
 591 
 592 # Make sure we did not pick up /usr/bin/link, which is the unix-style link
 593 # executable.
 594 #
 595 # $1 = linker to test (LD or BUILD_LD)
 596 AC_DEFUN(TOOLCHAIN_VERIFY_LINK_BINARY,
 597 [
 598   LINKER=[$]$1
 599 
 600   AC_MSG_CHECKING([if the found link.exe is actually the Visual Studio linker])
 601   $LINKER --version > /dev/null
 602   if test $? -eq 0 ; then
 603     AC_MSG_RESULT([no])
 604     AC_MSG_ERROR([$LINKER is the winenv link tool. Please check your PATH and rerun configure.])
 605   else
 606     AC_MSG_RESULT([yes])
 607   fi
 608 ])
 609 # Detect the core components of the toolchain, i.e. the compilers (CC and CXX),
 610 # preprocessor (CPP and CXXCPP), the linker (LD), the assembler (AS) and the
 611 # archiver (AR). Verify that the compilers are correct according to the
 612 # toolchain type.
 613 AC_DEFUN_ONCE([TOOLCHAIN_DETECT_TOOLCHAIN_CORE],
 614 [
 615   #
 616   # Setup the compilers (CC and CXX)
 617   #
 618   TOOLCHAIN_FIND_COMPILER([CC], [C], $TOOLCHAIN_CC_BINARY)
 619   # Now that we have resolved CC ourself, let autoconf have its go at it
 620   AC_PROG_CC([$CC])
 621 
 622   TOOLCHAIN_FIND_COMPILER([CXX], [C++], $TOOLCHAIN_CXX_BINARY)
 623   # Now that we have resolved CXX ourself, let autoconf have its go at it
 624   AC_PROG_CXX([$CXX])
 625 
 626   # This is the compiler version number on the form X.Y[.Z]
 627   AC_SUBST(CC_VERSION_NUMBER)
 628   AC_SUBST(CXX_VERSION_NUMBER)
 629 
 630   TOOLCHAIN_PREPARE_FOR_VERSION_COMPARISONS
 631 
 632   if test "x$TOOLCHAIN_MINIMUM_VERSION" != x; then
 633     TOOLCHAIN_CHECK_COMPILER_VERSION(VERSION: $TOOLCHAIN_MINIMUM_VERSION,
 634         IF_OLDER_THAN: [
 635           AC_MSG_WARN([You are using $TOOLCHAIN_TYPE older than $TOOLCHAIN_MINIMUM_VERSION. This is not a supported configuration.])
 636         ]
 637     )
 638   fi
 639 
 640   #
 641   # Setup the preprocessor (CPP and CXXCPP)
 642   #
 643   AC_PROG_CPP
 644   UTIL_FIXUP_EXECUTABLE(CPP)
 645   AC_PROG_CXXCPP
 646   UTIL_FIXUP_EXECUTABLE(CXXCPP)
 647 
 648   #
 649   # Setup the linker (LD)
 650   #
 651   if test "x$TOOLCHAIN_TYPE" = xmicrosoft; then
 652     # In the Microsoft toolchain we have a separate LD command "link".
 653     UTIL_LOOKUP_TOOLCHAIN_PROGS(LD, link)
 654     TOOLCHAIN_VERIFY_LINK_BINARY(LD)
 655     LDCXX="$LD"
 656   else
 657     # All other toolchains use the compiler to link.
 658     LD="$CC"
 659     LDCXX="$CXX"
 660   fi
 661   AC_SUBST(LD)
 662   # FIXME: it should be CXXLD, according to standard (cf CXXCPP)
 663   AC_SUBST(LDCXX)
 664 
 665   TOOLCHAIN_EXTRACT_LD_VERSION([LD], [linker])
 666   TOOLCHAIN_PREPARE_FOR_LD_VERSION_COMPARISONS
 667 
 668   if test "x$TOOLCHAIN_MINIMUM_LD_VERSION" != x; then
 669     AC_MSG_NOTICE([comparing linker version to minimum version $TOOLCHAIN_MINIMUM_LD_VERSION])
 670     TOOLCHAIN_CHECK_LINKER_VERSION(VERSION: $TOOLCHAIN_MINIMUM_LD_VERSION,
 671         IF_OLDER_THAN: [
 672           AC_MSG_ERROR([You are using a linker older than $TOOLCHAIN_MINIMUM_LD_VERSION. This is not a supported configuration.])
 673         ]
 674     )
 675   fi
 676 
 677   #
 678   # Setup the assembler (AS)
 679   #
 680   if test "x$TOOLCHAIN_TYPE" != xmicrosoft; then
 681     AS="$CC -c"
 682   else
 683     if test "x$OPENJDK_TARGET_CPU_BITS" = "x64"; then
 684       # On 64 bit windows, the assembler is "ml64.exe"
 685       UTIL_LOOKUP_TOOLCHAIN_PROGS(AS, ml64)
 686     else
 687       # otherwise, the assembler is "ml.exe"
 688       UTIL_LOOKUP_TOOLCHAIN_PROGS(AS, ml)
 689     fi
 690   fi
 691   AC_SUBST(AS)
 692 
 693   #
 694   # Setup the archiver (AR)
 695   #
 696   if test "x$TOOLCHAIN_TYPE" = xmicrosoft; then
 697     # The corresponding ar tool is lib.exe (used to create static libraries)
 698     UTIL_LOOKUP_TOOLCHAIN_PROGS(AR, lib)
 699   elif test "x$TOOLCHAIN_TYPE" = xgcc; then
 700     UTIL_LOOKUP_TOOLCHAIN_PROGS(AR, ar gcc-ar)
 701   else
 702     UTIL_LOOKUP_TOOLCHAIN_PROGS(AR, ar)
 703   fi
 704 ])
 705 
 706 # Setup additional tools that is considered a part of the toolchain, but not the
 707 # core part. Many of these are highly platform-specific and do not exist,
 708 # and/or are not needed on all platforms.
 709 AC_DEFUN_ONCE([TOOLCHAIN_DETECT_TOOLCHAIN_EXTRA],
 710 [
 711   if test "x$OPENJDK_TARGET_OS" = "xmacosx"; then
 712     UTIL_LOOKUP_PROGS(LIPO, lipo)
 713     UTIL_REQUIRE_PROGS(OTOOL, otool)
 714     UTIL_REQUIRE_PROGS(INSTALL_NAME_TOOL, install_name_tool)
 715 
 716     UTIL_LOOKUP_TOOLCHAIN_PROGS(METAL, metal)
 717     if test "x$METAL" = x; then
 718       AC_MSG_CHECKING([if metal can be run using xcrun])
 719       METAL="xcrun -sdk macosx metal"
 720       test_metal=`$METAL --version 2>&1`
 721       if test $? -ne 0; then
 722         AC_MSG_RESULT([no])
 723         AC_MSG_ERROR([XCode tool 'metal' neither found in path nor with xcrun])
 724       else
 725         AC_MSG_RESULT([yes, will be using '$METAL'])
 726       fi
 727     fi
 728 
 729     UTIL_LOOKUP_TOOLCHAIN_PROGS(METALLIB, metallib)
 730     if test "x$METALLIB" = x; then
 731       AC_MSG_CHECKING([if metallib can be run using xcrun])
 732       METALLIB="xcrun -sdk macosx metallib"
 733       test_metallib=`$METALLIB --version 2>&1`
 734       if test $? -ne 0; then
 735         AC_MSG_RESULT([no])
 736         AC_MSG_ERROR([XCode tool 'metallib' neither found in path nor with xcrun])
 737       else
 738         AC_MSG_RESULT([yes, will be using '$METALLIB'])
 739       fi
 740     fi
 741   fi
 742 
 743   if test "x$TOOLCHAIN_TYPE" = xmicrosoft; then
 744     # Setup the manifest tool (MT)
 745     UTIL_LOOKUP_TOOLCHAIN_PROGS(MT, mt)
 746     # Setup the resource compiler (RC)
 747     UTIL_LOOKUP_TOOLCHAIN_PROGS(RC, rc)
 748     UTIL_LOOKUP_TOOLCHAIN_PROGS(DUMPBIN, dumpbin)
 749   fi
 750 
 751   if test "x$OPENJDK_TARGET_OS" != xwindows; then
 752     UTIL_LOOKUP_TOOLCHAIN_PROGS(STRIP, strip)
 753     if test "x$TOOLCHAIN_TYPE" = xgcc; then
 754       UTIL_LOOKUP_TOOLCHAIN_PROGS(NM, nm gcc-nm)
 755     else
 756       UTIL_LOOKUP_TOOLCHAIN_PROGS(NM, nm)
 757     fi
 758   fi
 759 
 760   # objcopy is used for moving debug symbols to separate files when
 761   # full debug symbols are enabled.
 762   if test "x$OPENJDK_TARGET_OS" = xlinux; then
 763     UTIL_LOOKUP_TOOLCHAIN_PROGS(OBJCOPY, gobjcopy objcopy)
 764   fi
 765 
 766   UTIL_LOOKUP_TOOLCHAIN_PROGS(OBJDUMP, gobjdump objdump)
 767 
 768   case $TOOLCHAIN_TYPE in
 769     gcc|clang)
 770       UTIL_REQUIRE_TOOLCHAIN_PROGS(CXXFILT, c++filt)
 771       ;;
 772   esac
 773 ])
 774 
 775 # Setup the build tools (i.e, the compiler and linker used to build programs
 776 # that should be run on the build platform, not the target platform, as a build
 777 # helper). Since the non-cross-compile case uses the normal, target compilers
 778 # for this, we can only do this after these have been setup.
 779 AC_DEFUN_ONCE([TOOLCHAIN_SETUP_BUILD_COMPILERS],
 780 [
 781   if test "x$COMPILE_TYPE" = "xcross"; then
 782     # Now we need to find a C/C++ compiler that can build executables for the
 783     # build platform. We can't use the AC_PROG_CC macro, since it can only be
 784     # used once. Also, we need to do this without adding a tools dir to the
 785     # path, otherwise we might pick up cross-compilers which don't use standard
 786     # naming.
 787 
 788     OLDPATH="$PATH"
 789 
 790     AC_ARG_WITH(build-devkit, [AS_HELP_STRING([--with-build-devkit],
 791         [Devkit to use for the build platform toolchain])])
 792     if test "x$with_build_devkit" = "xyes"; then
 793       AC_MSG_ERROR([--with-build-devkit must have a value])
 794     elif test -n "$with_build_devkit"; then
 795       if test ! -d "$with_build_devkit"; then
 796         AC_MSG_ERROR([--with-build-devkit points to non existing dir: $with_build_devkit])
 797       else
 798         UTIL_FIXUP_PATH([with_build_devkit])
 799         BUILD_DEVKIT_ROOT="$with_build_devkit"
 800         # Check for a meta data info file in the root of the devkit
 801         if test -f "$BUILD_DEVKIT_ROOT/devkit.info"; then
 802           # Process devkit.info so that existing devkit variables are not
 803           # modified by this
 804           $SED -e "s/^DEVKIT_/BUILD_DEVKIT_/g" \
 805               -e "s/\$DEVKIT_ROOT/\$BUILD_DEVKIT_ROOT/g" \
 806               -e "s/\$host/\$build/g" \
 807               $BUILD_DEVKIT_ROOT/devkit.info \
 808               > $CONFIGURESUPPORT_OUTPUTDIR/build-devkit.info
 809           . $CONFIGURESUPPORT_OUTPUTDIR/build-devkit.info
 810           # This potentially sets the following:
 811           # A descriptive name of the devkit
 812           BASIC_EVAL_BUILD_DEVKIT_VARIABLE([BUILD_DEVKIT_NAME])
 813           # Corresponds to --with-extra-path
 814           BASIC_EVAL_BUILD_DEVKIT_VARIABLE([BUILD_DEVKIT_EXTRA_PATH])
 815           # Corresponds to --with-toolchain-path
 816           BASIC_EVAL_BUILD_DEVKIT_VARIABLE([BUILD_DEVKIT_TOOLCHAIN_PATH])
 817           # Corresponds to --with-sysroot
 818           BASIC_EVAL_BUILD_DEVKIT_VARIABLE([BUILD_DEVKIT_SYSROOT])
 819 
 820           if test "x$TOOLCHAIN_TYPE" = xmicrosoft; then
 821             BASIC_EVAL_BUILD_DEVKIT_VARIABLE([BUILD_DEVKIT_VS_INCLUDE])
 822             BASIC_EVAL_BUILD_DEVKIT_VARIABLE([BUILD_DEVKIT_VS_LIB])
 823           fi
 824         fi
 825 
 826         AC_MSG_CHECKING([for build platform devkit])
 827         if test "x$BUILD_DEVKIT_NAME" != x; then
 828           AC_MSG_RESULT([$BUILD_DEVKIT_NAME in $BUILD_DEVKIT_ROOT])
 829         else
 830           AC_MSG_RESULT([$BUILD_DEVKIT_ROOT])
 831         fi
 832 
 833         # Fallback default of just /bin if DEVKIT_PATH is not defined
 834         if test "x$BUILD_DEVKIT_TOOLCHAIN_PATH" = x; then
 835           BUILD_DEVKIT_TOOLCHAIN_PATH="$BUILD_DEVKIT_ROOT/bin"
 836         fi
 837         PATH="$BUILD_DEVKIT_TOOLCHAIN_PATH:$BUILD_DEVKIT_EXTRA_PATH"
 838 
 839         BUILD_SYSROOT="$BUILD_DEVKIT_SYSROOT"
 840 
 841         if test "x$TOOLCHAIN_TYPE" = xmicrosoft; then
 842           # For historical reasons, paths are separated by ; in devkit.info
 843           BUILD_VS_INCLUDE="${BUILD_DEVKIT_VS_INCLUDE//;/:}"
 844           BUILD_VS_LIB="${BUILD_DEVKIT_VS_LIB//;/:}"
 845 
 846           TOOLCHAIN_SETUP_VISUAL_STUDIO_SYSROOT_FLAGS(BUILD_, BUILD_)
 847         fi
 848       fi
 849     else
 850       if test "x$TOOLCHAIN_TYPE" = xmicrosoft; then
 851         # If we got no devkit, we need to go hunting for the proper env
 852         TOOLCHAIN_FIND_VISUAL_STUDIO_BAT_FILE($OPENJDK_BUILD_CPU, [$TOOLCHAIN_VERSION])
 853         TOOLCHAIN_EXTRACT_VISUAL_STUDIO_ENV($OPENJDK_BUILD_CPU, BUILD_)
 854 
 855         # We cannot currently export the VS_PATH to spec.gmk. This is probably
 856         # strictly not correct, but seems to work anyway.
 857 
 858         # Convert VS_INCLUDE and VS_LIB into sysroot flags
 859         TOOLCHAIN_SETUP_VISUAL_STUDIO_SYSROOT_FLAGS(BUILD_)
 860       fi
 861     fi
 862 
 863     if test "x$TOOLCHAIN_TYPE" = xmicrosoft; then
 864       UTIL_REQUIRE_PROGS(BUILD_CC, cl, [$VS_PATH])
 865       UTIL_REQUIRE_PROGS(BUILD_CXX, cl, [$VS_PATH])
 866 
 867       # On windows, the assembler is "ml.exe". We currently don't need this so
 868       # do not require.
 869       if test "x$OPENJDK_BUILD_CPU_BITS" = "x64"; then
 870         # On 64 bit windows, the assembler is "ml64.exe"
 871         UTIL_LOOKUP_PROGS(BUILD_AS, ml64, [$VS_PATH])
 872       else
 873         # otherwise the assembler is "ml.exe"
 874         UTIL_LOOKUP_PROGS(BUILD_AS, ml, [$VS_PATH])
 875       fi
 876 
 877       # On windows, the ar tool is lib.exe (used to create static libraries).
 878       # We currently don't need this so do not require.
 879       UTIL_LOOKUP_PROGS(BUILD_AR, lib, [$VS_PATH])
 880 
 881       # In the Microsoft toolchain we have a separate LD command "link".
 882       UTIL_REQUIRE_PROGS(BUILD_LD, link, [$VS_PATH])
 883       TOOLCHAIN_VERIFY_LINK_BINARY(BUILD_LD)
 884       BUILD_LDCXX="$BUILD_LD"
 885     else
 886       if test "x$OPENJDK_BUILD_OS" = xmacosx; then
 887         UTIL_REQUIRE_PROGS(BUILD_CC, clang)
 888         UTIL_REQUIRE_PROGS(BUILD_CXX, clang++)
 889       else
 890         UTIL_REQUIRE_PROGS(BUILD_CC, cc gcc)
 891         UTIL_REQUIRE_PROGS(BUILD_CXX, CC g++)
 892       fi
 893       UTIL_LOOKUP_PROGS(BUILD_NM, nm gcc-nm)
 894       UTIL_LOOKUP_PROGS(BUILD_AR, ar gcc-ar lib)
 895       UTIL_LOOKUP_PROGS(BUILD_OBJCOPY, objcopy)
 896       UTIL_LOOKUP_PROGS(BUILD_STRIP, strip)
 897       # Assume the C compiler is the assembler
 898       BUILD_AS="$BUILD_CC -c"
 899       # Just like for the target compiler, use the compiler as linker
 900       BUILD_LD="$BUILD_CC"
 901       BUILD_LDCXX="$BUILD_CXX"
 902     fi
 903 
 904     PATH="$OLDPATH"
 905 
 906     TOOLCHAIN_EXTRACT_COMPILER_VERSION(BUILD_CC, [BuildC])
 907     TOOLCHAIN_EXTRACT_COMPILER_VERSION(BUILD_CXX, [BuildC++])
 908     TOOLCHAIN_PREPARE_FOR_VERSION_COMPARISONS([BUILD_], [OPENJDK_BUILD_], [build ])
 909     TOOLCHAIN_EXTRACT_LD_VERSION(BUILD_LD, [build linker])
 910     TOOLCHAIN_PREPARE_FOR_LD_VERSION_COMPARISONS([BUILD_], [OPENJDK_BUILD_])
 911   else
 912     # If we are not cross compiling, use the normal target compilers for
 913     # building the build platform executables.
 914     BUILD_CC="$CC"
 915     BUILD_CXX="$CXX"
 916     BUILD_LD="$LD"
 917     BUILD_LDCXX="$LDCXX"
 918     BUILD_NM="$NM"
 919     BUILD_AS="$AS"
 920     BUILD_OBJCOPY="$OBJCOPY"
 921     BUILD_STRIP="$STRIP"
 922     BUILD_AR="$AR"
 923 
 924     TOOLCHAIN_PREPARE_FOR_VERSION_COMPARISONS([], [OPENJDK_BUILD_], [build ])
 925     TOOLCHAIN_PREPARE_FOR_LD_VERSION_COMPARISONS([BUILD_], [OPENJDK_BUILD_])
 926   fi
 927 
 928   AC_SUBST(BUILD_CC)
 929   AC_SUBST(BUILD_CXX)
 930   AC_SUBST(BUILD_LD)
 931   AC_SUBST(BUILD_LDCXX)
 932   AC_SUBST(BUILD_NM)
 933   AC_SUBST(BUILD_AS)
 934   AC_SUBST(BUILD_AR)
 935 ])
 936 
 937 # Do some additional checks on the detected tools.
 938 AC_DEFUN_ONCE([TOOLCHAIN_MISC_CHECKS],
 939 [
 940   # Check for extra potential brokenness.
 941   if test  "x$TOOLCHAIN_TYPE" = xmicrosoft; then
 942     # On Windows, double-check that we got the right compiler.
 943     CC_VERSION_OUTPUT=`$CC 2>&1 1>/dev/null | $HEAD -n 1 | $TR -d '\r'`
 944     COMPILER_CPU_TEST=`$ECHO $CC_VERSION_OUTPUT | $SED -n "s/^.* \(.*\)$/\1/p"`
 945     if test "x$OPENJDK_TARGET_CPU" = "xx86"; then
 946       if test "x$COMPILER_CPU_TEST" != "x80x86" -a "x$COMPILER_CPU_TEST" != "xx86"; then
 947         AC_MSG_ERROR([Target CPU mismatch. We are building for $OPENJDK_TARGET_CPU but CL is for "$COMPILER_CPU_TEST"; expected "80x86" or "x86".])
 948       fi
 949     elif test "x$OPENJDK_TARGET_CPU" = "xx86_64"; then
 950       if test "x$COMPILER_CPU_TEST" != "xx64"; then
 951         AC_MSG_ERROR([Target CPU mismatch. We are building for $OPENJDK_TARGET_CPU but CL is for "$COMPILER_CPU_TEST"; expected "x64".])
 952       fi
 953     elif test "x$OPENJDK_TARGET_CPU" = "xaarch64"; then
 954       if test "x$COMPILER_CPU_TEST" != "xARM64"; then
 955         AC_MSG_ERROR([Target CPU mismatch. We are building for $OPENJDK_TARGET_CPU but CL is for "$COMPILER_CPU_TEST"; expected "arm64".])
 956       fi
 957     fi
 958   fi
 959 
 960   if test "x$TOOLCHAIN_TYPE" = xgcc || test "x$TOOLCHAIN_TYPE" = xclang; then
 961     # Check if linker has -z noexecstack.
 962     HAS_NOEXECSTACK=`$CC -Wl,--help 2>/dev/null | $GREP 'z noexecstack'`
 963     # This is later checked when setting flags.
 964   fi
 965 
 966   # Setup hotspot lecagy names for toolchains
 967   HOTSPOT_TOOLCHAIN_TYPE=$TOOLCHAIN_TYPE
 968   if test "x$TOOLCHAIN_TYPE" = xclang; then
 969     HOTSPOT_TOOLCHAIN_TYPE=gcc
 970   elif test "x$TOOLCHAIN_TYPE" = xmicrosoft; then
 971     HOTSPOT_TOOLCHAIN_TYPE=visCPP
 972   fi
 973   AC_SUBST(HOTSPOT_TOOLCHAIN_TYPE)
 974 ])
 975 
 976 # Setup the JTReg Regression Test Harness.
 977 AC_DEFUN_ONCE([TOOLCHAIN_SETUP_JTREG],
 978 [
 979   AC_ARG_WITH(jtreg, [AS_HELP_STRING([--with-jtreg],
 980       [Regression Test Harness @<:@probed@:>@])])
 981 
 982   if test "x$with_jtreg" = xno; then
 983     # jtreg disabled
 984     AC_MSG_CHECKING([for jtreg test harness])
 985     AC_MSG_RESULT([no, disabled])
 986   elif test "x$with_jtreg" != xyes && test "x$with_jtreg" != x; then
 987     if test -d "$with_jtreg"; then
 988       # An explicit path is specified, use it.
 989       JT_HOME="$with_jtreg"
 990     else
 991       case "$with_jtreg" in
 992         *.zip )
 993           JTREG_SUPPORT_DIR=$CONFIGURESUPPORT_OUTPUTDIR/jtreg
 994           $RM -rf $JTREG_SUPPORT_DIR
 995           $MKDIR -p $JTREG_SUPPORT_DIR
 996           $UNZIP -qq -d $JTREG_SUPPORT_DIR $with_jtreg
 997 
 998           # Try to find jtreg to determine JT_HOME path
 999           JTREG_PATH=`$FIND $JTREG_SUPPORT_DIR | $GREP "/bin/jtreg"`
1000           if test "x$JTREG_PATH" != x; then
1001             JT_HOME=$($DIRNAME $($DIRNAME $JTREG_PATH))
1002           fi
1003           ;;
1004         * )
1005           ;;
1006       esac
1007     fi
1008     UTIL_FIXUP_PATH([JT_HOME])
1009     if test ! -d "$JT_HOME"; then
1010       AC_MSG_ERROR([jtreg home directory from --with-jtreg=$with_jtreg does not exist])
1011     fi
1012 
1013     if test ! -e "$JT_HOME/lib/jtreg.jar"; then
1014       AC_MSG_ERROR([jtreg home directory from --with-jtreg=$with_jtreg is not a valid jtreg home])
1015     fi
1016 
1017     AC_MSG_CHECKING([for jtreg test harness])
1018     AC_MSG_RESULT([$JT_HOME])
1019   else
1020     # Try to locate jtreg using the JT_HOME environment variable
1021     if test "x$JT_HOME" != x; then
1022       # JT_HOME set in environment, use it
1023       if test ! -d "$JT_HOME"; then
1024         AC_MSG_WARN([Ignoring JT_HOME pointing to invalid directory: $JT_HOME])
1025         JT_HOME=
1026       else
1027         if test ! -e "$JT_HOME/lib/jtreg.jar"; then
1028           AC_MSG_WARN([Ignoring JT_HOME which is not a valid jtreg home: $JT_HOME])
1029           JT_HOME=
1030         else
1031           AC_MSG_NOTICE([Located jtreg using JT_HOME from environment])
1032         fi
1033       fi
1034     fi
1035 
1036     if test "x$JT_HOME" = x; then
1037       # JT_HOME is not set in environment, or was deemed invalid.
1038       # Try to find jtreg on path
1039       UTIL_LOOKUP_PROGS(JTREGEXE, jtreg)
1040       if test "x$JTREGEXE" != x; then
1041         # That's good, now try to derive JT_HOME
1042         JT_HOME=`(cd $($DIRNAME $JTREGEXE)/.. && pwd)`
1043         if test ! -e "$JT_HOME/lib/jtreg.jar"; then
1044           AC_MSG_WARN([Ignoring jtreg from path since a valid jtreg home cannot be found])
1045           JT_HOME=
1046         else
1047           AC_MSG_NOTICE([Located jtreg using jtreg executable in path])
1048         fi
1049       fi
1050     fi
1051 
1052     AC_MSG_CHECKING([for jtreg test harness])
1053     if test "x$JT_HOME" != x; then
1054       AC_MSG_RESULT([$JT_HOME])
1055     else
1056       AC_MSG_RESULT([no, not found])
1057 
1058       if test "x$with_jtreg" = xyes; then
1059         AC_MSG_ERROR([--with-jtreg was specified, but no jtreg found.])
1060       fi
1061     fi
1062   fi
1063 
1064   UTIL_FIXUP_PATH(JT_HOME)
1065   AC_SUBST(JT_HOME)
1066 ])
1067 
1068 # Setup the JIB dependency resolver
1069 AC_DEFUN_ONCE([TOOLCHAIN_SETUP_JIB],
1070 [
1071   AC_ARG_WITH(jib, [AS_HELP_STRING([--with-jib],
1072       [Jib dependency management tool @<:@not used@:>@])])
1073 
1074   if test "x$with_jib" = xno || test "x$with_jib" = x; then
1075     # jib disabled
1076     AC_MSG_CHECKING([for jib])
1077     AC_MSG_RESULT(no)
1078   elif test "x$with_jib" = xyes; then
1079     AC_MSG_ERROR([Must supply a value to --with-jib])
1080   else
1081     JIB_HOME="${with_jib}"
1082     AC_MSG_CHECKING([for jib])
1083     AC_MSG_RESULT(${JIB_HOME})
1084     if test ! -d "${JIB_HOME}"; then
1085       AC_MSG_ERROR([--with-jib must be a directory])
1086     fi
1087     JIB_JAR=$(ls ${JIB_HOME}/lib/jib-*.jar)
1088     if test ! -f "${JIB_JAR}"; then
1089       AC_MSG_ERROR([Could not find jib jar file in ${JIB_HOME}])
1090     fi
1091   fi
1092 
1093   AC_SUBST(JIB_HOME)
1094 ])