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