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