toolchain.m4 53.5 KB
Newer Older
1
#
2
# Copyright (c) 2011, 2018, Oracle and/or its affiliates. All rights reserved.
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
#
# This code is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 2 only, as
# published by the Free Software Foundation.  Oracle designates this
# particular file as subject to the "Classpath" exception as provided
# by Oracle in the LICENSE file that accompanied this code.
#
# This code is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
# version 2 for more details (a copy is included in the LICENSE file that
# accompanied this code).
#
# You should have received a copy of the GNU General Public License version
# 2 along with this work; if not, write to the Free Software Foundation,
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
# or visit www.oracle.com if you need additional information or have any
# questions.
#

26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
# Prepare the system so that TOOLCHAIN_CHECK_COMPILER_VERSION can be called.
# Must have CC_VERSION_NUMBER and CXX_VERSION_NUMBER.
AC_DEFUN([TOOLCHAIN_PREPARE_FOR_VERSION_COMPARISONS],
[
  if test "x$CC_VERSION" != "x$CXX_VERSION"; then
    AC_MSG_WARN([C and C++ compiler has different version numbers, $CC_VERSION vs $CXX_VERSION.])
    AC_MSG_WARN([This typically indicates a broken setup, and is not supported])
  fi

  # We only check CC_VERSION since we assume CXX_VERSION is equal.
  if [ [[ "$CC_VERSION" =~ (.*\.){3} ]] ]; then
    AC_MSG_WARN([C compiler version number has more than three parts (X.Y.Z): $CC_VERSION. Comparisons might be wrong.])
  fi

  if [ [[  "$CC_VERSION" =~ [0-9]{6} ]] ]; then
    AC_MSG_WARN([C compiler version number has a part larger than 99999: $CC_VERSION. Comparisons might be wrong.])
  fi

  COMPARABLE_ACTUAL_VERSION=`$AWK -F. '{ printf("%05d%05d%05d\n", [$]1, [$]2, [$]3) }' <<< "$CC_VERSION"`
])

# Check if the configured compiler (C and C++) is of a specific version or
# newer. TOOLCHAIN_PREPARE_FOR_VERSION_COMPARISONS must have been called before.
#
# Arguments:
#   $1:   The version string to check against the found version
#   $2:   block to run if the compiler is at least this version (>=)
#   $3:   block to run if the compiler is older than this version (<)
AC_DEFUN([TOOLCHAIN_CHECK_COMPILER_VERSION],
[
  REFERENCE_VERSION=$1

  if [ [[ "$REFERENCE_VERSION" =~ (.*\.){3} ]] ]; then
    AC_MSG_ERROR([Internal error: Cannot compare to $REFERENCE_VERSION, only three parts (X.Y.Z) is supported])
  fi

  if [ [[ "$REFERENCE_VERSION" =~ [0-9]{6} ]] ]; then
    AC_MSG_ERROR([Internal error: Cannot compare to $REFERENCE_VERSION, only parts < 99999 is supported])
  fi

  # Version comparison method inspired by http://stackoverflow.com/a/24067243
  COMPARABLE_REFERENCE_VERSION=`$AWK -F. '{ printf("%05d%05d%05d\n", [$]1, [$]2, [$]3) }' <<< "$REFERENCE_VERSION"`

  if test $COMPARABLE_ACTUAL_VERSION -ge $COMPARABLE_REFERENCE_VERSION ; then
    m4_ifval([$2], [$2], [:])
  else
    m4_ifval([$3], [$3], [:])
  fi
])

O
ohair 已提交
76 77
# $1 = compiler to test (CC or CXX)
# $2 = human readable name of compiler (C or C++)
78
AC_DEFUN([TOOLCHAIN_EXTRACT_COMPILER_VERSION],
79
[
O
ohair 已提交
80 81 82 83 84 85 86 87 88
  COMPILER=[$]$1
  COMPILER_NAME=$2

  if test "x$OPENJDK_TARGET_OS" = xsolaris; then
    # Make sure we use the Sun Studio compiler and not gcc on Solaris, which won't work
    COMPILER_VERSION_TEST=`$COMPILER -V 2>&1 | $HEAD -n 1`
    $ECHO $COMPILER_VERSION_TEST | $GREP "^.*: Sun $COMPILER_NAME" > /dev/null
    if test $? -ne 0; then
      GCC_VERSION_TEST=`$COMPILER --version 2>&1 | $HEAD -n 1`
89

O
ohair 已提交
90 91 92
      AC_MSG_NOTICE([The $COMPILER_NAME compiler (located as $COMPILER) does not seem to be the required Sun Studio compiler.])
      AC_MSG_NOTICE([The result from running with -V was: "$COMPILER_VERSION_TEST" and with --version: "$GCC_VERSION_TEST"])
      AC_MSG_ERROR([Sun Studio compiler is required. Try setting --with-tools-dir.])
93
    else
O
ohair 已提交
94 95
      COMPILER_VERSION=`$ECHO $COMPILER_VERSION_TEST | $SED -n "s/^.*@<:@ ,\t@:>@$COMPILER_NAME@<:@ ,\t@:>@\(@<:@1-9@:>@\.@<:@0-9@:>@@<:@0-9@:>@*\).*/\1/p"`
      COMPILER_VENDOR="Sun Studio"
96
    fi
S
simonis 已提交
97 98 99 100 101 102 103 104 105
  elif test  "x$OPENJDK_TARGET_OS" = xaix; then
      COMPILER_VERSION_TEST=`$COMPILER -qversion  2>&1 | $TAIL -n 1`
      $ECHO $COMPILER_VERSION_TEST | $GREP "^Version: " > /dev/null
      if test $? -ne 0; then
        AC_MSG_ERROR([Failed to detect the compiler version of $COMPILER ....])
      else
        COMPILER_VERSION=`$ECHO $COMPILER_VERSION_TEST | $SED -n 's/Version: \([0-9][0-9]\.[0-9][0-9]*\).*/\1/p'`
        COMPILER_VENDOR='IBM'
      fi
O
ohair 已提交
106 107
  elif test  "x$OPENJDK_TARGET_OS" = xwindows; then
    # First line typically looks something like:
108
    # Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 16.00.40219.01 for 80x86
109
    COMPILER_VERSION_TEST=`$COMPILER 2>&1 | $HEAD -n 1 | $TR -d '\r'`
O
ohair 已提交
110 111 112 113 114 115 116 117 118 119 120
    COMPILER_VERSION=`$ECHO $COMPILER_VERSION_TEST | $SED -n "s/^.*Version \(@<:@1-9@:>@@<:@0-9.@:>@*\) .*/\1/p"`
    COMPILER_VENDOR="Microsoft CL.EXE"
    COMPILER_CPU_TEST=`$ECHO $COMPILER_VERSION_TEST | $SED -n "s/^.* for \(.*\)$/\1/p"`
    if test "x$OPENJDK_TARGET_CPU" = "xx86"; then
      if test "x$COMPILER_CPU_TEST" != "x80x86"; then
        AC_MSG_ERROR([Target CPU mismatch. We are building for $OPENJDK_TARGET_CPU but CL is for "$COMPILER_CPU_TEST"; expected "80x86".])
      fi
    elif test "x$OPENJDK_TARGET_CPU" = "xx86_64"; then
      if test "x$COMPILER_CPU_TEST" != "xx64"; then
        AC_MSG_ERROR([Target CPU mismatch. We are building for $OPENJDK_TARGET_CPU but CL is for "$COMPILER_CPU_TEST"; expected "x64".])
      fi
121
    fi
O
ohair 已提交
122 123 124 125 126 127 128 129 130
  else
    COMPILER_VERSION_TEST=`$COMPILER --version 2>&1 | $HEAD -n 1`
    # Check that this is likely to be GCC.
    $COMPILER --version 2>&1 | $GREP "Free Software Foundation" > /dev/null
    if test $? -ne 0; then
      AC_MSG_NOTICE([The $COMPILER_NAME compiler (located as $COMPILER) does not seem to be the required GCC compiler.])
      AC_MSG_NOTICE([The result from running with --version was: "$COMPILER_VERSION_TEST"])
      AC_MSG_ERROR([GCC compiler is required. Try setting --with-tools-dir.])
    fi
131

O
ohair 已提交
132 133
    # First line typically looks something like:
    # gcc (Ubuntu/Linaro 4.5.2-8ubuntu4) 4.5.2
134 135
    COMPILER_VERSION=`$ECHO $COMPILER_VERSION_TEST | \
        $SED -e 's/^.* \(@<:@1-9@:>@\.@<:@0-9.@:>@*\)@<:@^0-9.@:>@.*$/\1/'`
O
ohair 已提交
136 137 138 139 140 141 142 143
    COMPILER_VENDOR=`$ECHO $COMPILER_VERSION_TEST | $SED -n "s/^\(.*\) @<:@1-9@:>@@<:@0-9.@:>@*/\1/p"`
  fi
  # This sets CC_VERSION or CXX_VERSION. (This comment is a grep marker)
  $1_VERSION="$COMPILER_VERSION"
  # This sets CC_VENDOR or CXX_VENDOR. (This comment is a grep marker)
  $1_VENDOR="$COMPILER_VENDOR"

  AC_MSG_NOTICE([Using $COMPILER_VENDOR $COMPILER_NAME compiler version $COMPILER_VERSION (located at $COMPILER)])
144 145
])

O
ohair 已提交
146

147 148
AC_DEFUN_ONCE([TOOLCHAIN_SETUP_SYSROOT_AND_OUT_OPTIONS],
[
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167
  ###############################################################################
  #
  # Configure the development tool paths and potential sysroot.
  #
  AC_LANG(C++)

  # The option used to specify the target .o,.a or .so file.
  # When compiling, how to specify the to be created object file.
  CC_OUT_OPTION='-o$(SPACE)'
  # When linking, how to specify the to be created executable.
  EXE_OUT_OPTION='-o$(SPACE)'
  # When linking, how to specify the to be created dynamically linkable library.
  LD_OUT_OPTION='-o$(SPACE)'
  # When archiving, how to specify the to be create static archive for object files.
  AR_OUT_OPTION='rcs$(SPACE)'
  AC_SUBST(CC_OUT_OPTION)
  AC_SUBST(EXE_OUT_OPTION)
  AC_SUBST(LD_OUT_OPTION)
  AC_SUBST(AR_OUT_OPTION)
168 169
])

