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