toolchain.m4 revision 1829:5a7e1695ac8c
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 # Don't remove symbolic links on AIX because 'xlc_r' and 'xlC_r' may all be links 437 # to 'xlc' but it is crucial that we invoke the compiler with the right name! 438 if test "x$OPENJDK_BUILD_OS" != xaix; then 439 # FIXME: This test should not be needed anymore; we don't do that for any platform. 440 AC_MSG_CHECKING([resolved symbolic links for $1]) 441 BASIC_REMOVE_SYMBOLIC_LINKS(TEST_COMPILER) 442 AC_MSG_RESULT([$TEST_COMPILER]) 443 fi 444 AC_MSG_CHECKING([if $1 is disguised ccache]) 445 446 COMPILER_BASENAME=`$BASENAME "$TEST_COMPILER"` 447 if test "x$COMPILER_BASENAME" = "xccache"; then 448 AC_MSG_RESULT([yes, trying to find proper $COMPILER_NAME compiler]) 449 # We /usr/lib/ccache in the path, so cc is a symlink to /usr/bin/ccache. 450 # We want to control ccache invocation ourselves, so ignore this cc and try 451 # searching again. 452 453 # Remove the path to the fake ccache cc from the PATH 454 RETRY_COMPILER_SAVED_PATH="$PATH" 455 COMPILER_DIRNAME=`$DIRNAME [$]$1` 456 PATH="`$ECHO $PATH | $SED -e "s,$COMPILER_DIRNAME,,g" -e "s,::,:,g" -e "s,^:,,g"`" 457 458 # Try again looking for our compiler 459 AC_CHECK_TOOLS(PROPER_COMPILER_$1, $3) 460 BASIC_FIXUP_EXECUTABLE(PROPER_COMPILER_$1) 461 PATH="$RETRY_COMPILER_SAVED_PATH" 462 463 AC_MSG_CHECKING([for resolved symbolic links for $1]) 464 BASIC_REMOVE_SYMBOLIC_LINKS(PROPER_COMPILER_$1) 465 AC_MSG_RESULT([$PROPER_COMPILER_$1]) 466 $1="$PROPER_COMPILER_$1" 467 else 468 AC_MSG_RESULT([no, keeping $1]) 469 fi 470 471 TOOLCHAIN_CHECK_COMPILER_VERSION([$1], [$COMPILER_NAME]) 472]) 473 474# Detect the core components of the toolchain, i.e. the compilers (CC and CXX), 475# preprocessor (CPP and CXXCPP), the linker (LD), the assembler (AS) and the 476# archiver (AR). Verify that the compilers are correct according to the 477# toolchain type. 478AC_DEFUN_ONCE([TOOLCHAIN_DETECT_TOOLCHAIN_CORE], 479[ 480 # 481 # Setup the compilers (CC and CXX) 482 # 483 TOOLCHAIN_FIND_COMPILER([CC], [C], $TOOLCHAIN_CC_BINARY) 484 # Now that we have resolved CC ourself, let autoconf have its go at it 485 AC_PROG_CC([$CC]) 486 487 TOOLCHAIN_FIND_COMPILER([CXX], [C++], $TOOLCHAIN_CXX_BINARY) 488 # Now that we have resolved CXX ourself, let autoconf have its go at it 489 AC_PROG_CXX([$CXX]) 490 491 # 492 # Setup the preprocessor (CPP and CXXCPP) 493 # 494 AC_PROG_CPP 495 BASIC_FIXUP_EXECUTABLE(CPP) 496 AC_PROG_CXXCPP 497 BASIC_FIXUP_EXECUTABLE(CXXCPP) 498 499 # 500 # Setup the linker (LD) 501 # 502 if test "x$TOOLCHAIN_TYPE" = xmicrosoft; then 503 # In the Microsoft toolchain we have a separate LD command "link". 504 # Make sure we reject /usr/bin/link (as determined in CYGWIN_LINK), which is 505 # a cygwin program for something completely different. 506 AC_CHECK_PROG([LD], [link],[link],,, [$CYGWIN_LINK]) 507 BASIC_FIXUP_EXECUTABLE(LD) 508 # Verify that we indeed succeeded with this trick. 509 AC_MSG_CHECKING([if the found link.exe is actually the Visual Studio linker]) 510 "$LD" --version > /dev/null 511 if test $? -eq 0 ; then 512 AC_MSG_RESULT([no]) 513 AC_MSG_ERROR([This is the Cygwin link tool. Please check your PATH and rerun configure.]) 514 else 515 AC_MSG_RESULT([yes]) 516 fi 517 LDCXX="$LD" 518 else 519 # All other toolchains use the compiler to link. 520 LD="$CC" 521 LDCXX="$CXX" 522 fi 523 AC_SUBST(LD) 524 # FIXME: it should be CXXLD, according to standard (cf CXXCPP) 525 AC_SUBST(LDCXX) 526 527 # 528 # Setup the assembler (AS) 529 # 530 if test "x$OPENJDK_TARGET_OS" = xsolaris; then 531 # FIXME: should this really be solaris, or solstudio? 532 BASIC_PATH_PROGS(AS, as) 533 BASIC_FIXUP_EXECUTABLE(AS) 534 else 535 # FIXME: is this correct for microsoft? 536 AS="$CC -c" 537 fi 538 AC_SUBST(AS) 539 540 # 541 # Setup the archiver (AR) 542 # 543 if test "x$TOOLCHAIN_TYPE" = xmicrosoft; then 544 # The corresponding ar tool is lib.exe (used to create static libraries) 545 AC_CHECK_PROG([AR], [lib],[lib],,,) 546 elif test "x$TOOLCHAIN_TYPE" = xgcc; then 547 BASIC_CHECK_TOOLS(AR, ar gcc-ar) 548 else 549 BASIC_CHECK_TOOLS(AR, ar) 550 fi 551 BASIC_FIXUP_EXECUTABLE(AR) 552]) 553 554# Setup additional tools that is considered a part of the toolchain, but not the 555# core part. Many of these are highly platform-specific and do not exist, 556# and/or are not needed on all platforms. 557AC_DEFUN_ONCE([TOOLCHAIN_DETECT_TOOLCHAIN_EXTRA], 558[ 559 if test "x$OPENJDK_TARGET_OS" = "xmacosx"; then 560 BASIC_PATH_PROGS(LIPO, lipo) 561 BASIC_FIXUP_EXECUTABLE(LIPO) 562 fi 563 564 if test "x$TOOLCHAIN_TYPE" = xmicrosoft; then 565 AC_CHECK_PROG([MT], [mt], [mt],,, [/usr/bin/mt]) 566 BASIC_FIXUP_EXECUTABLE(MT) 567 # Setup the resource compiler (RC) 568 AC_CHECK_PROG([RC], [rc], [rc],,, [/usr/bin/rc]) 569 BASIC_FIXUP_EXECUTABLE(RC) 570 AC_CHECK_PROG([DUMPBIN], [dumpbin], [dumpbin],,,) 571 BASIC_FIXUP_EXECUTABLE(DUMPBIN) 572 # We need to check for 'msbuild.exe' because at the place where we expect to 573 # find 'msbuild.exe' there's also a directory called 'msbuild' and configure 574 # won't find the 'msbuild.exe' executable in that case (and the 575 # 'ac_executable_extensions' is unusable due to performance reasons). 576 # Notice that we intentionally don't fix up the path to MSBUILD because we 577 # will call it in a DOS shell during freetype detection on Windows (see 578 # 'LIB_SETUP_FREETYPE' in "libraries.m4" 579 AC_CHECK_PROG([MSBUILD], [msbuild.exe], [msbuild.exe],,,) 580 fi 581 582 if test "x$OPENJDK_TARGET_OS" = xsolaris; then 583 BASIC_PATH_PROGS(STRIP, strip) 584 BASIC_FIXUP_EXECUTABLE(STRIP) 585 BASIC_PATH_PROGS(NM, nm) 586 BASIC_FIXUP_EXECUTABLE(NM) 587 BASIC_PATH_PROGS(GNM, gnm) 588 BASIC_FIXUP_EXECUTABLE(GNM) 589 elif test "x$OPENJDK_TARGET_OS" != xwindows; then 590 # FIXME: we should unify this with the solaris case above. 591 BASIC_CHECK_TOOLS(STRIP, strip) 592 BASIC_FIXUP_EXECUTABLE(STRIP) 593 if test "x$TOOLCHAIN_TYPE" = xgcc; then 594 BASIC_CHECK_TOOLS(NM, nm gcc-nm) 595 else 596 BASIC_CHECK_TOOLS(NM, nm) 597 fi 598 BASIC_FIXUP_EXECUTABLE(NM) 599 GNM="$NM" 600 AC_SUBST(GNM) 601 fi 602 603 # objcopy is used for moving debug symbols to separate files when 604 # full debug symbols are enabled. 605 if test "x$OPENJDK_TARGET_OS" = xsolaris || test "x$OPENJDK_TARGET_OS" = xlinux; then 606 BASIC_CHECK_TOOLS(OBJCOPY, [gobjcopy objcopy]) 607 # Only call fixup if objcopy was found. 608 if test -n "$OBJCOPY"; then 609 BASIC_FIXUP_EXECUTABLE(OBJCOPY) 610 if test "x$OPENJDK_BUILD_OS" = xsolaris; then 611 # objcopy prior to 2.21.1 on solaris is broken and is not usable. 612 # Rewrite objcopy version output to VALID_VERSION or BAD_VERSION. 613 # - version number is last blank separate word on first line 614 # - version number formats that have been seen: 615 # - <major>.<minor> 616 # - <major>.<minor>.<micro> 617 OBJCOPY_VERSION=`$OBJCOPY --version | $HEAD -n 1` 618 # The outer [ ] is to prevent m4 from eating the [] in the sed expression. 619 [ OBJCOPY_VERSION_CHECK=`$ECHO $OBJCOPY_VERSION | $SED -n \ 620 -e 's/.* //' \ 621 -e '/^[01]\./b bad' \ 622 -e '/^2\./{' \ 623 -e ' s/^2\.//' \ 624 -e ' /^[0-9]$/b bad' \ 625 -e ' /^[0-9]\./b bad' \ 626 -e ' /^1[0-9]$/b bad' \ 627 -e ' /^1[0-9]\./b bad' \ 628 -e ' /^20\./b bad' \ 629 -e ' /^21\.0$/b bad' \ 630 -e ' /^21\.0\./b bad' \ 631 -e '}' \ 632 -e ':good' \ 633 -e 's/.*/VALID_VERSION/p' \ 634 -e 'q' \ 635 -e ':bad' \ 636 -e 's/.*/BAD_VERSION/p' \ 637 -e 'q'` ] 638 if test "x$OBJCOPY_VERSION_CHECK" = xBAD_VERSION; then 639 OBJCOPY= 640 AC_MSG_WARN([Ignoring found objcopy since it is broken (prior to 2.21.1). No debug symbols will be generated.]) 641 AC_MSG_NOTICE([objcopy reports version $OBJCOPY_VERSION]) 642 AC_MSG_NOTICE([Note: patch 149063-01 or newer contains the correct Solaris 10 SPARC version]) 643 AC_MSG_NOTICE([Note: patch 149064-01 or newer contains the correct Solaris 10 X86 version]) 644 AC_MSG_NOTICE([Note: Solaris 11 Update 1 contains the correct version]) 645 fi 646 fi 647 fi 648 fi 649 650 BASIC_CHECK_TOOLS(OBJDUMP, [gobjdump objdump]) 651 if test "x$OBJDUMP" != x; then 652 # Only used for compare.sh; we can live without it. BASIC_FIXUP_EXECUTABLE 653 # bails if argument is missing. 654 BASIC_FIXUP_EXECUTABLE(OBJDUMP) 655 fi 656]) 657 658# Setup the build tools (i.e, the compiler and linker used to build programs 659# that should be run on the build platform, not the target platform, as a build 660# helper). Since the non-cross-compile case uses the normal, target compilers 661# for this, we can only do this after these have been setup. 662AC_DEFUN_ONCE([TOOLCHAIN_SETUP_BUILD_COMPILERS], 663[ 664 if test "x$COMPILE_TYPE" = "xcross"; then 665 # Now we need to find a C/C++ compiler that can build executables for the 666 # build platform. We can't use the AC_PROG_CC macro, since it can only be 667 # used once. Also, we need to do this without adding a tools dir to the 668 # path, otherwise we might pick up cross-compilers which don't use standard 669 # naming. 670 671 OLDPATH="$PATH" 672 673 AC_ARG_WITH(build-devkit, [AS_HELP_STRING([--with-build-devkit], 674 [Devkit to use for the build platform toolchain])]) 675 if test "x$with_build_devkit" = "xyes"; then 676 AC_MSG_ERROR([--with-build-devkit must have a value]) 677 elif test -n "$with_build_devkit"; then 678 if test ! -d "$with_build_devkit"; then 679 AC_MSG_ERROR([--with-build-devkit points to non existing dir: $with_build_devkit]) 680 else 681 BASIC_FIXUP_PATH([with_build_devkit]) 682 BUILD_DEVKIT_ROOT="$with_build_devkit" 683 # Check for a meta data info file in the root of the devkit 684 if test -f "$BUILD_DEVKIT_ROOT/devkit.info"; then 685 # Process devkit.info so that existing devkit variables are not 686 # modified by this 687 $SED -e "s/^DEVKIT_/BUILD_DEVKIT_/g" \ 688 -e "s/\$DEVKIT_ROOT/\$BUILD_DEVKIT_ROOT/g" \ 689 -e "s/\$host/\$build/g" \ 690 $BUILD_DEVKIT_ROOT/devkit.info \ 691 > $CONFIGURESUPPORT_OUTPUTDIR/build-devkit.info 692 . $CONFIGURESUPPORT_OUTPUTDIR/build-devkit.info 693 # This potentially sets the following: 694 # A descriptive name of the devkit 695 BASIC_EVAL_DEVKIT_VARIABLE([BUILD_DEVKIT_NAME]) 696 # Corresponds to --with-extra-path 697 BASIC_EVAL_DEVKIT_VARIABLE([BUILD_DEVKIT_EXTRA_PATH]) 698 # Corresponds to --with-toolchain-path 699 BASIC_EVAL_DEVKIT_VARIABLE([BUILD_DEVKIT_TOOLCHAIN_PATH]) 700 # Corresponds to --with-sysroot 701 BASIC_EVAL_DEVKIT_VARIABLE([BUILD_DEVKIT_SYSROOT]) 702 # Skip the Window specific parts 703 fi 704 705 AC_MSG_CHECKING([for build platform devkit]) 706 if test "x$BUILD_DEVKIT_NAME" != x; then 707 AC_MSG_RESULT([$BUILD_DEVKIT_NAME in $BUILD_DEVKIT_ROOT]) 708 else 709 AC_MSG_RESULT([$BUILD_DEVKIT_ROOT]) 710 fi 711 712 BUILD_SYSROOT="$BUILD_DEVKIT_SYSROOT" 713 FLAGS_SETUP_SYSROOT_FLAGS([BUILD_]) 714 715 # Fallback default of just /bin if DEVKIT_PATH is not defined 716 if test "x$BUILD_DEVKIT_TOOLCHAIN_PATH" = x; then 717 BUILD_DEVKIT_TOOLCHAIN_PATH="$BUILD_DEVKIT_ROOT/bin" 718 fi 719 PATH="$BUILD_DEVKIT_TOOLCHAIN_PATH:$BUILD_DEVKIT_EXTRA_PATH" 720 fi 721 fi 722 723 # FIXME: we should list the discovered compilers as an exclude pattern! 724 # If we do that, we can do this detection before POST_DETECTION, and still 725 # find the build compilers in the tools dir, if needed. 726 BASIC_REQUIRE_PROGS(BUILD_CC, [cl cc gcc]) 727 BASIC_FIXUP_EXECUTABLE(BUILD_CC) 728 BASIC_REQUIRE_PROGS(BUILD_CXX, [cl CC g++]) 729 BASIC_FIXUP_EXECUTABLE(BUILD_CXX) 730 BASIC_PATH_PROGS(BUILD_NM, nm gcc-nm) 731 BASIC_FIXUP_EXECUTABLE(BUILD_NM) 732 BASIC_PATH_PROGS(BUILD_AR, ar gcc-ar) 733 BASIC_FIXUP_EXECUTABLE(BUILD_AR) 734 # Assume the C compiler is the assembler 735 BUILD_AS="$BUILD_CC -c" 736 # Just like for the target compiler, use the compiler as linker 737 BUILD_LD="$BUILD_CC" 738 BUILD_LDCXX="$BUILD_CXX" 739 740 PATH="$OLDPATH" 741 else 742 # If we are not cross compiling, use the normal target compilers for 743 # building the build platform executables. 744 BUILD_CC="$CC" 745 BUILD_CXX="$CXX" 746 BUILD_LD="$LD" 747 BUILD_LDCXX="$LDCXX" 748 BUILD_NM="$NM" 749 BUILD_AS="$AS" 750 BUILD_SYSROOT_CFLAGS="$SYSROOT_CFLAGS" 751 BUILD_SYSROOT_LDFLAGS="$SYSROOT_LDFLAGS" 752 BUILD_AR="$AR" 753 fi 754 755 AC_SUBST(BUILD_CC) 756 AC_SUBST(BUILD_CXX) 757 AC_SUBST(BUILD_LD) 758 AC_SUBST(BUILD_LDCXX) 759 AC_SUBST(BUILD_NM) 760 AC_SUBST(BUILD_AS) 761 AC_SUBST(BUILD_SYSROOT_CFLAGS) 762 AC_SUBST(BUILD_SYSROOT_LDFLAGS) 763 AC_SUBST(BUILD_AR) 764]) 765 766# Setup legacy variables that are still needed as alternative ways to refer to 767# parts of the toolchain. 768AC_DEFUN_ONCE([TOOLCHAIN_SETUP_LEGACY], 769[ 770 if test "x$TOOLCHAIN_TYPE" = xmicrosoft; then 771 # For hotspot, we need these in Windows mixed path, 772 # so rewrite them all. Need added .exe suffix. 773 HOTSPOT_CXX="$CXX.exe" 774 HOTSPOT_LD="$LD.exe" 775 HOTSPOT_MT="$MT.exe" 776 HOTSPOT_RC="$RC.exe" 777 BASIC_WINDOWS_REWRITE_AS_WINDOWS_MIXED_PATH(HOTSPOT_CXX) 778 BASIC_WINDOWS_REWRITE_AS_WINDOWS_MIXED_PATH(HOTSPOT_LD) 779 BASIC_WINDOWS_REWRITE_AS_WINDOWS_MIXED_PATH(HOTSPOT_MT) 780 BASIC_WINDOWS_REWRITE_AS_WINDOWS_MIXED_PATH(HOTSPOT_RC) 781 AC_SUBST(HOTSPOT_MT) 782 AC_SUBST(HOTSPOT_RC) 783 else 784 HOTSPOT_CXX="$CXX" 785 HOTSPOT_LD="$LD" 786 fi 787 AC_SUBST(HOTSPOT_CXX) 788 AC_SUBST(HOTSPOT_LD) 789 790 if test "x$TOOLCHAIN_TYPE" = xclang; then 791 USE_CLANG=true 792 fi 793 AC_SUBST(USE_CLANG) 794]) 795 796# Do some additional checks on the detected tools. 797AC_DEFUN_ONCE([TOOLCHAIN_MISC_CHECKS], 798[ 799 # The package path is used only on macosx? 800 # FIXME: clean this up, and/or move it elsewhere. 801 PACKAGE_PATH=/opt/local 802 AC_SUBST(PACKAGE_PATH) 803 804 # Check for extra potential brokenness. 805 if test "x$TOOLCHAIN_TYPE" = xmicrosoft; then 806 # On Windows, double-check that we got the right compiler. 807 CC_VERSION_OUTPUT=`$CC 2>&1 | $HEAD -n 1 | $TR -d '\r'` 808 COMPILER_CPU_TEST=`$ECHO $CC_VERSION_OUTPUT | $SED -n "s/^.* \(.*\)$/\1/p"` 809 if test "x$OPENJDK_TARGET_CPU" = "xx86"; then 810 if test "x$COMPILER_CPU_TEST" != "x80x86" -a "x$COMPILER_CPU_TEST" != "xx86"; then 811 AC_MSG_ERROR([Target CPU mismatch. We are building for $OPENJDK_TARGET_CPU but CL is for "$COMPILER_CPU_TEST"; expected "80x86" or "x86".]) 812 fi 813 elif test "x$OPENJDK_TARGET_CPU" = "xx86_64"; then 814 if test "x$COMPILER_CPU_TEST" != "xx64"; then 815 AC_MSG_ERROR([Target CPU mismatch. We are building for $OPENJDK_TARGET_CPU but CL is for "$COMPILER_CPU_TEST"; expected "x64".]) 816 fi 817 fi 818 fi 819 820 if test "x$TOOLCHAIN_TYPE" = xgcc; then 821 # If this is a --hash-style=gnu system, use --hash-style=both, why? 822 HAS_GNU_HASH=`$CC -dumpspecs 2>/dev/null | $GREP 'hash-style=gnu'` 823 # This is later checked when setting flags. 824 825 # "-Og" suppported for GCC 4.8 and later 826 CFLAG_OPTIMIZE_DEBUG_FLAG="-Og" 827 FLAGS_COMPILER_CHECK_ARGUMENTS([$CFLAG_OPTIMIZE_DEBUG_FLAG], 828 [HAS_CFLAG_OPTIMIZE_DEBUG=true], 829 [HAS_CFLAG_OPTIMIZE_DEBUG=false]) 830 831 # "-z relro" supported in GNU binutils 2.17 and later 832 LINKER_RELRO_FLAG="-Wl,-z,relro" 833 FLAGS_LINKER_CHECK_ARGUMENTS([$LINKER_RELRO_FLAG], 834 [HAS_LINKER_RELRO=true], 835 [HAS_LINKER_RELRO=false]) 836 837 # "-z now" supported in GNU binutils 2.11 and later 838 LINKER_NOW_FLAG="-Wl,-z,now" 839 FLAGS_LINKER_CHECK_ARGUMENTS([$LINKER_NOW_FLAG], 840 [HAS_LINKER_NOW=true], 841 [HAS_LINKER_NOW=false]) 842 fi 843 844 # Check for broken SuSE 'ld' for which 'Only anonymous version tag is allowed 845 # in executable.' 846 USING_BROKEN_SUSE_LD=no 847 if test "x$OPENJDK_TARGET_OS" = xlinux && test "x$TOOLCHAIN_TYPE" = xgcc; then 848 AC_MSG_CHECKING([for broken SuSE 'ld' which only understands anonymous version tags in executables]) 849 $ECHO "SUNWprivate_1.1 { local: *; };" > version-script.map 850 $ECHO "int main() { }" > main.c 851 if $CXX -Wl,-version-script=version-script.map main.c 2>&AS_MESSAGE_LOG_FD >&AS_MESSAGE_LOG_FD; then 852 AC_MSG_RESULT(no) 853 USING_BROKEN_SUSE_LD=no 854 else 855 AC_MSG_RESULT(yes) 856 USING_BROKEN_SUSE_LD=yes 857 fi 858 rm -rf version-script.map main.c a.out 859 fi 860 AC_SUBST(USING_BROKEN_SUSE_LD) 861]) 862 863# Setup the JTReg Regression Test Harness. 864AC_DEFUN_ONCE([TOOLCHAIN_SETUP_JTREG], 865[ 866 AC_ARG_WITH(jtreg, [AS_HELP_STRING([--with-jtreg], 867 [Regression Test Harness @<:@probed@:>@])], 868 [], 869 [with_jtreg=no]) 870 871 if test "x$with_jtreg" = xno; then 872 # jtreg disabled 873 AC_MSG_CHECKING([for jtreg]) 874 AC_MSG_RESULT(no) 875 else 876 if test "x$with_jtreg" != xyes; then 877 # with path specified. 878 JT_HOME="$with_jtreg" 879 fi 880 881 if test "x$JT_HOME" != x; then 882 AC_MSG_CHECKING([for jtreg]) 883 884 # use JT_HOME enviroment var. 885 BASIC_FIXUP_PATH([JT_HOME]) 886 887 # jtreg win32 script works for everybody 888 JTREGEXE="$JT_HOME/bin/jtreg" 889 890 if test ! -f "$JTREGEXE"; then 891 AC_MSG_ERROR([JTReg executable does not exist: $JTREGEXE]) 892 fi 893 894 AC_MSG_RESULT($JTREGEXE) 895 else 896 # try to find jtreg on path 897 BASIC_REQUIRE_PROGS(JTREGEXE, jtreg) 898 JT_HOME="`$DIRNAME $JTREGEXE`" 899 fi 900 fi 901 902 AC_SUBST(JT_HOME) 903 AC_SUBST(JTREGEXE) 904]) 905