O
ohair 已提交
170 171 172 173
# $1 = compiler to test (CC or CXX)
# $2 = human readable name of compiler (C or C++)
# $3 = list of compiler names to search for
AC_DEFUN([TOOLCHAIN_FIND_COMPILER],
174
[
O
ohair 已提交
175 176
  COMPILER_NAME=$2

177 178 179 180 181 182 183 184 185 186 187
  $1=
  # If TOOLS_DIR is set, check for all compiler names in there first
  # before checking the rest of the PATH.
  if test -n "$TOOLS_DIR"; then
    PATH_save="$PATH"
    PATH="$TOOLS_DIR"
    AC_PATH_PROGS(TOOLS_DIR_$1, $3)
    $1=$TOOLS_DIR_$1
    PATH="$PATH_save"
  fi

O
ohair 已提交
188 189
  # AC_PATH_PROGS can't be run multiple times with the same variable,
  # so create a new name for this run.
190 191 192 193
  if test "x[$]$1" = x; then
    AC_PATH_PROGS(POTENTIAL_$1, $3)
    $1=$POTENTIAL_$1
  fi
O
ohair 已提交
194

195
  if test "x[$]$1" = x; then
196 197
    HELP_MSG_MISSING_DEPENDENCY([devkit])
    AC_MSG_ERROR([Could not find a $COMPILER_NAME compiler. $HELP_MSG])
O
ohair 已提交
198 199 200
  fi
  BASIC_FIXUP_EXECUTABLE($1)
  TEST_COMPILER="[$]$1"
S
simonis 已提交
201 202 203 204 205 206 207
  # Don't remove symbolic links on AIX because 'xlc_r' and 'xlC_r' may all be links
  # to 'xlc' but it is crucial that we invoke the compiler with the right name!
  if test "x$OPENJDK_BUILD_OS" != xaix; then
    AC_MSG_CHECKING([resolved symbolic links for $1])
    BASIC_REMOVE_SYMBOLIC_LINKS(TEST_COMPILER)
    AC_MSG_RESULT([$TEST_COMPILER])
  fi
O
ohair 已提交
208
  AC_MSG_CHECKING([if $1 is disguised ccache])
209

O
ohair 已提交
210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234
  COMPILER_BASENAME=`$BASENAME "$TEST_COMPILER"`
  if test "x$COMPILER_BASENAME" = "xccache"; then
    AC_MSG_RESULT([yes, trying to find proper $COMPILER_NAME compiler])
    # We /usr/lib/ccache in the path, so cc is a symlink to /usr/bin/ccache.
    # We want to control ccache invocation ourselves, so ignore this cc and try
    # searching again.

    # Remove the path to the fake ccache cc from the PATH
    RETRY_COMPILER_SAVED_PATH="$PATH"
    COMPILER_DIRNAME=`$DIRNAME [$]$1`
    PATH="`$ECHO $PATH | $SED -e "s,$COMPILER_DIRNAME,,g" -e "s,::,:,g" -e "s,^:,,g"`"

    # Try again looking for our compiler
    AC_CHECK_TOOLS(PROPER_COMPILER_$1, $3)
    BASIC_FIXUP_EXECUTABLE(PROPER_COMPILER_$1)
    PATH="$RETRY_COMPILER_SAVED_PATH"

    AC_MSG_CHECKING([for resolved symbolic links for $1])
    BASIC_REMOVE_SYMBOLIC_LINKS(PROPER_COMPILER_$1)
    AC_MSG_RESULT([$PROPER_COMPILER_$1])
    $1="$PROPER_COMPILER_$1"
  else
    AC_MSG_RESULT([no, keeping $1])
    $1="$TEST_COMPILER"
  fi
235
  TOOLCHAIN_EXTRACT_COMPILER_VERSION([$1], [$COMPILER_NAME])
O
ohair 已提交
236 237 238 239 240
])


