flags.m4 41.2 KB
Newer Older
1
#
2
# Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved.
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
#
# This code is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 2 only, as
# published by the Free Software Foundation.  Oracle designates this
# particular file as subject to the "Classpath" exception as provided
# by Oracle in the LICENSE file that accompanied this code.
#
# This code is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
# version 2 for more details (a copy is included in the LICENSE file that
# accompanied this code).
#
# You should have received a copy of the GNU General Public License version
# 2 along with this work; if not, write to the Free Software Foundation,
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
# or visit www.oracle.com if you need additional information or have any
# questions.
#

26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
# Reset the global CFLAGS/LDFLAGS variables and initialize them with the
# corresponding configure arguments instead
AC_DEFUN_ONCE([FLAGS_SETUP_USER_SUPPLIED_FLAGS],
[
  if test "x$CFLAGS" != "x${ADDED_CFLAGS}"; then
    AC_MSG_WARN([Ignoring CFLAGS($CFLAGS) found in environment. Use --with-extra-cflags])
  fi

  if test "x$CXXFLAGS" != "x${ADDED_CXXFLAGS}"; then
    AC_MSG_WARN([Ignoring CXXFLAGS($CXXFLAGS) found in environment. Use --with-extra-cxxflags])
  fi

  if test "x$LDFLAGS" != "x${ADDED_LDFLAGS}"; then
    AC_MSG_WARN([Ignoring LDFLAGS($LDFLAGS) found in environment. Use --with-extra-ldflags])
  fi

  AC_ARG_WITH(extra-cflags, [AS_HELP_STRING([--with-extra-cflags],
      [extra flags to be used when compiling jdk c-files])])

  AC_ARG_WITH(extra-cxxflags, [AS_HELP_STRING([--with-extra-cxxflags],
      [extra flags to be used when compiling jdk c++-files])])

  AC_ARG_WITH(extra-ldflags, [AS_HELP_STRING([--with-extra-ldflags],
      [extra flags to be used when linking jdk])])

  EXTRA_CFLAGS="$with_extra_cflags"
  EXTRA_CXXFLAGS="$with_extra_cxxflags"
  EXTRA_LDFLAGS="$with_extra_ldflags"

  # Hotspot needs these set in their legacy form
  LEGACY_EXTRA_CFLAGS="$LEGACY_EXTRA_CFLAGS $EXTRA_CFLAGS"
  LEGACY_EXTRA_CXXFLAGS="$LEGACY_EXTRA_CXXFLAGS $EXTRA_CXXFLAGS"
  LEGACY_EXTRA_LDFLAGS="$LEGACY_EXTRA_LDFLAGS $EXTRA_LDFLAGS"

  AC_SUBST(LEGACY_EXTRA_CFLAGS)
  AC_SUBST(LEGACY_EXTRA_CXXFLAGS)
  AC_SUBST(LEGACY_EXTRA_LDFLAGS)

  # The global CFLAGS and LDLAGS variables are used by configure tests and
  # should include the extra parameters
  CFLAGS="$EXTRA_CFLAGS"
  CXXFLAGS="$EXTRA_CXXFLAGS"
  LDFLAGS="$EXTRA_LDFLAGS"
  CPPFLAGS=""
])

# Setup the sysroot flags and add them to global CFLAGS and LDFLAGS so
# that configure can use them while detecting compilers.
# TOOLCHAIN_TYPE is available here.
75 76
# Param 1 - Optional prefix to all variables. (e.g BUILD_)
AC_DEFUN([FLAGS_SETUP_SYSROOT_FLAGS],
77
[
78
  if test "x[$]$1SYSROOT" != "x"; then
79 80 81 82
    if test "x$TOOLCHAIN_TYPE" = xsolstudio; then
      if test "x$OPENJDK_TARGET_OS" = xsolaris; then
        # Solaris Studio does not have a concept of sysroot. Instead we must
        # make sure the default include and lib dirs are appended to each
83 84 85
        # compile and link command line. Must also add -I-xbuiltin to enable
        # inlining of system functions and intrinsics.
        $1SYSROOT_CFLAGS="-I-xbuiltin -I[$]$1SYSROOT/usr/include"
86 87 88
        $1SYSROOT_LDFLAGS="-L[$]$1SYSROOT/usr/lib$OPENJDK_TARGET_CPU_ISADIR \
            -L[$]$1SYSROOT/lib$OPENJDK_TARGET_CPU_ISADIR \
            -L[$]$1SYSROOT/usr/ccs/lib$OPENJDK_TARGET_CPU_ISADIR"
89 90
      fi
    elif test "x$TOOLCHAIN_TYPE" = xgcc; then
91 92
      $1SYSROOT_CFLAGS="--sysroot=[$]$1SYSROOT"
      $1SYSROOT_LDFLAGS="--sysroot=[$]$1SYSROOT"
93
    elif test "x$TOOLCHAIN_TYPE" = xclang; then
94 95
      $1SYSROOT_CFLAGS="-isysroot [$]$1SYSROOT"
      $1SYSROOT_LDFLAGS="-isysroot [$]$1SYSROOT"
96 97
    fi
    # Propagate the sysroot args to hotspot
98 99 100
    $1LEGACY_EXTRA_CFLAGS="[$]$1LEGACY_EXTRA_CFLAGS [$]$1SYSROOT_CFLAGS"
    $1LEGACY_EXTRA_CXXFLAGS="[$]$1LEGACY_EXTRA_CXXFLAGS [$]$1SYSROOT_CFLAGS"
    $1LEGACY_EXTRA_LDFLAGS="[$]$1LEGACY_EXTRA_LDFLAGS [$]$1SYSROOT_LDFLAGS"
101
    # The global CFLAGS and LDFLAGS variables need these for configure to function
102 103 104 105
    $1CFLAGS="[$]$1CFLAGS [$]$1SYSROOT_CFLAGS"
    $1CPPFLAGS="[$]$1CPPFLAGS [$]$1SYSROOT_CFLAGS"
    $1CXXFLAGS="[$]$1CXXFLAGS [$]$1SYSROOT_CFLAGS"
    $1LDFLAGS="[$]$1LDFLAGS [$]$1SYSROOT_LDFLAGS"
106 107 108 109
  fi

  if test "x$OPENJDK_TARGET_OS" = xmacosx; then
    # We also need -iframework<path>/System/Library/Frameworks
110 111
    $1SYSROOT_CFLAGS="[$]$1SYSROOT_CFLAGS -iframework [$]$1SYSROOT/System/Library/Frameworks"
    $1SYSROOT_LDFLAGS="[$]$1SYSROOT_LDFLAGS -iframework [$]$1SYSROOT/System/Library/Frameworks"
112 113
    # These always need to be set, or we can't find the frameworks embedded in JavaVM.framework
    # set this here so it doesn't have to be peppered throughout the forest
114 115
    $1SYSROOT_CFLAGS="[$]$1SYSROOT_CFLAGS -F [$]$1SYSROOT/System/Library/Frameworks/JavaVM.framework/Frameworks"
    $1SYSROOT_LDFLAGS="[$]$1SYSROOT_LDFLAGS -F [$]$1SYSROOT/System/Library/Frameworks/JavaVM.framework/Frameworks"
116 117
  fi

118 119
  AC_SUBST($1SYSROOT_CFLAGS)
  AC_SUBST($1SYSROOT_LDFLAGS)
120 121
])

