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