toolchain.m4 revision 2251:e51f798914a8
1#
2# Copyright (c) 2011, 2016, 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)
37VALID_TOOLCHAINS_all="gcc clang solstudio xlc microsoft"
38
39# These toolchains are valid on different platforms
40VALID_TOOLCHAINS_linux="gcc clang"
41VALID_TOOLCHAINS_solaris="solstudio"
42VALID_TOOLCHAINS_macosx="gcc clang"
43VALID_TOOLCHAINS_aix="xlc"
44VALID_TOOLCHAINS_windows="microsoft"
45
46# Toolchain descriptions
47TOOLCHAIN_DESCRIPTION_clang="clang/LLVM"
48TOOLCHAIN_DESCRIPTION_gcc="GNU Compiler Collection"
49TOOLCHAIN_DESCRIPTION_microsoft="Microsoft Visual Studio"
50TOOLCHAIN_DESCRIPTION_solstudio="Oracle Solaris Studio"
51TOOLCHAIN_DESCRIPTION_xlc="IBM XL C/C++"
52
53# Minimum supported versions, empty means unspecified
54TOOLCHAIN_MINIMUM_VERSION_clang="3.2"
55TOOLCHAIN_MINIMUM_VERSION_gcc="4.3"
56TOOLCHAIN_MINIMUM_VERSION_microsoft=""
57TOOLCHAIN_MINIMUM_VERSION_solstudio="5.13"
58TOOLCHAIN_MINIMUM_VERSION_xlc=""
59
60# Prepare the system so that TOOLCHAIN_CHECK_COMPILER_VERSION can be called.
61# Must have CC_VERSION_NUMBER and CXX_VERSION_NUMBER.
62# $1 - optional variable prefix for compiler and version variables (BUILD_)
63# $2 - optional variable prefix for comparable variable (OPENJDK_BUILD_)
64AC_DEFUN([TOOLCHAIN_PREPARE_FOR_VERSION_COMPARISONS],
65[
66  if test "x[$]$1CC_VERSION_NUMBER" != "x[$]$1CXX_VERSION_NUMBER"; then
67    AC_MSG_WARN([C and C++ compiler have different version numbers, [$]$1CC_VERSION_NUMBER vs [$]$1CXX_VERSION_NUMBER.])
68    AC_MSG_WARN([This typically indicates a broken setup, and is not supported])
69  fi
70
71  # We only check CC_VERSION_NUMBER since we assume CXX_VERSION_NUMBER is equal.
72  if [ [[ "[$]$1CC_VERSION_NUMBER" =~ (.*\.){3} ]] ]; then
73    AC_MSG_WARN([C compiler version number has more than three parts (X.Y.Z): [$]$1CC_VERSION_NUMBER. Comparisons might be wrong.])
74  fi
75
76  if [ [[  "[$]$1CC_VERSION_NUMBER" =~ [0-9]{6} ]] ]; then
77    AC_MSG_WARN([C compiler version number has a part larger than 99999: [$]$1CC_VERSION_NUMBER. Comparisons might be wrong.])
78  fi
79
80  $2COMPARABLE_ACTUAL_VERSION=`$AWK -F. '{ printf("%05d%05d%05d\n", [$]1, [$]2, [$]3) }' <<< "[$]$1CC_VERSION_NUMBER"`
81])
82
83# Check if the configured compiler (C and C++) is of a specific version or
84# newer. TOOLCHAIN_PREPARE_FOR_VERSION_COMPARISONS must have been called before.
85#
86# Arguments:
87#   VERSION:   The version string to check against the found version
88#   IF_AT_LEAST:   block to run if the compiler is at least this version (>=)
89#   IF_OLDER_THAN:   block to run if the compiler is older than this version (<)
90#   PREFIX:   Optional variable prefix for compiler to compare version for (OPENJDK_BUILD_)
91BASIC_DEFUN_NAMED([TOOLCHAIN_CHECK_COMPILER_VERSION],
92    [*VERSION PREFIX IF_AT_LEAST IF_OLDER_THAN], [$@],
93[
94  # Need to assign to a variable since m4 is blocked from modifying parts in [].
95  REFERENCE_VERSION=ARG_VERSION
96
97  if [ [[ "$REFERENCE_VERSION" =~ (.*\.){3} ]] ]; then
98    AC_MSG_ERROR([Internal error: Cannot compare to ARG_VERSION, only three parts (X.Y.Z) is supported])
99  fi
100
101  if [ [[ "$REFERENCE_VERSION" =~ [0-9]{6} ]] ]; then
102    AC_MSG_ERROR([Internal error: Cannot compare to ARG_VERSION, only parts < 99999 is supported])
103  fi
104
105  # Version comparison method inspired by http://stackoverflow.com/a/24067243
106  COMPARABLE_REFERENCE_VERSION=`$AWK -F. '{ printf("%05d%05d%05d\n", [$]1, [$]2, [$]3) }' <<< "$REFERENCE_VERSION"`
107
108  if test [$]ARG_PREFIX[COMPARABLE_ACTUAL_VERSION] -ge $COMPARABLE_REFERENCE_VERSION ; then
109    :
110    ARG_IF_AT_LEAST
111  else
112    :
113    ARG_IF_OLDER_THAN
114  fi
115])
116
117# Setup a number of variables describing how native output files are
118# named on this platform/toolchain.
119AC_DEFUN([TOOLCHAIN_SETUP_FILENAME_PATTERNS],
120[
121  # Define filename patterns
122  if test "x$OPENJDK_TARGET_OS" = xwindows; then
123    LIBRARY_PREFIX=
124    SHARED_LIBRARY_SUFFIX='.dll'
125    STATIC_LIBRARY_SUFFIX='.lib'
126    SHARED_LIBRARY='[$]1.dll'
127    STATIC_LIBRARY='[$]1.lib'
128    OBJ_SUFFIX='.obj'
129    EXE_SUFFIX='.exe'
130  else
131    LIBRARY_PREFIX=lib
132    SHARED_LIBRARY_SUFFIX='.so'
133    STATIC_LIBRARY_SUFFIX='.a'
134    SHARED_LIBRARY='lib[$]1.so'
135    STATIC_LIBRARY='lib[$]1.a'
136    OBJ_SUFFIX='.o'
137    EXE_SUFFIX=''
138    if test "x$OPENJDK_TARGET_OS" = xmacosx; then
139      # For full static builds, we're overloading the SHARED_LIBRARY
140      # variables in order to limit the amount of changes required.
141      # It would be better to remove SHARED and just use LIBRARY and
142      # LIBRARY_SUFFIX for libraries that can be built either
143      # shared or static and use STATIC_* for libraries that are
144      # always built statically.
145      if test "x$STATIC_BUILD" = xtrue; then
146        SHARED_LIBRARY='lib[$]1.a'
147        SHARED_LIBRARY_SUFFIX='.a'
148      else
149        SHARED_LIBRARY='lib[$]1.dylib'
150        SHARED_LIBRARY_SUFFIX='.dylib'
151      fi
152    fi
153  fi
154
155  AC_SUBST(LIBRARY_PREFIX)
156  AC_SUBST(SHARED_LIBRARY_SUFFIX)
157  AC_SUBST(STATIC_LIBRARY_SUFFIX)
158  AC_SUBST(SHARED_LIBRARY)
159  AC_SUBST(STATIC_LIBRARY)
160  AC_SUBST(OBJ_SUFFIX)
161  AC_SUBST(EXE_SUFFIX)
162])
163
164# Determine which toolchain type to use, and make sure it is valid for this
165# platform. Setup various information about the selected toolchain.
166AC_DEFUN_ONCE([TOOLCHAIN_DETERMINE_TOOLCHAIN_TYPE],
167[
168  AC_ARG_WITH(toolchain-type, [AS_HELP_STRING([--with-toolchain-type],
169      [the toolchain type (or family) to use, use '--help' to show possible values @<:@platform dependent@:>@])])
170
171  # Use indirect variable referencing
172  toolchain_var_name=VALID_TOOLCHAINS_$OPENJDK_BUILD_OS
173  VALID_TOOLCHAINS=${!toolchain_var_name}
174
175  if test "x$OPENJDK_TARGET_OS" = xmacosx; then
176    if test -n "$XCODEBUILD"; then
177      # On Mac OS X, default toolchain to clang after Xcode 5
178      XCODE_VERSION_OUTPUT=`"$XCODEBUILD" -version 2>&1 | $HEAD -n 1`
179      $ECHO "$XCODE_VERSION_OUTPUT" | $GREP "Xcode " > /dev/null
180      if test $? -ne 0; then
181        AC_MSG_ERROR([Failed to determine Xcode version.])
182      fi
183      XCODE_MAJOR_VERSION=`$ECHO $XCODE_VERSION_OUTPUT | \
184          $SED -e 's/^Xcode \(@<:@1-9@:>@@<:@0-9.@:>@*\)/\1/' | \
185          $CUT -f 1 -d .`
186      AC_MSG_NOTICE([Xcode major version: $XCODE_MAJOR_VERSION])
187      if test $XCODE_MAJOR_VERSION -ge 5; then
188          DEFAULT_TOOLCHAIN="clang"
189      else
190          DEFAULT_TOOLCHAIN="gcc"
191      fi
192    else
193      # If Xcode is not installed, but the command line tools are
194      # then we can't run xcodebuild. On these systems we should
195      # default to clang
196      DEFAULT_TOOLCHAIN="clang"
197    fi
198  else
199    # First toolchain type in the list is the default
200    DEFAULT_TOOLCHAIN=${VALID_TOOLCHAINS%% *}
201  fi
202
203  if test "x$with_toolchain_type" = xlist; then
204    # List all toolchains
205    AC_MSG_NOTICE([The following toolchains are valid on this platform:])
206    for toolchain in $VALID_TOOLCHAINS; do
207      toolchain_var_name=TOOLCHAIN_DESCRIPTION_$toolchain
208      TOOLCHAIN_DESCRIPTION=${!toolchain_var_name}
209      $PRINTF "  %-10s  %s\n" $toolchain "$TOOLCHAIN_DESCRIPTION"
210    done
211
212    exit 0
213  elif test "x$with_toolchain_type" != x; then
214    # User override; check that it is valid
215    if test "x${VALID_TOOLCHAINS/$with_toolchain_type/}" = "x${VALID_TOOLCHAINS}"; then
216      AC_MSG_NOTICE([Toolchain type $with_toolchain_type is not valid on this platform.])
217      AC_MSG_NOTICE([Valid toolchains: $VALID_TOOLCHAINS.])
218      AC_MSG_ERROR([Cannot continue.])
219    fi
220    TOOLCHAIN_TYPE=$with_toolchain_type
221  else
222    # No flag given, use default
223    TOOLCHAIN_TYPE=$DEFAULT_TOOLCHAIN
224  fi
225  AC_SUBST(TOOLCHAIN_TYPE)
226
227  TOOLCHAIN_CC_BINARY_clang="clang"
228  TOOLCHAIN_CC_BINARY_gcc="gcc"
229  TOOLCHAIN_CC_BINARY_microsoft="cl"
230  TOOLCHAIN_CC_BINARY_solstudio="cc"
231  TOOLCHAIN_CC_BINARY_xlc="xlc_r"
232
233  TOOLCHAIN_CXX_BINARY_clang="clang++"
234  TOOLCHAIN_CXX_BINARY_gcc="g++"
235  TOOLCHAIN_CXX_BINARY_microsoft="cl"
236  TOOLCHAIN_CXX_BINARY_solstudio="CC"
237  TOOLCHAIN_CXX_BINARY_xlc="xlC_r"
238
239  # Use indirect variable referencing
240  toolchain_var_name=TOOLCHAIN_DESCRIPTION_$TOOLCHAIN_TYPE
241  TOOLCHAIN_DESCRIPTION=${!toolchain_var_name}
242  toolchain_var_name=TOOLCHAIN_MINIMUM_VERSION_$TOOLCHAIN_TYPE
243  TOOLCHAIN_MINIMUM_VERSION=${!toolchain_var_name}
244  toolchain_var_name=TOOLCHAIN_CC_BINARY_$TOOLCHAIN_TYPE
245  TOOLCHAIN_CC_BINARY=${!toolchain_var_name}
246  toolchain_var_name=TOOLCHAIN_CXX_BINARY_$TOOLCHAIN_TYPE
247  TOOLCHAIN_CXX_BINARY=${!toolchain_var_name}
248
249  TOOLCHAIN_SETUP_FILENAME_PATTERNS
250
251  if test "x$TOOLCHAIN_TYPE" = "x$DEFAULT_TOOLCHAIN"; then
252    AC_MSG_NOTICE([Using default toolchain $TOOLCHAIN_TYPE ($TOOLCHAIN_DESCRIPTION)])
253  else
254    AC_MSG_NOTICE([Using user selected toolchain $TOOLCHAIN_TYPE ($TOOLCHAIN_DESCRIPTION). Default toolchain is $DEFAULT_TOOLCHAIN.])
255  fi
256])
257
258# Before we start detecting the toolchain executables, we might need some
259# special setup, e.g. additional paths etc.
260AC_DEFUN_ONCE([TOOLCHAIN_PRE_DETECTION],
261[
262  # FIXME: Is this needed?
263  AC_LANG(C++)
264
265  # Store the CFLAGS etc passed to the configure script.
266  ORG_CFLAGS="$CFLAGS"
267  ORG_CXXFLAGS="$CXXFLAGS"
268
269  # autoconf magic only relies on PATH, so update it if tools dir is specified
270  OLD_PATH="$PATH"
271
272  # On Windows, we need to detect the visual studio installation first.
273  # This will change the PATH, but we need to keep that new PATH even
274  # after toolchain detection is done, since the compiler (on x86) uses
275  # it for DLL resolution in runtime.
276  if test "x$OPENJDK_BUILD_OS" = "xwindows" \
277      && test "x$TOOLCHAIN_TYPE" = "xmicrosoft"; then
278    TOOLCHAIN_SETUP_VISUAL_STUDIO_ENV
279    # Reset path to VS_PATH. It will include everything that was on PATH at the time we
280    # ran TOOLCHAIN_SETUP_VISUAL_STUDIO_ENV.
281    PATH="$VS_PATH"
282    # The microsoft toolchain also requires INCLUDE and LIB to be set.
283    export INCLUDE="$VS_INCLUDE"
284    export LIB="$VS_LIB"
285  else
286    if test "x$XCODE_VERSION_OUTPUT" != x; then
287      # For Xcode, we set the Xcode version as TOOLCHAIN_VERSION
288      TOOLCHAIN_VERSION=`$ECHO $XCODE_VERSION_OUTPUT | $CUT -f 2 -d ' '`
289      TOOLCHAIN_DESCRIPTION="$TOOLCHAIN_DESCRIPTION from Xcode"
290    else
291      # Currently we do not define this for other toolchains. This might change as the need arise.
292      TOOLCHAIN_VERSION=
293    fi
294  fi
295  AC_SUBST(TOOLCHAIN_VERSION)
296
297  # Finally add TOOLCHAIN_PATH at the beginning, to allow --with-tools-dir to
298  # override all other locations.
299  if test "x$TOOLCHAIN_PATH" != x; then
300    PATH=$TOOLCHAIN_PATH:$PATH
301  fi
302])
303
304# Restore path, etc
305AC_DEFUN_ONCE([TOOLCHAIN_POST_DETECTION],
306[
307  # Restore old path, except for the microsoft toolchain, which requires VS_PATH
308  # to remain in place. Otherwise the compiler will not work in some siutations
309  # in later configure checks.
310  if test "x$TOOLCHAIN_TYPE" != "xmicrosoft"; then
311    PATH="$OLD_PATH"
312  fi
313
314  # Restore the flags to the user specified values.
315  # This is necessary since AC_PROG_CC defaults CFLAGS to "-g -O2"
316  CFLAGS="$ORG_CFLAGS"
317  CXXFLAGS="$ORG_CXXFLAGS"
318])
319
320# Check if a compiler is of the toolchain type we expect, and save the version
321# information from it. If the compiler does not match the expected type,
322# this function will abort using AC_MSG_ERROR. If it matches, the version will
323# be stored in CC_VERSION_NUMBER/CXX_VERSION_NUMBER (as a dotted number), and
324# the full version string in CC_VERSION_STRING/CXX_VERSION_STRING.
325#
326# $1 = compiler to test (CC or CXX)
327# $2 = human readable name of compiler (C or C++)
328AC_DEFUN([TOOLCHAIN_EXTRACT_COMPILER_VERSION],
329[
330  COMPILER=[$]$1
331  COMPILER_NAME=$2
332
333  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