AC_DEFUN([TOOLCHAIN_SETUP_PATHS],
[
241 242
  if test "x$OPENJDK_TARGET_OS" = "xwindows"; then
    TOOLCHAIN_SETUP_VISUAL_STUDIO_ENV
I
ihse 已提交
243
    TOOLCHAIN_SETUP_MSVCR_DLL
244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261
    BASIC_DEPRECATED_ARG_WITH([dxsdk])
    BASIC_DEPRECATED_ARG_WITH([dxsdk-lib])
    BASIC_DEPRECATED_ARG_WITH([dxsdk-include])
  fi

  AC_SUBST(MSVCR_DLL)

  # If --build AND --host is set, then the configure script will find any
  # cross compilation tools in the PATH. Cross compilation tools
  # follows the cross compilation standard where they are prefixed with ${host}.
  # For example the binary i686-sun-solaris2.10-gcc
  # will cross compile for i686-sun-solaris2.10
  # If neither of build and host is not set, then build=host and the
  # default compiler found in the path will be used.
  # Setting only --host, does not seem to be really supported.
  # Please set both --build and --host if you want to cross compile.

  if test "x$COMPILE_TYPE" = "xcross"; then
262 263
    # Now we to find a C/C++ compiler that can build executables for the build
    # platform. We can't use the AC_PROG_CC macro, since it can only be used
264 265 266 267 268
    # once. Also, we need to do this before adding a tools dir to the path,
    # otherwise we might pick up cross-compilers which don't use standard naming.
    # Otherwise, we'll set the BUILD_tools to the native tools, but that'll have
    # to wait until they are properly discovered.
    AC_PATH_PROGS(BUILD_CC, [cl cc gcc])
O
ohair 已提交
269
    BASIC_FIXUP_EXECUTABLE(BUILD_CC)
270
    AC_PATH_PROGS(BUILD_CXX, [cl CC g++])
O
ohair 已提交
271
    BASIC_FIXUP_EXECUTABLE(BUILD_CXX)
272
    AC_PATH_PROG(BUILD_LD, ld)
O
ohair 已提交
273
    BASIC_FIXUP_EXECUTABLE(BUILD_LD)
274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307
  fi
  AC_SUBST(BUILD_CC)
  AC_SUBST(BUILD_CXX)
  AC_SUBST(BUILD_LD)

  # If a devkit is found on the builddeps server, then prepend its path to the
  # PATH variable. If there are cross compilers available in the devkit, these
  # will be found by AC_PROG_CC et al.
  DEVKIT=
  BDEPS_CHECK_MODULE(DEVKIT, devkit, xxx,
      [
        # Found devkit
        PATH="$DEVKIT/bin:$PATH"
        SYS_ROOT="$DEVKIT/${rewritten_target}/sys-root"
        if test "x$x_includes" = "xNONE"; then
          x_includes="$SYS_ROOT/usr/include/X11"
        fi
        if test "x$x_libraries" = "xNONE"; then
          x_libraries="$SYS_ROOT/usr/lib"
        fi
      ],
      [])

  # Store the CFLAGS etal passed to the configure script.
  ORG_CFLAGS="$CFLAGS"
  ORG_CXXFLAGS="$CXXFLAGS"
  ORG_OBJCFLAGS="$OBJCFLAGS"

  # autoconf magic only relies on PATH, so update it if tools dir is specified
  OLD_PATH="$PATH"
  if test "x$TOOLS_DIR" != x; then
    PATH=$TOOLS_DIR:$PATH
  fi

308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387
  # Before we locate the compilers, we need to sanitize the Xcode build environment
  if test "x$OPENJDK_TARGET_OS" = "xmacosx"; then
    # determine path to Xcode developer directory
    # can be empty in which case all the tools will rely on a sane Xcode 4 installation
    SET_DEVELOPER_DIR=

    if test -n "$XCODE_PATH"; then
      DEVELOPER_DIR="$XCODE_PATH"/Contents/Developer
    fi

    # DEVELOPER_DIR could also be provided directly
    AC_MSG_CHECKING([Determining if we need to set DEVELOPER_DIR])
    if test -n "$DEVELOPER_DIR"; then
      if test ! -d "$DEVELOPER_DIR"; then
        AC_MSG_ERROR([Xcode Developer path does not exist: $DEVELOPER_DIR, please provide a path to the Xcode 4 application bundle using --with-xcode-path])
      fi
      if test ! -f "$DEVELOPER_DIR"/usr/bin/xcodebuild; then
        AC_MSG_ERROR([Xcode Developer path is not valid: $DEVELOPER_DIR, it must point to Contents/Developer inside an Xcode application bundle])
      fi
      # make it visible to all the tools immediately
      export DEVELOPER_DIR
      SET_DEVELOPER_DIR="export DEVELOPER_DIR := $DEVELOPER_DIR"
      AC_MSG_RESULT([yes ($DEVELOPER_DIR)])
    else
      AC_MSG_RESULT([no])
    fi
    AC_SUBST(SET_DEVELOPER_DIR)

    AC_PATH_PROG(XCODEBUILD, xcodebuild)
    if test -z "$XCODEBUILD"; then
      AC_MSG_ERROR([The xcodebuild tool was not found, the Xcode command line tools are required to build on Mac OS X])
    fi

    # Fail-fast: verify we're building on Xcode 4, we cannot build with Xcode 5 or later
    XCODE_VERSION=`$XCODEBUILD -version | grep '^Xcode ' | sed 's/Xcode //'`
    XC_VERSION_PARTS=( ${XCODE_VERSION//./ } )
    if test ! "${XC_VERSION_PARTS[[0]]}" = "4"; then
      AC_MSG_ERROR([Xcode 4 is required to build JDK 8, the version found was $XCODE_VERSION. Use --with-xcode-path to specify the location of Xcode 4 or make Xcode 4 active by using xcode-select.])
    fi

    # Some versions of Xcode 5 command line tools install gcc and g++ as symlinks to
    # clang and clang++, which will break the build. So handle that here if we need to.
    if test -L "/usr/bin/gcc" -o -L "/usr/bin/g++"; then
      # use xcrun to find the real gcc and add it's directory to PATH
      # then autoconf magic will find it
      AC_MSG_NOTICE([Found gcc symlinks to clang in /usr/bin, adding path to real gcc to PATH])
      XCODE_BIN_PATH=$(dirname `xcrun -find gcc`)
      PATH="$XCODE_BIN_PATH":$PATH
    fi

    # Determine appropriate SDKPATH, don't use SDKROOT as it interferes with the stub tools
    AC_MSG_CHECKING([Determining Xcode SDK path])
    # allow SDKNAME to be set to override the default SDK selection
    SDKPATH=`"$XCODEBUILD" -sdk ${SDKNAME:-macosx} -version | grep '^Path: ' | sed 's/Path: //'`
    if test -n "$SDKPATH"; then
      AC_MSG_RESULT([$SDKPATH])
    else
      AC_MSG_RESULT([(none, will use system headers and frameworks)])
    fi
    AC_SUBST(SDKPATH)

    # Perform a basic sanity test
    if test ! -f "$SDKPATH/System/Library/Frameworks/Foundation.framework/Headers/Foundation.h"; then
      AC_MSG_ERROR([Unable to find required framework headers, provide a valid path to Xcode 4 using --with-xcode-path])
    fi

    # if SDKPATH is non-empty then we need to add -isysroot and -iframework for gcc and g++
    if test -n "$SDKPATH"; then
      # We need -isysroot <path> and -iframework<path>/System/Library/Frameworks
      CFLAGS_JDK="${CFLAGS_JDK} -isysroot \"$SDKPATH\" -iframework\"$SDKPATH/System/Library/Frameworks\""
      CXXFLAGS_JDK="${CXXFLAGS_JDK} -isysroot \"$SDKPATH\" -iframework\"$SDKPATH/System/Library/Frameworks\""
      LDFLAGS_JDK="${LDFLAGS_JDK} -isysroot \"$SDKPATH\" -iframework\"$SDKPATH/System/Library/Frameworks\""
    fi
    
    # These always need to be set, or we can't find the frameworks embedded in JavaVM.framework
    # setting this here means it doesn't have to be peppered throughout the forest
    CFLAGS_JDK="$CFLAGS_JDK -F\"$SDKPATH/System/Library/Frameworks/JavaVM.framework/Frameworks\""
    CXXFLAGS_JDK="$CXXFLAGS_JDK -F\"$SDKPATH/System/Library/Frameworks/JavaVM.framework/Frameworks\""
    LDFLAGS_JDK="$LDFLAGS_JDK -F\"$SDKPATH/System/Library/Frameworks/JavaVM.framework/Frameworks\""
  fi
388 389 390 391 392 393 394 395 396 397 398 399 400

  ### Locate C compiler (CC)

  # On windows, only cl.exe is supported.
  # On Solaris, cc is preferred to gcc.
  # Elsewhere, gcc is preferred to cc.

  if test "x$CC" != x; then
    COMPILER_CHECK_LIST="$CC"
  elif test "x$OPENJDK_TARGET_OS" = "xwindows"; then
    COMPILER_CHECK_LIST="cl"
  elif test "x$OPENJDK_TARGET_OS" = "xsolaris"; then
    COMPILER_CHECK_LIST="cc gcc"
K
Merge  
kvn 已提交
401 402 403
  elif test "x$OPENJDK_TARGET_OS" = "xaix"; then
    # Do not probe for cc on AIX.
    COMPILER_CHECK_LIST="xlc_r"
404 405 406 407 408 409 410 411
  else
    COMPILER_CHECK_LIST="gcc cc"
  fi

  TOOLCHAIN_FIND_COMPILER([CC],[C],[$COMPILER_CHECK_LIST])
  # Now that we have resolved CC ourself, let autoconf have its go at it
  AC_PROG_CC([$CC])

K
Merge  
kvn 已提交
412 413 414 415 416 417 418 419
  # Option used to tell the compiler whether to create 32- or 64-bit executables
  # Notice that CC contains the full compiler path at this point.
  case $CC in
    *xlc_r) COMPILER_TARGET_BITS_FLAG="-q";;
    *)      COMPILER_TARGET_BITS_FLAG="-m";;
  esac
  AC_SUBST(COMPILER_TARGET_BITS_FLAG)

420 421 422 423 424 425 426 427
  ### Locate C++ compiler (CXX)

  if test "x$CXX" != x; then
    COMPILER_CHECK_LIST="$CXX"
  elif test "x$OPENJDK_TARGET_OS" = "xwindows"; then
    COMPILER_CHECK_LIST="cl"
  elif test "x$OPENJDK_TARGET_OS" = "xsolaris"; then
    COMPILER_CHECK_LIST="CC g++"
K
Merge  
kvn 已提交
428 429 430
  elif test "x$OPENJDK_TARGET_OS" = "xaix"; then
    # Do not probe for CC on AIX .
    COMPILER_CHECK_LIST="xlC_r"
431 432 433 434 435 436 437 438
  else
    COMPILER_CHECK_LIST="g++ CC"
  fi

  TOOLCHAIN_FIND_COMPILER([CXX],[C++],[$COMPILER_CHECK_LIST])
  # Now that we have resolved CXX ourself, let autoconf have its go at it
  AC_PROG_CXX([$CXX])

439 440 441 442 443 444
  # This is the compiler version number on the form X.Y[.Z]
  AC_SUBST(CC_VERSION)
  AC_SUBST(CXX_VERSION)

  TOOLCHAIN_PREPARE_FOR_VERSION_COMPARISONS

445 446 447
  ### Locate other tools

  if test "x$OPENJDK_TARGET_OS" = xmacosx; then
448
    AC_PROG_OBJC
O
ohair 已提交
449
    BASIC_FIXUP_EXECUTABLE(OBJC)
450
  else
451
    OBJC=
452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472
  fi

  # Restore the flags to the user specified values.
  # This is necessary since AC_PROG_CC defaults CFLAGS to "-g -O2"
  CFLAGS="$ORG_CFLAGS"
  CXXFLAGS="$ORG_CXXFLAGS"
  OBJCFLAGS="$ORG_OBJCFLAGS"

  LD="$CC"
  LDEXE="$CC"
  LDCXX="$CXX"
  LDEXECXX="$CXX"
  AC_SUBST(LD)
  # LDEXE is the linker to use, when creating executables.
  AC_SUBST(LDEXE)
  # Linking C++ libraries.
  AC_SUBST(LDCXX)
  # Linking C++ executables.
  AC_SUBST(LDEXECXX)

  if test "x$OPENJDK_TARGET_OS" != xwindows; then
473
    AC_CHECK_TOOL(AR, ar)
O
ohair 已提交
474
    BASIC_FIXUP_EXECUTABLE(AR)
475 476
  fi
  if test "x$OPENJDK_TARGET_OS" = xmacosx; then
477
    ARFLAGS="-r"
K
Merge  
kvn 已提交
478
  elif test "x$OPENJDK_TARGET_OS" = xaix; then
S
simonis 已提交
479
    ARFLAGS="-X64"
480
  else
481
    ARFLAGS=""
482 483 484 485 486 487 488 489 490 491 492 493
  fi
  AC_SUBST(ARFLAGS)

  # For hotspot, we need these in Windows mixed path; other platforms keep them the same
  HOTSPOT_CXX="$CXX"
  HOTSPOT_LD="$LD"
  AC_SUBST(HOTSPOT_CXX)
  AC_SUBST(HOTSPOT_LD)

  COMPILER_NAME=gcc
  COMPILER_TYPE=CC
  AS_IF([test "x$OPENJDK_TARGET_OS" = xwindows], [
494
    # For now, assume that we are always compiling using cl.exe.
495 496 497 498
    CC_OUT_OPTION=-Fo
    EXE_OUT_OPTION=-out:
    LD_OUT_OPTION=-out:
    AR_OUT_OPTION=-out:
499
    # On Windows, reject /usr/bin/link (as determined in CYGWIN_LINK), which is a cygwin
500
    # program for something completely different.
501
    AC_CHECK_PROG([WINLD], [link],[link],,, [$CYGWIN_LINK])
502 503
    # Since we must ignore the first found link, WINLD will contain
    # the full path to the link.exe program.
O
ohair 已提交
504
    BASIC_FIXUP_EXECUTABLE(WINLD)
505 506 507 508 509 510 511 512 513
    printf "Windows linker was found at $WINLD\n"
    AC_MSG_CHECKING([if the found link.exe is actually the Visual Studio linker])
    "$WINLD" --version > /dev/null
    if test $? -eq 0 ; then
      AC_MSG_RESULT([no])
      AC_MSG_ERROR([This is the Cygwin link tool. Please check your PATH and rerun configure.])
    else
      AC_MSG_RESULT([yes])
    fi
514 515 516 517 518 519
    LD="$WINLD"
    LDEXE="$WINLD"
    LDCXX="$WINLD"
    LDEXECXX="$WINLD"

    AC_CHECK_PROG([MT], [mt], [mt],,, [/usr/bin/mt])
O
ohair 已提交
520
    BASIC_FIXUP_EXECUTABLE(MT)
521 522
    # The resource compiler
    AC_CHECK_PROG([RC], [rc], [rc],,, [/usr/bin/rc])
O
ohair 已提交
523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538
    BASIC_FIXUP_EXECUTABLE(RC)

    # For hotspot, we need these in Windows mixed path,
    # so rewrite them all. Need added .exe suffix.
    HOTSPOT_CXX="$CXX.exe"
    HOTSPOT_LD="$LD.exe"
    HOTSPOT_MT="$MT.exe"
    HOTSPOT_RC="$RC.exe"
    BASIC_WINDOWS_REWRITE_AS_WINDOWS_MIXED_PATH(HOTSPOT_CXX)
    BASIC_WINDOWS_REWRITE_AS_WINDOWS_MIXED_PATH(HOTSPOT_LD)
    BASIC_WINDOWS_REWRITE_AS_WINDOWS_MIXED_PATH(HOTSPOT_MT)
    BASIC_WINDOWS_REWRITE_AS_WINDOWS_MIXED_PATH(HOTSPOT_RC)
    AC_SUBST(HOTSPOT_MT)
    AC_SUBST(HOTSPOT_RC)

    RC_FLAGS="-nologo -l 0x409 -r"
539
    AS_IF([test "x$VARIANT" = xOPT], [
540 541 542 543 544 545 546 547 548 549 550 551
    RC_FLAGS="$RC_FLAGS -d NDEBUG"
  ])

  # The version variables used to create RC_FLAGS may be overridden
  # in a custom configure script, or possibly the command line.
  # Let those variables be expanded at make time in spec.gmk.
  # The \$ are escaped to the shell, and the $(...) variables
  # are evaluated by make.
  RC_FLAGS="$RC_FLAGS \
      -d \"JDK_BUILD_ID=\$(FULL_VERSION)\" \
      -d \"JDK_COMPANY=\$(COMPANY_NAME)\" \
      -d \"JDK_COMPONENT=\$(PRODUCT_NAME) \$(JDK_RC_PLATFORM_NAME) binary\" \
552
      -d \"JDK_VER=\$(JDK_MINOR_VERSION).\$(JDK_MICRO_VERSION).\$(COOKED_JDK_UPDATE_VERSION).\$(COOKED_BUILD_NUMBER)\" \
553 554
      -d \"JDK_COPYRIGHT=Copyright \xA9 $COPYRIGHT_YEAR\" \
      -d \"JDK_NAME=\$(PRODUCT_NAME) \$(JDK_RC_PLATFORM_NAME) \$(JDK_MINOR_VERSION) \$(JDK_UPDATE_META_TAG)\" \
555
      -d \"JDK_FVER=\$(JDK_MINOR_VERSION),\$(JDK_MICRO_VERSION),\$(COOKED_JDK_UPDATE_VERSION),\$(COOKED_BUILD_NUMBER)\""
556 557 558 559 560 561 562 563 564 565 566

  # lib.exe is used to create static libraries.
  AC_CHECK_PROG([WINAR], [lib],[lib],,,)
  BASIC_FIXUP_EXECUTABLE(WINAR)
  AR="$WINAR"
  ARFLAGS="-nologo -NODEFAULTLIB:MSVCRT"

  AC_CHECK_PROG([DUMPBIN], [dumpbin], [dumpbin],,,)
      BASIC_FIXUP_EXECUTABLE(DUMPBIN)

      COMPILER_TYPE=CL
567 568
      # silence copyright notice and other headers.
      COMMON_CCXXFLAGS="$COMMON_CCXXFLAGS -nologo"
569 570 571 572 573 574 575 576 577 578 579
  ])
  AC_SUBST(RC_FLAGS)
  AC_SUBST(COMPILER_TYPE)

  AC_PROG_CPP
  BASIC_FIXUP_EXECUTABLE(CPP)

  AC_PROG_CXXCPP
  BASIC_FIXUP_EXECUTABLE(CXXCPP)

  if test "x$COMPILE_TYPE" != "xcross"; then
580 581 582 583 584 585 586
    # If we are not cross compiling, use the same compilers for
    # building the build platform executables. The cross-compilation
    # case needed to be done earlier, but this can only be done after
    # the native tools have been localized.
    BUILD_CC="$CC"
    BUILD_CXX="$CXX"
    BUILD_LD="$LD"
587
  fi
588

589 590 591 592 593 594 595
  # for solaris we really need solaris tools, and not gnu equivalent
  #   these seems to normally reside in /usr/ccs/bin so add that to path before
  #   starting to probe
  #
  #   NOTE: I add this /usr/ccs/bin after TOOLS but before OLD_PATH
  #         so that it can be overriden --with-tools-dir
  if test "x$OPENJDK_BUILD_OS" = xsolaris; then
596
    PATH="${TOOLS_DIR}:/usr/ccs/bin:${OLD_PATH}"
597
  fi
598

599 600
  # Find the right assembler.
  if test "x$OPENJDK_TARGET_OS" = xsolaris; then
601
    AC_PATH_PROG(AS, as)
O
ohair 已提交
602
    BASIC_FIXUP_EXECUTABLE(AS)
603
  else
604
    AS="$CC -c"
605 606
  fi
  AC_SUBST(AS)
607

608
  if test "x$OPENJDK_TARGET_OS" = xsolaris; then
609
    AC_PATH_PROG(NM, nm)
O
ohair 已提交
610
    BASIC_FIXUP_EXECUTABLE(NM)
611 612
    AC_PATH_PROG(GNM, gnm)
    BASIC_FIXUP_EXECUTABLE(GNM)
613
    AC_PATH_PROG(STRIP, strip)
O
ohair 已提交
614
    BASIC_FIXUP_EXECUTABLE(STRIP)
615
    AC_PATH_PROG(MCS, mcs)
O
ohair 已提交
616
    BASIC_FIXUP_EXECUTABLE(MCS)
617
  elif test "x$OPENJDK_TARGET_OS" != xwindows; then
618 619 620 621
    AC_PATH_PROG(OTOOL, otool)
    if test "x$OTOOL" = "x"; then
      OTOOL="true"
    fi
622
    AC_CHECK_TOOL(NM, nm)
O
ohair 已提交
623
    BASIC_FIXUP_EXECUTABLE(NM)
624 625
    GNM="$NM"
    AC_SUBST(GNM)
626
    AC_CHECK_TOOL(STRIP, strip)
O
ohair 已提交
627
    BASIC_FIXUP_EXECUTABLE(STRIP)
628
  fi
629

630 631 632
  # objcopy is used for moving debug symbols to separate files when
  # full debug symbols are enabled.
  if test "x$OPENJDK_TARGET_OS" = xsolaris || test "x$OPENJDK_TARGET_OS" = xlinux; then
O
ohair 已提交
633
    AC_CHECK_TOOLS(OBJCOPY, [gobjcopy objcopy])
634 635
    # Only call fixup if objcopy was found.
    if test -n "$OBJCOPY"; then
636
      BASIC_FIXUP_EXECUTABLE(OBJCOPY)
637
    fi
638
  fi
O
ohair 已提交
639

640 641 642 643 644
  AC_CHECK_TOOLS(OBJDUMP, [gobjdump objdump])
  if test "x$OBJDUMP" != x; then
    # Only used for compare.sh; we can live without it. BASIC_FIXUP_EXECUTABLE bails if argument is missing.
    BASIC_FIXUP_EXECUTABLE(OBJDUMP)
  fi
645

646
  TOOLCHAIN_SETUP_JTREG
647

648 649
  # Restore old path without tools dir
  PATH="$OLD_PATH"
650 651 652 653 654 655
])


