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