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