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