1 #
   2 # Copyright (c) 2011, 2016, 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 # Reset the global CFLAGS/LDFLAGS variables and initialize them with the
  27 # corresponding configure arguments instead
  28 AC_DEFUN_ONCE([FLAGS_SETUP_USER_SUPPLIED_FLAGS],
  29 [
  30   if test "x$CFLAGS" != "x${ADDED_CFLAGS}"; then
  31     AC_MSG_WARN([Ignoring CFLAGS($CFLAGS) found in environment. Use --with-extra-cflags])
  32   fi
  33 
  34   if test "x$CXXFLAGS" != "x${ADDED_CXXFLAGS}"; then
  35     AC_MSG_WARN([Ignoring CXXFLAGS($CXXFLAGS) found in environment. Use --with-extra-cxxflags])
  36   fi
  37 
  38   if test "x$LDFLAGS" != "x${ADDED_LDFLAGS}"; then
  39     AC_MSG_WARN([Ignoring LDFLAGS($LDFLAGS) found in environment. Use --with-extra-ldflags])
  40   fi
  41 
  42   AC_ARG_WITH(extra-cflags, [AS_HELP_STRING([--with-extra-cflags],
  43       [extra flags to be used when compiling jdk c-files])])
  44 
  45   AC_ARG_WITH(extra-cxxflags, [AS_HELP_STRING([--with-extra-cxxflags],
  46       [extra flags to be used when compiling jdk c++-files])])
  47 
  48   AC_ARG_WITH(extra-ldflags, [AS_HELP_STRING([--with-extra-ldflags],
  49       [extra flags to be used when linking jdk])])
  50 
  51   EXTRA_CFLAGS="$with_extra_cflags"
  52   EXTRA_CXXFLAGS="$with_extra_cxxflags"
  53   EXTRA_LDFLAGS="$with_extra_ldflags"
  54 
  55   # Hotspot needs these set in their legacy form
  56   LEGACY_EXTRA_CFLAGS="$LEGACY_EXTRA_CFLAGS $EXTRA_CFLAGS"
  57   LEGACY_EXTRA_CXXFLAGS="$LEGACY_EXTRA_CXXFLAGS $EXTRA_CXXFLAGS"
  58   LEGACY_EXTRA_LDFLAGS="$LEGACY_EXTRA_LDFLAGS $EXTRA_LDFLAGS"
  59 
  60   AC_SUBST(LEGACY_EXTRA_CFLAGS)
  61   AC_SUBST(LEGACY_EXTRA_CXXFLAGS)
  62   AC_SUBST(LEGACY_EXTRA_LDFLAGS)
  63 
  64   # The global CFLAGS and LDLAGS variables are used by configure tests and
  65   # should include the extra parameters
  66   CFLAGS="$EXTRA_CFLAGS"
  67   CXXFLAGS="$EXTRA_CXXFLAGS"
  68   LDFLAGS="$EXTRA_LDFLAGS"
  69   CPPFLAGS=""
  70 ])
  71 
  72 # Setup the sysroot flags and add them to global CFLAGS and LDFLAGS so
  73 # that configure can use them while detecting compilers.
  74 # TOOLCHAIN_TYPE is available here.
  75 # Param 1 - Optional prefix to all variables. (e.g BUILD_)
  76 AC_DEFUN([FLAGS_SETUP_SYSROOT_FLAGS],
  77 [
  78   if test "x[$]$1SYSROOT" != "x"; then
  79     if test "x$TOOLCHAIN_TYPE" = xsolstudio; then
  80       if test "x$OPENJDK_TARGET_OS" = xsolaris; then
  81         # Solaris Studio does not have a concept of sysroot. Instead we must
  82         # make sure the default include and lib dirs are appended to each
  83         # compile and link command line.
  84         $1SYSROOT_CFLAGS="-I[$]$1SYSROOT/usr/include"
  85         $1SYSROOT_LDFLAGS="-L[$]$1SYSROOT/usr/lib$OPENJDK_TARGET_CPU_ISADIR \
  86             -L[$]$1SYSROOT/lib$OPENJDK_TARGET_CPU_ISADIR \
  87             -L[$]$1SYSROOT/usr/ccs/lib$OPENJDK_TARGET_CPU_ISADIR"
  88       fi
  89     elif test "x$TOOLCHAIN_TYPE" = xgcc; then
  90       $1SYSROOT_CFLAGS="--sysroot=[$]$1SYSROOT"
  91       $1SYSROOT_LDFLAGS="--sysroot=[$]$1SYSROOT"
  92     elif test "x$TOOLCHAIN_TYPE" = xclang; then
  93       $1SYSROOT_CFLAGS="-isysroot [$]$1SYSROOT"
  94       $1SYSROOT_LDFLAGS="-isysroot [$]$1SYSROOT"
  95     fi
  96     # Propagate the sysroot args to hotspot
  97     $1LEGACY_EXTRA_CFLAGS="[$]$1LEGACY_EXTRA_CFLAGS [$]$1SYSROOT_CFLAGS"
  98     $1LEGACY_EXTRA_CXXFLAGS="[$]$1LEGACY_EXTRA_CXXFLAGS [$]$1SYSROOT_CFLAGS"
  99     $1LEGACY_EXTRA_LDFLAGS="[$]$1LEGACY_EXTRA_LDFLAGS [$]$1SYSROOT_LDFLAGS"
 100     # The global CFLAGS and LDFLAGS variables need these for configure to function
 101     $1CFLAGS="[$]$1CFLAGS [$]$1SYSROOT_CFLAGS"
 102     $1CPPFLAGS="[$]$1CPPFLAGS [$]$1SYSROOT_CFLAGS"
 103     $1CXXFLAGS="[$]$1CXXFLAGS [$]$1SYSROOT_CFLAGS"
 104     $1LDFLAGS="[$]$1LDFLAGS [$]$1SYSROOT_LDFLAGS"
 105   fi
 106 
 107   if test "x$OPENJDK_TARGET_OS" = xmacosx; then
 108     # We also need -iframework<path>/System/Library/Frameworks
 109     $1SYSROOT_CFLAGS="[$]$1SYSROOT_CFLAGS -iframework [$]$1SYSROOT/System/Library/Frameworks"
 110     $1SYSROOT_LDFLAGS="[$]$1SYSROOT_LDFLAGS -iframework [$]$1SYSROOT/System/Library/Frameworks"
 111     # These always need to be set, or we can't find the frameworks embedded in JavaVM.framework
 112     # set this here so it doesn't have to be peppered throughout the forest
 113     $1SYSROOT_CFLAGS="[$]$1SYSROOT_CFLAGS -F [$]$1SYSROOT/System/Library/Frameworks/JavaVM.framework/Frameworks"
 114     $1SYSROOT_LDFLAGS="[$]$1SYSROOT_LDFLAGS -F [$]$1SYSROOT/System/Library/Frameworks/JavaVM.framework/Frameworks"
 115   fi
 116 
 117   AC_SUBST($1SYSROOT_CFLAGS)
 118   AC_SUBST($1SYSROOT_LDFLAGS)
 119 ])
 120 
 121 AC_DEFUN_ONCE([FLAGS_SETUP_INIT_FLAGS],
 122 [
 123   # COMPILER_TARGET_BITS_FLAG  : option for selecting 32- or 64-bit output
 124   # COMPILER_COMMAND_FILE_FLAG : option for passing a command file to the compiler
 125   if test "x$TOOLCHAIN_TYPE" = xxlc; then
 126     COMPILER_TARGET_BITS_FLAG="-q"
 127     COMPILER_COMMAND_FILE_FLAG="-f"
 128   else
 129     COMPILER_TARGET_BITS_FLAG="-m"
 130     COMPILER_COMMAND_FILE_FLAG="@"
 131 
 132     # The solstudio linker does not support @-files.
 133     if test "x$TOOLCHAIN_TYPE" = xsolstudio; then
 134       COMPILER_COMMAND_FILE_FLAG=
 135     fi
 136 
 137     # Check if @file is supported by gcc
 138     if test "x$TOOLCHAIN_TYPE" = xgcc; then
 139       AC_MSG_CHECKING([if @file is supported by gcc])
 140       # Extra emtpy "" to prevent ECHO from interpreting '--version' as argument
 141       $ECHO "" "--version" > command.file
 142       if $CXX @command.file 2>&AS_MESSAGE_LOG_FD >&AS_MESSAGE_LOG_FD; then
 143         AC_MSG_RESULT(yes)
 144         COMPILER_COMMAND_FILE_FLAG="@"
 145       else
 146         AC_MSG_RESULT(no)
 147         COMPILER_COMMAND_FILE_FLAG=
 148       fi
 149       rm -rf command.file
 150     fi
 151   fi
 152   AC_SUBST(COMPILER_TARGET_BITS_FLAG)
 153   AC_SUBST(COMPILER_COMMAND_FILE_FLAG)
 154 
 155   # FIXME: figure out if we should select AR flags depending on OS or toolchain.
 156   if test "x$OPENJDK_TARGET_OS" = xmacosx; then
 157     ARFLAGS="-r"
 158   elif test "x$OPENJDK_TARGET_OS" = xaix; then
 159     ARFLAGS="-X64"
 160   elif test "x$OPENJDK_TARGET_OS" = xwindows; then
 161     # lib.exe is used as AR to create static libraries.
 162     ARFLAGS="-nologo -NODEFAULTLIB:MSVCRT"
 163   else
 164     ARFLAGS=""
 165   fi
 166   AC_SUBST(ARFLAGS)
 167 
 168   ## Setup strip.
 169   # FIXME: should this really be per platform, or should it be per toolchain type?
 170   # strip is not provided by clang or solstudio; so guessing platform makes most sense.
 171   # FIXME: we should really only export STRIPFLAGS from here, not POST_STRIP_CMD.
 172   if test "x$OPENJDK_TARGET_OS" = xlinux; then
 173     STRIPFLAGS="-g"
 174   elif test "x$OPENJDK_TARGET_OS" = xsolaris; then
 175     STRIPFLAGS="-x"
 176   elif test "x$OPENJDK_TARGET_OS" = xmacosx; then
 177     STRIPFLAGS="-S"
 178   elif test "x$OPENJDK_TARGET_OS" = xaix; then
 179     STRIPFLAGS="-X32_64"
 180   fi
 181 
 182   AC_SUBST(STRIPFLAGS)
 183 
 184   if test "x$TOOLCHAIN_TYPE" = xmicrosoft; then
 185     CC_OUT_OPTION=-Fo
 186     EXE_OUT_OPTION=-out:
 187     LD_OUT_OPTION=-out:
 188     AR_OUT_OPTION=-out:
 189   else
 190     # The option used to specify the target .o,.a or .so file.
 191     # When compiling, how to specify the to be created object file.
 192     CC_OUT_OPTION='-o$(SPACE)'
 193     # When linking, how to specify the to be created executable.
 194     EXE_OUT_OPTION='-o$(SPACE)'
 195     # When linking, how to specify the to be created dynamically linkable library.
 196     LD_OUT_OPTION='-o$(SPACE)'
 197     # When archiving, how to specify the to be create static archive for object files.
 198     AR_OUT_OPTION='rcs$(SPACE)'
 199   fi
 200   AC_SUBST(CC_OUT_OPTION)
 201   AC_SUBST(EXE_OUT_OPTION)
 202   AC_SUBST(LD_OUT_OPTION)
 203   AC_SUBST(AR_OUT_OPTION)
 204 
 205   # On Windows, we need to set RC flags.
 206   if test "x$TOOLCHAIN_TYPE" = xmicrosoft; then
 207     RC_FLAGS="-nologo -l0x409"
 208     if test "x$VARIANT" = xOPT; then
 209       RC_FLAGS="$RC_FLAGS -DNDEBUG"
 210     fi
 211 
 212     # The version variables used to create RC_FLAGS may be overridden
 213     # in a custom configure script, or possibly the command line.
 214     # Let those variables be expanded at make time in spec.gmk.
 215     # The \$ are escaped to the shell, and the $(...) variables
 216     # are evaluated by make.
 217     RC_FLAGS="$RC_FLAGS \
 218         -D\"JDK_VERSION_STRING=\$(VERSION_STRING)\" \
 219         -D\"JDK_COMPANY=\$(COMPANY_NAME)\" \
 220         -D\"JDK_COMPONENT=\$(PRODUCT_NAME) \$(JDK_RC_PLATFORM_NAME) binary\" \
 221         -D\"JDK_VER=\$(VERSION_NUMBER)\" \
 222         -D\"JDK_COPYRIGHT=Copyright \xA9 $COPYRIGHT_YEAR\" \
 223         -D\"JDK_NAME=\$(PRODUCT_NAME) \$(JDK_RC_PLATFORM_NAME) \$(VERSION_MAJOR)\" \
 224         -D\"JDK_FVER=\$(subst .,\$(COMMA),\$(VERSION_NUMBER_FOUR_POSITIONS))\""
 225   fi
 226   AC_SUBST(RC_FLAGS)
 227 
 228   if test "x$TOOLCHAIN_TYPE" = xmicrosoft; then
 229     # silence copyright notice and other headers.
 230     COMMON_CCXXFLAGS="$COMMON_CCXXFLAGS -nologo"
 231   fi
 232 ])
 233 
 234 AC_DEFUN_ONCE([FLAGS_SETUP_COMPILER_FLAGS_FOR_LIBS],
 235 [
 236   ###############################################################################
 237   #
 238   # How to compile shared libraries.
 239   #
 240 
 241   if test "x$TOOLCHAIN_TYPE" = xgcc; then
 242     PICFLAG="-fPIC"
 243     C_FLAG_REORDER=''
 244     CXX_FLAG_REORDER=''
 245 
 246     if test "x$OPENJDK_TARGET_OS" = xmacosx; then
 247       # Linking is different on MacOSX
 248       if test "x$STATIC_BUILD" = xtrue; then
 249         SHARED_LIBRARY_FLAGS ='-undefined dynamic_lookup'
 250       else
 251         SHARED_LIBRARY_FLAGS="-dynamiclib -compatibility_version 1.0.0 -current_version 1.0.0 $PICFLAG"
 252       fi
 253       SET_EXECUTABLE_ORIGIN='-Wl,-rpath,@loader_path/.'
 254       SET_SHARED_LIBRARY_ORIGIN="$SET_EXECUTABLE_ORIGIN"
 255       SET_SHARED_LIBRARY_NAME='-Wl,-install_name,@rpath/[$]1'
 256       SET_SHARED_LIBRARY_MAPFILE=''
 257     else
 258       # Default works for linux, might work on other platforms as well.
 259       SHARED_LIBRARY_FLAGS='-shared'
 260       if test "x$OPENJDK_TARGET_OS_ENV" = xbsd.netbsd; then
 261         # -rpath $ORIGIN is broken on NetBSD.
 262         SET_EXECUTABLE_ORIGIN=''
 263       else
 264         SET_EXECUTABLE_ORIGIN='-Wl,-z,origin -Wl,-rpath,\$$$$ORIGIN[$]1'
 265       fi
 266       SET_SHARED_LIBRARY_ORIGIN="$SET_EXECUTABLE_ORIGIN"
 267       SET_SHARED_LIBRARY_NAME='-Wl,-soname=[$]1'
 268       SET_SHARED_LIBRARY_MAPFILE='-Wl,-version-script=[$]1'
 269     fi
 270   elif test "x$TOOLCHAIN_TYPE" = xclang; then
 271     C_FLAG_REORDER=''
 272     CXX_FLAG_REORDER=''
 273 
 274     if test "x$OPENJDK_TARGET_OS" = xmacosx; then
 275       # Linking is different on MacOSX
 276       PICFLAG=''
 277       SHARED_LIBRARY_FLAGS="-dynamiclib -compatibility_version 1.0.0 -current_version 1.0.0 $PICFLAG"
 278       SET_EXECUTABLE_ORIGIN='-Wl,-rpath,@loader_path/.'
 279       SET_SHARED_LIBRARY_ORIGIN="$SET_EXECUTABLE_ORIGIN"
 280       SET_SHARED_LIBRARY_NAME='-Wl,-install_name,@rpath/[$]1'
 281       SET_SHARED_LIBRARY_MAPFILE=''
 282     else
 283       # Default works for linux, might work on other platforms as well.
 284       PICFLAG='-fPIC'
 285       SHARED_LIBRARY_FLAGS='-shared'
 286       if test "x$OPENJDK_TARGET_OS_ENV" = xbsd.netbsd; then
 287         # -rpath $ORIGIN is broken on NetBSD.
 288         SET_EXECUTABLE_ORIGIN=''
 289       else
 290         SET_EXECUTABLE_ORIGIN='-Wl,-z,origin -Wl,-rpath,\$$$$ORIGIN[$]1'
 291       fi
 292       SET_SHARED_LIBRARY_ORIGIN="$SET_EXECUTABLE_ORIGIN"
 293       SET_SHARED_LIBRARY_NAME='-Wl,-soname=[$]1'
 294       SET_SHARED_LIBRARY_MAPFILE='-Wl,-version-script=[$]1'
 295     fi
 296   elif test "x$TOOLCHAIN_TYPE" = xsolstudio; then
 297     PICFLAG="-KPIC"
 298     C_FLAG_REORDER='-xF'
 299     CXX_FLAG_REORDER='-xF'
 300     SHARED_LIBRARY_FLAGS="-G"
 301     SET_EXECUTABLE_ORIGIN='-R\$$$$ORIGIN[$]1'
 302     SET_SHARED_LIBRARY_ORIGIN="$SET_EXECUTABLE_ORIGIN"
 303     SET_SHARED_LIBRARY_NAME='-h [$]1'
 304     SET_SHARED_LIBRARY_MAPFILE='-M[$]1'
 305   elif test "x$TOOLCHAIN_TYPE" = xxlc; then
 306     PICFLAG="-qpic=large"
 307     C_FLAG_REORDER=''
 308     CXX_FLAG_REORDER=''
 309     SHARED_LIBRARY_FLAGS="-qmkshrobj"
 310     SET_EXECUTABLE_ORIGIN=""
 311     SET_SHARED_LIBRARY_ORIGIN=''
 312     SET_SHARED_LIBRARY_NAME=''
 313     SET_SHARED_LIBRARY_MAPFILE=''
 314   elif test "x$TOOLCHAIN_TYPE" = xmicrosoft; then
 315     PICFLAG=""
 316     C_FLAG_REORDER=''
 317     CXX_FLAG_REORDER=''
 318     SHARED_LIBRARY_FLAGS="-dll"
 319     SET_EXECUTABLE_ORIGIN=''
 320     SET_SHARED_LIBRARY_ORIGIN=''
 321     SET_SHARED_LIBRARY_NAME=''
 322     SET_SHARED_LIBRARY_MAPFILE=''
 323   fi
 324 
 325   AC_SUBST(C_FLAG_REORDER)
 326   AC_SUBST(CXX_FLAG_REORDER)
 327   AC_SUBST(SET_EXECUTABLE_ORIGIN)
 328   AC_SUBST(SET_SHARED_LIBRARY_ORIGIN)
 329   AC_SUBST(SET_SHARED_LIBRARY_NAME)
 330   AC_SUBST(SET_SHARED_LIBRARY_MAPFILE)
 331   AC_SUBST(SHARED_LIBRARY_FLAGS)
 332 
 333   if test "x$OPENJDK_TARGET_OS" = xsolaris; then
 334     CFLAGS_JDK="${CFLAGS_JDK} -D__solaris__"
 335     CXXFLAGS_JDK="${CXXFLAGS_JDK} -D__solaris__"
 336     CFLAGS_JDKLIB_EXTRA='-xstrconst'
 337   fi
 338   # The (cross) compiler is now configured, we can now test capabilities
 339   # of the target platform.
 340 ])
 341 
 342 # Documentation on common flags used for solstudio in HIGHEST.
 343 #
 344 # WARNING: Use of OPTIMIZATION_LEVEL=HIGHEST in your Makefile needs to be
 345 #          done with care, there are some assumptions below that need to
 346 #          be understood about the use of pointers, and IEEE behavior.
 347 #
 348 # -fns: Use non-standard floating point mode (not IEEE 754)
 349 # -fsimple: Do some simplification of floating point arithmetic (not IEEE 754)
 350 # -fsingle: Use single precision floating point with 'float'
 351 # -xalias_level=basic: Assume memory references via basic pointer types do not alias
 352 #   (Source with excessing pointer casting and data access with mixed
 353 #    pointer types are not recommended)
 354 # -xbuiltin=%all: Use intrinsic or inline versions for math/std functions
 355 #   (If you expect perfect errno behavior, do not use this)
 356 # -xdepend: Loop data dependency optimizations (need -xO3 or higher)
 357 # -xrestrict: Pointer parameters to functions do not overlap
 358 #   (Similar to -xalias_level=basic usage, but less obvious sometimes.
 359 #    If you pass in multiple pointers to the same data, do not use this)
 360 # -xlibmil: Inline some library routines
 361 #   (If you expect perfect errno behavior, do not use this)
 362 # -xlibmopt: Use optimized math routines (CURRENTLY DISABLED)
 363 #   (If you expect perfect errno behavior, do not use this)
 364 #  Can cause undefined external on Solaris 8 X86 on __sincos, removing for now
 365 
 366     # FIXME: this will never happen since sparc != sparcv9, ie 32 bit, which we don't build anymore.
 367     # Bug?
 368     #if test "x$OPENJDK_TARGET_CPU" = xsparc; then
 369     #  CFLAGS_JDK="${CFLAGS_JDK} -xmemalign=4s"
 370     #  CXXFLAGS_JDK="${CXXFLAGS_JDK} -xmemalign=4s"
 371     #fi
 372 
 373 AC_DEFUN_ONCE([FLAGS_SETUP_COMPILER_FLAGS_FOR_OPTIMIZATION],
 374 [
 375 
 376   ###############################################################################
 377   #
 378   # Setup the opt flags for different compilers
 379   # and different operating systems.
 380   #
 381 
 382   # FIXME: this was indirectly the old default, but just inherited.
 383   # if test "x$TOOLCHAIN_TYPE" = xmicrosoft; then
 384   #   C_FLAG_DEPS="-MMD -MF"
 385   # fi
 386 
 387   # Generate make dependency files
 388   if test "x$TOOLCHAIN_TYPE" = xgcc; then
 389     C_FLAG_DEPS="-MMD -MF"
 390   elif test "x$TOOLCHAIN_TYPE" = xclang; then
 391     C_FLAG_DEPS="-MMD -MF"
 392   elif test "x$TOOLCHAIN_TYPE" = xsolstudio; then
 393     C_FLAG_DEPS="-xMMD -xMF"
 394   elif test "x$TOOLCHAIN_TYPE" = xxlc; then
 395     C_FLAG_DEPS="-qmakedep=gcc -MF"
 396   fi
 397   CXX_FLAG_DEPS="$C_FLAG_DEPS"
 398   AC_SUBST(C_FLAG_DEPS)
 399   AC_SUBST(CXX_FLAG_DEPS)
 400 
 401   # Debug symbols
 402   if test "x$TOOLCHAIN_TYPE" = xgcc; then
 403     if test "x$OPENJDK_TARGET_CPU_BITS" = "x64" && test "x$DEBUG_LEVEL" = "xfastdebug"; then
 404       # reduce from default "-g2" option to save space
 405       CFLAGS_DEBUG_SYMBOLS="-g1"
 406       CXXFLAGS_DEBUG_SYMBOLS="-g1"
 407     else
 408       CFLAGS_DEBUG_SYMBOLS="-g"
 409       CXXFLAGS_DEBUG_SYMBOLS="-g"
 410     fi
 411   elif test "x$TOOLCHAIN_TYPE" = xclang; then
 412     CFLAGS_DEBUG_SYMBOLS="-g"
 413     CXXFLAGS_DEBUG_SYMBOLS="-g"
 414   elif test "x$TOOLCHAIN_TYPE" = xsolstudio; then
 415     CFLAGS_DEBUG_SYMBOLS="-g -xs"
 416     # -g0 enables debug symbols without disabling inlining.
 417     CXXFLAGS_DEBUG_SYMBOLS="-g0 -xs"
 418   elif test "x$TOOLCHAIN_TYPE" = xxlc; then
 419     CFLAGS_DEBUG_SYMBOLS="-g"
 420     CXXFLAGS_DEBUG_SYMBOLS="-g"
 421   fi
 422   AC_SUBST(CFLAGS_DEBUG_SYMBOLS)
 423   AC_SUBST(CXXFLAGS_DEBUG_SYMBOLS)
 424 
 425   # bounds, memory and behavior checking options
 426   if test "x$TOOLCHAIN_TYPE" = xgcc; then
 427     case $DEBUG_LEVEL in
 428     release )
 429       # no adjustment
 430       ;;
 431     fastdebug )
 432       # no adjustment
 433       ;;
 434     slowdebug )
 435       # Add runtime stack smashing and undefined behavior checks.
 436       # Not all versions of gcc support -fstack-protector
 437       STACK_PROTECTOR_CFLAG="-fstack-protector-all"
 438       FLAGS_COMPILER_CHECK_ARGUMENTS(ARGUMENT: [$STACK_PROTECTOR_CFLAG], IF_FALSE: [STACK_PROTECTOR_CFLAG=""])
 439 
 440       CFLAGS_DEBUG_OPTIONS="$STACK_PROTECTOR_CFLAG --param ssp-buffer-size=1"
 441       CXXFLAGS_DEBUG_OPTIONS="$STACK_PROTECTOR_CFLAG --param ssp-buffer-size=1"
 442       ;;
 443     esac
 444   fi
 445 
 446   # Optimization levels
 447   if test "x$TOOLCHAIN_TYPE" = xsolstudio; then
 448     CC_HIGHEST="$CC_HIGHEST -fns -fsimple -fsingle -xbuiltin=%all -xdepend -xrestrict -xlibmil"
 449 
 450     if test "x$OPENJDK_TARGET_CPU_ARCH" = "xx86"; then
 451       # FIXME: seems we always set -xregs=no%frameptr; put it elsewhere more global?
 452       C_O_FLAG_HIGHEST="-xO4 -Wu,-O4~yz $CC_HIGHEST -xalias_level=basic -xregs=no%frameptr"
 453       C_O_FLAG_HI="-xO4 -Wu,-O4~yz -xregs=no%frameptr"
 454       C_O_FLAG_NORM="-xO2 -Wu,-O2~yz -xregs=no%frameptr"
 455       C_O_FLAG_DEBUG="-xregs=no%frameptr"
 456       C_O_FLAG_NONE="-xregs=no%frameptr"
 457       CXX_O_FLAG_HIGHEST="-xO4 -Qoption ube -O4~yz $CC_HIGHEST -xregs=no%frameptr"
 458       CXX_O_FLAG_HI="-xO4 -Qoption ube -O4~yz -xregs=no%frameptr"
 459       CXX_O_FLAG_NORM="-xO2 -Qoption ube -O2~yz -xregs=no%frameptr"
 460       CXX_O_FLAG_DEBUG="-xregs=no%frameptr"
 461       CXX_O_FLAG_NONE="-xregs=no%frameptr"
 462       if test "x$OPENJDK_TARGET_CPU_BITS" = "x32"; then
 463         C_O_FLAG_HIGHEST="$C_O_FLAG_HIGHEST -xchip=pentium"
 464         CXX_O_FLAG_HIGHEST="$CXX_O_FLAG_HIGHEST -xchip=pentium"
 465       fi
 466     elif test "x$OPENJDK_TARGET_CPU_ARCH" = "xsparc"; then
 467       C_O_FLAG_HIGHEST="-xO4 -Wc,-Qrm-s -Wc,-Qiselect-T0 $CC_HIGHEST -xalias_level=basic -xprefetch=auto,explicit -xchip=ultra"
 468       C_O_FLAG_HI="-xO4 -Wc,-Qrm-s -Wc,-Qiselect-T0"
 469       C_O_FLAG_NORM="-xO2 -Wc,-Qrm-s -Wc,-Qiselect-T0"
 470       C_O_FLAG_DEBUG=""
 471       C_O_FLAG_NONE=""
 472       CXX_O_FLAG_HIGHEST="-xO4 -Qoption cg -Qrm-s -Qoption cg -Qiselect-T0 $CC_HIGHEST -xprefetch=auto,explicit -xchip=ultra"
 473       CXX_O_FLAG_HI="-xO4 -Qoption cg -Qrm-s -Qoption cg -Qiselect-T0"
 474       CXX_O_FLAG_NORM="-xO2 -Qoption cg -Qrm-s -Qoption cg -Qiselect-T0"
 475       C_O_FLAG_DEBUG=""
 476       CXX_O_FLAG_NONE=""
 477     fi
 478   else
 479     # The remaining toolchains share opt flags between CC and CXX;
 480     # setup for C and duplicate afterwards.
 481     if test "x$TOOLCHAIN_TYPE" = xgcc; then
 482       if test "x$OPENJDK_TARGET_OS" = xmacosx; then
 483         # On MacOSX we optimize for size, something
 484         # we should do for all platforms?
 485         C_O_FLAG_HIGHEST="-Os"
 486         C_O_FLAG_HI="-Os"
 487         C_O_FLAG_NORM="-Os"
 488       else
 489         C_O_FLAG_HIGHEST="-O3"
 490         C_O_FLAG_HI="-O3"
 491         C_O_FLAG_NORM="-O2"
 492       fi
 493       C_O_FLAG_DEBUG="-O0"
 494       C_O_FLAG_NONE="-O0"
 495     elif test "x$TOOLCHAIN_TYPE" = xclang; then
 496       if test "x$OPENJDK_TARGET_OS" = xmacosx; then
 497         # On MacOSX we optimize for size, something
 498         # we should do for all platforms?
 499         C_O_FLAG_HIGHEST="-Os"
 500         C_O_FLAG_HI="-Os"
 501         C_O_FLAG_NORM="-Os"
 502       else
 503         C_O_FLAG_HIGHEST="-O3"
 504         C_O_FLAG_HI="-O3"
 505         C_O_FLAG_NORM="-O2"
 506       fi
 507       C_O_FLAG_DEBUG="-O0"
 508       C_O_FLAG_NONE="-O0"
 509     elif test "x$TOOLCHAIN_TYPE" = xxlc; then
 510       C_O_FLAG_HIGHEST="-O3"
 511       C_O_FLAG_HI="-O3 -qstrict"
 512       C_O_FLAG_NORM="-O2"
 513       C_O_FLAG_DEBUG="-qnoopt"
 514       C_O_FLAG_NONE="-qnoopt"
 515     elif test "x$TOOLCHAIN_TYPE" = xmicrosoft; then
 516       C_O_FLAG_HIGHEST="-O2"
 517       C_O_FLAG_HI="-O1"
 518       C_O_FLAG_NORM="-O1"
 519       C_O_FLAG_DEBUG="-Od"
 520       C_O_FLAG_NONE="-Od"
 521     fi
 522     CXX_O_FLAG_HIGHEST="$C_O_FLAG_HIGHEST"
 523     CXX_O_FLAG_HI="$C_O_FLAG_HI"
 524     CXX_O_FLAG_NORM="$C_O_FLAG_NORM"
 525     CXX_O_FLAG_DEBUG="$C_O_FLAG_DEBUG"
 526     CXX_O_FLAG_NONE="$C_O_FLAG_NONE"
 527   fi
 528 
 529   # Adjust optimization flags according to debug level.
 530   case $DEBUG_LEVEL in
 531     release )
 532       # no adjustment
 533       ;;
 534     fastdebug )
 535       # Not quite so much optimization
 536       C_O_FLAG_HI="$C_O_FLAG_NORM"
 537       CXX_O_FLAG_HI="$CXX_O_FLAG_NORM"
 538       ;;
 539     slowdebug )
 540       # Disable optimization
 541       C_O_FLAG_HIGHEST="$C_O_FLAG_DEBUG"
 542       C_O_FLAG_HI="$C_O_FLAG_DEBUG"
 543       C_O_FLAG_NORM="$C_O_FLAG_DEBUG"
 544       CXX_O_FLAG_HIGHEST="$CXX_O_FLAG_DEBUG"
 545       CXX_O_FLAG_HI="$CXX_O_FLAG_DEBUG"
 546       CXX_O_FLAG_NORM="$CXX_O_FLAG_DEBUG"
 547       ;;
 548   esac
 549 
 550   AC_SUBST(C_O_FLAG_HIGHEST)
 551   AC_SUBST(C_O_FLAG_HI)
 552   AC_SUBST(C_O_FLAG_NORM)
 553   AC_SUBST(C_O_FLAG_DEBUG)
 554   AC_SUBST(C_O_FLAG_NONE)
 555   AC_SUBST(CXX_O_FLAG_HIGHEST)
 556   AC_SUBST(CXX_O_FLAG_HI)
 557   AC_SUBST(CXX_O_FLAG_NORM)
 558   AC_SUBST(CXX_O_FLAG_DEBUG)
 559   AC_SUBST(CXX_O_FLAG_NONE)
 560 ])
 561 
 562 AC_DEFUN_ONCE([FLAGS_SETUP_COMPILER_FLAGS_FOR_JDK],
 563 [
 564   # Special extras...
 565   if test "x$TOOLCHAIN_TYPE" = xsolstudio; then
 566     if test "x$OPENJDK_TARGET_CPU_ARCH" = "xsparc"; then
 567       CFLAGS_JDKLIB_EXTRA="${CFLAGS_JDKLIB_EXTRA} -xregs=no%appl"
 568       CXXFLAGS_JDKLIB_EXTRA="${CXXFLAGS_JDKLIB_EXTRA} -xregs=no%appl"
 569     fi
 570     CFLAGS_JDKLIB_EXTRA="${CFLAGS_JDKLIB_EXTRA} -errtags=yes -errfmt"
 571     CXXFLAGS_JDKLIB_EXTRA="${CXXFLAGS_JDKLIB_EXTRA} -errtags=yes -errfmt"
 572   elif test "x$TOOLCHAIN_TYPE" = xxlc; then
 573     CFLAGS_JDK="${CFLAGS_JDK} -qchars=signed -qfullpath -qsaveopt"
 574     CXXFLAGS_JDK="${CXXFLAGS_JDK} -qchars=signed -qfullpath -qsaveopt"
 575   fi
 576 
 577   CFLAGS_JDK="${CFLAGS_JDK} $EXTRA_CFLAGS"
 578   CXXFLAGS_JDK="${CXXFLAGS_JDK} $EXTRA_CXXFLAGS"
 579   LDFLAGS_JDK="${LDFLAGS_JDK} $EXTRA_LDFLAGS"
 580 
 581   ###############################################################################
 582   #
 583   # Now setup the CFLAGS and LDFLAGS for the JDK build.
 584   # Later we will also have CFLAGS and LDFLAGS for the hotspot subrepo build.
 585   #
 586 
 587   # Setup compiler/platform specific flags into
 588   #    CFLAGS_JDK    - C Compiler flags
 589   #    CXXFLAGS_JDK  - C++ Compiler flags
 590   #    COMMON_CCXXFLAGS_JDK - common to C and C++
 591   if test "x$TOOLCHAIN_TYPE" = xgcc; then
 592     if test "x$OPENJDK_TARGET_CPU" = xx86; then
 593       # Force compatibility with i586 on 32 bit intel platforms.
 594       COMMON_CCXXFLAGS="${COMMON_CCXXFLAGS} -march=i586"
 595     fi
 596     COMMON_CCXXFLAGS_JDK="$COMMON_CCXXFLAGS $COMMON_CCXXFLAGS_JDK -Wall -Wextra -Wno-unused -Wno-unused-parameter -Wformat=2 \
 597         -pipe -D_GNU_SOURCE -D_REENTRANT -D_LARGEFILE64_SOURCE"
 598     case $OPENJDK_TARGET_CPU_ARCH in
 599       arm )
 600         # on arm we don't prevent gcc to omit frame pointer but do prevent strict aliasing
 601         CFLAGS_JDK="${CFLAGS_JDK} -fno-strict-aliasing"
 602         ;;
 603       ppc )
 604         # on ppc we don't prevent gcc to omit frame pointer but do prevent strict aliasing
 605         CFLAGS_JDK="${CFLAGS_JDK} -fno-strict-aliasing"
 606         ;;
 607       * )
 608         COMMON_CCXXFLAGS_JDK="$COMMON_CCXXFLAGS_JDK -fno-omit-frame-pointer"
 609         CFLAGS_JDK="${CFLAGS_JDK} -fno-strict-aliasing"
 610         ;;
 611     esac
 612   elif test "x$TOOLCHAIN_TYPE" = xclang; then
 613     if test "x$OPENJDK_TARGET_OS" = xlinux; then
 614             if test "x$OPENJDK_TARGET_CPU" = xx86; then
 615               # Force compatibility with i586 on 32 bit intel platforms.
 616               COMMON_CCXXFLAGS="${COMMON_CCXXFLAGS} -march=i586"
 617             fi
 618             COMMON_CCXXFLAGS_JDK="$COMMON_CCXXFLAGS $COMMON_CCXXFLAGS_JDK -Wall -Wextra -Wno-unused -Wno-unused-parameter -Wformat=2 \
 619                 -pipe -D_GNU_SOURCE -D_REENTRANT -D_LARGEFILE64_SOURCE"
 620             case $OPENJDK_TARGET_CPU_ARCH in
 621               ppc )
 622                 # on ppc we don't prevent gcc to omit frame pointer but do prevent strict aliasing
 623                 CFLAGS_JDK="${CFLAGS_JDK} -fno-strict-aliasing"
 624                 ;;
 625               * )
 626                 COMMON_CCXXFLAGS_JDK="$COMMON_CCXXFLAGS_JDK -fno-omit-frame-pointer"
 627                 CFLAGS_JDK="${CFLAGS_JDK} -fno-strict-aliasing"
 628                 ;;
 629             esac
 630     fi
 631   elif test "x$TOOLCHAIN_TYPE" = xsolstudio; then
 632     COMMON_CCXXFLAGS_JDK="$COMMON_CCXXFLAGS $COMMON_CCXXFLAGS_JDK -DTRACING -DMACRO_MEMSYS_OPS -DBREAKPTS"
 633     if test "x$OPENJDK_TARGET_CPU_ARCH" = xx86; then
 634       COMMON_CCXXFLAGS_JDK="$COMMON_CCXXFLAGS_JDK -DcpuIntel -Di586 -D$OPENJDK_TARGET_CPU_LEGACY_LIB"
 635     fi
 636 
 637     CFLAGS_JDK="$CFLAGS_JDK -xc99=%none -xCC -errshort=tags -Xa -v -mt -W0,-noglobal"
 638     CXXFLAGS_JDK="$CXXFLAGS_JDK -errtags=yes +w -mt -features=no%except -DCC_NOEX -norunpath -xnolib"
 639   elif test "x$TOOLCHAIN_TYPE" = xxlc; then
 640     CFLAGS_JDK="$CFLAGS_JDK -D_GNU_SOURCE -D_REENTRANT -D_LARGEFILE64_SOURCE -DSTDC"
 641     CXXFLAGS_JDK="$CXXFLAGS_JDK -D_GNU_SOURCE -D_REENTRANT -D_LARGEFILE64_SOURCE -DSTDC"
 642   elif test "x$TOOLCHAIN_TYPE" = xmicrosoft; then
 643     COMMON_CCXXFLAGS_JDK="$COMMON_CCXXFLAGS $COMMON_CCXXFLAGS_JDK \
 644         -Zi -MD -Zc:wchar_t- -W3 -wd4800 \
 645         -DWIN32_LEAN_AND_MEAN \
 646         -D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE \
 647         -D_WINSOCK_DEPRECATED_NO_WARNINGS \
 648         -DWIN32 -DIAL"
 649     if test "x$OPENJDK_TARGET_CPU" = xx86_64; then
 650       COMMON_CCXXFLAGS_JDK="$COMMON_CCXXFLAGS_JDK -D_AMD64_ -Damd64"
 651     else
 652       COMMON_CCXXFLAGS_JDK="$COMMON_CCXXFLAGS_JDK -D_X86_ -Dx86"
 653     fi
 654     # If building with Visual Studio 2010, we can still use _STATIC_CPPLIB to
 655     # avoid bundling msvcpNNN.dll. Doesn't work with newer versions of visual
 656     # studio.
 657     if test "x$TOOLCHAIN_VERSION" = "x2010"; then
 658       COMMON_CCXXFLAGS_JDK="$COMMON_CCXXFLAGS_JDK \
 659           -D_STATIC_CPPLIB -D_DISABLE_DEPRECATE_STATIC_CPPLIB"
 660     fi
 661   fi
 662 
 663   ###############################################################################
 664 
 665   # Adjust flags according to debug level.
 666   case $DEBUG_LEVEL in
 667     fastdebug | slowdebug )
 668       CFLAGS_JDK="$CFLAGS_JDK $CFLAGS_DEBUG_SYMBOLS $CFLAGS_DEBUG_OPTIONS"
 669       CXXFLAGS_JDK="$CXXFLAGS_JDK $CXXFLAGS_DEBUG_SYMBOLS $CXXFLAGS_DEBUG_OPTIONS"
 670       JAVAC_FLAGS="$JAVAC_FLAGS -g"
 671       ;;
 672     release )
 673       ;;
 674     * )
 675       AC_MSG_ERROR([Unrecognized \$DEBUG_LEVEL: $DEBUG_LEVEL])
 676       ;;
 677   esac
 678 
 679   # Setup LP64
 680   COMMON_CCXXFLAGS_JDK="$COMMON_CCXXFLAGS_JDK $ADD_LP64"
 681 
 682   # Set some common defines. These works for all compilers, but assume
 683   # -D is universally accepted.
 684 
 685   # Setup endianness
 686   if test "x$OPENJDK_TARGET_CPU_ENDIAN" = xlittle; then
 687     # The macro _LITTLE_ENDIAN needs to be defined the same to avoid the
 688     #   Sun C compiler warning message: warning: macro redefined: _LITTLE_ENDIAN
 689     #   (The Solaris X86 system defines this in file /usr/include/sys/isa_defs.h).
 690     #   Note: -Dmacro         is the same as    #define macro 1
 691     #         -Dmacro=        is the same as    #define macro
 692     if test "x$OPENJDK_TARGET_OS" = xsolaris; then
 693       COMMON_CCXXFLAGS_JDK="$COMMON_CCXXFLAGS_JDK -D_LITTLE_ENDIAN="
 694     else
 695       COMMON_CCXXFLAGS_JDK="$COMMON_CCXXFLAGS_JDK -D_LITTLE_ENDIAN"
 696     fi
 697   else
 698     # Same goes for _BIG_ENDIAN. Do we really need to set *ENDIAN on Solaris if they
 699     # are defined in the system?
 700     if test "x$OPENJDK_TARGET_OS" = xsolaris; then
 701       COMMON_CCXXFLAGS_JDK="$COMMON_CCXXFLAGS_JDK -D_BIG_ENDIAN="
 702     else
 703       COMMON_CCXXFLAGS_JDK="$COMMON_CCXXFLAGS_JDK -D_BIG_ENDIAN"
 704     fi
 705   fi
 706 
 707   # Setup target OS define. Use OS target name but in upper case.
 708   OPENJDK_TARGET_OS_UPPERCASE=`$ECHO $OPENJDK_TARGET_OS | $TR 'abcdefghijklmnopqrstuvwxyz' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'`
 709   COMMON_CCXXFLAGS_JDK="$COMMON_CCXXFLAGS_JDK -D$OPENJDK_TARGET_OS_UPPERCASE"
 710 
 711   # Setup target CPU
 712   COMMON_CCXXFLAGS_JDK="$COMMON_CCXXFLAGS_JDK -DARCH='\"$OPENJDK_TARGET_CPU_LEGACY\"' -D$OPENJDK_TARGET_CPU_LEGACY"
 713 
 714   # Setup debug/release defines
 715   if test "x$DEBUG_LEVEL" = xrelease; then
 716     COMMON_CCXXFLAGS_JDK="$COMMON_CCXXFLAGS_JDK -DNDEBUG"
 717     if test "x$OPENJDK_TARGET_OS" = xsolaris; then
 718       COMMON_CCXXFLAGS_JDK="$COMMON_CCXXFLAGS_JDK -DTRIMMED"
 719     fi
 720   else
 721     COMMON_CCXXFLAGS_JDK="$COMMON_CCXXFLAGS_JDK -DDEBUG"
 722   fi
 723 
 724   # Set some additional per-OS defines.
 725   if test "x$OPENJDK_TARGET_OS" = xmacosx; then
 726     COMMON_CCXXFLAGS_JDK="$COMMON_CCXXFLAGS_JDK -D_ALLBSD_SOURCE -D_DARWIN_UNLIMITED_SELECT"
 727   elif test "x$OPENJDK_TARGET_OS" = xaix; then
 728     # FIXME: PPC64 should not be here.
 729     COMMON_CCXXFLAGS_JDK="$COMMON_CCXXFLAGS_JDK -DPPC64"
 730   elif test "x$OPENJDK_TARGET_OS" = xbsd; then
 731     COMMON_CCXXFLAGS_JDK="$COMMON_CCXXFLAGS_JDK -D_ALLBSD_SOURCE"
 732   fi
 733 
 734   # Additional macosx handling
 735   if test "x$OPENJDK_TARGET_OS" = xmacosx; then
 736     # Setting these parameters makes it an error to link to macosx APIs that are
 737     # newer than the given OS version and makes the linked binaries compatible
 738     # even if built on a newer version of the OS.
 739     # The expected format is X.Y.Z
 740     MACOSX_VERSION_MIN=10.7.0
 741     AC_SUBST(MACOSX_VERSION_MIN)
 742 
 743     # The macro takes the version with no dots, ex: 1070
 744     # Let the flags variables get resolved in make for easier override on make
 745     # command line.
 746     COMMON_CCXXFLAGS_JDK="$COMMON_CCXXFLAGS_JDK -DMAC_OS_X_VERSION_MAX_ALLOWED=\$(subst .,,\$(MACOSX_VERSION_MIN)) -mmacosx-version-min=\$(MACOSX_VERSION_MIN)"
 747     LDFLAGS_JDK="$LDFLAGS_JDK -mmacosx-version-min=\$(MACOSX_VERSION_MIN)"
 748   fi
 749 
 750   # Setup some hard coded includes
 751   COMMON_CCXXFLAGS_JDK="$COMMON_CCXXFLAGS_JDK \
 752       -I${JDK_TOPDIR}/src/java.base/share/native/include \
 753       -I${JDK_TOPDIR}/src/java.base/$OPENJDK_TARGET_OS/native/include \
 754       -I${JDK_TOPDIR}/src/java.base/$OPENJDK_TARGET_OS_TYPE/native/include \
 755       -I${JDK_TOPDIR}/src/java.base/share/native/libjava \
 756       -I${JDK_TOPDIR}/src/java.base/$OPENJDK_TARGET_OS_TYPE/native/libjava"
 757 
 758   # The shared libraries are compiled using the picflag.
 759   CFLAGS_JDKLIB="$COMMON_CCXXFLAGS_JDK $CFLAGS_JDK $PICFLAG $CFLAGS_JDKLIB_EXTRA"
 760   CXXFLAGS_JDKLIB="$COMMON_CCXXFLAGS_JDK $CXXFLAGS_JDK $PICFLAG $CXXFLAGS_JDKLIB_EXTRA"
 761 
 762   # Executable flags
 763   CFLAGS_JDKEXE="$COMMON_CCXXFLAGS_JDK $CFLAGS_JDK"
 764   CXXFLAGS_JDKEXE="$COMMON_CCXXFLAGS_JDK $CXXFLAGS_JDK"
 765 
 766   AC_SUBST(CFLAGS_JDKLIB)
 767   AC_SUBST(CFLAGS_JDKEXE)
 768   AC_SUBST(CXXFLAGS_JDKLIB)
 769   AC_SUBST(CXXFLAGS_JDKEXE)
 770 
 771   # Flags for compiling test libraries
 772   CFLAGS_TESTLIB="$COMMON_CCXXFLAGS_JDK $CFLAGS_JDK $PICFLAG $CFLAGS_JDKLIB_EXTRA"
 773   CXXFLAGS_TESTLIB="$COMMON_CCXXFLAGS_JDK $CXXFLAGS_JDK $PICFLAG $CXXFLAGS_JDKLIB_EXTRA"
 774 
 775   # Flags for compiling test executables
 776   CFLAGS_TESTEXE="$COMMON_CCXXFLAGS_JDK $CFLAGS_JDK"
 777   CXXFLAGS_TESTEXE="$COMMON_CCXXFLAGS_JDK $CXXFLAGS_JDK"
 778 
 779   AC_SUBST(CFLAGS_TESTLIB)
 780   AC_SUBST(CFLAGS_TESTEXE)
 781   AC_SUBST(CXXFLAGS_TESTLIB)
 782   AC_SUBST(CXXFLAGS_TESTEXE)
 783 
 784   # Setup LDFLAGS et al.
 785   #
 786 
 787   # Now this is odd. The JDK native libraries have to link against libjvm.so
 788   # On 32-bit machines there is normally two distinct libjvm.so:s, client and server.
 789   # Which should we link to? Are we lucky enough that the binary api to the libjvm.so library
 790   # is identical for client and server? Yes. Which is picked at runtime (client or server)?
 791   # Neither, since the chosen libjvm.so has already been loaded by the launcher, all the following
 792   # libraries will link to whatever is in memory. Yuck.
 793   #
 794   # Thus we offer the compiler to find libjvm.so first in server then in client. It works. Ugh.
 795   if test "x$TOOLCHAIN_TYPE" = xmicrosoft; then
 796     LDFLAGS_JDK="$LDFLAGS_JDK -nologo -opt:ref -incremental:no"
 797     if test "x$OPENJDK_TARGET_CPU_BITS" = "x32"; then
 798       LDFLAGS_JDK="$LDFLAGS_JDK -safeseh"
 799     fi
 800     # TODO: make -debug optional "--disable-full-debug-symbols"
 801     LDFLAGS_JDK="$LDFLAGS_JDK -debug"
 802   elif test "x$TOOLCHAIN_TYPE" = xgcc; then
 803     # If this is a --hash-style=gnu system, use --hash-style=both, why?
 804     # We have previously set HAS_GNU_HASH if this is the case
 805     if test -n "$HAS_GNU_HASH"; then
 806       LDFLAGS_JDK="${LDFLAGS_JDK} -Wl,--hash-style=both"
 807     fi
 808     if test "x$OPENJDK_TARGET_OS" = xlinux; then
 809       # And since we now know that the linker is gnu, then add -z defs, to forbid
 810       # undefined symbols in object files.
 811       LDFLAGS_JDK="${LDFLAGS_JDK} -Wl,-z,defs"
 812       case $DEBUG_LEVEL in
 813         release )
 814           # tell linker to optimize libraries.
 815           # Should this be supplied to the OSS linker as well?
 816           LDFLAGS_JDK="${LDFLAGS_JDK} -Wl,-O1"
 817           ;;
 818         slowdebug )
 819           if test "x$HAS_LINKER_NOW" = "xtrue"; then
 820             # do relocations at load
 821             LDFLAGS_JDK="$LDFLAGS_JDK $LINKER_NOW_FLAG"
 822             LDFLAGS_CXX_JDK="$LDFLAGS_CXX_JDK $LINKER_NOW_FLAG"
 823           fi
 824           if test "x$HAS_LINKER_RELRO" = "xtrue"; then
 825             # mark relocations read only
 826             LDFLAGS_JDK="$LDFLAGS_JDK $LINKER_RELRO_FLAG"
 827             LDFLAGS_CXX_JDK="$LDFLAGS_CXX_JDK $LINKER_RELRO_FLAG"
 828           fi
 829           ;;
 830         fastdebug )
 831           if test "x$HAS_LINKER_RELRO" = "xtrue"; then
 832             # mark relocations read only
 833             LDFLAGS_JDK="$LDFLAGS_JDK $LINKER_RELRO_FLAG"
 834             LDFLAGS_CXX_JDK="$LDFLAGS_CXX_JDK $LINKER_RELRO_FLAG"
 835           fi
 836           ;;
 837         * )
 838           AC_MSG_ERROR([Unrecognized \$DEBUG_LEVEL: $DEBUG_LEVEL])
 839           ;;
 840         esac
 841     fi
 842   elif test "x$TOOLCHAIN_TYPE" = xsolstudio; then
 843     LDFLAGS_JDK="$LDFLAGS_JDK -Wl,-z,defs -xildoff -ztext"
 844     LDFLAGS_CXX_JDK="$LDFLAGS_CXX_JDK -norunpath -xnolib"
 845   elif test "x$TOOLCHAIN_TYPE" = xxlc; then
 846     LDFLAGS_JDK="${LDFLAGS_JDK} -brtl -bnolibpath -bexpall -bernotok"
 847   fi
 848 
 849   # Customize LDFLAGS for executables
 850 
 851   LDFLAGS_JDKEXE="${LDFLAGS_JDK}"
 852 
 853   if test "x$TOOLCHAIN_TYPE" = xmicrosoft; then
 854     if test "x$OPENJDK_TARGET_CPU_BITS" = "x64"; then
 855       LDFLAGS_STACK_SIZE=1048576
 856     else
 857       LDFLAGS_STACK_SIZE=327680
 858     fi
 859     LDFLAGS_JDKEXE="${LDFLAGS_JDKEXE} /STACK:$LDFLAGS_STACK_SIZE"
 860   elif test "x$OPENJDK_TARGET_OS" = xlinux; then
 861     LDFLAGS_JDKEXE="$LDFLAGS_JDKEXE -Wl,--allow-shlib-undefined"
 862   fi
 863 
 864   # Customize LDFLAGS for libs
 865   LDFLAGS_JDKLIB="${LDFLAGS_JDK}"
 866 
 867   LDFLAGS_JDKLIB="${LDFLAGS_JDKLIB} ${SHARED_LIBRARY_FLAGS}"
 868   if test "x$TOOLCHAIN_TYPE" = xmicrosoft; then
 869     LDFLAGS_JDKLIB="${LDFLAGS_JDKLIB} \
 870         -libpath:${OUTPUT_ROOT}/support/modules_libs/java.base"
 871     JDKLIB_LIBS=""
 872   else
 873     LDFLAGS_JDKLIB="${LDFLAGS_JDKLIB} \
 874         -L${OUTPUT_ROOT}/support/modules_libs/java.base${OPENJDK_TARGET_CPU_LIBDIR}"
 875 
 876     # On some platforms (mac) the linker warns about non existing -L dirs.
 877     # Add server first if available. Linking aginst client does not always produce the same results.
 878     # Only add client dir if client is being built. Add minimal (note not minimal1) if only building minimal1.
 879     # Default to server for other variants.
 880     if test "x$JVM_VARIANT_SERVER" = xtrue; then
 881       LDFLAGS_JDKLIB="${LDFLAGS_JDKLIB} -L${OUTPUT_ROOT}/support/modules_libs/java.base${OPENJDK_TARGET_CPU_LIBDIR}/server"
 882     elif test "x$JVM_VARIANT_CLIENT" = xtrue; then
 883       LDFLAGS_JDKLIB="${LDFLAGS_JDKLIB} -L${OUTPUT_ROOT}/support/modules_libs/java.base${OPENJDK_TARGET_CPU_LIBDIR}/client"
 884     elif test "x$JVM_VARIANT_MINIMAL1" = xtrue; then
 885       LDFLAGS_JDKLIB="${LDFLAGS_JDKLIB} -L${OUTPUT_ROOT}/support/modules_libs/java.base${OPENJDK_TARGET_CPU_LIBDIR}/minimal"
 886     else
 887       LDFLAGS_JDKLIB="${LDFLAGS_JDKLIB} -L${OUTPUT_ROOT}/support/modules_libs/java.base${OPENJDK_TARGET_CPU_LIBDIR}/server"
 888     fi
 889 
 890     JDKLIB_LIBS="-ljava -ljvm"
 891     if test "x$TOOLCHAIN_TYPE" = xsolstudio; then
 892       JDKLIB_LIBS="$JDKLIB_LIBS -lc"
 893     fi
 894   fi
 895 
 896   AC_SUBST(LDFLAGS_JDKLIB)
 897   AC_SUBST(LDFLAGS_JDKEXE)
 898   AC_SUBST(JDKLIB_LIBS)
 899   AC_SUBST(JDKEXE_LIBS)
 900   AC_SUBST(LDFLAGS_CXX_JDK)
 901 
 902   LDFLAGS_TESTLIB="$LDFLAGS_JDKLIB"
 903   LDFLAGS_TESTEXE="$LDFLAGS_JDKEXE"
 904 
 905   AC_SUBST(LDFLAGS_TESTLIB)
 906   AC_SUBST(LDFLAGS_TESTEXE)
 907 ])
 908 
 909 # FLAGS_COMPILER_CHECK_ARGUMENTS(ARGUMENT: [ARGUMENT], IF_TRUE: [RUN-IF-TRUE],
 910 #                                   IF_FALSE: [RUN-IF-FALSE])
 911 # ------------------------------------------------------------
 912 # Check that the c and c++ compilers support an argument
 913 BASIC_DEFUN_NAMED([FLAGS_COMPILER_CHECK_ARGUMENTS],
 914     [*ARGUMENT IF_TRUE IF_FALSE], [$@],
 915 [
 916   AC_MSG_CHECKING([if compiler supports "ARG_ARGUMENT"])
 917   supports=yes
 918 
 919   saved_cflags="$CFLAGS"
 920   CFLAGS="$CFLAGS ARG_ARGUMENT"
 921   AC_LANG_PUSH([C])
 922   AC_COMPILE_IFELSE([AC_LANG_SOURCE([[int i;]])], [],
 923       [supports=no])
 924   AC_LANG_POP([C])
 925   CFLAGS="$saved_cflags"
 926 
 927   saved_cxxflags="$CXXFLAGS"
 928   CXXFLAGS="$CXXFLAG ARG_ARGUMENT"
 929   AC_LANG_PUSH([C++])
 930   AC_COMPILE_IFELSE([AC_LANG_SOURCE([[int i;]])], [],
 931       [supports=no])
 932   AC_LANG_POP([C++])
 933   CXXFLAGS="$saved_cxxflags"
 934 
 935   AC_MSG_RESULT([$supports])
 936   if test "x$supports" = "xyes" ; then
 937     :
 938     ARG_IF_TRUE
 939   else
 940     :
 941     ARG_IF_FALSE
 942   fi
 943 ])
 944 
 945 # FLAGS_LINKER_CHECK_ARGUMENTS(ARGUMENT: [ARGUMENT], IF_TRUE: [RUN-IF-TRUE],
 946 #                                   IF_FALSE: [RUN-IF-FALSE])
 947 # ------------------------------------------------------------
 948 # Check that the linker support an argument
 949 BASIC_DEFUN_NAMED([FLAGS_LINKER_CHECK_ARGUMENTS],
 950     [*ARGUMENT IF_TRUE IF_FALSE], [$@],
 951 [
 952   AC_MSG_CHECKING([if linker supports "ARG_ARGUMENT"])
 953   supports=yes
 954 
 955   saved_ldflags="$LDFLAGS"
 956   LDFLAGS="$LDFLAGS ARG_ARGUMENT"
 957   AC_LANG_PUSH([C])
 958   AC_LINK_IFELSE([AC_LANG_PROGRAM([[]],[[]])],
 959       [], [supports=no])
 960   AC_LANG_POP([C])
 961   LDFLAGS="$saved_ldflags"
 962 
 963   AC_MSG_RESULT([$supports])
 964   if test "x$supports" = "xyes" ; then
 965     :
 966     ARG_IF_TRUE
 967   else
 968     :
 969     ARG_IF_FALSE
 970   fi
 971 ])
 972 
 973 AC_DEFUN_ONCE([FLAGS_SETUP_COMPILER_FLAGS_MISC],
 974 [
 975   # Some Zero and Shark settings.
 976   # ZERO_ARCHFLAG tells the compiler which mode to build for
 977   case "${OPENJDK_TARGET_CPU}" in
 978     s390)
 979       ZERO_ARCHFLAG="${COMPILER_TARGET_BITS_FLAG}31"
 980       ;;
 981     *)
 982       ZERO_ARCHFLAG="${COMPILER_TARGET_BITS_FLAG}${OPENJDK_TARGET_CPU_BITS}"
 983   esac
 984   FLAGS_COMPILER_CHECK_ARGUMENTS(ARGUMENT: [$ZERO_ARCHFLAG], IF_FALSE: [ZERO_ARCHFLAG=""])
 985   AC_SUBST(ZERO_ARCHFLAG)
 986 
 987   # Check that the compiler supports -mX (or -qX on AIX) flags
 988   # Set COMPILER_SUPPORTS_TARGET_BITS_FLAG to 'true' if it does
 989   FLAGS_COMPILER_CHECK_ARGUMENTS(ARGUMENT: [${COMPILER_TARGET_BITS_FLAG}${OPENJDK_TARGET_CPU_BITS}],
 990       IF_TRUE: [COMPILER_SUPPORTS_TARGET_BITS_FLAG=true],
 991       IF_FALSE: [COMPILER_SUPPORTS_TARGET_BITS_FLAG=false])
 992   AC_SUBST(COMPILER_SUPPORTS_TARGET_BITS_FLAG)
 993 
 994   AC_ARG_ENABLE([warnings-as-errors], [AS_HELP_STRING([--disable-warnings-as-errors],
 995       [do not consider native warnings to be an error @<:@enabled@:>@])])
 996 
 997   AC_MSG_CHECKING([if native warnings are errors])
 998   if test "x$enable_warnings_as_errors" = "xyes"; then
 999     AC_MSG_RESULT([yes (explicitely set)])
