toolchain.m4 revision 975:b18872ff5379
11573Srgrimes# 21573Srgrimes# Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved. 31573Srgrimes# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 41573Srgrimes# 51573Srgrimes# This code is free software; you can redistribute it and/or modify it 61573Srgrimes# under the terms of the GNU General Public License version 2 only, as 71573Srgrimes# published by the Free Software Foundation. Oracle designates this 81573Srgrimes# particular file as subject to the "Classpath" exception as provided 91573Srgrimes# by Oracle in the LICENSE file that accompanied this code. 101573Srgrimes# 111573Srgrimes# This code is distributed in the hope that it will be useful, but WITHOUT 121573Srgrimes# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 131573Srgrimes# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 141573Srgrimes# version 2 for more details (a copy is included in the LICENSE file that 151573Srgrimes# accompanied this code). 161573Srgrimes# 171573Srgrimes# You should have received a copy of the GNU General Public License version 181573Srgrimes# 2 along with this work; if not, write to the Free Software Foundation, 191573Srgrimes# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 201573Srgrimes# 211573Srgrimes# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 221573Srgrimes# or visit www.oracle.com if you need additional information or have any 231573Srgrimes# questions. 241573Srgrimes# 251573Srgrimes 261573Srgrimes######################################################################## 271573Srgrimes# This file is responsible for detecting, verifying and setting up the 281573Srgrimes# toolchain, i.e. the compiler, linker and related utilities. It will setup 2950476Speter# proper paths to the binaries, but it will not setup any flags. 301573Srgrimes# 31130485Sbms# The binaries used is determined by the toolchain type, which is the family of 321573Srgrimes# compilers and related tools that are used. 3379531Sru######################################################################## 341573Srgrimes 351573Srgrimes 361573Srgrimes# All valid toolchains, regardless of platform (used by help.m4) 371573SrgrimesVALID_TOOLCHAINS_all="gcc clang solstudio xlc microsoft" 3859460Sphantom 3959460Sphantom# These toolchains are valid on different platforms 401573SrgrimesVALID_TOOLCHAINS_linux="gcc clang" 4184306SruVALID_TOOLCHAINS_solaris="solstudio" 42130485SbmsVALID_TOOLCHAINS_macosx="gcc clang" 43152716SruVALID_TOOLCHAINS_aix="xlc" 441573SrgrimesVALID_TOOLCHAINS_windows="microsoft" 45152716Sru 46152716Sru# Toolchain descriptions 471573SrgrimesTOOLCHAIN_DESCRIPTION_clang="clang/LLVM" 481573SrgrimesTOOLCHAIN_DESCRIPTION_gcc="GNU Compiler Collection" 491573SrgrimesTOOLCHAIN_DESCRIPTION_microsoft="Microsoft Visual Studio" 501573SrgrimesTOOLCHAIN_DESCRIPTION_solstudio="Oracle Solaris Studio" 511573SrgrimesTOOLCHAIN_DESCRIPTION_xlc="IBM XL C/C++" 521573Srgrimes 531573Srgrimes# Setup a number of variables describing how native output files are 541573Srgrimes# named on this platform/toolchain. 551573SrgrimesAC_DEFUN([TOOLCHAIN_SETUP_FILENAME_PATTERNS], 561573Srgrimes[ 571573Srgrimes # Define filename patterns 58108040Sru if test "x$OPENJDK_TARGET_OS" = xwindows; then 5938845Sjb LIBRARY_PREFIX= 601573Srgrimes SHARED_LIBRARY_SUFFIX='.dll' 611573Srgrimes STATIC_LIBRARY_SUFFIX='.lib' 621573Srgrimes SHARED_LIBRARY='[$]1.dll' 63108037Sru STATIC_LIBRARY='[$]1.lib' 641573Srgrimes OBJ_SUFFIX='.obj' 65108037Sru EXE_SUFFIX='.exe' 661573Srgrimes else 671573Srgrimes LIBRARY_PREFIX=lib 681573Srgrimes SHARED_LIBRARY_SUFFIX='.so' 691573Srgrimes STATIC_LIBRARY_SUFFIX='.a' 701573Srgrimes SHARED_LIBRARY='lib[$]1.so' 711573Srgrimes STATIC_LIBRARY='lib[$]1.a' 721573Srgrimes OBJ_SUFFIX='.o' 731573Srgrimes EXE_SUFFIX='' 7479754Sdd if test "x$OPENJDK_TARGET_OS" = xmacosx; then 751573Srgrimes SHARED_LIBRARY='lib[$]1.dylib' 761573Srgrimes SHARED_LIBRARY_SUFFIX='.dylib' 771573Srgrimes fi 781573Srgrimes fi 791573Srgrimes 801573Srgrimes AC_SUBST(LIBRARY_PREFIX) 811573Srgrimes AC_SUBST(SHARED_LIBRARY_SUFFIX) 82108087Sru AC_SUBST(STATIC_LIBRARY_SUFFIX) 831573Srgrimes AC_SUBST(SHARED_LIBRARY) 841573Srgrimes AC_SUBST(STATIC_LIBRARY) 851573Srgrimes AC_SUBST(OBJ_SUFFIX) 86108087Sru AC_SUBST(EXE_SUFFIX) 871573Srgrimes]) 881573Srgrimes 891573Srgrimes# Determine which toolchain type to use, and make sure it is valid for this 901573Srgrimes# platform. Setup various information about the selected toolchain. 911573SrgrimesAC_DEFUN_ONCE([TOOLCHAIN_DETERMINE_TOOLCHAIN_TYPE], 9279754Sdd[ 931573Srgrimes AC_ARG_WITH(toolchain-type, [AS_HELP_STRING([--with-toolchain-type], 941573Srgrimes [the toolchain type (or family) to use, use '--help' to show possible values @<:@platform dependent@:>@])]) 951573Srgrimes 961573Srgrimes # Use indirect variable referencing 971573Srgrimes toolchain_var_name=VALID_TOOLCHAINS_$OPENJDK_BUILD_OS 981573Srgrimes VALID_TOOLCHAINS=${!toolchain_var_name} 991573Srgrimes # First toolchain type in the list is the default 1001573Srgrimes DEFAULT_TOOLCHAIN=${VALID_TOOLCHAINS%% *} 101234819Seadler 102234819Seadler if test "x$with_toolchain_type" = xlist; then 103234819Seadler # List all toolchains 104234819Seadler AC_MSG_NOTICE([The following toolchains are valid on this platform:]) 105234819Seadler for toolchain in $VALID_TOOLCHAINS; do 106234819Seadler toolchain_var_name=TOOLCHAIN_DESCRIPTION_$toolchain 107235327Sjoel TOOLCHAIN_DESCRIPTION=${!toolchain_var_name} 1081573Srgrimes $PRINTF " %-10s %s\n" $toolchain "$TOOLCHAIN_DESCRIPTION" 10970481Sru done 11070481Sru 11170481Sru exit 0 1121573Srgrimes elif test "x$with_toolchain_type" != x; then 1131573Srgrimes # User override; check that it is valid 1141573Srgrimes if test "x${VALID_TOOLCHAINS/$with_toolchain_type/}" = "x${VALID_TOOLCHAINS}"; then 1151573Srgrimes AC_MSG_NOTICE([Toolchain type $with_toolchain_type is not valid on this platform.]) 11615049Sjoerg AC_MSG_NOTICE([Valid toolchains: $VALID_TOOLCHAINS.]) 11715049Sjoerg AC_MSG_ERROR([Cannot continue.]) 118 fi 119 TOOLCHAIN_TYPE=$with_toolchain_type 120 else 121 # No flag given, use default 122 TOOLCHAIN_TYPE=$DEFAULT_TOOLCHAIN 123 fi 124 AC_SUBST(TOOLCHAIN_TYPE) 125 126 TOOLCHAIN_CC_BINARY_clang="clang" 127 TOOLCHAIN_CC_BINARY_gcc="gcc" 128 TOOLCHAIN_CC_BINARY_microsoft="cl" 129 TOOLCHAIN_CC_BINARY_solstudio="cc" 130 TOOLCHAIN_CC_BINARY_xlc="xlc_r" 131 132 TOOLCHAIN_CXX_BINARY_clang="clang++" 133 TOOLCHAIN_CXX_BINARY_gcc="g++" 134 TOOLCHAIN_CXX_BINARY_microsoft="cl" 135 TOOLCHAIN_CXX_BINARY_solstudio="CC" 136 TOOLCHAIN_CXX_BINARY_xlc="xlC_r" 137 138 # Use indirect variable referencing 139 toolchain_var_name=TOOLCHAIN_DESCRIPTION_$TOOLCHAIN_TYPE 140 TOOLCHAIN_DESCRIPTION=${!toolchain_var_name} 141 toolchain_var_name=TOOLCHAIN_CC_BINARY_$TOOLCHAIN_TYPE 142 TOOLCHAIN_CC_BINARY=${!toolchain_var_name} 143 toolchain_var_name=TOOLCHAIN_CXX_BINARY_$TOOLCHAIN_TYPE 144 TOOLCHAIN_CXX_BINARY=${!toolchain_var_name} 145 146 TOOLCHAIN_SETUP_FILENAME_PATTERNS 147 148 if test "x$TOOLCHAIN_TYPE" = "x$DEFAULT_TOOLCHAIN"; then 149 AC_MSG_NOTICE([Using default toolchain $TOOLCHAIN_TYPE ($TOOLCHAIN_DESCRIPTION)]) 150 else 151 AC_MSG_NOTICE([Using user selected toolchain $TOOLCHAIN_TYPE ($TOOLCHAIN_DESCRIPTION). Default toolchain is $DEFAULT_TOOLCHAIN.]) 152 fi 153]) 154 155# Before we start detecting the toolchain executables, we might need some 156# special setup, e.g. additional paths etc. 157AC_DEFUN_ONCE([TOOLCHAIN_PRE_DETECTION], 158[ 159 # FIXME: Is this needed? 160 AC_LANG(C++) 161 162 # Store the CFLAGS etc passed to the configure script. 163 ORG_CFLAGS="$CFLAGS" 164 ORG_CXXFLAGS="$CXXFLAGS" 165 ORG_OBJCFLAGS="$OBJCFLAGS" 166 167 # autoconf magic only relies on PATH, so update it if tools dir is specified 168 OLD_PATH="$PATH" 169 170 # For solaris we really need solaris tools, and not the GNU equivalent. 171 # The build tools on Solaris reside in /usr/ccs (C Compilation System), 172 # so add that to path before starting to probe. 173 # FIXME: This was originally only done for AS,NM,GNM,STRIP,MCS,OBJCOPY,OBJDUMP. 174 if test "x$OPENJDK_BUILD_OS" = xsolaris; then 175 PATH="/usr/ccs/bin:$PATH" 176 fi 177 178 # On Windows, we need to detect the visual studio installation first. 179 if test "x$OPENJDK_BUILD_OS" = "xwindows" && test "x$TOOLCHAIN_TYPE" = "xmicrosoft"; then 180 TOOLCHAIN_SETUP_VISUAL_STUDIO_ENV 181 fi 182 183 # Finally add TOOLS_DIR at the beginning, to allow --with-tools-dir to 184 # override all other locations. 185 if test "x$TOOLS_DIR" != x; then 186 PATH=$TOOLS_DIR:$PATH 187 fi 188 189 # If a devkit is found on the builddeps server, then prepend its path to the 190 # PATH variable. If there are cross compilers available in the devkit, these 191 # will be found by AC_PROG_CC et al. 192 DEVKIT= 193 BDEPS_CHECK_MODULE(DEVKIT, devkit, xxx, 194 [ 195 # Found devkit 196 PATH="$DEVKIT/bin:$PATH" 197 SYS_ROOT="$DEVKIT/${rewritten_target}/sys-root" 198 if test "x$x_includes" = "xNONE"; then 199 x_includes="$SYS_ROOT/usr/include/X11" 200 fi 201 if test "x$x_libraries" = "xNONE"; then 202 x_libraries="$SYS_ROOT/usr/lib" 203 fi 204 ], 205 []) 206]) 207 208# Restore path, etc 209AC_DEFUN_ONCE([TOOLCHAIN_POST_DETECTION], 210[ 211 # Restore old path. 212 PATH="$OLD_PATH" 213 214 # Restore the flags to the user specified values. 215 # This is necessary since AC_PROG_CC defaults CFLAGS to "-g -O2" 216 CFLAGS="$ORG_CFLAGS" 217 CXXFLAGS="$ORG_CXXFLAGS" 218 OBJCFLAGS="$ORG_OBJCFLAGS" 219]) 220 221# Check if a compiler is of the toolchain type we expect, and save the version 222# information from it. If the compiler does not match the expected type, 223# this function will abort using AC_MSG_ERROR. If it matches, the version will 224# be stored in CC_VERSION_NUMBER/CXX_VERSION_NUMBER (as a dotted number), and 225# the full version string in CC_VERSION_STRING/CXX_VERSION_STRING. 226# 227# $1 = compiler to test (CC or CXX) 228# $2 = human readable name of compiler (C or C++) 229AC_DEFUN([TOOLCHAIN_CHECK_COMPILER_VERSION], 230[ 231 COMPILER=[$]$1 232 COMPILER_NAME=$2 233 234 if test "x$TOOLCHAIN_TYPE" = xsolstudio; then 235 # cc -V output typically looks like 236 # cc: Sun C 5.12 Linux_i386 2011/11/16 237 COMPILER_VERSION_OUTPUT=`$COMPILER -V 2>&1` 238 # Check that this is likely to be the Solaris Studio cc. 239 $ECHO "$COMPILER_VERSION_OUTPUT" | $GREP "^.*: Sun $COMPILER_NAME" > /dev/null 240 if test $? -ne 0; then 241 ALT_VERSION_OUTPUT=`$COMPILER --version 2>&1` 242 AC_MSG_NOTICE([The $COMPILER_NAME compiler (located as $COMPILER) does not seem to be the required $TOOLCHAIN_TYPE compiler.]) 243 AC_MSG_NOTICE([The result from running with -V was: "$COMPILER_VERSION_OUTPUT"]) 244 AC_MSG_NOTICE([The result from running with --version was: "$ALT_VERSION_OUTPUT"]) 245 AC_MSG_ERROR([A $TOOLCHAIN_TYPE compiler is required. Try setting --with-tools-dir.]) 246 fi 247 # Remove usage instructions (if present), and 248 # collapse compiler output into a single line 249 COMPILER_VERSION_STRING=`$ECHO $COMPILER_VERSION_OUTPUT | \ 250 $SED -e 's/ *@<:@Uu@:>@sage:.*//'` 251 COMPILER_VERSION_NUMBER=`$ECHO $COMPILER_VERSION_OUTPUT | \ 252 $SED -e "s/^.*@<:@ ,\t@:>@$COMPILER_NAME@<:@ ,\t@:>@\(@<:@1-9@:>@\.@<:@0-9@:>@@<:@0-9@:>@*\).*/\1/"` 253 elif test "x$TOOLCHAIN_TYPE" = xxlc; then 254 # xlc -qversion output typically looks like 255 # IBM XL C/C++ for AIX, V11.1 (5724-X13) 256 # Version: 11.01.0000.0015 257 COMPILER_VERSION_OUTPUT=`$COMPILER -qversion 2>&1` 258 # Check that this is likely to be the IBM XL C compiler. 259 $ECHO "$COMPILER_VERSION_OUTPUT" | $GREP "IBM XL C" > /dev/null 260 if test $? -ne 0; then 261 ALT_VERSION_OUTPUT=`$COMPILER --version 2>&1` 262 AC_MSG_NOTICE([The $COMPILER_NAME compiler (located as $COMPILER) does not seem to be the required $TOOLCHAIN_TYPE compiler.]) 263 AC_MSG_NOTICE([The result from running with -qversion was: "$COMPILER_VERSION_OUTPUT"]) 264 AC_MSG_NOTICE([The result from running with --version was: "$ALT_VERSION_OUTPUT"]) 265 AC_MSG_ERROR([A $TOOLCHAIN_TYPE compiler is required. Try setting --with-tools-dir.]) 266 fi 267 # Collapse compiler output into a single line 268 COMPILER_VERSION_STRING=`$ECHO $COMPILER_VERSION_OUTPUT` 269 COMPILER_VERSION_NUMBER=`$ECHO $COMPILER_VERSION_OUTPUT | \ 270 $SED -e 's/^.*, V\(@<:@1-9@:>@@<:@0-9.@:>@*\).*$/\1/'` 271 elif test "x$TOOLCHAIN_TYPE" = xmicrosoft; then 272 # There is no specific version flag, but all output starts with a version string. 273 # First line typically looks something like: 274 # Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 16.00.40219.01 for 80x86 275 COMPILER_VERSION_OUTPUT=`$COMPILER 2>&1 | $HEAD -n 1 | $TR -d '\r'` 276 # Check that this is likely to be Microsoft CL.EXE. 277 $ECHO "$COMPILER_VERSION_OUTPUT" | $GREP "Microsoft.*Compiler" > /dev/null 278 if test $? -ne 0; then 279 AC_MSG_NOTICE([The $COMPILER_NAME compiler (located as $COMPILER) does not seem to be the required $TOOLCHAIN_TYPE compiler.]) 280 AC_MSG_NOTICE([The result from running it was: "$COMPILER_VERSION_OUTPUT"]) 281 AC_MSG_ERROR([A $TOOLCHAIN_TYPE compiler is required. Try setting --with-tools-dir.]) 282 fi 283 # Collapse compiler output into a single line 284 COMPILER_VERSION_STRING=`$ECHO $COMPILER_VERSION_OUTPUT` 285 COMPILER_VERSION_NUMBER=`$ECHO $COMPILER_VERSION_OUTPUT | \ 286 $SED -e 's/^.*ersion.\(@<:@1-9@:>@@<:@0-9.@:>@*\) .*$/\1/'` 287 elif test "x$TOOLCHAIN_TYPE" = xgcc; then 288 # gcc --version output typically looks like 289 # gcc (Ubuntu/Linaro 4.8.1-10ubuntu9) 4.8.1 290 # Copyright (C) 2013 Free Software Foundation, Inc. 291 # This is free software; see the source for copying conditions. There is NO 292 # warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 293 COMPILER_VERSION_OUTPUT=`$COMPILER --version 2>&1` 294 # Check that this is likely to be GCC. 295 $ECHO "$COMPILER_VERSION_OUTPUT" | $GREP "Free Software Foundation" > /dev/null 296 if test $? -ne 0; then 297 AC_MSG_NOTICE([The $COMPILER_NAME compiler (located as $COMPILER) does not seem to be the required $TOOLCHAIN_TYPE compiler.]) 298 AC_MSG_NOTICE([The result from running with --version was: "$COMPILER_VERSION"]) 299 AC_MSG_ERROR([A $TOOLCHAIN_TYPE compiler is required. Try setting --with-tools-dir.]) 300 fi 301 # Remove Copyright and legalese from version string, and 302 # collapse into a single line 303 COMPILER_VERSION_STRING=`$ECHO $COMPILER_VERSION_OUTPUT | \ 304 $SED -e 's/ *Copyright .*//'` 305 COMPILER_VERSION_NUMBER=`$ECHO $COMPILER_VERSION_OUTPUT | \ 306 $SED -e 's/^.* \(@<:@1-9@:>@\.@<:@0-9.@:>@*\) .*$/\1/'` 307 elif test "x$TOOLCHAIN_TYPE" = xclang; then 308 # clang --version output typically looks like 309 # Apple LLVM version 5.0 (clang-500.2.79) (based on LLVM 3.3svn) 310 # clang version 3.3 (tags/RELEASE_33/final) 311 # or 312 # Debian clang version 3.2-7ubuntu1 (tags/RELEASE_32/final) (based on LLVM 3.2) 313 # Target: x86_64-pc-linux-gnu 314 # Thread model: posix 315 COMPILER_VERSION_OUTPUT=`$COMPILER --version 2>&1` 316 # Check that this is likely to be clang 317 $ECHO "$COMPILER_VERSION_OUTPUT" | $GREP "clang" > /dev/null 318 if test $? -ne 0; then 319 AC_MSG_NOTICE([The $COMPILER_NAME compiler (located as $COMPILER) does not seem to be the required $TOOLCHAIN_TYPE compiler.]) 320 AC_MSG_NOTICE([The result from running with --version was: "$COMPILER_VERSION_OUTPUT"]) 321 AC_MSG_ERROR([A $TOOLCHAIN_TYPE compiler is required. Try setting --with-tools-dir.]) 322 fi 323 # Collapse compiler output into a single line 324 COMPILER_VERSION_STRING=`$ECHO $COMPILER_VERSION_OUTPUT` 325 COMPILER_VERSION_NUMBER=`$ECHO $COMPILER_VERSION_OUTPUT | \ 326 $SED -e 's/^.*clang version \(@<:@1-9@:>@@<:@0-9.@:>@*\).*$/\1/'` 327 else 328 AC_MSG_ERROR([Unknown toolchain type $TOOLCHAIN_TYPE.]) 329 fi 330 # This sets CC_VERSION_NUMBER or CXX_VERSION_NUMBER. (This comment is a grep marker) 331 $1_VERSION_NUMBER="$COMPILER_VERSION_NUMBER" 332 # This sets CC_VERSION_STRING or CXX_VERSION_STRING. (This comment is a grep marker) 333 $1_VERSION_STRING="$COMPILER_VERSION_STRING" 334 335 AC_MSG_NOTICE([Using $TOOLCHAIN_TYPE $COMPILER_NAME compiler version $COMPILER_VERSION_NUMBER @<:@$COMPILER_VERSION_STRING@:>@]) 336]) 337 338# Try to locate the given C or C++ compiler in the path, or otherwise. 339# 340# $1 = compiler to test (CC or CXX) 341# $2 = human readable name of compiler (C or C++) 342# $3 = list of compiler names to search for 343AC_DEFUN([TOOLCHAIN_FIND_COMPILER], 344[ 345 COMPILER_NAME=$2 346 SEARCH_LIST="$3" 347 348 if test "x[$]$1" != x; then 349 # User has supplied compiler name already, always let that override. 350 AC_MSG_NOTICE([Will use user supplied compiler $1=[$]$1]) 351 if test "x`basename [$]$1`" = "x[$]$1"; then 352 # A command without a complete path is provided, search $PATH. 353 354 AC_PATH_PROGS(POTENTIAL_$1, [$]$1) 355 if test "x$POTENTIAL_$1" != x; then 356 $1=$POTENTIAL_$1 357 else 358 AC_MSG_ERROR([User supplied compiler $1=[$]$1 could not be found]) 359 fi 360 else 361 # Otherwise it might already be a complete path 362 if test ! -x "[$]$1"; then 363 AC_MSG_ERROR([User supplied compiler $1=[$]$1 does not exist]) 364 fi 365 fi 366 else 367 # No user supplied value. Locate compiler ourselves. 368 369 # If we are cross compiling, assume cross compilation tools follows the 370 # cross compilation standard where they are prefixed with the autoconf 371 # standard name for the target. For example the binary 372 # i686-sun-solaris2.10-gcc will cross compile for i686-sun-solaris2.10. 373 # If we are not cross compiling, then the default compiler name will be 374 # used. 375 376 $1= 377 # If TOOLS_DIR is set, check for all compiler names in there first 378 # before checking the rest of the PATH. 379 # FIXME: Now that we prefix the TOOLS_DIR to the PATH in the PRE_DETECTION 380 # step, this should not be necessary. 381 if test -n "$TOOLS_DIR"; then 382 PATH_save="$PATH" 383 PATH="$TOOLS_DIR" 384 AC_PATH_PROGS(TOOLS_DIR_$1, $SEARCH_LIST) 385 $1=$TOOLS_DIR_$1 386 PATH="$PATH_save" 387 fi 388 389 # AC_PATH_PROGS can't be run multiple times with the same variable, 390 # so create a new name for this run. 391 if test "x[$]$1" = x; then 392 AC_PATH_PROGS(POTENTIAL_$1, $SEARCH_LIST) 393 $1=$POTENTIAL_$1 394 fi 395 396 if test "x[$]$1" = x; then 397 HELP_MSG_MISSING_DEPENDENCY([devkit]) 398 AC_MSG_ERROR([Could not find a $COMPILER_NAME compiler. $HELP_MSG]) 399 fi 400 fi 401 402 # Now we have a compiler binary in $1. Make sure it's okay. 403 BASIC_FIXUP_EXECUTABLE($1) 404 TEST_COMPILER="[$]$1" 405 # Don't remove symbolic links on AIX because 'xlc_r' and 'xlC_r' may all be links 406 # to 'xlc' but it is crucial that we invoke the compiler with the right name! 407 if test "x$OPENJDK_BUILD_OS" != xaix; then 408 # FIXME: This test should not be needed anymore; we don't do that for any platform. 409 AC_MSG_CHECKING([resolved symbolic links for $1]) 410 BASIC_REMOVE_SYMBOLIC_LINKS(TEST_COMPILER) 411 AC_MSG_RESULT([$TEST_COMPILER]) 412 fi 413 AC_MSG_CHECKING([if $1 is disguised ccache]) 414 415 COMPILER_BASENAME=`$BASENAME "$TEST_COMPILER"` 416 if test "x$COMPILER_BASENAME" = "xccache"; then 417 AC_MSG_RESULT([yes, trying to find proper $COMPILER_NAME compiler]) 418 # We /usr/lib/ccache in the path, so cc is a symlink to /usr/bin/ccache. 419 # We want to control ccache invocation ourselves, so ignore this cc and try 420 # searching again. 421 422 # Remove the path to the fake ccache cc from the PATH 423 RETRY_COMPILER_SAVED_PATH="$PATH" 424 COMPILER_DIRNAME=`$DIRNAME [$]$1` 425 PATH="`$ECHO $PATH | $SED -e "s,$COMPILER_DIRNAME,,g" -e "s,::,:,g" -e "s,^:,,g"`" 426 427 # Try again looking for our compiler 428 AC_CHECK_TOOLS(PROPER_COMPILER_$1, $3) 429 BASIC_FIXUP_EXECUTABLE(PROPER_COMPILER_$1) 430 PATH="$RETRY_COMPILER_SAVED_PATH" 431 432 AC_MSG_CHECKING([for resolved symbolic links for $1]) 433 BASIC_REMOVE_SYMBOLIC_LINKS(PROPER_COMPILER_$1) 434 AC_MSG_RESULT([$PROPER_COMPILER_$1]) 435 $1="$PROPER_COMPILER_$1" 436 else 437 AC_MSG_RESULT([no, keeping $1]) 438 fi 439 440 TOOLCHAIN_CHECK_COMPILER_VERSION([$1], [$COMPILER_NAME]) 441]) 442 443# Detect the core components of the toolchain, i.e. the compilers (CC and CXX), 444# preprocessor (CPP and CXXCPP), the linker (LD), the assembler (AS) and the 445# archiver (AR). Verify that the compilers are correct according to the 446# toolchain type. 447AC_DEFUN_ONCE([TOOLCHAIN_DETECT_TOOLCHAIN_CORE], 448[ 449 # 450 # Setup the compilers (CC and CXX) 451 # 452 TOOLCHAIN_FIND_COMPILER([CC], [C], $TOOLCHAIN_CC_BINARY) 453 # Now that we have resolved CC ourself, let autoconf have its go at it 454 AC_PROG_CC([$CC]) 455 456 TOOLCHAIN_FIND_COMPILER([CXX], [C++], $TOOLCHAIN_CXX_BINARY) 457 # Now that we have resolved CXX ourself, let autoconf have its go at it 458 AC_PROG_CXX([$CXX]) 459 460 # 461 # Setup the preprocessor (CPP and CXXCPP) 462 # 463 AC_PROG_CPP 464 BASIC_FIXUP_EXECUTABLE(CPP) 465 AC_PROG_CXXCPP 466 BASIC_FIXUP_EXECUTABLE(CXXCPP) 467 468 # 469 # Setup the linker (LD) 470 # 471 if test "x$TOOLCHAIN_TYPE" = xmicrosoft; then 472 # In the Microsoft toolchain we have a separate LD command "link". 473 # Make sure we reject /usr/bin/link (as determined in CYGWIN_LINK), which is 474 # a cygwin program for something completely different. 475 AC_CHECK_PROG([LD], [link],[link],,, [$CYGWIN_LINK]) 476 BASIC_FIXUP_EXECUTABLE(LD) 477 # Verify that we indeed succeeded with this trick. 478 AC_MSG_CHECKING([if the found link.exe is actually the Visual Studio linker]) 479 "$LD" --version > /dev/null 480 if test $? -eq 0 ; then 481 AC_MSG_RESULT([no]) 482 AC_MSG_ERROR([This is the Cygwin link tool. Please check your PATH and rerun configure.]) 483 else 484 AC_MSG_RESULT([yes]) 485 fi 486 LDCXX="$LD" 487 else 488 # All other toolchains use the compiler to link. 489 LD="$CC" 490 LDCXX="$CXX" 491 fi 492 AC_SUBST(LD) 493 # FIXME: it should be CXXLD, according to standard (cf CXXCPP) 494 AC_SUBST(LDCXX) 495 496 # 497 # Setup the assembler (AS) 498 # 499 if test "x$OPENJDK_TARGET_OS" = xsolaris; then 500 # FIXME: should this really be solaris, or solstudio? 501 BASIC_PATH_PROGS(AS, as) 502 BASIC_FIXUP_EXECUTABLE(AS) 503 else 504 # FIXME: is this correct for microsoft? 505 AS="$CC -c" 506 fi 507 AC_SUBST(AS) 508 509 # 510 # Setup the archiver (AR) 511 # 512 if test "x$TOOLCHAIN_TYPE" = xmicrosoft; then 513 # The corresponding ar tool is lib.exe (used to create static libraries) 514 AC_CHECK_PROG([AR], [lib],[lib],,,) 515 else 516 BASIC_CHECK_TOOLS(AR, ar) 517 fi 518 BASIC_FIXUP_EXECUTABLE(AR) 519]) 520 521# Setup additional tools that is considered a part of the toolchain, but not the 522# core part. Many of these are highly platform-specific and do not exist, 523# and/or are not needed on all platforms. 524AC_DEFUN_ONCE([TOOLCHAIN_DETECT_TOOLCHAIN_EXTRA], 525[ 526 if test "x$OPENJDK_TARGET_OS" = "xmacosx"; then 527 AC_PROG_OBJC 528 BASIC_FIXUP_EXECUTABLE(OBJC) 529 BASIC_PATH_PROGS(LIPO, lipo) 530 BASIC_FIXUP_EXECUTABLE(LIPO) 531 else 532 OBJC= 533 fi 534 535 if test "x$TOOLCHAIN_TYPE" = xmicrosoft; then 536 AC_CHECK_PROG([MT], [mt], [mt],,, [/usr/bin/mt]) 537 BASIC_FIXUP_EXECUTABLE(MT) 538 # Setup the resource compiler (RC) 539 AC_CHECK_PROG([RC], [rc], [rc],,, [/usr/bin/rc]) 540 BASIC_FIXUP_EXECUTABLE(RC) 541 AC_CHECK_PROG([DUMPBIN], [dumpbin], [dumpbin],,,) 542 BASIC_FIXUP_EXECUTABLE(DUMPBIN) 543 fi 544 545 if test "x$OPENJDK_TARGET_OS" = xsolaris; then 546 BASIC_PATH_PROGS(STRIP, strip) 547 BASIC_FIXUP_EXECUTABLE(STRIP) 548 BASIC_PATH_PROGS(NM, nm) 549 BASIC_FIXUP_EXECUTABLE(NM) 550 BASIC_PATH_PROGS(GNM, gnm) 551 BASIC_FIXUP_EXECUTABLE(GNM) 552 553 BASIC_PATH_PROGS(MCS, mcs) 554 BASIC_FIXUP_EXECUTABLE(MCS) 555 elif test "x$OPENJDK_TARGET_OS" != xwindows; then 556 # FIXME: we should unify this with the solaris case above. 557 BASIC_CHECK_TOOLS(STRIP, strip) 558 BASIC_FIXUP_EXECUTABLE(STRIP) 559 BASIC_CHECK_TOOLS(NM, nm) 560 BASIC_FIXUP_EXECUTABLE(NM) 561 GNM="$NM" 562 AC_SUBST(GNM) 563 fi 564 565 # objcopy is used for moving debug symbols to separate files when 566 # full debug symbols are enabled. 567 if test "x$OPENJDK_TARGET_OS" = xsolaris || test "x$OPENJDK_TARGET_OS" = xlinux; then 568 BASIC_CHECK_TOOLS(OBJCOPY, [gobjcopy objcopy]) 569 # Only call fixup if objcopy was found. 570 if test -n "$OBJCOPY"; then 571 BASIC_FIXUP_EXECUTABLE(OBJCOPY) 572 fi 573 fi 574 575 BASIC_CHECK_TOOLS(OBJDUMP, [gobjdump objdump]) 576 if test "x$OBJDUMP" != x; then 577 # Only used for compare.sh; we can live without it. BASIC_FIXUP_EXECUTABLE 578 # bails if argument is missing. 579 BASIC_FIXUP_EXECUTABLE(OBJDUMP) 580 fi 581]) 582 583# Setup the build tools (i.e, the compiler and linker used to build programs 584# that should be run on the build platform, not the target platform, as a build 585# helper). Since the non-cross-compile case uses the normal, target compilers 586# for this, we can only do this after these have been setup. 587AC_DEFUN_ONCE([TOOLCHAIN_SETUP_BUILD_COMPILERS], 588[ 589 if test "x$COMPILE_TYPE" = "xcross"; then 590 # Now we need to find a C/C++ compiler that can build executables for the 591 # build platform. We can't use the AC_PROG_CC macro, since it can only be 592 # used once. Also, we need to do this without adding a tools dir to the 593 # path, otherwise we might pick up cross-compilers which don't use standard 594 # naming. 595 596 # FIXME: we should list the discovered compilers as an exclude pattern! 597 # If we do that, we can do this detection before POST_DETECTION, and still 598 # find the build compilers in the tools dir, if needed. 599 BASIC_PATH_PROGS(BUILD_CC, [cl cc gcc]) 600 BASIC_FIXUP_EXECUTABLE(BUILD_CC) 601 BASIC_PATH_PROGS(BUILD_CXX, [cl CC g++]) 602 BASIC_FIXUP_EXECUTABLE(BUILD_CXX) 603 BASIC_PATH_PROGS(BUILD_LD, ld) 604 BASIC_FIXUP_EXECUTABLE(BUILD_LD) 605 else 606 # If we are not cross compiling, use the normal target compilers for 607 # building the build platform executables. 608 BUILD_CC="$CC" 609 BUILD_CXX="$CXX" 610 BUILD_LD="$LD" 611 fi 612 613 AC_SUBST(BUILD_CC) 614 AC_SUBST(BUILD_CXX) 615 AC_SUBST(BUILD_LD) 616]) 617 618# Setup legacy variables that are still needed as alternative ways to refer to 619# parts of the toolchain. 620AC_DEFUN_ONCE([TOOLCHAIN_SETUP_LEGACY], 621[ 622 if test "x$TOOLCHAIN_TYPE" = xmicrosoft; then 623 # For hotspot, we need these in Windows mixed path, 624 # so rewrite them all. Need added .exe suffix. 625 HOTSPOT_CXX="$CXX.exe" 626 HOTSPOT_LD="$LD.exe" 627 HOTSPOT_MT="$MT.exe" 628 HOTSPOT_RC="$RC.exe" 629 BASIC_WINDOWS_REWRITE_AS_WINDOWS_MIXED_PATH(HOTSPOT_CXX) 630 BASIC_WINDOWS_REWRITE_AS_WINDOWS_MIXED_PATH(HOTSPOT_LD) 631 BASIC_WINDOWS_REWRITE_AS_WINDOWS_MIXED_PATH(HOTSPOT_MT) 632 BASIC_WINDOWS_REWRITE_AS_WINDOWS_MIXED_PATH(HOTSPOT_RC) 633 AC_SUBST(HOTSPOT_MT) 634 AC_SUBST(HOTSPOT_RC) 635 else 636 HOTSPOT_CXX="$CXX" 637 HOTSPOT_LD="$LD" 638 fi 639 AC_SUBST(HOTSPOT_CXX) 640 AC_SUBST(HOTSPOT_LD) 641 642 if test "x$TOOLCHAIN_TYPE" = xclang; then 643 USE_CLANG=true 644 fi 645 AC_SUBST(USE_CLANG) 646 647 # LDEXE is the linker to use, when creating executables. Not really used. 648 # FIXME: These should just be removed! 649 LDEXE="$LD" 650 LDEXECXX="$LDCXX" 651 AC_SUBST(LDEXE) 652 AC_SUBST(LDEXECXX) 653]) 654 655# Do some additional checks on the detected tools. 656AC_DEFUN_ONCE([TOOLCHAIN_MISC_CHECKS], 657[ 658 # The package path is used only on macosx? 659 # FIXME: clean this up, and/or move it elsewhere. 660 PACKAGE_PATH=/opt/local 661 AC_SUBST(PACKAGE_PATH) 662 663 # Check for extra potential brokenness. 664 if test "x$TOOLCHAIN_TYPE" = xmicrosoft; then 665 # On Windows, double-check that we got the right compiler. 666 CC_VERSION_OUTPUT=`$CC 2>&1 | $HEAD -n 1 | $TR -d '\r'` 667 COMPILER_CPU_TEST=`$ECHO $CC_VERSION_OUTPUT | $SED -n "s/^.* \(.*\)$/\1/p"` 668 if test "x$OPENJDK_TARGET_CPU" = "xx86"; then 669 if test "x$COMPILER_CPU_TEST" != "x80x86"; then 670 AC_MSG_ERROR([Target CPU mismatch. We are building for $OPENJDK_TARGET_CPU but CL is for "$COMPILER_CPU_TEST"; expected "80x86".]) 671 fi 672 elif test "x$OPENJDK_TARGET_CPU" = "xx86_64"; then 673 if test "x$COMPILER_CPU_TEST" != "xx64"; then 674 AC_MSG_ERROR([Target CPU mismatch. We are building for $OPENJDK_TARGET_CPU but CL is for "$COMPILER_CPU_TEST"; expected "x64".]) 675 fi 676 fi 677 fi 678 679 if test "x$TOOLCHAIN_TYPE" = xgcc; then 680 # If this is a --hash-style=gnu system, use --hash-style=both, why? 681 HAS_GNU_HASH=`$CC -dumpspecs 2>/dev/null | $GREP 'hash-style=gnu'` 682 # This is later checked when setting flags. 683 fi 684 685 # Check for broken SuSE 'ld' for which 'Only anonymous version tag is allowed 686 # in executable.' 687 USING_BROKEN_SUSE_LD=no 688 if test "x$OPENJDK_TARGET_OS" = xlinux && test "x$TOOLCHAIN_TYPE" = xgcc; then 689 AC_MSG_CHECKING([for broken SuSE 'ld' which only understands anonymous version tags in executables]) 690 echo "SUNWprivate_1.1 { local: *; };" > version-script.map 691 echo "int main() { }" > main.c 692 if $CXX -Xlinker -version-script=version-script.map main.c 2>&AS_MESSAGE_LOG_FD >&AS_MESSAGE_LOG_FD; then 693 AC_MSG_RESULT(no) 694 USING_BROKEN_SUSE_LD=no 695 else 696 AC_MSG_RESULT(yes) 697 USING_BROKEN_SUSE_LD=yes 698 fi 699 rm -rf version-script.map main.c a.out 700 fi 701 AC_SUBST(USING_BROKEN_SUSE_LD) 702]) 703 704# Setup the JTReg Regression Test Harness. 705AC_DEFUN_ONCE([TOOLCHAIN_SETUP_JTREG], 706[ 707 AC_ARG_WITH(jtreg, [AS_HELP_STRING([--with-jtreg], 708 [Regression Test Harness @<:@probed@:>@])], 709 [], 710 [with_jtreg=no]) 711 712 if test "x$with_jtreg" = xno; then 713 # jtreg disabled 714 AC_MSG_CHECKING([for jtreg]) 715 AC_MSG_RESULT(no) 716 else 717 if test "x$with_jtreg" != xyes; then 718 # with path specified. 719 JT_HOME="$with_jtreg" 720 fi 721 722 if test "x$JT_HOME" != x; then 723 AC_MSG_CHECKING([for jtreg]) 724 725 # use JT_HOME enviroment var. 726 BASIC_FIXUP_PATH([JT_HOME]) 727 728 # jtreg win32 script works for everybody 729 JTREGEXE="$JT_HOME/win32/bin/jtreg" 730 731 if test ! -f "$JTREGEXE"; then 732 AC_MSG_ERROR([JTReg executable does not exist: $JTREGEXE]) 733 fi 734 735 AC_MSG_RESULT($JTREGEXE) 736 else 737 # try to find jtreg on path 738 BASIC_REQUIRE_PROGS(JTREGEXE, jtreg) 739 JT_HOME="`$DIRNAME $JTREGEXE`" 740 fi 741 fi 742 743 AC_SUBST(JT_HOME) 744 AC_SUBST(JTREGEXE) 745]) 746