1 #
   2 # Copyright (c) 2011, 2014, 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$OPENJDK_TARGET_OS" = xsolaris; then
  69     # FIXME: break out into MCSFLAGS
  70     POST_MCS_CMD="$MCS -d -a \"JDK $FULL_VERSION\""
  71   fi
  72   AC_SUBST(POST_MCS_CMD)
  73 
  74   if test "x$TOOLCHAIN_TYPE" = xmicrosoft; then
  75     CC_OUT_OPTION=-Fo
  76     EXE_OUT_OPTION=-out:
  77     LD_OUT_OPTION=-out:
  78     AR_OUT_OPTION=-out:
  79   else
  80     # The option used to specify the target .o,.a or .so file.
  81     # When compiling, how to specify the to be created object file.
  82     CC_OUT_OPTION='-o$(SPACE)'
  83     # When linking, how to specify the to be created executable.
  84     EXE_OUT_OPTION='-o$(SPACE)'
  85     # When linking, how to specify the to be created dynamically linkable library.
  86     LD_OUT_OPTION='-o$(SPACE)'
  87     # When archiving, how to specify the to be create static archive for object files.
  88     AR_OUT_OPTION='rcs$(SPACE)'
  89   fi
  90   AC_SUBST(CC_OUT_OPTION)
  91   AC_SUBST(EXE_OUT_OPTION)
  92   AC_SUBST(LD_OUT_OPTION)
  93   AC_SUBST(AR_OUT_OPTION)
  94 
  95   # On Windows, we need to set RC flags.
  96   if test "x$TOOLCHAIN_TYPE" = xmicrosoft; then
  97     RC_FLAGS="-nologo -l 0x409 -r"
  98     if test "x$VARIANT" = xOPT; then
  99       RC_FLAGS="$RC_FLAGS -d NDEBUG"
 100     fi
 101 
 102     # The version variables used to create RC_FLAGS may be overridden
 103     # in a custom configure script, or possibly the command line.
 104     # Let those variables be expanded at make time in spec.gmk.
 105     # The \$ are escaped to the shell, and the $(...) variables
 106     # are evaluated by make.
 107     RC_FLAGS="$RC_FLAGS \
 108         -d \"JDK_BUILD_ID=\$(FULL_VERSION)\" \
 109         -d \"JDK_COMPANY=\$(COMPANY_NAME)\" \
 110         -d \"JDK_COMPONENT=\$(PRODUCT_NAME) \$(JDK_RC_PLATFORM_NAME) binary\" \
 111         -d \"JDK_VER=\$(JDK_MINOR_VERSION).\$(JDK_MICRO_VERSION).\$(if \$(JDK_UPDATE_VERSION),\$(JDK_UPDATE_VERSION),0).\$(COOKED_BUILD_NUMBER)\" \
 112         -d \"JDK_COPYRIGHT=Copyright \xA9 $COPYRIGHT_YEAR\" \
 113         -d \"JDK_NAME=\$(PRODUCT_NAME) \$(JDK_RC_PLATFORM_NAME) \$(JDK_MINOR_VERSION) \$(JDK_UPDATE_META_TAG)\" \
 114         -d \"JDK_FVER=\$(JDK_MINOR_VERSION),\$(JDK_MICRO_VERSION),\$(if \$(JDK_UPDATE_VERSION),\$(JDK_UPDATE_VERSION),0),\$(COOKED_BUILD_NUMBER)\""
 115   fi
 116   AC_SUBST(RC_FLAGS)
 117 
 118   if test "x$TOOLCHAIN_TYPE" = xmicrosoft; then
 119     # silence copyright notice and other headers.
 120     COMMON_FLAGS="$COMMON_FLAGS -nologo"
 121   fi
 122 ])
 123 
 124 AC_DEFUN_ONCE([FLAGS_SETUP_COMPILER_FLAGS_FOR_LIBS],
 125 [
 126   ###############################################################################
 127   #
 128   # How to compile shared libraries.
 129   #
 130 
 131   if test "x$TOOLCHAIN_TYPE" = xgcc; then
 132     PICFLAG="-fPIC"
 133     C_FLAG_REORDER=''
 134     CXX_FLAG_REORDER=''
 135 
 136     if test "x$OPENJDK_TARGET_OS" = xmacosx; then
 137       # Linking is different on MacOSX
 138       SHARED_LIBRARY_FLAGS="-dynamiclib -compatibility_version 1.0.0 -current_version 1.0.0 $PICFLAG"
 139       SET_EXECUTABLE_ORIGIN='-Xlinker -rpath -Xlinker @loader_path/.'
 140       SET_SHARED_LIBRARY_ORIGIN="$SET_EXECUTABLE_ORIGIN"
 141       SET_SHARED_LIBRARY_NAME='-Xlinker -install_name -Xlinker @rpath/[$]1'
 142       SET_SHARED_LIBRARY_MAPFILE=''
 143     else
 144       # Default works for linux, might work on other platforms as well.
 145       SHARED_LIBRARY_FLAGS='-shared'
 146       SET_EXECUTABLE_ORIGIN='-Xlinker -rpath -Xlinker \$$$$ORIGIN[$]1'
 147       SET_SHARED_LIBRARY_ORIGIN="-Xlinker -z -Xlinker origin $SET_EXECUTABLE_ORIGIN"
 148       SET_SHARED_LIBRARY_NAME='-Xlinker -soname=[$]1'
 149       SET_SHARED_LIBRARY_MAPFILE='-Xlinker -version-script=[$]1'
 150     fi
 151   elif test "x$TOOLCHAIN_TYPE" = xclang; then
 152     PICFLAG=''
 153     C_FLAG_REORDER=''
 154     CXX_FLAG_REORDER=''
 155 
 156     if test "x$OPENJDK_TARGET_OS" = xmacosx; then
 157       # Linking is different on MacOSX
 158       SHARED_LIBRARY_FLAGS="-dynamiclib -compatibility_version 1.0.0 -current_version 1.0.0 $PICFLAG"
 159       SET_EXECUTABLE_ORIGIN='-Xlinker -rpath -Xlinker @loader_path/.'
 160       SET_SHARED_LIBRARY_ORIGIN="$SET_EXECUTABLE_ORIGIN"
 161       SET_SHARED_LIBRARY_NAME='-Xlinker -install_name -Xlinker @rpath/[$]1'
 162       SET_SHARED_LIBRARY_MAPFILE=''
 163     else
 164       # Default works for linux, might work on other platforms as well.
 165       SHARED_LIBRARY_FLAGS='-shared'
 166       SET_EXECUTABLE_ORIGIN='-Xlinker -rpath -Xlinker \$$$$ORIGIN[$]1'
 167       SET_SHARED_LIBRARY_ORIGIN="-Xlinker -z -Xlinker origin $SET_EXECUTABLE_ORIGIN"
 168       SET_SHARED_LIBRARY_NAME='-Xlinker -soname=[$]1'
 169       SET_SHARED_LIBRARY_MAPFILE='-Xlinker -version-script=[$]1'
 170     fi
 171   elif test "x$TOOLCHAIN_TYPE" = xsolstudio; then
 172     PICFLAG="-KPIC"
 173     C_FLAG_REORDER='-xF'
 174     CXX_FLAG_REORDER='-xF'
 175     SHARED_LIBRARY_FLAGS="-G"
 176     SET_EXECUTABLE_ORIGIN='-R\$$$$ORIGIN[$]1'
 177     SET_SHARED_LIBRARY_ORIGIN="$SET_EXECUTABLE_ORIGIN"
 178     SET_SHARED_LIBRARY_NAME=''
 179     SET_SHARED_LIBRARY_MAPFILE='-M[$]1'
 180   elif test "x$TOOLCHAIN_TYPE" = xxlc; then
 181     PICFLAG="-qpic=large"
 182     C_FLAG_REORDER=''
 183     CXX_FLAG_REORDER=''
 184     SHARED_LIBRARY_FLAGS="-qmkshrobj"
 185     SET_EXECUTABLE_ORIGIN=""
 186     SET_SHARED_LIBRARY_ORIGIN=''
 187     SET_SHARED_LIBRARY_NAME=''
 188     SET_SHARED_LIBRARY_MAPFILE=''
 189   elif test "x$TOOLCHAIN_TYPE" = xmicrosoft; then
 190     PICFLAG=""
 191     C_FLAG_REORDER=''
 192     CXX_FLAG_REORDER=''
 193     SHARED_LIBRARY_FLAGS="-LD"
 194     SET_EXECUTABLE_ORIGIN=''
 195     SET_SHARED_LIBRARY_ORIGIN=''
 196     SET_SHARED_LIBRARY_NAME=''
 197     SET_SHARED_LIBRARY_MAPFILE=''
 198   fi
 199 
 200   AC_SUBST(C_FLAG_REORDER)
 201   AC_SUBST(CXX_FLAG_REORDER)
 202   AC_SUBST(SHARED_LIBRARY_FLAGS)
 203   AC_SUBST(SET_EXECUTABLE_ORIGIN)
 204   AC_SUBST(SET_SHARED_LIBRARY_ORIGIN)
 205   AC_SUBST(SET_SHARED_LIBRARY_NAME)
 206   AC_SUBST(SET_SHARED_LIBRARY_MAPFILE)
 207 
 208   if test "x$OPENJDK_TARGET_OS" = xsolaris; then
 209     CFLAGS_JDK="${CFLAGS_JDK} -D__solaris__"
 210     CXXFLAGS_JDK="${CXXFLAGS_JDK} -D__solaris__"
 211     CFLAGS_JDKLIB_EXTRA='-xstrconst'
 212   fi
 213   # The (cross) compiler is now configured, we can now test capabilities
 214   # of the target platform.
 215 ])
 216 
 217 # Documentation on common flags used for solstudio in HIGHEST.
 218 #
 219 # WARNING: Use of OPTIMIZATION_LEVEL=HIGHEST in your Makefile needs to be
 220 #          done with care, there are some assumptions below that need to
 221 #          be understood about the use of pointers, and IEEE behavior.
 222 #
 223 # -fns: Use non-standard floating point mode (not IEEE 754)
 224 # -fsimple: Do some simplification of floating point arithmetic (not IEEE 754)
 225 # -fsingle: Use single precision floating point with 'float'
 226 # -xalias_level=basic: Assume memory references via basic pointer types do not alias
 227 #   (Source with excessing pointer casting and data access with mixed
 228 #    pointer types are not recommended)
 229 # -xbuiltin=%all: Use intrinsic or inline versions for math/std functions
 230 #   (If you expect perfect errno behavior, do not use this)
 231 # -xdepend: Loop data dependency optimizations (need -xO3 or higher)
 232 # -xrestrict: Pointer parameters to functions do not overlap
 233 #   (Similar to -xalias_level=basic usage, but less obvious sometimes.
 234 #    If you pass in multiple pointers to the same data, do not use this)
 235 # -xlibmil: Inline some library routines
 236 #   (If you expect perfect errno behavior, do not use this)
 237 # -xlibmopt: Use optimized math routines (CURRENTLY DISABLED)
 238 #   (If you expect perfect errno behavior, do not use this)
 239 #  Can cause undefined external on Solaris 8 X86 on __sincos, removing for now
 240 
 241     # FIXME: this will never happen since sparc != sparcv9, ie 32 bit, which we don't build anymore.
 242     # Bug?
 243     #if test "x$OPENJDK_TARGET_CPU" = xsparc; then
 244     #  CFLAGS_JDK="${CFLAGS_JDK} -xmemalign=4s"
 245     #  CXXFLAGS_JDK="${CXXFLAGS_JDK} -xmemalign=4s"
 246     #fi
 247 
 248 AC_DEFUN_ONCE([FLAGS_SETUP_COMPILER_FLAGS_FOR_OPTIMIZATION],
 249 [
 250 
 251   ###############################################################################
 252   #
 253   # Setup the opt flags for different compilers
 254   # and different operating systems.
 255   #
 256 
 257   # FIXME: this was indirectly the old default, but just inherited.
 258   # if test "x$TOOLCHAIN_TYPE" = xmicrosoft; then
 259   #   C_FLAG_DEPS="-MMD -MF"
 260   # fi
 261 
 262   # Generate make dependency files
 263   if test "x$TOOLCHAIN_TYPE" = xgcc; then
 264     C_FLAG_DEPS="-MMD -MF"
 265   elif test "x$TOOLCHAIN_TYPE" = xclang; then
 266     C_FLAG_DEPS="-MMD -MF"
 267   elif test "x$TOOLCHAIN_TYPE" = xsolstudio; then
 268     C_FLAG_DEPS="-xMMD -xMF"
 269   elif test "x$TOOLCHAIN_TYPE" = xxlc; then
 270     C_FLAG_DEPS="-qmakedep=gcc -MF"
 271   fi
 272   CXX_FLAG_DEPS="$C_FLAG_DEPS"
 273   AC_SUBST(C_FLAG_DEPS)
 274   AC_SUBST(CXX_FLAG_DEPS)
 275 
 276   # Debug symbols
 277   if test "x$TOOLCHAIN_TYPE" = xgcc; then
 278     if test "x$OPENJDK_TARGET_CPU_BITS" = "x64" && test "x$DEBUG_LEVEL" = "xfastdebug"; then
 279       # reduce from default "-g2" option to save space
 280       CFLAGS_DEBUG_SYMBOLS="-g1"
 281       CXXFLAGS_DEBUG_SYMBOLS="-g1"
 282     else
 283       CFLAGS_DEBUG_SYMBOLS="-g"
 284       CXXFLAGS_DEBUG_SYMBOLS="-g"
 285     fi
 286   elif test "x$TOOLCHAIN_TYPE" = xclang; then
 287     CFLAGS_DEBUG_SYMBOLS="-g"
 288     CXXFLAGS_DEBUG_SYMBOLS="-g"
 289   elif test "x$TOOLCHAIN_TYPE" = xsolstudio; then
 290     CFLAGS_DEBUG_SYMBOLS="-g -xs"
 291     # FIXME: likely a bug, this disables debug symbols rather than enables them
 292     CXXFLAGS_DEBUG_SYMBOLS="-g0 -xs"
 293   elif test "x$TOOLCHAIN_TYPE" = xxlc; then
 294     CFLAGS_DEBUG_SYMBOLS="-g"
 295     CXXFLAGS_DEBUG_SYMBOLS="-g"
 296   fi
 297   AC_SUBST(CFLAGS_DEBUG_SYMBOLS)
 298   AC_SUBST(CXXFLAGS_DEBUG_SYMBOLS)
 299 
 300   # bounds and memory checking options
 301   if test "x$TOOLCHAIN_TYPE" = xgcc; then
 302     case $DEBUG_LEVEL in
 303     release )
 304       # no adjustment
 305       ;;
 306     fastdebug )
 307       # Add compile time bounds checks.
 308       CFLAGS_DEBUG_OPTIONS="-U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1"
 309       CXXFLAGS_DEBUG_OPTIONS="-U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1"
 310       ;;
 311     slowdebug )
 312       # Add runtime bounds checks and symbol info.
 313       CFLAGS_DEBUG_OPTIONS="-U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -fstack-protector-all --param ssp-buffer-size=1"
 314       CXXFLAGS_DEBUG_OPTIONS="-U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -fstack-protector-all --param ssp-buffer-size=1"
 315       ;;
 316     esac
 317   fi
 318   AC_SUBST(CFLAGS_DEBUG_OPTIONS)
 319   AC_SUBST(CXXFLAGS_DEBUG_OPTIONS)
 320 
 321   # Optimization levels
 322   if test "x$TOOLCHAIN_TYPE" = xsolstudio; then
 323     CC_HIGHEST="$CC_HIGHEST -fns -fsimple -fsingle -xbuiltin=%all -xdepend -xrestrict -xlibmil"
 324 
 325     if test "x$OPENJDK_TARGET_CPU_ARCH" = "xx86"; then
 326       # FIXME: seems we always set -xregs=no%frameptr; put it elsewhere more global?
 327       C_O_FLAG_HIGHEST="-xO4 -Wu,-O4~yz $CC_HIGHEST -xalias_level=basic -xregs=no%frameptr"
 328       C_O_FLAG_HI="-xO4 -Wu,-O4~yz -xregs=no%frameptr"
 329       C_O_FLAG_NORM="-xO2 -Wu,-O2~yz -xregs=no%frameptr"
 330       C_O_FLAG_DEBUG="-xregs=no%frameptr"
 331       C_O_FLAG_NONE="-xregs=no%frameptr"
 332       CXX_O_FLAG_HIGHEST="-xO4 -Qoption ube -O4~yz $CC_HIGHEST -xregs=no%frameptr"
 333       CXX_O_FLAG_HI="-xO4 -Qoption ube -O4~yz -xregs=no%frameptr"
 334       CXX_O_FLAG_NORM="-xO2 -Qoption ube -O2~yz -xregs=no%frameptr"
 335       CXX_O_FLAG_DEBUG="-xregs=no%frameptr"
 336       CXX_O_FLAG_NONE="-xregs=no%frameptr"
 337       if test "x$OPENJDK_TARGET_CPU_BITS" = "x32"; then
 338         C_O_FLAG_HIGHEST="$C_O_FLAG_HIGHEST -xchip=pentium"
 339         CXX_O_FLAG_HIGHEST="$CXX_O_FLAG_HIGHEST -xchip=pentium"
 340       fi
 341     elif test "x$OPENJDK_TARGET_CPU_ARCH" = "xsparc"; then
 342       C_O_FLAG_HIGHEST="-xO4 -Wc,-Qrm-s -Wc,-Qiselect-T0 $CC_HIGHEST -xalias_level=basic -xprefetch=auto,explicit -xchip=ultra"
 343       C_O_FLAG_HI="-xO4 -Wc,-Qrm-s -Wc,-Qiselect-T0"
 344       C_O_FLAG_NORM="-xO2 -Wc,-Qrm-s -Wc,-Qiselect-T0"
 345       C_O_FLAG_DEBUG=""
 346       C_O_FLAG_NONE=""
 347       CXX_O_FLAG_HIGHEST="-xO4 -Qoption cg -Qrm-s -Qoption cg -Qiselect-T0 $CC_HIGHEST -xprefetch=auto,explicit -xchip=ultra"
 348       CXX_O_FLAG_HI="-xO4 -Qoption cg -Qrm-s -Qoption cg -Qiselect-T0"
 349       CXX_O_FLAG_NORM="-xO2 -Qoption cg -Qrm-s -Qoption cg -Qiselect-T0"
 350       C_O_FLAG_DEBUG=""
 351       CXX_O_FLAG_NONE=""
 352     fi
 353   else
 354     # The remaining toolchains share opt flags between CC and CXX;
 355     # setup for C and duplicate afterwards.
 356     if test "x$TOOLCHAIN_TYPE" = xgcc; then
 357       if test "x$OPENJDK_TARGET_OS" = xmacosx; then
 358         # On MacOSX we optimize for size, something
 359         # we should do for all platforms?
 360         C_O_FLAG_HIGHEST="-Os"
 361         C_O_FLAG_HI="-Os"
 362         C_O_FLAG_NORM="-Os"
 363       else
 364         C_O_FLAG_HIGHEST="-O3"
 365         C_O_FLAG_HI="-O3"
 366         C_O_FLAG_NORM="-O2"
 367       fi
 368       if test "x$HAS_CFLAG_OPTIMIZE_DEBUG" = "xtrue"; then
 369         C_O_FLAG_DEBUG="-Og"
 370       else
 371         C_O_FLAG_DEBUG="-O0"
 372       fi
 373       C_O_FLAG_NONE="-O0"
 374     elif test "x$TOOLCHAIN_TYPE" = xclang; then
 375       if test "x$OPENJDK_TARGET_OS" = xmacosx; then
 376         # On MacOSX we optimize for size, something
 377         # we should do for all platforms?
 378         C_O_FLAG_HIGHEST="-Os"
 379         C_O_FLAG_HI="-Os"
 380         C_O_FLAG_NORM="-Os"
 381       else
 382         C_O_FLAG_HIGHEST="-O3"
 383         C_O_FLAG_HI="-O3"
 384         C_O_FLAG_NORM="-O2"
 385       fi
 386       C_O_FLAG_DEBUG="-O0"
 387       C_O_FLAG_NONE="-O0"
 388     elif test "x$TOOLCHAIN_TYPE" = xxlc; then
 389       C_O_FLAG_HIGHEST="-O3"
 390       C_O_FLAG_HI="-O3 -qstrict"
 391       C_O_FLAG_NORM="-O2"
 392       C_O_FLAG_DEBUG="-qnoopt"
 393       C_O_FLAG_NONE="-qnoop"
 394     elif test "x$TOOLCHAIN_TYPE" = xmicrosoft; then
 395       C_O_FLAG_HIGHEST="-O2"
 396       C_O_FLAG_HI="-O1"
 397       C_O_FLAG_NORM="-O1"
 398       C_O_FLAG_DEBUG="-Od"
 399       C_O_FLAG_NONE="-Od"
 400     fi
 401     CXX_O_FLAG_HIGHEST="$C_O_FLAG_HIGHEST"
 402     CXX_O_FLAG_HI="$C_O_FLAG_HI"
 403     CXX_O_FLAG_NORM="$C_O_FLAG_NORM"
 404     CXX_O_FLAG_DEBUG="$C_O_FLAG_DEBUG"
 405     CXX_O_FLAG_NONE="$C_O_FLAG_NONE"
 406   fi
 407 
 408   # Adjust optimization flags according to debug level.
 409   case $DEBUG_LEVEL in
 410     release )
 411       # no adjustment
 412       ;;
 413     fastdebug )
 414       # Not quite so much optimization
 415       C_O_FLAG_HIGHEST="$C_O_FLAG_NORM"
 416       C_O_FLAG_HI="$C_O_FLAG_NORM"
 417       CXX_O_FLAG_HIGHEST="$CXX_O_FLAG_NORM"
 418       CXX_O_FLAG_HI="$CXX_O_FLAG_NORM"
 419       ;;
 420     slowdebug )
 421       # Disable optimization
 422       C_O_FLAG_HIGHEST="$C_O_FLAG_DEBUG"
 423       C_O_FLAG_HI="$C_O_FLAG_DEBUG"
 424       C_O_FLAG_NORM="$C_O_FLAG_DEBUG"
 425       CXX_O_FLAG_HIGHEST="$CXX_O_FLAG_DEBUG"
 426       CXX_O_FLAG_HI="$CXX_O_FLAG_DEBUG"
 427       CXX_O_FLAG_NORM="$CXX_O_FLAG_DEBUG"
 428       ;;
 429   esac
 430 
 431   AC_SUBST(C_O_FLAG_HIGHEST)
 432   AC_SUBST(C_O_FLAG_HI)
 433   AC_SUBST(C_O_FLAG_NORM)
 434   AC_SUBST(C_O_FLAG_DEBUG)
 435   AC_SUBST(C_O_FLAG_NONE)
 436   AC_SUBST(CXX_O_FLAG_HIGHEST)
 437   AC_SUBST(CXX_O_FLAG_HI)
 438   AC_SUBST(CXX_O_FLAG_NORM)
 439   AC_SUBST(CXX_O_FLAG_DEBUG)
 440   AC_SUBST(CXX_O_FLAG_NONE)
 441 ])
 442 
 443 AC_DEFUN_ONCE([FLAGS_SETUP_COMPILER_FLAGS_FOR_JDK],
 444 [
 445   # Special extras...
 446   if test "x$TOOLCHAIN_TYPE" = xsolstudio; then
 447     if test "x$OPENJDK_TARGET_CPU_ARCH" = "xsparc"; then
 448       CFLAGS_JDKLIB_EXTRA="${CFLAGS_JDKLIB_EXTRA} -xregs=no%appl"
 449       CXXFLAGS_JDKLIB_EXTRA="${CXXFLAGS_JDKLIB_EXTRA} -xregs=no%appl"
 450     fi
 451   elif test "x$TOOLCHAIN_TYPE" = xxlc; then
 452     LDFLAGS_JDK="${LDFLAGS_JDK} -q64 -brtl -bnolibpath -liconv -bexpall"
 453     CFLAGS_JDK="${CFLAGS_JDK} -qchars=signed -q64 -qfullpath -qsaveopt"
 454     CXXFLAGS_JDK="${CXXFLAGS_JDK} -qchars=signed -q64 -qfullpath -qsaveopt"
 455   fi
 456 
 457   if test "x$CFLAGS" != "x${ADDED_CFLAGS}"; then
 458     AC_MSG_WARN([Ignoring CFLAGS($CFLAGS) found in environment. Use --with-extra-cflags])
 459   fi
 460 
 461   if test "x$CXXFLAGS" != "x${ADDED_CXXFLAGS}"; then
 462     AC_MSG_WARN([Ignoring CXXFLAGS($CXXFLAGS) found in environment. Use --with-extra-cxxflags])
 463   fi
 464 
 465   if test "x$LDFLAGS" != "x${ADDED_LDFLAGS}"; then
 466     AC_MSG_WARN([Ignoring LDFLAGS($LDFLAGS) found in environment. Use --with-extra-ldflags])
 467   fi
 468 
 469   AC_ARG_WITH(extra-cflags, [AS_HELP_STRING([--with-extra-cflags],
 470       [extra flags to be used when compiling jdk c-files])])
 471 
 472   AC_ARG_WITH(extra-cxxflags, [AS_HELP_STRING([--with-extra-cxxflags],
 473       [extra flags to be used when compiling jdk c++-files])])
 474 
 475   AC_ARG_WITH(extra-ldflags, [AS_HELP_STRING([--with-extra-ldflags],
 476       [extra flags to be used when linking jdk])])
 477 
 478   CFLAGS_JDK="${CFLAGS_JDK} $with_extra_cflags"
 479   CXXFLAGS_JDK="${CXXFLAGS_JDK} $with_extra_cxxflags"
 480   LDFLAGS_JDK="${LDFLAGS_JDK} $with_extra_ldflags"
 481 
 482   # Hotspot needs these set in their legacy form
 483   LEGACY_EXTRA_CFLAGS=$with_extra_cflags
 484   LEGACY_EXTRA_CXXFLAGS=$with_extra_cxxflags
 485   LEGACY_EXTRA_LDFLAGS=$with_extra_ldflags
 486 
 487   AC_SUBST(LEGACY_EXTRA_CFLAGS)
 488   AC_SUBST(LEGACY_EXTRA_CXXFLAGS)
 489   AC_SUBST(LEGACY_EXTRA_LDFLAGS)
 490 
 491   ###############################################################################
 492   #
 493   # Now setup the CFLAGS and LDFLAGS for the JDK build.
 494   # Later we will also have CFLAGS and LDFLAGS for the hotspot subrepo build.
 495   #
 496 
 497   # Setup compiler/platform specific flags into
 498   #    CFLAGS_JDK    - C Compiler flags
 499   #    CXXFLAGS_JDK  - C++ Compiler flags
 500   #    COMMON_FLAGS_JDK - common to C and C++
 501   if test "x$TOOLCHAIN_TYPE" = xgcc; then
 502     COMMON_FLAGS_JDK="$COMMON_FLAGS $COMMON_FLAGS_JDK -Wall -Wno-parentheses -Wextra -Wno-unused -Wno-unused-parameter -Wformat=2 \
 503         -pipe -D_GNU_SOURCE -D_REENTRANT -D_LARGEFILE64_SOURCE"
 504     case $OPENJDK_TARGET_CPU_ARCH in
 505       arm )
 506         # on arm we don't prevent gcc to omit frame pointer but do prevent strict aliasing
 507         CFLAGS_JDK="${CFLAGS_JDK} -fno-strict-aliasing"
 508         ;;
 509       ppc )
 510         # on ppc we don't prevent gcc to omit frame pointer nor strict-aliasing
 511         ;;
 512       * )
 513         COMMON_FLAGS_JDK="$COMMON_FLAGS_JDK -fno-omit-frame-pointer"
 514         CFLAGS_JDK="${CFLAGS_JDK} -fno-strict-aliasing"
 515         ;;
 516     esac
 517   elif test "x$TOOLCHAIN_TYPE" = xsolstudio; then
 518     COMMON_FLAGS_JDK="$COMMON_FLAGS $COMMON_FLAGS_JDK -DTRACING -DMACRO_MEMSYS_OPS -DBREAKPTS"
 519     if test "x$OPENJDK_TARGET_CPU_ARCH" = xx86; then
 520       COMMON_FLAGS_JDK="$COMMON_FLAGS_JDK -DcpuIntel -Di586 -D$OPENJDK_TARGET_CPU_LEGACY_LIB"
 521       CFLAGS_JDK="$CFLAGS_JDK -erroff=E_BAD_PRAGMA_PACK_VALUE"
 522     fi
 523   
 524     CFLAGS_JDK="$CFLAGS_JDK -xc99=%none -xCC -errshort=tags -Xa -v -mt -W0,-noglobal"
 525     CXXFLAGS_JDK="$CXXFLAGS_JDK -errtags=yes +w -mt -features=no%except -DCC_NOEX -norunpath -xnolib"
 526   elif test "x$TOOLCHAIN_TYPE" = xxlc; then
 527     CFLAGS_JDK="$CFLAGS_JDK -D_GNU_SOURCE -D_REENTRANT -D_LARGEFILE64_SOURCE -DSTDC"
 528     CXXFLAGS_JDK="$CXXFLAGS_JDK -D_GNU_SOURCE -D_REENTRANT -D_LARGEFILE64_SOURCE -DSTDC"
 529   elif test "x$TOOLCHAIN_TYPE" = xmicrosoft; then
 530     COMMON_FLAGS_JDK="$COMMON_FLAGS $COMMON_FLAGS_JDK -Zi -MD -Zc:wchar_t- -W3 -wd4800 \
 531     -D_STATIC_CPPLIB -D_DISABLE_DEPRECATE_STATIC_CPPLIB -DWIN32_LEAN_AND_MEAN \
 532     -D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE \
 533     -DWIN32 -DIAL"
 534     if test "x$OPENJDK_TARGET_CPU" = xx86_64; then
 535       COMMON_FLAGS_JDK="$COMMON_FLAGS_JDK -D_AMD64_ -Damd64"
 536     else
 537       COMMON_FLAGS_JDK="$COMMON_FLAGS_JDK -D_X86_ -Dx86"
 538     fi
 539   fi
 540 
 541   ###############################################################################
 542 
 543   # Adjust flags according to debug level.
 544   case $DEBUG_LEVEL in
 545     "fastdebug" | "slowdebug" )
 546       CFLAGS_JDK="$CFLAGS_JDK $CFLAGS_DEBUG_SYMBOLS $CFLAGS_DEBUG_OPTIONS"
 547       CXXFLAGS_JDK="$CXXFLAGS_JDK $CXXFLAGS_DEBUG_SYMBOLS $CXXFLAGS_DEBUG_OPTIONS"
 548       JAVAC_FLAGS="$JAVAC_FLAGS -g"
 549       ;;
 550     "release" )
 551       ;;
 552     * )
 553       AC_MSG_ERROR([Unrecognized \$DEBUG_LEVEL: $DEBUG_LEVEL])
 554       ;;
 555   esac
 556 
 557   # Setup LP64
 558   COMMON_FLAGS_JDK="$COMMON_FLAGS_JDK $ADD_LP64"
 559 
 560   # Set some common defines. These works for all compilers, but assume
 561   # -D is universally accepted.
 562 
 563   # Setup endianness
 564   if test "x$OPENJDK_TARGET_CPU_ENDIAN" = xlittle; then
 565     # The macro _LITTLE_ENDIAN needs to be defined the same to avoid the
 566     #   Sun C compiler warning message: warning: macro redefined: _LITTLE_ENDIAN
 567     #   (The Solaris X86 system defines this in file /usr/include/sys/isa_defs.h).
 568     #   Note: -Dmacro         is the same as    #define macro 1
 569     #         -Dmacro=        is the same as    #define macro
 570     if test "x$OPENJDK_TARGET_OS" = xsolaris; then
 571       COMMON_FLAGS_JDK="$COMMON_FLAGS_JDK -D_LITTLE_ENDIAN="
 572     else
 573       COMMON_FLAGS_JDK="$COMMON_FLAGS_JDK -D_LITTLE_ENDIAN"
 574     fi
 575   else
 576     COMMON_FLAGS_JDK="$COMMON_FLAGS_JDK -D_BIG_ENDIAN"
 577   fi
 578   
 579   # Setup target OS define. Use OS target name but in upper case.
 580   OPENJDK_TARGET_OS_UPPERCASE=`$ECHO $OPENJDK_TARGET_OS | $TR 'abcdefghijklmnopqrstuvwxyz' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'`
 581   COMMON_FLAGS_JDK="$COMMON_FLAGS_JDK -D$OPENJDK_TARGET_OS_UPPERCASE"
 582 
 583   # Setup target CPU
 584   COMMON_FLAGS_JDK="$COMMON_FLAGS_JDK -DARCH='\"$OPENJDK_TARGET_CPU_LEGACY\"' -D$OPENJDK_TARGET_CPU_LEGACY"
 585   
 586   # Setup debug/release defines
 587   if test "x$DEBUG_LEVEL" = xrelease; then
 588     COMMON_FLAGS_JDK="$COMMON_FLAGS_JDK -DNDEBUG"
 589     if test "x$OPENJDK_TARGET_OS" = xsolaris; then
 590       COMMON_FLAGS_JDK="$COMMON_FLAGS_JDK -DTRIMMED"
 591     fi
 592   else
 593     COMMON_FLAGS_JDK="$COMMON_FLAGS_JDK -DDEBUG"
 594   fi
 595 
 596 
 597   # Setup release name
 598   COMMON_FLAGS_JDK="$COMMON_FLAGS_JDK -DRELEASE='\"\$(RELEASE)\"'"
 599 
 600 
 601   # Set some additional per-OS defines.
 602   if test "x$OPENJDK_TARGET_OS" = xmacosx; then
 603     COMMON_FLAGS_JDK="$COMMON_FLAGS_JDK -D_ALLBSD_SOURCE -D_DARWIN_UNLIMITED_SELECT"
 604   elif test "x$OPENJDK_TARGET_OS" = xaix; then
 605     # FIXME: PPC64 should not be here.
 606     COMMON_FLAGS_JDK="$COMMON_FLAGS_JDK -DPPC64"
 607   elif test "x$OPENJDK_TARGET_OS" = xbsd; then
 608     COMMON_FLAGS_JDK="$COMMON_FLAGS_JDK -D_ALLBSD_SOURCE"
 609   fi
 610 
 611   # Additional macosx handling
 612   if test "x$OPENJDK_TARGET_OS" = xmacosx; then
 613     if test "x$TOOLCHAIN_TYPE" = xgcc; then
 614       # FIXME: This needs to be exported in spec.gmk due to closed legacy code.
 615       # FIXME: clean this up, and/or move it elsewhere.
 616 
 617       # Setting these parameters makes it an error to link to macosx APIs that are
 618       # newer than the given OS version and makes the linked binaries compatible 
 619       # even if built on a newer version of the OS.
 620       # The expected format is X.Y.Z
 621       MACOSX_VERSION_MIN=10.7.0
 622       AC_SUBST(MACOSX_VERSION_MIN)
 623     
 624       # The macro takes the version with no dots, ex: 1070
 625       # Let the flags variables get resolved in make for easier override on make
 626       # command line.
 627       COMMON_FLAGS_JDK="$COMMON_FLAGS_JDK -DMAC_OS_X_VERSION_MAX_ALLOWED=\$(subst .,,\$(MACOSX_VERSION_MIN)) -mmacosx-version-min=\$(MACOSX_VERSION_MIN)"
 628       LDFLAGS_JDK="$LDFLAGS_JDK -mmacosx-version-min=\$(MACOSX_VERSION_MIN)"
 629     fi
 630   fi
 631 
 632   # Setup some hard coded includes
 633   COMMON_FLAGS_JDK="$COMMON_FLAGS_JDK \
 634       -I${JDK_OUTPUTDIR}/include \
 635       -I${JDK_OUTPUTDIR}/include/$OPENJDK_TARGET_OS \
 636       -I${JDK_TOPDIR}/src/share/javavm/export \
 637       -I${JDK_TOPDIR}/src/$OPENJDK_TARGET_OS_EXPORT_DIR/javavm/export \
 638       -I${JDK_TOPDIR}/src/share/native/common \
 639       -I${JDK_TOPDIR}/src/$OPENJDK_TARGET_OS_API_DIR/native/common"
 640 
 641   # The shared libraries are compiled using the picflag.
 642   CFLAGS_JDKLIB="$COMMON_FLAGS_JDK $CFLAGS_JDK $PICFLAG $CFLAGS_JDKLIB_EXTRA"
 643   CXXFLAGS_JDKLIB="$COMMON_FLAGS_JDK $CXXFLAGS_JDK $PICFLAG $CXXFLAGS_JDKLIB_EXTRA "
 644 
 645   # Executable flags
 646   CFLAGS_JDKEXE="$COMMON_FLAGS_JDK $CFLAGS_JDK"
 647   CXXFLAGS_JDKEXE="$COMMON_FLAGS_JDK $CXXFLAGS_JDK"
 648 
 649   AC_SUBST(CFLAGS_JDKLIB)
 650   AC_SUBST(CFLAGS_JDKEXE)
 651   AC_SUBST(CXXFLAGS_JDKLIB)
 652   AC_SUBST(CXXFLAGS_JDKEXE)
 653 
 654   # Setup LDFLAGS et al.
 655   #
 656   # Now this is odd. The JDK native libraries have to link against libjvm.so
 657   # On 32-bit machines there is normally two distinct libjvm.so:s, client and server.
 658   # Which should we link to? Are we lucky enough that the binary api to the libjvm.so library
 659   # is identical for client and server? Yes. Which is picked at runtime (client or server)?
 660   # Neither, since the chosen libjvm.so has already been loaded by the launcher, all the following
 661   # libraries will link to whatever is in memory. Yuck.
 662   #
 663   # Thus we offer the compiler to find libjvm.so first in server then in client. It works. Ugh.
 664   if test "x$TOOLCHAIN_TYPE" = xmicrosoft; then
 665     LDFLAGS_JDK="$LDFLAGS_JDK -nologo -opt:ref -incremental:no"
 666     if test "x$OPENJDK_TARGET_CPU_BITS" = "x32"; then
 667       LDFLAGS_JDK="$LDFLAGS_JDK -safeseh"
 668     fi
 669     # TODO: make -debug optional "--disable-full-debug-symbols"
 670     LDFLAGS_JDK="$LDFLAGS_JDK -debug"
 671     LDFLAGS_JDKLIB="${LDFLAGS_JDK} -dll -libpath:${JDK_OUTPUTDIR}/lib"
 672     LDFLAGS_JDKLIB_SUFFIX=""
 673     if test "x$OPENJDK_TARGET_CPU_BITS" = "x64"; then
 674       LDFLAGS_STACK_SIZE=1048576
 675     else
 676       LDFLAGS_STACK_SIZE=327680
 677     fi
 678     LDFLAGS_JDKEXE="${LDFLAGS_JDK} /STACK:$LDFLAGS_STACK_SIZE"
 679   elif test "x$TOOLCHAIN_TYPE" = xgcc; then
 680     # If this is a --hash-style=gnu system, use --hash-style=both, why?
 681     # We have previously set HAS_GNU_HASH if this is the case
 682     if test -n "$HAS_GNU_HASH"; then
 683       LDFLAGS_JDK="${LDFLAGS_JDK} -Xlinker --hash-style=both"
 684     fi
 685     if test "x$OPENJDK_TARGET_OS" = xlinux; then
 686       # And since we now know that the linker is gnu, then add -z defs, to forbid
 687       # undefined symbols in object files.
 688       LDFLAGS_JDK="${LDFLAGS_JDK} -Xlinker -z -Xlinker defs"
 689       case $DEBUG_LEVEL in
 690         release )
 691           # tell linker to optimize libraries.
 692           # Should this be supplied to the OSS linker as well?
 693           LDFLAGS_JDK="${LDFLAGS_JDK} -Xlinker -O1"
 694           ;;
 695         slowdebug )
 696           if test "x$HAS_LINKER_RELRO" = "xtrue"; then
 697             # do relocations at load
 698             LDFLAGS_JDK="$LDFLAGS_JDK -Xlinker -z -Xlinker now"
 699             LDFLAGS_CXX_JDK="$LDFLAGS_CXX_JDK -Xlinker -z -Xlinker now"
 700           fi
 701           ;& # FALLSTHROUGH
 702         fastdebug )
 703           if test "x$HAS_LINKER_RELRO" = "xtrue"; then
 704             # mark relocations read only
 705             LDFLAGS_JDK="$LDFLAGS_JDK -Xlinker -z -Xlinker relro"
 706             LDFLAGS_CXX_JDK="$LDFLAGS_CXX_JDK -Xlinker -z -Xlinker relro"
 707           fi
 708           ;;
 709         * )
 710           AC_MSG_ERROR([Unrecognized \$DEBUG_LEVEL: $DEBUG_LEVEL])
 711           ;;
 712         esac
 713     fi
 714 
 715 
 716   elif test "x$TOOLCHAIN_TYPE" = xsolstudio; then
 717     LDFLAGS_JDK="$LDFLAGS_JDK -z defs -xildoff -ztext"
 718     LDFLAGS_CXX_JDK="$LDFLAGS_CXX_JDK -norunpath -xnolib"
 719   fi
 720 
 721   LDFLAGS_JDKLIB="${LDFLAGS_JDK} $SHARED_LIBRARY_FLAGS \
 722       -L${JDK_OUTPUTDIR}/lib${OPENJDK_TARGET_CPU_LIBDIR}"
 723 
 724   # On some platforms (mac) the linker warns about non existing -L dirs.
 725   # Add server first if available. Linking aginst client does not always produce the same results.
 726   # Only add client dir if client is being built. Add minimal (note not minimal1) if only building minimal1.
 727   # Default to server for other variants.
 728   if test "x$JVM_VARIANT_SERVER" = xtrue; then
 729     LDFLAGS_JDKLIB="${LDFLAGS_JDKLIB} -L${JDK_OUTPUTDIR}/lib${OPENJDK_TARGET_CPU_LIBDIR}/server"
 730   elif test "x$JVM_VARIANT_CLIENT" = xtrue; then
 731     LDFLAGS_JDKLIB="${LDFLAGS_JDKLIB} -L${JDK_OUTPUTDIR}/lib${OPENJDK_TARGET_CPU_LIBDIR}/client"
 732   elif test "x$JVM_VARIANT_MINIMAL1" = xtrue; then
 733     LDFLAGS_JDKLIB="${LDFLAGS_JDKLIB} -L${JDK_OUTPUTDIR}/lib${OPENJDK_TARGET_CPU_LIBDIR}/minimal"
 734   else
 735     LDFLAGS_JDKLIB="${LDFLAGS_JDKLIB} -L${JDK_OUTPUTDIR}/lib${OPENJDK_TARGET_CPU_LIBDIR}/server"
 736   fi
 737 
 738   LDFLAGS_JDKLIB_SUFFIX="-ljava -ljvm"
 739   if test "x$TOOLCHAIN_TYPE" = xsolstudio; then
 740     LDFLAGS_JDKLIB_SUFFIX="$LDFLAGS_JDKLIB_SUFFIX -lc"
 741   fi
 742 
 743   LDFLAGS_JDKEXE="${LDFLAGS_JDK}"
 744   if test "x$OPENJDK_TARGET_OS" = xlinux; then
 745     LDFLAGS_JDKEXE="$LDFLAGS_JDKEXE -Xlinker --allow-shlib-undefined"
 746   fi
 747 
 748   AC_SUBST(LDFLAGS_JDKLIB)
 749   AC_SUBST(LDFLAGS_JDKEXE)
 750   AC_SUBST(LDFLAGS_JDKLIB_SUFFIX)
 751   AC_SUBST(LDFLAGS_JDKEXE_SUFFIX)
 752   AC_SUBST(LDFLAGS_CXX_JDK)
 753 ])
 754 
 755 AC_DEFUN_ONCE([FLAGS_SETUP_COMPILER_FLAGS_MISC],
 756 [
 757   # Some Zero and Shark settings.
 758   # ZERO_ARCHFLAG tells the compiler which mode to build for
 759   case "${OPENJDK_TARGET_CPU}" in
 760     s390)
 761       ZERO_ARCHFLAG="${COMPILER_TARGET_BITS_FLAG}31"
 762       ;;
 763     *)
 764       ZERO_ARCHFLAG="${COMPILER_TARGET_BITS_FLAG}${OPENJDK_TARGET_CPU_BITS}"
 765   esac
 766   TOOLCHAIN_COMPILER_CHECK_ARGUMENTS([$ZERO_ARCHFLAG], [], [ZERO_ARCHFLAG=""])
 767   AC_SUBST(ZERO_ARCHFLAG)
 768 
 769   # Check that the compiler supports -mX (or -qX on AIX) flags
 770   # Set COMPILER_SUPPORTS_TARGET_BITS_FLAG to 'true' if it does
 771   TOOLCHAIN_COMPILER_CHECK_ARGUMENTS([${COMPILER_TARGET_BITS_FLAG}${OPENJDK_TARGET_CPU_BITS}],
 772       [COMPILER_SUPPORTS_TARGET_BITS_FLAG=true],
 773       [COMPILER_SUPPORTS_TARGET_BITS_FLAG=false])
 774   AC_SUBST(COMPILER_SUPPORTS_TARGET_BITS_FLAG)
 775 ])