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     LINKER_VERSION_STRING=`$LD 2>&1 | $HEAD -n 1 | $TR -d '\r'`
 600     # Extract version number
 601     [ LINKER_VERSION_NUMBER=`$ECHO $LINKER_VERSION_STRING | \
 602         $SED -e 's/.* \([0-9][0-9]*\(\.[0-9][0-9]*\)*\).*/\1/'` ]
 603   elif test  "x$TOOLCHAIN_TYPE" = xgcc; then
 604     # gcc -Wl,-version output typically looks like:
 605     #   GNU ld (GNU Binutils for Ubuntu) 2.26.1
 606     #   Copyright (C) 2015 Free Software Foundation, Inc.
 607     #   This program is free software; [...]
 608     # If using gold it will look like:
 609     #   GNU gold (GNU Binutils 2.30) 1.15
 610     LINKER_VERSION_STRING=`$LD -Wl,--version 2> /dev/null | $HEAD -n 1`
 611     # Extract version number
 612     if [ [[ "$LINKER_VERSION_STRING" == *gold* ]] ]; then
 613       [ LINKER_VERSION_NUMBER=`$ECHO $LINKER_VERSION_STRING | \
 614           $SED -e 's/.* \([0-9][0-9]*\(\.[0-9][0-9]*\)*\).*) .*/\1/'` ]
 615     else
 616       [ LINKER_VERSION_NUMBER=`$ECHO $LINKER_VERSION_STRING | \
 617           $SED -e 's/.* \([0-9][0-9]*\(\.[0-9][0-9]*\)*\).*/\1/'` ]
 618     fi
 619   elif test  "x$TOOLCHAIN_TYPE" = xclang; then
 620     # clang -Wl,-v output typically looks like
 621     #   @(#)PROGRAM:ld  PROJECT:ld64-305
 622     #   configured to support archs: armv6 armv7 armv7s arm64 i386 x86_64 x86_64h armv6m armv7k armv7m armv7em (tvOS)
 623     #   Library search paths: [...]
 624     # or
 625     #   GNU ld (GNU Binutils for Ubuntu) 2.26.1
 626 
 627     LINKER_VERSION_STRING=`$LD -Wl,-v 2>&1 | $HEAD -n 1`
 628     # Check if we're using the GNU ld
 629     $ECHO "$LINKER_VERSION_STRING" | $GREP "GNU" > /dev/null
 630     if test $? -eq 0; then
 631       # Extract version number
 632       [ LINKER_VERSION_NUMBER=`$ECHO $LINKER_VERSION_STRING | \
 633           $SED -e 's/.* \([0-9][0-9]*\(\.[0-9][0-9]*\)*\).*/\1/'` ]
 634     else
 635       # Extract version number
 636       [ LINKER_VERSION_NUMBER=`$ECHO $LINKER_VERSION_STRING | \
 637           $SED -e 's/.*-\([0-9][0-9]*\)/\1/'` ]
 638     fi
 639   fi
 640 
 641   $1_VERSION_NUMBER="$LINKER_VERSION_NUMBER"
 642   $1_VERSION_STRING="$LINKER_VERSION_STRING"
 643 
 644   AC_MSG_NOTICE([Using $TOOLCHAIN_TYPE $LINKER_NAME version $LINKER_VERSION_NUMBER @<:@$LINKER_VERSION_STRING@:>@])
 645 ])
 646 
 647 # Detect the core components of the toolchain, i.e. the compilers (CC and CXX),
 648 # preprocessor (CPP and CXXCPP), the linker (LD), the assembler (AS) and the
 649 # archiver (AR). Verify that the compilers are correct according to the
 650 # toolchain type.
 651 AC_DEFUN_ONCE([TOOLCHAIN_DETECT_TOOLCHAIN_CORE],
 652 [
 653   #
 654   # Setup the compilers (CC and CXX)
 655   #
 656   TOOLCHAIN_FIND_COMPILER([CC], [C], $TOOLCHAIN_CC_BINARY)
 657   # Now that we have resolved CC ourself, let autoconf have its go at it
 658   AC_PROG_CC([$CC])
 659 
 660   TOOLCHAIN_FIND_COMPILER([CXX], [C++], $TOOLCHAIN_CXX_BINARY)
 661   # Now that we have resolved CXX ourself, let autoconf have its go at it
 662   AC_PROG_CXX([$CXX])
 663 
 664   # This is the compiler version number on the form X.Y[.Z]
 665   AC_SUBST(CC_VERSION_NUMBER)
 666   AC_SUBST(CXX_VERSION_NUMBER)
 667 
 668   TOOLCHAIN_PREPARE_FOR_VERSION_COMPARISONS
 669 
 670   if test "x$TOOLCHAIN_MINIMUM_VERSION" != x; then
 671     TOOLCHAIN_CHECK_COMPILER_VERSION(VERSION: $TOOLCHAIN_MINIMUM_VERSION,
 672         IF_OLDER_THAN: [
 673           AC_MSG_WARN([You are using $TOOLCHAIN_TYPE older than $TOOLCHAIN_MINIMUM_VERSION. This is not a supported configuration.])
 674         ]
 675     )
 676   fi
 677 
 678   #
 679   # Setup the preprocessor (CPP and CXXCPP)
 680   #
 681   AC_PROG_CPP
 682   UTIL_FIXUP_EXECUTABLE(CPP)
 683   AC_PROG_CXXCPP
 684   UTIL_FIXUP_EXECUTABLE(CXXCPP)
 685 
 686   #
 687   # Setup the linker (LD)
 688   #
 689   if test "x$TOOLCHAIN_TYPE" = xmicrosoft; then
 690     # In the Microsoft toolchain we have a separate LD command "link".
 691     # Make sure we reject /usr/bin/link (as determined in CYGWIN_LINK), which is
 692     # a cygwin program for something completely different.
 693     AC_CHECK_PROG([LD], [link$EXE_SUFFIX],[link$EXE_SUFFIX],,, [$CYGWIN_LINK])
 694     UTIL_FIXUP_EXECUTABLE(LD)
 695     # Verify that we indeed succeeded with this trick.
 696     AC_MSG_CHECKING([if the found link.exe is actually the Visual Studio linker])
 697     "$LD" --version > /dev/null
 698     if test $? -eq 0 ; then
 699       AC_MSG_RESULT([no])
 700       AC_MSG_ERROR([This is the Cygwin link tool. Please check your PATH and rerun configure.])
 701     else
 702       AC_MSG_RESULT([yes])
 703     fi
 704     LDCXX="$LD"
 705     # jaotc being a windows program expects the linker to be supplied with exe suffix.
 706     LD_JAOTC="$LD$EXE_SUFFIX"
 707   else
 708     # All other toolchains use the compiler to link.
 709     LD="$CC"
 710     LDCXX="$CXX"
 711     # jaotc expects 'ld' as the linker rather than the compiler.
 712     UTIL_CHECK_TOOLS([LD_JAOTC], ld)
 713     UTIL_FIXUP_EXECUTABLE(LD_JAOTC)
 714   fi
 715   AC_SUBST(LD)
 716   AC_SUBST(LD_JAOTC)
 717   # FIXME: it should be CXXLD, according to standard (cf CXXCPP)
 718   AC_SUBST(LDCXX)
 719 
 720   TOOLCHAIN_EXTRACT_LD_VERSION([LD], [linker])
 721   TOOLCHAIN_PREPARE_FOR_LD_VERSION_COMPARISONS
 722 
 723   if test "x$TOOLCHAIN_MINIMUM_LD_VERSION" != x; then
 724     TOOLCHAIN_CHECK_LINKER_VERSION(VERSION: $TOOLCHAIN_MINIMUM_LD_VERSION,
 725         IF_OLDER_THAN: [
 726           AC_MSG_WARN([You are using a linker older than $TOOLCHAIN_MINIMUM_LD_VERSION. This is not a supported configuration.])
 727         ]
 728     )
 729   fi
 730 
 731   #
 732   # Setup the assembler (AS)
 733   #
 734   # FIXME: is this correct for microsoft?
 735   AS="$CC -c"
 736   AC_SUBST(AS)
 737 
 738   #
 739   # Setup the archiver (AR)
 740   #
 741   if test "x$TOOLCHAIN_TYPE" = xmicrosoft; then
 742     # The corresponding ar tool is lib.exe (used to create static libraries)
 743     AC_CHECK_PROG([AR], [lib$EXE_SUFFIX],[lib$EXE_SUFFIX],,,)
 744   elif test "x$TOOLCHAIN_TYPE" = xgcc; then
 745     UTIL_CHECK_TOOLS(AR, ar gcc-ar)
 746   else
 747     UTIL_CHECK_TOOLS(AR, ar)
 748   fi
 749   UTIL_FIXUP_EXECUTABLE(AR)
 750 ])
 751 
 752 # Setup additional tools that is considered a part of the toolchain, but not the
 753 # core part. Many of these are highly platform-specific and do not exist,
 754 # and/or are not needed on all platforms.
 755 AC_DEFUN_ONCE([TOOLCHAIN_DETECT_TOOLCHAIN_EXTRA],
 756 [
 757   if test "x$OPENJDK_TARGET_OS" = "xmacosx"; then
 758     UTIL_PATH_PROGS(LIPO, lipo)
 759     UTIL_FIXUP_EXECUTABLE(LIPO)
 760     UTIL_REQUIRE_PROGS(OTOOL, otool)
 761     UTIL_FIXUP_EXECUTABLE(OTOOL)
 762     UTIL_REQUIRE_PROGS(INSTALL_NAME_TOOL, install_name_tool)
 763     UTIL_FIXUP_EXECUTABLE(INSTALL_NAME_TOOL)
 764   fi
 765 
 766   if test "x$TOOLCHAIN_TYPE" = xmicrosoft; then
 767     AC_CHECK_PROG([MT], [mt$EXE_SUFFIX], [mt$EXE_SUFFIX],,, [/usr/bin/mt])
 768     UTIL_FIXUP_EXECUTABLE(MT)
 769     # Setup the resource compiler (RC)
 770     AC_CHECK_PROG([RC], [rc$EXE_SUFFIX], [rc$EXE_SUFFIX],,, [/usr/bin/rc])
 771     UTIL_FIXUP_EXECUTABLE(RC)
 772     AC_CHECK_PROG([DUMPBIN], [dumpbin$EXE_SUFFIX], [dumpbin$EXE_SUFFIX],,,)
 773     UTIL_FIXUP_EXECUTABLE(DUMPBIN)
 774     # We need to check for 'msbuild.exe' because at the place where we expect to
 775     # find 'msbuild.exe' there's also a directory called 'msbuild' and configure
 776     # won't find the 'msbuild.exe' executable in that case (and the
 777     # 'ac_executable_extensions' is unusable due to performance reasons).
 778     # Notice that we intentionally don't fix up the path to MSBUILD because we
 779     # will call it in a DOS shell during freetype detection on Windows (see
 780     # 'LIB_SETUP_FREETYPE' in "libraries.m4"
 781     AC_CHECK_PROG([MSBUILD], [msbuild$EXE_SUFFIX], [msbuild$EXE_SUFFIX],,,)
 782   fi
 783 
 784   if test "x$OPENJDK_TARGET_OS" != xwindows; then
 785     UTIL_CHECK_TOOLS(STRIP, strip)
 786     UTIL_FIXUP_EXECUTABLE(STRIP)
 787     if test "x$TOOLCHAIN_TYPE" = xgcc; then
 788       UTIL_CHECK_TOOLS(NM, nm gcc-nm)
 789     else
 790       UTIL_CHECK_TOOLS(NM, nm)
 791     fi
 792     UTIL_FIXUP_EXECUTABLE(NM)
 793     GNM="$NM"
 794     AC_SUBST(GNM)
 795   fi
 796 
 797   # objcopy is used for moving debug symbols to separate files when
 798   # full debug symbols are enabled.
 799   if test "x$OPENJDK_TARGET_OS" = xlinux; then
 800     UTIL_CHECK_TOOLS(OBJCOPY, [gobjcopy objcopy])
 801     # Only call fixup if objcopy was found.
 802     if test -n "$OBJCOPY"; then
 803       UTIL_FIXUP_EXECUTABLE(OBJCOPY)
 804     fi
 805   fi
 806 
 807   UTIL_CHECK_TOOLS(OBJDUMP, [gobjdump objdump])
 808   if test "x$OBJDUMP" != x; then
 809     # Only used for compare.sh; we can live without it. UTIL_FIXUP_EXECUTABLE
 810     # bails if argument is missing.
 811     UTIL_FIXUP_EXECUTABLE(OBJDUMP)
 812   fi
 813 
 814   case $TOOLCHAIN_TYPE in
 815     gcc|clang)
 816       UTIL_CHECK_TOOLS(CXXFILT, [c++filt])
 817       UTIL_CHECK_NONEMPTY(CXXFILT)
 818       UTIL_FIXUP_EXECUTABLE(CXXFILT)
 819       ;;
 820   esac
 821 ])
 822 
 823 # Setup the build tools (i.e, the compiler and linker used to build programs
 824 # that should be run on the build platform, not the target platform, as a build
 825 # helper). Since the non-cross-compile case uses the normal, target compilers
 826 # for this, we can only do this after these have been setup.
 827 AC_DEFUN_ONCE([TOOLCHAIN_SETUP_BUILD_COMPILERS],
 828 [
 829   if test "x$COMPILE_TYPE" = "xcross"; then
 830     # Now we need to find a C/C++ compiler that can build executables for the
 831     # build platform. We can't use the AC_PROG_CC macro, since it can only be
 832     # used once. Also, we need to do this without adding a tools dir to the
 833     # path, otherwise we might pick up cross-compilers which don't use standard
 834     # naming.
 835 
 836     OLDPATH="$PATH"
 837 
 838     AC_ARG_WITH(build-devkit, [AS_HELP_STRING([--with-build-devkit],
 839         [Devkit to use for the build platform toolchain])])
 840     if test "x$with_build_devkit" = "xyes"; then
 841       AC_MSG_ERROR([--with-build-devkit must have a value])
 842     elif test -n "$with_build_devkit"; then
 843       if test ! -d "$with_build_devkit"; then
 844         AC_MSG_ERROR([--with-build-devkit points to non existing dir: $with_build_devkit])
 845       else
 846         UTIL_FIXUP_PATH([with_build_devkit])
 847         BUILD_DEVKIT_ROOT="$with_build_devkit"
 848         # Check for a meta data info file in the root of the devkit
 849         if test -f "$BUILD_DEVKIT_ROOT/devkit.info"; then
 850           # Process devkit.info so that existing devkit variables are not
 851           # modified by this
 852           $SED -e "s/^DEVKIT_/BUILD_DEVKIT_/g" \
 853               -e "s/\$DEVKIT_ROOT/\$BUILD_DEVKIT_ROOT/g" \
 854               -e "s/\$host/\$build/g" \
 855               $BUILD_DEVKIT_ROOT/devkit.info \
 856               > $CONFIGURESUPPORT_OUTPUTDIR/build-devkit.info
 857           . $CONFIGURESUPPORT_OUTPUTDIR/build-devkit.info
 858           # This potentially sets the following:
 859           # A descriptive name of the devkit
 860           BASIC_EVAL_DEVKIT_VARIABLE([BUILD_DEVKIT_NAME])
 861           # Corresponds to --with-extra-path
 862           BASIC_EVAL_DEVKIT_VARIABLE([BUILD_DEVKIT_EXTRA_PATH])
 863           # Corresponds to --with-toolchain-path
 864           BASIC_EVAL_DEVKIT_VARIABLE([BUILD_DEVKIT_TOOLCHAIN_PATH])
 865           # Corresponds to --with-sysroot
 866           BASIC_EVAL_DEVKIT_VARIABLE([BUILD_DEVKIT_SYSROOT])
 867           # Skip the Window specific parts
 868         fi
 869 
 870         AC_MSG_CHECKING([for build platform devkit])
 871         if test "x$BUILD_DEVKIT_NAME" != x; then
 872           AC_MSG_RESULT([$BUILD_DEVKIT_NAME in $BUILD_DEVKIT_ROOT])
 873         else
 874           AC_MSG_RESULT([$BUILD_DEVKIT_ROOT])
 875         fi
 876 
 877         BUILD_SYSROOT="$BUILD_DEVKIT_SYSROOT"
 878 
 879          # Fallback default of just /bin if DEVKIT_PATH is not defined
 880         if test "x$BUILD_DEVKIT_TOOLCHAIN_PATH" = x; then
 881           BUILD_DEVKIT_TOOLCHAIN_PATH="$BUILD_DEVKIT_ROOT/bin"
 882         fi
 883         PATH="$BUILD_DEVKIT_TOOLCHAIN_PATH:$BUILD_DEVKIT_EXTRA_PATH"
 884       fi
 885     fi
 886 
 887     # FIXME: we should list the discovered compilers as an exclude pattern!
 888     # If we do that, we can do this detection before POST_DETECTION, and still
 889     # find the build compilers in the tools dir, if needed.
 890     UTIL_REQUIRE_PROGS(BUILD_CC, [cl cc gcc])
 891     UTIL_FIXUP_EXECUTABLE(BUILD_CC)
 892     UTIL_REQUIRE_PROGS(BUILD_CXX, [cl CC g++])
 893     UTIL_FIXUP_EXECUTABLE(BUILD_CXX)
 894     UTIL_PATH_PROGS(BUILD_NM, nm gcc-nm)
 895     UTIL_FIXUP_EXECUTABLE(BUILD_NM)
 896     UTIL_PATH_PROGS(BUILD_AR, ar gcc-ar)
 897     UTIL_FIXUP_EXECUTABLE(BUILD_AR)
 898     UTIL_PATH_PROGS(BUILD_OBJCOPY, objcopy)
 899     UTIL_FIXUP_EXECUTABLE(BUILD_OBJCOPY)
 900     UTIL_PATH_PROGS(BUILD_STRIP, strip)
 901     UTIL_FIXUP_EXECUTABLE(BUILD_STRIP)
 902     # Assume the C compiler is the assembler
 903     BUILD_AS="$BUILD_CC -c"
 904     # Just like for the target compiler, use the compiler as linker
 905     BUILD_LD="$BUILD_CC"
 906     BUILD_LDCXX="$BUILD_CXX"
 907 
 908     PATH="$OLDPATH"
 909 
 910     TOOLCHAIN_EXTRACT_COMPILER_VERSION(BUILD_CC, [BuildC])
 911     TOOLCHAIN_EXTRACT_COMPILER_VERSION(BUILD_CXX, [BuildC++])
 912     TOOLCHAIN_PREPARE_FOR_VERSION_COMPARISONS([BUILD_], [OPENJDK_BUILD_], [build ])
 913     TOOLCHAIN_EXTRACT_LD_VERSION(BUILD_LD, [build linker])
 914     TOOLCHAIN_PREPARE_FOR_LD_VERSION_COMPARISONS([BUILD_], [OPENJDK_BUILD_])
 915   else
 916     # If we are not cross compiling, use the normal target compilers for
 917     # building the build platform executables.
 918     BUILD_CC="$CC"
 919     BUILD_CXX="$CXX"
 920     BUILD_LD="$LD"
 921     BUILD_LDCXX="$LDCXX"
 922     BUILD_NM="$NM"
 923     BUILD_AS="$AS"
 924     BUILD_OBJCOPY="$OBJCOPY"
 925     BUILD_STRIP="$STRIP"
 926     BUILD_AR="$AR"
 927 
 928     TOOLCHAIN_PREPARE_FOR_VERSION_COMPARISONS([], [OPENJDK_BUILD_], [build ])
 929     TOOLCHAIN_PREPARE_FOR_LD_VERSION_COMPARISONS([BUILD_], [OPENJDK_BUILD_])
 930   fi
 931 
 932   AC_SUBST(BUILD_CC)
 933   AC_SUBST(BUILD_CXX)
 934   AC_SUBST(BUILD_LD)
 935   AC_SUBST(BUILD_LDCXX)
 936   AC_SUBST(BUILD_NM)
 937   AC_SUBST(BUILD_AS)
 938   AC_SUBST(BUILD_AR)
 939 ])
 940 
 941 # Do some additional checks on the detected tools.
 942 AC_DEFUN_ONCE([TOOLCHAIN_MISC_CHECKS],
 943 [
 944   # Check for extra potential brokenness.
 945   if test  "x$TOOLCHAIN_TYPE" = xmicrosoft; then
 946     # On Windows, double-check that we got the right compiler.
 947     CC_VERSION_OUTPUT=`$CC 2>&1 | $GREP -v 'ERROR.*UtilTranslatePathList' | $HEAD -n 1 | $TR -d '\r'`
 948     COMPILER_CPU_TEST=`$ECHO $CC_VERSION_OUTPUT | $SED -n "s/^.* \(.*\)$/\1/p"`
 949     if test "x$OPENJDK_TARGET_CPU" = "xx86"; then
 950       if test "x$COMPILER_CPU_TEST" != "x80x86" -a "x$COMPILER_CPU_TEST" != "xx86"; then
 951         AC_MSG_ERROR([Target CPU mismatch. We are building for $OPENJDK_TARGET_CPU but CL is for "$COMPILER_CPU_TEST"; expected "80x86" or "x86".])
 952       fi
 953     elif test "x$OPENJDK_TARGET_CPU" = "xx86_64"; then
 954       if test "x$COMPILER_CPU_TEST" != "xx64"; then
 955         AC_MSG_ERROR([Target CPU mismatch. We are building for $OPENJDK_TARGET_CPU but CL is for "$COMPILER_CPU_TEST"; expected "x64".])
 956       fi
 957     fi
 958   fi
 959 
 960   if test "x$TOOLCHAIN_TYPE" = xgcc; then
 961     # If this is a --hash-style=gnu system, use --hash-style=both, why?
 962     HAS_GNU_HASH=`$CC -dumpspecs 2>/dev/null | $GREP 'hash-style=gnu'`
 963     # This is later checked when setting flags.
 964   fi
 965 
 966   if test "x$TOOLCHAIN_TYPE" = xgcc || test "x$TOOLCHAIN_TYPE" = xclang; then
 967     # Check if linker has -z noexecstack.
 968     HAS_NOEXECSTACK=`$CC -Wl,--help 2>/dev/null | $GREP 'z noexecstack'`
 969     # This is later checked when setting flags.
 970   fi
 971 
 972   # Setup hotspot lecagy names for toolchains
 973   HOTSPOT_TOOLCHAIN_TYPE=$TOOLCHAIN_TYPE
 974   if test "x$TOOLCHAIN_TYPE" = xclang; then
 975     HOTSPOT_TOOLCHAIN_TYPE=gcc
 976   elif test "x$TOOLCHAIN_TYPE" = xmicrosoft; then
 977     HOTSPOT_TOOLCHAIN_TYPE=visCPP
 978   fi
 979   AC_SUBST(HOTSPOT_TOOLCHAIN_TYPE)
 980 ])
 981 
 982 # Setup the JTReg Regression Test Harness.
 983 AC_DEFUN_ONCE([TOOLCHAIN_SETUP_JTREG],
 984 [
 985   AC_ARG_WITH(jtreg, [AS_HELP_STRING([--with-jtreg],
 986       [Regression Test Harness @<:@probed@:>@])])
 987 
 988   if test "x$with_jtreg" = xno; then
 989     # jtreg disabled
 990     AC_MSG_CHECKING([for jtreg test harness])
 991     AC_MSG_RESULT([no, disabled])
 992   elif test "x$with_jtreg" != xyes && test "x$with_jtreg" != x; then
 993     # An explicit path is specified, use it.
 994     JT_HOME="$with_jtreg"
 995     UTIL_FIXUP_PATH([JT_HOME])
 996     if test ! -d "$JT_HOME"; then
 997       AC_MSG_ERROR([jtreg home directory from --with-jtreg=$with_jtreg does not exist])
 998     fi
 999 
1000     if test ! -e "$JT_HOME/lib/jtreg.jar"; then
1001       AC_MSG_ERROR([jtreg home directory from --with-jtreg=$with_jtreg is not a valid jtreg home])
1002     fi
1003 
1004     AC_MSG_CHECKING([for jtreg test harness])
1005     AC_MSG_RESULT([$JT_HOME])
1006   else
1007     # Try to locate jtreg using the JT_HOME environment variable
1008     if test "x$JT_HOME" != x; then
1009       # JT_HOME set in environment, use it
1010       if test ! -d "$JT_HOME"; then
1011         AC_MSG_WARN([Ignoring JT_HOME pointing to invalid directory: $JT_HOME])
1012         JT_HOME=
1013       else
1014         if test ! -e "$JT_HOME/lib/jtreg.jar"; then
1015           AC_MSG_WARN([Ignoring JT_HOME which is not a valid jtreg home: $JT_HOME])
1016           JT_HOME=
1017         else
1018           AC_MSG_NOTICE([Located jtreg using JT_HOME from environment])
1019         fi
1020       fi
1021     fi
1022 
1023     if test "x$JT_HOME" = x; then
1024       # JT_HOME is not set in environment, or was deemed invalid.
1025       # Try to find jtreg on path
1026       UTIL_PATH_PROGS(JTREGEXE, jtreg)
1027       if test "x$JTREGEXE" != x; then
1028         # That's good, now try to derive JT_HOME
1029         JT_HOME=`(cd $($DIRNAME $JTREGEXE)/.. && pwd)`
1030         if test ! -e "$JT_HOME/lib/jtreg.jar"; then
1031           AC_MSG_WARN([Ignoring jtreg from path since a valid jtreg home cannot be found])
1032           JT_HOME=
1033         else
1034           AC_MSG_NOTICE([Located jtreg using jtreg executable in path])
1035         fi
1036       fi
1037     fi
1038 
1039     AC_MSG_CHECKING([for jtreg test harness])
1040     if test "x$JT_HOME" != x; then
1041       AC_MSG_RESULT([$JT_HOME])
1042     else
1043       AC_MSG_RESULT([no, not found])
1044 
1045       if test "x$with_jtreg" = xyes; then
1046         AC_MSG_ERROR([--with-jtreg was specified, but no jtreg found.])
1047       fi
1048     fi
1049   fi
1050 
1051   UTIL_FIXUP_PATH(JT_HOME)
1052   AC_SUBST(JT_HOME)
1053 ])
1054 
1055 # Setup the JIB dependency resolver
1056 AC_DEFUN_ONCE([TOOLCHAIN_SETUP_JIB],
1057 [
1058   AC_ARG_WITH(jib, [AS_HELP_STRING([--with-jib],
1059       [Jib dependency management tool @<:@not used@:>@])])
1060 
1061   if test "x$with_jib" = xno || test "x$with_jib" = x; then
1062     # jib disabled
1063     AC_MSG_CHECKING([for jib])
1064     AC_MSG_RESULT(no)
1065   elif test "x$with_jib" = xyes; then
1066     AC_MSG_ERROR([Must supply a value to --with-jib])
1067   else
1068     JIB_HOME="${with_jib}"
1069     AC_MSG_CHECKING([for jib])
1070     AC_MSG_RESULT(${JIB_HOME})
1071     if test ! -d "${JIB_HOME}"; then
1072       AC_MSG_ERROR([--with-jib must be a directory])
1073     fi
1074     JIB_JAR=$(ls ${JIB_HOME}/lib/jib-*.jar)
1075     if test ! -f "${JIB_JAR}"; then
1076       AC_MSG_ERROR([Could not find jib jar file in ${JIB_HOME}])
1077     fi
1078   fi
1079 
1080   AC_SUBST(JIB_HOME)
1081 ])