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