AC_DEFUN_ONCE([TOOLCHAIN_SETUP_COMPILER_FLAGS_FOR_LIBS],
[

656 657 658 659
  ###############################################################################
  #
  # How to compile shared libraries.
  #
660

661
  if test "x$GCC" = xyes; then
662 663 664 665 666 667 668 669 670 671 672 673 674 675
    COMPILER_NAME=gcc
    PICFLAG="-fPIC"
    LIBRARY_PREFIX=lib
    SHARED_LIBRARY='lib[$]1.so'
    STATIC_LIBRARY='lib[$]1.a'
    SHARED_LIBRARY_FLAGS="-shared"
    SHARED_LIBRARY_SUFFIX='.so'
    STATIC_LIBRARY_SUFFIX='.a'
    OBJ_SUFFIX='.o'
    EXE_SUFFIX=''
    SET_SHARED_LIBRARY_NAME='-Xlinker -soname=[$]1'
    SET_SHARED_LIBRARY_MAPFILE='-Xlinker -version-script=[$]1'
    C_FLAG_REORDER=''
    CXX_FLAG_REORDER=''
676 677
    SET_SHARED_LIBRARY_ORIGIN='-Xlinker -z -Xlinker origin -Xlinker -rpath -Xlinker \$$$$ORIGIN[$]1'
    SET_EXECUTABLE_ORIGIN='-Xlinker -rpath -Xlinker \$$$$ORIGIN[$]1'
678 679 680 681 682 683 684
    LD="$CC"
    LDEXE="$CC"
    LDCXX="$CXX"
    LDEXECXX="$CXX"
    POST_STRIP_CMD="$STRIP -g"

    # Linking is different on MacOSX
O
ohair 已提交
685
    if test "x$OPENJDK_TARGET_OS" = xmacosx; then
686 687 688 689 690 691 692 693 694 695 696
      # Might change in the future to clang.
      COMPILER_NAME=gcc
      SHARED_LIBRARY='lib[$]1.dylib'
      SHARED_LIBRARY_FLAGS="-dynamiclib -compatibility_version 1.0.0 -current_version 1.0.0 $PICFLAG"
      SHARED_LIBRARY_SUFFIX='.dylib'
      EXE_SUFFIX=''
      SET_SHARED_LIBRARY_NAME='-Xlinker -install_name -Xlinker @rpath/[$]1'
      SET_SHARED_LIBRARY_MAPFILE=''
      SET_SHARED_LIBRARY_ORIGIN='-Xlinker -rpath -Xlinker @loader_path/.'
      SET_EXECUTABLE_ORIGIN="$SET_SHARED_LIBRARY_ORIGIN"
      POST_STRIP_CMD="$STRIP -S"
697
    fi
698
  else
O
ohair 已提交
699
    if test "x$OPENJDK_TARGET_OS" = xsolaris; then
700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721
      # If it is not gcc, then assume it is the Oracle Solaris Studio Compiler
      COMPILER_NAME=ossc
      PICFLAG="-KPIC"
      LIBRARY_PREFIX=lib
      SHARED_LIBRARY='lib[$]1.so'
      STATIC_LIBRARY='lib[$]1.a'
      SHARED_LIBRARY_FLAGS="-G"
      SHARED_LIBRARY_SUFFIX='.so'
      STATIC_LIBRARY_SUFFIX='.a'
      OBJ_SUFFIX='.o'
      EXE_SUFFIX=''
      SET_SHARED_LIBRARY_NAME=''
      SET_SHARED_LIBRARY_MAPFILE='-M[$]1'
      C_FLAG_REORDER='-xF'
      CXX_FLAG_REORDER='-xF'
      SET_SHARED_LIBRARY_ORIGIN='-R\$$$$ORIGIN[$]1'
      SET_EXECUTABLE_ORIGIN="$SET_SHARED_LIBRARY_ORIGIN"
      CFLAGS_JDK="${CFLAGS_JDK} -D__solaris__"
      CXXFLAGS_JDK="${CXXFLAGS_JDK} -D__solaris__"
      CFLAGS_JDKLIB_EXTRA='-xstrconst'
      POST_STRIP_CMD="$STRIP -x"
      POST_MCS_CMD="$MCS -d -a \"JDK $FULL_VERSION\""
722
    fi
S
simonis 已提交
723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745
    if test "x$OPENJDK_TARGET_OS" = xaix; then
        COMPILER_NAME=xlc
        PICFLAG="-qpic=large"
        LIBRARY_PREFIX=lib
        SHARED_LIBRARY='lib[$]1.so'
        STATIC_LIBRARY='lib[$]1.a'
        SHARED_LIBRARY_FLAGS="-qmkshrobj"
        SHARED_LIBRARY_SUFFIX='.so'
        STATIC_LIBRARY_SUFFIX='.a'
        OBJ_SUFFIX='.o'
        EXE_SUFFIX=''
        SET_SHARED_LIBRARY_NAME=''
        SET_SHARED_LIBRARY_MAPFILE=''
        C_FLAG_REORDER=''
        CXX_FLAG_REORDER=''
        SET_SHARED_LIBRARY_ORIGIN=''
        SET_EXECUTABLE_ORIGIN=""
        CFLAGS_JDK=""
        CXXFLAGS_JDK=""
        CFLAGS_JDKLIB_EXTRA=''
        POST_STRIP_CMD="$STRIP -X32_64"
        POST_MCS_CMD=""
    fi
O
ohair 已提交
746
    if test "x$OPENJDK_TARGET_OS" = xwindows; then
747 748 749 750 751 752 753 754 755 756 757 758 759 760 761
      # If it is not gcc, then assume it is the MS Visual Studio compiler
      COMPILER_NAME=cl
      PICFLAG=""
      LIBRARY_PREFIX=
      SHARED_LIBRARY='[$]1.dll'
      STATIC_LIBRARY='[$]1.lib'
      SHARED_LIBRARY_FLAGS="-LD"
      SHARED_LIBRARY_SUFFIX='.dll'
      STATIC_LIBRARY_SUFFIX='.lib'
      OBJ_SUFFIX='.obj'
      EXE_SUFFIX='.exe'
      SET_SHARED_LIBRARY_NAME=''
      SET_SHARED_LIBRARY_MAPFILE=''
      SET_SHARED_LIBRARY_ORIGIN=''
      SET_EXECUTABLE_ORIGIN=''
762
    fi
763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784
  fi

  AC_SUBST(COMPILER_NAME)
  AC_SUBST(OBJ_SUFFIX)
  AC_SUBST(SHARED_LIBRARY)
  AC_SUBST(STATIC_LIBRARY)
  AC_SUBST(LIBRARY_PREFIX)
  AC_SUBST(SHARED_LIBRARY_SUFFIX)
  AC_SUBST(STATIC_LIBRARY_SUFFIX)
  AC_SUBST(EXE_SUFFIX)
  AC_SUBST(SHARED_LIBRARY_FLAGS)
  AC_SUBST(SET_SHARED_LIBRARY_NAME)
  AC_SUBST(SET_SHARED_LIBRARY_MAPFILE)
  AC_SUBST(C_FLAG_REORDER)
  AC_SUBST(CXX_FLAG_REORDER)
  AC_SUBST(SET_SHARED_LIBRARY_ORIGIN)
  AC_SUBST(SET_EXECUTABLE_ORIGIN)
  AC_SUBST(POST_STRIP_CMD)
  AC_SUBST(POST_MCS_CMD)

  # The (cross) compiler is now configured, we can now test capabilities
  # of the target platform.
785 786 787 788 789
])