122 123
AC_DEFUN_ONCE([FLAGS_SETUP_INIT_FLAGS],
[
124 125
  # COMPILER_TARGET_BITS_FLAG  : option for selecting 32- or 64-bit output
  # COMPILER_COMMAND_FILE_FLAG : option for passing a command file to the compiler
126 127
  # COMPILER_BINDCMD_FILE_FLAG : option for specifying a file which saves the binder
  #                              commands produced by the link step (currently AIX only)
128 129
  if test "x$TOOLCHAIN_TYPE" = xxlc; then
    COMPILER_TARGET_BITS_FLAG="-q"
130
    COMPILER_COMMAND_FILE_FLAG="-f"
131
    COMPILER_BINDCMD_FILE_FLAG="-bloadmap:"
132 133
  else
    COMPILER_TARGET_BITS_FLAG="-m"
134
    COMPILER_COMMAND_FILE_FLAG="@"
135
    COMPILER_BINDCMD_FILE_FLAG=""
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155

    # The solstudio linker does not support @-files.
    if test "x$TOOLCHAIN_TYPE" = xsolstudio; then
      COMPILER_COMMAND_FILE_FLAG=
    fi

    # Check if @file is supported by gcc
    if test "x$TOOLCHAIN_TYPE" = xgcc; then
      AC_MSG_CHECKING([if @file is supported by gcc])
      # Extra emtpy "" to prevent ECHO from interpreting '--version' as argument
      $ECHO "" "--version" > command.file
      if $CXX @command.file 2>&AS_MESSAGE_LOG_FD >&AS_MESSAGE_LOG_FD; then
        AC_MSG_RESULT(yes)
        COMPILER_COMMAND_FILE_FLAG="@"
      else
        AC_MSG_RESULT(no)
        COMPILER_COMMAND_FILE_FLAG=
      fi
      rm -rf command.file
    fi
156 157
  fi
  AC_SUBST(COMPILER_TARGET_BITS_FLAG)
158
  AC_SUBST(COMPILER_COMMAND_FILE_FLAG)
159
  AC_SUBST(COMPILER_BINDCMD_FILE_FLAG)
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187

  # FIXME: figure out if we should select AR flags depending on OS or toolchain.
  if test "x$OPENJDK_TARGET_OS" = xmacosx; then
    ARFLAGS="-r"
  elif test "x$OPENJDK_TARGET_OS" = xaix; then
    ARFLAGS="-X64"
  elif test "x$OPENJDK_TARGET_OS" = xwindows; then
    # lib.exe is used as AR to create static libraries.
    ARFLAGS="-nologo -NODEFAULTLIB:MSVCRT"
  else
    ARFLAGS=""
  fi
  AC_SUBST(ARFLAGS)

  ## Setup strip.
  # FIXME: should this really be per platform, or should it be per toolchain type?
  # strip is not provided by clang or solstudio; so guessing platform makes most sense.
  # FIXME: we should really only export STRIPFLAGS from here, not POST_STRIP_CMD.
  if test "x$OPENJDK_TARGET_OS" = xlinux; then
    STRIPFLAGS="-g"
  elif test "x$OPENJDK_TARGET_OS" = xsolaris; then
    STRIPFLAGS="-x"
  elif test "x$OPENJDK_TARGET_OS" = xmacosx; then
    STRIPFLAGS="-S"
  elif test "x$OPENJDK_TARGET_OS" = xaix; then
    STRIPFLAGS="-X32_64"
  fi

188
  AC_SUBST(STRIPFLAGS)
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212

  if test "x$TOOLCHAIN_TYPE" = xmicrosoft; then
    CC_OUT_OPTION=-Fo
    EXE_OUT_OPTION=-out:
    LD_OUT_OPTION=-out:
    AR_OUT_OPTION=-out:
  else
    # The option used to specify the target .o,.a or .so file.
    # When compiling, how to specify the to be created object file.
    CC_OUT_OPTION='-o$(SPACE)'
    # When linking, how to specify the to be created executable.
    EXE_OUT_OPTION='-o$(SPACE)'
    # When linking, how to specify the to be created dynamically linkable library.
    LD_OUT_OPTION='-o$(SPACE)'
    # When archiving, how to specify the to be create static archive for object files.
    AR_OUT_OPTION='rcs$(SPACE)'
  fi
  AC_SUBST(CC_OUT_OPTION)
  AC_SUBST(EXE_OUT_OPTION)
  AC_SUBST(LD_OUT_OPTION)
  AC_SUBST(AR_OUT_OPTION)

  # On Windows, we need to set RC flags.
  if test "x$TOOLCHAIN_TYPE" = xmicrosoft; then
213
    RC_FLAGS="-nologo -l0x409"
214
    if test "x$DEBUG_LEVEL" = xrelease; then
215
      RC_FLAGS="$RC_FLAGS -DNDEBUG"
216 217 218 219 220 221 222 223
    fi

    # The version variables used to create RC_FLAGS may be overridden
    # in a custom configure script, or possibly the command line.
    # Let those variables be expanded at make time in spec.gmk.
    # The \$ are escaped to the shell, and the $(...) variables
    # are evaluated by make.
    RC_FLAGS="$RC_FLAGS \
224
        -D\"JDK_VERSION_STRING=\$(VERSION_STRING)\" \
225 226
        -D\"JDK_COMPANY=\$(COMPANY_NAME)\" \
        -D\"JDK_COMPONENT=\$(PRODUCT_NAME) \$(JDK_RC_PLATFORM_NAME) binary\" \
227
        -D\"JDK_VER=\$(VERSION_NUMBER)\" \
228
        -D\"JDK_COPYRIGHT=Copyright \xA9 $COPYRIGHT_YEAR\" \
229 230
        -D\"JDK_NAME=\$(PRODUCT_NAME) \$(JDK_RC_PLATFORM_NAME) \$(VERSION_MAJOR)\" \
        -D\"JDK_FVER=\$(subst .,\$(COMMA),\$(VERSION_NUMBER_FOUR_POSITIONS))\""
231 232 233 234
  fi
  AC_SUBST(RC_FLAGS)

  if test "x$TOOLCHAIN_TYPE" = xmicrosoft; then
235 236
    # silence copyright notice and other headers.
    COMMON_CCXXFLAGS="$COMMON_CCXXFLAGS -nologo"
237 238 239 240 241 242 243 244 245 246 247 248 249 250 251
  fi
])

