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