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