< prev index next >

make/autoconf/toolchain.m4

Print this page
rev 59102 : imported patch build


  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 m4_include([toolchain_windows.m4])
  36 
  37 # All valid toolchains, regardless of platform (used by help.m4)
  38 VALID_TOOLCHAINS_all="gcc clang solstudio xlc microsoft"
  39 
  40 # These toolchains are valid on different platforms
  41 VALID_TOOLCHAINS_linux="gcc clang"
  42 VALID_TOOLCHAINS_solaris="solstudio"
  43 VALID_TOOLCHAINS_macosx="gcc clang"
  44 VALID_TOOLCHAINS_aix="xlc"
  45 VALID_TOOLCHAINS_windows="microsoft"
  46 
  47 # Toolchain descriptions
  48 TOOLCHAIN_DESCRIPTION_clang="clang/LLVM"
  49 TOOLCHAIN_DESCRIPTION_gcc="GNU Compiler Collection"
  50 TOOLCHAIN_DESCRIPTION_microsoft="Microsoft Visual Studio"
  51 TOOLCHAIN_DESCRIPTION_solstudio="Oracle Solaris Studio"
  52 TOOLCHAIN_DESCRIPTION_xlc="IBM XL C/C++"
  53 
  54 # Minimum supported versions, empty means unspecified
  55 TOOLCHAIN_MINIMUM_VERSION_clang="3.2"
  56 TOOLCHAIN_MINIMUM_VERSION_gcc="5.0"
  57 TOOLCHAIN_MINIMUM_VERSION_microsoft="16.00.30319.01" # VS2010
  58 TOOLCHAIN_MINIMUM_VERSION_solstudio="5.13"
  59 TOOLCHAIN_MINIMUM_VERSION_xlc=""
  60 
  61 # Minimum supported linker versions, empty means unspecified
  62 TOOLCHAIN_MINIMUM_LD_VERSION_gcc="2.18"
  63 
  64 # Prepare the system so that TOOLCHAIN_CHECK_COMPILER_VERSION can be called.
  65 # Must have CC_VERSION_NUMBER and CXX_VERSION_NUMBER.
  66 # $1 - optional variable prefix for compiler and version variables (BUILD_)
  67 # $2 - optional variable prefix for comparable variable (OPENJDK_BUILD_)
  68 # $3 - optional human readable description for the type of compilers ("build " or "")
  69 AC_DEFUN([TOOLCHAIN_PREPARE_FOR_VERSION_COMPARISONS],
  70 [
  71   if test "x[$]$1CC_VERSION_NUMBER" != "x[$]$1CXX_VERSION_NUMBER"; then
  72     AC_MSG_WARN([The $3C and C++ compilers have different version numbers, [$]$1CC_VERSION_NUMBER vs [$]$1CXX_VERSION_NUMBER.])
  73     AC_MSG_WARN([This typically indicates a broken setup, and is not supported])
  74   fi
  75 
  76   # We only check CC_VERSION_NUMBER since we assume CXX_VERSION_NUMBER is equal.
  77   if [ [[ "[$]$1CC_VERSION_NUMBER" =~ (.*\.){4} ]] ]; then
  78     AC_MSG_WARN([C compiler version number has more than four parts (W.X.Y.Z): [$]$1CC_VERSION_NUMBER. Comparisons might be wrong.])


 279   AC_SUBST(TOOLCHAIN_TYPE)
 280 
 281   # on AIX, check for xlclang++ on the PATH and TOOLCHAIN_PATH and use it if it is available
 282   if test "x$OPENJDK_TARGET_OS" = xaix; then
 283     if test "x$TOOLCHAIN_PATH" != x; then
 284       XLC_TEST_PATH=${TOOLCHAIN_PATH}/
 285     fi
 286 
 287     XLCLANG_VERSION_OUTPUT=`${XLC_TEST_PATH}xlclang++ -qversion 2>&1 | $HEAD -n 1`
 288     $ECHO "$XLCLANG_VERSION_OUTPUT" | $GREP "IBM XL C/C++ for AIX" > /dev/null
 289     if test $? -eq 0; then
 290       AC_MSG_NOTICE([xlclang++ output: $XLCLANG_VERSION_OUTPUT])
 291     else
 292       AC_MSG_ERROR([xlclang++ version output check failed, output: $XLCLANG_VERSION_OUTPUT])
 293     fi
 294   fi
 295 
 296   TOOLCHAIN_CC_BINARY_clang="clang"
 297   TOOLCHAIN_CC_BINARY_gcc="gcc"
 298   TOOLCHAIN_CC_BINARY_microsoft="cl$EXE_SUFFIX"
 299   TOOLCHAIN_CC_BINARY_solstudio="cc"
 300   TOOLCHAIN_CC_BINARY_xlc="xlclang"
 301 
 302   TOOLCHAIN_CXX_BINARY_clang="clang++"
 303   TOOLCHAIN_CXX_BINARY_gcc="g++"
 304   TOOLCHAIN_CXX_BINARY_microsoft="cl$EXE_SUFFIX"
 305   TOOLCHAIN_CXX_BINARY_solstudio="CC"
 306   TOOLCHAIN_CXX_BINARY_xlc="xlclang++"
 307 
 308   # Use indirect variable referencing
 309   toolchain_var_name=TOOLCHAIN_DESCRIPTION_$TOOLCHAIN_TYPE
 310   TOOLCHAIN_DESCRIPTION=${!toolchain_var_name}
 311   toolchain_var_name=TOOLCHAIN_MINIMUM_VERSION_$TOOLCHAIN_TYPE
 312   TOOLCHAIN_MINIMUM_VERSION=${!toolchain_var_name}
 313   toolchain_var_name=TOOLCHAIN_MINIMUM_LD_VERSION_$TOOLCHAIN_TYPE
 314   TOOLCHAIN_MINIMUM_LD_VERSION=${!toolchain_var_name}
 315   toolchain_var_name=TOOLCHAIN_CC_BINARY_$TOOLCHAIN_TYPE
 316   TOOLCHAIN_CC_BINARY=${!toolchain_var_name}
 317   toolchain_var_name=TOOLCHAIN_CXX_BINARY_$TOOLCHAIN_TYPE
 318   TOOLCHAIN_CXX_BINARY=${!toolchain_var_name}
 319 
 320   TOOLCHAIN_SETUP_FILENAME_PATTERNS
 321 
 322   if test "x$TOOLCHAIN_TYPE" = "x$DEFAULT_TOOLCHAIN"; then
 323     AC_MSG_NOTICE([Using default toolchain $TOOLCHAIN_TYPE ($TOOLCHAIN_DESCRIPTION)])
 324   else
 325     AC_MSG_NOTICE([Using user selected toolchain $TOOLCHAIN_TYPE ($TOOLCHAIN_DESCRIPTION). Default toolchain is $DEFAULT_TOOLCHAIN.])


 392 
 393   # Restore the flags to the user specified values.
 394   # This is necessary since AC_PROG_CC defaults CFLAGS to "-g -O2"
 395   CFLAGS="$ORG_CFLAGS"
 396   CXXFLAGS="$ORG_CXXFLAGS"
 397 ])
 398 
 399 # Check if a compiler is of the toolchain type we expect, and save the version
 400 # information from it. If the compiler does not match the expected type,
 401 # this function will abort using AC_MSG_ERROR. If it matches, the version will
 402 # be stored in CC_VERSION_NUMBER/CXX_VERSION_NUMBER (as a dotted number), and
 403 # the full version string in CC_VERSION_STRING/CXX_VERSION_STRING.
 404 #
 405 # $1 = compiler to test (CC or CXX)
 406 # $2 = human readable name of compiler (C or C++)
 407 AC_DEFUN([TOOLCHAIN_EXTRACT_COMPILER_VERSION],
 408 [
 409   COMPILER=[$]$1
 410   COMPILER_NAME=$2
 411 
 412   if test "x$TOOLCHAIN_TYPE" = xsolstudio; then
 413     # cc -V output typically looks like
 414     #     cc: Sun C 5.12 Linux_i386 2011/11/16
 415     # or
 416     #     cc: Studio 12.5 Sun C 5.14 SunOS_sparc 2016/05/31
 417     COMPILER_VERSION_OUTPUT=`$COMPILER -V 2>&1`
 418     # Check that this is likely to be the Solaris Studio cc.
 419     $ECHO "$COMPILER_VERSION_OUTPUT" | $GREP "^.* Sun $COMPILER_NAME" > /dev/null
 420     if test $? -ne 0; then
 421       ALT_VERSION_OUTPUT=`$COMPILER --version 2>&1`
 422       AC_MSG_NOTICE([The $COMPILER_NAME compiler (located as $COMPILER) does not seem to be the required $TOOLCHAIN_TYPE compiler.])
 423       AC_MSG_NOTICE([The result from running with -V was: "$COMPILER_VERSION_OUTPUT"])
 424       AC_MSG_NOTICE([The result from running with --version was: "$ALT_VERSION_OUTPUT"])
 425       AC_MSG_ERROR([A $TOOLCHAIN_TYPE compiler is required. Try setting --with-tools-dir.])
 426     fi
 427     # Remove usage instructions (if present), and
 428     # collapse compiler output into a single line
 429     COMPILER_VERSION_STRING=`$ECHO $COMPILER_VERSION_OUTPUT | \
 430         $SED -e 's/ *@<:@Uu@:>@sage:.*//'`
 431     COMPILER_VERSION_NUMBER=`$ECHO $COMPILER_VERSION_OUTPUT | \
 432         $SED -e "s/^.*@<:@ ,\t@:>@$COMPILER_NAME@<:@ ,\t@:>@\(@<:@1-9@:>@\.@<:@0-9@:>@@<:@0-9@:>@*\).*/\1/"`
 433   elif test  "x$TOOLCHAIN_TYPE" = xxlc; then
 434     # xlc -qversion output typically looks like
 435     #     IBM XL C/C++ for AIX, V11.1 (5724-X13)
 436     #     Version: 11.01.0000.0015
 437     COMPILER_VERSION_OUTPUT=`$COMPILER -qversion 2>&1`
 438     # Check that this is likely to be the IBM XL C compiler.
 439     $ECHO "$COMPILER_VERSION_OUTPUT" | $GREP "IBM XL C" > /dev/null
 440     if test $? -ne 0; then
 441       ALT_VERSION_OUTPUT=`$COMPILER --version 2>&1`
 442       AC_MSG_NOTICE([The $COMPILER_NAME compiler (located as $COMPILER) does not seem to be the required $TOOLCHAIN_TYPE compiler.])
 443       AC_MSG_NOTICE([The result from running with -qversion was: "$COMPILER_VERSION_OUTPUT"])
 444       AC_MSG_NOTICE([The result from running with --version was: "$ALT_VERSION_OUTPUT"])
 445       AC_MSG_ERROR([A $TOOLCHAIN_TYPE compiler is required. Try setting --with-tools-dir.])
 446     fi
 447     # Collapse compiler output into a single line
 448     COMPILER_VERSION_STRING=`$ECHO $COMPILER_VERSION_OUTPUT`
 449     COMPILER_VERSION_NUMBER=`$ECHO $COMPILER_VERSION_OUTPUT | \
 450         $SED -e 's/^.*, V\(@<:@1-9@:>@@<:@0-9.@:>@*\).*$/\1/'`
 451   elif test  "x$TOOLCHAIN_TYPE" = xmicrosoft; then
 452     # There is no specific version flag, but all output starts with a version string.
 453     # First line typically looks something like:


 598     if test "x$COMPILER_BASENAME" = "xccache"; then
 599       AC_MSG_NOTICE([Please use --enable-ccache instead of providing a wrapped compiler.])
 600       AC_MSG_ERROR([$TEST_COMPILER is a symbolic link to ccache. This is not supported.])
 601     fi
 602   fi
 603 
 604   TOOLCHAIN_EXTRACT_COMPILER_VERSION([$1], [$COMPILER_NAME])
 605 ])
 606 
 607 # Retrieve the linker version number and store it in LD_VERSION_NUMBER
 608 # (as a dotted number), and
 609 # the full version string in LD_VERSION_STRING.
 610 #
 611 # $1 = linker to test (LD or BUILD_LD)
 612 # $2 = human readable name of linker (Linker or BuildLinker)
 613 AC_DEFUN([TOOLCHAIN_EXTRACT_LD_VERSION],
 614 [
 615   LINKER=[$]$1
 616   LINKER_NAME="$2"
 617 
 618   if test "x$TOOLCHAIN_TYPE" = xsolstudio; then
 619     # cc -Wl,-V output typically looks like
 620     #   ld: Software Generation Utilities - Solaris Link Editors: 5.11-1.2329
 621 
 622     # solstudio cc requires us to have an existing file to pass as argument,
 623     # but it need not be a syntactically correct C file, so just use
 624     # ourself. :) The intermediate 'cat' is needed to stop ld from leaving
 625     # a lingering a.out (!).
 626     LINKER_VERSION_STRING=`$LD -Wl,-V $TOPDIR/configure 2>&1 | $CAT | $HEAD -n 1 | $SED -e 's/ld: //'`
 627     # Extract version number
 628     [ LINKER_VERSION_NUMBER=`$ECHO $LINKER_VERSION_STRING | \
 629         $SED -e 's/.* \([0-9][0-9]*\.[0-9][0-9]*\)-\([0-9][0-9]*\.[0-9][0-9]*\)/\1.\2/'` ]
 630   elif test  "x$TOOLCHAIN_TYPE" = xxlc; then
 631     LINKER_VERSION_STRING="Unknown"
 632     LINKER_VERSION_NUMBER="0.0"
 633   elif test  "x$TOOLCHAIN_TYPE" = xmicrosoft; then
 634     # There is no specific version flag, but all output starts with a version string.
 635     # First line typically looks something like:
 636     #   Microsoft (R) Incremental Linker Version 12.00.31101.0
 637     LINKER_VERSION_STRING=`$LD 2>&1 | $HEAD -n 1 | $TR -d '\r'`
 638     # Extract version number
 639     [ LINKER_VERSION_NUMBER=`$ECHO $LINKER_VERSION_STRING | \
 640         $SED -e 's/.* \([0-9][0-9]*\(\.[0-9][0-9]*\)*\).*/\1/'` ]
 641   elif test  "x$TOOLCHAIN_TYPE" = xgcc; then
 642     # gcc -Wl,-version output typically looks like:
 643     #   GNU ld (GNU Binutils for Ubuntu) 2.26.1
 644     #   Copyright (C) 2015 Free Software Foundation, Inc.
 645     #   This program is free software; [...]
 646     # If using gold it will look like:
 647     #   GNU gold (GNU Binutils 2.30) 1.15
 648     LINKER_VERSION_STRING=`$LD -Wl,--version 2> /dev/null | $HEAD -n 1`
 649     # Extract version number
 650     if [ [[ "$LINKER_VERSION_STRING" == *gold* ]] ]; then


 752   fi
 753   AC_SUBST(LD)
 754   AC_SUBST(LD_JAOTC)
 755   # FIXME: it should be CXXLD, according to standard (cf CXXCPP)
 756   AC_SUBST(LDCXX)
 757 
 758   TOOLCHAIN_EXTRACT_LD_VERSION([LD], [linker])
 759   TOOLCHAIN_PREPARE_FOR_LD_VERSION_COMPARISONS
 760 
 761   if test "x$TOOLCHAIN_MINIMUM_LD_VERSION" != x; then
 762     TOOLCHAIN_CHECK_LINKER_VERSION(VERSION: $TOOLCHAIN_MINIMUM_LD_VERSION,
 763         IF_OLDER_THAN: [
 764           AC_MSG_WARN([You are using a linker older than $TOOLCHAIN_MINIMUM_LD_VERSION. This is not a supported configuration.])
 765         ]
 766     )
 767   fi
 768 
 769   #
 770   # Setup the assembler (AS)
 771   #
 772   if test "x$OPENJDK_TARGET_OS" = xsolaris; then
 773     UTIL_PATH_PROGS(AS, as)
 774     UTIL_FIXUP_EXECUTABLE(AS)
 775     if test "x$AS" = x; then
 776       AC_MSG_ERROR([Solaris assembler (as) is required. Please install via "pkg install pkg:/developer/assembler".])
 777     fi
 778   else
 779     # FIXME: is this correct for microsoft?
 780     AS="$CC -c"
 781   fi
 782   AC_SUBST(AS)
 783 
 784   #
 785   # Setup the archiver (AR)
 786   #
 787   if test "x$TOOLCHAIN_TYPE" = xmicrosoft; then
 788     # The corresponding ar tool is lib.exe (used to create static libraries)
 789     AC_CHECK_PROG([AR], [lib$EXE_SUFFIX],[lib$EXE_SUFFIX],,,)
 790   elif test "x$TOOLCHAIN_TYPE" = xgcc; then
 791     UTIL_CHECK_TOOLS(AR, ar gcc-ar)
 792   else
 793     UTIL_CHECK_TOOLS(AR, ar)
 794   fi
 795   UTIL_FIXUP_EXECUTABLE(AR)
 796 ])
 797 
 798 # Setup additional tools that is considered a part of the toolchain, but not the
 799 # core part. Many of these are highly platform-specific and do not exist,
 800 # and/or are not needed on all platforms.
 801 AC_DEFUN_ONCE([TOOLCHAIN_DETECT_TOOLCHAIN_EXTRA],


 810   fi
 811 
 812   if test "x$TOOLCHAIN_TYPE" = xmicrosoft; then
 813     AC_CHECK_PROG([MT], [mt$EXE_SUFFIX], [mt$EXE_SUFFIX],,, [/usr/bin/mt])
 814     UTIL_FIXUP_EXECUTABLE(MT)
 815     # Setup the resource compiler (RC)
 816     AC_CHECK_PROG([RC], [rc$EXE_SUFFIX], [rc$EXE_SUFFIX],,, [/usr/bin/rc])
 817     UTIL_FIXUP_EXECUTABLE(RC)
 818     AC_CHECK_PROG([DUMPBIN], [dumpbin$EXE_SUFFIX], [dumpbin$EXE_SUFFIX],,,)
 819     UTIL_FIXUP_EXECUTABLE(DUMPBIN)
 820     # We need to check for 'msbuild.exe' because at the place where we expect to
 821     # find 'msbuild.exe' there's also a directory called 'msbuild' and configure
 822     # won't find the 'msbuild.exe' executable in that case (and the
 823     # 'ac_executable_extensions' is unusable due to performance reasons).
 824     # Notice that we intentionally don't fix up the path to MSBUILD because we
 825     # will call it in a DOS shell during freetype detection on Windows (see
 826     # 'LIB_SETUP_FREETYPE' in "libraries.m4"
 827     AC_CHECK_PROG([MSBUILD], [msbuild$EXE_SUFFIX], [msbuild$EXE_SUFFIX],,,)
 828   fi
 829 
 830   if test "x$OPENJDK_TARGET_OS" = xsolaris; then
 831     UTIL_PATH_PROGS(STRIP, strip)
 832     UTIL_FIXUP_EXECUTABLE(STRIP)
 833     UTIL_PATH_PROGS(NM, nm)
 834     UTIL_FIXUP_EXECUTABLE(NM)
 835     UTIL_PATH_PROGS(GNM, gnm)
 836     UTIL_FIXUP_EXECUTABLE(GNM)
 837   elif test "x$OPENJDK_TARGET_OS" != xwindows; then
 838     # FIXME: we should unify this with the solaris case above.
 839     UTIL_CHECK_TOOLS(STRIP, strip)
 840     UTIL_FIXUP_EXECUTABLE(STRIP)
 841     if test "x$TOOLCHAIN_TYPE" = xgcc; then
 842       UTIL_CHECK_TOOLS(NM, nm gcc-nm)
 843     else
 844       UTIL_CHECK_TOOLS(NM, nm)
 845     fi
 846     UTIL_FIXUP_EXECUTABLE(NM)
 847     GNM="$NM"
 848     AC_SUBST(GNM)
 849   fi
 850 
 851   # objcopy is used for moving debug symbols to separate files when
 852   # full debug symbols are enabled.
 853   if test "x$OPENJDK_TARGET_OS" = xsolaris || test "x$OPENJDK_TARGET_OS" = xlinux; then
 854     UTIL_CHECK_TOOLS(OBJCOPY, [gobjcopy objcopy])
 855     # Only call fixup if objcopy was found.
 856     if test -n "$OBJCOPY"; then
 857       UTIL_FIXUP_EXECUTABLE(OBJCOPY)
 858       if test "x$OPENJDK_BUILD_OS" = xsolaris; then
 859         # objcopy prior to 2.21.1 on solaris is broken and is not usable.
 860         # Rewrite objcopy version output to VALID_VERSION or BAD_VERSION.
 861         # - version number is last blank separate word on first line
 862         # - version number formats that have been seen:
 863         #   - <major>.<minor>
 864         #   - <major>.<minor>.<micro>
 865         OBJCOPY_VERSION=`$OBJCOPY --version | $HEAD -n 1`
 866         # The outer [ ] is to prevent m4 from eating the [] in the sed expression.
 867         [ OBJCOPY_VERSION_CHECK=`$ECHO $OBJCOPY_VERSION | $SED -n \
 868               -e 's/.* //' \
 869               -e '/^[01]\./b bad' \
 870               -e '/^2\./{' \
 871               -e '  s/^2\.//' \
 872               -e '  /^[0-9]$/b bad' \
 873               -e '  /^[0-9]\./b bad' \
 874               -e '  /^1[0-9]$/b bad' \
 875               -e '  /^1[0-9]\./b bad' \
 876               -e '  /^20\./b bad' \
 877               -e '  /^21\.0$/b bad' \
 878               -e '  /^21\.0\./b bad' \
 879               -e '}' \
 880               -e ':good' \
 881               -e 's/.*/VALID_VERSION/p' \
 882               -e 'q' \
 883               -e ':bad' \
 884               -e 's/.*/BAD_VERSION/p' \
 885               -e 'q'` ]
 886         if test "x$OBJCOPY_VERSION_CHECK" = xBAD_VERSION; then
 887           OBJCOPY=
 888           AC_MSG_WARN([Ignoring found objcopy since it is broken (prior to 2.21.1). No debug symbols will be generated.])
 889           AC_MSG_NOTICE([objcopy reports version $OBJCOPY_VERSION])
 890           AC_MSG_NOTICE([Note: patch 149063-01 or newer contains the correct Solaris 10 SPARC version])
 891           AC_MSG_NOTICE([Note: patch 149064-01 or newer contains the correct Solaris 10 X86 version])
 892           AC_MSG_NOTICE([Note: Solaris 11 Update 1 contains the correct version])
 893         fi
 894       fi
 895     fi
 896   fi
 897 
 898   UTIL_CHECK_TOOLS(OBJDUMP, [gobjdump objdump])
 899   if test "x$OBJDUMP" != x; then
 900     # Only used for compare.sh; we can live without it. UTIL_FIXUP_EXECUTABLE
 901     # bails if argument is missing.
 902     UTIL_FIXUP_EXECUTABLE(OBJDUMP)
 903   fi
 904 
 905   case $TOOLCHAIN_TYPE in
 906     gcc|clang|solstudio)
 907       UTIL_CHECK_TOOLS(CXXFILT, [c++filt])
 908       UTIL_CHECK_NONEMPTY(CXXFILT)
 909       UTIL_FIXUP_EXECUTABLE(CXXFILT)
 910       ;;
 911   esac
 912 ])
 913 
 914 # Setup the build tools (i.e, the compiler and linker used to build programs
 915 # that should be run on the build platform, not the target platform, as a build
 916 # helper). Since the non-cross-compile case uses the normal, target compilers
 917 # for this, we can only do this after these have been setup.
 918 AC_DEFUN_ONCE([TOOLCHAIN_SETUP_BUILD_COMPILERS],
 919 [
 920   if test "x$COMPILE_TYPE" = "xcross"; then
 921     # Now we need to find a C/C++ compiler that can build executables for the
 922     # build platform. We can't use the AC_PROG_CC macro, since it can only be
 923     # used once. Also, we need to do this without adding a tools dir to the
 924     # path, otherwise we might pick up cross-compilers which don't use standard
 925     # naming.
 926 




  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 m4_include([toolchain_windows.m4])
  36 
  37 # All valid toolchains, regardless of platform (used by help.m4)
  38 VALID_TOOLCHAINS_all="gcc clang xlc microsoft"
  39 
  40 # These toolchains are valid on different platforms
  41 VALID_TOOLCHAINS_linux="gcc clang"

  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_xlc="IBM XL C/C++"
  51 
  52 # Minimum supported versions, empty means unspecified
  53 TOOLCHAIN_MINIMUM_VERSION_clang="3.2"
  54 TOOLCHAIN_MINIMUM_VERSION_gcc="5.0"
  55 TOOLCHAIN_MINIMUM_VERSION_microsoft="16.00.30319.01" # VS2010

  56 TOOLCHAIN_MINIMUM_VERSION_xlc=""
  57 
  58 # Minimum supported linker versions, empty means unspecified
  59 TOOLCHAIN_MINIMUM_LD_VERSION_gcc="2.18"
  60 
  61 # Prepare the system so that TOOLCHAIN_CHECK_COMPILER_VERSION can be called.
  62 # Must have CC_VERSION_NUMBER and CXX_VERSION_NUMBER.
  63 # $1 - optional variable prefix for compiler and version variables (BUILD_)
  64 # $2 - optional variable prefix for comparable variable (OPENJDK_BUILD_)
  65 # $3 - optional human readable description for the type of compilers ("build " or "")
  66 AC_DEFUN([TOOLCHAIN_PREPARE_FOR_VERSION_COMPARISONS],
  67 [
  68   if test "x[$]$1CC_VERSION_NUMBER" != "x[$]$1CXX_VERSION_NUMBER"; then
  69     AC_MSG_WARN([The $3C and C++ compilers have different version numbers, [$]$1CC_VERSION_NUMBER vs [$]$1CXX_VERSION_NUMBER.])
  70     AC_MSG_WARN([This typically indicates a broken setup, and is not supported])
  71   fi
  72 
  73   # We only check CC_VERSION_NUMBER since we assume CXX_VERSION_NUMBER is equal.
  74   if [ [[ "[$]$1CC_VERSION_NUMBER" =~ (.*\.){4} ]] ]; then
  75     AC_MSG_WARN([C compiler version number has more than four parts (W.X.Y.Z): [$]$1CC_VERSION_NUMBER. Comparisons might be wrong.])


 276   AC_SUBST(TOOLCHAIN_TYPE)
 277 
 278   # on AIX, check for xlclang++ on the PATH and TOOLCHAIN_PATH and use it if it is available
 279   if test "x$OPENJDK_TARGET_OS" = xaix; then
 280     if test "x$TOOLCHAIN_PATH" != x; then
 281       XLC_TEST_PATH=${TOOLCHAIN_PATH}/
 282     fi
 283 
 284     XLCLANG_VERSION_OUTPUT=`${XLC_TEST_PATH}xlclang++ -qversion 2>&1 | $HEAD -n 1`
 285     $ECHO "$XLCLANG_VERSION_OUTPUT" | $GREP "IBM XL C/C++ for AIX" > /dev/null
 286     if test $? -eq 0; then
 287       AC_MSG_NOTICE([xlclang++ output: $XLCLANG_VERSION_OUTPUT])
 288     else
 289       AC_MSG_ERROR([xlclang++ version output check failed, output: $XLCLANG_VERSION_OUTPUT])
 290     fi
 291   fi
 292 
 293   TOOLCHAIN_CC_BINARY_clang="clang"
 294   TOOLCHAIN_CC_BINARY_gcc="gcc"
 295   TOOLCHAIN_CC_BINARY_microsoft="cl$EXE_SUFFIX"

 296   TOOLCHAIN_CC_BINARY_xlc="xlclang"
 297 
 298   TOOLCHAIN_CXX_BINARY_clang="clang++"
 299   TOOLCHAIN_CXX_BINARY_gcc="g++"
 300   TOOLCHAIN_CXX_BINARY_microsoft="cl$EXE_SUFFIX"

 301   TOOLCHAIN_CXX_BINARY_xlc="xlclang++"
 302 
 303   # Use indirect variable referencing
 304   toolchain_var_name=TOOLCHAIN_DESCRIPTION_$TOOLCHAIN_TYPE
 305   TOOLCHAIN_DESCRIPTION=${!toolchain_var_name}
 306   toolchain_var_name=TOOLCHAIN_MINIMUM_VERSION_$TOOLCHAIN_TYPE
 307   TOOLCHAIN_MINIMUM_VERSION=${!toolchain_var_name}
 308   toolchain_var_name=TOOLCHAIN_MINIMUM_LD_VERSION_$TOOLCHAIN_TYPE
 309   TOOLCHAIN_MINIMUM_LD_VERSION=${!toolchain_var_name}
 310   toolchain_var_name=TOOLCHAIN_CC_BINARY_$TOOLCHAIN_TYPE
 311   TOOLCHAIN_CC_BINARY=${!toolchain_var_name}
 312   toolchain_var_name=TOOLCHAIN_CXX_BINARY_$TOOLCHAIN_TYPE
 313   TOOLCHAIN_CXX_BINARY=${!toolchain_var_name}
 314 
 315   TOOLCHAIN_SETUP_FILENAME_PATTERNS
 316 
 317   if test "x$TOOLCHAIN_TYPE" = "x$DEFAULT_TOOLCHAIN"; then
 318     AC_MSG_NOTICE([Using default toolchain $TOOLCHAIN_TYPE ($TOOLCHAIN_DESCRIPTION)])
 319   else
 320     AC_MSG_NOTICE([Using user selected toolchain $TOOLCHAIN_TYPE ($TOOLCHAIN_DESCRIPTION). Default toolchain is $DEFAULT_TOOLCHAIN.])


 387 
 388   # Restore the flags to the user specified values.
 389   # This is necessary since AC_PROG_CC defaults CFLAGS to "-g -O2"
 390   CFLAGS="$ORG_CFLAGS"
 391   CXXFLAGS="$ORG_CXXFLAGS"
 392 ])
 393 
 394 # Check if a compiler is of the toolchain type we expect, and save the version
 395 # information from it. If the compiler does not match the expected type,
 396 # this function will abort using AC_MSG_ERROR. If it matches, the version will
 397 # be stored in CC_VERSION_NUMBER/CXX_VERSION_NUMBER (as a dotted number), and
 398 # the full version string in CC_VERSION_STRING/CXX_VERSION_STRING.
 399 #
 400 # $1 = compiler to test (CC or CXX)
 401 # $2 = human readable name of compiler (C or C++)
 402 AC_DEFUN([TOOLCHAIN_EXTRACT_COMPILER_VERSION],
 403 [
 404   COMPILER=[$]$1
 405   COMPILER_NAME=$2
 406 
 407   if test  "x$TOOLCHAIN_TYPE" = xxlc; then





















 408     # xlc -qversion output typically looks like
 409     #     IBM XL C/C++ for AIX, V11.1 (5724-X13)
 410     #     Version: 11.01.0000.0015
 411     COMPILER_VERSION_OUTPUT=`$COMPILER -qversion 2>&1`
 412     # Check that this is likely to be the IBM XL C compiler.
 413     $ECHO "$COMPILER_VERSION_OUTPUT" | $GREP "IBM XL C" > /dev/null
 414     if test $? -ne 0; then
 415       ALT_VERSION_OUTPUT=`$COMPILER --version 2>&1`
 416       AC_MSG_NOTICE([The $COMPILER_NAME compiler (located as $COMPILER) does not seem to be the required $TOOLCHAIN_TYPE compiler.])
 417       AC_MSG_NOTICE([The result from running with -qversion was: "$COMPILER_VERSION_OUTPUT"])
 418       AC_MSG_NOTICE([The result from running with --version was: "$ALT_VERSION_OUTPUT"])
 419       AC_MSG_ERROR([A $TOOLCHAIN_TYPE compiler is required. Try setting --with-tools-dir.])
 420     fi
 421     # Collapse compiler output into a single line
 422     COMPILER_VERSION_STRING=`$ECHO $COMPILER_VERSION_OUTPUT`
 423     COMPILER_VERSION_NUMBER=`$ECHO $COMPILER_VERSION_OUTPUT | \
 424         $SED -e 's/^.*, V\(@<:@1-9@:>@@<:@0-9.@:>@*\).*$/\1/'`
 425   elif test  "x$TOOLCHAIN_TYPE" = xmicrosoft; then
 426     # There is no specific version flag, but all output starts with a version string.
 427     # First line typically looks something like:


 572     if test "x$COMPILER_BASENAME" = "xccache"; then
 573       AC_MSG_NOTICE([Please use --enable-ccache instead of providing a wrapped compiler.])
 574       AC_MSG_ERROR([$TEST_COMPILER is a symbolic link to ccache. This is not supported.])
 575     fi
 576   fi
 577 
 578   TOOLCHAIN_EXTRACT_COMPILER_VERSION([$1], [$COMPILER_NAME])
 579 ])
 580 
 581 # Retrieve the linker version number and store it in LD_VERSION_NUMBER
 582 # (as a dotted number), and
 583 # the full version string in LD_VERSION_STRING.
 584 #
 585 # $1 = linker to test (LD or BUILD_LD)
 586 # $2 = human readable name of linker (Linker or BuildLinker)
 587 AC_DEFUN([TOOLCHAIN_EXTRACT_LD_VERSION],
 588 [
 589   LINKER=[$]$1
 590   LINKER_NAME="$2"
 591 
 592   if test  "x$TOOLCHAIN_TYPE" = xxlc; then












 593     LINKER_VERSION_STRING="Unknown"
 594     LINKER_VERSION_NUMBER="0.0"
 595   elif test  "x$TOOLCHAIN_TYPE" = xmicrosoft; then
 596     # There is no specific version flag, but all output starts with a version string.
 597     # First line typically looks something like:
 598     #   Microsoft (R) Incremental Linker Version 12.00.31101.0
 599     LINKER_VERSION_STRING=`$LD 2>&1 | $HEAD -n 1 | $TR -d '\r'`
 600     # Extract version number
 601     [ LINKER_VERSION_NUMBER=`$ECHO $LINKER_VERSION_STRING | \
 602         $SED -e 's/.* \([0-9][0-9]*\(\.[0-9][0-9]*\)*\).*/\1/'` ]
 603   elif test  "x$TOOLCHAIN_TYPE" = xgcc; then
 604     # gcc -Wl,-version output typically looks like:
 605     #   GNU ld (GNU Binutils for Ubuntu) 2.26.1
 606     #   Copyright (C) 2015 Free Software Foundation, Inc.
 607     #   This program is free software; [...]
 608     # If using gold it will look like:
 609     #   GNU gold (GNU Binutils 2.30) 1.15
 610     LINKER_VERSION_STRING=`$LD -Wl,--version 2> /dev/null | $HEAD -n 1`
 611     # Extract version number
 612     if [ [[ "$LINKER_VERSION_STRING" == *gold* ]] ]; then


 714   fi
 715   AC_SUBST(LD)
 716   AC_SUBST(LD_JAOTC)
 717   # FIXME: it should be CXXLD, according to standard (cf CXXCPP)
 718   AC_SUBST(LDCXX)
 719 
 720   TOOLCHAIN_EXTRACT_LD_VERSION([LD], [linker])
 721   TOOLCHAIN_PREPARE_FOR_LD_VERSION_COMPARISONS
 722 
 723   if test "x$TOOLCHAIN_MINIMUM_LD_VERSION" != x; then
 724     TOOLCHAIN_CHECK_LINKER_VERSION(VERSION: $TOOLCHAIN_MINIMUM_LD_VERSION,
 725         IF_OLDER_THAN: [
 726           AC_MSG_WARN([You are using a linker older than $TOOLCHAIN_MINIMUM_LD_VERSION. This is not a supported configuration.])
 727         ]
 728     )
 729   fi
 730 
 731   #
 732   # Setup the assembler (AS)
 733   #







 734   # FIXME: is this correct for microsoft?
 735   AS="$CC -c"

 736   AC_SUBST(AS)
 737 
 738   #
 739   # Setup the archiver (AR)
 740   #
 741   if test "x$TOOLCHAIN_TYPE" = xmicrosoft; then
 742     # The corresponding ar tool is lib.exe (used to create static libraries)
 743     AC_CHECK_PROG([AR], [lib$EXE_SUFFIX],[lib$EXE_SUFFIX],,,)
 744   elif test "x$TOOLCHAIN_TYPE" = xgcc; then
 745     UTIL_CHECK_TOOLS(AR, ar gcc-ar)
 746   else
 747     UTIL_CHECK_TOOLS(AR, ar)
 748   fi
 749   UTIL_FIXUP_EXECUTABLE(AR)
 750 ])
 751 
 752 # Setup additional tools that is considered a part of the toolchain, but not the
 753 # core part. Many of these are highly platform-specific and do not exist,
 754 # and/or are not needed on all platforms.
 755 AC_DEFUN_ONCE([TOOLCHAIN_DETECT_TOOLCHAIN_EXTRA],


 764   fi
 765 
 766   if test "x$TOOLCHAIN_TYPE" = xmicrosoft; then
 767     AC_CHECK_PROG([MT], [mt$EXE_SUFFIX], [mt$EXE_SUFFIX],,, [/usr/bin/mt])
 768     UTIL_FIXUP_EXECUTABLE(MT)
 769     # Setup the resource compiler (RC)
 770     AC_CHECK_PROG([RC], [rc$EXE_SUFFIX], [rc$EXE_SUFFIX],,, [/usr/bin/rc])
 771     UTIL_FIXUP_EXECUTABLE(RC)
 772     AC_CHECK_PROG([DUMPBIN], [dumpbin$EXE_SUFFIX], [dumpbin$EXE_SUFFIX],,,)
 773     UTIL_FIXUP_EXECUTABLE(DUMPBIN)
 774     # We need to check for 'msbuild.exe' because at the place where we expect to
 775     # find 'msbuild.exe' there's also a directory called 'msbuild' and configure
 776     # won't find the 'msbuild.exe' executable in that case (and the
 777     # 'ac_executable_extensions' is unusable due to performance reasons).
 778     # Notice that we intentionally don't fix up the path to MSBUILD because we
 779     # will call it in a DOS shell during freetype detection on Windows (see
 780     # 'LIB_SETUP_FREETYPE' in "libraries.m4"
 781     AC_CHECK_PROG([MSBUILD], [msbuild$EXE_SUFFIX], [msbuild$EXE_SUFFIX],,,)
 782   fi
 783 
 784   if test "x$OPENJDK_TARGET_OS" != xwindows; then








 785     UTIL_CHECK_TOOLS(STRIP, strip)
 786     UTIL_FIXUP_EXECUTABLE(STRIP)
 787     if test "x$TOOLCHAIN_TYPE" = xgcc; then
 788       UTIL_CHECK_TOOLS(NM, nm gcc-nm)
 789     else
 790       UTIL_CHECK_TOOLS(NM, nm)
 791     fi
 792     UTIL_FIXUP_EXECUTABLE(NM)
 793     GNM="$NM"
 794     AC_SUBST(GNM)
 795   fi
 796 
 797   # objcopy is used for moving debug symbols to separate files when
 798   # full debug symbols are enabled.
 799   if test "x$OPENJDK_TARGET_OS" = xlinux; then
 800     UTIL_CHECK_TOOLS(OBJCOPY, [gobjcopy objcopy])
 801     # Only call fixup if objcopy was found.
 802     if test -n "$OBJCOPY"; then
 803       UTIL_FIXUP_EXECUTABLE(OBJCOPY)





































 804     fi
 805   fi
 806 
 807   UTIL_CHECK_TOOLS(OBJDUMP, [gobjdump objdump])
 808   if test "x$OBJDUMP" != x; then
 809     # Only used for compare.sh; we can live without it. UTIL_FIXUP_EXECUTABLE
 810     # bails if argument is missing.
 811     UTIL_FIXUP_EXECUTABLE(OBJDUMP)
 812   fi
 813 
 814   case $TOOLCHAIN_TYPE in
 815     gcc|clang)
 816       UTIL_CHECK_TOOLS(CXXFILT, [c++filt])
 817       UTIL_CHECK_NONEMPTY(CXXFILT)
 818       UTIL_FIXUP_EXECUTABLE(CXXFILT)
 819       ;;
 820   esac
 821 ])
 822 
 823 # Setup the build tools (i.e, the compiler and linker used to build programs
 824 # that should be run on the build platform, not the target platform, as a build
 825 # helper). Since the non-cross-compile case uses the normal, target compilers
 826 # for this, we can only do this after these have been setup.
 827 AC_DEFUN_ONCE([TOOLCHAIN_SETUP_BUILD_COMPILERS],
 828 [
 829   if test "x$COMPILE_TYPE" = "xcross"; then
 830     # Now we need to find a C/C++ compiler that can build executables for the
 831     # build platform. We can't use the AC_PROG_CC macro, since it can only be
 832     # used once. Also, we need to do this without adding a tools dir to the
 833     # path, otherwise we might pick up cross-compilers which don't use standard
 834     # naming.
 835 


< prev index next >