1 #
   2 # Copyright (c) 2011, 2012, 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 # $1 = compiler to test (CC or CXX)
  27 # $2 = human readable name of compiler (C or C++)
  28 AC_DEFUN([TOOLCHAIN_CHECK_COMPILER_VERSION],
  29 [
  30   COMPILER=[$]$1
  31   COMPILER_NAME=$2
  32 
  33   if test "x$OPENJDK_TARGET_OS" = xsolaris; then
  34     # Make sure we use the Sun Studio compiler and not gcc on Solaris, which won't work
  35     COMPILER_VERSION_TEST=`$COMPILER -V 2>&1 | $HEAD -n 1`
  36     $ECHO $COMPILER_VERSION_TEST | $GREP "^.*: Sun $COMPILER_NAME" > /dev/null
  37     if test $? -ne 0; then
  38       GCC_VERSION_TEST=`$COMPILER --version 2>&1 | $HEAD -n 1`
  39 
  40       AC_MSG_NOTICE([The $COMPILER_NAME compiler (located as $COMPILER) does not seem to be the required Sun Studio compiler.])
  41       AC_MSG_NOTICE([The result from running with -V was: "$COMPILER_VERSION_TEST" and with --version: "$GCC_VERSION_TEST"])
  42       AC_MSG_ERROR([Sun Studio compiler is required. Try setting --with-tools-dir.])
  43     else
  44       COMPILER_VERSION=`$ECHO $COMPILER_VERSION_TEST | $SED -n "s/^.*@<:@ ,\t@:>@$COMPILER_NAME@<:@ ,\t@:>@\(@<:@1-9@:>@\.@<:@0-9@:>@@<:@0-9@:>@*\).*/\1/p"`
  45       COMPILER_VENDOR="Sun Studio"
  46     fi
  47   elif test  "x$OPENJDK_TARGET_OS" = xwindows; then
  48     # First line typically looks something like:
  49     # Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 16.00.30319.01 for 80x86
  50     COMPILER_VERSION_TEST=`$COMPILER 2>&1 | $HEAD -n 1 | $TR -d '\r'`
  51     COMPILER_VERSION=`$ECHO $COMPILER_VERSION_TEST | $SED -n "s/^.*Version \(@<:@1-9@:>@@<:@0-9.@:>@*\) .*/\1/p"`
  52     COMPILER_VENDOR="Microsoft CL.EXE"
  53     COMPILER_CPU_TEST=`$ECHO $COMPILER_VERSION_TEST | $SED -n "s/^.* for \(.*\)$/\1/p"`
  54     if test "x$OPENJDK_TARGET_CPU" = "xx86"; then
  55       if test "x$COMPILER_CPU_TEST" != "x80x86"; then
  56         AC_MSG_ERROR([Target CPU mismatch. We are building for $OPENJDK_TARGET_CPU but CL is for "$COMPILER_CPU_TEST"; expected "80x86".])
  57       fi
  58     elif test "x$OPENJDK_TARGET_CPU" = "xx86_64"; then
  59       if test "x$COMPILER_CPU_TEST" != "xx64"; then
  60         AC_MSG_ERROR([Target CPU mismatch. We are building for $OPENJDK_TARGET_CPU but CL is for "$COMPILER_CPU_TEST"; expected "x64".])
  61       fi
  62     fi
  63   else
  64     COMPILER_VERSION_TEST=`$COMPILER --version 2>&1 | $HEAD -n 1`
  65     # Check that this is likely to be GCC.
  66     $COMPILER --version 2>&1 | $GREP "Free Software Foundation" > /dev/null
  67     if test $? -ne 0; then
  68       AC_MSG_NOTICE([The $COMPILER_NAME compiler (located as $COMPILER) does not seem to be the required GCC compiler.])
  69       AC_MSG_NOTICE([The result from running with --version was: "$COMPILER_VERSION_TEST"])
  70       AC_MSG_ERROR([GCC compiler is required. Try setting --with-tools-dir.])
  71     fi
  72 
  73     # First line typically looks something like:
  74     # gcc (Ubuntu/Linaro 4.5.2-8ubuntu4) 4.5.2
  75     COMPILER_VERSION=`$ECHO $COMPILER_VERSION_TEST | $SED -n "s/^.* \(@<:@1-9@:>@@<:@0-9.@:>@*\)/\1/p"`
  76     COMPILER_VENDOR=`$ECHO $COMPILER_VERSION_TEST | $SED -n "s/^\(.*\) @<:@1-9@:>@@<:@0-9.@:>@*/\1/p"`
  77   fi
  78   # This sets CC_VERSION or CXX_VERSION. (This comment is a grep marker)
  79   $1_VERSION="$COMPILER_VERSION"
  80   # This sets CC_VENDOR or CXX_VENDOR. (This comment is a grep marker)
  81   $1_VENDOR="$COMPILER_VENDOR"
  82 
  83   AC_MSG_NOTICE([Using $COMPILER_VENDOR $COMPILER_NAME compiler version $COMPILER_VERSION (located at $COMPILER)])
  84 ])
  85 
  86 
  87 AC_DEFUN_ONCE([TOOLCHAIN_SETUP_SYSROOT_AND_OUT_OPTIONS],
  88 [
  89 ###############################################################################
  90 #
  91 # Configure the development tool paths and potential sysroot.
  92 #
  93 AC_LANG(C++)
  94 
  95 # The option used to specify the target .o,.a or .so file.
  96 # When compiling, how to specify the to be created object file.
  97 CC_OUT_OPTION='-o$(SPACE)'
  98 # When linking, how to specify the to be created executable.
  99 EXE_OUT_OPTION='-o$(SPACE)'
 100 # When linking, how to specify the to be created dynamically linkable library.
 101 LD_OUT_OPTION='-o$(SPACE)'
 102 # When archiving, how to specify the to be create static archive for object files.
 103 AR_OUT_OPTION='rcs$(SPACE)'
 104 AC_SUBST(CC_OUT_OPTION)
 105 AC_SUBST(EXE_OUT_OPTION)
 106 AC_SUBST(LD_OUT_OPTION)
 107 AC_SUBST(AR_OUT_OPTION)
 108 ])
 109 
 110 # $1 = compiler to test (CC or CXX)
 111 # $2 = human readable name of compiler (C or C++)
 112 # $3 = list of compiler names to search for
 113 AC_DEFUN([TOOLCHAIN_FIND_COMPILER],
 114 [
 115   COMPILER_NAME=$2
 116 
 117   $1=
 118   # If TOOLS_DIR is set, check for all compiler names in there first
 119   # before checking the rest of the PATH.
 120   if test -n "$TOOLS_DIR"; then
 121     PATH_save="$PATH"
 122     PATH="$TOOLS_DIR"
 123     AC_PATH_PROGS(TOOLS_DIR_$1, $3)
 124     $1=$TOOLS_DIR_$1
 125     PATH="$PATH_save"
 126   fi
 127 
 128   # AC_PATH_PROGS can't be run multiple times with the same variable,
 129   # so create a new name for this run.
 130   if test "x[$]$1" = x; then
 131     AC_PATH_PROGS(POTENTIAL_$1, $3)
 132     $1=$POTENTIAL_$1
 133   fi
 134 
 135   if test "x[$]$1" = x; then
 136       HELP_MSG_MISSING_DEPENDENCY([devkit])
 137       AC_MSG_ERROR([Could not find a $COMPILER_NAME compiler. $HELP_MSG])
 138   fi
 139   BASIC_FIXUP_EXECUTABLE($1)
 140   AC_MSG_CHECKING([resolved symbolic links for $1])
 141   TEST_COMPILER="[$]$1"
 142   BASIC_REMOVE_SYMBOLIC_LINKS(TEST_COMPILER)
 143   AC_MSG_RESULT([$TEST_COMPILER])
 144   AC_MSG_CHECKING([if $1 is disguised ccache])
 145 
 146   COMPILER_BASENAME=`$BASENAME "$TEST_COMPILER"`
 147   if test "x$COMPILER_BASENAME" = "xccache"; then
 148     AC_MSG_RESULT([yes, trying to find proper $COMPILER_NAME compiler])
 149     # We /usr/lib/ccache in the path, so cc is a symlink to /usr/bin/ccache.
 150     # We want to control ccache invocation ourselves, so ignore this cc and try
 151     # searching again.
 152 
 153     # Remove the path to the fake ccache cc from the PATH
 154     RETRY_COMPILER_SAVED_PATH="$PATH"
 155     COMPILER_DIRNAME=`$DIRNAME [$]$1`
 156     PATH="`$ECHO $PATH | $SED -e "s,$COMPILER_DIRNAME,,g" -e "s,::,:,g" -e "s,^:,,g"`"
 157 
 158     # Try again looking for our compiler
 159     AC_CHECK_TOOLS(PROPER_COMPILER_$1, $3)
 160     BASIC_FIXUP_EXECUTABLE(PROPER_COMPILER_$1)
 161     PATH="$RETRY_COMPILER_SAVED_PATH"
 162 
 163     AC_MSG_CHECKING([for resolved symbolic links for $1])
 164     BASIC_REMOVE_SYMBOLIC_LINKS(PROPER_COMPILER_$1)
 165     AC_MSG_RESULT([$PROPER_COMPILER_$1])
 166     $1="$PROPER_COMPILER_$1"
 167   else
 168     AC_MSG_RESULT([no, keeping $1])
 169     $1="$TEST_COMPILER"
 170   fi
 171   TOOLCHAIN_CHECK_COMPILER_VERSION([$1], [$COMPILER_NAME])
 172 ])
 173 
 174 
 175 AC_DEFUN([TOOLCHAIN_SETUP_PATHS],
 176 [
 177 if test "x$OPENJDK_TARGET_OS" = "xwindows"; then
 178   TOOLCHAIN_SETUP_VISUAL_STUDIO_ENV
 179   TOOLCHAIN_SETUP_DXSDK
 180 fi
 181 
 182 AC_SUBST(MSVCR_DLL)
 183 
 184 # If --build AND --host is set, then the configure script will find any
 185 # cross compilation tools in the PATH. Cross compilation tools
 186 # follows the cross compilation standard where they are prefixed with ${host}.
 187 # For example the binary i686-sun-solaris2.10-gcc
 188 # will cross compile for i686-sun-solaris2.10
 189 # If neither of build and host is not set, then build=host and the
 190 # default compiler found in the path will be used.
 191 # Setting only --host, does not seem to be really supported.
 192 # Please set both --build and --host if you want to cross compile.
 193 
 194 if test "x$COMPILE_TYPE" = "xcross"; then
 195     # Now we to find a C/C++ compiler that can build executables for the build
 196     # platform. We can't use the AC_PROG_CC macro, since it can only be used
 197     # once. Also, we need to do this before adding a tools dir to the path,
 198     # otherwise we might pick up cross-compilers which don't use standard naming.
 199     # Otherwise, we'll set the BUILD_tools to the native tools, but that'll have
 200     # to wait until they are properly discovered.
 201     AC_PATH_PROGS(BUILD_CC, [cl cc gcc])
 202     BASIC_FIXUP_EXECUTABLE(BUILD_CC)
 203     AC_PATH_PROGS(BUILD_CXX, [cl CC g++])
 204     BASIC_FIXUP_EXECUTABLE(BUILD_CXX)
 205     AC_PATH_PROG(BUILD_LD, ld)
 206     BASIC_FIXUP_EXECUTABLE(BUILD_LD)
 207 fi
 208 AC_SUBST(BUILD_CC)
 209 AC_SUBST(BUILD_CXX)
 210 AC_SUBST(BUILD_LD)
 211 
 212 # If a devkit is found on the builddeps server, then prepend its path to the
 213 # PATH variable. If there are cross compilers available in the devkit, these
 214 # will be found by AC_PROG_CC et al.
 215 DEVKIT=
 216 BDEPS_CHECK_MODULE(DEVKIT, devkit, xxx,
 217                     [# Found devkit
 218                      PATH="$DEVKIT/bin:$PATH"
 219                      SYS_ROOT="$DEVKIT/${rewritten_target}/sys-root"
 220                      if test "x$x_includes" = "xNONE"; then
 221                          x_includes="$SYS_ROOT/usr/include/X11"
 222                      fi
 223                      if test "x$x_libraries" = "xNONE"; then
 224                          x_libraries="$SYS_ROOT/usr/lib"
 225                      fi
 226                     ],
 227                     [])
 228 
 229 # Store the CFLAGS etal passed to the configure script.
 230 ORG_CFLAGS="$CFLAGS"
 231 ORG_CXXFLAGS="$CXXFLAGS"
 232 ORG_OBJCFLAGS="$OBJCFLAGS"
 233 
 234 # autoconf magic only relies on PATH, so update it if tools dir is specified
 235 OLD_PATH="$PATH"
 236 if test "x$TOOLS_DIR" != x; then
 237   PATH=$TOOLS_DIR:$PATH
 238 fi
 239 
 240 
 241 ### Locate C compiler (CC)
 242 
 243 # On windows, only cl.exe is supported.
 244 # On Solaris, cc is preferred to gcc.
 245 # Elsewhere, gcc is preferred to cc.
 246 
 247 if test "x$CC" != x; then
 248   COMPILER_CHECK_LIST="$CC"
 249 elif test "x$OPENJDK_TARGET_OS" = "xwindows"; then
 250   COMPILER_CHECK_LIST="cl"
 251 elif test "x$OPENJDK_TARGET_OS" = "xsolaris"; then
 252   COMPILER_CHECK_LIST="cc gcc"
 253 else
 254   COMPILER_CHECK_LIST="gcc cc"
 255 fi
 256 
 257 TOOLCHAIN_FIND_COMPILER([CC],[C],[$COMPILER_CHECK_LIST])
 258 # Now that we have resolved CC ourself, let autoconf have its go at it
 259 AC_PROG_CC([$CC])
 260 
 261 ### Locate C++ compiler (CXX)
 262 
 263 if test "x$CXX" != x; then
 264   COMPILER_CHECK_LIST="$CXX"
 265 elif test "x$OPENJDK_TARGET_OS" = "xwindows"; then
 266   COMPILER_CHECK_LIST="cl"
 267 elif test "x$OPENJDK_TARGET_OS" = "xsolaris"; then
 268   COMPILER_CHECK_LIST="CC g++"
 269 else
 270   COMPILER_CHECK_LIST="g++ CC"
 271 fi
 272 
 273 TOOLCHAIN_FIND_COMPILER([CXX],[C++],[$COMPILER_CHECK_LIST])
 274 # Now that we have resolved CXX ourself, let autoconf have its go at it
 275 AC_PROG_CXX([$CXX])
 276 
 277 ### Locate other tools
 278 
 279 if test "x$OPENJDK_TARGET_OS" = xmacosx; then
 280     AC_PROG_OBJC
 281     BASIC_FIXUP_EXECUTABLE(OBJC)
 282 else
 283     OBJC=
 284 fi
 285 
 286 # Restore the flags to the user specified values.
 287 # This is necessary since AC_PROG_CC defaults CFLAGS to "-g -O2"
 288 CFLAGS="$ORG_CFLAGS"
 289 CXXFLAGS="$ORG_CXXFLAGS"
 290 OBJCFLAGS="$ORG_OBJCFLAGS"
 291 
 292 LD="$CC"
 293 LDEXE="$CC"
 294 LDCXX="$CXX"
 295 LDEXECXX="$CXX"
 296 AC_SUBST(LD)
 297 # LDEXE is the linker to use, when creating executables.
 298 AC_SUBST(LDEXE)
 299 # Linking C++ libraries.
 300 AC_SUBST(LDCXX)
 301 # Linking C++ executables.
 302 AC_SUBST(LDEXECXX)
 303 
 304 if test "x$OPENJDK_TARGET_OS" != xwindows; then
 305     AC_CHECK_TOOL(AR, ar)
 306     BASIC_FIXUP_EXECUTABLE(AR)
 307 fi
 308 if test "x$OPENJDK_TARGET_OS" = xmacosx; then
 309     ARFLAGS="-r"
 310 else
 311     ARFLAGS=""
 312 fi
 313 AC_SUBST(ARFLAGS)
 314 
 315 # For hotspot, we need these in Windows mixed path; other platforms keep them the same
 316 HOTSPOT_CXX="$CXX"
 317 HOTSPOT_LD="$LD"
 318 AC_SUBST(HOTSPOT_CXX)
 319 AC_SUBST(HOTSPOT_LD)
 320 
 321 COMPILER_NAME=gcc
 322 COMPILER_TYPE=CC
 323 AS_IF([test "x$OPENJDK_TARGET_OS" = xwindows], [
 324     # For now, assume that we are always compiling using cl.exe.
 325     CC_OUT_OPTION=-Fo
 326     EXE_OUT_OPTION=-out:
 327     LD_OUT_OPTION=-out:
 328     AR_OUT_OPTION=-out:
 329     # On Windows, reject /usr/bin/link (as determined in CYGWIN_LINK), which is a cygwin
 330     # program for something completely different.
 331     AC_CHECK_PROG([WINLD], [link],[link],,, [$CYGWIN_LINK])
 332     # Since we must ignore the first found link, WINLD will contain
 333     # the full path to the link.exe program.
 334     BASIC_FIXUP_EXECUTABLE(WINLD)
 335     printf "Windows linker was found at $WINLD\n"
 336     AC_MSG_CHECKING([if the found link.exe is actually the Visual Studio linker])
 337     "$WINLD" --version > /dev/null
 338     if test $? -eq 0 ; then
 339       AC_MSG_RESULT([no])
 340       AC_MSG_ERROR([This is the Cygwin link tool. Please check your PATH and rerun configure.])
 341     else
 342       AC_MSG_RESULT([yes])
 343     fi
 344     LD="$WINLD"
 345     LDEXE="$WINLD"
 346     LDCXX="$WINLD"
 347     LDEXECXX="$WINLD"
 348 
 349     AC_CHECK_PROG([MT], [mt], [mt],,, [/usr/bin/mt])
 350     BASIC_FIXUP_EXECUTABLE(MT)
 351     # The resource compiler
 352     AC_CHECK_PROG([RC], [rc], [rc],,, [/usr/bin/rc])
 353     BASIC_FIXUP_EXECUTABLE(RC)
 354 
 355     # For hotspot, we need these in Windows mixed path,
 356     # so rewrite them all. Need added .exe suffix.
 357     HOTSPOT_CXX="$CXX.exe"
 358     HOTSPOT_LD="$LD.exe"
 359     HOTSPOT_MT="$MT.exe"
 360     HOTSPOT_RC="$RC.exe"
 361     BASIC_WINDOWS_REWRITE_AS_WINDOWS_MIXED_PATH(HOTSPOT_CXX)
 362     BASIC_WINDOWS_REWRITE_AS_WINDOWS_MIXED_PATH(HOTSPOT_LD)
 363     BASIC_WINDOWS_REWRITE_AS_WINDOWS_MIXED_PATH(HOTSPOT_MT)
 364     BASIC_WINDOWS_REWRITE_AS_WINDOWS_MIXED_PATH(HOTSPOT_RC)
 365     AC_SUBST(HOTSPOT_MT)
 366     AC_SUBST(HOTSPOT_RC)
 367 
 368     RC_FLAGS="-nologo -l 0x409 -r"
 369     AS_IF([test "x$VARIANT" = xOPT], [
 370         RC_FLAGS="$RC_FLAGS -d NDEBUG"
 371     ])
 372 
 373     # The version variables used to create RC_FLAGS may be overridden
 374     # in a custom configure script, or possibly the command line.  
 375     # Let those variables be expanded at make time in spec.gmk.
 376     # The \$ are escaped to the shell, and the $(...) variables
 377     # are evaluated by make.
 378     RC_FLAGS="$RC_FLAGS \
 379         -d \"JDK_BUILD_ID=\$(FULL_VERSION)\" \
 380         -d \"JDK_COMPANY=\$(COMPANY_NAME)\" \
 381         -d \"JDK_COMPONENT=\$(PRODUCT_NAME) \$(JDK_RC_PLATFORM_NAME) binary\" \
 382         -d \"JDK_VER=\$(JDK_MINOR_VERSION).\$(JDK_MICRO_VERSION).\$(if \$(JDK_UPDATE_VERSION),\$(JDK_UPDATE_VERSION),0).\$(COOKED_BUILD_NUMBER)\" \
 383         -d \"JDK_COPYRIGHT=Copyright \xA9 $COPYRIGHT_YEAR\" \
 384         -d \"JDK_NAME=\$(PRODUCT_NAME) \$(JDK_RC_PLATFORM_NAME) \$(JDK_MINOR_VERSION) \$(JDK_UPDATE_META_TAG)\" \
 385         -d \"JDK_FVER=\$(JDK_MINOR_VERSION),\$(JDK_MICRO_VERSION),\$(if \$(JDK_UPDATE_VERSION),\$(JDK_UPDATE_VERSION),0),\$(COOKED_BUILD_NUMBER)\""
 386 
 387     # lib.exe is used to create static libraries.
 388     AC_CHECK_PROG([WINAR], [lib],[lib],,,)
 389     BASIC_FIXUP_EXECUTABLE(WINAR)
 390     AR="$WINAR"
 391     ARFLAGS="-nologo -NODEFAULTLIB:MSVCRT"
 392 
 393     AC_CHECK_PROG([DUMPBIN], [dumpbin], [dumpbin],,,)
 394     BASIC_FIXUP_EXECUTABLE(DUMPBIN)
 395 
 396     COMPILER_TYPE=CL
 397     CCXXFLAGS="$CCXXFLAGS -nologo"
 398 ])
 399 AC_SUBST(RC_FLAGS)
 400 AC_SUBST(COMPILER_TYPE)
 401 
 402 AC_PROG_CPP
 403 BASIC_FIXUP_EXECUTABLE(CPP)
 404 
 405 AC_PROG_CXXCPP
 406 BASIC_FIXUP_EXECUTABLE(CXXCPP)
 407 
 408 if test "x$COMPILE_TYPE" != "xcross"; then
 409     # If we are not cross compiling, use the same compilers for
 410     # building the build platform executables. The cross-compilation
 411     # case needed to be done earlier, but this can only be done after
 412     # the native tools have been localized.
 413     BUILD_CC="$CC"
 414     BUILD_CXX="$CXX"
 415     BUILD_LD="$LD"
 416 fi
 417 
 418 # for solaris we really need solaris tools, and not gnu equivalent
 419 #   these seems to normally reside in /usr/ccs/bin so add that to path before
 420 #   starting to probe
 421 #
 422 #   NOTE: I add this /usr/ccs/bin after TOOLS but before OLD_PATH
 423 #         so that it can be overriden --with-tools-dir
 424 if test "x$OPENJDK_BUILD_OS" = xsolaris; then
 425     PATH="${TOOLS_DIR}:/usr/ccs/bin:${OLD_PATH}"
 426 fi
 427 
 428 # Find the right assembler.
 429 if test "x$OPENJDK_TARGET_OS" = xsolaris; then
 430     AC_PATH_PROG(AS, as)
 431     BASIC_FIXUP_EXECUTABLE(AS)
 432 else
 433   # Enforce preprocessing of assembler files for GCC
 434   if test "x$ac_compiler_gnu" = "xyes"; then
 435      AS="$CC -c -x assembler-with-cpp "
 436   else
 437      AS="$CC -c"
 438   fi
 439 fi
 440 AC_MSG_NOTICE([Using $AS as assembler])
 441 AC_SUBST(AS)
 442 
 443 if test "x$OPENJDK_TARGET_OS" = xsolaris; then
 444     AC_PATH_PROG(NM, nm)
 445     BASIC_FIXUP_EXECUTABLE(NM)
 446     AC_PATH_PROG(GNM, gnm)
 447     BASIC_FIXUP_EXECUTABLE(GNM)
 448     AC_PATH_PROG(STRIP, strip)
 449     BASIC_FIXUP_EXECUTABLE(STRIP)
 450     AC_PATH_PROG(MCS, mcs)
 451     BASIC_FIXUP_EXECUTABLE(MCS)
 452 elif test "x$OPENJDK_TARGET_OS" != xwindows; then
 453     AC_CHECK_TOOL(NM, nm)
 454     BASIC_FIXUP_EXECUTABLE(NM)
 455     GNM="$NM"
 456     AC_SUBST(GNM)
 457     AC_CHECK_TOOL(STRIP, strip)
 458     BASIC_FIXUP_EXECUTABLE(STRIP)
 459 fi
 460 
 461 # objcopy is used for moving debug symbols to separate files when
 462 # full debug symbols are enabled.
 463 if test "x$OPENJDK_TARGET_OS" = xsolaris || test "x$OPENJDK_TARGET_OS" = xlinux; then
 464     AC_CHECK_TOOLS(OBJCOPY, [gobjcopy objcopy])
 465     # Only call fixup if objcopy was found.
 466     if test -n "$OBJCOPY"; then
 467         BASIC_FIXUP_EXECUTABLE(OBJCOPY)
 468     fi
 469 fi
 470 
 471 AC_CHECK_TOOLS(OBJDUMP, [gobjdump objdump])
 472 if test "x$OBJDUMP" != x; then
 473   # Only used for compare.sh; we can live without it. BASIC_FIXUP_EXECUTABLE bails if argument is missing.
 474   BASIC_FIXUP_EXECUTABLE(OBJDUMP)
 475 fi
 476 
 477 if test "x$OPENJDK_TARGET_OS" = "xmacosx"; then
 478    AC_PATH_PROG(LIPO, lipo)
 479    BASIC_FIXUP_EXECUTABLE(LIPO)
 480 fi
 481 
 482 TOOLCHAIN_SETUP_JTREG
 483 
 484 # Restore old path without tools dir
 485 PATH="$OLD_PATH"
 486 ])
 487 
 488 
 489 AC_DEFUN_ONCE([TOOLCHAIN_SETUP_COMPILER_FLAGS_FOR_LIBS],
 490 [
 491 
 492 ###############################################################################
 493 #
 494 # How to compile shared libraries.
 495 #
 496 
 497 if test "x$GCC" = xyes; then
 498     COMPILER_NAME=gcc
 499     PICFLAG="-fPIC"
 500     LIBRARY_PREFIX=lib
 501     SHARED_LIBRARY='lib[$]1.so'
 502     STATIC_LIBRARY='lib[$]1.a'
 503     SHARED_LIBRARY_FLAGS="-shared"
 504     SHARED_LIBRARY_SUFFIX='.so'
 505     STATIC_LIBRARY_SUFFIX='.a'
 506     OBJ_SUFFIX='.o'
 507     EXE_SUFFIX=''
 508     SET_SHARED_LIBRARY_NAME='-Xlinker -soname=[$]1'
 509     SET_SHARED_LIBRARY_MAPFILE='-Xlinker -version-script=[$]1'
 510     C_FLAG_REORDER=''
 511     CXX_FLAG_REORDER=''
 512     SET_SHARED_LIBRARY_ORIGIN='-Xlinker -z -Xlinker origin -Xlinker -rpath -Xlinker \$$$$ORIGIN[$]1'
 513     SET_EXECUTABLE_ORIGIN='-Xlinker -rpath -Xlinker \$$$$ORIGIN[$]1'
 514     LD="$CC"
 515     LDEXE="$CC"
 516     LDCXX="$CXX"
 517     LDEXECXX="$CXX"
 518     POST_STRIP_CMD="$STRIP -g"
 519 
 520     # Linking is different on MacOSX
 521     if test "x$OPENJDK_TARGET_OS" = xmacosx; then
 522         # Might change in the future to clang.
 523         COMPILER_NAME=gcc
 524         SHARED_LIBRARY='lib[$]1.dylib'
 525         SHARED_LIBRARY_FLAGS="-dynamiclib -compatibility_version 1.0.0 -current_version 1.0.0 $PICFLAG"
 526         SHARED_LIBRARY_SUFFIX='.dylib'
 527         EXE_SUFFIX=''
 528         SET_SHARED_LIBRARY_NAME='-Xlinker -install_name -Xlinker @rpath/[$]1'
 529         SET_SHARED_LIBRARY_MAPFILE=''
 530         SET_SHARED_LIBRARY_ORIGIN='-Xlinker -rpath -Xlinker @loader_path/.'
 531         SET_EXECUTABLE_ORIGIN="$SET_SHARED_LIBRARY_ORIGIN"
 532         POST_STRIP_CMD="$STRIP -S"
 533     fi
 534 else
 535     if test "x$OPENJDK_TARGET_OS" = xsolaris; then
 536         # If it is not gcc, then assume it is the Oracle Solaris Studio Compiler
 537         COMPILER_NAME=ossc
 538         PICFLAG="-KPIC"
 539         LIBRARY_PREFIX=lib
 540         SHARED_LIBRARY='lib[$]1.so'
 541         STATIC_LIBRARY='lib[$]1.a'
 542         SHARED_LIBRARY_FLAGS="-G"
 543         SHARED_LIBRARY_SUFFIX='.so'
 544         STATIC_LIBRARY_SUFFIX='.a'
 545         OBJ_SUFFIX='.o'
 546         EXE_SUFFIX=''
 547         SET_SHARED_LIBRARY_NAME=''
 548         SET_SHARED_LIBRARY_MAPFILE='-M[$]1'
 549         C_FLAG_REORDER='-xF'
 550         CXX_FLAG_REORDER='-xF'
 551         SET_SHARED_LIBRARY_ORIGIN='-R\$$$$ORIGIN[$]1'
 552         SET_EXECUTABLE_ORIGIN="$SET_SHARED_LIBRARY_ORIGIN"
 553         CFLAGS_JDK="${CFLAGS_JDK} -D__solaris__"
 554         CXXFLAGS_JDK="${CXXFLAGS_JDK} -D__solaris__"
 555         CFLAGS_JDKLIB_EXTRA='-xstrconst'
 556         POST_STRIP_CMD="$STRIP -x"
 557         POST_MCS_CMD="$MCS -d -a \"JDK $FULL_VERSION\""
 558     fi
 559     if test "x$OPENJDK_TARGET_OS" = xwindows; then
 560         # If it is not gcc, then assume it is the MS Visual Studio compiler
 561         COMPILER_NAME=cl
 562         PICFLAG=""
 563         LIBRARY_PREFIX=
 564         SHARED_LIBRARY='[$]1.dll'
 565         STATIC_LIBRARY='[$]1.lib'
 566         SHARED_LIBRARY_FLAGS="-LD"
 567         SHARED_LIBRARY_SUFFIX='.dll'
 568         STATIC_LIBRARY_SUFFIX='.lib'
 569         OBJ_SUFFIX='.obj'
 570         EXE_SUFFIX='.exe'
 571         SET_SHARED_LIBRARY_NAME=''
 572         SET_SHARED_LIBRARY_MAPFILE=''
 573         SET_SHARED_LIBRARY_ORIGIN=''
 574         SET_EXECUTABLE_ORIGIN=''
 575     fi
 576 fi
 577 
 578 AC_SUBST(COMPILER_NAME)
 579 AC_SUBST(OBJ_SUFFIX)
 580 AC_SUBST(SHARED_LIBRARY)
 581 AC_SUBST(STATIC_LIBRARY)
 582 AC_SUBST(LIBRARY_PREFIX)
 583 AC_SUBST(SHARED_LIBRARY_SUFFIX)
 584 AC_SUBST(STATIC_LIBRARY_SUFFIX)
 585 AC_SUBST(EXE_SUFFIX)
 586 AC_SUBST(SHARED_LIBRARY_FLAGS)
 587 AC_SUBST(SET_SHARED_LIBRARY_NAME)
 588 AC_SUBST(SET_SHARED_LIBRARY_MAPFILE)
 589 AC_SUBST(C_FLAG_REORDER)
 590 AC_SUBST(CXX_FLAG_REORDER)
 591 AC_SUBST(SET_SHARED_LIBRARY_ORIGIN)
 592 AC_SUBST(SET_EXECUTABLE_ORIGIN)
 593 AC_SUBST(POST_STRIP_CMD)
 594 AC_SUBST(POST_MCS_CMD)
 595 
 596 # The (cross) compiler is now configured, we can now test capabilities
 597 # of the target platform.
 598 ])
 599 
 600 AC_DEFUN_ONCE([TOOLCHAIN_SETUP_COMPILER_FLAGS_FOR_OPTIMIZATION],
 601 [
 602 
 603 ###############################################################################
 604 #
 605 # Setup the opt flags for different compilers
 606 # and different operating systems.
 607 #
 608 
 609 #
 610 # NOTE: check for -mstackrealign needs to be below potential addition of -m32
 611 #
 612 if test "x$OPENJDK_TARGET_CPU_BITS" = x32 && test "x$OPENJDK_TARGET_OS" = xmacosx; then
 613     # On 32-bit MacOSX the OS requires C-entry points to be 16 byte aligned.
 614     # While waiting for a better solution, the current workaround is to use -mstackrealign.
 615     CFLAGS="$CFLAGS -mstackrealign"
 616     AC_MSG_CHECKING([if 32-bit compiler supports -mstackrealign])
 617     AC_LINK_IFELSE([AC_LANG_SOURCE([[int main() { return 0; }]])],
 618                    [
 619                         AC_MSG_RESULT([yes])
 620                    ],
 621                    [
 622                         AC_MSG_RESULT([no])
 623                         AC_MSG_ERROR([The selected compiler $CXX does not support -mstackrealign! Try to put another compiler in the path.])
 624                    ])
 625 fi
 626 
 627 C_FLAG_DEPS="-MMD -MF"
 628 CXX_FLAG_DEPS="-MMD -MF"
 629 
 630 case $COMPILER_TYPE in
 631   CC )
 632     case $COMPILER_NAME in
 633       gcc )
 634         case $OPENJDK_TARGET_OS in
 635           macosx )
 636             # On MacOSX we optimize for size, something
 637             # we should do for all platforms?
 638             C_O_FLAG_HI="-Os"
 639             C_O_FLAG_NORM="-Os"
 640             C_O_FLAG_NONE=""
 641             ;;
 642           *)
 643             C_O_FLAG_HI="-O3"
 644             C_O_FLAG_NORM="-O2"
 645             C_O_FLAG_NONE="-O0"
 646             ;;
 647         esac
 648         CXX_O_FLAG_HI="$C_O_FLAG_HI"
 649         CXX_O_FLAG_NORM="$C_O_FLAG_NORM"
 650         CXX_O_FLAG_NONE="$C_O_FLAG_NONE"
 651         CFLAGS_DEBUG_SYMBOLS="-g"
 652         CXXFLAGS_DEBUG_SYMBOLS="-g"
 653         if test "x$OPENJDK_TARGET_CPU_BITS" = "x64" && test "x$DEBUG_LEVEL" = "xfastdebug"; then
 654             CFLAGS_DEBUG_SYMBOLS="-g1"
 655             CXXFLAGS_DEBUG_SYMBOLS="-g1"
 656         fi
 657         ;;
 658       ossc )
 659         #
 660         # Forte has different names for this with their C++ compiler...
 661         #
 662         C_FLAG_DEPS="-xMMD -xMF"
 663         CXX_FLAG_DEPS="-xMMD -xMF"
 664 
 665         # Extra options used with HIGHEST
 666         #
 667         # WARNING: Use of OPTIMIZATION_LEVEL=HIGHEST in your Makefile needs to be
 668         #          done with care, there are some assumptions below that need to
 669         #          be understood about the use of pointers, and IEEE behavior.
 670         #
 671         # Use non-standard floating point mode (not IEEE 754)
 672         CC_HIGHEST="$CC_HIGHEST -fns"
 673         # Do some simplification of floating point arithmetic (not IEEE 754)
 674         CC_HIGHEST="$CC_HIGHEST -fsimple"
 675         # Use single precision floating point with 'float'
 676         CC_HIGHEST="$CC_HIGHEST -fsingle"
 677         # Assume memory references via basic pointer types do not alias
 678         #   (Source with excessing pointer casting and data access with mixed
 679         #    pointer types are not recommended)
 680         CC_HIGHEST="$CC_HIGHEST -xalias_level=basic"
 681         # Use intrinsic or inline versions for math/std functions
 682         #   (If you expect perfect errno behavior, do not use this)
 683         CC_HIGHEST="$CC_HIGHEST -xbuiltin=%all"
 684         # Loop data dependency optimizations (need -xO3 or higher)
 685         CC_HIGHEST="$CC_HIGHEST -xdepend"
 686         # Pointer parameters to functions do not overlap
 687         #   (Similar to -xalias_level=basic usage, but less obvious sometimes.
 688         #    If you pass in multiple pointers to the same data, do not use this)
 689         CC_HIGHEST="$CC_HIGHEST -xrestrict"
 690         # Inline some library routines
 691         #   (If you expect perfect errno behavior, do not use this)
 692         CC_HIGHEST="$CC_HIGHEST -xlibmil"
 693         # Use optimized math routines
 694         #   (If you expect perfect errno behavior, do not use this)
 695         #  Can cause undefined external on Solaris 8 X86 on __sincos, removing for now
 696         #CC_HIGHEST="$CC_HIGHEST -xlibmopt"
 697 
 698         if test "x$OPENJDK_TARGET_CPU" = xsparc; then
 699           CFLAGS_JDK="${CFLAGS_JDK} -xmemalign=4s"
 700           CXXFLAGS_JDK="${CXXFLAGS_JDK} -xmemalign=4s"
 701         fi
 702 
 703         case $OPENJDK_TARGET_CPU_ARCH in
 704           x86)
 705             C_O_FLAG_HIGHEST="-xO4 -Wu,-O4~yz $CC_HIGHEST -xregs=no%frameptr"
 706             C_O_FLAG_HI="-xO4 -Wu,-O4~yz -xregs=no%frameptr"
 707             C_O_FLAG_NORM="-xO2 -Wu,-O2~yz -xregs=no%frameptr"
 708             C_O_FLAG_NONE="-xregs=no%frameptr"
 709             CXX_O_FLAG_HIGHEST="-xO4 -Qoption ube -O4~yz $CC_HIGHEST -xregs=no%frameptr"
 710             CXX_O_FLAG_HI="-xO4 -Qoption ube -O4~yz -xregs=no%frameptr"
 711             CXX_O_FLAG_NORM="-xO2 -Qoption ube -O2~yz -xregs=no%frameptr"
 712             CXX_O_FLAG_NONE="-xregs=no%frameptr"
 713             if test "x$OPENJDK_TARGET_CPU" = xx86; then
 714                C_O_FLAG_HIGHEST="$C_O_FLAG_HIGHEST -xchip=pentium"
 715                CXX_O_FLAG_HIGHEST="$CXX_O_FLAG_HIGHEST -xchip=pentium"
 716             fi
 717             ;;
 718           sparc)
 719             CFLAGS_JDKLIB_EXTRA="${CFLAGS_JDKLIB_EXTRA} -xregs=no%appl"
 720             CXXFLAGS_JDKLIB_EXTRA="${CXXFLAGS_JDKLIB_EXTRA} -xregs=no%appl"
 721             C_O_FLAG_HIGHEST="-xO4 -Wc,-Qrm-s -Wc,-Qiselect-T0 $CC_HIGHEST -xprefetch=auto,explicit -xchip=ultra"
 722             C_O_FLAG_HI="-xO4 -Wc,-Qrm-s -Wc,-Qiselect-T0"
 723             C_O_FLAG_NORM="-xO2 -Wc,-Qrm-s -Wc,-Qiselect-T0"
 724             C_O_FLAG_NONE=""
 725             CXX_O_FLAG_HIGHEST="-xO4 -Qoption cg -Qrm-s -Qoption cg -Qiselect-T0 $CC_HIGHEST -xprefetch=auto,explicit -xchip=ultra"
 726             CXX_O_FLAG_HI="-xO4 -Qoption cg -Qrm-s -Qoption cg -Qiselect-T0"
 727             CXX_O_FLAG_NORM="-xO2 -Qoption cg -Qrm-s -Qoption cg -Qiselect-T0"
 728             CXX_O_FLAG_NONE=""
 729             ;;
 730         esac
 731 
 732     CFLAGS_DEBUG_SYMBOLS="-g -xs"
 733     CXXFLAGS_DEBUG_SYMBOLS="-g0 -xs"
 734     esac
 735     ;;
 736   CL )
 737     C_O_FLAG_HIGHEST="-O2"
 738     C_O_FLAG_HI="-O1"
 739     C_O_FLAG_NORM="-O1"
 740     C_O_FLAG_NONE="-Od"
 741     CXX_O_FLAG_HIGHEST="$C_O_FLAG_HIGHEST"
 742     CXX_O_FLAG_HI="$C_O_FLAG_HI"
 743     CXX_O_FLAG_NORM="$C_O_FLAG_NORM"
 744     CXX_O_FLAG_NONE="$C_O_FLAG_NONE"
 745     ;;
 746 esac
 747 
 748 if test -z "$C_O_FLAG_HIGHEST"; then
 749    C_O_FLAG_HIGHEST="$C_O_FLAG_HI"
 750 fi
 751 
 752 if test -z "$CXX_O_FLAG_HIGHEST"; then
 753    CXX_O_FLAG_HIGHEST="$CXX_O_FLAG_HI"
 754 fi
 755 
 756 AC_SUBST(C_O_FLAG_HIGHEST)
 757 AC_SUBST(C_O_FLAG_HI)
 758 AC_SUBST(C_O_FLAG_NORM)
 759 AC_SUBST(C_O_FLAG_NONE)
 760 AC_SUBST(CXX_O_FLAG_HIGHEST)
 761 AC_SUBST(CXX_O_FLAG_HI)
 762 AC_SUBST(CXX_O_FLAG_NORM)
 763 AC_SUBST(CXX_O_FLAG_NONE)
 764 AC_SUBST(C_FLAG_DEPS)
 765 AC_SUBST(CXX_FLAG_DEPS)
 766 ])
 767 
 768 AC_DEFUN_ONCE([TOOLCHAIN_SETUP_COMPILER_FLAGS_FOR_JDK],
 769 [
 770 
 771 if test "x$CFLAGS" != "x${ADDED_CFLAGS}"; then
 772    AC_MSG_WARN([Ignoring CFLAGS($CFLAGS) found in environment. Use --with-extra-cflags])
 773 fi
 774 
 775 if test "x$CXXFLAGS" != "x${ADDED_CXXFLAGS}"; then
 776    AC_MSG_WARN([Ignoring CXXFLAGS($CXXFLAGS) found in environment. Use --with-extra-cxxflags])
 777 fi
 778 
 779 if test "x$LDFLAGS" != "x${ADDED_LDFLAGS}"; then
 780    AC_MSG_WARN([Ignoring LDFLAGS($LDFLAGS) found in environment. Use --with-extra-ldflags])
 781 fi
 782 
 783 AC_ARG_WITH(extra-cflags, [AS_HELP_STRING([--with-extra-cflags],
 784     [extra flags to be used when compiling jdk c-files])])
 785 
 786 AC_ARG_WITH(extra-cxxflags, [AS_HELP_STRING([--with-extra-cxxflags],
 787     [extra flags to be used when compiling jdk c++-files])])
 788 
 789 AC_ARG_WITH(extra-ldflags, [AS_HELP_STRING([--with-extra-ldflags],
 790     [extra flags to be used when linking jdk])])
 791 
 792 CFLAGS_JDK="${CFLAGS_JDK} $with_extra_cflags"
 793 CXXFLAGS_JDK="${CXXFLAGS_JDK} $with_extra_cxxflags"
 794 LDFLAGS_JDK="${LDFLAGS_JDK} $with_extra_ldflags"
 795 
 796 # Hotspot needs these set in their legacy form
 797 LEGACY_EXTRA_CFLAGS=$with_extra_cflags
 798 LEGACY_EXTRA_CXXFLAGS=$with_extra_cxxflags
 799 LEGACY_EXTRA_LDFLAGS=$with_extra_ldflags
 800 
 801 AC_SUBST(LEGACY_EXTRA_CFLAGS)
 802 AC_SUBST(LEGACY_EXTRA_CXXFLAGS)
 803 AC_SUBST(LEGACY_EXTRA_LDFLAGS)
 804 
 805 ###############################################################################
 806 #
 807 # Now setup the CFLAGS and LDFLAGS for the JDK build.
 808 # Later we will also have CFLAGS and LDFLAGS for the hotspot subrepo build.
 809 #
 810 case $COMPILER_NAME in
 811       gcc )
 812           CCXXFLAGS_JDK="$CCXXFLAGS $CCXXFLAGS_JDK -W -Wall -Wno-unused -Wno-parentheses \
 813                           -pipe \
 814                           -D_GNU_SOURCE -D_REENTRANT -D_LARGEFILE64_SOURCE"
 815           case $OPENJDK_TARGET_CPU_ARCH in
 816           arm )
 817             # on arm we don't prevent gcc to omit frame pointer but do prevent strict aliasing
 818             CFLAGS_JDK="${CFLAGS_JDK} -fno-strict-aliasing"
 819           ;;
 820           ppc )
 821             # on ppc we don't prevent gcc to omit frame pointer nor strict-aliasing
 822           ;;
 823           * )
 824             CCXXFLAGS_JDK="$CCXXFLAGS_JDK -fno-omit-frame-pointer"
 825             CFLAGS_JDK="${CFLAGS_JDK} -fno-strict-aliasing"
 826           ;;
 827           esac
 828           ;;
 829       ossc )
 830           CCXXFLAGS_JDK="$CCXXFLAGS $CCXXFLAGS_JDK -DTRACING -DMACRO_MEMSYS_OPS -DBREAKPTS"
 831           case $OPENJDK_TARGET_CPU_ARCH in
 832           x86 )
 833             CCXXFLAGS_JDK="$CCXXFLAGS_JDK -DcpuIntel -Di586 -D$OPENJDK_TARGET_CPU_LEGACY_LIB"
 834             CFLAGS_JDK="$CFLAGS_JDK -erroff=E_BAD_PRAGMA_PACK_VALUE"
 835           ;;
 836           esac
 837 
 838           CFLAGS_JDK="$CFLAGS_JDK -xc99=%none -xCC -errshort=tags -Xa -v -mt -W0,-noglobal"
 839           CXXFLAGS_JDK="$CXXFLAGS_JDK -errtags=yes +w -mt -features=no%except -DCC_NOEX -norunpath -xnolib"
 840 
 841           LDFLAGS_JDK="$LDFLAGS_JDK -z defs -xildoff -ztext"
 842           LDFLAGS_CXX_JDK="$LDFLAGS_CXX_JDK -norunpath -xnolib"
 843           ;;
 844       cl )
 845           CCXXFLAGS_JDK="$CCXXFLAGS $CCXXFLAGS_JDK -Zi -MD -Zc:wchar_t- -W3 -wd4800 \
 846                -D_STATIC_CPPLIB -D_DISABLE_DEPRECATE_STATIC_CPPLIB -DWIN32_LEAN_AND_MEAN \
 847                -D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE \
 848                -DWIN32 -DIAL"
 849           case $OPENJDK_TARGET_CPU in
 850               x86 )
 851                   CCXXFLAGS_JDK="$CCXXFLAGS_JDK -D_X86_ -Dx86"
 852                   ;;
 853               x86_64 )
 854                   CCXXFLAGS_JDK="$CCXXFLAGS_JDK -D_AMD64_ -Damd64"
 855                   ;;
 856           esac
 857           ;;
 858 esac
 859 
 860 ###############################################################################
 861 
 862 # Adjust flags according to debug level.
 863 case $DEBUG_LEVEL in
 864       fastdebug )
 865               CFLAGS_JDK="$CFLAGS_JDK $CFLAGS_DEBUG_SYMBOLS"
 866               CXXFLAGS_JDK="$CXXFLAGS_JDK $CXXFLAGS_DEBUG_SYMBOLS"
 867               C_O_FLAG_HI="$C_O_FLAG_NORM"
 868               C_O_FLAG_NORM="$C_O_FLAG_NORM"
 869               CXX_O_FLAG_HI="$CXX_O_FLAG_NORM"
 870               CXX_O_FLAG_NORM="$CXX_O_FLAG_NORM"
 871               JAVAC_FLAGS="$JAVAC_FLAGS -g"
 872               ;;
 873       slowdebug )
 874               CFLAGS_JDK="$CFLAGS_JDK $CFLAGS_DEBUG_SYMBOLS"
 875               CXXFLAGS_JDK="$CXXFLAGS_JDK $CXXFLAGS_DEBUG_SYMBOLS"
 876               C_O_FLAG_HI="$C_O_FLAG_NONE"
 877               C_O_FLAG_NORM="$C_O_FLAG_NONE"
 878               CXX_O_FLAG_HI="$CXX_O_FLAG_NONE"
 879               CXX_O_FLAG_NORM="$CXX_O_FLAG_NONE"
 880               JAVAC_FLAGS="$JAVAC_FLAGS -g"
 881               ;;
 882 esac
 883 
 884 CCXXFLAGS_JDK="$CCXXFLAGS_JDK $ADD_LP64"
 885 
 886 # The package path is used only on macosx?
 887 PACKAGE_PATH=/opt/local
 888 AC_SUBST(PACKAGE_PATH)
 889 
 890 if test "x$OPENJDK_TARGET_CPU_ENDIAN" = xlittle; then
 891     # The macro _LITTLE_ENDIAN needs to be defined the same to avoid the
 892     #   Sun C compiler warning message: warning: macro redefined: _LITTLE_ENDIAN
 893     #   (The Solaris X86 system defines this in file /usr/include/sys/isa_defs.h).
 894     #   Note: -Dmacro         is the same as    #define macro 1
 895     #         -Dmacro=      is the same as    #define macro
 896     if test "x$OPENJDK_TARGET_OS" = xsolaris; then
 897         CCXXFLAGS_JDK="$CCXXFLAGS_JDK -D_LITTLE_ENDIAN="
 898     else
 899         CCXXFLAGS_JDK="$CCXXFLAGS_JDK -D_LITTLE_ENDIAN"
 900     fi
 901 else
 902     CCXXFLAGS_JDK="$CCXXFLAGS_JDK -D_BIG_ENDIAN"
 903 fi
 904 if test "x$OPENJDK_TARGET_OS" = xlinux; then
 905     CCXXFLAGS_JDK="$CCXXFLAGS_JDK -DLINUX"
 906 fi
 907 if test "x$OPENJDK_TARGET_OS" = xwindows; then
 908     CCXXFLAGS_JDK="$CCXXFLAGS_JDK -DWINDOWS"
 909 fi
 910 if test "x$OPENJDK_TARGET_OS" = xsolaris; then
 911     CCXXFLAGS_JDK="$CCXXFLAGS_JDK -DSOLARIS"
 912 fi
 913 if test "x$OPENJDK_TARGET_OS" = xmacosx; then
 914     CCXXFLAGS_JDK="$CCXXFLAGS_JDK -DMACOSX -D_ALLBSD_SOURCE"
 915     # Setting these parameters makes it an error to link to macosx APIs that are
 916     # newer than the given OS version and makes the linked binaries compatible even
 917     # if built on a newer version of the OS.
 918     # The expected format is X.Y.Z
 919     MACOSX_VERSION_MIN=10.7.0
 920     AC_SUBST(MACOSX_VERSION_MIN)
 921     # The macro takes the version with no dots, ex: 1070
 922     # Let the flags variables get resolved in make for easier override on make
 923     # command line.
 924     CCXXFLAGS_JDK="$CCXXFLAGS_JDK -DMAC_OS_X_VERSION_MAX_ALLOWED=\$(subst .,,\$(MACOSX_VERSION_MIN)) -mmacosx-version-min=\$(MACOSX_VERSION_MIN)"
 925     LDFLAGS_JDK="$LDFLAGS_JDK -mmacosx-version-min=\$(MACOSX_VERSION_MIN)"
 926 fi
 927 if test "x$OPENJDK_TARGET_OS" = xbsd; then
 928     CCXXFLAGS_JDK="$CCXXFLAGS_JDK -DBSD -D_ALLBSD_SOURCE"
 929 fi
 930 if test "x$DEBUG_LEVEL" = xrelease; then
 931     CCXXFLAGS_JDK="$CCXXFLAGS_JDK -DNDEBUG"
 932     if test "x$OPENJDK_TARGET_OS" = xsolaris; then
 933         CCXXFLAGS_JDK="$CCXXFLAGS_JDK -DTRIMMED"
 934     fi
 935 else
 936     CCXXFLAGS_JDK="$CCXXFLAGS_JDK -DDEBUG"
 937 fi
 938 
 939 CCXXFLAGS_JDK="$CCXXFLAGS_JDK -DARCH='\"$OPENJDK_TARGET_CPU_LEGACY\"' -D$OPENJDK_TARGET_CPU_LEGACY"
 940 CCXXFLAGS_JDK="$CCXXFLAGS_JDK -DRELEASE='\"$RELEASE\"'"
 941 
 942 CCXXFLAGS_JDK="$CCXXFLAGS_JDK \
 943         -I${JDK_OUTPUTDIR}/include \
 944         -I${JDK_OUTPUTDIR}/include/$OPENJDK_TARGET_OS \
 945         -I${JDK_TOPDIR}/src/share/javavm/export \
 946         -I${JDK_TOPDIR}/src/$OPENJDK_TARGET_OS_API_DIR/javavm/export \
 947         -I${JDK_TOPDIR}/src/share/native/common \
 948         -I${JDK_TOPDIR}/src/$OPENJDK_TARGET_OS_API_DIR/native/common"
 949 
 950 # The shared libraries are compiled using the picflag.
 951 CFLAGS_JDKLIB="$CCXXFLAGS_JDK $CFLAGS_JDK $PICFLAG $CFLAGS_JDKLIB_EXTRA"
 952 CXXFLAGS_JDKLIB="$CCXXFLAGS_JDK $CXXFLAGS_JDK $PICFLAG $CXXFLAGS_JDKLIB_EXTRA "
 953 
 954 # Executable flags
 955 CFLAGS_JDKEXE="$CCXXFLAGS_JDK $CFLAGS_JDK"
 956 CXXFLAGS_JDKEXE="$CCXXFLAGS_JDK $CXXFLAGS_JDK"
 957 
 958 # Now this is odd. The JDK native libraries have to link against libjvm.so
 959 # On 32-bit machines there is normally two distinct libjvm.so:s, client and server.
 960 # Which should we link to? Are we lucky enough that the binary api to the libjvm.so library
 961 # is identical for client and server? Yes. Which is picked at runtime (client or server)?
 962 # Neither, since the chosen libjvm.so has already been loaded by the launcher, all the following
 963 # libraries will link to whatever is in memory. Yuck.
 964 #
 965 # Thus we offer the compiler to find libjvm.so first in server then in client. It works. Ugh.
 966 if test "x$COMPILER_NAME" = xcl; then
 967     LDFLAGS_JDK="$LDFLAGS_JDK -nologo -opt:ref -incremental:no"
 968     if test "x$OPENJDK_TARGET_CPU" = xx86; then
 969         LDFLAGS_JDK="$LDFLAGS_JDK -safeseh"
 970     fi
 971     # TODO: make -debug optional "--disable-full-debug-symbols"
 972     LDFLAGS_JDK="$LDFLAGS_JDK -debug"
 973     LDFLAGS_JDKLIB="${LDFLAGS_JDK} -dll -libpath:${JDK_OUTPUTDIR}/lib"
 974     LDFLAGS_JDKLIB_SUFFIX=""
 975     if test "x$OPENJDK_TARGET_CPU_BITS" = "x64"; then
 976         LDFLAGS_STACK_SIZE=1048576
 977     else
 978         LDFLAGS_STACK_SIZE=327680
 979     fi
 980     LDFLAGS_JDKEXE="${LDFLAGS_JDK} /STACK:$LDFLAGS_STACK_SIZE"
 981 else
 982     if test "x$COMPILER_NAME" = xgcc; then
 983         # If this is a --hash-style=gnu system, use --hash-style=both, why?
 984         HAS_GNU_HASH=`$CC -dumpspecs 2>/dev/null | $GREP 'hash-style=gnu'`
 985         if test -n "$HAS_GNU_HASH"; then
 986             LDFLAGS_JDK="${LDFLAGS_JDK} -Xlinker --hash-style=both "
 987         fi
 988         if test "x$OPENJDK_TARGET_OS" = xlinux; then
 989           # And since we now know that the linker is gnu, then add -z defs, to forbid
 990           # undefined symbols in object files.
 991           LDFLAGS_JDK="${LDFLAGS_JDK} -Xlinker -z -Xlinker defs"
 992           if test "x$DEBUG_LEVEL" = "xrelease"; then
 993               # When building release libraries, tell the linker optimize them.
 994               # Should this be supplied to the OSS linker as well?
 995               LDFLAGS_JDK="${LDFLAGS_JDK} -Xlinker -O1"
 996           fi
 997         fi
 998     fi
 999     LDFLAGS_JDKLIB="${LDFLAGS_JDK} $SHARED_LIBRARY_FLAGS \
1000                     -L${JDK_OUTPUTDIR}/lib${OPENJDK_TARGET_CPU_LIBDIR}"
1001 
1002     # On some platforms (mac) the linker warns about non existing -L dirs.
1003     # Add server first if available. Linking aginst client does not always produce the same results.
1004     # Only add client dir if client is being built. Add minimal (note not minimal1) if only building minimal1.
1005     # Default to server for other variants.
1006     if test "x$JVM_VARIANT_SERVER" = xtrue; then
1007         LDFLAGS_JDKLIB="${LDFLAGS_JDKLIB} -L${JDK_OUTPUTDIR}/lib${OPENJDK_TARGET_CPU_LIBDIR}/server"
1008     elif test "x$JVM_VARIANT_CLIENT" = xtrue; then
1009         LDFLAGS_JDKLIB="${LDFLAGS_JDKLIB} -L${JDK_OUTPUTDIR}/lib${OPENJDK_TARGET_CPU_LIBDIR}/client"
1010     elif test "x$JVM_VARIANT_MINIMAL1" = xtrue; then
1011         LDFLAGS_JDKLIB="${LDFLAGS_JDKLIB} -L${JDK_OUTPUTDIR}/lib${OPENJDK_TARGET_CPU_LIBDIR}/minimal"
1012     else
1013         LDFLAGS_JDKLIB="${LDFLAGS_JDKLIB} -L${JDK_OUTPUTDIR}/lib${OPENJDK_TARGET_CPU_LIBDIR}/server"
1014     fi
1015 
1016     LDFLAGS_JDKLIB_SUFFIX="-ljava -ljvm"
1017     if test "x$COMPILER_NAME" = xossc; then
1018         LDFLAGS_JDKLIB_SUFFIX="$LDFLAGS_JDKLIB_SUFFIX -lc"
1019     fi
1020 
1021     LDFLAGS_JDKEXE="${LDFLAGS_JDK}"
1022     if test "x$OPENJDK_TARGET_OS" = xlinux; then
1023         LDFLAGS_JDKEXE="$LDFLAGS_JDKEXE -Xlinker --allow-shlib-undefined"
1024     fi
1025 fi
1026 
1027 AC_SUBST(CFLAGS_JDKLIB)
1028 AC_SUBST(CFLAGS_JDKEXE)
1029 
1030 AC_SUBST(CXXFLAGS_JDKLIB)
1031 AC_SUBST(CXXFLAGS_JDKEXE)
1032 
1033 AC_SUBST(LDFLAGS_JDKLIB)
1034 AC_SUBST(LDFLAGS_JDKEXE)
1035 AC_SUBST(LDFLAGS_JDKLIB_SUFFIX)
1036 AC_SUBST(LDFLAGS_JDKEXE_SUFFIX)
1037 AC_SUBST(LDFLAGS_CXX_JDK)
1038 ])
1039 
1040 
1041 # TOOLCHAIN_COMPILER_CHECK_ARGUMENTS([ARGUMENT], [RUN-IF-TRUE],
1042 #                                   [RUN-IF-FALSE])
1043 # ------------------------------------------------------------
1044 # Check that the c and c++ compilers support an argument
1045 AC_DEFUN([TOOLCHAIN_COMPILER_CHECK_ARGUMENTS],
1046 [
1047   AC_MSG_CHECKING([if compiler supports "$1"])
1048   supports=yes
1049 
1050   saved_cflags="$CFLAGS"
1051   CFLAGS="$CFLAGS $1"
1052   AC_LANG_PUSH([C])
1053   AC_COMPILE_IFELSE([
1054     AC_LANG_SOURCE([[int i;]])
1055   ], [], [supports=no])
1056   AC_LANG_POP([C])
1057   CFLAGS="$saved_cflags"
1058 
1059   saved_cxxflags="$CXXFLAGS"
1060   CXXFLAGS="$CXXFLAG $1"
1061   AC_LANG_PUSH([C++])
1062   AC_COMPILE_IFELSE([
1063     AC_LANG_SOURCE([[int i;]])
1064   ], [], [supports=no])
1065   AC_LANG_POP([C++])
1066   CXXFLAGS="$saved_cxxflags"
1067 
1068   AC_MSG_RESULT([$supports])
1069   if test "x$supports" = "xyes" ; then
1070     m4_ifval([$2], [$2], [:])
1071   else
1072     m4_ifval([$3], [$3], [:])
1073   fi
1074 ])
1075 
1076 AC_DEFUN_ONCE([TOOLCHAIN_SETUP_COMPILER_FLAGS_MISC],
1077 [
1078   # Some Zero and Shark settings.
1079   # ZERO_ARCHFLAG tells the compiler which mode to build for
1080   case "${OPENJDK_TARGET_CPU}" in
1081     s390)
1082       ZERO_ARCHFLAG="-m31"
1083       ;;
1084     *)
1085       ZERO_ARCHFLAG="-m${OPENJDK_TARGET_CPU_BITS}"
1086   esac
1087   TOOLCHAIN_COMPILER_CHECK_ARGUMENTS([$ZERO_ARCHFLAG], [], [ZERO_ARCHFLAG=""])
1088   AC_SUBST(ZERO_ARCHFLAG)
1089 
1090   # Check that the compiler supports -mX flags
1091   # Set COMPILER_SUPPORTS_TARGET_BITS_FLAG to 'true' if it does
1092   TOOLCHAIN_COMPILER_CHECK_ARGUMENTS([-m${OPENJDK_TARGET_CPU_BITS}],
1093     [COMPILER_SUPPORTS_TARGET_BITS_FLAG=true],
1094     [COMPILER_SUPPORTS_TARGET_BITS_FLAG=false])
1095   AC_SUBST(COMPILER_SUPPORTS_TARGET_BITS_FLAG)
1096 ])
1097 
1098 # Setup the JTREG paths
1099 AC_DEFUN_ONCE([TOOLCHAIN_SETUP_JTREG],
1100 [
1101   AC_ARG_WITH(jtreg, [AS_HELP_STRING([--with-jtreg],
1102   [Regression Test Harness @<:@probed@:>@])],
1103   [],
1104   [with_jtreg=no])
1105 
1106   if test "x$with_jtreg" = xno; then
1107     # jtreg disabled
1108     AC_MSG_CHECKING([for jtreg])
1109     AC_MSG_RESULT(no)
1110   else
1111     if test "x$with_jtreg" != xyes; then
1112       # with path specified.
1113       JT_HOME="$with_jtreg"
1114     fi
1115 
1116     if test "x$JT_HOME" != x; then
1117       AC_MSG_CHECKING([for jtreg])
1118 
1119       # use JT_HOME enviroment var.
1120       BASIC_FIXUP_PATH([JT_HOME])
1121 
1122       # jtreg win32 script works for everybody
1123       JTREGEXE="$JT_HOME/win32/bin/jtreg"
1124 
1125       if test ! -f "$JTREGEXE"; then
1126         AC_MSG_ERROR([JTReg executable does not exist: $JTREGEXE])
1127       fi
1128 
1129       AC_MSG_RESULT($JTREGEXE)
1130     else
1131       # try to find jtreg on path
1132       BASIC_REQUIRE_PROG(JTREGEXE, jtreg)
1133       JT_HOME="`$DIRNAME $JTREGEXE`"
1134     fi
1135   fi
1136 
1137   AC_SUBST(JT_HOME)
1138   AC_SUBST(JTREGEXE)
1139 ])