1 #
   2 # Copyright (c) 2011, 2015, 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 # Setup a number of variables describing how native output files are
  54 # named on this platform/toolchain.
  55 AC_DEFUN([TOOLCHAIN_SETUP_FILENAME_PATTERNS],
  56 [
  57   # Define filename patterns
  58   if test "x$OPENJDK_TARGET_OS" = xwindows; then
  59     LIBRARY_PREFIX=
  60     SHARED_LIBRARY_SUFFIX='.dll'
  61     STATIC_LIBRARY_SUFFIX='.lib'
  62     SHARED_LIBRARY='[$]1.dll'
  63     STATIC_LIBRARY='[$]1.lib'
  64     OBJ_SUFFIX='.obj'
  65     EXE_SUFFIX='.exe'
  66   else
  67     LIBRARY_PREFIX=lib
  68     SHARED_LIBRARY_SUFFIX='.so'
  69     STATIC_LIBRARY_SUFFIX='.a'
  70     SHARED_LIBRARY='lib[$]1.so'
  71     STATIC_LIBRARY='lib[$]1.a'
  72     OBJ_SUFFIX='.o'
  73     EXE_SUFFIX=''
  74     if test "x$OPENJDK_TARGET_OS" = xmacosx; then
  75       SHARED_LIBRARY='lib[$]1.dylib'
  76       SHARED_LIBRARY_SUFFIX='.dylib'
  77     fi
  78   fi
  79 
  80   AC_SUBST(LIBRARY_PREFIX)
  81   AC_SUBST(SHARED_LIBRARY_SUFFIX)
  82   AC_SUBST(STATIC_LIBRARY_SUFFIX)
  83   AC_SUBST(SHARED_LIBRARY)
  84   AC_SUBST(STATIC_LIBRARY)
  85   AC_SUBST(OBJ_SUFFIX)
  86   AC_SUBST(EXE_SUFFIX)
  87 ])
  88 
  89 # Determine which toolchain type to use, and make sure it is valid for this
  90 # platform. Setup various information about the selected toolchain.
  91 AC_DEFUN_ONCE([TOOLCHAIN_DETERMINE_TOOLCHAIN_TYPE],
  92 [
  93   AC_ARG_WITH(toolchain-type, [AS_HELP_STRING([--with-toolchain-type],
  94       [the toolchain type (or family) to use, use '--help' to show possible values @<:@platform dependent@:>@])])
  95 
  96   # Use indirect variable referencing
  97   toolchain_var_name=VALID_TOOLCHAINS_$OPENJDK_BUILD_OS
  98   VALID_TOOLCHAINS=${!toolchain_var_name}
  99 
 100   if test "x$OPENJDK_TARGET_OS" = xmacosx; then
 101     if test -n "$XCODEBUILD"; then
 102       # On Mac OS X, default toolchain to clang after Xcode 5
 103       XCODE_VERSION_OUTPUT=`"$XCODEBUILD" -version 2>&1 | $HEAD -n 1`
 104       $ECHO "$XCODE_VERSION_OUTPUT" | $GREP "Xcode " > /dev/null
 105       if test $? -ne 0; then
 106         AC_MSG_ERROR([Failed to determine Xcode version.])
 107       fi
 108       XCODE_MAJOR_VERSION=`$ECHO $XCODE_VERSION_OUTPUT | \
 109           $SED -e 's/^Xcode \(@<:@1-9@:>@@<:@0-9.@:>@*\)/\1/' | \
 110           $CUT -f 1 -d .`
 111       AC_MSG_NOTICE([Xcode major version: $XCODE_MAJOR_VERSION])
 112       if test $XCODE_MAJOR_VERSION -ge 5; then
 113           DEFAULT_TOOLCHAIN="clang"
 114       else
 115           DEFAULT_TOOLCHAIN="gcc"
 116       fi
 117     else
 118       # If Xcode is not installed, but the command line tools are
 119       # then we can't run xcodebuild. On these systems we should
 120       # default to clang
 121       DEFAULT_TOOLCHAIN="clang"
 122     fi
 123   else
 124     # First toolchain type in the list is the default
 125     DEFAULT_TOOLCHAIN=${VALID_TOOLCHAINS%% *}
 126   fi
 127 
 128   if test "x$with_toolchain_type" = xlist; then
 129     # List all toolchains
 130     AC_MSG_NOTICE([The following toolchains are valid on this platform:])
 131     for toolchain in $VALID_TOOLCHAINS; do
 132       toolchain_var_name=TOOLCHAIN_DESCRIPTION_$toolchain
 133       TOOLCHAIN_DESCRIPTION=${!toolchain_var_name}
 134       $PRINTF "  %-10s  %s\n" $toolchain "$TOOLCHAIN_DESCRIPTION"
 135     done
 136 
 137     exit 0
 138   elif test "x$with_toolchain_type" != x; then
 139     # User override; check that it is valid
 140     if test "x${VALID_TOOLCHAINS/$with_toolchain_type/}" = "x${VALID_TOOLCHAINS}"; then
 141       AC_MSG_NOTICE([Toolchain type $with_toolchain_type is not valid on this platform.])
 142       AC_MSG_NOTICE([Valid toolchains: $VALID_TOOLCHAINS.])
 143       AC_MSG_ERROR([Cannot continue.])
 144     fi
 145     TOOLCHAIN_TYPE=$with_toolchain_type
 146   else
 147     # No flag given, use default
 148     TOOLCHAIN_TYPE=$DEFAULT_TOOLCHAIN
 149   fi
 150   AC_SUBST(TOOLCHAIN_TYPE)
 151 
 152   TOOLCHAIN_CC_BINARY_clang="clang"
 153   TOOLCHAIN_CC_BINARY_gcc="gcc"
 154   TOOLCHAIN_CC_BINARY_microsoft="cl"
 155   TOOLCHAIN_CC_BINARY_solstudio="cc"
 156   TOOLCHAIN_CC_BINARY_xlc="xlc_r"
 157 
 158   TOOLCHAIN_CXX_BINARY_clang="clang++"
 159   TOOLCHAIN_CXX_BINARY_gcc="g++"
 160   TOOLCHAIN_CXX_BINARY_microsoft="cl"
 161   TOOLCHAIN_CXX_BINARY_solstudio="CC"
 162   TOOLCHAIN_CXX_BINARY_xlc="xlC_r"
 163 
 164   # Use indirect variable referencing
 165   toolchain_var_name=TOOLCHAIN_DESCRIPTION_$TOOLCHAIN_TYPE
 166   TOOLCHAIN_DESCRIPTION=${!toolchain_var_name}
 167   toolchain_var_name=TOOLCHAIN_CC_BINARY_$TOOLCHAIN_TYPE
 168   TOOLCHAIN_CC_BINARY=${!toolchain_var_name}
 169   toolchain_var_name=TOOLCHAIN_CXX_BINARY_$TOOLCHAIN_TYPE
 170   TOOLCHAIN_CXX_BINARY=${!toolchain_var_name}
 171 
 172   TOOLCHAIN_SETUP_FILENAME_PATTERNS
 173 
 174   if test "x$TOOLCHAIN_TYPE" = "x$DEFAULT_TOOLCHAIN"; then
 175     AC_MSG_NOTICE([Using default toolchain $TOOLCHAIN_TYPE ($TOOLCHAIN_DESCRIPTION)])
 176   else
 177     AC_MSG_NOTICE([Using user selected toolchain $TOOLCHAIN_TYPE ($TOOLCHAIN_DESCRIPTION). Default toolchain is $DEFAULT_TOOLCHAIN.])
 178   fi
 179 ])
 180 
 181 # Before we start detecting the toolchain executables, we might need some
 182 # special setup, e.g. additional paths etc.
 183 AC_DEFUN_ONCE([TOOLCHAIN_PRE_DETECTION],
 184 [
 185   # FIXME: Is this needed?
 186   AC_LANG(C++)
 187 
 188   # Store the CFLAGS etc passed to the configure script.
 189   ORG_CFLAGS="$CFLAGS"
 190   ORG_CXXFLAGS="$CXXFLAGS"
 191 
 192   # On Windows, we need to detect the visual studio installation first.
 193   # This will change the PATH, but we need to keep that new PATH even
 194   # after toolchain detection is done, since the compiler (on x86) uses
 195   # it for DLL resolution in runtime.
 196   if test "x$OPENJDK_BUILD_OS" = "xwindows" && test "x$TOOLCHAIN_TYPE" = "xmicrosoft"; then
 197     TOOLCHAIN_SETUP_VISUAL_STUDIO_ENV
 198     # Reset path to VS_PATH. It will include everything that was on PATH at the time we
 199     # ran TOOLCHAIN_SETUP_VISUAL_STUDIO_ENV.
 200     PATH="$VS_PATH"
 201     # The microsoft toolchain also requires INCLUDE and LIB to be set.
 202     export INCLUDE="$VS_INCLUDE"
 203     export LIB="$VS_LIB"
 204   fi
 205 
 206   # autoconf magic only relies on PATH, so update it if tools dir is specified
 207   OLD_PATH="$PATH"
 208 
 209   # For solaris we really need solaris tools, and not the GNU equivalent.
 210   # The build tools on Solaris reside in /usr/ccs (C Compilation System),
 211   # so add that to path before starting to probe.
 212   # FIXME: This was originally only done for AS,NM,GNM,STRIP,MCS,OBJCOPY,OBJDUMP.
 213   if test "x$OPENJDK_BUILD_OS" = xsolaris; then
 214     PATH="/usr/ccs/bin:$PATH"
 215   fi
 216 
 217   # Finally add TOOLCHAIN_PATH at the beginning, to allow --with-tools-dir to
 218   # override all other locations.
 219   if test "x$TOOLCHAIN_PATH" != x; then
 220     PATH=$TOOLCHAIN_PATH:$PATH
 221   fi
 222 ])
 223 
 224 # Restore path, etc
 225 AC_DEFUN_ONCE([TOOLCHAIN_POST_DETECTION],
 226 [
 227   # Restore old path.
 228   PATH="$OLD_PATH"
 229 
 230   # Restore the flags to the user specified values.
 231   # This is necessary since AC_PROG_CC defaults CFLAGS to "-g -O2"
 232   CFLAGS="$ORG_CFLAGS"
 233   CXXFLAGS="$ORG_CXXFLAGS"
 234 ])
 235 
 236 # Check if a compiler is of the toolchain type we expect, and save the version
 237 # information from it. If the compiler does not match the expected type,
 238 # this function will abort using AC_MSG_ERROR. If it matches, the version will
 239 # be stored in CC_VERSION_NUMBER/CXX_VERSION_NUMBER (as a dotted number), and
 240 # the full version string in CC_VERSION_STRING/CXX_VERSION_STRING.
 241 #
 242 # $1 = compiler to test (CC or CXX)
 243 # $2 = human readable name of compiler (C or C++)
 244 AC_DEFUN([TOOLCHAIN_CHECK_COMPILER_VERSION],
 245 [
 246   COMPILER=[$]$1
 247   COMPILER_NAME=$2
 248 
 249   if test "x$TOOLCHAIN_TYPE" = xsolstudio; then
 250     # cc -V output typically looks like
 251     #     cc: Sun C 5.12 Linux_i386 2011/11/16
 252     COMPILER_VERSION_OUTPUT=`$COMPILER -V 2>&1`
 253     # Check that this is likely to be the Solaris Studio cc.
 254     $ECHO "$COMPILER_VERSION_OUTPUT" | $GREP "^.*: Sun $COMPILER_NAME" > /dev/null
 255     if test $? -ne 0; then
 256       ALT_VERSION_OUTPUT=`$COMPILER --version 2>&1`
 257       AC_MSG_NOTICE([The $COMPILER_NAME compiler (located as $COMPILER) does not seem to be the required $TOOLCHAIN_TYPE compiler.])
 258       AC_MSG_NOTICE([The result from running with -V was: "$COMPILER_VERSION_OUTPUT"])
 259       AC_MSG_NOTICE([The result from running with --version was: "$ALT_VERSION_OUTPUT"])
 260       AC_MSG_ERROR([A $TOOLCHAIN_TYPE compiler is required. Try setting --with-tools-dir.])
 261     fi
 262     # Remove usage instructions (if present), and
 263     # collapse compiler output into a single line
 264     COMPILER_VERSION_STRING=`$ECHO $COMPILER_VERSION_OUTPUT | \
 265         $SED -e 's/ *@<:@Uu@:>@sage:.*//'`
 266     COMPILER_VERSION_NUMBER=`$ECHO $COMPILER_VERSION_OUTPUT | \
 267         $SED -e "s/^.*@<:@ ,\t@:>@$COMPILER_NAME@<:@ ,\t@:>@\(@<:@1-9@:>@\.@<:@0-9@:>@@<:@0-9@:>@*\).*/\1/"`
 268   elif test  "x$TOOLCHAIN_TYPE" = xxlc; then
 269     # xlc -qversion output typically looks like
 270     #     IBM XL C/C++ for AIX, V11.1 (5724-X13)
 271     #     Version: 11.01.0000.0015
 272     COMPILER_VERSION_OUTPUT=`$COMPILER -qversion 2>&1`
 273     # Check that this is likely to be the IBM XL C compiler.
 274     $ECHO "$COMPILER_VERSION_OUTPUT" | $GREP "IBM XL C" > /dev/null
 275     if test $? -ne 0; then
 276       ALT_VERSION_OUTPUT=`$COMPILER --version 2>&1`
 277       AC_MSG_NOTICE([The $COMPILER_NAME compiler (located as $COMPILER) does not seem to be the required $TOOLCHAIN_TYPE compiler.])
 278       AC_MSG_NOTICE([The result from running with -qversion was: "$COMPILER_VERSION_OUTPUT"])
 279       AC_MSG_NOTICE([The result from running with --version was: "$ALT_VERSION_OUTPUT"])
 280       AC_MSG_ERROR([A $TOOLCHAIN_TYPE compiler is required. Try setting --with-tools-dir.])
 281     fi
 282     # Collapse compiler output into a single line
 283     COMPILER_VERSION_STRING=`$ECHO $COMPILER_VERSION_OUTPUT`
 284     COMPILER_VERSION_NUMBER=`$ECHO $COMPILER_VERSION_OUTPUT | \
 285         $SED -e 's/^.*, V\(@<:@1-9@:>@@<:@0-9.@:>@*\).*$/\1/'`
 286   elif test  "x$TOOLCHAIN_TYPE" = xmicrosoft; then
 287     # There is no specific version flag, but all output starts with a version string.
 288     # First line typically looks something like:
 289     # Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 16.00.40219.01 for 80x86
 290     COMPILER_VERSION_OUTPUT=`$COMPILER 2>&1 | $HEAD -n 1 | $TR -d '\r'`
 291     # Check that this is likely to be Microsoft CL.EXE.
 292     $ECHO "$COMPILER_VERSION_OUTPUT" | $GREP "Microsoft.*Compiler" > /dev/null
 293     if test $? -ne 0; then
 294       AC_MSG_NOTICE([The $COMPILER_NAME compiler (located as $COMPILER) does not seem to be the required $TOOLCHAIN_TYPE compiler.])
 295       AC_MSG_NOTICE([The result from running it was: "$COMPILER_VERSION_OUTPUT"])
 296       AC_MSG_ERROR([A $TOOLCHAIN_TYPE compiler is required. Try setting --with-tools-dir.])
 297     fi
 298     # Collapse compiler output into a single line
 299     COMPILER_VERSION_STRING=`$ECHO $COMPILER_VERSION_OUTPUT`
 300     COMPILER_VERSION_NUMBER=`$ECHO $COMPILER_VERSION_OUTPUT | \
 301         $SED -e 's/^.*ersion.\(@<:@1-9@:>@@<:@0-9.@:>@*\) .*$/\1/'`
 302   elif test  "x$TOOLCHAIN_TYPE" = xgcc; then
 303     # gcc --version output typically looks like
 304     #     gcc (Ubuntu/Linaro 4.8.1-10ubuntu9) 4.8.1
 305     #     Copyright (C) 2013 Free Software Foundation, Inc.
 306     #     This is free software; see the source for copying conditions.  There is NO
 307     #     warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 308     COMPILER_VERSION_OUTPUT=`$COMPILER --version 2>&1`
 309     # Check that this is likely to be GCC.
 310     $ECHO "$COMPILER_VERSION_OUTPUT" | $GREP "Free Software Foundation" > /dev/null
 311     if test $? -ne 0; then
 312       AC_MSG_NOTICE([The $COMPILER_NAME compiler (located as $COMPILER) does not seem to be the required $TOOLCHAIN_TYPE compiler.])
 313       AC_MSG_NOTICE([The result from running with --version was: "$COMPILER_VERSION"])
 314       AC_MSG_ERROR([A $TOOLCHAIN_TYPE compiler is required. Try setting --with-tools-dir.])
 315     fi
 316     # Remove Copyright and legalese from version string, and
 317     # collapse into a single line
 318     COMPILER_VERSION_STRING=`$ECHO $COMPILER_VERSION_OUTPUT | \
 319         $SED -e 's/ *Copyright .*//'`
 320     COMPILER_VERSION_NUMBER=`$ECHO $COMPILER_VERSION_OUTPUT | \
 321         $SED -e 's/^.* \(@<:@1-9@:>@\.@<:@0-9.@:>@*\) .*$/\1/'`
 322   elif test  "x$TOOLCHAIN_TYPE" = xclang; then
 323     # clang --version output typically looks like
 324     #    Apple LLVM version 5.0 (clang-500.2.79) (based on LLVM 3.3svn)
 325     #    clang version 3.3 (tags/RELEASE_33/final)
 326     # or
 327     #    Debian clang version 3.2-7ubuntu1 (tags/RELEASE_32/final) (based on LLVM 3.2)
 328     #    Target: x86_64-pc-linux-gnu
 329     #    Thread model: posix
 330     COMPILER_VERSION_OUTPUT=`$COMPILER --version 2>&1`
 331     # Check that this is likely to be clang
 332     $ECHO "$COMPILER_VERSION_OUTPUT" | $GREP "clang" > /dev/null
 333     if test $? -ne 0; then
 334       AC_MSG_NOTICE([The $COMPILER_NAME compiler (located as $COMPILER) does not seem to be the required $TOOLCHAIN_TYPE compiler.])
 335       AC_MSG_NOTICE([The result from running with --version was: "$COMPILER_VERSION_OUTPUT"])
 336       AC_MSG_ERROR([A $TOOLCHAIN_TYPE compiler is required. Try setting --with-tools-dir.])
 337     fi
 338     # Collapse compiler output into a single line
 339     COMPILER_VERSION_STRING=`$ECHO $COMPILER_VERSION_OUTPUT`
 340     COMPILER_VERSION_NUMBER=`$ECHO $COMPILER_VERSION_OUTPUT | \
 341         $SED -e 's/^.*clang version \(@<:@1-9@:>@@<:@0-9.@:>@*\).*$/\1/'`
 342   else
 343       AC_MSG_ERROR([Unknown toolchain type $TOOLCHAIN_TYPE.])
 344   fi
 345   # This sets CC_VERSION_NUMBER or CXX_VERSION_NUMBER. (This comment is a grep marker)
 346   $1_VERSION_NUMBER="$COMPILER_VERSION_NUMBER"
 347   # This sets CC_VERSION_STRING or CXX_VERSION_STRING. (This comment is a grep marker)
 348   $1_VERSION_STRING="$COMPILER_VERSION_STRING"
 349 
 350   AC_MSG_NOTICE([Using $TOOLCHAIN_TYPE $COMPILER_NAME compiler version $COMPILER_VERSION_NUMBER @<:@$COMPILER_VERSION_STRING@:>@])
 351 ])
 352 
 353 # Try to locate the given C or C++ compiler in the path, or otherwise.
 354 #
 355 # $1 = compiler to test (CC or CXX)
 356 # $2 = human readable name of compiler (C or C++)
 357 # $3 = list of compiler names to search for
 358 AC_DEFUN([TOOLCHAIN_FIND_COMPILER],
 359 [
 360   COMPILER_NAME=$2
 361   SEARCH_LIST="$3"
 362 
 363   if test "x[$]$1" != x; then
 364     # User has supplied compiler name already, always let that override.
 365     AC_MSG_NOTICE([Will use user supplied compiler $1=[$]$1])
 366     if test "x`basename [$]$1`" = "x[$]$1"; then
 367       # A command without a complete path is provided, search $PATH.
 368 
 369       AC_PATH_PROGS(POTENTIAL_$1, [$]$1)
 370       if test "x$POTENTIAL_$1" != x; then
 371         $1=$POTENTIAL_$1
 372       else
 373         AC_MSG_ERROR([User supplied compiler $1=[$]$1 could not be found])
 374       fi
 375     else
 376       # Otherwise it might already be a complete path
 377       if test ! -x "[$]$1"; then
 378         AC_MSG_ERROR([User supplied compiler $1=[$]$1 does not exist])
 379       fi
 380     fi
 381   else
 382     # No user supplied value. Locate compiler ourselves.
 383 
 384     # If we are cross compiling, assume cross compilation tools follows the
 385     # cross compilation standard where they are prefixed with the autoconf
 386     # standard name for the target. For example the binary
 387     # i686-sun-solaris2.10-gcc will cross compile for i686-sun-solaris2.10.
 388     # If we are not cross compiling, then the default compiler name will be
 389     # used.
 390 
 391     $1=
 392     # If TOOLCHAIN_PATH is set, check for all compiler names in there first
 393     # before checking the rest of the PATH.
 394     # FIXME: Now that we prefix the TOOLS_DIR to the PATH in the PRE_DETECTION
 395     # step, this should not be necessary.
 396     if test -n "$TOOLCHAIN_PATH"; then
 397       PATH_save="$PATH"
 398       PATH="$TOOLCHAIN_PATH"
 399       AC_PATH_PROGS(TOOLCHAIN_PATH_$1, $SEARCH_LIST)
 400       $1=$TOOLCHAIN_PATH_$1
 401       PATH="$PATH_save"
 402     fi
 403 
 404     # AC_PATH_PROGS can't be run multiple times with the same variable,
 405     # so create a new name for this run.
 406     if test "x[$]$1" = x; then
 407       AC_PATH_PROGS(POTENTIAL_$1, $SEARCH_LIST)
 408       $1=$POTENTIAL_$1
 409     fi
 410 
 411     if test "x[$]$1" = x; then
 412       HELP_MSG_MISSING_DEPENDENCY([devkit])
 413       AC_MSG_ERROR([Could not find a $COMPILER_NAME compiler. $HELP_MSG])
 414     fi
 415   fi
 416 
 417   # Now we have a compiler binary in $1. Make sure it's okay.
 418   BASIC_FIXUP_EXECUTABLE($1)
 419   TEST_COMPILER="[$]$1"
 420   # Don't remove symbolic links on AIX because 'xlc_r' and 'xlC_r' may all be links
 421   # to 'xlc' but it is crucial that we invoke the compiler with the right name!
 422   if test "x$OPENJDK_BUILD_OS" != xaix; then
 423     # FIXME: This test should not be needed anymore; we don't do that for any platform.
 424     AC_MSG_CHECKING([resolved symbolic links for $1])
 425     BASIC_REMOVE_SYMBOLIC_LINKS(TEST_COMPILER)
 426     AC_MSG_RESULT([$TEST_COMPILER])
 427   fi
 428   AC_MSG_CHECKING([if $1 is disguised ccache])
 429 
 430   COMPILER_BASENAME=`$BASENAME "$TEST_COMPILER"`
 431   if test "x$COMPILER_BASENAME" = "xccache"; then
 432     AC_MSG_RESULT([yes, trying to find proper $COMPILER_NAME compiler])
 433     # We /usr/lib/ccache in the path, so cc is a symlink to /usr/bin/ccache.
 434     # We want to control ccache invocation ourselves, so ignore this cc and try
 435     # searching again.
 436 
 437     # Remove the path to the fake ccache cc from the PATH
 438     RETRY_COMPILER_SAVED_PATH="$PATH"
 439     COMPILER_DIRNAME=`$DIRNAME [$]$1`
 440     PATH="`$ECHO $PATH | $SED -e "s,$COMPILER_DIRNAME,,g" -e "s,::,:,g" -e "s,^:,,g"`"
 441 
 442     # Try again looking for our compiler
 443     AC_CHECK_TOOLS(PROPER_COMPILER_$1, $3)
 444     BASIC_FIXUP_EXECUTABLE(PROPER_COMPILER_$1)
 445     PATH="$RETRY_COMPILER_SAVED_PATH"
 446 
 447     AC_MSG_CHECKING([for resolved symbolic links for $1])
 448     BASIC_REMOVE_SYMBOLIC_LINKS(PROPER_COMPILER_$1)
 449     AC_MSG_RESULT([$PROPER_COMPILER_$1])
 450     $1="$PROPER_COMPILER_$1"
 451   else
 452     AC_MSG_RESULT([no, keeping $1])
 453   fi
 454 
 455   TOOLCHAIN_CHECK_COMPILER_VERSION([$1], [$COMPILER_NAME])
 456 ])
 457 
 458 # Detect the core components of the toolchain, i.e. the compilers (CC and CXX),
 459 # preprocessor (CPP and CXXCPP), the linker (LD), the assembler (AS) and the
 460 # archiver (AR). Verify that the compilers are correct according to the
 461 # toolchain type.
 462 AC_DEFUN_ONCE([TOOLCHAIN_DETECT_TOOLCHAIN_CORE],
 463 [
 464   #
 465   # Setup the compilers (CC and CXX)
 466   #
 467   TOOLCHAIN_FIND_COMPILER([CC], [C], $TOOLCHAIN_CC_BINARY)
 468   # Now that we have resolved CC ourself, let autoconf have its go at it
 469   AC_PROG_CC([$CC])
 470 
 471   TOOLCHAIN_FIND_COMPILER([CXX], [C++], $TOOLCHAIN_CXX_BINARY)
 472   # Now that we have resolved CXX ourself, let autoconf have its go at it
 473   AC_PROG_CXX([$CXX])
 474 
 475   #
 476   # Setup the preprocessor (CPP and CXXCPP)
 477   #
 478   AC_PROG_CPP
 479   BASIC_FIXUP_EXECUTABLE(CPP)
 480   AC_PROG_CXXCPP
 481   BASIC_FIXUP_EXECUTABLE(CXXCPP)
 482 
 483   #
 484   # Setup the linker (LD)
 485   #
 486   if test "x$TOOLCHAIN_TYPE" = xmicrosoft; then
 487     # In the Microsoft toolchain we have a separate LD command "link".
 488     # Make sure we reject /usr/bin/link (as determined in CYGWIN_LINK), which is
 489     # a cygwin program for something completely different.
 490     AC_CHECK_PROG([LD], [link],[link],,, [$CYGWIN_LINK])
 491     BASIC_FIXUP_EXECUTABLE(LD)
 492     # Verify that we indeed succeeded with this trick.
 493     AC_MSG_CHECKING([if the found link.exe is actually the Visual Studio linker])
 494     "$LD" --version > /dev/null
 495     if test $? -eq 0 ; then
 496       AC_MSG_RESULT([no])
 497       AC_MSG_ERROR([This is the Cygwin link tool. Please check your PATH and rerun configure.])
 498     else
 499       AC_MSG_RESULT([yes])
 500     fi
 501     LDCXX="$LD"
 502   else
 503     # All other toolchains use the compiler to link.
 504     LD="$CC"
 505     LDCXX="$CXX"
 506   fi
 507   AC_SUBST(LD)
 508   # FIXME: it should be CXXLD, according to standard (cf CXXCPP)
 509   AC_SUBST(LDCXX)
 510 
 511   #
 512   # Setup the assembler (AS)
 513   #
 514   if test "x$OPENJDK_TARGET_OS" = xsolaris; then
 515     # FIXME: should this really be solaris, or solstudio?
 516     BASIC_PATH_PROGS(AS, as)
 517     BASIC_FIXUP_EXECUTABLE(AS)
 518   else
 519     # FIXME: is this correct for microsoft?
 520     AS="$CC -c"
 521   fi
 522   AC_SUBST(AS)
 523 
 524   #
 525   # Setup the archiver (AR)
 526   #
 527   if test "x$TOOLCHAIN_TYPE" = xmicrosoft; then
 528     # The corresponding ar tool is lib.exe (used to create static libraries)
 529     AC_CHECK_PROG([AR], [lib],[lib],,,)
 530   else
 531     BASIC_CHECK_TOOLS(AR, ar)
 532   fi
 533   BASIC_FIXUP_EXECUTABLE(AR)
 534 ])
 535 
 536 # Setup additional tools that is considered a part of the toolchain, but not the
 537 # core part. Many of these are highly platform-specific and do not exist,
 538 # and/or are not needed on all platforms.
 539 AC_DEFUN_ONCE([TOOLCHAIN_DETECT_TOOLCHAIN_EXTRA],
 540 [
 541   if test "x$OPENJDK_TARGET_OS" = "xmacosx"; then
 542     BASIC_PATH_PROGS(LIPO, lipo)
 543     BASIC_FIXUP_EXECUTABLE(LIPO)
 544   fi
 545 
 546   if test "x$TOOLCHAIN_TYPE" = xmicrosoft; then
 547     AC_CHECK_PROG([MT], [mt], [mt],,, [/usr/bin/mt])
 548     BASIC_FIXUP_EXECUTABLE(MT)
 549     # Setup the resource compiler (RC)
 550     AC_CHECK_PROG([RC], [rc], [rc],,, [/usr/bin/rc])
 551     BASIC_FIXUP_EXECUTABLE(RC)
 552     AC_CHECK_PROG([DUMPBIN], [dumpbin], [dumpbin],,,)
 553     BASIC_FIXUP_EXECUTABLE(DUMPBIN)
 554     # We need to check for 'msbuild.exe' because at the place where we expect to
 555     # find 'msbuild.exe' there's also a directory called 'msbuild' and configure
 556     # won't find the 'msbuild.exe' executable in that case (and the
 557     # 'ac_executable_extensions' is unusable due to performance reasons).
 558     # Notice that we intentionally don't fix up the path to MSBUILD because we
 559     # will call it in a DOS shell during freetype detection on Windows (see
 560     # 'LIB_SETUP_FREETYPE' in "libraries.m4"
 561     AC_CHECK_PROG([MSBUILD], [msbuild.exe], [msbuild.exe],,,)
 562   fi
 563 
 564   if test "x$OPENJDK_TARGET_OS" = xsolaris; then
 565     BASIC_PATH_PROGS(STRIP, strip)
 566     BASIC_FIXUP_EXECUTABLE(STRIP)
 567     BASIC_PATH_PROGS(NM, nm)
 568     BASIC_FIXUP_EXECUTABLE(NM)
 569     BASIC_PATH_PROGS(GNM, gnm)
 570     BASIC_FIXUP_EXECUTABLE(GNM)
 571 
 572     BASIC_PATH_PROGS(MCS, mcs)
 573     BASIC_FIXUP_EXECUTABLE(MCS)
 574   elif test "x$OPENJDK_TARGET_OS" != xwindows; then
 575     # FIXME: we should unify this with the solaris case above.
 576     BASIC_CHECK_TOOLS(STRIP, strip)
 577     BASIC_FIXUP_EXECUTABLE(STRIP)
 578     BASIC_CHECK_TOOLS(NM, nm)
 579     BASIC_FIXUP_EXECUTABLE(NM)
 580     GNM="$NM"
 581     AC_SUBST(GNM)
 582   fi
 583 
 584   # objcopy is used for moving debug symbols to separate files when
 585   # full debug symbols are enabled.
 586   if test "x$OPENJDK_TARGET_OS" = xsolaris || test "x$OPENJDK_TARGET_OS" = xlinux; then
 587     BASIC_CHECK_TOOLS(OBJCOPY, [gobjcopy objcopy])
 588     # Only call fixup if objcopy was found.
 589     if test -n "$OBJCOPY"; then
 590       BASIC_FIXUP_EXECUTABLE(OBJCOPY)
 591     fi
 592   fi
 593 
 594   BASIC_CHECK_TOOLS(OBJDUMP, [gobjdump objdump])
 595   if test "x$OBJDUMP" != x; then
 596     # Only used for compare.sh; we can live without it. BASIC_FIXUP_EXECUTABLE
 597     # bails if argument is missing.
 598     BASIC_FIXUP_EXECUTABLE(OBJDUMP)
 599   fi
 600 ])
 601 
 602 # Setup the build tools (i.e, the compiler and linker used to build programs
 603 # that should be run on the build platform, not the target platform, as a build
 604 # helper). Since the non-cross-compile case uses the normal, target compilers
 605 # for this, we can only do this after these have been setup.
 606 AC_DEFUN_ONCE([TOOLCHAIN_SETUP_BUILD_COMPILERS],
 607 [
 608   if test "x$COMPILE_TYPE" = "xcross"; then
 609     # Now we need to find a C/C++ compiler that can build executables for the
 610     # build platform. We can't use the AC_PROG_CC macro, since it can only be
 611     # used once. Also, we need to do this without adding a tools dir to the
 612     # path, otherwise we might pick up cross-compilers which don't use standard
 613     # naming.
 614 
 615     # FIXME: we should list the discovered compilers as an exclude pattern!
 616     # If we do that, we can do this detection before POST_DETECTION, and still
 617     # find the build compilers in the tools dir, if needed.
 618     BASIC_PATH_PROGS(BUILD_CC, [cl cc gcc])
 619     BASIC_FIXUP_EXECUTABLE(BUILD_CC)
 620     BASIC_PATH_PROGS(BUILD_CXX, [cl CC g++])
 621     BASIC_FIXUP_EXECUTABLE(BUILD_CXX)
 622     BASIC_PATH_PROGS(BUILD_LD, ld)
 623     BASIC_FIXUP_EXECUTABLE(BUILD_LD)
 624   else
 625     # If we are not cross compiling, use the normal target compilers for
 626     # building the build platform executables.
 627     BUILD_CC="$CC"
 628     BUILD_CXX="$CXX"
 629     BUILD_LD="$LD"
 630   fi
 631 
 632   AC_SUBST(BUILD_CC)
 633   AC_SUBST(BUILD_CXX)
 634   AC_SUBST(BUILD_LD)
 635 ])
 636 
 637 # Setup legacy variables that are still needed as alternative ways to refer to
 638 # parts of the toolchain.
 639 AC_DEFUN_ONCE([TOOLCHAIN_SETUP_LEGACY],
 640 [
 641   if test "x$TOOLCHAIN_TYPE" = xmicrosoft; then
 642     # For hotspot, we need these in Windows mixed path,
 643     # so rewrite them all. Need added .exe suffix.
 644     HOTSPOT_CXX="$CXX.exe"
 645     HOTSPOT_LD="$LD.exe"
 646     HOTSPOT_MT="$MT.exe"
 647     HOTSPOT_RC="$RC.exe"
 648     BASIC_WINDOWS_REWRITE_AS_WINDOWS_MIXED_PATH(HOTSPOT_CXX)
 649     BASIC_WINDOWS_REWRITE_AS_WINDOWS_MIXED_PATH(HOTSPOT_LD)
 650     BASIC_WINDOWS_REWRITE_AS_WINDOWS_MIXED_PATH(HOTSPOT_MT)
 651     BASIC_WINDOWS_REWRITE_AS_WINDOWS_MIXED_PATH(HOTSPOT_RC)
 652     AC_SUBST(HOTSPOT_MT)
 653     AC_SUBST(HOTSPOT_RC)
 654   else
 655     HOTSPOT_CXX="$CXX"
 656     HOTSPOT_LD="$LD"
 657   fi
 658   AC_SUBST(HOTSPOT_CXX)
 659   AC_SUBST(HOTSPOT_LD)
 660 
 661   if test  "x$TOOLCHAIN_TYPE" = xclang; then
 662     USE_CLANG=true
 663   fi
 664   AC_SUBST(USE_CLANG)
 665 
 666   # LDEXE is the linker to use, when creating executables. Not really used.
 667   # FIXME: These should just be removed!
 668   LDEXE="$LD"
 669   LDEXECXX="$LDCXX"
 670   AC_SUBST(LDEXE)
 671   AC_SUBST(LDEXECXX)
 672 ])
 673 
 674 # Do some additional checks on the detected tools.
 675 AC_DEFUN_ONCE([TOOLCHAIN_MISC_CHECKS],
 676 [
 677   # The package path is used only on macosx?
 678   # FIXME: clean this up, and/or move it elsewhere.
 679   PACKAGE_PATH=/opt/local
 680   AC_SUBST(PACKAGE_PATH)
 681 
 682   # Check for extra potential brokenness.
 683   if test  "x$TOOLCHAIN_TYPE" = xmicrosoft; then
 684     # On Windows, double-check that we got the right compiler.
 685     CC_VERSION_OUTPUT=`$CC 2>&1 | $HEAD -n 1 | $TR -d '\r'`
 686     COMPILER_CPU_TEST=`$ECHO $CC_VERSION_OUTPUT | $SED -n "s/^.* \(.*\)$/\1/p"`
 687     if test "x$OPENJDK_TARGET_CPU" = "xx86"; then
 688       if test "x$COMPILER_CPU_TEST" != "x80x86" -a "x$COMPILER_CPU_TEST" != "xx86"; then
 689         AC_MSG_ERROR([Target CPU mismatch. We are building for $OPENJDK_TARGET_CPU but CL is for "$COMPILER_CPU_TEST"; expected "80x86" or "x86".])
 690       fi
 691     elif test "x$OPENJDK_TARGET_CPU" = "xx86_64"; then
 692       if test "x$COMPILER_CPU_TEST" != "xx64"; then
 693         AC_MSG_ERROR([Target CPU mismatch. We are building for $OPENJDK_TARGET_CPU but CL is for "$COMPILER_CPU_TEST"; expected "x64".])
 694       fi
 695     fi
 696   fi
 697 
 698   if test "x$TOOLCHAIN_TYPE" = xgcc; then
 699     # If this is a --hash-style=gnu system, use --hash-style=both, why?
 700     HAS_GNU_HASH=`$CC -dumpspecs 2>/dev/null | $GREP 'hash-style=gnu'`
 701     # This is later checked when setting flags.
 702 
 703     # "-Og" suppported for GCC 4.8 and later
 704     CFLAG_OPTIMIZE_DEBUG_FLAG="-Og"
 705     FLAGS_COMPILER_CHECK_ARGUMENTS([$CFLAG_OPTIMIZE_DEBUG_FLAG],
 706       [HAS_CFLAG_OPTIMIZE_DEBUG=true],
 707       [HAS_CFLAG_OPTIMIZE_DEBUG=false])
 708 
 709     # "-z relro" supported in GNU binutils 2.17 and later
 710     LINKER_RELRO_FLAG="-Xlinker -z -Xlinker relro"
 711     FLAGS_LINKER_CHECK_ARGUMENTS([$LINKER_RELRO_FLAG],
 712       [HAS_LINKER_RELRO=true],
 713       [HAS_LINKER_RELRO=false])
 714 
 715     # "-z now" supported in GNU binutils 2.11 and later
 716     LINKER_NOW_FLAG="-Xlinker -z -Xlinker now"
 717     FLAGS_LINKER_CHECK_ARGUMENTS([$LINKER_NOW_FLAG],
 718       [HAS_LINKER_NOW=true],
 719       [HAS_LINKER_NOW=false])
 720   fi
 721 
 722   # Check for broken SuSE 'ld' for which 'Only anonymous version tag is allowed
 723   # in executable.'
 724   USING_BROKEN_SUSE_LD=no
 725   if test "x$OPENJDK_TARGET_OS" = xlinux && test "x$TOOLCHAIN_TYPE" = xgcc; then
 726     AC_MSG_CHECKING([for broken SuSE 'ld' which only understands anonymous version tags in executables])
 727     $ECHO "SUNWprivate_1.1 { local: *; };" > version-script.map
 728     $ECHO "int main() { }" > main.c
 729     if $CXX -Xlinker -version-script=version-script.map main.c 2>&AS_MESSAGE_LOG_FD >&AS_MESSAGE_LOG_FD; then
 730       AC_MSG_RESULT(no)
 731       USING_BROKEN_SUSE_LD=no
 732     else
 733       AC_MSG_RESULT(yes)
 734       USING_BROKEN_SUSE_LD=yes
 735     fi
 736     rm -rf version-script.map main.c a.out
 737   fi
 738   AC_SUBST(USING_BROKEN_SUSE_LD)
 739 ])
 740 
 741 # Setup the JTReg Regression Test Harness.
 742 AC_DEFUN_ONCE([TOOLCHAIN_SETUP_JTREG],
 743 [
 744   AC_ARG_WITH(jtreg, [AS_HELP_STRING([--with-jtreg],
 745       [Regression Test Harness @<:@probed@:>@])],
 746       [],
 747       [with_jtreg=no])
 748 
 749   if test "x$with_jtreg" = xno; then
 750     # jtreg disabled
 751     AC_MSG_CHECKING([for jtreg])
 752     AC_MSG_RESULT(no)
 753   else
 754     if test "x$with_jtreg" != xyes; then
 755       # with path specified.
 756       JT_HOME="$with_jtreg"
 757     fi
 758 
 759     if test "x$JT_HOME" != x; then
 760       AC_MSG_CHECKING([for jtreg])
 761 
 762       # use JT_HOME enviroment var.
 763       BASIC_FIXUP_PATH([JT_HOME])
 764 
 765       # jtreg win32 script works for everybody
 766       JTREGEXE="$JT_HOME/bin/jtreg"
 767 
 768       if test ! -f "$JTREGEXE"; then
 769         AC_MSG_ERROR([JTReg executable does not exist: $JTREGEXE])
 770       fi
 771 
 772       AC_MSG_RESULT($JTREGEXE)
 773     else
 774       # try to find jtreg on path
 775       BASIC_REQUIRE_PROGS(JTREGEXE, jtreg)
 776       JT_HOME="`$DIRNAME $JTREGEXE`"
 777     fi
 778   fi
 779 
 780   AC_SUBST(JT_HOME)
 781   AC_SUBST(JTREGEXE)
 782 ])