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