AC_DEFUN_ONCE([TOOLCHAIN_SETUP_COMPILER_FLAGS_FOR_OPTIMIZATION],
[

790 791 792 793 794
  ###############################################################################
  #
  # Setup the opt flags for different compilers
  # and different operating systems.
  #
795

796 797 798 799
  #
  # NOTE: check for -mstackrealign needs to be below potential addition of -m32
  #
  if test "x$OPENJDK_TARGET_CPU_BITS" = x32 && test "x$OPENJDK_TARGET_OS" = xmacosx; then
800 801 802 803 804
    # On 32-bit MacOSX the OS requires C-entry points to be 16 byte aligned.
    # While waiting for a better solution, the current workaround is to use -mstackrealign.
    CFLAGS="$CFLAGS -mstackrealign"
    AC_MSG_CHECKING([if 32-bit compiler supports -mstackrealign])
    AC_LINK_IFELSE([AC_LANG_SOURCE([[int main() { return 0; }]])],
805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841
        [
          AC_MSG_RESULT([yes])
        ],
        [
          AC_MSG_RESULT([no])
          AC_MSG_ERROR([The selected compiler $CXX does not support -mstackrealign! Try to put another compiler in the path.])
        ]
    )
  fi

  C_FLAG_DEPS="-MMD -MF"
  CXX_FLAG_DEPS="-MMD -MF"

  case $COMPILER_TYPE in
    CC )
      case $COMPILER_NAME in
        gcc )
          case $OPENJDK_TARGET_OS in
            macosx )
              # On MacOSX we optimize for size, something
              # we should do for all platforms?
              C_O_FLAG_HI="-Os"
              C_O_FLAG_NORM="-Os"
              C_O_FLAG_NONE=""
              ;;
            *)
              C_O_FLAG_HI="-O3"
              C_O_FLAG_NORM="-O2"
              C_O_FLAG_NONE="-O0"
              ;;
          esac
          CXX_O_FLAG_HI="$C_O_FLAG_HI"
          CXX_O_FLAG_NORM="$C_O_FLAG_NORM"
          CXX_O_FLAG_NONE="$C_O_FLAG_NONE"
          CFLAGS_DEBUG_SYMBOLS="-g"
          CXXFLAGS_DEBUG_SYMBOLS="-g"
          if test "x$OPENJDK_TARGET_CPU_BITS" = "x64" && test "x$DEBUG_LEVEL" = "xfastdebug"; then
842 843
            CFLAGS_DEBUG_SYMBOLS="-g1"
            CXXFLAGS_DEBUG_SYMBOLS="-g1"
844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889
          fi
          ;;
        ossc )
          #
          # Forte has different names for this with their C++ compiler...
          #
          C_FLAG_DEPS="-xMMD -xMF"
          CXX_FLAG_DEPS="-xMMD -xMF"

          # Extra options used with HIGHEST
          #
          # WARNING: Use of OPTIMIZATION_LEVEL=HIGHEST in your Makefile needs to be
          #          done with care, there are some assumptions below that need to
          #          be understood about the use of pointers, and IEEE behavior.
          #
          # Use non-standard floating point mode (not IEEE 754)
          CC_HIGHEST="$CC_HIGHEST -fns"
          # Do some simplification of floating point arithmetic (not IEEE 754)
          CC_HIGHEST="$CC_HIGHEST -fsimple"
          # Use single precision floating point with 'float'
          CC_HIGHEST="$CC_HIGHEST -fsingle"
          # Assume memory references via basic pointer types do not alias
          #   (Source with excessing pointer casting and data access with mixed
          #    pointer types are not recommended)
          CC_HIGHEST="$CC_HIGHEST -xalias_level=basic"
          # Use intrinsic or inline versions for math/std functions
          #   (If you expect perfect errno behavior, do not use this)
          CC_HIGHEST="$CC_HIGHEST -xbuiltin=%all"
          # Loop data dependency optimizations (need -xO3 or higher)
          CC_HIGHEST="$CC_HIGHEST -xdepend"
          # Pointer parameters to functions do not overlap
          #   (Similar to -xalias_level=basic usage, but less obvious sometimes.
          #    If you pass in multiple pointers to the same data, do not use this)
          CC_HIGHEST="$CC_HIGHEST -xrestrict"
          # Inline some library routines
          #   (If you expect perfect errno behavior, do not use this)
          CC_HIGHEST="$CC_HIGHEST -xlibmil"
          # Use optimized math routines
          #   (If you expect perfect errno behavior, do not use this)
          #  Can cause undefined external on Solaris 8 X86 on __sincos, removing for now
          #CC_HIGHEST="$CC_HIGHEST -xlibmopt"

          if test "x$OPENJDK_TARGET_CPU" = xsparc; then
            CFLAGS_JDK="${CFLAGS_JDK} -xmemalign=4s"
            CXXFLAGS_JDK="${CXXFLAGS_JDK} -xmemalign=4s"
          fi
890

891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918
          case $OPENJDK_TARGET_CPU_ARCH in
            x86)
              C_O_FLAG_HIGHEST="-xO4 -Wu,-O4~yz $CC_HIGHEST -xregs=no%frameptr"
              C_O_FLAG_HI="-xO4 -Wu,-O4~yz -xregs=no%frameptr"
              C_O_FLAG_NORM="-xO2 -Wu,-O2~yz -xregs=no%frameptr"
              C_O_FLAG_NONE="-xregs=no%frameptr"
              CXX_O_FLAG_HIGHEST="-xO4 -Qoption ube -O4~yz $CC_HIGHEST -xregs=no%frameptr"
              CXX_O_FLAG_HI="-xO4 -Qoption ube -O4~yz -xregs=no%frameptr"
              CXX_O_FLAG_NORM="-xO2 -Qoption ube -O2~yz -xregs=no%frameptr"
              CXX_O_FLAG_NONE="-xregs=no%frameptr"
              if test "x$OPENJDK_TARGET_CPU" = xx86; then
                C_O_FLAG_HIGHEST="$C_O_FLAG_HIGHEST -xchip=pentium"
                CXX_O_FLAG_HIGHEST="$CXX_O_FLAG_HIGHEST -xchip=pentium"
              fi
              ;;
            sparc)
              CFLAGS_JDKLIB_EXTRA="${CFLAGS_JDKLIB_EXTRA} -xregs=no%appl"
              CXXFLAGS_JDKLIB_EXTRA="${CXXFLAGS_JDKLIB_EXTRA} -xregs=no%appl"
              C_O_FLAG_HIGHEST="-xO4 -Wc,-Qrm-s -Wc,-Qiselect-T0 $CC_HIGHEST -xprefetch=auto,explicit -xchip=ultra"
              C_O_FLAG_HI="-xO4 -Wc,-Qrm-s -Wc,-Qiselect-T0"
              C_O_FLAG_NORM="-xO2 -Wc,-Qrm-s -Wc,-Qiselect-T0"
              C_O_FLAG_NONE=""
              CXX_O_FLAG_HIGHEST="-xO4 -Qoption cg -Qrm-s -Qoption cg -Qiselect-T0 $CC_HIGHEST -xprefetch=auto,explicit -xchip=ultra"
              CXX_O_FLAG_HI="-xO4 -Qoption cg -Qrm-s -Qoption cg -Qiselect-T0"
              CXX_O_FLAG_NORM="-xO2 -Qoption cg -Qrm-s -Qoption cg -Qiselect-T0"
              CXX_O_FLAG_NONE=""
              ;;
          esac
919

920 921
          CFLAGS_DEBUG_SYMBOLS="-g -xs"
          CXXFLAGS_DEBUG_SYMBOLS="-g0 -xs"
K
Merge  
kvn 已提交
922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939
          ;;
        xlc )
          C_FLAG_DEPS="-qmakedep=gcc -MF"
          CXX_FLAG_DEPS="-qmakedep=gcc -MF"
          C_O_FLAG_HIGHEST="-O3"
          C_O_FLAG_HI="-O3 -qstrict"
          C_O_FLAG_NORM="-O2"
          C_O_FLAG_NONE=""
          CXX_O_FLAG_HIGHEST="-O3"
          CXX_O_FLAG_HI="-O3 -qstrict"
          CXX_O_FLAG_NORM="-O2"
          CXX_O_FLAG_NONE=""
          CFLAGS_DEBUG_SYMBOLS="-g"
          CXXFLAGS_DEBUG_SYMBOLS="-g"
          LDFLAGS_JDK="${LDFLAGS_JDK} -q64 -brtl -bnolibpath -liconv -bexpall"
          CFLAGS_JDK="${CFLAGS_JDK} -qchars=signed -q64 -qfullpath -qsaveopt"
          CXXFLAGS_JDK="${CXXFLAGS_JDK} -qchars=signed -q64 -qfullpath -qsaveopt"
          ;;
