1 #
   2 # Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved.
   3 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4 #
   5 # This code is free software; you can redistribute it and/or modify it
   6 # under the terms of the GNU General Public License version 2 only, as
   7 # published by the Free Software Foundation.  Oracle designates this
   8 # particular file as subject to the "Classpath" exception as provided
   9 # by Oracle in the LICENSE file that accompanied this code.
  10 #
  11 # This code is distributed in the hope that it will be useful, but WITHOUT
  12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13 # FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14 # version 2 for more details (a copy is included in the LICENSE file that
  15 # accompanied this code).
  16 #
  17 # You should have received a copy of the GNU General Public License version
  18 # 2 along with this work; if not, write to the Free Software Foundation,
  19 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20 #
  21 # Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22 # or visit www.oracle.com if you need additional information or have any
  23 # questions.
  24 #
  25 
  26 ########################################################################
  27 # This file handles detection of the Boot JDK. The Boot JDK detection 
  28 # process has been developed as a response to solve a complex real-world 
  29 # problem. Initially, it was simple, but it has grown as platform after 
  30 # platform, idiosyncracy after idiosyncracy has been supported.
  31 #
  32 # The basic idea is this:
  33 # 1) You need an acceptable *) JDK to use as a Boot JDK
  34 # 2) There are several ways to locate a JDK, that are mostly platform 
  35 #    dependent **)
  36 # 3) You can have multiple JDKs installed
  37 # 4) If possible, configure should try to dig out an acceptable JDK 
  38 #    automatically, without having to resort to command-line options
  39 #
  40 # *)  acceptable means e.g. JDK7 for building JDK8, a complete JDK (with 
  41 #     javac) and not a JRE, etc. 
  42 #
  43 # **) On Windows we typically use a well-known path. 
  44 #     On MacOSX we typically use the tool java_home.
  45 #     On Linux we typically find javac in the $PATH, and then follow a 
  46 #     chain of symlinks that often ends up in a real JDK. 
  47 #
  48 # This leads to the code where we check in different ways to locate a 
  49 # JDK, and if one is found, check if it is acceptable. If not, we print 
  50 # our reasons for rejecting it (useful when debugging non-working 
  51 # configure situations) and continue checking the next one. 
  52 ########################################################################
  53 
  54 # Execute the check given as argument, and verify the result
  55 # If the Boot JDK was previously found, do nothing
  56 # $1 A command line (typically autoconf macro) to execute
  57 AC_DEFUN([BOOTJDK_DO_CHECK],
  58 [
  59   if test "x$BOOT_JDK_FOUND" = xno; then
  60     # Now execute the test
  61     $1
  62 
  63     # If previous step claimed to have found a JDK, check it to see if it seems to be valid.
  64     if test "x$BOOT_JDK_FOUND" = xmaybe; then
  65       # Do we have a bin/java?
  66       if test ! -x "$BOOT_JDK/bin/java"; then
  67         AC_MSG_NOTICE([Potential Boot JDK found at $BOOT_JDK did not contain bin/java; ignoring])
  68         BOOT_JDK_FOUND=no
  69       else
  70         # Do we have a bin/javac?
  71         if test ! -x "$BOOT_JDK/bin/javac"; then
  72           AC_MSG_NOTICE([Potential Boot JDK found at $BOOT_JDK did not contain bin/javac; ignoring])
  73           AC_MSG_NOTICE([(This might be an JRE instead of an JDK)])
  74           BOOT_JDK_FOUND=no
  75         else
  76           # Do we have an rt.jar? (On MacOSX it is called classes.jar)
  77           if test ! -f "$BOOT_JDK/jre/lib/rt.jar" && test ! -f "$BOOT_JDK/../Classes/classes.jar"; then
  78             AC_MSG_NOTICE([Potential Boot JDK found at $BOOT_JDK did not contain an rt.jar; ignoring])
  79             BOOT_JDK_FOUND=no
  80           else
  81             # Oh, this is looking good! We probably have found a proper JDK. Is it the correct version?
  82             BOOT_JDK_VERSION=`"$BOOT_JDK/bin/java" -version 2>&1 | head -n 1`
  83 
  84             # Extra M4 quote needed to protect [] in grep expression.
  85             [FOUND_CORRECT_VERSION=`echo $BOOT_JDK_VERSION | grep  '\"1\.[789]\.'`]
  86             if test "x$FOUND_CORRECT_VERSION" = x; then
  87               AC_MSG_NOTICE([Potential Boot JDK found at $BOOT_JDK is incorrect JDK version ($BOOT_JDK_VERSION); ignoring])
  88               AC_MSG_NOTICE([(Your Boot JDK must be version 7, 8 or 9)])
  89               BOOT_JDK_FOUND=no
  90             else
  91               # We're done! :-)
  92               BOOT_JDK_FOUND=yes
  93               BASIC_FIXUP_PATH(BOOT_JDK)
  94               AC_MSG_CHECKING([for Boot JDK])
  95               AC_MSG_RESULT([$BOOT_JDK])
  96               AC_MSG_CHECKING([Boot JDK version])
  97               BOOT_JDK_VERSION=`"$BOOT_JDK/bin/java" -version 2>&1 | $TR '\n\r' '  '`
  98               AC_MSG_RESULT([$BOOT_JDK_VERSION])
  99             fi # end check jdk version
 100           fi # end check rt.jar
 101         fi # end check javac
 102       fi # end check java
 103     fi # end check boot jdk found
 104   fi
 105 ])
 106 
 107 # Test: Is bootjdk explicitely set by command line arguments?
 108 AC_DEFUN([BOOTJDK_CHECK_ARGUMENTS],
 109 [
 110   if test "x$with_boot_jdk" != x; then
 111     BOOT_JDK=$with_boot_jdk
 112     BOOT_JDK_FOUND=maybe
 113     AC_MSG_NOTICE([Found potential Boot JDK using configure arguments])
 114   fi
 115 ])
 116 
 117 # Test: Is bootjdk available from builddeps?
 118 AC_DEFUN([BOOTJDK_CHECK_BUILDDEPS],
 119 [
 120   BDEPS_CHECK_MODULE(BOOT_JDK, bootjdk, xxx, [BOOT_JDK_FOUND=maybe], [BOOT_JDK_FOUND=no])
 121 ])
 122 
 123 # Test: Is $JAVA_HOME set?
 124 AC_DEFUN([BOOTJDK_CHECK_JAVA_HOME],
 125 [
 126   if test "x$JAVA_HOME" != x; then
 127     JAVA_HOME_PROCESSED="$JAVA_HOME"
 128     BASIC_FIXUP_PATH(JAVA_HOME_PROCESSED)
 129     if test ! -d "$JAVA_HOME_PROCESSED"; then
 130       AC_MSG_NOTICE([Your JAVA_HOME points to a non-existing directory!])
 131     else
 132       # Aha, the user has set a JAVA_HOME
 133       # let us use that as the Boot JDK.
 134       BOOT_JDK="$JAVA_HOME_PROCESSED"
 135       BOOT_JDK_FOUND=maybe
 136       AC_MSG_NOTICE([Found potential Boot JDK using JAVA_HOME])
 137     fi
 138   fi
 139 ])
 140 
 141 # Test: Is there a java or javac in the PATH, which is a symlink to the JDK?
 142 AC_DEFUN([BOOTJDK_CHECK_JAVA_IN_PATH_IS_SYMLINK],
 143 [
 144   AC_PATH_PROG(JAVAC_CHECK, javac)
 145   AC_PATH_PROG(JAVA_CHECK, java)
 146   BINARY="$JAVAC_CHECK"
 147   if test "x$JAVAC_CHECK" = x; then
 148     BINARY="$JAVA_CHECK"
 149   fi
 150   if test "x$BINARY" != x; then
 151     # So there is a java(c) binary, it might be part of a JDK.
 152     # Lets find the JDK/JRE directory by following symbolic links.
 153     # Linux/GNU systems often have links from /usr/bin/java to
 154     # /etc/alternatives/java to the real JDK binary.
 155     BASIC_REMOVE_SYMBOLIC_LINKS(BINARY)
 156     BOOT_JDK=`dirname "$BINARY"`
 157     BOOT_JDK=`cd "$BOOT_JDK/.."; pwd`
 158     if test -x "$BOOT_JDK/bin/javac" && test -x "$BOOT_JDK/bin/java"; then
 159       # Looks like we found ourselves an JDK
 160       BOOT_JDK_FOUND=maybe
 161       AC_MSG_NOTICE([Found potential Boot JDK using java(c) in PATH])
 162     fi
 163   fi
 164 ])
 165 
 166 # Test: Is there a /usr/libexec/java_home? (Typically on MacOSX)
 167 # $1: Argument to the java_home binary (optional)
 168 AC_DEFUN([BOOTJDK_CHECK_LIBEXEC_JAVA_HOME],
 169 [
 170   if test -x /usr/libexec/java_home; then
 171     BOOT_JDK=`/usr/libexec/java_home $1`
 172     BOOT_JDK_FOUND=maybe
 173     AC_MSG_NOTICE([Found potential Boot JDK using /usr/libexec/java_home $1])
 174   fi
 175 ])
 176 
 177 # Test: On MacOS X, can we find a boot jdk using /usr/libexec/java_home?
 178 AC_DEFUN([BOOTJDK_CHECK_MACOSX_JAVA_LOCATOR],
 179 [
 180   if test "x$OPENJDK_TARGET_OS" = xmacosx; then
 181     # First check at user selected default
 182     BOOTJDK_DO_CHECK([BOOTJDK_CHECK_LIBEXEC_JAVA_HOME()])
 183     # If that did not work out (e.g. too old), try explicit versions instead
 184     BOOTJDK_DO_CHECK([BOOTJDK_CHECK_LIBEXEC_JAVA_HOME([-v 1.9])])
 185     BOOTJDK_DO_CHECK([BOOTJDK_CHECK_LIBEXEC_JAVA_HOME([-v 1.8])])
 186     BOOTJDK_DO_CHECK([BOOTJDK_CHECK_LIBEXEC_JAVA_HOME([-v 1.7])])
 187   fi
 188 ])
 189 
 190 # Look for a jdk in the given path. If there are multiple, try to select the newest.
 191 # If found, set BOOT_JDK and BOOT_JDK_FOUND.
 192 # $1 = Path to directory containing jdk installations.
 193 # $2 = String to append to the found JDK directory to get the proper JDK home
 194 AC_DEFUN([BOOTJDK_FIND_BEST_JDK_IN_DIRECTORY],
 195 [
 196   BOOT_JDK_PREFIX="$1"
 197   BOOT_JDK_SUFFIX="$2"
 198   ALL_JDKS_FOUND=`$LS "$BOOT_JDK_PREFIX" 2> /dev/null | $SORT -r`
 199   if test "x$ALL_JDKS_FOUND" != x; then
 200     for JDK_TO_TRY in $ALL_JDKS_FOUND ; do
 201       BOOTJDK_DO_CHECK([
 202         BOOT_JDK="${BOOT_JDK_PREFIX}/${JDK_TO_TRY}${BOOT_JDK_SUFFIX}"
 203         if test -d "$BOOT_JDK"; then
 204           BOOT_JDK_FOUND=maybe
 205           AC_MSG_NOTICE([Found potential Boot JDK using well-known locations (in $BOOT_JDK_PREFIX/$JDK_TO_TRY)])
 206         fi
 207       ])
 208     done
 209   fi
 210 ])
 211 
 212 # Call BOOTJDK_FIND_BEST_JDK_IN_DIRECTORY, but use the given
 213 # environmental variable as base for where to look.
 214 # $1 Name of an environmal variable, assumed to point to the Program Files directory.
 215 AC_DEFUN([BOOTJDK_FIND_BEST_JDK_IN_WINDOWS_VIRTUAL_DIRECTORY],
 216 [
 217   if test "x[$]$1" != x; then
 218     VIRTUAL_DIR="[$]$1/Java"
 219     BASIC_WINDOWS_REWRITE_AS_UNIX_PATH(VIRTUAL_DIR)
 220     BOOTJDK_FIND_BEST_JDK_IN_DIRECTORY($VIRTUAL_DIR)
 221   fi
 222 ])
 223 
 224 # Test: Is there a JDK installed in default, well-known locations?
 225 AC_DEFUN([BOOTJDK_CHECK_WELL_KNOWN_LOCATIONS],
 226 [
 227   if test "x$OPENJDK_TARGET_OS" = xwindows; then
 228     BOOTJDK_DO_CHECK([BOOTJDK_FIND_BEST_JDK_IN_WINDOWS_VIRTUAL_DIRECTORY([ProgramW6432])])
 229     BOOTJDK_DO_CHECK([BOOTJDK_FIND_BEST_JDK_IN_WINDOWS_VIRTUAL_DIRECTORY([PROGRAMW6432])])
 230     BOOTJDK_DO_CHECK([BOOTJDK_FIND_BEST_JDK_IN_WINDOWS_VIRTUAL_DIRECTORY([PROGRAMFILES])])
 231     BOOTJDK_DO_CHECK([BOOTJDK_FIND_BEST_JDK_IN_WINDOWS_VIRTUAL_DIRECTORY([ProgramFiles])])
 232     BOOTJDK_DO_CHECK([BOOTJDK_FIND_BEST_JDK_IN_DIRECTORY([/cygdrive/c/Program Files/Java])])
 233   elif test "x$OPENJDK_TARGET_OS" = xmacosx; then
 234     BOOTJDK_DO_CHECK([BOOTJDK_FIND_BEST_JDK_IN_DIRECTORY([/Library/Java/JavaVirtualMachines],[/Contents/Home])])
 235     BOOTJDK_DO_CHECK([BOOTJDK_FIND_BEST_JDK_IN_DIRECTORY([/System/Library/Java/JavaVirtualMachines],[/Contents/Home])])
 236   elif test "x$OPENJDK_TARGET_OS" = xlinux; then
 237     BOOTJDK_DO_CHECK([BOOTJDK_FIND_BEST_JDK_IN_DIRECTORY([/usr/lib/jvm])])
 238   fi
 239 ])
 240 
 241 # Check that a command-line tool in the Boot JDK is correct
 242 # $1 = name of variable to assign
 243 # $2 = name of binary
 244 AC_DEFUN([BOOTJDK_CHECK_TOOL_IN_BOOTJDK],
 245 [
 246   # Use user overridden value if available, otherwise locate tool in the Boot JDK.
 247   BASIC_SETUP_TOOL($1, 
 248     [
 249       AC_MSG_CHECKING([for $2 in Boot JDK])
 250       $1=$BOOT_JDK/bin/$2
 251       if test ! -x [$]$1; then
 252         AC_MSG_RESULT(not found)
 253         AC_MSG_NOTICE([Your Boot JDK seems broken. This might be fixed by explicitely setting --with-boot-jdk])
 254         AC_MSG_ERROR([Could not find $2 in the Boot JDK])
 255       fi
 256       AC_MSG_RESULT(ok)
 257       AC_SUBST($1)
 258     ])
 259 ])
 260 
 261 ###############################################################################
 262 #
 263 # We need a Boot JDK to bootstrap the build.
 264 #
 265 
 266 AC_DEFUN_ONCE([BOOTJDK_SETUP_BOOT_JDK],
 267 [
 268   BOOT_JDK_FOUND=no
 269   AC_ARG_WITH(boot-jdk, [AS_HELP_STRING([--with-boot-jdk],
 270       [path to Boot JDK (used to bootstrap build) @<:@probed@:>@])])
 271 
 272   # We look for the Boot JDK through various means, going from more certain to
 273   # more of a guess-work. After each test, BOOT_JDK_FOUND is set to "yes" if
 274   # we detected something (if so, the path to the jdk is in BOOT_JDK). But we
 275   # must check if this is indeed valid; otherwise we'll continue looking.
 276 
 277   # Test: Is bootjdk explicitely set by command line arguments?
 278   BOOTJDK_DO_CHECK([BOOTJDK_CHECK_ARGUMENTS])
 279   if test "x$with_boot_jdk" != x && test "x$BOOT_JDK_FOUND" = xno; then
 280     # Having specified an argument which is incorrect will produce an instant failure;
 281     # we should not go on looking
 282     AC_MSG_ERROR([The path given by --with-boot-jdk does not contain a valid Boot JDK])
 283   fi
 284 
 285   # Test: Is bootjdk available from builddeps?
 286   BOOTJDK_DO_CHECK([BOOTJDK_CHECK_BUILDDEPS])
 287 
 288   # Test: On MacOS X, can we find a boot jdk using /usr/libexec/java_home?
 289   BOOTJDK_DO_CHECK([BOOTJDK_CHECK_MACOSX_JAVA_LOCATOR])
 290 
 291   # Test: Is $JAVA_HOME set?
 292   BOOTJDK_DO_CHECK([BOOTJDK_CHECK_JAVA_HOME])
 293 
 294   # Test: Is there a java or javac in the PATH, which is a symlink to the JDK?
 295   BOOTJDK_DO_CHECK([BOOTJDK_CHECK_JAVA_IN_PATH_IS_SYMLINK])
 296 
 297   # Test: Is there a JDK installed in default, well-known locations?
 298   BOOTJDK_DO_CHECK([BOOTJDK_CHECK_WELL_KNOWN_LOCATIONS])
 299 
 300   # If we haven't found anything yet, we've truly lost. Give up.
 301   if test "x$BOOT_JDK_FOUND" = xno; then
 302     HELP_MSG_MISSING_DEPENDENCY([openjdk])
 303     AC_MSG_NOTICE([Could not find a valid Boot JDK. $HELP_MSG])
 304     AC_MSG_NOTICE([This might be fixed by explicitely setting --with-boot-jdk])
 305     AC_MSG_ERROR([Cannot continue])
 306   fi
 307 
 308   # Setup proper paths for what we found
 309   BOOT_RTJAR="$BOOT_JDK/jre/lib/rt.jar"
 310   if test ! -f "$BOOT_RTJAR"; then
 311     # On MacOSX it is called classes.jar
 312     BOOT_RTJAR="$BOOT_JDK/../Classes/classes.jar"
 313     if test -f "$BOOT_RTJAR"; then
 314       # Remove the ..
 315       BOOT_RTJAR="`cd ${BOOT_RTJAR%/*} && pwd`/${BOOT_RTJAR##*/}"
 316     fi
 317   fi
 318   BOOT_TOOLSJAR="$BOOT_JDK/lib/tools.jar"
 319   BOOT_JDK="$BOOT_JDK"
 320   AC_SUBST(BOOT_RTJAR)
 321   AC_SUBST(BOOT_TOOLSJAR)
 322   AC_SUBST(BOOT_JDK)
 323 
 324   # Setup tools from the Boot JDK.
 325   BOOTJDK_CHECK_TOOL_IN_BOOTJDK(JAVA, java)
 326   BOOTJDK_CHECK_TOOL_IN_BOOTJDK(JAVAC, javac)
 327   BOOTJDK_CHECK_TOOL_IN_BOOTJDK(JAVAH, javah)
 328   BOOTJDK_CHECK_TOOL_IN_BOOTJDK(JAR, jar)
 329   BOOTJDK_CHECK_TOOL_IN_BOOTJDK(NATIVE2ASCII, native2ascii)
 330   BOOTJDK_CHECK_TOOL_IN_BOOTJDK(JARSIGNER, jarsigner)
 331 
 332   # Finally, set some other options...
 333 
 334   # When compiling code to be executed by the Boot JDK, force jdk7 compatibility.
 335   BOOT_JDK_SOURCETARGET="-source 7 -target 7"
 336   AC_SUBST(BOOT_JDK_SOURCETARGET)
 337   AC_SUBST(JAVAC_FLAGS)
 338 ])
 339 
 340 AC_DEFUN_ONCE([BOOTJDK_SETUP_BOOT_JDK_ARGUMENTS],
 341 [
 342   ##############################################################################
 343   #
 344   # Specify jvm options for anything that is run with the Boot JDK.
 345   # Not all JVM:s accept the same arguments on the command line.
 346   #
 347   AC_ARG_WITH(boot-jdk-jvmargs, [AS_HELP_STRING([--with-boot-jdk-jvmargs],
 348   [specify JVM arguments to be passed to all java invocations of boot JDK, overriding the default values,
 349   e.g --with-boot-jdk-jvmargs="-Xmx8G -enableassertions"])])
 350 
 351   AC_MSG_CHECKING([flags for boot jdk java command] )
 352 
 353   # Disable special log output when a debug build is used as Boot JDK...
 354   ADD_JVM_ARG_IF_OK([-XX:-PrintVMOptions -XX:-UnlockDiagnosticVMOptions -XX:-LogVMOutput],boot_jdk_jvmargs,[$JAVA])
 355 
 356   # Apply user provided options.
 357   ADD_JVM_ARG_IF_OK([$with_boot_jdk_jvmargs],boot_jdk_jvmargs,[$JAVA])
 358 
 359   AC_MSG_RESULT([$boot_jdk_jvmargs])
 360 
 361   # For now, general JAVA_FLAGS are the same as the boot jdk jvmargs
 362   JAVA_FLAGS=$boot_jdk_jvmargs
 363 
 364   AC_SUBST(BOOT_JDK_JVMARGS, $boot_jdk_jvmargs)
 365   AC_SUBST(JAVA_FLAGS)
 366 
 367 
 368   AC_MSG_CHECKING([flags for boot jdk java command for big configurations] )
 369 
 370   # Starting amount of heap memory.
 371   ADD_JVM_ARG_IF_OK([-Xms64M],boot_jdk_jvmargs_big,[$JAVA])
 372 
 373   # Maximum amount of heap memory.
 374   # Maximum stack size.
 375   if test "x$BUILD_NUM_BITS" = x32; then
 376     JVM_MAX_HEAP=1100M
 377     STACK_SIZE=768
 378   else
 379     # Running Javac on a JVM on a 64-bit machine, takes more space since 64-bit
 380     # pointers are used. Apparently, we need to increase the heap and stack
 381     # space for the jvm. More specifically, when running javac to build huge
 382     # jdk batch
 383     JVM_MAX_HEAP=1600M
 384     STACK_SIZE=1536
 385   fi
 386   ADD_JVM_ARG_IF_OK([-Xmx$JVM_MAX_HEAP],boot_jdk_jvmargs_big,[$JAVA])
 387   ADD_JVM_ARG_IF_OK([-XX:ThreadStackSize=$STACK_SIZE],boot_jdk_jvmargs_big,[$JAVA])
 388 
 389   AC_MSG_RESULT([$boot_jdk_jvmargs_big])

 390 
 391   JAVA_FLAGS_BIG=$boot_jdk_jvmargs_big
 392   AC_SUBST(JAVA_FLAGS_BIG)
 393 

 394 
 395   AC_MSG_CHECKING([flags for boot jdk java command for small configurations] )

 396 
 397   # Use serial gc for small short lived tools if possible
 398   ADD_JVM_ARG_IF_OK([-XX:+UseSerialGC],boot_jdk_jvmargs_small,[$JAVA])
 399   ADD_JVM_ARG_IF_OK([-Xms32M],boot_jdk_jvmargs_small,[$JAVA])
 400   ADD_JVM_ARG_IF_OK([-Xmx512M],boot_jdk_jvmargs_small,[$JAVA])
 401 
 402   AC_MSG_RESULT([$boot_jdk_jvmargs_small])
 403 
 404   JAVA_FLAGS_SMALL=$boot_jdk_jvmargs_small
 405   AC_SUBST(JAVA_FLAGS_SMALL)
 406 ])
--- EOF ---