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