940 941 942 943 944 945 946 947 948 949 950 951 952
      esac
      ;;
    CL )
      C_O_FLAG_HIGHEST="-O2"
      C_O_FLAG_HI="-O1"
      C_O_FLAG_NORM="-O1"
      C_O_FLAG_NONE="-Od"
      CXX_O_FLAG_HIGHEST="$C_O_FLAG_HIGHEST"
      CXX_O_FLAG_HI="$C_O_FLAG_HI"
      CXX_O_FLAG_NORM="$C_O_FLAG_NORM"
      CXX_O_FLAG_NONE="$C_O_FLAG_NONE"
      ;;
  esac
953

954 955 956
  if test -z "$C_O_FLAG_HIGHEST"; then
    C_O_FLAG_HIGHEST="$C_O_FLAG_HI"
  fi
957

958 959 960
  if test -z "$CXX_O_FLAG_HIGHEST"; then
    CXX_O_FLAG_HIGHEST="$CXX_O_FLAG_HI"
  fi
961

962 963 964 965 966 967 968 969 970 971 972
  AC_SUBST(C_O_FLAG_HIGHEST)
  AC_SUBST(C_O_FLAG_HI)
  AC_SUBST(C_O_FLAG_NORM)
  AC_SUBST(C_O_FLAG_NONE)
  AC_SUBST(CXX_O_FLAG_HIGHEST)
  AC_SUBST(CXX_O_FLAG_HI)
  AC_SUBST(CXX_O_FLAG_NORM)
  AC_SUBST(CXX_O_FLAG_NONE)
  AC_SUBST(C_FLAG_DEPS)
  AC_SUBST(CXX_FLAG_DEPS)
])
973

974 975
AC_DEFUN_ONCE([TOOLCHAIN_SETUP_COMPILER_FLAGS_FOR_JDK],
[
976

977 978 979
  if test "x$CFLAGS" != "x${ADDED_CFLAGS}"; then
    AC_MSG_WARN([Ignoring CFLAGS($CFLAGS) found in environment. Use --with-extra-cflags])
  fi
980

981 982 983
  if test "x$CXXFLAGS" != "x${ADDED_CXXFLAGS}"; then
    AC_MSG_WARN([Ignoring CXXFLAGS($CXXFLAGS) found in environment. Use --with-extra-cxxflags])
  fi
984

985 986 987
  if test "x$LDFLAGS" != "x${ADDED_LDFLAGS}"; then
    AC_MSG_WARN([Ignoring LDFLAGS($LDFLAGS) found in environment. Use --with-extra-ldflags])
  fi
988

989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014
  AC_ARG_WITH(extra-cflags, [AS_HELP_STRING([--with-extra-cflags],
      [extra flags to be used when compiling jdk c-files])])

  AC_ARG_WITH(extra-cxxflags, [AS_HELP_STRING([--with-extra-cxxflags],
      [extra flags to be used when compiling jdk c++-files])])

  AC_ARG_WITH(extra-ldflags, [AS_HELP_STRING([--with-extra-ldflags],
      [extra flags to be used when linking jdk])])

  CFLAGS_JDK="${CFLAGS_JDK} $with_extra_cflags"
  CXXFLAGS_JDK="${CXXFLAGS_JDK} $with_extra_cxxflags"
  LDFLAGS_JDK="${LDFLAGS_JDK} $with_extra_ldflags"

  # Hotspot needs these set in their legacy form
  LEGACY_EXTRA_CFLAGS=$with_extra_cflags
  LEGACY_EXTRA_CXXFLAGS=$with_extra_cxxflags
  LEGACY_EXTRA_LDFLAGS=$with_extra_ldflags

  AC_SUBST(LEGACY_EXTRA_CFLAGS)
  AC_SUBST(LEGACY_EXTRA_CXXFLAGS)
  AC_SUBST(LEGACY_EXTRA_LDFLAGS)

  ###############################################################################
  #
  # Now setup the CFLAGS and LDFLAGS for the JDK build.
  # Later we will also have CFLAGS and LDFLAGS for the hotspot subrepo build.
1015 1016 1017
  #    CFLAGS_JDK    - C Compiler flags
  #    CXXFLAGS_JDK  - C++ Compiler flags
  #    COMMON_CCXXFLAGS_JDK - common to C and C++
1018 1019 1020
  #
  case $COMPILER_NAME in
    gcc )
1021
      COMMON_CCXXFLAGS_JDK="$COMMON_CCXXFLAGS $COMMON_CCXXFLAGS_JDK -W -Wall -Wno-unused -Wno-parentheses \
1022 1023
      -pipe \
      -D_GNU_SOURCE -D_REENTRANT -D_LARGEFILE64_SOURCE"
1024 1025 1026 1027 1028
      CXXSTD_CXXFLAG="-std=gnu++98"
      TOOLCHAIN_CXX_COMPILER_CHECK_ARGUMENTS([$CXXSTD_CXXFLAG $CFLAGS_WARNINGS_ARE_ERRORS],
    					     [], [CXXSTD_CXXFLAG=""])
      CXXFLAGS_JDK="${CXXFLAGS_JDK} ${CXXSTD_CXXFLAG}"
      AC_SUBST([CXXSTD_CXXFLAG])
1029 1030 1031 1032
      case $OPENJDK_TARGET_CPU_ARCH in
        arm )
          # on arm we don't prevent gcc to omit frame pointer but do prevent strict aliasing
          CFLAGS_JDK="${CFLAGS_JDK} -fno-strict-aliasing"
1033
          ;;
1034 1035
        ppc )
          # on ppc we don't prevent gcc to omit frame pointer nor strict-aliasing
1036
          ;;
1037
        * )
1038
          COMMON_CCXXFLAGS_JDK="$COMMON_CCXXFLAGS_JDK -fno-omit-frame-pointer"
1039
          CFLAGS_JDK="${CFLAGS_JDK} -fno-strict-aliasing"
1040
          ;;
1041
      esac
1042
      TOOLCHAIN_CHECK_COMPILER_VERSION(6, TOOLCHAIN_SETUP_GCC6_COMPILER_FLAGS)
1043 1044
      ;;
    ossc )
1045
      COMMON_CCXXFLAGS_JDK="$COMMON_CCXXFLAGS $COMMON_CCXXFLAGS_JDK -DTRACING -DMACRO_MEMSYS_OPS -DBREAKPTS"
1046 1047
      case $OPENJDK_TARGET_CPU_ARCH in
        x86 )
1048
          COMMON_CCXXFLAGS_JDK="$COMMON_CCXXFLAGS_JDK -DcpuIntel -Di586 -D$OPENJDK_TARGET_CPU_LEGACY_LIB"
1049 1050 1051
          CFLAGS_JDK="$CFLAGS_JDK -erroff=E_BAD_PRAGMA_PACK_VALUE"
          ;;
      esac
1052

1053 1054
      CFLAGS_JDK="$CFLAGS_JDK -xc99=%none -xCC -errshort=tags -Xa -v -mt -W0,-noglobal"
      CXXFLAGS_JDK="$CXXFLAGS_JDK -errtags=yes +w -mt -features=no%except -DCC_NOEX -norunpath -xnolib"
1055

1056 1057 1058
      LDFLAGS_JDK="$LDFLAGS_JDK -z defs -xildoff -ztext"
      LDFLAGS_CXX_JDK="$LDFLAGS_CXX_JDK -norunpath -xnolib"
      ;;
K
Merge  
kvn 已提交
1059 1060 1061
    xlc )
      CFLAGS_JDK="$CFLAGS_JDK -D_GNU_SOURCE -D_REENTRANT -D_LARGEFILE64_SOURCE -DSTDC"
      CXXFLAGS_JDK="$CXXFLAGS_JDK -D_GNU_SOURCE -D_REENTRANT -D_LARGEFILE64_SOURCE -DSTDC"
S
simonis 已提交
1062

K
Merge  
kvn 已提交
1063 1064 1065
      LDFLAGS_JDK="$LDFLAGS_JDK"
      LDFLAGS_CXX_JDK="$LDFLAGS_CXX_JDK"
      ;;
1066
    cl )
1067
      COMMON_CCXXFLAGS_JDK="$COMMON_CCXXFLAGS $COMMON_CCXXFLAGS_JDK -Zi -MD -Zc:wchar_t- -W3 -wd4800 \
1068 1069 1070 1071 1072
      -D_STATIC_CPPLIB -D_DISABLE_DEPRECATE_STATIC_CPPLIB -DWIN32_LEAN_AND_MEAN \
      -D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE \
      -DWIN32 -DIAL"
      case $OPENJDK_TARGET_CPU in
        x86 )
1073
          COMMON_CCXXFLAGS_JDK="$COMMON_CCXXFLAGS_JDK -D_X86_ -Dx86"
S
simonis 已提交
1074
          ;;
1075
        x86_64 )
1076
          COMMON_CCXXFLAGS_JDK="$COMMON_CCXXFLAGS_JDK -D_AMD64_ -Damd64"
1077
          ;;
1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104
      esac
      ;;
  esac

  ###############################################################################

  # Adjust flags according to debug level.
  case $DEBUG_LEVEL in
    fastdebug )
      CFLAGS_JDK="$CFLAGS_JDK $CFLAGS_DEBUG_SYMBOLS"
      CXXFLAGS_JDK="$CXXFLAGS_JDK $CXXFLAGS_DEBUG_SYMBOLS"
      C_O_FLAG_HI="$C_O_FLAG_NORM"
      C_O_FLAG_NORM="$C_O_FLAG_NORM"
      CXX_O_FLAG_HI="$CXX_O_FLAG_NORM"
      CXX_O_FLAG_NORM="$CXX_O_FLAG_NORM"
      JAVAC_FLAGS="$JAVAC_FLAGS -g"
      ;;
    slowdebug )
      CFLAGS_JDK="$CFLAGS_JDK $CFLAGS_DEBUG_SYMBOLS"
      CXXFLAGS_JDK="$CXXFLAGS_JDK $CXXFLAGS_DEBUG_SYMBOLS"
      C_O_FLAG_HI="$C_O_FLAG_NONE"
      C_O_FLAG_NORM="$C_O_FLAG_NONE"
      CXX_O_FLAG_HI="$CXX_O_FLAG_NONE"
      CXX_O_FLAG_NORM="$CXX_O_FLAG_NONE"
      JAVAC_FLAGS="$JAVAC_FLAGS -g"
      ;;
  esac
1105

1106
  COMMON_CCXXFLAGS_JDK="$COMMON_CCXXFLAGS_JDK $ADD_LP64"
