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