AC_DEFUN_ONCE([FLAGS_SETUP_COMPILER_FLAGS_FOR_LIBS],
[
  ###############################################################################
  #
  # How to compile shared libraries.
  #

  if test "x$TOOLCHAIN_TYPE" = xgcc; then
    PICFLAG="-fPIC"
    C_FLAG_REORDER=''
    CXX_FLAG_REORDER=''

252 253
    if test "x$OPENJDK_TARGET_OS" = xmacosx; then
      # Linking is different on MacOSX
254 255 256 257 258
      if test "x$STATIC_BUILD" = xtrue; then
        SHARED_LIBRARY_FLAGS ='-undefined dynamic_lookup'
      else
        SHARED_LIBRARY_FLAGS="-dynamiclib -compatibility_version 1.0.0 -current_version 1.0.0 $PICFLAG"
      fi
259
      SET_EXECUTABLE_ORIGIN='-Wl,-rpath,@loader_path/.'
260
      SET_SHARED_LIBRARY_ORIGIN="$SET_EXECUTABLE_ORIGIN"
261
      SET_SHARED_LIBRARY_NAME='-Wl,-install_name,@rpath/[$]1'
262
      SET_SHARED_LIBRARY_MAPFILE='-Wl,-exported_symbols_list,[$]1'
263 264 265
    else
      # Default works for linux, might work on other platforms as well.
      SHARED_LIBRARY_FLAGS='-shared'
266 267 268 269
      SET_EXECUTABLE_ORIGIN='-Wl,-rpath,\$$$$ORIGIN[$]1'
      SET_SHARED_LIBRARY_ORIGIN="-Wl,-z,origin $SET_EXECUTABLE_ORIGIN"
      SET_SHARED_LIBRARY_NAME='-Wl,-soname=[$]1'
      SET_SHARED_LIBRARY_MAPFILE='-Wl,-version-script=[$]1'
270 271 272 273 274
    fi
  elif test "x$TOOLCHAIN_TYPE" = xclang; then
    C_FLAG_REORDER=''
    CXX_FLAG_REORDER=''

275 276
    if test "x$OPENJDK_TARGET_OS" = xmacosx; then
      # Linking is different on MacOSX
277
      PICFLAG=''
278
      SHARED_LIBRARY_FLAGS="-dynamiclib -compatibility_version 1.0.0 -current_version 1.0.0 $PICFLAG"
279
      SET_EXECUTABLE_ORIGIN='-Wl,-rpath,@loader_path/.'
280
      SET_SHARED_LIBRARY_ORIGIN="$SET_EXECUTABLE_ORIGIN"
281
      SET_SHARED_LIBRARY_NAME='-Wl,-install_name,@rpath/[$]1'
282
      SET_SHARED_LIBRARY_MAPFILE='-Wl,-exported_symbols_list,[$]1'
283 284
    else
      # Default works for linux, might work on other platforms as well.
285
      PICFLAG='-fPIC'
286
      SHARED_LIBRARY_FLAGS='-shared'
287 288 289 290
      SET_EXECUTABLE_ORIGIN='-Wl,-rpath,\$$$$ORIGIN[$]1'
      SET_SHARED_LIBRARY_ORIGIN="-Wl,-z,origin $SET_EXECUTABLE_ORIGIN"
      SET_SHARED_LIBRARY_NAME='-Wl,-soname=[$]1'
      SET_SHARED_LIBRARY_MAPFILE='-Wl,-version-script=[$]1'
291 292 293 294 295 296 297 298
    fi
  elif test "x$TOOLCHAIN_TYPE" = xsolstudio; then
    PICFLAG="-KPIC"
    C_FLAG_REORDER='-xF'
    CXX_FLAG_REORDER='-xF'
    SHARED_LIBRARY_FLAGS="-G"
    SET_EXECUTABLE_ORIGIN='-R\$$$$ORIGIN[$]1'
    SET_SHARED_LIBRARY_ORIGIN="$SET_EXECUTABLE_ORIGIN"
299
    SET_SHARED_LIBRARY_NAME='-h [$]1'
300 301
    SET_SHARED_LIBRARY_MAPFILE='-M[$]1'
  elif test "x$TOOLCHAIN_TYPE" = xxlc; then
302 303 304 305 306 307 308 309 310 311 312 313 314 315
    # '-qpic' defaults to 'qpic=small'. This means that the compiler generates only
    # one instruction for accessing the TOC. If the TOC grows larger than 64K, the linker
    # will have to patch this single instruction with a call to some out-of-order code which
    # does the load from the TOC. This is of course slow. But in that case we also would have
    # to use '-bbigtoc' for linking anyway so we could also change the PICFLAG to 'qpic=large'.
    # With 'qpic=large' the compiler will by default generate a two-instruction sequence which
    # can be patched directly by the linker and does not require a jump to out-of-order code.
    # Another alternative instead of using 'qpic=large -bbigtoc' may be to use '-qminimaltoc'
    # instead. This creates a distinct TOC for every compilation unit (and thus requires two
    # loads for accessing a global variable). But there are rumors that this may be seen as a
    # 'performance feature' because of improved code locality of the symbols used in a
    # compilation unit.
    PICFLAG="-qpic"
    JVM_CFLAGS="$JVM_CFLAGS $PICFLAG"
316 317
    C_FLAG_REORDER=''
    CXX_FLAG_REORDER=''
318
    SHARED_LIBRARY_FLAGS="-qmkshrobj -bM:SRE -bnoentry"
319 320 321 322 323 324 325 326
    SET_EXECUTABLE_ORIGIN=""
    SET_SHARED_LIBRARY_ORIGIN=''
    SET_SHARED_LIBRARY_NAME=''
    SET_SHARED_LIBRARY_MAPFILE=''
  elif test "x$TOOLCHAIN_TYPE" = xmicrosoft; then
    PICFLAG=""
    C_FLAG_REORDER=''
    CXX_FLAG_REORDER=''
327
    SHARED_LIBRARY_FLAGS="-dll"
328 329 330
    SET_EXECUTABLE_ORIGIN=''
    SET_SHARED_LIBRARY_ORIGIN=''
    SET_SHARED_LIBRARY_NAME=''
331
    SET_SHARED_LIBRARY_MAPFILE='-def:[$]1'
332 333 334 335 336 337 338 339
  fi

  AC_SUBST(C_FLAG_REORDER)
  AC_SUBST(CXX_FLAG_REORDER)
  AC_SUBST(SET_EXECUTABLE_ORIGIN)
  AC_SUBST(SET_SHARED_LIBRARY_ORIGIN)
  AC_SUBST(SET_SHARED_LIBRARY_NAME)
  AC_SUBST(SET_SHARED_LIBRARY_MAPFILE)
340
  AC_SUBST(SHARED_LIBRARY_FLAGS)
341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398

  if test "x$OPENJDK_TARGET_OS" = xsolaris; then
    CFLAGS_JDK="${CFLAGS_JDK} -D__solaris__"
    CXXFLAGS_JDK="${CXXFLAGS_JDK} -D__solaris__"
    CFLAGS_JDKLIB_EXTRA='-xstrconst'
  fi
  # The (cross) compiler is now configured, we can now test capabilities
  # of the target platform.
])

# Documentation on common flags used for solstudio in HIGHEST.
#
# WARNING: Use of OPTIMIZATION_LEVEL=HIGHEST in your Makefile needs to be
#          done with care, there are some assumptions below that need to
#          be understood about the use of pointers, and IEEE behavior.
#
# -fns: Use non-standard floating point mode (not IEEE 754)
# -fsimple: Do some simplification of floating point arithmetic (not IEEE 754)
# -fsingle: Use single precision floating point with 'float'
# -xalias_level=basic: Assume memory references via basic pointer types do not alias
#   (Source with excessing pointer casting and data access with mixed
#    pointer types are not recommended)
# -xbuiltin=%all: Use intrinsic or inline versions for math/std functions
#   (If you expect perfect errno behavior, do not use this)
# -xdepend: Loop data dependency optimizations (need -xO3 or higher)
# -xrestrict: Pointer parameters to functions do not overlap
#   (Similar to -xalias_level=basic usage, but less obvious sometimes.
#    If you pass in multiple pointers to the same data, do not use this)
# -xlibmil: Inline some library routines
#   (If you expect perfect errno behavior, do not use this)
# -xlibmopt: Use optimized math routines (CURRENTLY DISABLED)
#   (If you expect perfect errno behavior, do not use this)
#  Can cause undefined external on Solaris 8 X86 on __sincos, removing for now

    # FIXME: this will never happen since sparc != sparcv9, ie 32 bit, which we don't build anymore.
    # Bug?
    #if test "x$OPENJDK_TARGET_CPU" = xsparc; then
    #  CFLAGS_JDK="${CFLAGS_JDK} -xmemalign=4s"
    #  CXXFLAGS_JDK="${CXXFLAGS_JDK} -xmemalign=4s"
    #fi

AC_DEFUN_ONCE([FLAGS_SETUP_COMPILER_FLAGS_FOR_OPTIMIZATION],
[

  ###############################################################################
  #
  # Setup the opt flags for different compilers
  # and different operating systems.
  #

  # FIXME: this was indirectly the old default, but just inherited.
  # if test "x$TOOLCHAIN_TYPE" = xmicrosoft; then
  #   C_FLAG_DEPS="-MMD -MF"
  # fi

  # Generate make dependency files
  if test "x$TOOLCHAIN_TYPE" = xgcc; then
    C_FLAG_DEPS="-MMD -MF"
399 400
  elif test "x$TOOLCHAIN_TYPE" = xclang; then
    C_FLAG_DEPS="-MMD -MF"
401 402 403 404 405 406 407 408 409 410 411 412
  elif test "x$TOOLCHAIN_TYPE" = xsolstudio; then
    C_FLAG_DEPS="-xMMD -xMF"
  elif test "x$TOOLCHAIN_TYPE" = xxlc; then
    C_FLAG_DEPS="-qmakedep=gcc -MF"
  fi
  CXX_FLAG_DEPS="$C_FLAG_DEPS"
  AC_SUBST(C_FLAG_DEPS)
  AC_SUBST(CXX_FLAG_DEPS)

  # Debug symbols
  if test "x$TOOLCHAIN_TYPE" = xgcc; then
    if test "x$OPENJDK_TARGET_CPU_BITS" = "x64" && test "x$DEBUG_LEVEL" = "xfastdebug"; then
413
      # reduce from default "-g2" option to save space
414 415 416 417 418 419
      CFLAGS_DEBUG_SYMBOLS="-g1"
      CXXFLAGS_DEBUG_SYMBOLS="-g1"
    else
      CFLAGS_DEBUG_SYMBOLS="-g"
      CXXFLAGS_DEBUG_SYMBOLS="-g"
    fi
420 421 422
  elif test "x$TOOLCHAIN_TYPE" = xclang; then
    CFLAGS_DEBUG_SYMBOLS="-g"
    CXXFLAGS_DEBUG_SYMBOLS="-g"
423 424
  elif test "x$TOOLCHAIN_TYPE" = xsolstudio; then
    CFLAGS_DEBUG_SYMBOLS="-g -xs"
425
    # -g0 enables debug symbols without disabling inlining.
426 427 428 429
    CXXFLAGS_DEBUG_SYMBOLS="-g0 -xs"
  elif test "x$TOOLCHAIN_TYPE" = xxlc; then
    CFLAGS_DEBUG_SYMBOLS="-g"
    CXXFLAGS_DEBUG_SYMBOLS="-g"
430 431 432
  elif test "x$TOOLCHAIN_TYPE" = xmicrosoft; then
    CFLAGS_DEBUG_SYMBOLS="-Zi"
    CXXFLAGS_DEBUG_SYMBOLS="-Zi"
433 434 435 436
  fi
  AC_SUBST(CFLAGS_DEBUG_SYMBOLS)
  AC_SUBST(CXXFLAGS_DEBUG_SYMBOLS)

437 438 439 440 441 442 443
  # bounds, memory and behavior checking options
  if test "x$TOOLCHAIN_TYPE" = xgcc; then
    case $DEBUG_LEVEL in
    release )
      # no adjustment
      ;;
    fastdebug )