1107

1108 1109 1110
  # The package path is used only on macosx?
  PACKAGE_PATH=/opt/local
  AC_SUBST(PACKAGE_PATH)
1111

1112
  if test "x$OPENJDK_TARGET_CPU_ENDIAN" = xlittle; then
1113 1114 1115 1116
    # The macro _LITTLE_ENDIAN needs to be defined the same to avoid the
    #   Sun C compiler warning message: warning: macro redefined: _LITTLE_ENDIAN
    #   (The Solaris X86 system defines this in file /usr/include/sys/isa_defs.h).
    #   Note: -Dmacro         is the same as    #define macro 1
1117
    #         -Dmacro=        is the same as    #define macro
1118
    if test "x$OPENJDK_TARGET_OS" = xsolaris; then
1119
      COMMON_CCXXFLAGS_JDK="$COMMON_CCXXFLAGS_JDK -D_LITTLE_ENDIAN="
1120
    else
1121
      COMMON_CCXXFLAGS_JDK="$COMMON_CCXXFLAGS_JDK -D_LITTLE_ENDIAN"
1122
    fi
1123
  else
1124
    COMMON_CCXXFLAGS_JDK="$COMMON_CCXXFLAGS_JDK -D_BIG_ENDIAN"
1125 1126
  fi
  if test "x$OPENJDK_TARGET_OS" = xlinux; then
1127
    COMMON_CCXXFLAGS_JDK="$COMMON_CCXXFLAGS_JDK -DLINUX"
1128 1129
  fi
  if test "x$OPENJDK_TARGET_OS" = xwindows; then
1130
    COMMON_CCXXFLAGS_JDK="$COMMON_CCXXFLAGS_JDK -DWINDOWS"
1131 1132
  fi
  if test "x$OPENJDK_TARGET_OS" = xsolaris; then
1133
    COMMON_CCXXFLAGS_JDK="$COMMON_CCXXFLAGS_JDK -DSOLARIS"
1134
  fi
K
Merge  
kvn 已提交
1135
  if test "x$OPENJDK_TARGET_OS" = xaix; then
1136
    COMMON_CCXXFLAGS_JDK="$COMMON_CCXXFLAGS_JDK -DAIX -DPPC64"
K
Merge  
kvn 已提交
1137
  fi
1138
  if test "x$OPENJDK_TARGET_OS" = xmacosx; then
1139
    COMMON_CCXXFLAGS_JDK="$COMMON_CCXXFLAGS_JDK -DMACOSX -D_ALLBSD_SOURCE -D_DARWIN_UNLIMITED_SELECT"
1140
    # Setting these parameters makes it an error to link to macosx APIs that are
1141 1142 1143 1144 1145 1146 1147 1148
    # newer than the given OS version and makes the linked binaries compatible even
    # if built on a newer version of the OS.
    # The expected format is X.Y.Z
    MACOSX_VERSION_MIN=10.7.0
    AC_SUBST(MACOSX_VERSION_MIN)
    # The macro takes the version with no dots, ex: 1070
    # Let the flags variables get resolved in make for easier override on make
    # command line.
1149
    COMMON_CCXXFLAGS_JDK="$COMMON_CCXXFLAGS_JDK -DMAC_OS_X_VERSION_MAX_ALLOWED=\$(subst .,,\$(MACOSX_VERSION_MIN)) -mmacosx-version-min=\$(MACOSX_VERSION_MIN)"
1150
    LDFLAGS_JDK="$LDFLAGS_JDK -mmacosx-version-min=\$(MACOSX_VERSION_MIN)"
1151 1152
  fi
  if test "x$OPENJDK_TARGET_OS" = xbsd; then
1153
    COMMON_CCXXFLAGS_JDK="$COMMON_CCXXFLAGS_JDK -DBSD -D_ALLBSD_SOURCE"
1154 1155
  fi
  if test "x$DEBUG_LEVEL" = xrelease; then
1156
    COMMON_CCXXFLAGS_JDK="$COMMON_CCXXFLAGS_JDK -DNDEBUG"
1157
  if test "x$OPENJDK_TARGET_OS" = xsolaris; then
1158
    COMMON_CCXXFLAGS_JDK="$COMMON_CCXXFLAGS_JDK -DTRIMMED"
1159 1160
  fi
  else
1161
    COMMON_CCXXFLAGS_JDK="$COMMON_CCXXFLAGS_JDK -DDEBUG"
1162 1163
  fi

1164 1165
  COMMON_CCXXFLAGS_JDK="$COMMON_CCXXFLAGS_JDK -DARCH='\"$OPENJDK_TARGET_CPU_LEGACY\"' -D$OPENJDK_TARGET_CPU_LEGACY"
  COMMON_CCXXFLAGS_JDK="$COMMON_CCXXFLAGS_JDK -DRELEASE='\"\$(RELEASE)\"'"
1166

1167
  COMMON_CCXXFLAGS_JDK="$COMMON_CCXXFLAGS_JDK \
1168 1169 1170
      -I${JDK_OUTPUTDIR}/include \
      -I${JDK_OUTPUTDIR}/include/$OPENJDK_TARGET_OS \
      -I${JDK_TOPDIR}/src/share/javavm/export \
1171
      -I${JDK_TOPDIR}/src/$OPENJDK_TARGET_OS_EXPORT_DIR/javavm/export \
1172 1173 1174 1175
      -I${JDK_TOPDIR}/src/share/native/common \
      -I${JDK_TOPDIR}/src/$OPENJDK_TARGET_OS_API_DIR/native/common"

  # The shared libraries are compiled using the picflag.
1176 1177
  CFLAGS_JDKLIB="$COMMON_CCXXFLAGS_JDK $CFLAGS_JDK $PICFLAG $CFLAGS_JDKLIB_EXTRA"
  CXXFLAGS_JDKLIB="$COMMON_CCXXFLAGS_JDK $CXXFLAGS_JDK $PICFLAG $CXXFLAGS_JDKLIB_EXTRA "
1178 1179

  # Executable flags
1180 1181
  CFLAGS_JDKEXE="$COMMON_CCXXFLAGS_JDK $CFLAGS_JDK"
  CXXFLAGS_JDKEXE="$COMMON_CCXXFLAGS_JDK $CXXFLAGS_JDK"
1182 1183 1184 1185 1186 1187 1188 1189 1190 1191

  # Now this is odd. The JDK native libraries have to link against libjvm.so
  # On 32-bit machines there is normally two distinct libjvm.so:s, client and server.
  # Which should we link to? Are we lucky enough that the binary api to the libjvm.so library
  # is identical for client and server? Yes. Which is picked at runtime (client or server)?
  # Neither, since the chosen libjvm.so has already been loaded by the launcher, all the following
  # libraries will link to whatever is in memory. Yuck.
  #
  # Thus we offer the compiler to find libjvm.so first in server then in client. It works. Ugh.
  if test "x$COMPILER_NAME" = xcl; then
1192
    LDFLAGS_JDK="$LDFLAGS_JDK -nologo -opt:ref -incremental:no"
1193
    if test "x$OPENJDK_TARGET_CPU" = xx86; then
1194
      LDFLAGS_JDK="$LDFLAGS_JDK -safeseh"
1195 1196 1197 1198 1199 1200
    fi
    # TODO: make -debug optional "--disable-full-debug-symbols"
    LDFLAGS_JDK="$LDFLAGS_JDK -debug"
    LDFLAGS_JDKLIB="${LDFLAGS_JDK} -dll -libpath:${JDK_OUTPUTDIR}/lib"
    LDFLAGS_JDKLIB_SUFFIX=""
    if test "x$OPENJDK_TARGET_CPU_BITS" = "x64"; then
1201
      LDFLAGS_STACK_SIZE=1048576
1202
    else
1203
      LDFLAGS_STACK_SIZE=327680
1204 1205
    fi
    LDFLAGS_JDKEXE="${LDFLAGS_JDK} /STACK:$LDFLAGS_STACK_SIZE"
1206
  else
O
ohair 已提交
1207
    if test "x$COMPILER_NAME" = xgcc; then
1208 1209 1210 1211 1212 1213
      # If this is a --hash-style=gnu system, use --hash-style=both, why?
      HAS_GNU_HASH=`$CC -dumpspecs 2>/dev/null | $GREP 'hash-style=gnu'`
      if test -n "$HAS_GNU_HASH"; then
        LDFLAGS_JDK="${LDFLAGS_JDK} -Xlinker --hash-style=both "
      fi
      if test "x$OPENJDK_TARGET_OS" = xlinux; then
1214 1215 1216 1217
        # And since we now know that the linker is gnu, then add:
        #   -z defs, to forbid undefined symbols in object files
        #   -z noexecstack, to mark stack regions as non-executable
        LDFLAGS_JDK="${LDFLAGS_JDK} -Xlinker -z -Xlinker defs -Xlinker -z -Xlinker noexecstack"
1218 1219 1220 1221
        if test "x$DEBUG_LEVEL" = "xrelease"; then
          # When building release libraries, tell the linker optimize them.
          # Should this be supplied to the OSS linker as well?
          LDFLAGS_JDK="${LDFLAGS_JDK} -Xlinker -O1"
1222
        fi
1223
      fi
1224 1225
    fi
    LDFLAGS_JDKLIB="${LDFLAGS_JDK} $SHARED_LIBRARY_FLAGS \
1226
        -L${JDK_OUTPUTDIR}/lib${OPENJDK_TARGET_CPU_LIBDIR}"
1227

1228
    # On some platforms (mac) the linker warns about non existing -L dirs.
1229
    # Add server first if available. Linking aginst client does not always produce the same results.
1230 1231
    # Only add client dir if client is being built. Add minimal (note not minimal1) if only building minimal1.
    # Default to server for other variants.
1232
    if test "x$JVM_VARIANT_SERVER" = xtrue; then
1233
      LDFLAGS_JDKLIB="${LDFLAGS_JDKLIB} -L${JDK_OUTPUTDIR}/lib${OPENJDK_TARGET_CPU_LIBDIR}/server"
1234
    elif test "x$JVM_VARIANT_CLIENT" = xtrue; then
1235
      LDFLAGS_JDKLIB="${LDFLAGS_JDKLIB} -L${JDK_OUTPUTDIR}/lib${OPENJDK_TARGET_CPU_LIBDIR}/client"
1236
    elif test "x$JVM_VARIANT_MINIMAL1" = xtrue; then
1237
      LDFLAGS_JDKLIB="${LDFLAGS_JDKLIB} -L${JDK_OUTPUTDIR}/lib${OPENJDK_TARGET_CPU_LIBDIR}/minimal"