1000     WARNINGS_AS_ERRORS=true
1001   elif test "x$enable_warnings_as_errors" = "xno"; then
1002     AC_MSG_RESULT([no])
1003     WARNINGS_AS_ERRORS=false
1004   elif test "x$enable_warnings_as_errors" = "x"; then
1005     AC_MSG_RESULT([yes (default)])
1006     WARNINGS_AS_ERRORS=true
1007   else
1008     AC_MSG_ERROR([--enable-warnings-as-errors accepts no argument])
1009   fi
1010 
1011   if test "x$WARNINGS_AS_ERRORS" = "xfalse"; then
1012     # Set legacy hotspot variable
1013     HOTSPOT_SET_WARNINGS_AS_ERRORS="WARNINGS_ARE_ERRORS="
1014   else
1015     HOTSPOT_SET_WARNINGS_AS_ERRORS=""
1016   fi
1017 
1018   AC_SUBST(WARNINGS_AS_ERRORS)
1019   AC_SUBST(HOTSPOT_SET_WARNINGS_AS_ERRORS)
1020 
1021   case "${TOOLCHAIN_TYPE}" in
1022     microsoft)
1023       DISABLE_WARNING_PREFIX="-wd"
1024       CFLAGS_WARNINGS_ARE_ERRORS="-WX"
1025       ;;
1026     solstudio)
1027       DISABLE_WARNING_PREFIX="-erroff="
1028       CFLAGS_WARNINGS_ARE_ERRORS="-errtags -errwarn=%all"
1029       ;;
1030     gcc)
1031       # Prior to gcc 4.4, a -Wno-X where X is unknown for that version of gcc will cause an error
1032       FLAGS_COMPILER_CHECK_ARGUMENTS(ARGUMENT: [-Wno-this-is-a-warning-that-do-not-exist],
1033           IF_TRUE: [GCC_CAN_DISABLE_WARNINGS=true],
1034           IF_FALSE: [GCC_CAN_DISABLE_WARNINGS=false]
1035       )
1036       if test "x$GCC_CAN_DISABLE_WARNINGS" = "xtrue"; then
1037         DISABLE_WARNING_PREFIX="-Wno-"
1038       else
1039         DISABLE_WARNING_PREFIX=
1040       fi
1041       CFLAGS_WARNINGS_ARE_ERRORS="-Werror"
1042       # Repeate the check for the BUILD_CC
1043       CC_OLD="$CC"
1044       CC="$BUILD_CC"
1045       FLAGS_COMPILER_CHECK_ARGUMENTS(ARGUMENT: [-Wno-this-is-a-warning-that-do-not-exist],
1046           IF_TRUE: [BUILD_CC_CAN_DISABLE_WARNINGS=true],
1047           IF_FALSE: [BUILD_CC_CAN_DISABLE_WARNINGS=false]
1048       )
1049       if test "x$BUILD_CC_CAN_DISABLE_WARNINGS" = "xtrue"; then
1050         BUILD_CC_DISABLE_WARNING_PREFIX="-Wno-"
1051       else
1052         BUILD_CC_DISABLE_WARNING_PREFIX=
1053       fi
1054       CC="$CC_OLD"
1055       ;;
1056     clang)
1057       DISABLE_WARNING_PREFIX="-Wno-"
1058       CFLAGS_WARNINGS_ARE_ERRORS="-Werror"
1059       ;;
1060   esac
1061   AC_SUBST(DISABLE_WARNING_PREFIX)
1062   AC_SUBST(CFLAGS_WARNINGS_ARE_ERRORS)
1063 ])
--- EOF ---