444
      # no adjustment
445 446
      ;;
    slowdebug )
447 448 449 450
      # FIXME: By adding this to C(XX)FLAGS_DEBUG_OPTIONS it
      # get's added conditionally on whether we produce debug symbols or not.
      # This is most likely not really correct.

451 452 453
      # Add runtime stack smashing and undefined behavior checks.
      # Not all versions of gcc support -fstack-protector
      STACK_PROTECTOR_CFLAG="-fstack-protector-all"
454
      FLAGS_COMPILER_CHECK_ARGUMENTS(ARGUMENT: [$STACK_PROTECTOR_CFLAG -Werror], IF_FALSE: [STACK_PROTECTOR_CFLAG=""])
455 456 457

      CFLAGS_DEBUG_OPTIONS="$STACK_PROTECTOR_CFLAG --param ssp-buffer-size=1"
      CXXFLAGS_DEBUG_OPTIONS="$STACK_PROTECTOR_CFLAG --param ssp-buffer-size=1"
458 459 460 461
      ;;
    esac
  fi

462 463
  # Optimization levels
  if test "x$TOOLCHAIN_TYPE" = xsolstudio; then
464
    CC_HIGHEST="$CC_HIGHEST -fns -fsimple -fsingle -xbuiltin=%all -xdepend -xrestrict -xlibmil"
465 466 467

    if test "x$OPENJDK_TARGET_CPU_ARCH" = "xx86"; then
      # FIXME: seems we always set -xregs=no%frameptr; put it elsewhere more global?
468
      C_O_FLAG_HIGHEST="-xO4 -Wu,-O4~yz $CC_HIGHEST -xalias_level=basic -xregs=no%frameptr"
469 470
      C_O_FLAG_HI="-xO4 -Wu,-O4~yz -xregs=no%frameptr"
      C_O_FLAG_NORM="-xO2 -Wu,-O2~yz -xregs=no%frameptr"
471
      C_O_FLAG_DEBUG="-xregs=no%frameptr"
472 473 474 475
      C_O_FLAG_NONE="-xregs=no%frameptr"
      CXX_O_FLAG_HIGHEST="-xO4 -Qoption ube -O4~yz $CC_HIGHEST -xregs=no%frameptr"
      CXX_O_FLAG_HI="-xO4 -Qoption ube -O4~yz -xregs=no%frameptr"
      CXX_O_FLAG_NORM="-xO2 -Qoption ube -O2~yz -xregs=no%frameptr"
476
      CXX_O_FLAG_DEBUG="-xregs=no%frameptr"
477 478 479 480 481 482
      CXX_O_FLAG_NONE="-xregs=no%frameptr"
      if test "x$OPENJDK_TARGET_CPU_BITS" = "x32"; then
        C_O_FLAG_HIGHEST="$C_O_FLAG_HIGHEST -xchip=pentium"
        CXX_O_FLAG_HIGHEST="$CXX_O_FLAG_HIGHEST -xchip=pentium"
      fi
    elif test "x$OPENJDK_TARGET_CPU_ARCH" = "xsparc"; then
483
      C_O_FLAG_HIGHEST="-xO4 -Wc,-Qrm-s -Wc,-Qiselect-T0 $CC_HIGHEST -xalias_level=basic -xprefetch=auto,explicit -xchip=ultra"
484 485
      C_O_FLAG_HI="-xO4 -Wc,-Qrm-s -Wc,-Qiselect-T0"
      C_O_FLAG_NORM="-xO2 -Wc,-Qrm-s -Wc,-Qiselect-T0"
486
      C_O_FLAG_DEBUG=""
487 488 489 490
      C_O_FLAG_NONE=""
      CXX_O_FLAG_HIGHEST="-xO4 -Qoption cg -Qrm-s -Qoption cg -Qiselect-T0 $CC_HIGHEST -xprefetch=auto,explicit -xchip=ultra"
      CXX_O_FLAG_HI="-xO4 -Qoption cg -Qrm-s -Qoption cg -Qiselect-T0"
      CXX_O_FLAG_NORM="-xO2 -Qoption cg -Qrm-s -Qoption cg -Qiselect-T0"
491
      CXX_O_FLAG_DEBUG=""
492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508
      CXX_O_FLAG_NONE=""
    fi
  else
    # The remaining toolchains share opt flags between CC and CXX;
    # setup for C and duplicate afterwards.
    if test "x$TOOLCHAIN_TYPE" = xgcc; then
      if test "x$OPENJDK_TARGET_OS" = xmacosx; then
        # On MacOSX we optimize for size, something
        # we should do for all platforms?
        C_O_FLAG_HIGHEST="-Os"
        C_O_FLAG_HI="-Os"
        C_O_FLAG_NORM="-Os"
      else
        C_O_FLAG_HIGHEST="-O3"
        C_O_FLAG_HI="-O3"
        C_O_FLAG_NORM="-O2"
      fi
M
mduigou 已提交
509
      C_O_FLAG_DEBUG="-O0"
510
      C_O_FLAG_NONE="-O0"
511 512 513 514 515 516 517 518 519 520 521 522
    elif test "x$TOOLCHAIN_TYPE" = xclang; then
      if test "x$OPENJDK_TARGET_OS" = xmacosx; then
        # On MacOSX we optimize for size, something
        # we should do for all platforms?
        C_O_FLAG_HIGHEST="-Os"
        C_O_FLAG_HI="-Os"
        C_O_FLAG_NORM="-Os"
      else
        C_O_FLAG_HIGHEST="-O3"
        C_O_FLAG_HI="-O3"
        C_O_FLAG_NORM="-O2"
      fi
523 524
      C_O_FLAG_DEBUG="-O0"
      C_O_FLAG_NONE="-O0"
525 526 527 528
    elif test "x$TOOLCHAIN_TYPE" = xxlc; then
      C_O_FLAG_HIGHEST="-O3"
      C_O_FLAG_HI="-O3 -qstrict"
      C_O_FLAG_NORM="-O2"
529
      C_O_FLAG_DEBUG="-qnoopt"
530
      C_O_FLAG_NONE="-qnoopt"
531 532 533 534
    elif test "x$TOOLCHAIN_TYPE" = xmicrosoft; then
      C_O_FLAG_HIGHEST="-O2"
      C_O_FLAG_HI="-O1"
      C_O_FLAG_NORM="-O1"
535
      C_O_FLAG_DEBUG="-Od"
536 537 538 539 540
      C_O_FLAG_NONE="-Od"
    fi
    CXX_O_FLAG_HIGHEST="$C_O_FLAG_HIGHEST"
    CXX_O_FLAG_HI="$C_O_FLAG_HI"
    CXX_O_FLAG_NORM="$C_O_FLAG_NORM"
541
    CXX_O_FLAG_DEBUG="$C_O_FLAG_DEBUG"
542 543 544
    CXX_O_FLAG_NONE="$C_O_FLAG_NONE"
  fi

545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565
  # Adjust optimization flags according to debug level.
  case $DEBUG_LEVEL in
    release )
      # no adjustment
      ;;
    fastdebug )
      # Not quite so much optimization
      C_O_FLAG_HI="$C_O_FLAG_NORM"
      CXX_O_FLAG_HI="$CXX_O_FLAG_NORM"
      ;;
    slowdebug )
      # Disable optimization
      C_O_FLAG_HIGHEST="$C_O_FLAG_DEBUG"
      C_O_FLAG_HI="$C_O_FLAG_DEBUG"
      C_O_FLAG_NORM="$C_O_FLAG_DEBUG"
      CXX_O_FLAG_HIGHEST="$CXX_O_FLAG_DEBUG"
      CXX_O_FLAG_HI="$CXX_O_FLAG_DEBUG"
      CXX_O_FLAG_NORM="$CXX_O_FLAG_DEBUG"
      ;;
  esac

