common/autoconf/flags.m4

Mon, 29 Jun 2020 21:30:12 +0100

author
andrew
date
Mon, 29 Jun 2020 21:30:12 +0100
changeset 2537
a8da94d779b3
parent 2497
343c4ea489d5
permissions
-rw-r--r--

Merge

     1 #
     2 # Copyright (c) 2011, 2018, 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 #
    26 AC_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)
    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)
    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
    63   if test "x$OPENJDK_TARGET_OS" != xwindows; then
    64     POST_STRIP_CMD="$STRIP $STRIPFLAGS"
    65   fi
    66   AC_SUBST(POST_STRIP_CMD)
    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)
    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)
    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
   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).\$(COOKED_JDK_UPDATE_VERSION).\$(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 \$(COOKED_JDK_UPDATE_VERSION),\$(COOKED_JDK_UPDATE_VERSION),0),\$(COOKED_BUILD_NUMBER)\""
   115   fi
   116   AC_SUBST(RC_FLAGS)
   118   if test "x$TOOLCHAIN_TYPE" = xmicrosoft; then
   119     # FIXME: likely bug, should be CCXXFLAGS_JDK? or one for C or CXX.
   120     CCXXFLAGS="$CCXXFLAGS -nologo"
   121   fi
   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 ])
   150 AC_DEFUN_ONCE([FLAGS_SETUP_COMPILER_FLAGS_FOR_LIBS],
   151 [
   152   ###############################################################################
   153   #
   154   # How to compile shared libraries.
   155   #
   157   if test "x$TOOLCHAIN_TYPE" = xgcc; then
   158     PICFLAG="-fPIC"
   159     PIEFLAG="-fPIE"
   160     C_FLAG_REORDER=''
   161     CXX_FLAG_REORDER=''
   163     if test "x$OPENJDK_TARGET_OS" = xmacosx; then
   164       # Linking is different on MacOSX
   165       SHARED_LIBRARY_FLAGS="-dynamiclib -compatibility_version 1.0.0 -current_version 1.0.0 $PICFLAG"
   166       SET_EXECUTABLE_ORIGIN='-Xlinker -rpath -Xlinker @loader_path/.'
   167       SET_SHARED_LIBRARY_ORIGIN="$SET_EXECUTABLE_ORIGIN"
   168       SET_SHARED_LIBRARY_NAME='-Xlinker -install_name -Xlinker @rpath/[$]1'
   169       SET_SHARED_LIBRARY_MAPFILE=''
   170     else
   171       # Default works for linux, might work on other platforms as well.
   172       SHARED_LIBRARY_FLAGS='-shared'
   173       SET_EXECUTABLE_ORIGIN='-Xlinker -rpath -Xlinker \$$$$ORIGIN[$]1'
   174       SET_SHARED_LIBRARY_ORIGIN="-Xlinker -z -Xlinker origin $SET_EXECUTABLE_ORIGIN"
   175       SET_SHARED_LIBRARY_NAME='-Xlinker -soname=[$]1'
   176       SET_SHARED_LIBRARY_MAPFILE='-Xlinker -version-script=[$]1'
   177     fi
   178   elif test "x$TOOLCHAIN_TYPE" = xsolstudio; then
   179     PICFLAG="-KPIC"
   180     PIEFLAG=""
   181     C_FLAG_REORDER='-xF'
   182     CXX_FLAG_REORDER='-xF'
   183     SHARED_LIBRARY_FLAGS="-G"
   184     SET_EXECUTABLE_ORIGIN='-R\$$$$ORIGIN[$]1'
   185     SET_SHARED_LIBRARY_ORIGIN="$SET_EXECUTABLE_ORIGIN"
   186     SET_SHARED_LIBRARY_NAME=''
   187     SET_SHARED_LIBRARY_MAPFILE='-M[$]1'
   188   elif test "x$TOOLCHAIN_TYPE" = xxlc; then
   189     PICFLAG="-qpic=large"
   190     PIEFLAG=""
   191     C_FLAG_REORDER=''
   192     CXX_FLAG_REORDER=''
   193     SHARED_LIBRARY_FLAGS="-qmkshrobj"
   194     SET_EXECUTABLE_ORIGIN=""
   195     SET_SHARED_LIBRARY_ORIGIN=''
   196     SET_SHARED_LIBRARY_NAME=''
   197     SET_SHARED_LIBRARY_MAPFILE=''
   198   elif test "x$TOOLCHAIN_TYPE" = xmicrosoft; then
   199     PICFLAG=""
   200     PIEFLAG=""
   201     C_FLAG_REORDER=''
   202     CXX_FLAG_REORDER=''
   203     SHARED_LIBRARY_FLAGS="-LD"
   204     SET_EXECUTABLE_ORIGIN=''
   205     SET_SHARED_LIBRARY_ORIGIN=''
   206     SET_SHARED_LIBRARY_NAME=''
   207     SET_SHARED_LIBRARY_MAPFILE=''
   208   fi
   210   AC_SUBST(C_FLAG_REORDER)
   211   AC_SUBST(CXX_FLAG_REORDER)
   212   AC_SUBST(SHARED_LIBRARY_FLAGS)
   213   AC_SUBST(SET_EXECUTABLE_ORIGIN)
   214   AC_SUBST(SET_SHARED_LIBRARY_ORIGIN)
   215   AC_SUBST(SET_SHARED_LIBRARY_NAME)
   216   AC_SUBST(SET_SHARED_LIBRARY_MAPFILE)
   218   if test "x$OPENJDK_TARGET_OS" = xsolaris; then
   219     CFLAGS_JDK="${CFLAGS_JDK} -D__solaris__"
   220     CXXFLAGS_JDK="${CXXFLAGS_JDK} -D__solaris__"
   221     CFLAGS_JDKLIB_EXTRA='-xstrconst'
   222   fi
   223   # The (cross) compiler is now configured, we can now test capabilities
   224   # of the target platform.
   225 ])
   227 # Documentation on common flags used for solstudio in HIGHEST.
   228 #
   229 # WARNING: Use of OPTIMIZATION_LEVEL=HIGHEST in your Makefile needs to be
   230 #          done with care, there are some assumptions below that need to
   231 #          be understood about the use of pointers, and IEEE behavior.
   232 #
   233 # -fns: Use non-standard floating point mode (not IEEE 754)
   234 # -fsimple: Do some simplification of floating point arithmetic (not IEEE 754)
   235 # -fsingle: Use single precision floating point with 'float'
   236 # -xalias_level=basic: Assume memory references via basic pointer types do not alias
   237 #   (Source with excessing pointer casting and data access with mixed
   238 #    pointer types are not recommended)
   239 # -xbuiltin=%all: Use intrinsic or inline versions for math/std functions
   240 #   (If you expect perfect errno behavior, do not use this)
   241 # -xdepend: Loop data dependency optimizations (need -xO3 or higher)
   242 # -xrestrict: Pointer parameters to functions do not overlap
   243 #   (Similar to -xalias_level=basic usage, but less obvious sometimes.
   244 #    If you pass in multiple pointers to the same data, do not use this)
   245 # -xlibmil: Inline some library routines
   246 #   (If you expect perfect errno behavior, do not use this)
   247 # -xlibmopt: Use optimized math routines (CURRENTLY DISABLED)
   248 #   (If you expect perfect errno behavior, do not use this)
   249 #  Can cause undefined external on Solaris 8 X86 on __sincos, removing for now
   251     # FIXME: this will never happen since sparc != sparcv9, ie 32 bit, which we don't build anymore.
   252     # Bug?
   253     #if test "x$OPENJDK_TARGET_CPU" = xsparc; then
   254     #  CFLAGS_JDK="${CFLAGS_JDK} -xmemalign=4s"
   255     #  CXXFLAGS_JDK="${CXXFLAGS_JDK} -xmemalign=4s"
   256     #fi
   258 AC_DEFUN_ONCE([FLAGS_SETUP_COMPILER_FLAGS_FOR_OPTIMIZATION],
   259 [
   261   ###############################################################################
   262   #
   263   # Setup the opt flags for different compilers
   264   # and different operating systems.
   265   #
   267   # FIXME: this was indirectly the old default, but just inherited.
   268   # if test "x$TOOLCHAIN_TYPE" = xmicrosoft; then
   269   #   C_FLAG_DEPS="-MMD -MF"
   270   # fi
   272   # Generate make dependency files
   273   if test "x$TOOLCHAIN_TYPE" = xgcc; then
   274     C_FLAG_DEPS="-MMD -MF"
   275   elif test "x$TOOLCHAIN_TYPE" = xsolstudio; then
   276     C_FLAG_DEPS="-xMMD -xMF"
   277   elif test "x$TOOLCHAIN_TYPE" = xxlc; then
   278     C_FLAG_DEPS="-qmakedep=gcc -MF"
   279   fi
   280   CXX_FLAG_DEPS="$C_FLAG_DEPS"
   281   AC_SUBST(C_FLAG_DEPS)
   282   AC_SUBST(CXX_FLAG_DEPS)
   284   # Debug symbols
   285   #
   286   # By default don't set any specific assembler debug
   287   # info flags for toolchains unless we know they work.
   288   # See JDK-8207057.
   289   ASFLAGS_DEBUG_SYMBOLS=""
   290   if test "x$TOOLCHAIN_TYPE" = xgcc; then
   291     if test "x$OPENJDK_TARGET_CPU_BITS" = "x64" && test "x$DEBUG_LEVEL" = "xfastdebug"; then
   292       CFLAGS_DEBUG_SYMBOLS="-g1"
   293       CXXFLAGS_DEBUG_SYMBOLS="-g1"
   294     else
   295       CFLAGS_DEBUG_SYMBOLS="-g"
   296       CXXFLAGS_DEBUG_SYMBOLS="-g"
   297     fi
   298     ASFLAGS_DEBUG_SYMBOLS="-g"
   299   elif test "x$TOOLCHAIN_TYPE" = xsolstudio; then
   300     CFLAGS_DEBUG_SYMBOLS="-g -xs"
   301     CXXFLAGS_DEBUG_SYMBOLS="-g0 -xs"
   302   elif test "x$TOOLCHAIN_TYPE" = xxlc; then
   303     CFLAGS_DEBUG_SYMBOLS="-g"
   304     CXXFLAGS_DEBUG_SYMBOLS="-g"
   305   fi
   306   AC_SUBST(ASFLAGS_DEBUG_SYMBOLS)
   307   AC_SUBST(CFLAGS_DEBUG_SYMBOLS)
   308   AC_SUBST(CXXFLAGS_DEBUG_SYMBOLS)
   310   # Optimization levels
   311   if test "x$TOOLCHAIN_TYPE" = xsolstudio; then
   312     CC_HIGHEST="$CC_HIGHEST -fns -fsimple -fsingle -xalias_level=basic -xbuiltin=%all -xdepend -xrestrict -xlibmil"
   314     if test "x$OPENJDK_TARGET_CPU_ARCH" = "xx86"; then
   315       # FIXME: seems we always set -xregs=no%frameptr; put it elsewhere more global?
   316       C_O_FLAG_HIGHEST="-xO4 -Wu,-O4~yz $CC_HIGHEST -xregs=no%frameptr"
   317       C_O_FLAG_HI="-xO4 -Wu,-O4~yz -xregs=no%frameptr"
   318       C_O_FLAG_NORM="-xO2 -Wu,-O2~yz -xregs=no%frameptr"
   319       C_O_FLAG_NONE="-xregs=no%frameptr"
   320       CXX_O_FLAG_HIGHEST="-xO4 -Qoption ube -O4~yz $CC_HIGHEST -xregs=no%frameptr"
   321       CXX_O_FLAG_HI="-xO4 -Qoption ube -O4~yz -xregs=no%frameptr"
   322       CXX_O_FLAG_NORM="-xO2 -Qoption ube -O2~yz -xregs=no%frameptr"
   323       CXX_O_FLAG_NONE="-xregs=no%frameptr"
   324       if test "x$OPENJDK_TARGET_CPU_BITS" = "x32"; then
   325         C_O_FLAG_HIGHEST="$C_O_FLAG_HIGHEST -xchip=pentium"
   326         CXX_O_FLAG_HIGHEST="$CXX_O_FLAG_HIGHEST -xchip=pentium"
   327       fi
   328     elif test "x$OPENJDK_TARGET_CPU_ARCH" = "xsparc"; then
   329       C_O_FLAG_HIGHEST="-xO4 -Wc,-Qrm-s -Wc,-Qiselect-T0 $CC_HIGHEST -xprefetch=auto,explicit -xchip=ultra"
   330       C_O_FLAG_HI="-xO4 -Wc,-Qrm-s -Wc,-Qiselect-T0"
   331       C_O_FLAG_NORM="-xO2 -Wc,-Qrm-s -Wc,-Qiselect-T0"
   332       C_O_FLAG_NONE=""
   333       CXX_O_FLAG_HIGHEST="-xO4 -Qoption cg -Qrm-s -Qoption cg -Qiselect-T0 $CC_HIGHEST -xprefetch=auto,explicit -xchip=ultra"
   334       CXX_O_FLAG_HI="-xO4 -Qoption cg -Qrm-s -Qoption cg -Qiselect-T0"
   335       CXX_O_FLAG_NORM="-xO2 -Qoption cg -Qrm-s -Qoption cg -Qiselect-T0"
   336       CXX_O_FLAG_NONE=""
   337     fi
   338   else
   339     # The remaining toolchains share opt flags between CC and CXX;
   340     # setup for C and duplicate afterwards.
   341     if test "x$TOOLCHAIN_TYPE" = xgcc; then
   342       if test "x$OPENJDK_TARGET_OS" = xmacosx; then
   343         # On MacOSX we optimize for size, something
   344         # we should do for all platforms?
   345         C_O_FLAG_HIGHEST="-Os"
   346         C_O_FLAG_HI="-Os"
   347         C_O_FLAG_NORM="-Os"
   348         C_O_FLAG_NONE=""
   349       else
   350         C_O_FLAG_HIGHEST="-O3"
   351         C_O_FLAG_HI="-O3"
   352         C_O_FLAG_NORM="-O2"
   353         C_O_FLAG_NONE="-O0"
   354       fi
   355     elif test "x$TOOLCHAIN_TYPE" = xxlc; then
   356       C_O_FLAG_HIGHEST="-O3"
   357       C_O_FLAG_HI="-O3 -qstrict"
   358       C_O_FLAG_NORM="-O2"
   359       C_O_FLAG_NONE=""
   360     elif test "x$TOOLCHAIN_TYPE" = xmicrosoft; then
   361       C_O_FLAG_HIGHEST="-O2"
   362       C_O_FLAG_HI="-O1"
   363       C_O_FLAG_NORM="-O1"
   364       C_O_FLAG_NONE="-Od"
   365     fi
   366     CXX_O_FLAG_HIGHEST="$C_O_FLAG_HIGHEST"
   367     CXX_O_FLAG_HI="$C_O_FLAG_HI"
   368     CXX_O_FLAG_NORM="$C_O_FLAG_NORM"
   369     CXX_O_FLAG_NONE="$C_O_FLAG_NONE"
   370   fi
   372   AC_SUBST(C_O_FLAG_HIGHEST)
   373   AC_SUBST(C_O_FLAG_HI)
   374   AC_SUBST(C_O_FLAG_NORM)
   375   AC_SUBST(C_O_FLAG_NONE)
   376   AC_SUBST(CXX_O_FLAG_HIGHEST)
   377   AC_SUBST(CXX_O_FLAG_HI)
   378   AC_SUBST(CXX_O_FLAG_NORM)
   379   AC_SUBST(CXX_O_FLAG_NONE)
   380 ])
   382 AC_DEFUN_ONCE([FLAGS_SETUP_COMPILER_FLAGS_FOR_JDK],
   383 [
   384   # Special extras...
   385   if test "x$TOOLCHAIN_TYPE" = xsolstudio; then
   386     if test "x$OPENJDK_TARGET_CPU_ARCH" = "xsparc"; then
   387       CFLAGS_JDKLIB_EXTRA="${CFLAGS_JDKLIB_EXTRA} -xregs=no%appl"
   388       CXXFLAGS_JDKLIB_EXTRA="${CXXFLAGS_JDKLIB_EXTRA} -xregs=no%appl"
   389     fi
   390   elif test "x$TOOLCHAIN_TYPE" = xxlc; then
   391     LDFLAGS_JDK="${LDFLAGS_JDK} -q64 -brtl -bnolibpath -liconv -bexpall"
   392     CFLAGS_JDK="${CFLAGS_JDK} -qchars=signed -q64 -qfullpath -qsaveopt"
   393     CXXFLAGS_JDK="${CXXFLAGS_JDK} -qchars=signed -q64 -qfullpath -qsaveopt"
   394   elif test "x$TOOLCHAIN_TYPE" = xgcc; then
   395     LEGACY_EXTRA_CFLAGS="$LEGACY_EXTRA_CFLAGS -fstack-protector"
   396     LEGACY_EXTRA_CXXFLAGS="$LEGACY_EXTRA_CXXFLAGS -fstack-protector"
   397     if test "x$OPENJDK_TARGET_OS" != xmacosx; then
   398       LDFLAGS_JDK="$LDFLAGS_JDK -Wl,-z,relro"
   399       LEGACY_EXTRA_LDFLAGS="$LEGACY_EXTRA_LDFLAGS -Wl,-z,relro"
   400     fi
   401     $2CXXSTD_CXXFLAG="-std=gnu++98"
   402     FLAGS_CXX_COMPILER_CHECK_ARGUMENTS([[$]$2CXXSTD_CXXFLAG -Werror],
   403                                        [], [$2CXXSTD_CXXFLAG=""])
   404     $2CXXFLAGS_JDK="${$2CXXFLAGS_JDK} ${$2CXXSTD_CXXFLAG}"
   405     $2JVM_CFLAGS="${$2JVM_CFLAGS} ${$2CXXSTD_CXXFLAG}"
   406     AC_SUBST($2CXXSTD_CXXFLAG)
   407   fi
   409   if test "x$CFLAGS" != "x${ADDED_CFLAGS}"; then
   410     AC_MSG_WARN([Ignoring CFLAGS($CFLAGS) found in environment. Use --with-extra-cflags])
   411   fi
   413   if test "x$CXXFLAGS" != "x${ADDED_CXXFLAGS}"; then
   414     AC_MSG_WARN([Ignoring CXXFLAGS($CXXFLAGS) found in environment. Use --with-extra-cxxflags])
   415   fi
   417   if test "x$LDFLAGS" != "x${ADDED_LDFLAGS}"; then
   418     AC_MSG_WARN([Ignoring LDFLAGS($LDFLAGS) found in environment. Use --with-extra-ldflags])
   419   fi
   422   if test "x$ASFLAGS" != "x"; then
   423     AC_MSG_WARN([Ignoring ASFLAGS($ASFLAGS) found in environment. Use --with-extra-asflags])
   424   fi
   426   AC_ARG_WITH(extra-cflags, [AS_HELP_STRING([--with-extra-cflags],
   427       [extra flags to be used when compiling jdk c-files])])
   429   AC_ARG_WITH(extra-cxxflags, [AS_HELP_STRING([--with-extra-cxxflags],
   430       [extra flags to be used when compiling jdk c++-files])])
   432   AC_ARG_WITH(extra-ldflags, [AS_HELP_STRING([--with-extra-ldflags],
   433       [extra flags to be used when linking jdk])])
   435   AC_ARG_WITH(extra-asflags, [AS_HELP_STRING([--with-extra-asflags],
   436       [extra flags to be passed to the assembler])])
   438   CFLAGS_JDK="${CFLAGS_JDK} $with_extra_cflags"
   439   CXXFLAGS_JDK="${CXXFLAGS_JDK} $with_extra_cxxflags"
   440   LDFLAGS_JDK="${LDFLAGS_JDK} $with_extra_ldflags"
   442   # Hotspot needs these set in their legacy form
   443   LEGACY_EXTRA_CFLAGS="$LEGACY_EXTRA_CFLAGS $with_extra_cflags"
   444   LEGACY_EXTRA_CXXFLAGS="$LEGACY_EXTRA_CXXFLAGS $with_extra_cxxflags"
   445   LEGACY_EXTRA_LDFLAGS="$LEGACY_EXTRA_LDFLAGS $with_extra_ldflags"
   446   LEGACY_EXTRA_ASFLAGS="$with_extra_asflags"
   448   AC_SUBST(LEGACY_EXTRA_CFLAGS)
   449   AC_SUBST(LEGACY_EXTRA_CXXFLAGS)
   450   AC_SUBST(LEGACY_EXTRA_LDFLAGS)
   451   AC_SUBST(LEGACY_EXTRA_ASFLAGS)
   453   ###############################################################################
   454   #
   455   # Now setup the CFLAGS and LDFLAGS for the JDK build.
   456   # Later we will also have CFLAGS and LDFLAGS for the hotspot subrepo build.
   457   #
   459   FDLIBM_CFLAGS=""
   460   # Setup compiler/platform specific flags to CFLAGS_JDK,
   461   # CXXFLAGS_JDK and CCXXFLAGS_JDK (common to C and CXX?)
   462   if test "x$TOOLCHAIN_TYPE" = xgcc; then
   463     # these options are used for both C and C++ compiles
   464     CCXXFLAGS_JDK="$CCXXFLAGS $CCXXFLAGS_JDK -Wall -Wno-parentheses -Wextra -Wno-unused -Wno-unused-parameter -Wformat=2 \
   465         -pipe -fstack-protector -D_GNU_SOURCE -D_REENTRANT -D_LARGEFILE64_SOURCE"
   466     case $OPENJDK_TARGET_CPU_ARCH in
   467       arm )
   468         # on arm we don't prevent gcc to omit frame pointer but do prevent strict aliasing
   469         CFLAGS_JDK="${CFLAGS_JDK} -fno-strict-aliasing"
   470         ;;
   471       ppc )
   472         # on ppc we don't prevent gcc to omit frame pointer nor strict-aliasing
   473         ;;
   474       * )
   475         CCXXFLAGS_JDK="$CCXXFLAGS_JDK -fno-omit-frame-pointer"
   476         CFLAGS_JDK="${CFLAGS_JDK} -fno-strict-aliasing"
   477         ;;
   478     esac
   479     TOOLCHAIN_CHECK_COMPILER_VERSION(6, FLAGS_SETUP_GCC6_COMPILER_FLAGS)
   481     # Check that the compiler supports -ffp-contract=off flag
   482     # Set FDLIBM_CFLAGS to -ffp-contract=off if it does.
   483     # For GCC < 4.6, on x86, x86_64 and ppc check for
   484     # -mno-fused-madd and -fno-strict-aliasing. If they exist,
   485     # use them as a substitute for -ffp-contract=off.
   486     #
   487     # These flags are required for GCC-based builds of
   488     # fdlibm with optimization without losing precision.
   489     # Notably, -ffp-contract=off needs to be added for GCC >= 4.6,
   490     #          -mno-fused-madd -fno-strict-aliasing for GCC < 4.6
   491     COMPILER_FP_CONTRACT_OFF_FLAG="-ffp-contract=off"
   492     FLAGS_CXX_COMPILER_CHECK_ARGUMENTS([[$]COMPILER_FP_CONTRACT_OFF_FLAG -Werror],
   493                                        [], [COMPILER_FP_CONTRACT_OFF_FLAG=""])
   494     if test "x$COMPILER_FP_CONTRACT_OFF_FLAG" = x; then
   495       if test "$OPENJDK_TARGET_CPU_ARCH" = "x86" ||
   496          test "$OPENJDK_TARGET_CPU_ARCH" = "x86_64" ||
   497          test "$OPENJDK_TARGET_CPU_ARCH" = "ppc"; then
   498         M_NO_FUSED_ADD_FLAG="-mno-fused-madd"
   499         FLAGS_CXX_COMPILER_CHECK_ARGUMENTS([[$]M_NO_FUSED_ADD_FLAG -Werror],
   500                                            [], [M_NO_FUSED_ADD_FLAG=""])
   501         NO_STRICT_ALIASING_FLAG="-fno-strict-aliasing"
   502         FLAGS_CXX_COMPILER_CHECK_ARGUMENTS([[$]NO_STRICT_ALIASING_FLAG -Werror],
   503                                            [], [NO_STRICT_ALIASING_FLAG=""])
   504         if test "x$M_NO_FUSED_ADD_FLAG" != "x" && test "x$NO_STRICT_ALIASING_FLAG" != "x"; then
   505           FDLIBM_CFLAGS="$M_NO_FUSED_ADD_FLAG $NO_STRICT_ALIASING_FLAG"
   506         fi
   507       fi
   508     else
   509       FDLIBM_CFLAGS="$COMPILER_FP_CONTRACT_OFF_FLAG"
   510     fi
   511   elif test "x$TOOLCHAIN_TYPE" = xsolstudio; then
   512     CCXXFLAGS_JDK="$CCXXFLAGS $CCXXFLAGS_JDK -DTRACING -DMACRO_MEMSYS_OPS -DBREAKPTS"
   513     if test "x$OPENJDK_TARGET_CPU_ARCH" = xx86; then
   514       CCXXFLAGS_JDK="$CCXXFLAGS_JDK -DcpuIntel -Di586 -D$OPENJDK_TARGET_CPU_LEGACY_LIB"
   515       CFLAGS_JDK="$CFLAGS_JDK -erroff=E_BAD_PRAGMA_PACK_VALUE"
   516     fi
   518     CFLAGS_JDK="$CFLAGS_JDK -xc99=%none -xCC -errshort=tags -Xa -v -mt -W0,-noglobal"
   519     CXXFLAGS_JDK="$CXXFLAGS_JDK -errtags=yes +w -mt -features=no%except -DCC_NOEX -norunpath -xnolib"
   520   elif test "x$TOOLCHAIN_TYPE" = xxlc; then
   521     CFLAGS_JDK="$CFLAGS_JDK -D_GNU_SOURCE -D_REENTRANT -D_LARGEFILE64_SOURCE -DSTDC"
   522     CXXFLAGS_JDK="$CXXFLAGS_JDK -D_GNU_SOURCE -D_REENTRANT -D_LARGEFILE64_SOURCE -DSTDC"
   523   elif test "x$TOOLCHAIN_TYPE" = xmicrosoft; then
   524     CCXXFLAGS_JDK="$CCXXFLAGS $CCXXFLAGS_JDK \
   525         -Zi -MD -Zc:wchar_t- -W3 -wd4800 \
   526         -DWIN32_LEAN_AND_MEAN \
   527         -D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE \
   528         -DWIN32 -DIAL"
   529     if test "x$OPENJDK_TARGET_CPU" = xx86_64; then
   530       CCXXFLAGS_JDK="$CCXXFLAGS_JDK -D_AMD64_ -Damd64"
   531     else
   532       CCXXFLAGS_JDK="$CCXXFLAGS_JDK -D_X86_ -Dx86"
   533     fi
   534     # If building with Visual Studio 2010, we can still use _STATIC_CPPLIB to
   535     # avoid bundling msvcpNNN.dll. Doesn't work with newer versions of visual
   536     # studio.
   537     if test "x$TOOLCHAIN_VERSION" = "x2010"; then
   538       CCXXFLAGS_JDK="$CCXXFLAGS_JDK \
   539           -D_STATIC_CPPLIB -D_DISABLE_DEPRECATE_STATIC_CPPLIB"
   540     fi
   541   fi
   542   AC_SUBST(FDLIBM_CFLAGS)
   544   ###############################################################################
   546   # Adjust flags according to debug level.
   547   case $DEBUG_LEVEL in
   548     fastdebug )
   549       CFLAGS_JDK="$CFLAGS_JDK $CFLAGS_DEBUG_SYMBOLS"
   550       CXXFLAGS_JDK="$CXXFLAGS_JDK $CXXFLAGS_DEBUG_SYMBOLS"
   551       C_O_FLAG_HI="$C_O_FLAG_NORM"
   552       C_O_FLAG_NORM="$C_O_FLAG_NORM"
   553       CXX_O_FLAG_HI="$CXX_O_FLAG_NORM"
   554       CXX_O_FLAG_NORM="$CXX_O_FLAG_NORM"
   555       JAVAC_FLAGS="$JAVAC_FLAGS -g"
   556       ;;
   557     slowdebug )
   558       CFLAGS_JDK="$CFLAGS_JDK $CFLAGS_DEBUG_SYMBOLS"
   559       CXXFLAGS_JDK="$CXXFLAGS_JDK $CXXFLAGS_DEBUG_SYMBOLS"
   560       C_O_FLAG_HI="$C_O_FLAG_NONE"
   561       C_O_FLAG_NORM="$C_O_FLAG_NONE"
   562       CXX_O_FLAG_HI="$CXX_O_FLAG_NONE"
   563       CXX_O_FLAG_NORM="$CXX_O_FLAG_NONE"
   564       JAVAC_FLAGS="$JAVAC_FLAGS -g"
   565       ;;
   566   esac
   568   # Setup LP64
   569   CCXXFLAGS_JDK="$CCXXFLAGS_JDK $ADD_LP64"
   571   # Set some common defines. These works for all compilers, but assume
   572   # -D is universally accepted.
   574   # Setup endianness
   575   if test "x$OPENJDK_TARGET_CPU_ENDIAN" = xlittle; then
   576     # The macro _LITTLE_ENDIAN needs to be defined the same to avoid the
   577     #   Sun C compiler warning message: warning: macro redefined: _LITTLE_ENDIAN
   578     #   (The Solaris X86 system defines this in file /usr/include/sys/isa_defs.h).
   579     #   Note: -Dmacro         is the same as    #define macro 1
   580     #         -Dmacro=        is the same as    #define macro
   581     if test "x$OPENJDK_TARGET_OS" = xsolaris; then
   582       CCXXFLAGS_JDK="$CCXXFLAGS_JDK -D_LITTLE_ENDIAN="
   583     else
   584       CCXXFLAGS_JDK="$CCXXFLAGS_JDK -D_LITTLE_ENDIAN"
   585     fi
   586   else
   587     # Same goes for _BIG_ENDIAN. Do we really need to set *ENDIAN on Solaris if they
   588     # are defined in the system?
   589     if test "x$OPENJDK_TARGET_OS" = xsolaris; then
   590       CCXXFLAGS_JDK="$CCXXFLAGS_JDK -D_BIG_ENDIAN="
   591     else
   592       CCXXFLAGS_JDK="$CCXXFLAGS_JDK -D_BIG_ENDIAN"
   593     fi
   594   fi
   595   if test "x$OPENJDK_TARGET_CPU" = xppc64le; then
   596     CCXXFLAGS_JDK="$CCXXFLAGS_JDK -DABI_ELFv2"
   597   fi
   599   # Setup target OS define. Use OS target name but in upper case.
   600   OPENJDK_TARGET_OS_UPPERCASE=`$ECHO $OPENJDK_TARGET_OS | $TR 'abcdefghijklmnopqrstuvwxyz' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'`
   601   CCXXFLAGS_JDK="$CCXXFLAGS_JDK -D$OPENJDK_TARGET_OS_UPPERCASE"
   603   # Setup target CPU
   604   CCXXFLAGS_JDK="$CCXXFLAGS_JDK -DARCH='\"$OPENJDK_TARGET_CPU_LEGACY\"' -D$OPENJDK_TARGET_CPU_LEGACY"
   606   # Setup debug/release defines
   607   if test "x$DEBUG_LEVEL" = xrelease; then
   608     CCXXFLAGS_JDK="$CCXXFLAGS_JDK -DNDEBUG"
   609     if test "x$OPENJDK_TARGET_OS" = xsolaris; then
   610       CCXXFLAGS_JDK="$CCXXFLAGS_JDK -DTRIMMED"
   611     fi
   612   else
   613     CCXXFLAGS_JDK="$CCXXFLAGS_JDK -DDEBUG"
   614   fi
   616   # Setup release name
   617   CCXXFLAGS_JDK="$CCXXFLAGS_JDK -DRELEASE='\"\$(RELEASE)\"'"
   620   # Set some additional per-OS defines.
   621   if test "x$OPENJDK_TARGET_OS" = xmacosx; then
   622     CCXXFLAGS_JDK="$CCXXFLAGS_JDK -D_ALLBSD_SOURCE -D_DARWIN_UNLIMITED_SELECT"
   623   elif test "x$OPENJDK_TARGET_OS" = xaix; then
   624     # FIXME: PPC64 should not be here.
   625     CCXXFLAGS_JDK="$CCXXFLAGS_JDK -DPPC64"
   626   elif test "x$OPENJDK_TARGET_OS" = xbsd; then
   627     CCXXFLAGS_JDK="$CCXXFLAGS_JDK -D_ALLBSD_SOURCE"
   628   fi
   630   # Additional macosx handling
   631   if test "x$OPENJDK_TARGET_OS" = xmacosx; then
   632     if test "x$TOOLCHAIN_TYPE" = xgcc; then
   633       # FIXME: This needs to be exported in spec.gmk due to closed legacy code.
   634       # FIXME: clean this up, and/or move it elsewhere.
   636       # Setting these parameters makes it an error to link to macosx APIs that are
   637       # newer than the given OS version and makes the linked binaries compatible 
   638       # even if built on a newer version of the OS.
   639       # The expected format is X.Y.Z
   640       MACOSX_VERSION_MIN=10.7.0
   641       AC_SUBST(MACOSX_VERSION_MIN)
   643       # The macro takes the version with no dots, ex: 1070
   644       # Let the flags variables get resolved in make for easier override on make
   645       # command line.
   646       CCXXFLAGS_JDK="$CCXXFLAGS_JDK -DMAC_OS_X_VERSION_MAX_ALLOWED=\$(subst .,,\$(MACOSX_VERSION_MIN)) -mmacosx-version-min=\$(MACOSX_VERSION_MIN)"
   647       LDFLAGS_JDK="$LDFLAGS_JDK -mmacosx-version-min=\$(MACOSX_VERSION_MIN)"
   648     fi
   649   fi
   651   # Setup some hard coded includes
   652   CCXXFLAGS_JDK="$CCXXFLAGS_JDK \
   653       -I${JDK_OUTPUTDIR}/include \
   654       -I${JDK_OUTPUTDIR}/include/$OPENJDK_TARGET_OS \
   655       -I${JDK_TOPDIR}/src/share/javavm/export \
   656       -I${JDK_TOPDIR}/src/$OPENJDK_TARGET_OS_EXPORT_DIR/javavm/export \
   657       -I${JDK_TOPDIR}/src/share/native/common \
   658       -I${JDK_TOPDIR}/src/$OPENJDK_TARGET_OS_API_DIR/native/common"
   660   # The shared libraries are compiled using the picflag.
   661   CFLAGS_JDKLIB="$CCXXFLAGS_JDK $CFLAGS_JDK $PICFLAG $CFLAGS_JDKLIB_EXTRA"
   662   CXXFLAGS_JDKLIB="$CCXXFLAGS_JDK $CXXFLAGS_JDK $PICFLAG $CXXFLAGS_JDKLIB_EXTRA "
   664   # Executable flags
   665   CFLAGS_JDKEXE="$CCXXFLAGS_JDK $CFLAGS_JDK $PIEFLAG"
   666   CXXFLAGS_JDKEXE="$CCXXFLAGS_JDK $CXXFLAGS_JDK $PIEFLAG"
   668   AC_SUBST(CFLAGS_JDKLIB)
   669   AC_SUBST(CFLAGS_JDKEXE)
   670   AC_SUBST(CXXFLAGS_JDKLIB)
   671   AC_SUBST(CXXFLAGS_JDKEXE)
   673   # Setup LDFLAGS et al.
   674   #
   675   # Now this is odd. The JDK native libraries have to link against libjvm.so
   676   # On 32-bit machines there is normally two distinct libjvm.so:s, client and server.
   677   # Which should we link to? Are we lucky enough that the binary api to the libjvm.so library
   678   # is identical for client and server? Yes. Which is picked at runtime (client or server)?
   679   # Neither, since the chosen libjvm.so has already been loaded by the launcher, all the following
   680   # libraries will link to whatever is in memory. Yuck.
   681   #
   682   # Thus we offer the compiler to find libjvm.so first in server then in client. It works. Ugh.
   683   if test "x$TOOLCHAIN_TYPE" = xmicrosoft; then
   684     LDFLAGS_JDK="$LDFLAGS_JDK -nologo -opt:ref -incremental:no"
   685     if test "x$OPENJDK_TARGET_CPU_BITS" = "x32"; then
   686       LDFLAGS_JDK="$LDFLAGS_JDK -safeseh"
   687     fi
   688     # TODO: make -debug optional "--disable-full-debug-symbols"
   689     LDFLAGS_JDK="$LDFLAGS_JDK -debug"
   690     LDFLAGS_JDKLIB="${LDFLAGS_JDK} -dll -libpath:${JDK_OUTPUTDIR}/lib"
   691     LDFLAGS_JDKLIB_SUFFIX=""
   692     if test "x$OPENJDK_TARGET_CPU_BITS" = "x64"; then
   693       LDFLAGS_STACK_SIZE=1048576
   694     else
   695       LDFLAGS_STACK_SIZE=327680
   696     fi
   697     LDFLAGS_JDKEXE="${LDFLAGS_JDK} /STACK:$LDFLAGS_STACK_SIZE"
   698   else
   699     if test "x$TOOLCHAIN_TYPE" = xgcc; then
   700       # If this is a --hash-style=gnu system, use --hash-style=both, why?
   701       # We have previously set HAS_GNU_HASH if this is the case
   702       if test -n "$HAS_GNU_HASH"; then
   703         LDFLAGS_JDK="${LDFLAGS_JDK} -Xlinker --hash-style=both "
   704       fi
   705       if test "x$OPENJDK_TARGET_OS" = xlinux; then
   706         # And since we now know that the linker is gnu, then add:
   707         #   -z defs, to forbid undefined symbols in object files
   708         #   -z noexecstack, to mark stack regions as non-executable
   709         LDFLAGS_JDK="${LDFLAGS_JDK} -Xlinker -z -Xlinker defs -Xlinker -z -Xlinker noexecstack"
   710         if test "x$DEBUG_LEVEL" = "xrelease"; then
   711           # When building release libraries, tell the linker optimize them.
   712           # Should this be supplied to the OSS linker as well?
   713           LDFLAGS_JDK="${LDFLAGS_JDK} -Xlinker -O1"
   714         fi
   715       fi
   716     fi
   718     if test "x$TOOLCHAIN_TYPE" = xsolstudio; then
   719       LDFLAGS_JDK="$LDFLAGS_JDK -z defs -xildoff -ztext"
   720       LDFLAGS_CXX_JDK="$LDFLAGS_CXX_JDK -norunpath -xnolib"
   721     fi
   723     LDFLAGS_JDKLIB="${LDFLAGS_JDK} $SHARED_LIBRARY_FLAGS \
   724         -L${JDK_OUTPUTDIR}/lib${OPENJDK_TARGET_CPU_LIBDIR}"
   726     # On some platforms (mac) the linker warns about non existing -L dirs.
   727     # Add server first if available. Linking aginst client does not always produce the same results.
   728     # Only add client dir if client is being built. Add minimal (note not minimal1) if only building minimal1.
   729     # Default to server for other variants.
   730     if test "x$JVM_VARIANT_SERVER" = xtrue; then
   731       LDFLAGS_JDKLIB="${LDFLAGS_JDKLIB} -L${JDK_OUTPUTDIR}/lib${OPENJDK_TARGET_CPU_LIBDIR}/server"
   732     elif test "x$JVM_VARIANT_CLIENT" = xtrue; then
   733       LDFLAGS_JDKLIB="${LDFLAGS_JDKLIB} -L${JDK_OUTPUTDIR}/lib${OPENJDK_TARGET_CPU_LIBDIR}/client"
   734     elif test "x$JVM_VARIANT_MINIMAL1" = xtrue; then
   735       LDFLAGS_JDKLIB="${LDFLAGS_JDKLIB} -L${JDK_OUTPUTDIR}/lib${OPENJDK_TARGET_CPU_LIBDIR}/minimal"
   736     else
   737       LDFLAGS_JDKLIB="${LDFLAGS_JDKLIB} -L${JDK_OUTPUTDIR}/lib${OPENJDK_TARGET_CPU_LIBDIR}/server"
   738     fi
   740     LDFLAGS_JDKLIB_SUFFIX="-ljava -ljvm"
   741     if test "x$TOOLCHAIN_TYPE" = xsolstudio; then
   742       LDFLAGS_JDKLIB_SUFFIX="$LDFLAGS_JDKLIB_SUFFIX -lc"
   743     fi
   745     LDFLAGS_JDKEXE="${LDFLAGS_JDK}"
   746     if test "x$OPENJDK_TARGET_OS" = xlinux; then
   747       LDFLAGS_JDKEXE="$LDFLAGS_JDKEXE -Xlinker --allow-shlib-undefined"
   748     fi
   749     if test "x$TOOLCHAIN_TYPE" = xgcc; then
   750       # Enabling pie on 32 bit builds prevents the JVM from allocating a continuous
   751       # java heap.
   752       if test "x$OPENJDK_TARGET_CPU_BITS" != "x32"; then
   753         LDFLAGS_JDKEXE="$LDFLAGS_JDKEXE -pie"
   754       fi
   755     fi
   756   fi
   757   AC_SUBST(LDFLAGS_JDKLIB)
   758   AC_SUBST(LDFLAGS_JDKEXE)
   759   AC_SUBST(LDFLAGS_JDKLIB_SUFFIX)
   760   AC_SUBST(LDFLAGS_JDKEXE_SUFFIX)
   761   AC_SUBST(LDFLAGS_CXX_JDK)
   762 ])
   765 # FLAGS_C_COMPILER_CHECK_ARGUMENTS([ARGUMENT], [RUN-IF-TRUE],
   766 #                                  [RUN-IF-FALSE])
   767 # ------------------------------------------------------------
   768 # Check that the C compiler supports an argument
   769 AC_DEFUN([FLAGS_C_COMPILER_CHECK_ARGUMENTS],
   770 [
   771   AC_MSG_CHECKING([if the C compiler supports "$1"])
   772   supports=yes
   774   saved_cflags="$CFLAGS"
   775   CFLAGS="$CFLAGS $1"
   776   AC_LANG_PUSH([C])
   777   AC_COMPILE_IFELSE([AC_LANG_SOURCE([[int i;]])], [], 
   778       [supports=no])
   779   AC_LANG_POP([C])
   780   CFLAGS="$saved_cflags"
   782   AC_MSG_RESULT([$supports])
   783   if test "x$supports" = "xyes" ; then
   784     m4_ifval([$2], [$2], [:])
   785   else
   786     m4_ifval([$3], [$3], [:])
   787   fi
   788 ])
   790 # FLAGS_CXX_COMPILER_CHECK_ARGUMENTS([ARGUMENT], [RUN-IF-TRUE],
   791 #                                    [RUN-IF-FALSE])
   792 # ------------------------------------------------------------
   793 # Check that the C++ compiler supports an argument
   794 AC_DEFUN([FLAGS_CXX_COMPILER_CHECK_ARGUMENTS],
   795 [
   796   AC_MSG_CHECKING([if the C++ compiler supports "$1"])
   797   supports=yes
   799   saved_cxxflags="$CXXFLAGS"
   800   CXXFLAGS="$CXXFLAG $1"
   801   AC_LANG_PUSH([C++])
   802   AC_COMPILE_IFELSE([AC_LANG_SOURCE([[int i;]])], [], 
   803       [supports=no])
   804   AC_LANG_POP([C++])
   805   CXXFLAGS="$saved_cxxflags"
   807   AC_MSG_RESULT([$supports])
   808   if test "x$supports" = "xyes" ; then
   809     m4_ifval([$2], [$2], [:])
   810   else
   811     m4_ifval([$3], [$3], [:])
   812   fi
   813 ])
   815 # FLAGS_COMPILER_CHECK_ARGUMENTS([ARGUMENT], [RUN-IF-TRUE],
   816 #                                [RUN-IF-FALSE])
   817 # ------------------------------------------------------------
   818 # Check that the C and C++ compilers support an argument
   819 AC_DEFUN([FLAGS_COMPILER_CHECK_ARGUMENTS],
   820 [
   821   FLAGS_C_COMPILER_CHECK_ARGUMENTS([$1],
   822                        [C_COMP_SUPPORTS="yes"],
   823                        [C_COMP_SUPPORTS="no"])
   824   FLAGS_CXX_COMPILER_CHECK_ARGUMENTS([$1],
   825                      [CXX_COMP_SUPPORTS="yes"],
   826                      [CXX_COMP_SUPPORTS="no"])
   828   AC_MSG_CHECKING([if both compilers support "$1"])
   829   supports=no
   830   if test "x$C_COMP_SUPPORTS" = "xyes" -a "x$CXX_COMP_SUPPORTS" = "xyes"; then supports=yes; fi
   832   AC_MSG_RESULT([$supports])
   833   if test "x$supports" = "xyes" ; then
   834     m4_ifval([$2], [$2], [:])
   835   else
   836     m4_ifval([$3], [$3], [:])
   837   fi
   838 ])
   840 AC_DEFUN_ONCE([FLAGS_SETUP_COMPILER_FLAGS_MISC],
   841 [
   842   # Some Zero and Shark settings.
   843   # ZERO_ARCHFLAG tells the compiler which mode to build for
   844   case "${OPENJDK_TARGET_CPU}" in
   845     s390)
   846       ZERO_ARCHFLAG="${COMPILER_TARGET_BITS_FLAG}31"
   847       ;;
   848     *)
   849       ZERO_ARCHFLAG="${COMPILER_TARGET_BITS_FLAG}${OPENJDK_TARGET_CPU_BITS}"
   850   esac
   851   FLAGS_COMPILER_CHECK_ARGUMENTS([$ZERO_ARCHFLAG], [], [ZERO_ARCHFLAG=""])
   852   AC_SUBST(ZERO_ARCHFLAG)
   854   # Check that the compiler supports -mX (or -qX on AIX) flags
   855   # Set COMPILER_SUPPORTS_TARGET_BITS_FLAG to 'true' if it does
   856   FLAGS_COMPILER_CHECK_ARGUMENTS([${COMPILER_TARGET_BITS_FLAG}${OPENJDK_TARGET_CPU_BITS}],
   857       [COMPILER_SUPPORTS_TARGET_BITS_FLAG=true],
   858       [COMPILER_SUPPORTS_TARGET_BITS_FLAG=false])
   859   AC_SUBST(COMPILER_SUPPORTS_TARGET_BITS_FLAG)
   860 ])
   862 AC_DEFUN_ONCE([FLAGS_SETUP_GCC6_COMPILER_FLAGS],
   863 [
   864   # These flags are required for GCC 6 builds as undefined behaviour in OpenJDK code
   865   # runs afoul of the more aggressive versions of these optimisations.
   866   # Notably, value range propagation now assumes that the this pointer of C++
   867   # member functions is non-null.
   868   NO_DELETE_NULL_POINTER_CHECKS_CFLAG="-fno-delete-null-pointer-checks"
   869   FLAGS_COMPILER_CHECK_ARGUMENTS([$NO_DELETE_NULL_POINTER_CHECKS_CFLAG -Werror],
   870                                      [], [NO_DELETE_NULL_POINTER_CHECKS_CFLAG=""])
   871   AC_SUBST([NO_DELETE_NULL_POINTER_CHECKS_CFLAG])
   872   NO_LIFETIME_DSE_CFLAG="-fno-lifetime-dse"
   873   FLAGS_COMPILER_CHECK_ARGUMENTS([$NO_LIFETIME_DSE_CFLAG -Werror],
   874                                      [], [NO_LIFETIME_DSE_CFLAG=""])
   875   CFLAGS_JDK="${CFLAGS_JDK} ${NO_DELETE_NULL_POINTER_CHECKS_CFLAG} ${NO_LIFETIME_DSE_CFLAG}"
   876   AC_SUBST([NO_LIFETIME_DSE_CFLAG])
   877 ])

mercurial