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