toolchain.m4 revision 2251:e51f798914a8
119370Spst#
298944Sobrien# Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved.
398944Sobrien# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
498944Sobrien#
519370Spst# This code is free software; you can redistribute it and/or modify it
619370Spst# under the terms of the GNU General Public License version 2 only, as
798944Sobrien# published by the Free Software Foundation.  Oracle designates this
898944Sobrien# particular file as subject to the "Classpath" exception as provided
919370Spst# by Oracle in the LICENSE file that accompanied this code.
1098944Sobrien#
1198944Sobrien# This code is distributed in the hope that it will be useful, but WITHOUT
1246283Sdfr# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1398944Sobrien# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
1419370Spst# version 2 for more details (a copy is included in the LICENSE file that
1598944Sobrien# accompanied this code).
1698944Sobrien#
1719370Spst# You should have received a copy of the GNU General Public License version
1898944Sobrien# 2 along with this work; if not, write to the Free Software Foundation,
1919370Spst# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
2098944Sobrien#
2198944Sobrien# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2219370Spst# or visit www.oracle.com if you need additional information or have any
2398944Sobrien# questions.
2419370Spst#
2598944Sobrien
2698944Sobrien########################################################################
2719370Spst# This file is responsible for detecting, verifying and setting up the
2898944Sobrien# toolchain, i.e. the compiler, linker and related utilities. It will setup
2998944Sobrien# proper paths to the binaries, but it will not setup any flags.
3019370Spst#
3198944Sobrien# The binaries used is determined by the toolchain type, which is the family of
3219370Spst# compilers and related tools that are used.
3398944Sobrien########################################################################
3419370Spst
3598944Sobrien
3698944Sobrien# All valid toolchains, regardless of platform (used by help.m4)
3719370SpstVALID_TOOLCHAINS_all="gcc clang solstudio xlc microsoft"
3898944Sobrien
3919370Spst# These toolchains are valid on different platforms
4098944SobrienVALID_TOOLCHAINS_linux="gcc clang"
4119370SpstVALID_TOOLCHAINS_solaris="solstudio"
4298944SobrienVALID_TOOLCHAINS_macosx="gcc clang"
4398944SobrienVALID_TOOLCHAINS_aix="xlc"
4419370SpstVALID_TOOLCHAINS_windows="microsoft"
4598944Sobrien
4619370Spst# Toolchain descriptions
4798944SobrienTOOLCHAIN_DESCRIPTION_clang="clang/LLVM"
4819370SpstTOOLCHAIN_DESCRIPTION_gcc="GNU Compiler Collection"
4998944SobrienTOOLCHAIN_DESCRIPTION_microsoft="Microsoft Visual Studio"
5098944SobrienTOOLCHAIN_DESCRIPTION_solstudio="Oracle Solaris Studio"
5119370SpstTOOLCHAIN_DESCRIPTION_xlc="IBM XL C/C++"
5298944Sobrien
5319370Spst# Minimum supported versions, empty means unspecified
5498944SobrienTOOLCHAIN_MINIMUM_VERSION_clang="3.2"
5519370SpstTOOLCHAIN_MINIMUM_VERSION_gcc="4.3"
5698944SobrienTOOLCHAIN_MINIMUM_VERSION_microsoft=""
5798944SobrienTOOLCHAIN_MINIMUM_VERSION_solstudio="5.13"
5819370SpstTOOLCHAIN_MINIMUM_VERSION_xlc=""
5998944Sobrien
6019370Spst# Prepare the system so that TOOLCHAIN_CHECK_COMPILER_VERSION can be called.
6198944Sobrien# Must have CC_VERSION_NUMBER and CXX_VERSION_NUMBER.
6219370Spst# $1 - optional variable prefix for compiler and version variables (BUILD_)
6398944Sobrien# $2 - optional variable prefix for comparable variable (OPENJDK_BUILD_)
6498944SobrienAC_DEFUN([TOOLCHAIN_PREPARE_FOR_VERSION_COMPARISONS],
6598944Sobrien[
6698944Sobrien  if test "x[$]$1CC_VERSION_NUMBER" != "x[$]$1CXX_VERSION_NUMBER"; then
6798944Sobrien    AC_MSG_WARN([C and C++ compiler have different version numbers, [$]$1CC_VERSION_NUMBER vs [$]$1CXX_VERSION_NUMBER.])
6898944Sobrien    AC_MSG_WARN([This typically indicates a broken setup, and is not supported])
6919370Spst  fi
7098944Sobrien
7119370Spst  # We only check CC_VERSION_NUMBER since we assume CXX_VERSION_NUMBER is equal.
7298944Sobrien  if [ [[ "[$]$1CC_VERSION_NUMBER" =~ (.*\.){3} ]] ]; then
7398944Sobrien    AC_MSG_WARN([C compiler version number has more than three parts (X.Y.Z): [$]$1CC_VERSION_NUMBER. Comparisons might be wrong.])
7419370Spst  fi
7598944Sobrien
7619370Spst  if [ [[  "[$]$1CC_VERSION_NUMBER" =~ [0-9]{6} ]] ]; then
7798944Sobrien    AC_MSG_WARN([C compiler version number has a part larger than 99999: [$]$1CC_VERSION_NUMBER. Comparisons might be wrong.])
7819370Spst  fi
7998944Sobrien
8098944Sobrien  $2COMPARABLE_ACTUAL_VERSION=`$AWK -F. '{ printf("%05d%05d%05d\n", [$]1, [$]2, [$]3) }' <<< "[$]$1CC_VERSION_NUMBER"`
8119370Spst])
8298944Sobrien
8398944Sobrien# Check if the configured compiler (C and C++) is of a specific version or
8498944Sobrien# newer. TOOLCHAIN_PREPARE_FOR_VERSION_COMPARISONS must have been called before.
8519370Spst#
8698944Sobrien# Arguments:
8719370Spst#   VERSION:   The version string to check against the found version
8898944Sobrien#   IF_AT_LEAST:   block to run if the compiler is at least this version (>=)
8998944Sobrien#   IF_OLDER_THAN:   block to run if the compiler is older than this version (<)
9019370Spst#   PREFIX:   Optional variable prefix for compiler to compare version for (OPENJDK_BUILD_)
9198944SobrienBASIC_DEFUN_NAMED([TOOLCHAIN_CHECK_COMPILER_VERSION],
9219370Spst    [*VERSION PREFIX IF_AT_LEAST IF_OLDER_THAN], [$@],
9398944Sobrien[
9498944Sobrien  # Need to assign to a variable since m4 is blocked from modifying parts in [].
9519370Spst  REFERENCE_VERSION=ARG_VERSION
9698944Sobrien
9719370Spst  if [ [[ "$REFERENCE_VERSION" =~ (.*\.){3} ]] ]; then
9898944Sobrien    AC_MSG_ERROR([Internal error: Cannot compare to ARG_VERSION, only three parts (X.Y.Z) is supported])
9919370Spst  fi
10098944Sobrien
10119370Spst  if [ [[ "$REFERENCE_VERSION" =~ [0-9]{6} ]] ]; then
10298944Sobrien    AC_MSG_ERROR([Internal error: Cannot compare to ARG_VERSION, only parts < 99999 is supported])
10319370Spst  fi
10498944Sobrien
10519370Spst  # Version comparison method inspired by http://stackoverflow.com/a/24067243
10698944Sobrien  COMPARABLE_REFERENCE_VERSION=`$AWK -F. '{ printf("%05d%05d%05d\n", [$]1, [$]2, [$]3) }' <<< "$REFERENCE_VERSION"`
10719370Spst
10898944Sobrien  if test [$]ARG_PREFIX[COMPARABLE_ACTUAL_VERSION] -ge $COMPARABLE_REFERENCE_VERSION ; then
10919370Spst    :
11098944Sobrien    ARG_IF_AT_LEAST
11198944Sobrien  else
11219370Spst    :
11398944Sobrien    ARG_IF_OLDER_THAN
11419370Spst  fi
11598944Sobrien])
11619370Spst
11798944Sobrien# Setup a number of variables describing how native output files are
11819370Spst# named on this platform/toolchain.
11998944SobrienAC_DEFUN([TOOLCHAIN_SETUP_FILENAME_PATTERNS],
12098944Sobrien[
12198944Sobrien  # Define filename patterns
12298944Sobrien  if test "x$OPENJDK_TARGET_OS" = xwindows; then
12398944Sobrien    LIBRARY_PREFIX=
12498944Sobrien    SHARED_LIBRARY_SUFFIX='.dll'
12598944Sobrien    STATIC_LIBRARY_SUFFIX='.lib'
12619370Spst    SHARED_LIBRARY='[$]1.dll'
12798944Sobrien    STATIC_LIBRARY='[$]1.lib'
12819370Spst    OBJ_SUFFIX='.obj'
12998944Sobrien    EXE_SUFFIX='.exe'
13019370Spst  else
13198944Sobrien    LIBRARY_PREFIX=lib
13298944Sobrien    SHARED_LIBRARY_SUFFIX='.so'
13398944Sobrien    STATIC_LIBRARY_SUFFIX='.a'
13498944Sobrien    SHARED_LIBRARY='lib[$]1.so'
13598944Sobrien    STATIC_LIBRARY='lib[$]1.a'
13698944Sobrien    OBJ_SUFFIX='.o'
13798944Sobrien    EXE_SUFFIX=''
13898944Sobrien    if test "x$OPENJDK_TARGET_OS" = xmacosx; then
13998944Sobrien      # For full static builds, we're overloading the SHARED_LIBRARY
14098944Sobrien      # variables in order to limit the amount of changes required.
14198944Sobrien      # It would be better to remove SHARED and just use LIBRARY and
14219370Spst      # LIBRARY_SUFFIX for libraries that can be built either
14398944Sobrien      # shared or static and use STATIC_* for libraries that are
14498944Sobrien      # always built statically.
14598944Sobrien      if test "x$STATIC_BUILD" = xtrue; then
14698944Sobrien        SHARED_LIBRARY='lib[$]1.a'
14798944Sobrien        SHARED_LIBRARY_SUFFIX='.a'
14898944Sobrien      else
14919370Spst        SHARED_LIBRARY='lib[$]1.dylib'
15098944Sobrien        SHARED_LIBRARY_SUFFIX='.dylib'
15198944Sobrien      fi
15298944Sobrien    fi
15398944Sobrien  fi
15498944Sobrien
15598944Sobrien  AC_SUBST(LIBRARY_PREFIX)
15619370Spst  AC_SUBST(SHARED_LIBRARY_SUFFIX)
15798944Sobrien  AC_SUBST(STATIC_LIBRARY_SUFFIX)
15898944Sobrien  AC_SUBST(SHARED_LIBRARY)
15998944Sobrien  AC_SUBST(STATIC_LIBRARY)
16098944Sobrien  AC_SUBST(OBJ_SUFFIX)
16198944Sobrien  AC_SUBST(EXE_SUFFIX)
16298944Sobrien])
16398944Sobrien
16419370Spst# Determine which toolchain type to use, and make sure it is valid for this
16598944Sobrien# platform. Setup various information about the selected toolchain.
16698944SobrienAC_DEFUN_ONCE([TOOLCHAIN_DETERMINE_TOOLCHAIN_TYPE],
16798944Sobrien[
16819370Spst  AC_ARG_WITH(toolchain-type, [AS_HELP_STRING([--with-toolchain-type],
16998944Sobrien      [the toolchain type (or family) to use, use '--help' to show possible values @<:@platform dependent@:>@])])
17098944Sobrien
17198944Sobrien  # Use indirect variable referencing
17298944Sobrien  toolchain_var_name=VALID_TOOLCHAINS_$OPENJDK_BUILD_OS
17319370Spst  VALID_TOOLCHAINS=${!toolchain_var_name}
17498944Sobrien
17519370Spst  if test "x$OPENJDK_TARGET_OS" = xmacosx; then
17698944Sobrien    if test -n "$XCODEBUILD"; then
17719370Spst      # On Mac OS X, default toolchain to clang after Xcode 5
17898944Sobrien      XCODE_VERSION_OUTPUT=`"$XCODEBUILD" -version 2>&1 | $HEAD -n 1`
17998944Sobrien      $ECHO "$XCODE_VERSION_OUTPUT" | $GREP "Xcode " > /dev/null
18098944Sobrien      if test $? -ne 0; then
18119370Spst        AC_MSG_ERROR([Failed to determine Xcode version.])
18298944Sobrien      fi
18319370Spst      XCODE_MAJOR_VERSION=`$ECHO $XCODE_VERSION_OUTPUT | \
18498944Sobrien          $SED -e 's/^Xcode \(@<:@1-9@:>@@<:@0-9.@:>@*\)/\1/' | \
18519370Spst          $CUT -f 1 -d .`
18698944Sobrien      AC_MSG_NOTICE([Xcode major version: $XCODE_MAJOR_VERSION])
18719370Spst      if test $XCODE_MAJOR_VERSION -ge 5; then
18898944Sobrien          DEFAULT_TOOLCHAIN="clang"
18998944Sobrien      else
19019370Spst          DEFAULT_TOOLCHAIN="gcc"
19198944Sobrien      fi
19219370Spst    else
19398944Sobrien      # If Xcode is not installed, but the command line tools are
19498944Sobrien      # then we can't run xcodebuild. On these systems we should
19519370Spst      # default to clang
19698944Sobrien      DEFAULT_TOOLCHAIN="clang"
19719370Spst    fi
19898944Sobrien  else
19919370Spst    # First toolchain type in the list is the default
20098944Sobrien    DEFAULT_TOOLCHAIN=${VALID_TOOLCHAINS%% *}
20119370Spst  fi
20298944Sobrien
20398944Sobrien  if test "x$with_toolchain_type" = xlist; then
20419370Spst    # List all toolchains
20598944Sobrien    AC_MSG_NOTICE([The following toolchains are valid on this platform:])
20619370Spst    for toolchain in $VALID_TOOLCHAINS; do
20798944Sobrien      toolchain_var_name=TOOLCHAIN_DESCRIPTION_$toolchain
20898944Sobrien      TOOLCHAIN_DESCRIPTION=${!toolchain_var_name}
20919370Spst      $PRINTF "  %-10s  %s\n" $toolchain "$TOOLCHAIN_DESCRIPTION"
21098944Sobrien    done
21119370Spst
21298944Sobrien    exit 0
21398944Sobrien  elif test "x$with_toolchain_type" != x; then
21419370Spst    # User override; check that it is valid
21598944Sobrien    if test "x${VALID_TOOLCHAINS/$with_toolchain_type/}" = "x${VALID_TOOLCHAINS}"; then
21698944Sobrien      AC_MSG_NOTICE([Toolchain type $with_toolchain_type is not valid on this platform.])
21719370Spst      AC_MSG_NOTICE([Valid toolchains: $VALID_TOOLCHAINS.])
21819370Spst      AC_MSG_ERROR([Cannot continue.])
21998944Sobrien    fi
22098944Sobrien    TOOLCHAIN_TYPE=$with_toolchain_type
22119370Spst  else
22298944Sobrien    # No flag given, use default
22398944Sobrien    TOOLCHAIN_TYPE=$DEFAULT_TOOLCHAIN
22419370Spst  fi
22598944Sobrien  AC_SUBST(TOOLCHAIN_TYPE)
22619370Spst
22798944Sobrien  TOOLCHAIN_CC_BINARY_clang="clang"
22898944Sobrien  TOOLCHAIN_CC_BINARY_gcc="gcc"
22919370Spst  TOOLCHAIN_CC_BINARY_microsoft="cl"
23098944Sobrien  TOOLCHAIN_CC_BINARY_solstudio="cc"
23119370Spst  TOOLCHAIN_CC_BINARY_xlc="xlc_r"
23298944Sobrien
23319370Spst  TOOLCHAIN_CXX_BINARY_clang="clang++"
23498944Sobrien  TOOLCHAIN_CXX_BINARY_gcc="g++"
23519370Spst  TOOLCHAIN_CXX_BINARY_microsoft="cl"
23698944Sobrien  TOOLCHAIN_CXX_BINARY_solstudio="CC"
23798944Sobrien  TOOLCHAIN_CXX_BINARY_xlc="xlC_r"
23898944Sobrien
23998944Sobrien  # Use indirect variable referencing
24098944Sobrien  toolchain_var_name=TOOLCHAIN_DESCRIPTION_$TOOLCHAIN_TYPE
24119370Spst  TOOLCHAIN_DESCRIPTION=${!toolchain_var_name}
24298944Sobrien  toolchain_var_name=TOOLCHAIN_MINIMUM_VERSION_$TOOLCHAIN_TYPE
24398944Sobrien  TOOLCHAIN_MINIMUM_VERSION=${!toolchain_var_name}
24419370Spst  toolchain_var_name=TOOLCHAIN_CC_BINARY_$TOOLCHAIN_TYPE
24598944Sobrien  TOOLCHAIN_CC_BINARY=${!toolchain_var_name}
24698944Sobrien  toolchain_var_name=TOOLCHAIN_CXX_BINARY_$TOOLCHAIN_TYPE
24798944Sobrien  TOOLCHAIN_CXX_BINARY=${!toolchain_var_name}
24819370Spst
24998944Sobrien  TOOLCHAIN_SETUP_FILENAME_PATTERNS
25019370Spst
25119370Spst  if test "x$TOOLCHAIN_TYPE" = "x$DEFAULT_TOOLCHAIN"; then
25298944Sobrien    AC_MSG_NOTICE([Using default toolchain $TOOLCHAIN_TYPE ($TOOLCHAIN_DESCRIPTION)])
25398944Sobrien  else
25419370Spst    AC_MSG_NOTICE([Using user selected toolchain $TOOLCHAIN_TYPE ($TOOLCHAIN_DESCRIPTION). Default toolchain is $DEFAULT_TOOLCHAIN.])
25598944Sobrien  fi
25619370Spst])
25798944Sobrien
25819370Spst# Before we start detecting the toolchain executables, we might need some
25998944Sobrien# special setup, e.g. additional paths etc.
26019370SpstAC_DEFUN_ONCE([TOOLCHAIN_PRE_DETECTION],
26198944Sobrien[
26219370Spst  # FIXME: Is this needed?
26398944Sobrien  AC_LANG(C++)
26419370Spst
26598944Sobrien  # Store the CFLAGS etc passed to the configure script.
26698944Sobrien  ORG_CFLAGS="$CFLAGS"
26719370Spst  ORG_CXXFLAGS="$CXXFLAGS"
26898944Sobrien
26919370Spst  # autoconf magic only relies on PATH, so update it if tools dir is specified
27098944Sobrien  OLD_PATH="$PATH"
27119370Spst
27298944Sobrien  # On Windows, we need to detect the visual studio installation first.
27319370Spst  # This will change the PATH, but we need to keep that new PATH even
27498944Sobrien  # after toolchain detection is done, since the compiler (on x86) uses
27519370Spst  # it for DLL resolution in runtime.
27698944Sobrien  if test "x$OPENJDK_BUILD_OS" = "xwindows" \
27719370Spst      && test "x$TOOLCHAIN_TYPE" = "xmicrosoft"; then
27898944Sobrien    TOOLCHAIN_SETUP_VISUAL_STUDIO_ENV
27919370Spst    # Reset path to VS_PATH. It will include everything that was on PATH at the time we
28098944Sobrien    # ran TOOLCHAIN_SETUP_VISUAL_STUDIO_ENV.
28198944Sobrien    PATH="$VS_PATH"
28219370Spst    # The microsoft toolchain also requires INCLUDE and LIB to be set.
28398944Sobrien    export INCLUDE="$VS_INCLUDE"
28498944Sobrien    export LIB="$VS_LIB"
28598944Sobrien  else
28619370Spst    if test "x$XCODE_VERSION_OUTPUT" != x; then
28798944Sobrien      # For Xcode, we set the Xcode version as TOOLCHAIN_VERSION
28819370Spst      TOOLCHAIN_VERSION=`$ECHO $XCODE_VERSION_OUTPUT | $CUT -f 2 -d ' '`
28998944Sobrien      TOOLCHAIN_DESCRIPTION="$TOOLCHAIN_DESCRIPTION from Xcode"
29098944Sobrien    else
29119370Spst      # Currently we do not define this for other toolchains. This might change as the need arise.
29298944Sobrien      TOOLCHAIN_VERSION=
29398944Sobrien    fi
29498944Sobrien  fi
29519370Spst  AC_SUBST(TOOLCHAIN_VERSION)
29698944Sobrien
29798944Sobrien  # Finally add TOOLCHAIN_PATH at the beginning, to allow --with-tools-dir to
29898944Sobrien  # override all other locations.
29919370Spst  if test "x$TOOLCHAIN_PATH" != x; then
30098944Sobrien    PATH=$TOOLCHAIN_PATH:$PATH
30198944Sobrien  fi
30298944Sobrien])
30319370Spst
30498944Sobrien# Restore path, etc
30519370SpstAC_DEFUN_ONCE([TOOLCHAIN_POST_DETECTION],
30698944Sobrien[
30798944Sobrien  # Restore old path, except for the microsoft toolchain, which requires VS_PATH
30819370Spst  # to remain in place. Otherwise the compiler will not work in some siutations
30998944Sobrien  # in later configure checks.
31098944Sobrien  if test "x$TOOLCHAIN_TYPE" != "xmicrosoft"; then
31198944Sobrien    PATH="$OLD_PATH"
31219370Spst  fi
31398944Sobrien
31498944Sobrien  # Restore the flags to the user specified values.
31519370Spst  # This is necessary since AC_PROG_CC defaults CFLAGS to "-g -O2"
31698944Sobrien  CFLAGS="$ORG_CFLAGS"
31719370Spst  CXXFLAGS="$ORG_CXXFLAGS"
31898944Sobrien])
31998944Sobrien
32019370Spst# Check if a compiler is of the toolchain type we expect, and save the version
32198944Sobrien# information from it. If the compiler does not match the expected type,
32298944Sobrien# this function will abort using AC_MSG_ERROR. If it matches, the version will
32398944Sobrien# be stored in CC_VERSION_NUMBER/CXX_VERSION_NUMBER (as a dotted number), and
32498944Sobrien# the full version string in CC_VERSION_STRING/CXX_VERSION_STRING.
32519370Spst#
32698944Sobrien# $1 = compiler to test (CC or CXX)
32798944Sobrien# $2 = human readable name of compiler (C or C++)
32819370SpstAC_DEFUN([TOOLCHAIN_EXTRACT_COMPILER_VERSION],
32998944Sobrien[
33019370Spst  COMPILER=[$]$1
33119370Spst  COMPILER_NAME=$2
33219370Spst
33319370Spst  if test "x$TOOLCHAIN_TYPE" = xsolstudio; then
334    # cc -V output typically looks like
335    #     cc: Sun C 5.12 Linux_i386 2011/11/16
336    COMPILER_VERSION_OUTPUT=`$COMPILER -V 2>&1`
337    # Check that this is likely to be the Solaris Studio cc.
338    $ECHO "$COMPILER_VERSION_OUTPUT" | $GREP "^.*: Sun $COMPILER_NAME" > /dev/null
339    if test $? -ne 0; then
340      ALT_VERSION_OUTPUT=`$COMPILER --version 2>&1`
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 -V was: "$COMPILER_VERSION_OUTPUT"])
343      AC_MSG_NOTICE([The result from running with --version was: "$ALT_VERSION_OUTPUT"])
344      AC_MSG_ERROR([A $TOOLCHAIN_TYPE compiler is required. Try setting --with-tools-dir.])
345    fi
346    # Remove usage instructions (if present), and
347    # collapse compiler output into a single line
348    COMPILER_VERSION_STRING=`$ECHO $COMPILER_VERSION_OUTPUT | \
349        $SED -e 's/ *@<:@Uu@:>@sage:.*//'`
350    COMPILER_VERSION_NUMBER=`$ECHO $COMPILER_VERSION_OUTPUT | \
351        $SED -e "s/^.*@<:@ ,\t@:>@$COMPILER_NAME@<:@ ,\t@:>@\(@<:@1-9@:>@\.@<:@0-9@:>@@<:@0-9@:>@*\).*/\1/"`
352  elif test  "x$TOOLCHAIN_TYPE" = xxlc; then
353    # xlc -qversion output typically looks like
354    #     IBM XL C/C++ for AIX, V11.1 (5724-X13)
355    #     Version: 11.01.0000.0015
356    COMPILER_VERSION_OUTPUT=`$COMPILER -qversion 2>&1`
357    # Check that this is likely to be the IBM XL C compiler.
358    $ECHO "$COMPILER_VERSION_OUTPUT" | $GREP "IBM XL C" > /dev/null
359    if test $? -ne 0; then
360      ALT_VERSION_OUTPUT=`$COMPILER --version 2>&1`
361      AC_MSG_NOTICE([The $COMPILER_NAME compiler (located as $COMPILER) does not seem to be the required $TOOLCHAIN_TYPE compiler.])
362      AC_MSG_NOTICE([The result from running with -qversion was: "$COMPILER_VERSION_OUTPUT"])
363      AC_MSG_NOTICE([The result from running with --version was: "$ALT_VERSION_OUTPUT"])
364      AC_MSG_ERROR([A $TOOLCHAIN_TYPE compiler is required. Try setting --with-tools-dir.])
365    fi
366    # Collapse compiler output into a single line
367    COMPILER_VERSION_STRING=`$ECHO $COMPILER_VERSION_OUTPUT`
368    COMPILER_VERSION_NUMBER=`$ECHO $COMPILER_VERSION_OUTPUT | \
369        $SED -e 's/^.*, V\(@<:@1-9@:>@@<:@0-9.@:>@*\).*$/\1/'`
370  elif test  "x$TOOLCHAIN_TYPE" = xmicrosoft; then
371    # There is no specific version flag, but all output starts with a version string.
372    # First line typically looks something like:
373    # Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 16.00.40219.01 for 80x86
374    COMPILER_VERSION_OUTPUT=`$COMPILER 2>&1 | $HEAD -n 1 | $TR -d '\r'`
375    # Check that this is likely to be Microsoft CL.EXE.
376    $ECHO "$COMPILER_VERSION_OUTPUT" | $GREP "Microsoft.*Compiler" > /dev/null
377    if test $? -ne 0; then
378      AC_MSG_NOTICE([The $COMPILER_NAME compiler (located as $COMPILER) does not seem to be the required $TOOLCHAIN_TYPE compiler.])
379      AC_MSG_NOTICE([The result from running it was: "$COMPILER_VERSION_OUTPUT"])
380      AC_MSG_ERROR([A $TOOLCHAIN_TYPE compiler is required. Try setting --with-tools-dir.])
381    fi
382    # Collapse compiler output into a single line
383    COMPILER_VERSION_STRING=`$ECHO $COMPILER_VERSION_OUTPUT`
384    COMPILER_VERSION_NUMBER=`$ECHO $COMPILER_VERSION_OUTPUT | \
385        $SED -e 's/^.*ersion.\(@<:@1-9@:>@@<:@0-9.@:>@*\) .*$/\1/'`
386  elif test  "x$TOOLCHAIN_TYPE" = xgcc; then
387    # gcc --version output typically looks like
388    #     gcc (Ubuntu/Linaro 4.8.1-10ubuntu9) 4.8.1
389    #     Copyright (C) 2013 Free Software Foundation, Inc.
390    #     This is free software; see the source for copying conditions.  There is NO
391    #     warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
392    COMPILER_VERSION_OUTPUT=`$COMPILER --version 2>&1`
393    # Check that this is likely to be GCC.
394    $ECHO "$COMPILER_VERSION_OUTPUT" | $GREP "Free Software Foundation" > /dev/null
395    if test $? -ne 0; then
396      AC_MSG_NOTICE([The $COMPILER_NAME compiler (located as $COMPILER) does not seem to be the required $TOOLCHAIN_TYPE compiler.])
397      AC_MSG_NOTICE([The result from running with --version was: "$COMPILER_VERSION"])
398      AC_MSG_ERROR([A $TOOLCHAIN_TYPE compiler is required. Try setting --with-tools-dir.])
399    fi
400    # Remove Copyright and legalese from version string, and
401    # collapse into a single line
402    COMPILER_VERSION_STRING=`$ECHO $COMPILER_VERSION_OUTPUT | \
403        $SED -e 's/ *Copyright .*//'`
404    COMPILER_VERSION_NUMBER=`$ECHO $COMPILER_VERSION_OUTPUT | \
405        $SED -e 's/^.* \(@<:@1-9@:>@\.@<:@0-9.@:>@*\)@<:@^0-9.@:>@.*$/\1/'`
406  elif test  "x$TOOLCHAIN_TYPE" = xclang; then
407    # clang --version output typically looks like
408    #    Apple LLVM version 5.0 (clang-500.2.79) (based on LLVM 3.3svn)
409    #    clang version 3.3 (tags/RELEASE_33/final)
410    # or
411    #    Debian clang version 3.2-7ubuntu1 (tags/RELEASE_32/final) (based on LLVM 3.2)
412    #    Target: x86_64-pc-linux-gnu
413    #    Thread model: posix
414    COMPILER_VERSION_OUTPUT=`$COMPILER --version 2>&1`
415    # Check that this is likely to be clang
416    $ECHO "$COMPILER_VERSION_OUTPUT" | $GREP "clang" > /dev/null
417    if test $? -ne 0; then
418      AC_MSG_NOTICE([The $COMPILER_NAME compiler (located as $COMPILER) does not seem to be the required $TOOLCHAIN_TYPE compiler.])
419      AC_MSG_NOTICE([The result from running with --version was: "$COMPILER_VERSION_OUTPUT"])
420      AC_MSG_ERROR([A $TOOLCHAIN_TYPE compiler is required. Try setting --with-tools-dir.])
421    fi
422    # Collapse compiler output into a single line
423    COMPILER_VERSION_STRING=`$ECHO $COMPILER_VERSION_OUTPUT`
424    COMPILER_VERSION_NUMBER=`$ECHO $COMPILER_VERSION_OUTPUT | \
425        $SED -e 's/^.* version \(@<:@1-9@:>@@<:@0-9.@:>@*\).*$/\1/'`
426  else
427      AC_MSG_ERROR([Unknown toolchain type $TOOLCHAIN_TYPE.])
428  fi
429  # This sets CC_VERSION_NUMBER or CXX_VERSION_NUMBER. (This comment is a grep marker)
430  $1_VERSION_NUMBER="$COMPILER_VERSION_NUMBER"
431  # This sets CC_VERSION_STRING or CXX_VERSION_STRING. (This comment is a grep marker)
432  $1_VERSION_STRING="$COMPILER_VERSION_STRING"
433
434  AC_MSG_NOTICE([Using $TOOLCHAIN_TYPE $COMPILER_NAME compiler version $COMPILER_VERSION_NUMBER @<:@$COMPILER_VERSION_STRING@:>@])
435])
436
437# Try to locate the given C or C++ compiler in the path, or otherwise.
438#
439# $1 = compiler to test (CC or CXX)
440# $2 = human readable name of compiler (C or C++)
441# $3 = list of compiler names to search for
442AC_DEFUN([TOOLCHAIN_FIND_COMPILER],
443[
444  COMPILER_NAME=$2
445  SEARCH_LIST="$3"
446
447  if test "x[$]$1" != x; then
448    # User has supplied compiler name already, always let that override.
449    AC_MSG_NOTICE([Will use user supplied compiler $1=[$]$1])
450    if test "x`basename [$]$1`" = "x[$]$1"; then
451      # A command without a complete path is provided, search $PATH.
452
453      AC_PATH_PROGS(POTENTIAL_$1, [$]$1)
454      if test "x$POTENTIAL_$1" != x; then
455        $1=$POTENTIAL_$1
456      else
457        AC_MSG_ERROR([User supplied compiler $1=[$]$1 could not be found])
458      fi
459    else
460      # Otherwise it might already be a complete path
461      if test ! -x "[$]$1"; then
462        AC_MSG_ERROR([User supplied compiler $1=[$]$1 does not exist])
463      fi
464    fi
465  else
466    # No user supplied value. Locate compiler ourselves.
467
468    # If we are cross compiling, assume cross compilation tools follows the
469    # cross compilation standard where they are prefixed with the autoconf
470    # standard name for the target. For example the binary
471    # i686-sun-solaris2.10-gcc will cross compile for i686-sun-solaris2.10.
472    # If we are not cross compiling, then the default compiler name will be
473    # used.
474
475    $1=
476    # If TOOLCHAIN_PATH is set, check for all compiler names in there first
477    # before checking the rest of the PATH.
478    # FIXME: Now that we prefix the TOOLS_DIR to the PATH in the PRE_DETECTION
479    # step, this should not be necessary.
480    if test -n "$TOOLCHAIN_PATH"; then
481      PATH_save="$PATH"
482      PATH="$TOOLCHAIN_PATH"
483      AC_PATH_PROGS(TOOLCHAIN_PATH_$1, $SEARCH_LIST)
484      $1=$TOOLCHAIN_PATH_$1
485      PATH="$PATH_save"
486    fi
487
488    # AC_PATH_PROGS can't be run multiple times with the same variable,
489    # so create a new name for this run.
490    if test "x[$]$1" = x; then
491      AC_PATH_PROGS(POTENTIAL_$1, $SEARCH_LIST)
492      $1=$POTENTIAL_$1
493    fi
494
495    if test "x[$]$1" = x; then
496      HELP_MSG_MISSING_DEPENDENCY([devkit])
497      AC_MSG_ERROR([Could not find a $COMPILER_NAME compiler. $HELP_MSG])
498    fi
499  fi
500
501  # Now we have a compiler binary in $1. Make sure it's okay.
502  BASIC_FIXUP_EXECUTABLE($1)
503  TEST_COMPILER="[$]$1"
504
505  AC_MSG_CHECKING([resolved symbolic links for $1])
506  SYMLINK_ORIGINAL="$TEST_COMPILER"
507  BASIC_REMOVE_SYMBOLIC_LINKS(SYMLINK_ORIGINAL)
508  if test "x$TEST_COMPILER" = "x$SYMLINK_ORIGINAL"; then
509    AC_MSG_RESULT([no symlink])
510  else
511    AC_MSG_RESULT([$SYMLINK_ORIGINAL])
512
513    # We can't handle ccache by gcc wrappers, since we need to know if we're
514    # using ccache. Instead ccache usage must be controlled by a configure option.
515    COMPILER_BASENAME=`$BASENAME "$SYMLINK_ORIGINAL"`
516    if test "x$COMPILER_BASENAME" = "xccache"; then
517      AC_MSG_NOTICE([Please use --enable-ccache instead of providing a wrapped compiler.])
518      AC_MSG_ERROR([$TEST_COMPILER is a symbolic link to ccache. This is not supported.])
519    fi
520  fi
521
522  TOOLCHAIN_EXTRACT_COMPILER_VERSION([$1], [$COMPILER_NAME])
523])
524
525# Detect the core components of the toolchain, i.e. the compilers (CC and CXX),
526# preprocessor (CPP and CXXCPP), the linker (LD), the assembler (AS) and the
527# archiver (AR). Verify that the compilers are correct according to the
528# toolchain type.
529AC_DEFUN_ONCE([TOOLCHAIN_DETECT_TOOLCHAIN_CORE],
530[
531  #
532  # Setup the compilers (CC and CXX)
533  #
534  TOOLCHAIN_FIND_COMPILER([CC], [C], $TOOLCHAIN_CC_BINARY)
535  # Now that we have resolved CC ourself, let autoconf have its go at it
536  AC_PROG_CC([$CC])
537
538  TOOLCHAIN_FIND_COMPILER([CXX], [C++], $TOOLCHAIN_CXX_BINARY)
539  # Now that we have resolved CXX ourself, let autoconf have its go at it
540  AC_PROG_CXX([$CXX])
541
542  # This is the compiler version number on the form X.Y[.Z]
543  AC_SUBST(CC_VERSION_NUMBER)
544  AC_SUBST(CXX_VERSION_NUMBER)
545
546  TOOLCHAIN_PREPARE_FOR_VERSION_COMPARISONS
547
548  if test "x$TOOLCHAIN_MINIMUM_VERSION" != x; then
549    TOOLCHAIN_CHECK_COMPILER_VERSION(VERSION: $TOOLCHAIN_MINIMUM_VERSION,
550        IF_OLDER_THAN: [
551          AC_MSG_WARN([You are using $TOOLCHAIN_TYPE older than $TOOLCHAIN_MINIMUM_VERSION. This is not a supported configuration.])
552        ]
553    )
554  fi
555
556  #
557  # Setup the preprocessor (CPP and CXXCPP)
558  #
559  AC_PROG_CPP
560  BASIC_FIXUP_EXECUTABLE(CPP)
561  AC_PROG_CXXCPP
562  BASIC_FIXUP_EXECUTABLE(CXXCPP)
563
564  #
565  # Setup the linker (LD)
566  #
567  if test "x$TOOLCHAIN_TYPE" = xmicrosoft; then
568    # In the Microsoft toolchain we have a separate LD command "link".
569    # Make sure we reject /usr/bin/link (as determined in CYGWIN_LINK), which is
570    # a cygwin program for something completely different.
571    AC_CHECK_PROG([LD], [link],[link],,, [$CYGWIN_LINK])
572    BASIC_FIXUP_EXECUTABLE(LD)
573    # Verify that we indeed succeeded with this trick.
574    AC_MSG_CHECKING([if the found link.exe is actually the Visual Studio linker])
575    "$LD" --version > /dev/null
576    if test $? -eq 0 ; then
577      AC_MSG_RESULT([no])
578      AC_MSG_ERROR([This is the Cygwin link tool. Please check your PATH and rerun configure.])
579    else
580      AC_MSG_RESULT([yes])
581    fi
582    LDCXX="$LD"
583  else
584    # All other toolchains use the compiler to link.
585    LD="$CC"
586    LDCXX="$CXX"
587  fi
588  AC_SUBST(LD)
589  # FIXME: it should be CXXLD, according to standard (cf CXXCPP)
590  AC_SUBST(LDCXX)
591
592  #
593  # Setup the assembler (AS)
594  #
595  if test "x$OPENJDK_TARGET_OS" = xsolaris; then
596    BASIC_PATH_PROGS(AS, as)
597    BASIC_FIXUP_EXECUTABLE(AS)
598    if test "x$AS" = x; then
599      AC_MSG_ERROR([Solaris assembler (as) is required. Please install via "pkg install pkg:/developer/assembler".])
600    fi
601  else
602    # FIXME: is this correct for microsoft?
603    AS="$CC -c"
604  fi
605  AC_SUBST(AS)
606
607  #
608  # Setup the archiver (AR)
609  #
610  if test "x$TOOLCHAIN_TYPE" = xmicrosoft; then
611    # The corresponding ar tool is lib.exe (used to create static libraries)
612    AC_CHECK_PROG([AR], [lib],[lib],,,)
613  elif test "x$TOOLCHAIN_TYPE" = xgcc; then
614    BASIC_CHECK_TOOLS(AR, ar gcc-ar)
615  else
616    BASIC_CHECK_TOOLS(AR, ar)
617  fi
618  BASIC_FIXUP_EXECUTABLE(AR)
619])
620
621# Setup additional tools that is considered a part of the toolchain, but not the
622# core part. Many of these are highly platform-specific and do not exist,
623# and/or are not needed on all platforms.
624AC_DEFUN_ONCE([TOOLCHAIN_DETECT_TOOLCHAIN_EXTRA],
625[
626  if test "x$OPENJDK_TARGET_OS" = "xmacosx"; then
627    BASIC_PATH_PROGS(LIPO, lipo)
628    BASIC_FIXUP_EXECUTABLE(LIPO)
629  fi
630
631  if test "x$TOOLCHAIN_TYPE" = xmicrosoft; then
632    AC_CHECK_PROG([MT], [mt], [mt],,, [/usr/bin/mt])
633    BASIC_FIXUP_EXECUTABLE(MT)
634    # Setup the resource compiler (RC)
635    AC_CHECK_PROG([RC], [rc], [rc],,, [/usr/bin/rc])
636    BASIC_FIXUP_EXECUTABLE(RC)
637    AC_CHECK_PROG([DUMPBIN], [dumpbin], [dumpbin],,,)
638    BASIC_FIXUP_EXECUTABLE(DUMPBIN)
639    # We need to check for 'msbuild.exe' because at the place where we expect to
640    # find 'msbuild.exe' there's also a directory called 'msbuild' and configure
641    # won't find the 'msbuild.exe' executable in that case (and the
642    # 'ac_executable_extensions' is unusable due to performance reasons).
643    # Notice that we intentionally don't fix up the path to MSBUILD because we
644    # will call it in a DOS shell during freetype detection on Windows (see
645    # 'LIB_SETUP_FREETYPE' in "libraries.m4"
646    AC_CHECK_PROG([MSBUILD], [msbuild.exe], [msbuild.exe],,,)
647  fi
648
649  if test "x$OPENJDK_TARGET_OS" = xsolaris; then
650    BASIC_PATH_PROGS(STRIP, strip)
651    BASIC_FIXUP_EXECUTABLE(STRIP)
652    BASIC_PATH_PROGS(NM, nm)
653    BASIC_FIXUP_EXECUTABLE(NM)
654    BASIC_PATH_PROGS(GNM, gnm)
655    BASIC_FIXUP_EXECUTABLE(GNM)
656  elif test "x$OPENJDK_TARGET_OS" != xwindows; then
657    # FIXME: we should unify this with the solaris case above.
658    BASIC_CHECK_TOOLS(STRIP, strip)
659    BASIC_FIXUP_EXECUTABLE(STRIP)
660    if test "x$TOOLCHAIN_TYPE" = xgcc; then
661      BASIC_CHECK_TOOLS(NM, nm gcc-nm)
662    else
663      BASIC_CHECK_TOOLS(NM, nm)
664    fi
665    BASIC_FIXUP_EXECUTABLE(NM)
666    GNM="$NM"
667    AC_SUBST(GNM)
668  fi
669
670  # objcopy is used for moving debug symbols to separate files when
671  # full debug symbols are enabled.
672  if test "x$OPENJDK_TARGET_OS" = xsolaris || test "x$OPENJDK_TARGET_OS" = xlinux; then
673    BASIC_CHECK_TOOLS(OBJCOPY, [gobjcopy objcopy])
674    # Only call fixup if objcopy was found.
675    if test -n "$OBJCOPY"; then
676      BASIC_FIXUP_EXECUTABLE(OBJCOPY)
677      if test "x$OPENJDK_BUILD_OS" = xsolaris; then
678        # objcopy prior to 2.21.1 on solaris is broken and is not usable.
679        # Rewrite objcopy version output to VALID_VERSION or BAD_VERSION.
680        # - version number is last blank separate word on first line
681        # - version number formats that have been seen:
682        #   - <major>.<minor>
683        #   - <major>.<minor>.<micro>
684        OBJCOPY_VERSION=`$OBJCOPY --version | $HEAD -n 1`
685        # The outer [ ] is to prevent m4 from eating the [] in the sed expression.
686        [ OBJCOPY_VERSION_CHECK=`$ECHO $OBJCOPY_VERSION | $SED -n \
687              -e 's/.* //' \
688              -e '/^[01]\./b bad' \
689              -e '/^2\./{' \
690              -e '  s/^2\.//' \
691              -e '  /^[0-9]$/b bad' \
692              -e '  /^[0-9]\./b bad' \
693              -e '  /^1[0-9]$/b bad' \
694              -e '  /^1[0-9]\./b bad' \
695              -e '  /^20\./b bad' \
696              -e '  /^21\.0$/b bad' \
697              -e '  /^21\.0\./b bad' \
698              -e '}' \
699              -e ':good' \
700              -e 's/.*/VALID_VERSION/p' \
701              -e 'q' \
702              -e ':bad' \
703              -e 's/.*/BAD_VERSION/p' \
704              -e 'q'` ]
705        if test "x$OBJCOPY_VERSION_CHECK" = xBAD_VERSION; then
706          OBJCOPY=
707          AC_MSG_WARN([Ignoring found objcopy since it is broken (prior to 2.21.1). No debug symbols will be generated.])
708          AC_MSG_NOTICE([objcopy reports version $OBJCOPY_VERSION])
709          AC_MSG_NOTICE([Note: patch 149063-01 or newer contains the correct Solaris 10 SPARC version])
710          AC_MSG_NOTICE([Note: patch 149064-01 or newer contains the correct Solaris 10 X86 version])
711          AC_MSG_NOTICE([Note: Solaris 11 Update 1 contains the correct version])
712        fi
713      fi
714    fi
715  fi
716
717  BASIC_CHECK_TOOLS(OBJDUMP, [gobjdump objdump])
718  if test "x$OBJDUMP" != x; then
719    # Only used for compare.sh; we can live without it. BASIC_FIXUP_EXECUTABLE
720    # bails if argument is missing.
721    BASIC_FIXUP_EXECUTABLE(OBJDUMP)
722  fi
723])
724
725# Setup the build tools (i.e, the compiler and linker used to build programs
726# that should be run on the build platform, not the target platform, as a build
727# helper). Since the non-cross-compile case uses the normal, target compilers
728# for this, we can only do this after these have been setup.
729AC_DEFUN_ONCE([TOOLCHAIN_SETUP_BUILD_COMPILERS],
730[
731  if test "x$COMPILE_TYPE" = "xcross"; then
732    # Now we need to find a C/C++ compiler that can build executables for the
733    # build platform. We can't use the AC_PROG_CC macro, since it can only be
734    # used once. Also, we need to do this without adding a tools dir to the
735    # path, otherwise we might pick up cross-compilers which don't use standard
736    # naming.
737
738    OLDPATH="$PATH"
739
740    AC_ARG_WITH(build-devkit, [AS_HELP_STRING([--with-build-devkit],
741        [Devkit to use for the build platform toolchain])])
742    if test "x$with_build_devkit" = "xyes"; then
743      AC_MSG_ERROR([--with-build-devkit must have a value])
744    elif test -n "$with_build_devkit"; then
745      if test ! -d "$with_build_devkit"; then
746        AC_MSG_ERROR([--with-build-devkit points to non existing dir: $with_build_devkit])
747      else
748        BASIC_FIXUP_PATH([with_build_devkit])
749        BUILD_DEVKIT_ROOT="$with_build_devkit"
750        # Check for a meta data info file in the root of the devkit
751        if test -f "$BUILD_DEVKIT_ROOT/devkit.info"; then
752          # Process devkit.info so that existing devkit variables are not
753          # modified by this
754          $SED -e "s/^DEVKIT_/BUILD_DEVKIT_/g" \
755              -e "s/\$DEVKIT_ROOT/\$BUILD_DEVKIT_ROOT/g" \
756              -e "s/\$host/\$build/g" \
757              $BUILD_DEVKIT_ROOT/devkit.info \
758              > $CONFIGURESUPPORT_OUTPUTDIR/build-devkit.info
759          . $CONFIGURESUPPORT_OUTPUTDIR/build-devkit.info
760          # This potentially sets the following:
761          # A descriptive name of the devkit
762          BASIC_EVAL_DEVKIT_VARIABLE([BUILD_DEVKIT_NAME])
763          # Corresponds to --with-extra-path
764          BASIC_EVAL_DEVKIT_VARIABLE([BUILD_DEVKIT_EXTRA_PATH])
765          # Corresponds to --with-toolchain-path
766          BASIC_EVAL_DEVKIT_VARIABLE([BUILD_DEVKIT_TOOLCHAIN_PATH])
767          # Corresponds to --with-sysroot
768          BASIC_EVAL_DEVKIT_VARIABLE([BUILD_DEVKIT_SYSROOT])
769          # Skip the Window specific parts
770        fi
771
772        AC_MSG_CHECKING([for build platform devkit])
773        if test "x$BUILD_DEVKIT_NAME" != x; then
774          AC_MSG_RESULT([$BUILD_DEVKIT_NAME in $BUILD_DEVKIT_ROOT])
775        else
776          AC_MSG_RESULT([$BUILD_DEVKIT_ROOT])
777        fi
778
779        BUILD_SYSROOT="$BUILD_DEVKIT_SYSROOT"
780        FLAGS_SETUP_SYSROOT_FLAGS([BUILD_])
781
782         # Fallback default of just /bin if DEVKIT_PATH is not defined
783        if test "x$BUILD_DEVKIT_TOOLCHAIN_PATH" = x; then
784          BUILD_DEVKIT_TOOLCHAIN_PATH="$BUILD_DEVKIT_ROOT/bin"
785        fi
786        PATH="$BUILD_DEVKIT_TOOLCHAIN_PATH:$BUILD_DEVKIT_EXTRA_PATH"
787      fi
788    fi
789
790    # FIXME: we should list the discovered compilers as an exclude pattern!
791    # If we do that, we can do this detection before POST_DETECTION, and still
792    # find the build compilers in the tools dir, if needed.
793    BASIC_REQUIRE_PROGS(BUILD_CC, [cl cc gcc])
794    BASIC_FIXUP_EXECUTABLE(BUILD_CC)
795    BASIC_REQUIRE_PROGS(BUILD_CXX, [cl CC g++])
796    BASIC_FIXUP_EXECUTABLE(BUILD_CXX)
797    BASIC_PATH_PROGS(BUILD_NM, nm gcc-nm)
798    BASIC_FIXUP_EXECUTABLE(BUILD_NM)
799    BASIC_PATH_PROGS(BUILD_AR, ar gcc-ar)
800    BASIC_FIXUP_EXECUTABLE(BUILD_AR)
801    BASIC_PATH_PROGS(BUILD_OBJCOPY, objcopy)
802    BASIC_FIXUP_EXECUTABLE(BUILD_OBJCOPY)
803    BASIC_PATH_PROGS(BUILD_STRIP, strip)
804    BASIC_FIXUP_EXECUTABLE(BUILD_STRIP)
805    # Assume the C compiler is the assembler
806    BUILD_AS="$BUILD_CC -c"
807    # Just like for the target compiler, use the compiler as linker
808    BUILD_LD="$BUILD_CC"
809    BUILD_LDCXX="$BUILD_CXX"
810
811    PATH="$OLDPATH"
812
813    TOOLCHAIN_EXTRACT_COMPILER_VERSION(BUILD_CC, [BuildC])
814    TOOLCHAIN_EXTRACT_COMPILER_VERSION(BUILD_CXX, [BuildC++])
815    TOOLCHAIN_PREPARE_FOR_VERSION_COMPARISONS([BUILD_], [OPENJDK_BUILD_])
816  else
817    # If we are not cross compiling, use the normal target compilers for
818    # building the build platform executables.
819    BUILD_CC="$CC"
820    BUILD_CXX="$CXX"
821    BUILD_LD="$LD"
822    BUILD_LDCXX="$LDCXX"
823    BUILD_NM="$NM"
824    BUILD_AS="$AS"
825    BUILD_OBJCOPY="$OBJCOPY"
826    BUILD_STRIP="$STRIP"
827    BUILD_SYSROOT_CFLAGS="$SYSROOT_CFLAGS"
828    BUILD_SYSROOT_LDFLAGS="$SYSROOT_LDFLAGS"
829    BUILD_AR="$AR"
830    
831    TOOLCHAIN_PREPARE_FOR_VERSION_COMPARISONS([], [OPENJDK_BUILD_])
832  fi
833
834  AC_SUBST(BUILD_CC)
835  AC_SUBST(BUILD_CXX)
836  AC_SUBST(BUILD_LD)
837  AC_SUBST(BUILD_LDCXX)
838  AC_SUBST(BUILD_NM)
839  AC_SUBST(BUILD_AS)
840  AC_SUBST(BUILD_SYSROOT_CFLAGS)
841  AC_SUBST(BUILD_SYSROOT_LDFLAGS)
842  AC_SUBST(BUILD_AR)
843])
844
845# Setup legacy variables that are still needed as alternative ways to refer to
846# parts of the toolchain.
847AC_DEFUN_ONCE([TOOLCHAIN_SETUP_LEGACY],
848[
849  if test "x$TOOLCHAIN_TYPE" = xmicrosoft; then
850    # For hotspot, we need these in Windows mixed path,
851    # so rewrite them all. Need added .exe suffix.
852    HOTSPOT_CXX="$CXX.exe"
853    HOTSPOT_LD="$LD.exe"
854    HOTSPOT_MT="$MT.exe"
855    HOTSPOT_RC="$RC.exe"
856    BASIC_WINDOWS_REWRITE_AS_WINDOWS_MIXED_PATH(HOTSPOT_CXX)
857    BASIC_WINDOWS_REWRITE_AS_WINDOWS_MIXED_PATH(HOTSPOT_LD)
858    BASIC_WINDOWS_REWRITE_AS_WINDOWS_MIXED_PATH(HOTSPOT_MT)
859    BASIC_WINDOWS_REWRITE_AS_WINDOWS_MIXED_PATH(HOTSPOT_RC)
860    AC_SUBST(HOTSPOT_MT)
861    AC_SUBST(HOTSPOT_RC)
862  else
863    HOTSPOT_CXX="$CXX"
864    HOTSPOT_LD="$LD"
865  fi
866  AC_SUBST(HOTSPOT_CXX)
867  AC_SUBST(HOTSPOT_LD)
868
869  if test  "x$TOOLCHAIN_TYPE" = xclang; then
870    USE_CLANG=true
871  fi
872  AC_SUBST(USE_CLANG)
873])
874
875# Do some additional checks on the detected tools.
876AC_DEFUN_ONCE([TOOLCHAIN_MISC_CHECKS],
877[
878  # The package path is used only on macosx?
879  # FIXME: clean this up, and/or move it elsewhere.
880  PACKAGE_PATH=/opt/local
881  AC_SUBST(PACKAGE_PATH)
882
883  # Check for extra potential brokenness.
884  if test  "x$TOOLCHAIN_TYPE" = xmicrosoft; then
885    # On Windows, double-check that we got the right compiler.
886    CC_VERSION_OUTPUT=`$CC 2>&1 | $HEAD -n 1 | $TR -d '\r'`
887    COMPILER_CPU_TEST=`$ECHO $CC_VERSION_OUTPUT | $SED -n "s/^.* \(.*\)$/\1/p"`
888    if test "x$OPENJDK_TARGET_CPU" = "xx86"; then
889      if test "x$COMPILER_CPU_TEST" != "x80x86" -a "x$COMPILER_CPU_TEST" != "xx86"; then
890        AC_MSG_ERROR([Target CPU mismatch. We are building for $OPENJDK_TARGET_CPU but CL is for "$COMPILER_CPU_TEST"; expected "80x86" or "x86".])
891      fi
892    elif test "x$OPENJDK_TARGET_CPU" = "xx86_64"; then
893      if test "x$COMPILER_CPU_TEST" != "xx64"; then
894        AC_MSG_ERROR([Target CPU mismatch. We are building for $OPENJDK_TARGET_CPU but CL is for "$COMPILER_CPU_TEST"; expected "x64".])
895      fi
896    fi
897  fi
898
899  if test "x$TOOLCHAIN_TYPE" = xgcc; then
900    # If this is a --hash-style=gnu system, use --hash-style=both, why?
901    HAS_GNU_HASH=`$CC -dumpspecs 2>/dev/null | $GREP 'hash-style=gnu'`
902    # This is later checked when setting flags.
903
904    # "-Og" suppported for GCC 4.8 and later
905    CFLAG_OPTIMIZE_DEBUG_FLAG="-Og"
906    FLAGS_COMPILER_CHECK_ARGUMENTS(ARGUMENT: [$CFLAG_OPTIMIZE_DEBUG_FLAG],
907      IF_TRUE: [HAS_CFLAG_OPTIMIZE_DEBUG=true],
908      IF_FALSE: [HAS_CFLAG_OPTIMIZE_DEBUG=false])
909
910    # "-z relro" supported in GNU binutils 2.17 and later
911    LINKER_RELRO_FLAG="-Wl,-z,relro"
912    FLAGS_LINKER_CHECK_ARGUMENTS(ARGUMENT: [$LINKER_RELRO_FLAG],
913      IF_TRUE: [HAS_LINKER_RELRO=true],
914      IF_FALSE: [HAS_LINKER_RELRO=false])
915
916    # "-z now" supported in GNU binutils 2.11 and later
917    LINKER_NOW_FLAG="-Wl,-z,now"
918    FLAGS_LINKER_CHECK_ARGUMENTS(ARGUMENT: [$LINKER_NOW_FLAG],
919      IF_TRUE: [HAS_LINKER_NOW=true],
920      IF_FALSE: [HAS_LINKER_NOW=false])
921  fi
922
923  # Check for broken SuSE 'ld' for which 'Only anonymous version tag is allowed
924  # in executable.'
925  USING_BROKEN_SUSE_LD=no
926  if test "x$OPENJDK_TARGET_OS" = xlinux && test "x$TOOLCHAIN_TYPE" = xgcc; then
927    AC_MSG_CHECKING([for broken SuSE 'ld' which only understands anonymous version tags in executables])
928    $ECHO "SUNWprivate_1.1 { local: *; };" > version-script.map
929    $ECHO "int main() { }" > main.c
930    if $CXX -Wl,-version-script=version-script.map main.c 2>&AS_MESSAGE_LOG_FD >&AS_MESSAGE_LOG_FD; then
931      AC_MSG_RESULT(no)
932      USING_BROKEN_SUSE_LD=no
933    else
934      AC_MSG_RESULT(yes)
935      USING_BROKEN_SUSE_LD=yes
936    fi
937    $RM version-script.map main.c a.out
938  fi
939  AC_SUBST(USING_BROKEN_SUSE_LD)
940
941  # Setup hotspot lecagy names for toolchains
942  HOTSPOT_TOOLCHAIN_TYPE=$TOOLCHAIN_TYPE
943  if test "x$TOOLCHAIN_TYPE" = xclang; then
944    HOTSPOT_TOOLCHAIN_TYPE=gcc
945  elif test "x$TOOLCHAIN_TYPE" = xsolstudio; then
946    HOTSPOT_TOOLCHAIN_TYPE=sparcWorks
947  elif test "x$TOOLCHAIN_TYPE" = xmicrosoft; then
948    HOTSPOT_TOOLCHAIN_TYPE=visCPP
949  fi
950  AC_SUBST(HOTSPOT_TOOLCHAIN_TYPE)
951])
952
953# Setup the JTReg Regression Test Harness.
954AC_DEFUN_ONCE([TOOLCHAIN_SETUP_JTREG],
955[
956  AC_ARG_WITH(jtreg, [AS_HELP_STRING([--with-jtreg],
957      [Regression Test Harness @<:@probed@:>@])],
958      [],
959      [with_jtreg=no])
960
961  if test "x$with_jtreg" = xno; then
962    # jtreg disabled
963    AC_MSG_CHECKING([for jtreg])
964    AC_MSG_RESULT(no)
965  else
966    if test "x$with_jtreg" != xyes; then
967      # with path specified.
968      JT_HOME="$with_jtreg"
969    fi
970
971    if test "x$JT_HOME" != x; then
972      AC_MSG_CHECKING([for jtreg])
973
974      # use JT_HOME enviroment var.
975      BASIC_FIXUP_PATH([JT_HOME])
976
977      # jtreg win32 script works for everybody
978      JTREGEXE="$JT_HOME/bin/jtreg"
979
980      if test ! -f "$JTREGEXE"; then
981        AC_MSG_ERROR([JTReg executable does not exist: $JTREGEXE])
982      fi
983
984      AC_MSG_RESULT($JTREGEXE)
985    else
986      # try to find jtreg on path
987      BASIC_REQUIRE_PROGS(JTREGEXE, jtreg)
988      JT_HOME="`$DIRNAME $JTREGEXE`"
989    fi
990  fi
991
992  AC_SUBST(JT_HOME)
993  AC_SUBST(JTREGEXE)
994])
995