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