1238
    else
1239
      LDFLAGS_JDKLIB="${LDFLAGS_JDKLIB} -L${JDK_OUTPUTDIR}/lib${OPENJDK_TARGET_CPU_LIBDIR}/server"
1240 1241
    fi

1242
    LDFLAGS_JDKLIB_SUFFIX="-ljava -ljvm"
1243
    if test "x$COMPILER_NAME" = xossc; then
1244
      LDFLAGS_JDKLIB_SUFFIX="$LDFLAGS_JDKLIB_SUFFIX -lc"
1245 1246 1247
    fi

    LDFLAGS_JDKEXE="${LDFLAGS_JDK}"
1248
    if test "x$OPENJDK_TARGET_OS" = xlinux; then
1249
      LDFLAGS_JDKEXE="$LDFLAGS_JDKEXE -Xlinker --allow-shlib-undefined"
1250
    fi
1251
  fi
1252

1253 1254
  AC_SUBST(CFLAGS_JDKLIB)
  AC_SUBST(CFLAGS_JDKEXE)
1255

1256 1257
  AC_SUBST(CXXFLAGS_JDKLIB)
  AC_SUBST(CXXFLAGS_JDKEXE)
1258

1259 1260 1261 1262 1263
  AC_SUBST(LDFLAGS_JDKLIB)
  AC_SUBST(LDFLAGS_JDKEXE)
  AC_SUBST(LDFLAGS_JDKLIB_SUFFIX)
  AC_SUBST(LDFLAGS_JDKEXE_SUFFIX)
  AC_SUBST(LDFLAGS_CXX_JDK)
1264
])
1265 1266


1267 1268
# TOOLCHAIN_C_COMPILER_CHECK_ARGUMENTS([ARGUMENT], [RUN-IF-TRUE],
#                                      [RUN-IF-FALSE])
1269
# ------------------------------------------------------------
1270 1271
# Check that the C compiler supports an argument
AC_DEFUN([TOOLCHAIN_C_COMPILER_CHECK_ARGUMENTS],
1272
[
1273
  AC_MSG_CHECKING([if the C compiler supports "$1"])
1274 1275 1276 1277 1278
  supports=yes

  saved_cflags="$CFLAGS"
  CFLAGS="$CFLAGS $1"
  AC_LANG_PUSH([C])
1279 1280
  AC_COMPILE_IFELSE([AC_LANG_SOURCE([[int i;]])], [], 
      [supports=no])
1281 1282 1283
  AC_LANG_POP([C])
  CFLAGS="$saved_cflags"

1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300
  AC_MSG_RESULT([$supports])
  if test "x$supports" = "xyes" ; then
    m4_ifval([$2], [$2], [:])
  else
    m4_ifval([$3], [$3], [:])
  fi
])

# TOOLCHAIN_CXX_COMPILER_CHECK_ARGUMENTS([ARGUMENT], [RUN-IF-TRUE],
#                                        [RUN-IF-FALSE])
# ------------------------------------------------------------
# Check that the C++ compiler supports an argument
AC_DEFUN([TOOLCHAIN_CXX_COMPILER_CHECK_ARGUMENTS],
[
  AC_MSG_CHECKING([if the C++ compiler supports "$1"])
  supports=yes

1301 1302 1303
  saved_cxxflags="$CXXFLAGS"
  CXXFLAGS="$CXXFLAG $1"
  AC_LANG_PUSH([C++])
1304 1305
  AC_COMPILE_IFELSE([AC_LANG_SOURCE([[int i;]])], [], 
      [supports=no])
1306 1307
  AC_LANG_POP([C++])
  CXXFLAGS="$saved_cxxflags"
1308 1309 1310 1311 1312 1313 1314 1315
  
  AC_MSG_RESULT([$supports])
  if test "x$supports" = "xyes" ; then
    m4_ifval([$2], [$2], [:])
  else
    m4_ifval([$3], [$3], [:])
  fi
])
1316

1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333
# TOOLCHAIN_COMPILER_CHECK_ARGUMENTS([ARGUMENT], [RUN-IF-TRUE],
#                                    [RUN-IF-FALSE])
# ------------------------------------------------------------
# Check that the C and C++ compilers support an argument
AC_DEFUN([TOOLCHAIN_COMPILER_CHECK_ARGUMENTS],
[
  TOOLCHAIN_C_COMPILER_CHECK_ARGUMENTS([$1],
  				       [C_COMP_SUPPORTS="yes"],
				       [C_COMP_SUPPORTS="no"])
  TOOLCHAIN_CXX_COMPILER_CHECK_ARGUMENTS([$1],
  					 [CXX_COMP_SUPPORTS="yes"],
					 [CXX_COMP_SUPPORTS="no"])

  AC_MSG_CHECKING([if both compilers support "$1"])
  supports=no
  if test "x$C_COMP_SUPPORTS" = "xyes" -a "x$CXX_COMP_SUPPORTS" = "xyes"; then supports=yes; fi
  
1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347
  AC_MSG_RESULT([$supports])
  if test "x$supports" = "xyes" ; then
    m4_ifval([$2], [$2], [:])
  else
    m4_ifval([$3], [$3], [:])
  fi
])

AC_DEFUN_ONCE([TOOLCHAIN_SETUP_COMPILER_FLAGS_MISC],
[
  # Some Zero and Shark settings.
  # ZERO_ARCHFLAG tells the compiler which mode to build for
  case "${OPENJDK_TARGET_CPU}" in
    s390)
S
simonis 已提交
1348
      ZERO_ARCHFLAG="${COMPILER_TARGET_BITS_FLAG}31"
1349 1350
      ;;
    *)
S
simonis 已提交
1351
      ZERO_ARCHFLAG="${COMPILER_TARGET_BITS_FLAG}${OPENJDK_TARGET_CPU_BITS}"
1352 1353 1354 1355
  esac
  TOOLCHAIN_COMPILER_CHECK_ARGUMENTS([$ZERO_ARCHFLAG], [], [ZERO_ARCHFLAG=""])
  AC_SUBST(ZERO_ARCHFLAG)

S
simonis 已提交
1356
  # Check that the compiler supports -mX (or -qX on AIX) flags
1357
  # Set COMPILER_SUPPORTS_TARGET_BITS_FLAG to 'true' if it does
S
simonis 已提交
1358
  TOOLCHAIN_COMPILER_CHECK_ARGUMENTS([${COMPILER_TARGET_BITS_FLAG}${OPENJDK_TARGET_CPU_BITS}],
1359 1360
      [COMPILER_SUPPORTS_TARGET_BITS_FLAG=true],
      [COMPILER_SUPPORTS_TARGET_BITS_FLAG=false])
1361
  AC_SUBST(COMPILER_SUPPORTS_TARGET_BITS_FLAG)
1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379


  # Check for broken SuSE 'ld' for which 'Only anonymous version tag is allowed in executable.'
  USING_BROKEN_SUSE_LD=no
  if test "x$OPENJDK_TARGET_OS" = xlinux && test "x$GCC" = xyes; then
    AC_MSG_CHECKING([for broken SuSE 'ld' which only understands anonymous version tags in executables])
    echo "SUNWprivate_1.1 { local: *; };" > version-script.map
    echo "int main() { }" > main.c
    if $CXX -Xlinker -version-script=version-script.map main.c 2>&AS_MESSAGE_LOG_FD >&AS_MESSAGE_LOG_FD; then
      AC_MSG_RESULT(no)
      USING_BROKEN_SUSE_LD=no
    else
      AC_MSG_RESULT(yes)
      USING_BROKEN_SUSE_LD=yes
    fi
    rm -rf version-script.map main.c
  fi
  AC_SUBST(USING_BROKEN_SUSE_LD)
1380
])
1381

1382 1383 1384 1385
# Setup the JTREG paths
AC_DEFUN_ONCE([TOOLCHAIN_SETUP_JTREG],
[
  AC_ARG_WITH(jtreg, [AS_HELP_STRING([--with-jtreg],
1386 1387 1388
      [Regression Test Harness @<:@probed@:>@])],
      [],
      [with_jtreg=no])
1389 1390 1391 1392

  if test "x$with_jtreg" = xno; then
    # jtreg disabled
    AC_MSG_CHECKING([for jtreg])
1393
    AC_MSG_RESULT(no)
1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406
  else
    if test "x$with_jtreg" != xyes; then
      # with path specified.
      JT_HOME="$with_jtreg"
    fi

    if test "x$JT_HOME" != x; then
      AC_MSG_CHECKING([for jtreg])

      # use JT_HOME enviroment var.
      BASIC_FIXUP_PATH([JT_HOME])

      # jtreg win32 script works for everybody
1407
      JTREGEXE="$JT_HOME/bin/jtreg"
1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422

      if test ! -f "$JTREGEXE"; then
        AC_MSG_ERROR([JTReg executable does not exist: $JTREGEXE])
      fi

      AC_MSG_RESULT($JTREGEXE)
    else
      # try to find jtreg on path
      BASIC_REQUIRE_PROG(JTREGEXE, jtreg)
      JT_HOME="`$DIRNAME $JTREGEXE`"
    fi
  fi

  AC_SUBST(JT_HOME)
  AC_SUBST(JTREGEXE)
1423
])
1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440

AC_DEFUN_ONCE([TOOLCHAIN_SETUP_GCC6_COMPILER_FLAGS],
[
  # These flags are required for GCC 6 builds as undefined behaviour in OpenJDK code
  # runs afoul of the more aggressive versions of these optimisations.
  # Notably, value range propagation now assumes that the this pointer of C++
  # member functions is non-null.
  NO_DELETE_NULL_POINTER_CHECKS_CFLAG="-fno-delete-null-pointer-checks"
  TOOLCHAIN_COMPILER_CHECK_ARGUMENTS([$NO_DELETE_NULL_POINTER_CHECKS_CFLAG -Werror],
  				     [], [NO_DELETE_NULL_POINTER_CHECKS_CFLAG=""])
  AC_SUBST([NO_DELETE_NULL_POINTER_CHECKS_CFLAG])
  NO_LIFETIME_DSE_CFLAG="-fno-lifetime-dse"
  TOOLCHAIN_COMPILER_CHECK_ARGUMENTS([$NO_LIFETIME_DSE_CFLAG -Werror],
  				     [], [NO_LIFETIME_DSE_CFLAG=""])
  CFLAGS_JDK="${CFLAGS_JDK} ${NO_DELETE_NULL_POINTER_CHECKS_CFLAG} ${NO_LIFETIME_DSE_CFLAG}"
  AC_SUBST([NO_LIFETIME_DSE_CFLAG])
])