2
# Copyright (c) 2011, 2024, Oracle and/or its affiliates. All rights reserved.
3
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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.
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).
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.
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
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.
31
# The binaries used is determined by the toolchain type, which is the family of
32
# compilers and related tools that are used.
33
########################################################################
35
m4_include([toolchain_microsoft.m4])
37
# All valid toolchains, regardless of platform (used by help.m4)
38
VALID_TOOLCHAINS_all="gcc clang microsoft"
40
# These toolchains are valid on different platforms
41
VALID_TOOLCHAINS_linux="gcc clang"
42
VALID_TOOLCHAINS_macosx="clang"
43
VALID_TOOLCHAINS_aix="clang"
44
VALID_TOOLCHAINS_windows="microsoft"
46
# Toolchain descriptions
47
TOOLCHAIN_DESCRIPTION_clang="clang/LLVM"
48
TOOLCHAIN_DESCRIPTION_gcc="GNU Compiler Collection"
49
TOOLCHAIN_DESCRIPTION_microsoft="Microsoft Visual Studio"
51
# Minimum supported versions, empty means unspecified
52
TOOLCHAIN_MINIMUM_VERSION_clang="13.0"
53
TOOLCHAIN_MINIMUM_VERSION_gcc="10.0"
54
TOOLCHAIN_MINIMUM_VERSION_microsoft="19.28.0.0" # VS2019 16.8, aka MSVC 14.28
56
# Minimum supported linker versions, empty means unspecified
57
TOOLCHAIN_MINIMUM_LD_VERSION_gcc="2.18"
59
# Prepare the system so that TOOLCHAIN_CHECK_COMPILER_VERSION can be called.
60
# Must have CC_VERSION_NUMBER and CXX_VERSION_NUMBER.
61
# $1 - optional variable prefix for compiler and version variables (BUILD_)
62
# $2 - optional variable prefix for comparable variable (OPENJDK_BUILD_)
63
# $3 - optional human readable description for the type of compilers ("build " or "")
64
AC_DEFUN([TOOLCHAIN_PREPARE_FOR_VERSION_COMPARISONS],
66
if test "x[$]$1CC_VERSION_NUMBER" != "x[$]$1CXX_VERSION_NUMBER"; then
67
AC_MSG_WARN([The $3C and C++ compilers have different version numbers, [$]$1CC_VERSION_NUMBER vs [$]$1CXX_VERSION_NUMBER.])
68
AC_MSG_WARN([This typically indicates a broken setup, and is not supported])
71
# We only check CC_VERSION_NUMBER since we assume CXX_VERSION_NUMBER is equal.
72
if [ [[ "[$]$1CC_VERSION_NUMBER" =~ (.*\.){4} ]] ]; then
73
AC_MSG_WARN([C compiler version number has more than four parts (W.X.Y.Z): [$]$1CC_VERSION_NUMBER. Comparisons might be wrong.])
76
if [ [[ "[$]$1CC_VERSION_NUMBER" =~ [0-9]{6} ]] ]; then
77
AC_MSG_WARN([C compiler version number has a part larger than 99999: [$]$1CC_VERSION_NUMBER. Comparisons might be wrong.])
80
$2COMPARABLE_ACTUAL_VERSION=`$AWK -F. '{ printf("%05d%05d%05d%05d\n", [$]1, [$]2, [$]3, [$]4) }' <<< "[$]$1CC_VERSION_NUMBER"`
83
# Check if the configured compiler (C and C++) is of a specific version or
84
# newer. TOOLCHAIN_PREPARE_FOR_VERSION_COMPARISONS must have been called before.
87
# VERSION: The version string to check against the found version
88
# IF_AT_LEAST: block to run if the compiler is at least this version (>=)
89
# IF_OLDER_THAN: block to run if the compiler is older than this version (<)
90
# PREFIX: Optional variable prefix for compiler to compare version for (OPENJDK_BUILD_)
91
UTIL_DEFUN_NAMED([TOOLCHAIN_CHECK_COMPILER_VERSION],
92
[*VERSION PREFIX IF_AT_LEAST IF_OLDER_THAN], [$@],
94
# Need to assign to a variable since m4 is blocked from modifying parts in [].
95
REFERENCE_VERSION=ARG_VERSION
97
if [ [[ "$REFERENCE_VERSION" =~ (.*\.){4} ]] ]; then
98
AC_MSG_ERROR([Internal error: Cannot compare to ARG_VERSION, only four parts (W.X.Y.Z) is supported])
101
if [ [[ "$REFERENCE_VERSION" =~ [0-9]{6} ]] ]; then
102
AC_MSG_ERROR([Internal error: Cannot compare to ARG_VERSION, only parts < 99999 is supported])
105
# Version comparison method inspired by http://stackoverflow.com/a/24067243
106
COMPARABLE_REFERENCE_VERSION=`$AWK -F. '{ printf("%05d%05d%05d%05d\n", [$]1, [$]2, [$]3, [$]4) }' <<< "$REFERENCE_VERSION"`
108
if test [$]ARG_PREFIX[COMPARABLE_ACTUAL_VERSION] -ge $COMPARABLE_REFERENCE_VERSION ; then
117
# Prepare the system so that TOOLCHAIN_CHECK_COMPILER_VERSION can be called.
118
# Must have LD_VERSION_NUMBER.
119
# $1 - optional variable prefix for compiler and version variables (BUILD_)
120
# $2 - optional variable prefix for comparable variable (OPENJDK_BUILD_)
121
AC_DEFUN([TOOLCHAIN_PREPARE_FOR_LD_VERSION_COMPARISONS],
123
if [ [[ "[$]$1LD_VERSION_NUMBER" =~ (.*\.){4} ]] ]; then
124
AC_MSG_WARN([Linker version number has more than four parts (W.X.Y.Z): [$]$1LD_VERSION_NUMBER. Comparisons might be wrong.])
127
if [ [[ "[$]$1LD_VERSION_NUMBER" =~ [0-9]{6} ]] ]; then
128
AC_MSG_WARN([Linker version number has a part larger than 99999: [$]$1LD_VERSION_NUMBER. Comparisons might be wrong.])
131
$2COMPARABLE_ACTUAL_LD_VERSION=`$AWK -F. '{ printf("%05d%05d%05d%05d\n", [$]1, [$]2, [$]3, [$]4) }' <<< "[$]$1LD_VERSION_NUMBER"`
134
# Check if the configured linker is of a specific version or
135
# newer. TOOLCHAIN_PREPARE_FOR_LD_VERSION_COMPARISONS must have been called before.
138
# VERSION: The version string to check against the found version
139
# IF_AT_LEAST: block to run if the compiler is at least this version (>=)
140
# IF_OLDER_THAN: block to run if the compiler is older than this version (<)
141
# PREFIX: Optional variable prefix for compiler to compare version for (OPENJDK_BUILD_)
142
UTIL_DEFUN_NAMED([TOOLCHAIN_CHECK_LINKER_VERSION],
143
[*VERSION PREFIX IF_AT_LEAST IF_OLDER_THAN], [$@],
145
# Need to assign to a variable since m4 is blocked from modifying parts in [].
146
REFERENCE_VERSION=ARG_VERSION
148
if [ [[ "$REFERENCE_VERSION" =~ (.*\.){4} ]] ]; then
149
AC_MSG_ERROR([Internal error: Cannot compare to ARG_VERSION, only four parts (W.X.Y.Z) is supported])
152
if [ [[ "$REFERENCE_VERSION" =~ [0-9]{6} ]] ]; then
153
AC_MSG_ERROR([Internal error: Cannot compare to ARG_VERSION, only parts < 99999 is supported])
156
# Version comparison method inspired by http://stackoverflow.com/a/24067243
157
COMPARABLE_REFERENCE_VERSION=`$AWK -F. '{ printf("%05d%05d%05d%05d\n", [$]1, [$]2, [$]3, [$]4) }' <<< "$REFERENCE_VERSION"`
159
if test [$]ARG_PREFIX[COMPARABLE_ACTUAL_LD_VERSION] -ge $COMPARABLE_REFERENCE_VERSION ; then
168
# Setup a number of variables describing how native output files are
169
# named on this platform/toolchain.
170
AC_DEFUN([TOOLCHAIN_SETUP_FILENAME_PATTERNS],
172
# Define filename patterns
173
if test "x$OPENJDK_TARGET_OS" = xwindows; then
175
SHARED_LIBRARY_SUFFIX='.dll'
176
STATIC_LIBRARY_SUFFIX='.lib'
178
EXECUTABLE_SUFFIX='.exe'
181
if test "x$OPENJDK_TARGET_OS" = xmacosx; then
182
SHARED_LIBRARY_SUFFIX='.dylib'
184
SHARED_LIBRARY_SUFFIX='.so'
186
STATIC_LIBRARY_SUFFIX='.a'
191
AC_SUBST(LIBRARY_PREFIX)
192
AC_SUBST(SHARED_LIBRARY_SUFFIX)
193
AC_SUBST(STATIC_LIBRARY_SUFFIX)
195
AC_SUBST(EXECUTABLE_SUFFIX)
198
# Determine which toolchain type to use, and make sure it is valid for this
199
# platform. Setup various information about the selected toolchain.
200
AC_DEFUN_ONCE([TOOLCHAIN_DETERMINE_TOOLCHAIN_TYPE],
202
AC_ARG_WITH(toolchain-type, [AS_HELP_STRING([--with-toolchain-type],
203
[the toolchain type (or family) to use, use '--help' to show possible values @<:@platform dependent@:>@])])
205
# Linux x86_64 needs higher binutils after 8265783
206
# (this really is a dependency on as version, but we take ld as a check for a general binutils version)
207
if test "x$OPENJDK_TARGET_CPU" = "xx86_64"; then
208
TOOLCHAIN_MINIMUM_LD_VERSION_gcc="2.25"
211
# Use indirect variable referencing
212
toolchain_var_name=VALID_TOOLCHAINS_$OPENJDK_BUILD_OS
213
VALID_TOOLCHAINS=${!toolchain_var_name}
215
# First toolchain type in the list is the default
216
DEFAULT_TOOLCHAIN=${VALID_TOOLCHAINS%% *}
218
if test "x$with_toolchain_type" = xlist; then
219
# List all toolchains
220
AC_MSG_NOTICE([The following toolchains are valid on this platform:])
221
for toolchain in $VALID_TOOLCHAINS; do
222
toolchain_var_name=TOOLCHAIN_DESCRIPTION_$toolchain
223
TOOLCHAIN_DESCRIPTION=${!toolchain_var_name}
224
$PRINTF " %-10s %s\n" $toolchain "$TOOLCHAIN_DESCRIPTION"
228
elif test "x$with_toolchain_type" != x; then
229
# User override; check that it is valid
230
if test "x${VALID_TOOLCHAINS/$with_toolchain_type/}" = "x${VALID_TOOLCHAINS}"; then
231
AC_MSG_NOTICE([Toolchain type $with_toolchain_type is not valid on this platform.])
232
AC_MSG_NOTICE([Valid toolchains: $VALID_TOOLCHAINS.])
233
AC_MSG_ERROR([Cannot continue.])
235
TOOLCHAIN_TYPE=$with_toolchain_type
237
# No flag given, use default
238
TOOLCHAIN_TYPE=$DEFAULT_TOOLCHAIN
240
AC_SUBST(TOOLCHAIN_TYPE)
242
TOOLCHAIN_CC_BINARY_clang="ibm-clang_r clang"
243
TOOLCHAIN_CC_BINARY_gcc="gcc"
244
TOOLCHAIN_CC_BINARY_microsoft="cl"
246
TOOLCHAIN_CXX_BINARY_clang="ibm-clang++_r clang++"
247
TOOLCHAIN_CXX_BINARY_gcc="g++"
248
TOOLCHAIN_CXX_BINARY_microsoft="cl"
250
# Use indirect variable referencing
251
toolchain_var_name=TOOLCHAIN_DESCRIPTION_$TOOLCHAIN_TYPE
252
TOOLCHAIN_DESCRIPTION=${!toolchain_var_name}
253
toolchain_var_name=TOOLCHAIN_MINIMUM_VERSION_$TOOLCHAIN_TYPE
254
TOOLCHAIN_MINIMUM_VERSION=${!toolchain_var_name}
255
toolchain_var_name=TOOLCHAIN_MINIMUM_LD_VERSION_$TOOLCHAIN_TYPE
256
TOOLCHAIN_MINIMUM_LD_VERSION=${!toolchain_var_name}
257
toolchain_var_name=TOOLCHAIN_CC_BINARY_$TOOLCHAIN_TYPE
258
TOOLCHAIN_CC_BINARY=${!toolchain_var_name}
259
toolchain_var_name=TOOLCHAIN_CXX_BINARY_$TOOLCHAIN_TYPE
260
TOOLCHAIN_CXX_BINARY=${!toolchain_var_name}
262
TOOLCHAIN_SETUP_FILENAME_PATTERNS
264
if test "x$TOOLCHAIN_TYPE" = "x$DEFAULT_TOOLCHAIN"; then
265
AC_MSG_NOTICE([Using default toolchain $TOOLCHAIN_TYPE ($TOOLCHAIN_DESCRIPTION)])
267
AC_MSG_NOTICE([Using user selected toolchain $TOOLCHAIN_TYPE ($TOOLCHAIN_DESCRIPTION). Default toolchain is $DEFAULT_TOOLCHAIN.])
271
# Before we start detecting the toolchain executables, we might need some
272
# special setup, e.g. additional paths etc.
273
AC_DEFUN_ONCE([TOOLCHAIN_PRE_DETECTION],
275
# Store the CFLAGS etc passed to the configure script.
277
ORG_CXXFLAGS="$CXXFLAGS"
279
# autoconf magic only relies on PATH, so update it if tools dir is specified
282
if test "x$OPENJDK_BUILD_OS" = "xmacosx"; then
283
if test "x$XCODEBUILD" != x; then
284
XCODE_VERSION_OUTPUT=`"$XCODEBUILD" -version 2> /dev/null | $HEAD -n 1`
285
$ECHO "$XCODE_VERSION_OUTPUT" | $GREP "^Xcode " > /dev/null
286
if test $? -ne 0; then
287
AC_MSG_NOTICE([xcodebuild -version output: $XCODE_VERSION_OUTPUT])
288
AC_MSG_ERROR([Failed to determine Xcode version])
291
# For Xcode, we set the Xcode version as TOOLCHAIN_VERSION
292
TOOLCHAIN_VERSION=`$ECHO $XCODE_VERSION_OUTPUT | $CUT -f 2 -d ' '`
293
TOOLCHAIN_DESCRIPTION="$TOOLCHAIN_DESCRIPTION from Xcode $TOOLCHAIN_VERSION"
296
AC_SUBST(TOOLCHAIN_VERSION)
298
# Finally prepend TOOLCHAIN_PATH to the PATH, to allow --with-tools-dir to
299
# override all other locations.
300
if test "x$TOOLCHAIN_PATH" != x; then
301
export PATH=$TOOLCHAIN_PATH:$PATH
306
AC_DEFUN_ONCE([TOOLCHAIN_POST_DETECTION],
308
# Restore old path, except for the microsoft toolchain, which requires the
309
# toolchain path to remain in place. Otherwise the compiler will not work in
310
# some siutations in later configure checks.
311
if test "x$TOOLCHAIN_TYPE" != "xmicrosoft"; then
315
# Restore the flags to the user specified values.
316
# This is necessary since AC_PROG_CC defaults CFLAGS to "-g -O2"
318
CXXFLAGS="$ORG_CXXFLAGS"
320
# filter out some unwanted additions autoconf may add to CXX; we saw this on macOS with autoconf 2.72
321
UTIL_GET_NON_MATCHING_VALUES(cxx_filtered, $CXX, -std=c++11 -std=gnu++11)
325
# Check if a compiler is of the toolchain type we expect, and save the version
326
# information from it. If the compiler does not match the expected type,
327
# this function will abort using AC_MSG_ERROR. If it matches, the version will
328
# be stored in CC_VERSION_NUMBER/CXX_VERSION_NUMBER (as a dotted number), and
329
# the full version string in CC_VERSION_STRING/CXX_VERSION_STRING.
331
# $1 = compiler to test (CC or CXX)
332
# $2 = human readable name of compiler (C or C++)
333
AC_DEFUN([TOOLCHAIN_EXTRACT_COMPILER_VERSION],
338
if test "x$TOOLCHAIN_TYPE" = xmicrosoft; then
339
# There is no specific version flag, but all output starts with a version string.
340
# First line typically looks something like:
341
# Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 16.00.40219.01 for 80x86
342
# but the compiler name may vary depending on locale.
343
COMPILER_VERSION_OUTPUT=`$COMPILER 2>&1 1>/dev/null | $HEAD -n 1 | $TR -d '\r'`
344
# Check that this is likely to be Microsoft CL.EXE.
345
$ECHO "$COMPILER_VERSION_OUTPUT" | $GREP "Microsoft" > /dev/null
346
if test $? -ne 0; then
347
AC_MSG_NOTICE([The $COMPILER_NAME compiler (located as $COMPILER) does not seem to be the required $TOOLCHAIN_TYPE compiler.])
348
AC_MSG_NOTICE([The result from running it was: "$COMPILER_VERSION_OUTPUT"])
349
AC_MSG_ERROR([A $TOOLCHAIN_TYPE compiler is required. Try setting --with-tools-dir.])
351
# Collapse compiler output into a single line
352
COMPILER_VERSION_STRING=`$ECHO $COMPILER_VERSION_OUTPUT`
353
COMPILER_VERSION_NUMBER=`$ECHO $COMPILER_VERSION_OUTPUT | \
354
$SED -e 's/^.*ersion.\(@<:@1-9@:>@@<:@0-9.@:>@*\) .*$/\1/'`
355
elif test "x$TOOLCHAIN_TYPE" = xgcc; then
356
# gcc --version output typically looks like
357
# gcc (Ubuntu/Linaro 4.8.1-10ubuntu9) 4.8.1
358
# Copyright (C) 2013 Free Software Foundation, Inc.
359
# This is free software; see the source for copying conditions. There is NO
360
# warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
361
COMPILER_VERSION_OUTPUT=`$COMPILER --version 2>&1`
362
# Check that this is likely to be GCC.
363
$ECHO "$COMPILER_VERSION_OUTPUT" | $GREP "Free Software Foundation" > /dev/null
364
if test $? -ne 0; then
365
AC_MSG_NOTICE([The $COMPILER_NAME compiler (located as $COMPILER) does not seem to be the required $TOOLCHAIN_TYPE compiler.])
366
AC_MSG_NOTICE([The result from running with --version was: "$COMPILER_VERSION"])
367
AC_MSG_ERROR([A $TOOLCHAIN_TYPE compiler is required. Try setting --with-tools-dir.])
369
# Remove Copyright and legalese from version string, and
370
# collapse into a single line
371
COMPILER_VERSION_STRING=`$ECHO $COMPILER_VERSION_OUTPUT | \
372
$SED -e 's/ *Copyright .*//'`
373
COMPILER_VERSION_NUMBER=`$ECHO $COMPILER_VERSION_OUTPUT | \
374
$SED -e 's/^.* \(@<:@1-9@:>@<:@0-9@:>@*\.@<:@0-9.@:>@*\)@<:@^0-9.@:>@.*$/\1/'`
375
elif test "x$TOOLCHAIN_TYPE" = xclang; then
376
# clang --version output typically looks like
377
# Apple clang version 15.0.0 (clang-1500.3.9.4)
378
# Target: arm64-apple-darwin23.2.0
379
# Thread model: posix
380
# InstalledDir: /Library/Developer/CommandLineTools/usr/bin
382
# clang version 10.0.0-4ubuntu1
383
# Target: x86_64-pc-linux-gnu
384
# Thread model: posix
385
# InstalledDir: /usr/bin
386
# Target: x86_64-pc-linux-gnu
387
# Thread model: posix
389
# IBM Open XL C/C++ for AIX 17.1.0 (5725-C72, 5765-J18), clang version 13.0.0
390
# Target: powerpc-ibm-aix7.2.0.0
391
# Thread model: posix
392
# InstalledDir: /opt/IBM/openxlC/17.1.0/bin
393
COMPILER_VERSION_OUTPUT=`$COMPILER --version 2>&1`
394
# Check that this is likely to be clang
395
$ECHO "$COMPILER_VERSION_OUTPUT" | $GREP "clang" > /dev/null
396
if test $? -ne 0; then
397
AC_MSG_NOTICE([The $COMPILER_NAME compiler (located as $COMPILER) does not seem to be the required $TOOLCHAIN_TYPE compiler.])
398
AC_MSG_NOTICE([The result from running with --version was: "$COMPILER_VERSION_OUTPUT"])
399
AC_MSG_ERROR([A $TOOLCHAIN_TYPE compiler is required. Try setting --with-tools-dir.])
401
# Remove "Thread model:" and further details from the version string, and
402
# collapse into a single line
403
COMPILER_VERSION_STRING=`$ECHO $COMPILER_VERSION_OUTPUT | \
404
$SED -e 's/ *Thread model: .*//'`
405
COMPILER_VERSION_NUMBER=`$ECHO $COMPILER_VERSION_OUTPUT | \
406
$SED -e 's/^.*clang version \(@<:@1-9@:>@@<:@0-9.@:>@*\).*$/\1/'`
408
AC_MSG_ERROR([Unknown toolchain type $TOOLCHAIN_TYPE.])
410
# This sets CC_VERSION_NUMBER or CXX_VERSION_NUMBER. (This comment is a grep marker)
411
$1_VERSION_NUMBER="$COMPILER_VERSION_NUMBER"
412
# This sets CC_VERSION_STRING or CXX_VERSION_STRING. (This comment is a grep marker)
413
$1_VERSION_STRING="$COMPILER_VERSION_STRING"
415
AC_MSG_NOTICE([Using $TOOLCHAIN_TYPE $COMPILER_NAME compiler version $COMPILER_VERSION_NUMBER @<:@$COMPILER_VERSION_STRING@:>@])
418
# Try to locate the given C or C++ compiler in the path, or otherwise.
420
# $1 = compiler to test (CC or CXX)
421
# $2 = human readable name of compiler (C or C++)
422
# $3 = compiler name to search for
423
AC_DEFUN([TOOLCHAIN_FIND_COMPILER],
428
if test "x[$]$1" != x; then
429
# User has supplied compiler name already, always let that override.
430
AC_MSG_NOTICE([Will use user supplied compiler $1=[$]$1])
431
if test "x`basename [$]$1`" = "x[$]$1"; then
432
# A command without a complete path is provided, search $PATH.
434
UTIL_LOOKUP_PROGS(POTENTIAL_$1, [$]$1)
435
if test "x$POTENTIAL_$1" != x; then
438
AC_MSG_ERROR([User supplied compiler $1=[$]$1 could not be found])
441
# Otherwise it might already be a complete path
442
if test ! -x "[$]$1"; then
443
AC_MSG_ERROR([User supplied compiler $1=[$]$1 does not exist])
447
# No user supplied value. Locate compiler ourselves.
449
# If we are cross compiling, assume cross compilation tools follows the
450
# cross compilation standard where they are prefixed with the autoconf
451
# standard name for the target. For example the binary
452
# i686-sun-solaris2.10-gcc will cross compile for i686-sun-solaris2.10.
453
# If we are not cross compiling, then the default compiler name will be
456
UTIL_LOOKUP_TOOLCHAIN_PROGS(POTENTIAL_$1, $SEARCH_LIST)
457
if test "x$POTENTIAL_$1" != x; then
460
HELP_MSG_MISSING_DEPENDENCY([devkit])
461
AC_MSG_ERROR([Could not find a $COMPILER_NAME compiler. $HELP_MSG])
465
# Now we have a compiler binary in $1. Make sure it's okay.
466
TEST_COMPILER="[$]$1"
468
AC_MSG_CHECKING([resolved symbolic links for $1])
469
SYMLINK_ORIGINAL="$TEST_COMPILER"
470
UTIL_REMOVE_SYMBOLIC_LINKS(SYMLINK_ORIGINAL)
471
if test "x$TEST_COMPILER" = "x$SYMLINK_ORIGINAL"; then
472
AC_MSG_RESULT([no symlink])
474
AC_MSG_RESULT([$SYMLINK_ORIGINAL])
476
# We can't handle ccache by gcc wrappers, since we need to know if we're
477
# using ccache. Instead ccache usage must be controlled by a configure option.
478
COMPILER_BASENAME=`$BASENAME "$SYMLINK_ORIGINAL"`
479
if test "x$COMPILER_BASENAME" = "xccache"; then
480
AC_MSG_NOTICE([Please use --enable-ccache instead of providing a wrapped compiler.])
481
AC_MSG_ERROR([$TEST_COMPILER is a symbolic link to ccache. This is not supported.])
485
TOOLCHAIN_EXTRACT_COMPILER_VERSION([$1], [$COMPILER_NAME])
488
# Retrieve the linker version number and store it in LD_VERSION_NUMBER
489
# (as a dotted number), and
490
# the full version string in LD_VERSION_STRING.
492
# $1 = linker to test (LD or BUILD_LD)
493
# $2 = human readable name of linker (Linker or BuildLinker)
494
AC_DEFUN([TOOLCHAIN_EXTRACT_LD_VERSION],
499
if test "x$TOOLCHAIN_TYPE" = xmicrosoft; then
500
# There is no specific version flag, but all output starts with a version string.
501
# First line typically looks something like:
502
# Microsoft (R) Incremental Linker Version 12.00.31101.0
503
LINKER_VERSION_STRING=`$LINKER 2>&1 | $HEAD -n 1 | $TR -d '\r'`
504
# Extract version number
505
[ LINKER_VERSION_NUMBER=`$ECHO $LINKER_VERSION_STRING | \
506
$SED -e 's/.* \([0-9][0-9]*\(\.[0-9][0-9]*\)*\).*/\1/'` ]
507
elif test "x$TOOLCHAIN_TYPE" = xgcc; then
508
# gcc -Wl,-version output typically looks like:
509
# GNU ld (GNU Binutils for Ubuntu) 2.26.1
510
# Copyright (C) 2015 Free Software Foundation, Inc.
511
# This program is free software; [...]
512
# If using gold it will look like:
513
# GNU gold (GNU Binutils 2.30) 1.15
514
LINKER_VERSION_STRING=`$LINKER -Wl,--version 2> /dev/null | $HEAD -n 1`
515
# Extract version number
516
if [ [[ "$LINKER_VERSION_STRING" == *gold* ]] ]; then
517
[ LINKER_VERSION_NUMBER=`$ECHO $LINKER_VERSION_STRING | \
518
$SED -e 's/.* \([0-9][0-9]*\(\.[0-9][0-9]*\)*\).*) .*/\1/'` ]
520
[ LINKER_VERSION_NUMBER=`$ECHO $LINKER_VERSION_STRING | \
521
$SED -e 's/.* \([0-9][0-9]*\(\.[0-9][0-9]*\)*\).*/\1/'` ]
523
elif test "x$TOOLCHAIN_TYPE" = xclang; then
524
# clang -Wl,-v output typically looks like
525
# @(#)PROGRAM:ld PROJECT:ld64-305
526
# configured to support archs: armv6 armv7 armv7s arm64 i386 x86_64 x86_64h armv6m armv7k armv7m armv7em (tvOS)
527
# Library search paths: [...]
529
# GNU ld (GNU Binutils for Ubuntu) 2.26.1
531
LINKER_VERSION_STRING=`$LINKER -Wl,-v 2>&1 | $HEAD -n 1`
532
# Check if we're using the GNU ld
533
$ECHO "$LINKER_VERSION_STRING" | $GREP "GNU" > /dev/null
534
if test $? -eq 0; then
535
# Extract version number
536
[ LINKER_VERSION_NUMBER=`$ECHO $LINKER_VERSION_STRING | \
537
$SED -e 's/.* \([0-9][0-9]*\(\.[0-9][0-9]*\)*\).*/\1/'` ]
539
# Extract version number
540
[ LINKER_VERSION_NUMBER=`$ECHO $LINKER_VERSION_STRING | \
541
$SED -e 's/.*-\([0-9][0-9]*\)/\1/'` ]
545
$1_VERSION_NUMBER="$LINKER_VERSION_NUMBER"
546
$1_VERSION_STRING="$LINKER_VERSION_STRING"
548
AC_MSG_NOTICE([Using $TOOLCHAIN_TYPE $LINKER_NAME version $LINKER_VERSION_NUMBER @<:@$LINKER_VERSION_STRING@:>@])
551
# Make sure we did not pick up /usr/bin/link, which is the unix-style link
554
# $1 = linker to test (LD or BUILD_LD)
555
AC_DEFUN(TOOLCHAIN_VERIFY_LINK_BINARY,
559
AC_MSG_CHECKING([if the found link.exe is actually the Visual Studio linker])
560
$LINKER --version > /dev/null
561
if test $? -eq 0 ; then
563
AC_MSG_ERROR([$LINKER is the winenv link tool. Please check your PATH and rerun configure.])
568
# Detect the core components of the toolchain, i.e. the compilers (CC and CXX),
569
# preprocessor (CPP and CXXCPP), the linker (LD), the assembler (AS) and the
570
# archiver (AR). Verify that the compilers are correct according to the
572
AC_DEFUN_ONCE([TOOLCHAIN_DETECT_TOOLCHAIN_CORE],
575
# Setup the compilers (CC and CXX)
577
TOOLCHAIN_FIND_COMPILER([CC], [C], $TOOLCHAIN_CC_BINARY)
578
# Now that we have resolved CC ourself, let autoconf have its go at it
581
TOOLCHAIN_FIND_COMPILER([CXX], [C++], $TOOLCHAIN_CXX_BINARY)
582
# Now that we have resolved CXX ourself, let autoconf have its go at it
585
# This is the compiler version number on the form X.Y[.Z]
586
AC_SUBST(CC_VERSION_NUMBER)
587
AC_SUBST(CXX_VERSION_NUMBER)
589
TOOLCHAIN_PREPARE_FOR_VERSION_COMPARISONS
591
if test "x$TOOLCHAIN_MINIMUM_VERSION" != x; then
592
TOOLCHAIN_CHECK_COMPILER_VERSION(VERSION: $TOOLCHAIN_MINIMUM_VERSION,
594
AC_MSG_WARN([You are using $TOOLCHAIN_TYPE $CC_VERSION_NUMBER which is older than $TOOLCHAIN_MINIMUM_VERSION. This is not a supported configuration.])
600
# Setup the preprocessor (CPP and CXXCPP)
603
UTIL_FIXUP_EXECUTABLE(CPP)
605
UTIL_FIXUP_EXECUTABLE(CXXCPP)
608
# Setup the linker (LD)
610
if test "x$TOOLCHAIN_TYPE" = xmicrosoft; then
611
# In the Microsoft toolchain we have a separate LD command "link".
612
UTIL_LOOKUP_TOOLCHAIN_PROGS(LD, link)
613
TOOLCHAIN_VERIFY_LINK_BINARY(LD)
616
# All other toolchains use the compiler to link.
621
# FIXME: it should be CXXLD, according to standard (cf CXXCPP)
624
TOOLCHAIN_EXTRACT_LD_VERSION([LD], [linker])
625
TOOLCHAIN_PREPARE_FOR_LD_VERSION_COMPARISONS
627
if test "x$TOOLCHAIN_MINIMUM_LD_VERSION" != x; then
628
AC_MSG_NOTICE([comparing linker version to minimum version $TOOLCHAIN_MINIMUM_LD_VERSION])
629
TOOLCHAIN_CHECK_LINKER_VERSION(VERSION: $TOOLCHAIN_MINIMUM_LD_VERSION,
631
AC_MSG_ERROR([You are using a linker older than $TOOLCHAIN_MINIMUM_LD_VERSION. This is not a supported configuration.])
637
# Setup the assembler (AS)
639
if test "x$TOOLCHAIN_TYPE" != xmicrosoft; then
642
if test "x$OPENJDK_TARGET_CPU_BITS" = "x64"; then
643
# On 64 bit windows, the assembler is "ml64.exe"
644
UTIL_LOOKUP_TOOLCHAIN_PROGS(AS, ml64)
646
# otherwise, the assembler is "ml.exe"
647
UTIL_LOOKUP_TOOLCHAIN_PROGS(AS, ml)
653
# Setup tools for creating static libraries (AR/LIB)
655
if test "x$TOOLCHAIN_TYPE" = xmicrosoft; then
656
UTIL_LOOKUP_TOOLCHAIN_PROGS(LIB, lib)
657
elif test "x$TOOLCHAIN_TYPE" = xgcc; then
658
UTIL_LOOKUP_TOOLCHAIN_PROGS(AR, ar gcc-ar)
660
UTIL_LOOKUP_TOOLCHAIN_PROGS(AR, ar)
664
# Setup additional tools that is considered a part of the toolchain, but not the
665
# core part. Many of these are highly platform-specific and do not exist,
666
# and/or are not needed on all platforms.
667
AC_DEFUN_ONCE([TOOLCHAIN_DETECT_TOOLCHAIN_EXTRA],
669
if test "x$OPENJDK_TARGET_OS" = "xmacosx"; then
670
UTIL_LOOKUP_PROGS(LIPO, lipo)
671
UTIL_REQUIRE_PROGS(OTOOL, otool)
672
UTIL_REQUIRE_PROGS(INSTALL_NAME_TOOL, install_name_tool)
674
UTIL_LOOKUP_TOOLCHAIN_PROGS(METAL, metal)
675
if test "x$METAL" = x; then
676
AC_MSG_CHECKING([if metal can be run using xcrun])
677
METAL="xcrun -sdk macosx metal"
678
test_metal=`$METAL --version 2>&1`
679
if test $? -ne 0; then
681
AC_MSG_ERROR([XCode tool 'metal' neither found in path nor with xcrun])
683
AC_MSG_RESULT([yes, will be using '$METAL'])
687
UTIL_LOOKUP_TOOLCHAIN_PROGS(METALLIB, metallib)
688
if test "x$METALLIB" = x; then
689
AC_MSG_CHECKING([if metallib can be run using xcrun])
690
METALLIB="xcrun -sdk macosx metallib"
691
test_metallib=`$METALLIB --version 2>&1`
692
if test $? -ne 0; then
694
AC_MSG_ERROR([XCode tool 'metallib' neither found in path nor with xcrun])
696
AC_MSG_RESULT([yes, will be using '$METALLIB'])
701
if test "x$TOOLCHAIN_TYPE" = xmicrosoft; then
702
# Setup the manifest tool (MT)
703
UTIL_LOOKUP_TOOLCHAIN_PROGS(MT, mt)
704
# Setup the resource compiler (RC)
705
UTIL_LOOKUP_TOOLCHAIN_PROGS(RC, rc)
706
UTIL_LOOKUP_TOOLCHAIN_PROGS(DUMPBIN, dumpbin)
709
if test "x$OPENJDK_TARGET_OS" != xwindows; then
710
UTIL_LOOKUP_TOOLCHAIN_PROGS(STRIP, strip)
711
if test "x$TOOLCHAIN_TYPE" = xgcc; then
712
UTIL_LOOKUP_TOOLCHAIN_PROGS(NM, nm gcc-nm)
714
UTIL_LOOKUP_TOOLCHAIN_PROGS(NM, nm)
718
# objcopy is used for moving debug symbols to separate files when
719
# full debug symbols are enabled.
720
if test "x$OPENJDK_TARGET_OS" = xlinux; then
721
UTIL_LOOKUP_TOOLCHAIN_PROGS(OBJCOPY, gobjcopy objcopy)
724
UTIL_LOOKUP_TOOLCHAIN_PROGS(OBJDUMP, gobjdump objdump)
726
case $TOOLCHAIN_TYPE in
728
if test "x$OPENJDK_TARGET_OS" = xaix; then
729
UTIL_REQUIRE_TOOLCHAIN_PROGS(CXXFILT, ibm-llvm-cxxfilt)
731
UTIL_REQUIRE_TOOLCHAIN_PROGS(CXXFILT, c++filt)
737
# Setup the build tools (i.e, the compiler and linker used to build programs
738
# that should be run on the build platform, not the target platform, as a build
739
# helper). Since the non-cross-compile case uses the normal, target compilers
740
# for this, we can only do this after these have been setup.
741
AC_DEFUN_ONCE([TOOLCHAIN_SETUP_BUILD_COMPILERS],
743
if test "x$COMPILE_TYPE" = "xcross"; then
744
# Now we need to find a C/C++ compiler that can build executables for the
745
# build platform. We can't use the AC_PROG_CC macro, since it can only be
746
# used once. Also, we need to do this without adding a tools dir to the
747
# path, otherwise we might pick up cross-compilers which don't use standard
752
AC_ARG_WITH(build-devkit, [AS_HELP_STRING([--with-build-devkit],
753
[Devkit to use for the build platform toolchain])])
754
if test "x$with_build_devkit" = "xyes"; then
755
AC_MSG_ERROR([--with-build-devkit must have a value])
756
elif test -n "$with_build_devkit"; then
757
if test ! -d "$with_build_devkit"; then
758
AC_MSG_ERROR([--with-build-devkit points to non existing dir: $with_build_devkit])
760
UTIL_FIXUP_PATH([with_build_devkit])
761
BUILD_DEVKIT_ROOT="$with_build_devkit"
762
# Check for a meta data info file in the root of the devkit
763
if test -f "$BUILD_DEVKIT_ROOT/devkit.info"; then
764
# Process devkit.info so that existing devkit variables are not
766
$SED -e "s/^DEVKIT_/BUILD_DEVKIT_/g" \
767
-e "s/\$DEVKIT_ROOT/\$BUILD_DEVKIT_ROOT/g" \
768
-e "s/\$host/\$build/g" \
769
$BUILD_DEVKIT_ROOT/devkit.info \
770
> $CONFIGURESUPPORT_OUTPUTDIR/build-devkit.info
771
. $CONFIGURESUPPORT_OUTPUTDIR/build-devkit.info
772
# This potentially sets the following:
773
# A descriptive name of the devkit
774
BASIC_EVAL_BUILD_DEVKIT_VARIABLE([BUILD_DEVKIT_NAME])
775
# Corresponds to --with-extra-path
776
BASIC_EVAL_BUILD_DEVKIT_VARIABLE([BUILD_DEVKIT_EXTRA_PATH])
777
# Corresponds to --with-toolchain-path
778
BASIC_EVAL_BUILD_DEVKIT_VARIABLE([BUILD_DEVKIT_TOOLCHAIN_PATH])
779
# Corresponds to --with-sysroot
780
BASIC_EVAL_BUILD_DEVKIT_VARIABLE([BUILD_DEVKIT_SYSROOT])
782
if test "x$TOOLCHAIN_TYPE" = xmicrosoft; then
783
BASIC_EVAL_BUILD_DEVKIT_VARIABLE([BUILD_DEVKIT_VS_INCLUDE])
784
BASIC_EVAL_BUILD_DEVKIT_VARIABLE([BUILD_DEVKIT_VS_LIB])
788
AC_MSG_CHECKING([for build platform devkit])
789
if test "x$BUILD_DEVKIT_NAME" != x; then
790
AC_MSG_RESULT([$BUILD_DEVKIT_NAME in $BUILD_DEVKIT_ROOT])
792
AC_MSG_RESULT([$BUILD_DEVKIT_ROOT])
795
# Fallback default of just /bin if DEVKIT_PATH is not defined
796
if test "x$BUILD_DEVKIT_TOOLCHAIN_PATH" = x; then
797
BUILD_DEVKIT_TOOLCHAIN_PATH="$BUILD_DEVKIT_ROOT/bin"
799
PATH="$BUILD_DEVKIT_TOOLCHAIN_PATH:$BUILD_DEVKIT_EXTRA_PATH"
801
BUILD_SYSROOT="$BUILD_DEVKIT_SYSROOT"
803
if test "x$TOOLCHAIN_TYPE" = xmicrosoft; then
804
# For historical reasons, paths are separated by ; in devkit.info
805
BUILD_VS_INCLUDE="${BUILD_DEVKIT_VS_INCLUDE//;/:}"
806
BUILD_VS_LIB="${BUILD_DEVKIT_VS_LIB//;/:}"
808
TOOLCHAIN_SETUP_VISUAL_STUDIO_SYSROOT_FLAGS(BUILD_, BUILD_)
812
if test "x$TOOLCHAIN_TYPE" = xmicrosoft; then
813
# If we got no devkit, we need to go hunting for the proper env
814
TOOLCHAIN_FIND_VISUAL_STUDIO_BAT_FILE($OPENJDK_BUILD_CPU, [$TOOLCHAIN_VERSION])
815
TOOLCHAIN_EXTRACT_VISUAL_STUDIO_ENV($OPENJDK_BUILD_CPU, BUILD_)
817
# We cannot currently export the VS_PATH to spec.gmk. This is probably
818
# strictly not correct, but seems to work anyway.
820
# Convert VS_INCLUDE and VS_LIB into sysroot flags
821
TOOLCHAIN_SETUP_VISUAL_STUDIO_SYSROOT_FLAGS(BUILD_)
825
if test "x$TOOLCHAIN_TYPE" = xmicrosoft; then
826
UTIL_REQUIRE_PROGS(BUILD_CC, cl, [$VS_PATH])
827
UTIL_REQUIRE_PROGS(BUILD_CXX, cl, [$VS_PATH])
829
# On windows, the assembler is "ml.exe". We currently don't need this so
831
if test "x$OPENJDK_BUILD_CPU_BITS" = "x64"; then
832
# On 64 bit windows, the assembler is "ml64.exe"
833
UTIL_LOOKUP_PROGS(BUILD_AS, ml64, [$VS_PATH])
835
# otherwise the assembler is "ml.exe"
836
UTIL_LOOKUP_PROGS(BUILD_AS, ml, [$VS_PATH])
839
# On windows, the ar tool is lib.exe (used to create static libraries).
840
# We currently don't need this so do not require.
841
UTIL_LOOKUP_PROGS(BUILD_AR, lib, [$VS_PATH])
843
# In the Microsoft toolchain we have a separate LD command "link".
844
UTIL_REQUIRE_PROGS(BUILD_LD, link, [$VS_PATH])
845
TOOLCHAIN_VERIFY_LINK_BINARY(BUILD_LD)
846
BUILD_LDCXX="$BUILD_LD"
848
if test "x$OPENJDK_BUILD_OS" = xmacosx; then
849
UTIL_REQUIRE_PROGS(BUILD_CC, clang)
850
UTIL_REQUIRE_PROGS(BUILD_CXX, clang++)
852
UTIL_REQUIRE_PROGS(BUILD_CC, cc gcc)
853
UTIL_REQUIRE_PROGS(BUILD_CXX, CC g++)
855
UTIL_LOOKUP_PROGS(BUILD_NM, nm gcc-nm)
856
UTIL_LOOKUP_PROGS(BUILD_AR, ar gcc-ar lib)
857
UTIL_LOOKUP_PROGS(BUILD_OBJCOPY, objcopy)
858
UTIL_LOOKUP_PROGS(BUILD_STRIP, strip)
859
# Assume the C compiler is the assembler
860
BUILD_AS="$BUILD_CC -c"
861
# Just like for the target compiler, use the compiler as linker
863
BUILD_LDCXX="$BUILD_CXX"
868
TOOLCHAIN_EXTRACT_COMPILER_VERSION(BUILD_CC, [BuildC])
869
TOOLCHAIN_EXTRACT_COMPILER_VERSION(BUILD_CXX, [BuildC++])
870
TOOLCHAIN_PREPARE_FOR_VERSION_COMPARISONS([BUILD_], [OPENJDK_BUILD_], [build ])
871
TOOLCHAIN_EXTRACT_LD_VERSION(BUILD_LD, [build linker])
872
TOOLCHAIN_PREPARE_FOR_LD_VERSION_COMPARISONS([BUILD_], [OPENJDK_BUILD_])
874
# If we are not cross compiling, use the normal target compilers for
875
# building the build platform executables.
882
BUILD_OBJCOPY="$OBJCOPY"
886
TOOLCHAIN_PREPARE_FOR_VERSION_COMPARISONS([], [OPENJDK_BUILD_], [build ])
887
TOOLCHAIN_PREPARE_FOR_LD_VERSION_COMPARISONS([BUILD_], [OPENJDK_BUILD_])
893
AC_SUBST(BUILD_LDCXX)
899
# Do some additional checks on the detected tools.
900
AC_DEFUN_ONCE([TOOLCHAIN_MISC_CHECKS],
902
# Check for extra potential brokenness.
903
if test "x$TOOLCHAIN_TYPE" = xmicrosoft; then
904
# On Windows, double-check that we got the right compiler.
905
CC_VERSION_OUTPUT=`$CC 2>&1 1>/dev/null | $HEAD -n 1 | $TR -d '\r'`
906
COMPILER_CPU_TEST=`$ECHO $CC_VERSION_OUTPUT | $SED -n "s/^.* \(.*\)$/\1/p"`
907
if test "x$OPENJDK_TARGET_CPU" = "xx86"; then
908
if test "x$COMPILER_CPU_TEST" != "x80x86" -a "x$COMPILER_CPU_TEST" != "xx86"; then
909
AC_MSG_ERROR([Target CPU mismatch. We are building for $OPENJDK_TARGET_CPU but CL is for "$COMPILER_CPU_TEST"; expected "80x86" or "x86".])
911
elif test "x$OPENJDK_TARGET_CPU" = "xx86_64"; then
912
if test "x$COMPILER_CPU_TEST" != "xx64"; then
913
AC_MSG_ERROR([Target CPU mismatch. We are building for $OPENJDK_TARGET_CPU but CL is for "$COMPILER_CPU_TEST"; expected "x64".])
915
elif test "x$OPENJDK_TARGET_CPU" = "xaarch64"; then
916
if test "x$COMPILER_CPU_TEST" != "xARM64"; then
917
AC_MSG_ERROR([Target CPU mismatch. We are building for $OPENJDK_TARGET_CPU but CL is for "$COMPILER_CPU_TEST"; expected "arm64".])
921
if test "x$OPENJDK_TARGET_OS" = xaix; then
922
# Make sure we have the Open XL version of clang on AIX
924
$ECHO "$CC_VERSION_STRING" | $GREP "IBM Open XL C/C++ for AIX" > /dev/null
925
if test $? -ne 0; then
926
AC_MSG_ERROR([ibm-clang_r version output check failed, output: $CC_VERSION_OUTPUT])
930
if test "x$TOOLCHAIN_TYPE" = xgcc || test "x$TOOLCHAIN_TYPE" = xclang; then
931
# Check if linker has -z noexecstack.
932
HAS_NOEXECSTACK=`$CC -Wl,--help 2>/dev/null | $GREP 'z noexecstack'`
933
# This is later checked when setting flags.
936
# Setup hotspot lecagy names for toolchains
937
HOTSPOT_TOOLCHAIN_TYPE=$TOOLCHAIN_TYPE
938
if test "x$TOOLCHAIN_TYPE" = xclang; then
939
HOTSPOT_TOOLCHAIN_TYPE=gcc
940
elif test "x$TOOLCHAIN_TYPE" = xmicrosoft; then
941
HOTSPOT_TOOLCHAIN_TYPE=visCPP
943
AC_SUBST(HOTSPOT_TOOLCHAIN_TYPE)