566 567 568
  AC_SUBST(C_O_FLAG_HIGHEST)
  AC_SUBST(C_O_FLAG_HI)
  AC_SUBST(C_O_FLAG_NORM)
569
  AC_SUBST(C_O_FLAG_DEBUG)
570 571 572 573
  AC_SUBST(C_O_FLAG_NONE)
  AC_SUBST(CXX_O_FLAG_HIGHEST)
  AC_SUBST(CXX_O_FLAG_HI)
  AC_SUBST(CXX_O_FLAG_NORM)
574
  AC_SUBST(CXX_O_FLAG_DEBUG)
575 576 577 578 579 580 581 582 583 584 585
  AC_SUBST(CXX_O_FLAG_NONE)
])

AC_DEFUN_ONCE([FLAGS_SETUP_COMPILER_FLAGS_FOR_JDK],
[
  # Special extras...
  if test "x$TOOLCHAIN_TYPE" = xsolstudio; then
    if test "x$OPENJDK_TARGET_CPU_ARCH" = "xsparc"; then
      CFLAGS_JDKLIB_EXTRA="${CFLAGS_JDKLIB_EXTRA} -xregs=no%appl"
      CXXFLAGS_JDKLIB_EXTRA="${CXXFLAGS_JDKLIB_EXTRA} -xregs=no%appl"
    fi
586 587
    CFLAGS_JDKLIB_EXTRA="${CFLAGS_JDKLIB_EXTRA} -errtags=yes -errfmt"
    CXXFLAGS_JDKLIB_EXTRA="${CXXFLAGS_JDKLIB_EXTRA} -errtags=yes -errfmt"
588
  elif test "x$TOOLCHAIN_TYPE" = xxlc; then
589 590
    CFLAGS_JDK="${CFLAGS_JDK} -qchars=signed -qfullpath -qsaveopt"
    CXXFLAGS_JDK="${CXXFLAGS_JDK} -qchars=signed -qfullpath -qsaveopt"
591 592
  fi

593 594 595
  CFLAGS_JDK="${CFLAGS_JDK} $EXTRA_CFLAGS"
  CXXFLAGS_JDK="${CXXFLAGS_JDK} $EXTRA_CXXFLAGS"
  LDFLAGS_JDK="${LDFLAGS_JDK} $EXTRA_LDFLAGS"
596 597 598 599 600 601 602

  ###############################################################################
  #
  # Now setup the CFLAGS and LDFLAGS for the JDK build.
  # Later we will also have CFLAGS and LDFLAGS for the hotspot subrepo build.
  #

603 604 605 606
  # Setup compiler/platform specific flags into
  #    CFLAGS_JDK    - C Compiler flags
  #    CXXFLAGS_JDK  - C++ Compiler flags
  #    COMMON_CCXXFLAGS_JDK - common to C and C++
607
  if test "x$TOOLCHAIN_TYPE" = xgcc; then
608 609 610 611
    if test "x$OPENJDK_TARGET_CPU" = xx86; then
      # Force compatibility with i586 on 32 bit intel platforms.
      COMMON_CCXXFLAGS="${COMMON_CCXXFLAGS} -march=i586"
    fi
612
    COMMON_CCXXFLAGS_JDK="$COMMON_CCXXFLAGS $COMMON_CCXXFLAGS_JDK -Wall -Wextra -Wno-unused -Wno-unused-parameter -Wformat=2 \
613 614 615 616 617 618 619
        -pipe -D_GNU_SOURCE -D_REENTRANT -D_LARGEFILE64_SOURCE"
    case $OPENJDK_TARGET_CPU_ARCH in
      arm )
        # on arm we don't prevent gcc to omit frame pointer but do prevent strict aliasing
        CFLAGS_JDK="${CFLAGS_JDK} -fno-strict-aliasing"
        ;;
      ppc )
620 621
        # on ppc we don't prevent gcc to omit frame pointer but do prevent strict aliasing
        CFLAGS_JDK="${CFLAGS_JDK} -fno-strict-aliasing"
622 623
        ;;
      * )
624
        COMMON_CCXXFLAGS_JDK="$COMMON_CCXXFLAGS_JDK -fno-omit-frame-pointer"
625 626 627
        CFLAGS_JDK="${CFLAGS_JDK} -fno-strict-aliasing"
        ;;
    esac
628 629
  elif test "x$TOOLCHAIN_TYPE" = xclang; then
    if test "x$OPENJDK_TARGET_OS" = xlinux; then
630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645
      if test "x$OPENJDK_TARGET_CPU" = xx86; then
        # Force compatibility with i586 on 32 bit intel platforms.
        COMMON_CCXXFLAGS="${COMMON_CCXXFLAGS} -march=i586"
      fi
      COMMON_CCXXFLAGS_JDK="$COMMON_CCXXFLAGS $COMMON_CCXXFLAGS_JDK -Wall -Wextra -Wno-unused -Wno-unused-parameter -Wformat=2 \
          -pipe -D_GNU_SOURCE -D_REENTRANT -D_LARGEFILE64_SOURCE"
      case $OPENJDK_TARGET_CPU_ARCH in
        ppc )
          # on ppc we don't prevent gcc to omit frame pointer but do prevent strict aliasing
          CFLAGS_JDK="${CFLAGS_JDK} -fno-strict-aliasing"
          ;;
        * )
          COMMON_CCXXFLAGS_JDK="$COMMON_CCXXFLAGS_JDK -fno-omit-frame-pointer"
          CFLAGS_JDK="${CFLAGS_JDK} -fno-strict-aliasing"
          ;;
      esac
646
    fi
647
  elif test "x$TOOLCHAIN_TYPE" = xsolstudio; then
648
    COMMON_CCXXFLAGS_JDK="$COMMON_CCXXFLAGS $COMMON_CCXXFLAGS_JDK -DTRACING -DMACRO_MEMSYS_OPS -DBREAKPTS"
649
    if test "x$OPENJDK_TARGET_CPU_ARCH" = xx86; then
650
      COMMON_CCXXFLAGS_JDK="$COMMON_CCXXFLAGS_JDK -DcpuIntel -Di586 -D$OPENJDK_TARGET_CPU_LEGACY_LIB"
651
    fi
652

653 654 655 656 657 658
    CFLAGS_JDK="$CFLAGS_JDK -xc99=%none -xCC -errshort=tags -Xa -v -mt -W0,-noglobal"
    CXXFLAGS_JDK="$CXXFLAGS_JDK -errtags=yes +w -mt -features=no%except -DCC_NOEX -norunpath -xnolib"
  elif test "x$TOOLCHAIN_TYPE" = xxlc; then
    CFLAGS_JDK="$CFLAGS_JDK -D_GNU_SOURCE -D_REENTRANT -D_LARGEFILE64_SOURCE -DSTDC"
    CXXFLAGS_JDK="$CXXFLAGS_JDK -D_GNU_SOURCE -D_REENTRANT -D_LARGEFILE64_SOURCE -DSTDC"
  elif test "x$TOOLCHAIN_TYPE" = xmicrosoft; then
659
    COMMON_CCXXFLAGS_JDK="$COMMON_CCXXFLAGS $COMMON_CCXXFLAGS_JDK \
660
        -MD -Zc:wchar_t- -W3 -wd4800 \
661 662
        -DWIN32_LEAN_AND_MEAN \
        -D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE \
663
        -D_WINSOCK_DEPRECATED_NO_WARNINGS \
664
        -DWIN32 -DIAL"
665
    if test "x$OPENJDK_TARGET_CPU" = xx86_64; then
666
      COMMON_CCXXFLAGS_JDK="$COMMON_CCXXFLAGS_JDK -D_AMD64_ -Damd64"
667
    else
668
      COMMON_CCXXFLAGS_JDK="$COMMON_CCXXFLAGS_JDK -D_X86_ -Dx86"
669
    fi
670 671 672 673
    # If building with Visual Studio 2010, we can still use _STATIC_CPPLIB to
    # avoid bundling msvcpNNN.dll. Doesn't work with newer versions of visual
    # studio.
    if test "x$TOOLCHAIN_VERSION" = "x2010"; then
674 675
      STATIC_CPPLIB_FLAGS="-D_STATIC_CPPLIB -D_DISABLE_DEPRECATE_STATIC_CPPLIB"
      COMMON_CCXXFLAGS_JDK="$COMMON_CCXXFLAGS_JDK $STATIC_CPPLIB_FLAGS"
676
    fi
