1 #
   2 # Copyright (c) 2011, 2017, Oracle and/or its affiliates. All rights reserved.
   3 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4 #
   5 # This code is free software; you can redistribute it and/or modify it
   6 # under the terms of the GNU General Public License version 2 only, as
   7 # published by the Free Software Foundation.  Oracle designates this
   8 # particular file as subject to the "Classpath" exception as provided
   9 # by Oracle in the LICENSE file that accompanied this code.
  10 #
  11 # This code is distributed in the hope that it will be useful, but WITHOUT
  12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13 # FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14 # version 2 for more details (a copy is included in the LICENSE file that
  15 # accompanied this code).
  16 #
  17 # You should have received a copy of the GNU General Public License version
  18 # 2 along with this work; if not, write to the Free Software Foundation,
  19 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20 #
  21 # Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22 # or visit www.oracle.com if you need additional information or have any
  23 # questions.
  24 #
  25 
  26 # Support macro for PLATFORM_EXTRACT_TARGET_AND_BUILD.
  27 # Converts autoconf style CPU name to OpenJDK style, into
  28 # VAR_CPU, VAR_CPU_ARCH, VAR_CPU_BITS and VAR_CPU_ENDIAN.
  29 AC_DEFUN([PLATFORM_EXTRACT_VARS_FROM_CPU],
  30 [
  31   # First argument is the cpu name from the trip/quad
  32   case "$1" in
  33     x86_64)
  34       VAR_CPU=x86_64
  35       VAR_CPU_ARCH=x86
  36       VAR_CPU_BITS=64
  37       VAR_CPU_ENDIAN=little
  38       ;;
  39     i?86)
  40       VAR_CPU=x86
  41       VAR_CPU_ARCH=x86
  42       VAR_CPU_BITS=32
  43       VAR_CPU_ENDIAN=little
  44       ;;
  45     arm*)
  46       VAR_CPU=arm
  47       VAR_CPU_ARCH=arm
  48       VAR_CPU_BITS=32
  49       VAR_CPU_ENDIAN=little
  50       ;;
  51     aarch64)
  52       VAR_CPU=aarch64
  53       VAR_CPU_ARCH=aarch64
  54       VAR_CPU_BITS=64
  55       VAR_CPU_ENDIAN=little
  56       ;;
  57     powerpc)
  58       VAR_CPU=ppc
  59       VAR_CPU_ARCH=ppc
  60       VAR_CPU_BITS=32
  61       VAR_CPU_ENDIAN=big
  62       ;;
  63     powerpc64)
  64       VAR_CPU=ppc64
  65       VAR_CPU_ARCH=ppc
  66       VAR_CPU_BITS=64
  67       VAR_CPU_ENDIAN=big
  68       ;;
  69     powerpc64le)
  70       VAR_CPU=ppc64le
  71       VAR_CPU_ARCH=ppc
  72       VAR_CPU_BITS=64
  73       VAR_CPU_ENDIAN=little
  74       ;;
  75     s390)
  76       VAR_CPU=s390
  77       VAR_CPU_ARCH=s390
  78       VAR_CPU_BITS=32
  79       VAR_CPU_ENDIAN=big
  80       ;;
  81     s390x)
  82       VAR_CPU=s390x
  83       VAR_CPU_ARCH=s390
  84       VAR_CPU_BITS=64
  85       VAR_CPU_ENDIAN=big
  86       ;;
  87     sparc)
  88       VAR_CPU=sparc
  89       VAR_CPU_ARCH=sparc
  90       VAR_CPU_BITS=32
  91       VAR_CPU_ENDIAN=big
  92       ;;
  93     sparcv9|sparc64)
  94       VAR_CPU=sparcv9
  95       VAR_CPU_ARCH=sparc
  96       VAR_CPU_BITS=64
  97       VAR_CPU_ENDIAN=big
  98       ;;
  99     *)
 100       AC_MSG_ERROR([unsupported cpu $1])
 101       ;;
 102   esac
 103 ])
 104 
 105 # Support macro for PLATFORM_EXTRACT_TARGET_AND_BUILD.
 106 # Converts autoconf style OS name to OpenJDK style, into
 107 # VAR_OS, VAR_OS_TYPE and VAR_OS_ENV.
 108 AC_DEFUN([PLATFORM_EXTRACT_VARS_FROM_OS],
 109 [
 110   case "$1" in
 111     *linux*)
 112       VAR_OS=linux
 113       VAR_OS_TYPE=unix
 114       ;;
 115     *solaris*)
 116       VAR_OS=solaris
 117       VAR_OS_TYPE=unix
 118       ;;
 119     *darwin*)
 120       VAR_OS=macosx
 121       VAR_OS_TYPE=unix
 122       ;;
 123     *bsd*)
 124       VAR_OS=bsd
 125       VAR_OS_TYPE=unix
 126       ;;
 127     *cygwin*)
 128       VAR_OS=windows
 129       VAR_OS_ENV=windows.cygwin
 130       ;;
 131     *mingw*)
 132       VAR_OS=windows
 133       VAR_OS_ENV=windows.msys
 134       ;;
 135     *aix*)
 136       VAR_OS=aix
 137       VAR_OS_TYPE=unix
 138       ;;
 139     *)
 140       AC_MSG_ERROR([unsupported operating system $1])
 141       ;;
 142   esac
 143 ])
 144 
 145 # Expects $host_os $host_cpu $build_os and $build_cpu
 146 # and $with_target_bits to have been setup!
 147 #
 148 # Translate the standard triplet(quadruplet) definition
 149 # of the target/build system into OPENJDK_TARGET_OS, OPENJDK_TARGET_CPU,
 150 # OPENJDK_BUILD_OS, etc.
 151 AC_DEFUN([PLATFORM_EXTRACT_TARGET_AND_BUILD],
 152 [
 153   # Copy the autoconf trip/quadruplet verbatim to OPENJDK_TARGET_AUTOCONF_NAME
 154   # (from the autoconf "host") and OPENJDK_BUILD_AUTOCONF_NAME
 155   # Note that we might later on rewrite e.g. OPENJDK_TARGET_CPU due to reduced build,
 156   # but this will not change the value of OPENJDK_TARGET_AUTOCONF_NAME.
 157   OPENJDK_TARGET_AUTOCONF_NAME="$host"
 158   OPENJDK_BUILD_AUTOCONF_NAME="$build"
 159   AC_SUBST(OPENJDK_TARGET_AUTOCONF_NAME)
 160   AC_SUBST(OPENJDK_BUILD_AUTOCONF_NAME)
 161 
 162   # Convert the autoconf OS/CPU value to our own data, into the VAR_OS/CPU variables.
 163   PLATFORM_EXTRACT_VARS_FROM_OS($build_os)
 164   PLATFORM_EXTRACT_VARS_FROM_CPU($build_cpu)
 165   # ..and setup our own variables. (Do this explicitly to facilitate searching)
 166   OPENJDK_BUILD_OS="$VAR_OS"
 167   if test "x$VAR_OS_TYPE" != x; then
 168     OPENJDK_BUILD_OS_TYPE="$VAR_OS_TYPE"
 169   else
 170     OPENJDK_BUILD_OS_TYPE="$VAR_OS"
 171   fi
 172   if test "x$VAR_OS_ENV" != x; then
 173     OPENJDK_BUILD_OS_ENV="$VAR_OS_ENV"
 174   else
 175     OPENJDK_BUILD_OS_ENV="$VAR_OS"
 176   fi
 177   OPENJDK_BUILD_CPU="$VAR_CPU"
 178   OPENJDK_BUILD_CPU_ARCH="$VAR_CPU_ARCH"
 179   OPENJDK_BUILD_CPU_BITS="$VAR_CPU_BITS"
 180   OPENJDK_BUILD_CPU_ENDIAN="$VAR_CPU_ENDIAN"
 181   AC_SUBST(OPENJDK_BUILD_OS)
 182   AC_SUBST(OPENJDK_BUILD_OS_TYPE)
 183   AC_SUBST(OPENJDK_BUILD_OS_ENV)
 184   AC_SUBST(OPENJDK_BUILD_CPU)
 185   AC_SUBST(OPENJDK_BUILD_CPU_ARCH)
 186   AC_SUBST(OPENJDK_BUILD_CPU_BITS)
 187   AC_SUBST(OPENJDK_BUILD_CPU_ENDIAN)
 188 
 189   AC_MSG_CHECKING([openjdk-build os-cpu])
 190   AC_MSG_RESULT([$OPENJDK_BUILD_OS-$OPENJDK_BUILD_CPU])
 191 
 192   # Convert the autoconf OS/CPU value to our own data, into the VAR_OS/CPU variables.
 193   PLATFORM_EXTRACT_VARS_FROM_OS($host_os)
 194   PLATFORM_EXTRACT_VARS_FROM_CPU($host_cpu)
 195   # ... and setup our own variables. (Do this explicitly to facilitate searching)
 196   OPENJDK_TARGET_OS="$VAR_OS"
 197   if test "x$VAR_OS_TYPE" != x; then
 198     OPENJDK_TARGET_OS_TYPE="$VAR_OS_TYPE"
 199   else
 200     OPENJDK_TARGET_OS_TYPE="$VAR_OS"
 201   fi
 202   if test "x$VAR_OS_ENV" != x; then
 203     OPENJDK_TARGET_OS_ENV="$VAR_OS_ENV"
 204   else
 205     OPENJDK_TARGET_OS_ENV="$VAR_OS"
 206   fi
 207   OPENJDK_TARGET_CPU="$VAR_CPU"
 208   OPENJDK_TARGET_CPU_ARCH="$VAR_CPU_ARCH"
 209   OPENJDK_TARGET_CPU_BITS="$VAR_CPU_BITS"
 210   OPENJDK_TARGET_CPU_ENDIAN="$VAR_CPU_ENDIAN"
 211   AC_SUBST(OPENJDK_TARGET_OS)
 212   AC_SUBST(OPENJDK_TARGET_OS_TYPE)
 213   AC_SUBST(OPENJDK_TARGET_OS_ENV)
 214   AC_SUBST(OPENJDK_TARGET_CPU)
 215   AC_SUBST(OPENJDK_TARGET_CPU_ARCH)
 216   AC_SUBST(OPENJDK_TARGET_CPU_BITS)
 217   AC_SUBST(OPENJDK_TARGET_CPU_ENDIAN)
 218 
 219   AC_MSG_CHECKING([openjdk-target os-cpu])
 220   AC_MSG_RESULT([$OPENJDK_TARGET_OS-$OPENJDK_TARGET_CPU])
 221 ])
 222 
 223 # Check if a reduced build (32-bit on 64-bit platforms) is requested, and modify behaviour
 224 # accordingly. Must be done after setting up build and target system, but before
 225 # doing anything else with these values.
 226 AC_DEFUN([PLATFORM_SETUP_TARGET_CPU_BITS],
 227 [
 228   AC_ARG_WITH(target-bits, [AS_HELP_STRING([--with-target-bits],
 229        [build 32-bit or 64-bit binaries (for platforms that support it), e.g. --with-target-bits=32 @<:@guessed@:>@])])
 230 
 231   # We have three types of compiles:
 232   # native  == normal compilation, target system == build system
 233   # cross   == traditional cross compilation, target system != build system; special toolchain needed
 234   # reduced == using native compilers, but with special flags (e.g. -m32) to produce 32-bit builds on 64-bit machines
 235   #
 236   if test "x$OPENJDK_BUILD_AUTOCONF_NAME" != "x$OPENJDK_TARGET_AUTOCONF_NAME"; then
 237     # We're doing a proper cross-compilation
 238     COMPILE_TYPE="cross"
 239   else
 240     COMPILE_TYPE="native"
 241   fi
 242 
 243   if test "x$with_target_bits" != x; then
 244     if test "x$COMPILE_TYPE" = "xcross"; then
 245       AC_MSG_ERROR([It is not possible to combine --with-target-bits=X and proper cross-compilation. Choose either.])
 246     fi
 247 
 248     if test "x$with_target_bits" = x32 && test "x$OPENJDK_TARGET_CPU_BITS" = x64; then
 249       # A reduced build is requested
 250       COMPILE_TYPE="reduced"
 251       OPENJDK_TARGET_CPU_BITS=32
 252       if test "x$OPENJDK_TARGET_CPU_ARCH" = "xx86"; then
 253         OPENJDK_TARGET_CPU=x86
 254       elif test "x$OPENJDK_TARGET_CPU_ARCH" = "xsparc"; then
 255         OPENJDK_TARGET_CPU=sparc
 256       else
 257         AC_MSG_ERROR([Reduced build (--with-target-bits=32) is only supported on x86_64 and sparcv9])
 258       fi
 259     elif test "x$with_target_bits" = x64 && test "x$OPENJDK_TARGET_CPU_BITS" = x32; then
 260       AC_MSG_ERROR([It is not possible to use --with-target-bits=64 on a 32 bit system. Use proper cross-compilation instead.])
 261     elif test "x$with_target_bits" = "x$OPENJDK_TARGET_CPU_BITS"; then
 262       AC_MSG_NOTICE([--with-target-bits are set to build platform address size; argument has no meaning])
 263     else
 264       AC_MSG_ERROR([--with-target-bits can only be 32 or 64, you specified $with_target_bits!])
 265     fi
 266   fi
 267   AC_SUBST(COMPILE_TYPE)
 268 
 269   AC_MSG_CHECKING([compilation type])
 270   AC_MSG_RESULT([$COMPILE_TYPE])
 271 ])
 272 
 273 # Setup the legacy variables, for controlling the old makefiles.
 274 #
 275 AC_DEFUN([PLATFORM_SETUP_LEGACY_VARS],
 276 [
 277   PLATFORM_SETUP_LEGACY_VARS_HELPER([TARGET])
 278   PLATFORM_SETUP_LEGACY_VARS_HELPER([BUILD])
 279 ])
 280 
 281 # $1 - Either TARGET or BUILD to setup the variables for.
 282 AC_DEFUN([PLATFORM_SETUP_LEGACY_VARS_HELPER],
 283 [
 284   # Also store the legacy naming of the cpu.
 285   # Ie i586 and amd64 instead of x86 and x86_64
 286   OPENJDK_$1_CPU_LEGACY="$OPENJDK_$1_CPU"
 287   if test "x$OPENJDK_$1_CPU" = xx86; then
 288     OPENJDK_$1_CPU_LEGACY="i586"
 289   elif test "x$OPENJDK_$1_OS" != xmacosx && test "x$OPENJDK_$1_CPU" = xx86_64; then
 290     # On all platforms except MacOSX replace x86_64 with amd64.
 291     OPENJDK_$1_CPU_LEGACY="amd64"
 292   fi
 293   AC_SUBST(OPENJDK_$1_CPU_LEGACY)
 294 
 295   # And the second legacy naming of the cpu.
 296   # Ie i386 and amd64 instead of x86 and x86_64.
 297   OPENJDK_$1_CPU_LEGACY_LIB="$OPENJDK_$1_CPU"
 298   if test "x$OPENJDK_$1_CPU" = xx86; then
 299     OPENJDK_$1_CPU_LEGACY_LIB="i386"
 300   elif test "x$OPENJDK_$1_CPU" = xx86_64; then
 301     OPENJDK_$1_CPU_LEGACY_LIB="amd64"
 302   fi
 303   AC_SUBST(OPENJDK_$1_CPU_LEGACY_LIB)
 304 
 305   # OPENJDK_$1_CPU_ISADIR is normally empty. On 64-bit Solaris systems, it is set to
 306   # /amd64 or /sparcv9. This string is appended to some library paths, like this:
 307   # /usr/lib${OPENJDK_$1_CPU_ISADIR}/libexample.so
 308   OPENJDK_$1_CPU_ISADIR=""
 309   if test "x$OPENJDK_$1_OS" = xsolaris; then
 310     if test "x$OPENJDK_$1_CPU" = xx86_64; then
 311       OPENJDK_$1_CPU_ISADIR="/amd64"
 312     elif test "x$OPENJDK_$1_CPU" = xsparcv9; then
 313       OPENJDK_$1_CPU_ISADIR="/sparcv9"
 314     fi
 315   fi
 316   AC_SUBST(OPENJDK_$1_CPU_ISADIR)
 317 
 318   # Setup OPENJDK_$1_CPU_OSARCH, which is used to set the os.arch Java system property
 319   OPENJDK_$1_CPU_OSARCH="$OPENJDK_$1_CPU"
 320   if test "x$OPENJDK_$1_OS" = xlinux && test "x$OPENJDK_$1_CPU" = xx86; then
 321     # On linux only, we replace x86 with i386.
 322     OPENJDK_$1_CPU_OSARCH="i386"
 323   elif test "x$OPENJDK_$1_OS" != xmacosx && test "x$OPENJDK_$1_CPU" = xx86_64; then
 324     # On all platforms except macosx, we replace x86_64 with amd64.
 325     OPENJDK_$1_CPU_OSARCH="amd64"
 326   fi
 327   AC_SUBST(OPENJDK_$1_CPU_OSARCH)
 328 
 329   OPENJDK_$1_CPU_JLI="$OPENJDK_$1_CPU"
 330   if test "x$OPENJDK_$1_CPU" = xx86; then
 331     OPENJDK_$1_CPU_JLI="i386"
 332   elif test "x$OPENJDK_$1_OS" != xmacosx && test "x$OPENJDK_$1_CPU" = xx86_64; then
 333     # On all platforms except macosx, we replace x86_64 with amd64.
 334     OPENJDK_$1_CPU_JLI="amd64"
 335   fi
 336 
 337   if test "x$OPENJDK_$1_OS" = xmacosx; then
 338       OPENJDK_$1_OS_EXPORT_DIR=macosx
 339   else
 340       OPENJDK_$1_OS_EXPORT_DIR=${OPENJDK_$1_OS_TYPE}
 341   fi
 342   AC_SUBST(OPENJDK_$1_OS_EXPORT_DIR)
 343 
 344   # The new version string in JDK 9 also defined new naming of OS and ARCH for bundles
 345   # Macosx is osx and x86_64 is x64
 346   if test "x$OPENJDK_$1_OS" = xmacosx; then
 347     OPENJDK_$1_OS_BUNDLE="osx"
 348   else
 349     OPENJDK_$1_OS_BUNDLE="$OPENJDK_TARGET_OS"
 350   fi
 351   if test "x$OPENJDK_$1_CPU" = xx86_64; then
 352     OPENJDK_$1_CPU_BUNDLE="x64"
 353   else
 354     OPENJDK_$1_CPU_BUNDLE="$OPENJDK_$1_CPU"
 355   fi
 356   OPENJDK_$1_BUNDLE_PLATFORM="${OPENJDK_$1_OS_BUNDLE}-${OPENJDK_$1_CPU_BUNDLE}"
 357   AC_SUBST(OPENJDK_$1_BUNDLE_PLATFORM)
 358 
 359   if test "x$OPENJDK_$1_CPU_BITS" = x64; then
 360     # -D_LP64=1 is only set on linux and mac. Setting on windows causes diff in
 361     # unpack200.exe. This variable is used in
 362     # FLAGS_SETUP_COMPILER_FLAGS_FOR_JDK_HELPER.
 363     if test "x$OPENJDK_$1_OS" = xlinux || test "x$OPENJDK_$1_OS" = xmacosx; then
 364       OPENJDK_$1_ADD_LP64="-D_LP64=1"
 365     fi
 366   fi
 367 
 368   if test "x$COMPILE_TYPE" = "xcross"; then
 369     # FIXME: ... or should this include reduced builds..?
 370     DEFINE_CROSS_COMPILE_ARCH="CROSS_COMPILE_ARCH:=$OPENJDK_$1_CPU_LEGACY"
 371   else
 372     DEFINE_CROSS_COMPILE_ARCH=""
 373   fi
 374   AC_SUBST(DEFINE_CROSS_COMPILE_ARCH)
 375 
 376   # Convert openjdk platform names to hotspot names
 377 
 378   HOTSPOT_$1_OS=${OPENJDK_$1_OS}
 379   if test "x$OPENJDK_$1_OS" = xmacosx; then
 380     HOTSPOT_$1_OS=bsd
 381   fi
 382   AC_SUBST(HOTSPOT_$1_OS)
 383 
 384   HOTSPOT_$1_OS_TYPE=${OPENJDK_$1_OS_TYPE}
 385   if test "x$OPENJDK_$1_OS_TYPE" = xunix; then
 386     HOTSPOT_$1_OS_TYPE=posix
 387   fi
 388   AC_SUBST(HOTSPOT_$1_OS_TYPE)
 389 
 390   HOTSPOT_$1_CPU=${OPENJDK_$1_CPU}
 391   if test "x$OPENJDK_$1_CPU" = xx86; then
 392     HOTSPOT_$1_CPU=x86_32
 393   elif test "x$OPENJDK_$1_CPU" = xsparcv9; then
 394     HOTSPOT_$1_CPU=sparc
 395   elif test "x$OPENJDK_$1_CPU" = xppc64; then
 396     HOTSPOT_$1_CPU=ppc_64
 397   elif test "x$OPENJDK_$1_CPU" = xppc64le; then
 398     HOTSPOT_$1_CPU=ppc_64
 399   fi
 400   AC_SUBST(HOTSPOT_$1_CPU)
 401 
 402   # This is identical with OPENJDK_*, but define anyway for consistency.
 403   HOTSPOT_$1_CPU_ARCH=${OPENJDK_$1_CPU_ARCH}
 404   AC_SUBST(HOTSPOT_$1_CPU_ARCH)
 405 
 406   # Setup HOTSPOT_$1_CPU_DEFINE
 407   if test "x$OPENJDK_$1_CPU" = xx86; then
 408     HOTSPOT_$1_CPU_DEFINE=IA32
 409   elif test "x$OPENJDK_$1_CPU" = xx86_64; then
 410     HOTSPOT_$1_CPU_DEFINE=AMD64
 411   elif test "x$OPENJDK_$1_CPU" = xsparcv9; then
 412     HOTSPOT_$1_CPU_DEFINE=SPARC
 413   elif test "x$OPENJDK_$1_CPU" = xaarch64; then
 414     HOTSPOT_$1_CPU_DEFINE=AARCH64
 415   elif test "x$OPENJDK_$1_CPU" = xppc64; then
 416     HOTSPOT_$1_CPU_DEFINE=PPC64
 417   elif test "x$OPENJDK_$1_CPU" = xppc64le; then
 418     HOTSPOT_$1_CPU_DEFINE=PPC64
 419 
 420   # The cpu defines below are for zero, we don't support them directly.
 421   elif test "x$OPENJDK_$1_CPU" = xsparc; then
 422     HOTSPOT_$1_CPU_DEFINE=SPARC
 423   elif test "x$OPENJDK_$1_CPU" = xppc; then
 424     HOTSPOT_$1_CPU_DEFINE=PPC32
 425   elif test "x$OPENJDK_$1_CPU" = xs390; then
 426     HOTSPOT_$1_CPU_DEFINE=S390
 427   elif test "x$OPENJDK_$1_CPU" = xs390x; then
 428     HOTSPOT_$1_CPU_DEFINE=S390
 429   elif test "x$OPENJDK_$1_CPU" != x; then
 430     HOTSPOT_$1_CPU_DEFINE=$(echo $OPENJDK_$1_CPU | tr a-z A-Z)
 431   fi
 432   AC_SUBST(HOTSPOT_$1_CPU_DEFINE)
 433 
 434 ])
 435 
 436 AC_DEFUN([PLATFORM_SET_MODULE_TARGET_OS_VALUES],
 437 [
 438   if test "x$OPENJDK_TARGET_OS" = xmacosx; then
 439     OPENJDK_MODULE_TARGET_OS_NAME="macos"
 440   else
 441     OPENJDK_MODULE_TARGET_OS_NAME="$OPENJDK_TARGET_OS"
 442   fi
 443 
 444   if test "x$OPENJDK_TARGET_CPU" = xx86_64; then
 445     OPENJDK_MODULE_TARGET_OS_ARCH="amd64"
 446   else
 447     OPENJDK_MODULE_TARGET_OS_ARCH="$OPENJDK_TARGET_CPU"
 448   fi
 449 
 450   AC_SUBST(OPENJDK_MODULE_TARGET_OS_NAME)
 451   AC_SUBST(OPENJDK_MODULE_TARGET_OS_ARCH)
 452 ])
 453 
 454 #%%% Build and target systems %%%
 455 AC_DEFUN_ONCE([PLATFORM_SETUP_OPENJDK_BUILD_AND_TARGET],
 456 [
 457   # Figure out the build and target systems. # Note that in autoconf terminology, "build" is obvious, but "target"
 458   # is confusing; it assumes you are cross-compiling a cross-compiler (!)  and "target" is thus the target of the
 459   # product you're building. The target of this build is called "host". Since this is confusing to most people, we
 460   # have not adopted that system, but use "target" as the platform we are building for. In some places though we need
 461   # to use the configure naming style.
 462   AC_CANONICAL_BUILD
 463   AC_CANONICAL_HOST
 464   AC_CANONICAL_TARGET
 465 
 466   PLATFORM_EXTRACT_TARGET_AND_BUILD
 467   PLATFORM_SETUP_TARGET_CPU_BITS
 468   PLATFORM_SET_MODULE_TARGET_OS_VALUES
 469   PLATFORM_SETUP_LEGACY_VARS
 470 ])
 471 
 472 AC_DEFUN_ONCE([PLATFORM_SETUP_OPENJDK_BUILD_OS_VERSION],
 473 [
 474   ###############################################################################
 475 
 476   # Note that this is the build platform OS version!
 477 
 478   OS_VERSION="`uname -r | ${SED} 's!\.! !g' | ${SED} 's!-! !g'`"
 479   OS_VERSION_MAJOR="`${ECHO} ${OS_VERSION} | ${CUT} -f 1 -d ' '`"
 480   OS_VERSION_MINOR="`${ECHO} ${OS_VERSION} | ${CUT} -f 2 -d ' '`"
 481   OS_VERSION_MICRO="`${ECHO} ${OS_VERSION} | ${CUT} -f 3 -d ' '`"
 482   AC_SUBST(OS_VERSION_MAJOR)
 483   AC_SUBST(OS_VERSION_MINOR)
 484   AC_SUBST(OS_VERSION_MICRO)
 485 ])
 486 
 487 # Support macro for PLATFORM_SETUP_OPENJDK_TARGET_BITS.
 488 # Add -mX to various FLAGS variables.
 489 AC_DEFUN([PLATFORM_SET_COMPILER_TARGET_BITS_FLAGS],
 490 [
 491   # When we add flags to the "official" CFLAGS etc, we need to
 492   # keep track of these additions in ADDED_CFLAGS etc. These
 493   # will later be checked to make sure only controlled additions
 494   # have been made to CFLAGS etc.
 495   ADDED_CFLAGS=" ${COMPILER_TARGET_BITS_FLAG}${OPENJDK_TARGET_CPU_BITS}"
 496   ADDED_CXXFLAGS=" ${COMPILER_TARGET_BITS_FLAG}${OPENJDK_TARGET_CPU_BITS}"
 497   ADDED_LDFLAGS=" ${COMPILER_TARGET_BITS_FLAG}${OPENJDK_TARGET_CPU_BITS}"
 498 
 499   CFLAGS="${CFLAGS}${ADDED_CFLAGS}"
 500   CXXFLAGS="${CXXFLAGS}${ADDED_CXXFLAGS}"
 501   LDFLAGS="${LDFLAGS}${ADDED_LDFLAGS}"
 502 
 503   CFLAGS_JDK="${CFLAGS_JDK}${ADDED_CFLAGS}"
 504   CXXFLAGS_JDK="${CXXFLAGS_JDK}${ADDED_CXXFLAGS}"
 505   LDFLAGS_JDK="${LDFLAGS_JDK}${ADDED_LDFLAGS}"
 506 
 507   JVM_CFLAGS="$JVM_CFLAGS $ADDED_CFLAGS"
 508   JVM_LDFLAGS="$JVM_LDFLAGS $ADDED_LDFLAGS"
 509   JVM_ASFLAGS="$JVM_ASFLAGS $ADDED_CFLAGS"
 510 ])
 511 
 512 AC_DEFUN_ONCE([PLATFORM_SETUP_OPENJDK_TARGET_BITS],
 513 [
 514   ###############################################################################
 515   #
 516   # Now we check if libjvm.so will use 32 or 64 bit pointers for the C/C++ code.
 517   # (The JVM can use 32 or 64 bit Java pointers but that decision
 518   # is made at runtime.)
 519   #
 520 
 521   if test "x$OPENJDK_TARGET_OS" = xsolaris || test "x$OPENJDK_TARGET_OS" = xaix; then
 522     # Always specify -m flag on Solaris
 523     # And -q on AIX because otherwise the compiler produces 32-bit objects by default
 524     PLATFORM_SET_COMPILER_TARGET_BITS_FLAGS
 525   elif test "x$COMPILE_TYPE" = xreduced; then
 526     if test "x$OPENJDK_TARGET_OS_TYPE" = xunix; then
 527       # Specify -m if running reduced on unix platforms
 528       PLATFORM_SET_COMPILER_TARGET_BITS_FLAGS
 529     fi
 530   fi
 531   if test "x$OPENJDK_TARGET_OS" = xmacosx; then
 532     JVM_CFLAGS="$JVM_CFLAGS ${COMPILER_TARGET_BITS_FLAG}${OPENJDK_TARGET_CPU_BITS}"
 533     JVM_LDFLAGS="$JVM_LDFLAGS ${COMPILER_TARGET_BITS_FLAG}${OPENJDK_TARGET_CPU_BITS}"
 534     JVM_ASFLAGS="$JVM_ASFLAGS ${COMPILER_TARGET_BITS_FLAG}${OPENJDK_TARGET_CPU_BITS}"
 535   fi
 536 
 537   # Make compilation sanity check
 538   AC_CHECK_HEADERS([stdio.h], , [
 539     AC_MSG_NOTICE([Failed to compile stdio.h. This likely implies missing compile dependencies.])
 540     if test "x$COMPILE_TYPE" = xreduced; then
 541       HELP_MSG_MISSING_DEPENDENCY([reduced])
 542       AC_MSG_NOTICE([You are doing a reduced build. Check that you have 32-bit libraries installed. $HELP_MSG])
 543     elif test "x$COMPILE_TYPE" = xcross; then
 544       AC_MSG_NOTICE([You are doing a cross-compilation. Check that you have all target platform libraries installed.])
 545     fi
 546     AC_MSG_ERROR([Cannot continue.])
 547   ])
 548 
 549   AC_CHECK_SIZEOF([int *], [1111])
 550 
 551   # AC_CHECK_SIZEOF defines 'ac_cv_sizeof_int_p' to hold the number of bytes used by an 'int*'
 552   if test "x$ac_cv_sizeof_int_p" = x; then
 553     # The test failed, lets stick to the assumed value.
 554     AC_MSG_WARN([The number of bits in the target could not be determined, using $OPENJDK_TARGET_CPU_BITS.])
 555   else
 556     TESTED_TARGET_CPU_BITS=`expr 8 \* $ac_cv_sizeof_int_p`
 557 
 558     if test "x$TESTED_TARGET_CPU_BITS" != "x$OPENJDK_TARGET_CPU_BITS"; then
 559       # This situation may happen on 64-bit platforms where the compiler by default only generates 32-bit objects
 560       # Let's try to implicitely set the compilers target architecture and retry the test
 561       AC_MSG_NOTICE([The tested number of bits in the target ($TESTED_TARGET_CPU_BITS) differs from the number of bits expected to be found in the target ($OPENJDK_TARGET_CPU_BITS).])
 562       AC_MSG_NOTICE([Retrying with platforms compiler target bits flag to ${COMPILER_TARGET_BITS_FLAG}${OPENJDK_TARGET_CPU_BITS}])
 563       PLATFORM_SET_COMPILER_TARGET_BITS_FLAGS
 564 
 565       # We have to unset 'ac_cv_sizeof_int_p' first, otherwise AC_CHECK_SIZEOF will use the previously cached value!
 566       unset ac_cv_sizeof_int_p
 567       # And we have to undef the definition of SIZEOF_INT_P in confdefs.h by the previous invocation of AC_CHECK_SIZEOF
 568       cat >>confdefs.h <<_ACEOF
 569 #undef SIZEOF_INT_P
 570 _ACEOF
 571 
 572       AC_CHECK_SIZEOF([int *], [1111])
 573 
 574       TESTED_TARGET_CPU_BITS=`expr 8 \* $ac_cv_sizeof_int_p`
 575 
 576       if test "x$TESTED_TARGET_CPU_BITS" != "x$OPENJDK_TARGET_CPU_BITS"; then
 577         AC_MSG_NOTICE([The tested number of bits in the target ($TESTED_TARGET_CPU_BITS) differs from the number of bits expected to be found in the target ($OPENJDK_TARGET_CPU_BITS)])
 578         if test "x$COMPILE_TYPE" = xreduced; then
 579           HELP_MSG_MISSING_DEPENDENCY([reduced])
 580           AC_MSG_NOTICE([You are doing a reduced build. Check that you have 32-bit libraries installed. $HELP_MSG])
 581         elif test "x$COMPILE_TYPE" = xcross; then
 582           AC_MSG_NOTICE([You are doing a cross-compilation. Check that you have all target platform libraries installed.])
 583         fi
 584         AC_MSG_ERROR([Cannot continue.])
 585       fi
 586     fi
 587   fi
 588 
 589   AC_MSG_CHECKING([for target address size])
 590   AC_MSG_RESULT([$OPENJDK_TARGET_CPU_BITS bits])
 591 ])
 592 
 593 AC_DEFUN_ONCE([PLATFORM_SETUP_OPENJDK_TARGET_ENDIANNESS],
 594 [
 595   ###############################################################################
 596   #
 597   # Is the target little of big endian?
 598   #
 599   AC_C_BIGENDIAN([ENDIAN="big"],[ENDIAN="little"],[ENDIAN="unknown"],[ENDIAN="universal_endianness"])
 600 
 601   if test "x$ENDIAN" = xuniversal_endianness; then
 602     AC_MSG_ERROR([Building with both big and little endianness is not supported])
 603   fi
 604   if test "x$ENDIAN" != "x$OPENJDK_TARGET_CPU_ENDIAN"; then
 605     AC_MSG_ERROR([The tested endian in the target ($ENDIAN) differs from the endian expected to be found in the target ($OPENJDK_TARGET_CPU_ENDIAN)])
 606   fi
 607 ])