677 678 679 680 681 682
  fi

  ###############################################################################

  # Adjust flags according to debug level.
  case $DEBUG_LEVEL in
683 684 685
    fastdebug | slowdebug )
      CFLAGS_JDK="$CFLAGS_JDK $CFLAGS_DEBUG_SYMBOLS $CFLAGS_DEBUG_OPTIONS"
      CXXFLAGS_JDK="$CXXFLAGS_JDK $CXXFLAGS_DEBUG_SYMBOLS $CXXFLAGS_DEBUG_OPTIONS"
686 687
      JAVAC_FLAGS="$JAVAC_FLAGS -g"
      ;;
688 689 690 691
    release )
      ;;
    * )
      AC_MSG_ERROR([Unrecognized \$DEBUG_LEVEL: $DEBUG_LEVEL])
692 693 694 695
      ;;
  esac

  # Setup LP64
696
  COMMON_CCXXFLAGS_JDK="$COMMON_CCXXFLAGS_JDK $ADD_LP64"
697 698 699 700 701 702 703 704 705 706 707 708

  # Set some common defines. These works for all compilers, but assume
  # -D is universally accepted.

  # Setup endianness
  if test "x$OPENJDK_TARGET_CPU_ENDIAN" = xlittle; then
    # The macro _LITTLE_ENDIAN needs to be defined the same to avoid the
    #   Sun C compiler warning message: warning: macro redefined: _LITTLE_ENDIAN
    #   (The Solaris X86 system defines this in file /usr/include/sys/isa_defs.h).
    #   Note: -Dmacro         is the same as    #define macro 1
    #         -Dmacro=        is the same as    #define macro
    if test "x$OPENJDK_TARGET_OS" = xsolaris; then
709
      COMMON_CCXXFLAGS_JDK="$COMMON_CCXXFLAGS_JDK -D_LITTLE_ENDIAN="
710
    else
711
      COMMON_CCXXFLAGS_JDK="$COMMON_CCXXFLAGS_JDK -D_LITTLE_ENDIAN"
712 713
    fi
  else
714 715 716
    # Same goes for _BIG_ENDIAN. Do we really need to set *ENDIAN on Solaris if they
    # are defined in the system?
    if test "x$OPENJDK_TARGET_OS" = xsolaris; then
717
      COMMON_CCXXFLAGS_JDK="$COMMON_CCXXFLAGS_JDK -D_BIG_ENDIAN="
718
    else
719
      COMMON_CCXXFLAGS_JDK="$COMMON_CCXXFLAGS_JDK -D_BIG_ENDIAN"
720
    fi
721
  fi
722

723 724
  # Setup target OS define. Use OS target name but in upper case.
  OPENJDK_TARGET_OS_UPPERCASE=`$ECHO $OPENJDK_TARGET_OS | $TR 'abcdefghijklmnopqrstuvwxyz' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'`
725
  COMMON_CCXXFLAGS_JDK="$COMMON_CCXXFLAGS_JDK -D$OPENJDK_TARGET_OS_UPPERCASE"
726 727

  # Setup target CPU
728 729
  COMMON_CCXXFLAGS_JDK="$COMMON_CCXXFLAGS_JDK -DARCH='\"$OPENJDK_TARGET_CPU_LEGACY\"' -D$OPENJDK_TARGET_CPU_LEGACY"

730 731
  # Setup debug/release defines
  if test "x$DEBUG_LEVEL" = xrelease; then
732
    COMMON_CCXXFLAGS_JDK="$COMMON_CCXXFLAGS_JDK -DNDEBUG"
733
    if test "x$OPENJDK_TARGET_OS" = xsolaris; then
734
      COMMON_CCXXFLAGS_JDK="$COMMON_CCXXFLAGS_JDK -DTRIMMED"
735 736
    fi
  else
737
    COMMON_CCXXFLAGS_JDK="$COMMON_CCXXFLAGS_JDK -DDEBUG"
738 739 740 741
  fi

  # Set some additional per-OS defines.
  if test "x$OPENJDK_TARGET_OS" = xmacosx; then
742
    COMMON_CCXXFLAGS_JDK="$COMMON_CCXXFLAGS_JDK -D_ALLBSD_SOURCE -D_DARWIN_UNLIMITED_SELECT"
743
  elif test "x$OPENJDK_TARGET_OS" = xbsd; then
744
    COMMON_CCXXFLAGS_JDK="$COMMON_CCXXFLAGS_JDK -D_ALLBSD_SOURCE"
745 746 747 748
  fi

  # Additional macosx handling
  if test "x$OPENJDK_TARGET_OS" = xmacosx; then
749 750 751 752 753 754 755 756 757 758 759 760
    # Setting these parameters makes it an error to link to macosx APIs that are
    # newer than the given OS version and makes the linked binaries compatible
    # even if built on a newer version of the OS.
    # The expected format is X.Y.Z
    MACOSX_VERSION_MIN=10.7.0
    AC_SUBST(MACOSX_VERSION_MIN)

    # The macro takes the version with no dots, ex: 1070
    # Let the flags variables get resolved in make for easier override on make
    # command line.
    COMMON_CCXXFLAGS_JDK="$COMMON_CCXXFLAGS_JDK -DMAC_OS_X_VERSION_MAX_ALLOWED=\$(subst .,,\$(MACOSX_VERSION_MIN)) -mmacosx-version-min=\$(MACOSX_VERSION_MIN)"
    LDFLAGS_JDK="$LDFLAGS_JDK -mmacosx-version-min=\$(MACOSX_VERSION_MIN)"
761 762 763
  fi

  # Setup some hard coded includes
764
  COMMON_CCXXFLAGS_JDK="$COMMON_CCXXFLAGS_JDK \
C
chegar 已提交
765 766
      -I${JDK_TOPDIR}/src/java.base/share/native/include \
      -I${JDK_TOPDIR}/src/java.base/$OPENJDK_TARGET_OS/native/include \
767
      -I${JDK_TOPDIR}/src/java.base/$OPENJDK_TARGET_OS_TYPE/native/include \
768
      -I${JDK_TOPDIR}/src/java.base/share/native/libjava \
769
      -I${JDK_TOPDIR}/src/java.base/$OPENJDK_TARGET_OS_TYPE/native/libjava"
770 771

  # The shared libraries are compiled using the picflag.
772
  CFLAGS_JDKLIB="$COMMON_CCXXFLAGS_JDK $CFLAGS_JDK $PICFLAG $CFLAGS_JDKLIB_EXTRA"
773
  CXXFLAGS_JDKLIB="$COMMON_CCXXFLAGS_JDK $CXXFLAGS_JDK $PICFLAG $CXXFLAGS_JDKLIB_EXTRA"
774 775

  # Executable flags
776 777
  CFLAGS_JDKEXE="$COMMON_CCXXFLAGS_JDK $CFLAGS_JDK"
  CXXFLAGS_JDKEXE="$COMMON_CCXXFLAGS_JDK $CXXFLAGS_JDK"
778 779 780 781 782 783

  AC_SUBST(CFLAGS_JDKLIB)
  AC_SUBST(CFLAGS_JDKEXE)
  AC_SUBST(CXXFLAGS_JDKLIB)
  AC_SUBST(CXXFLAGS_JDKEXE)

784 785 786 787 788 789 790 791 792 793 794 795 796
  # Flags for compiling test libraries
  CFLAGS_TESTLIB="$COMMON_CCXXFLAGS_JDK $CFLAGS_JDK $PICFLAG $CFLAGS_JDKLIB_EXTRA"
  CXXFLAGS_TESTLIB="$COMMON_CCXXFLAGS_JDK $CXXFLAGS_JDK $PICFLAG $CXXFLAGS_JDKLIB_EXTRA"

  # Flags for compiling test executables
  CFLAGS_TESTEXE="$COMMON_CCXXFLAGS_JDK $CFLAGS_JDK"
  CXXFLAGS_TESTEXE="$COMMON_CCXXFLAGS_JDK $CXXFLAGS_JDK"

  AC_SUBST(CFLAGS_TESTLIB)
  AC_SUBST(CFLAGS_TESTEXE)
  AC_SUBST(CXXFLAGS_TESTLIB)
  AC_SUBST(CXXFLAGS_TESTEXE)

797 798
  # Setup LDFLAGS et al.
  #
799

800
  if test "x$TOOLCHAIN_TYPE" = xmicrosoft; then
801 802
    LDFLAGS_MICROSOFT="-nologo -opt:ref"
    LDFLAGS_JDK="$LDFLAGS_JDK $LDFLAGS_MICROSOFT -incremental:no"
803
    if test "x$OPENJDK_TARGET_CPU_BITS" = "x32"; then
804 805
      LDFLAGS_SAFESH="-safeseh"
      LDFLAGS_JDK="$LDFLAGS_JDK $LDFLAGS_SAFESH"
806
    fi
807 808 809 810
  elif test "x$TOOLCHAIN_TYPE" = xgcc; then
    # If this is a --hash-style=gnu system, use --hash-style=both, why?
    # We have previously set HAS_GNU_HASH if this is the case
    if test -n "$HAS_GNU_HASH"; then
811 812
      LDFLAGS_HASH_STYLE="-Wl,--hash-style=both"
      LDFLAGS_JDK="${LDFLAGS_JDK} $LDFLAGS_HASH_STYLE"
813
    fi
814 815 816
    if test "x$OPENJDK_TARGET_OS" = xlinux; then
      # And since we now know that the linker is gnu, then add -z defs, to forbid
      # undefined symbols in object files.
817 818
      LDFLAGS_NO_UNDEF_SYM="-Wl,-z,defs"
      LDFLAGS_JDK="${LDFLAGS_JDK} $LDFLAGS_NO_UNDEF_SYM"
819 820 821
      case $DEBUG_LEVEL in
        release )
          # tell linker to optimize libraries.
822
          # Should this be supplied to the OSS linker as well?
823 824
          LDFLAGS_DEBUGLEVEL_release="-Wl,-O1"
          LDFLAGS_JDK="${LDFLAGS_JDK} $LDFLAGS_DEBUGLEVEL_release"
825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848
          ;;
        slowdebug )
          if test "x$HAS_LINKER_NOW" = "xtrue"; then
            # do relocations at load
            LDFLAGS_JDK="$LDFLAGS_JDK $LINKER_NOW_FLAG"
            LDFLAGS_CXX_JDK="$LDFLAGS_CXX_JDK $LINKER_NOW_FLAG"
          fi
          if test "x$HAS_LINKER_RELRO" = "xtrue"; then
            # mark relocations read only
            LDFLAGS_JDK="$LDFLAGS_JDK $LINKER_RELRO_FLAG"
            LDFLAGS_CXX_JDK="$LDFLAGS_CXX_JDK $LINKER_RELRO_FLAG"
          fi
          ;;
        fastdebug )
          if test "x$HAS_LINKER_RELRO" = "xtrue"; then
            # mark relocations read only
            LDFLAGS_JDK="$LDFLAGS_JDK $LINKER_RELRO_FLAG"
            LDFLAGS_CXX_JDK="$LDFLAGS_CXX_JDK $LINKER_RELRO_FLAG"
          fi
          ;;
        * )
          AC_MSG_ERROR([Unrecognized \$DEBUG_LEVEL: $DEBUG_LEVEL])
          ;;
        esac
849
    fi
850
  elif test "x$TOOLCHAIN_TYPE" = xsolstudio; then
851 852 853 854
    LDFLAGS_SOLSTUDIO="-Wl,-z,defs"
    LDFLAGS_JDK="$LDFLAGS_JDK $LDFLAGS_SOLSTUDIO -xildoff -ztext"
    LDFLAGS_CXX_SOLSTUDIO="-norunpath"
    LDFLAGS_CXX_JDK="$LDFLAGS_CXX_JDK $LDFLAGS_CXX_SOLSTUDIO -xnolib"
855
  elif test "x$TOOLCHAIN_TYPE" = xxlc; then
856
    LDFLAGS_XLC="-b64 -brtl -bnolibpath -bexpall -bernotok"
857
    LDFLAGS_JDK="${LDFLAGS_JDK} $LDFLAGS_XLC"
858
  fi
859

860 861 862 863 864 865 866 867 868
  # Customize LDFLAGS for executables

  LDFLAGS_JDKEXE="${LDFLAGS_JDK}"

  if test "x$TOOLCHAIN_TYPE" = xmicrosoft; then
    if test "x$OPENJDK_TARGET_CPU_BITS" = "x64"; then
      LDFLAGS_STACK_SIZE=1048576
    else
      LDFLAGS_STACK_SIZE=327680
869
    fi
870 871
    LDFLAGS_JDKEXE="${LDFLAGS_JDKEXE} /STACK:$LDFLAGS_STACK_SIZE"
  elif test "x$OPENJDK_TARGET_OS" = xlinux; then
872
    LDFLAGS_JDKEXE="$LDFLAGS_JDKEXE -Wl,--allow-shlib-undefined"
873
  fi
874

875 876 877
  # Customize LDFLAGS for libs
  LDFLAGS_JDKLIB="${LDFLAGS_JDK}"

878
  LDFLAGS_JDKLIB="${LDFLAGS_JDKLIB} ${SHARED_LIBRARY_FLAGS}"
879
  if test "x$TOOLCHAIN_TYPE" = xmicrosoft; then
880 881
    LDFLAGS_JDKLIB="${LDFLAGS_JDKLIB} \
        -libpath:${OUTPUT_ROOT}/support/modules_libs/java.base"
I
ihse 已提交
882
    JDKLIB_LIBS=""
883
  else
884
    LDFLAGS_JDKLIB="${LDFLAGS_JDKLIB} \
C
chegar 已提交
885
        -L${OUTPUT_ROOT}/support/modules_libs/java.base${OPENJDK_TARGET_CPU_LIBDIR}"
886 887 888 889 890 891

    # On some platforms (mac) the linker warns about non existing -L dirs.
    # Add server first if available. Linking aginst client does not always produce the same results.
    # Only add client dir if client is being built. Add minimal (note not minimal1) if only building minimal1.
    # Default to server for other variants.
    if test "x$JVM_VARIANT_SERVER" = xtrue; then
C
chegar 已提交
892
      LDFLAGS_JDKLIB="${LDFLAGS_JDKLIB} -L${OUTPUT_ROOT}/support/modules_libs/java.base${OPENJDK_TARGET_CPU_LIBDIR}/server"
893
    elif test "x$JVM_VARIANT_CLIENT" = xtrue; then
C
chegar 已提交
894
      LDFLAGS_JDKLIB="${LDFLAGS_JDKLIB} -L${OUTPUT_ROOT}/support/modules_libs/java.base${OPENJDK_TARGET_CPU_LIBDIR}/client"
895
    elif test "x$JVM_VARIANT_MINIMAL1" = xtrue; then
C
chegar 已提交
896
      LDFLAGS_JDKLIB="${LDFLAGS_JDKLIB} -L${OUTPUT_ROOT}/support/modules_libs/java.base${OPENJDK_TARGET_CPU_LIBDIR}/minimal"
897
    else
C
chegar 已提交
898
      LDFLAGS_JDKLIB="${LDFLAGS_JDKLIB} -L${OUTPUT_ROOT}/support/modules_libs/java.base${OPENJDK_TARGET_CPU_LIBDIR}/server"
899 900
    fi

I
ihse 已提交
901
    JDKLIB_LIBS="-ljava -ljvm"
902
    if test "x$TOOLCHAIN_TYPE" = xsolstudio; then
I
ihse 已提交
903
      JDKLIB_LIBS="$JDKLIB_LIBS -lc"
904 905
    fi
  fi
906

907 908
  AC_SUBST(LDFLAGS_JDKLIB)
  AC_SUBST(LDFLAGS_JDKEXE)
I
ihse 已提交
909 910
  AC_SUBST(JDKLIB_LIBS)
  AC_SUBST(JDKEXE_LIBS)
911
  AC_SUBST(LDFLAGS_CXX_JDK)
912
  AC_SUBST(LDFLAGS_HASH_STYLE)
913 914 915 916 917 918

  LDFLAGS_TESTLIB="$LDFLAGS_JDKLIB"
  LDFLAGS_TESTEXE="$LDFLAGS_JDKEXE"

  AC_SUBST(LDFLAGS_TESTLIB)
  AC_SUBST(LDFLAGS_TESTEXE)
919 920
])

921 922
# FLAGS_COMPILER_CHECK_ARGUMENTS(ARGUMENT: [ARGUMENT], IF_TRUE: [RUN-IF-TRUE],
#                                   IF_FALSE: [RUN-IF-FALSE])
923 924
# ------------------------------------------------------------
# Check that the c and c++ compilers support an argument
925 926
BASIC_DEFUN_NAMED([FLAGS_COMPILER_CHECK_ARGUMENTS],
    [*ARGUMENT IF_TRUE IF_FALSE], [$@],
927
[
928
  AC_MSG_CHECKING([if compiler supports "ARG_ARGUMENT"])
929 930 931
  supports=yes

  saved_cflags="$CFLAGS"
932
  CFLAGS="$CFLAGS ARG_ARGUMENT"
933
  AC_LANG_PUSH([C])
934
  AC_COMPILE_IFELSE([AC_LANG_SOURCE([[int i;]])], [],
935 936 937 938 939
      [supports=no])
  AC_LANG_POP([C])
  CFLAGS="$saved_cflags"

  saved_cxxflags="$CXXFLAGS"
940
  CXXFLAGS="$CXXFLAG ARG_ARGUMENT"
941
  AC_LANG_PUSH([C++])
942
  AC_COMPILE_IFELSE([AC_LANG_SOURCE([[int i;]])], [],
943 944 945 946 947 948
      [supports=no])
  AC_LANG_POP([C++])
  CXXFLAGS="$saved_cxxflags"

  AC_MSG_RESULT([$supports])
  if test "x$supports" = "xyes" ; then
949 950
    :
    ARG_IF_TRUE
951
  else
952 953
    :
    ARG_IF_FALSE
954 955 956
  fi
])

957 958
# FLAGS_LINKER_CHECK_ARGUMENTS(ARGUMENT: [ARGUMENT], IF_TRUE: [RUN-IF-TRUE],
#                                   IF_FALSE: [RUN-IF-FALSE])
959 960
# ------------------------------------------------------------
# Check that the linker support an argument
961 962
BASIC_DEFUN_NAMED([FLAGS_LINKER_CHECK_ARGUMENTS],
    [*ARGUMENT IF_TRUE IF_FALSE], [$@],
963
[
964
  AC_MSG_CHECKING([if linker supports "ARG_ARGUMENT"])
965 966 967
  supports=yes

  saved_ldflags="$LDFLAGS"
968
  LDFLAGS="$LDFLAGS ARG_ARGUMENT"
969 970 971 972 973 974 975 976
  AC_LANG_PUSH([C])
  AC_LINK_IFELSE([AC_LANG_PROGRAM([[]],[[]])],
      [], [supports=no])
  AC_LANG_POP([C])
  LDFLAGS="$saved_ldflags"

  AC_MSG_RESULT([$supports])
  if test "x$supports" = "xyes" ; then
977 978
    :
    ARG_IF_TRUE
979
  else
980 981
    :
    ARG_IF_FALSE
982 983 984
  fi
])

985 986 987 988 989 990 991 992 993 994 995
AC_DEFUN_ONCE([FLAGS_SETUP_COMPILER_FLAGS_MISC],
[
  # Some Zero and Shark settings.
  # ZERO_ARCHFLAG tells the compiler which mode to build for
  case "${OPENJDK_TARGET_CPU}" in
    s390)
      ZERO_ARCHFLAG="${COMPILER_TARGET_BITS_FLAG}31"
      ;;
    *)
      ZERO_ARCHFLAG="${COMPILER_TARGET_BITS_FLAG}${OPENJDK_TARGET_CPU_BITS}"
  esac
996
  FLAGS_COMPILER_CHECK_ARGUMENTS(ARGUMENT: [$ZERO_ARCHFLAG], IF_FALSE: [ZERO_ARCHFLAG=""])
997 998 999 1000
  AC_SUBST(ZERO_ARCHFLAG)

  # Check that the compiler supports -mX (or -qX on AIX) flags
  # Set COMPILER_SUPPORTS_TARGET_BITS_FLAG to 'true' if it does
1001 1002 1003
  FLAGS_COMPILER_CHECK_ARGUMENTS(ARGUMENT: [${COMPILER_TARGET_BITS_FLAG}${OPENJDK_TARGET_CPU_BITS}],
      IF_TRUE: [COMPILER_SUPPORTS_TARGET_BITS_FLAG=true],
      IF_FALSE: [COMPILER_SUPPORTS_TARGET_BITS_FLAG=false])
1004
  AC_SUBST(COMPILER_SUPPORTS_TARGET_BITS_FLAG)
1005

I
ihse 已提交
1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021
  AC_ARG_ENABLE([warnings-as-errors], [AS_HELP_STRING([--disable-warnings-as-errors],
      [do not consider native warnings to be an error @<:@enabled@:>@])])

  AC_MSG_CHECKING([if native warnings are errors])
  if test "x$enable_warnings_as_errors" = "xyes"; then
    AC_MSG_RESULT([yes (explicitely set)])
    WARNINGS_AS_ERRORS=true
  elif test "x$enable_warnings_as_errors" = "xno"; then
    AC_MSG_RESULT([no])
    WARNINGS_AS_ERRORS=false
  elif test "x$enable_warnings_as_errors" = "x"; then
    AC_MSG_RESULT([yes (default)])
    WARNINGS_AS_ERRORS=true
  else
    AC_MSG_ERROR([--enable-warnings-as-errors accepts no argument])
  fi
1022 1023 1024

  if test "x$WARNINGS_AS_ERRORS" = "xfalse"; then
    # Set legacy hotspot variable
1025
    HOTSPOT_SET_WARNINGS_AS_ERRORS="WARNINGS_ARE_ERRORS="
1026
  else
1027
    HOTSPOT_SET_WARNINGS_AS_ERRORS=""
1028 1029
  fi

I
ihse 已提交
1030
  AC_SUBST(WARNINGS_AS_ERRORS)
1031
  AC_SUBST(HOTSPOT_SET_WARNINGS_AS_ERRORS)
I
ihse 已提交
1032

1033 1034
  case "${TOOLCHAIN_TYPE}" in
    microsoft)
1035
      DISABLE_WARNING_PREFIX="-wd"
E
erikj 已提交
1036
      CFLAGS_WARNINGS_ARE_ERRORS="-WX"
1037 1038
      ;;
    solstudio)
1039
      DISABLE_WARNING_PREFIX="-erroff="
1040 1041 1042
      CFLAGS_WARNINGS_ARE_ERRORS="-errtags -errwarn=%all"
      ;;
    gcc)
1043
      # Prior to gcc 4.4, a -Wno-X where X is unknown for that version of gcc will cause an error
1044 1045 1046
      FLAGS_COMPILER_CHECK_ARGUMENTS(ARGUMENT: [-Wno-this-is-a-warning-that-do-not-exist],
          IF_TRUE: [GCC_CAN_DISABLE_WARNINGS=true],
          IF_FALSE: [GCC_CAN_DISABLE_WARNINGS=false]
1047 1048 1049 1050 1051 1052
      )
      if test "x$GCC_CAN_DISABLE_WARNINGS" = "xtrue"; then
        DISABLE_WARNING_PREFIX="-Wno-"
      else
        DISABLE_WARNING_PREFIX=
      fi
1053
      CFLAGS_WARNINGS_ARE_ERRORS="-Werror"
1054 1055 1056
      # Repeate the check for the BUILD_CC
      CC_OLD="$CC"
      CC="$BUILD_CC"
1057 1058 1059
      FLAGS_COMPILER_CHECK_ARGUMENTS(ARGUMENT: [-Wno-this-is-a-warning-that-do-not-exist],
          IF_TRUE: [BUILD_CC_CAN_DISABLE_WARNINGS=true],
          IF_FALSE: [BUILD_CC_CAN_DISABLE_WARNINGS=false]
1060 1061 1062 1063 1064 1065 1066
      )
      if test "x$BUILD_CC_CAN_DISABLE_WARNINGS" = "xtrue"; then
        BUILD_CC_DISABLE_WARNING_PREFIX="-Wno-"
      else
        BUILD_CC_DISABLE_WARNING_PREFIX=
      fi
      CC="$CC_OLD"
1067 1068
      ;;
    clang)
1069
      DISABLE_WARNING_PREFIX="-Wno-"
1070 1071
      CFLAGS_WARNINGS_ARE_ERRORS="-Werror"
      ;;
1072 1073 1074 1075
    xlc)
      DISABLE_WARNING_PREFIX="-qsuppress="
      CFLAGS_WARNINGS_ARE_ERRORS="-qhalt=w"
      ;;
1076
  esac
1077
  AC_SUBST(DISABLE_WARNING_PREFIX)
1078
  AC_SUBST(CFLAGS_WARNINGS_ARE_ERRORS)
1079
])