1 #
  2 # Copyright (c) 2011, 2023, 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, idiosyncrasy after idiosyncrasy 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" && test ! -x "$BOOT_JDK/bin/java.exe"; 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" && test ! -x "$BOOT_JDK/bin/javac.exe"; 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           # Oh, this is looking good! We probably have found a proper JDK. Is it the correct version?
 77           java_to_test="$BOOT_JDK/bin/java"
 78           UTIL_FIXUP_EXECUTABLE(java_to_test)
 79           BOOT_JDK_VERSION_OUTPUT=`$java_to_test $USER_BOOT_JDK_OPTIONS -version 2>&1`
 80           # Additional [] needed to keep m4 from mangling shell constructs.
 81           [ BOOT_JDK_VERSION=`echo $BOOT_JDK_VERSION_OUTPUT | $AWK '/version "[0-9a-zA-Z\._\-]+"/ {print $ 0; exit;}'` ]
 82 
 83           if [ [[ "$BOOT_JDK_VERSION" =~ "Picked up" ]] ]; then
 84             AC_MSG_NOTICE([You have _JAVA_OPTIONS or JAVA_TOOL_OPTIONS set. This can mess up the build. Please use --with-boot-jdk-jvmargs instead.])
 85             AC_MSG_NOTICE([Java reports: "$BOOT_JDK_VERSION".])
 86             AC_MSG_ERROR([Cannot continue])
 87           fi
 88           if [ [[ "$BOOT_JDK_VERSION" =~ "Unrecognized option" ]] ]; then
 89             AC_MSG_NOTICE([The specified --with-boot-jdk-jvmargs is invalid for the tested java])
 90             AC_MSG_NOTICE([Error message: "$BOOT_JDK_VERSION".])
 91             AC_MSG_NOTICE([Please fix arguments, or point to an explicit boot JDK which accept these arguments])
 92             AC_MSG_ERROR([Cannot continue])
 93           fi
 94 
 95           # Extra M4 quote needed to protect [] in grep expression.
 96           [FOUND_CORRECT_VERSION=`$ECHO $BOOT_JDK_VERSION \
 97               | $EGREP "\"(${DEFAULT_ACCEPTABLE_BOOT_VERSIONS// /|})([\.+-].*)?\""`]
 98 
 99           if test "x$BOOT_JDK_VERSION" = x; then
100             AC_MSG_NOTICE([Potential Boot JDK found at $BOOT_JDK is not a working JDK; ignoring])
101             AC_MSG_NOTICE([Output from java -version was: $BOOT_JDK_VERSION_OUTPUT])
102             BOOT_JDK_FOUND=no
103           elif test "x$FOUND_CORRECT_VERSION" = x; then
104             AC_MSG_NOTICE([Potential Boot JDK found at $BOOT_JDK is incorrect JDK version ($BOOT_JDK_VERSION); ignoring])
105             AC_MSG_NOTICE([(Your Boot JDK version must be one of: $DEFAULT_ACCEPTABLE_BOOT_VERSIONS)])
106             BOOT_JDK_FOUND=no
107           else
108             # We're done! :-)
109             BOOT_JDK_FOUND=yes
110             UTIL_FIXUP_PATH(BOOT_JDK)
111             AC_MSG_CHECKING([for Boot JDK])
112             AC_MSG_RESULT([$BOOT_JDK])
113             AC_MSG_CHECKING([Boot JDK version])
114             BOOT_JDK_VERSION=`$java_to_test $USER_BOOT_JDK_OPTIONS -version 2>&1 | $TR -d '\r'`
115             # This is not a no-op; it will portably convert newline to space
116             BOOT_JDK_VERSION=`$ECHO $BOOT_JDK_VERSION`
117             AC_MSG_RESULT([$BOOT_JDK_VERSION])
118           fi # end check jdk version
119         fi # end check javac
120       fi # end check java
121     fi # end check boot jdk found
122   fi
123 ])
124 
125 # Test: Is bootjdk explicitly set by command line arguments?
126 AC_DEFUN([BOOTJDK_CHECK_ARGUMENTS],
127 [
128   if test "x$with_boot_jdk" != x; then
129     BOOT_JDK_ARG="$with_boot_jdk"
130     UTIL_FIXUP_PATH(BOOT_JDK_ARG)
131     if test -d "$BOOT_JDK_ARG"; then
132       BOOT_JDK=$BOOT_JDK_ARG
133       BOOT_JDK_FOUND=maybe
134     elif test -f "$BOOT_JDK_ARG"; then
135       case "$BOOT_JDK_ARG" in
136         *.tar.gz )
137             BOOT_JDK_SUPPORT_DIR=$CONFIGURESUPPORT_OUTPUTDIR/boot-jdk
138             $RM -rf $BOOT_JDK_SUPPORT_DIR
139             $MKDIR -p $BOOT_JDK_SUPPORT_DIR
140             $GUNZIP -c $BOOT_JDK_ARG | $TAR xf - -C $BOOT_JDK_SUPPORT_DIR
141 
142             # Try to find javac to determine BOOT_JDK path
143             BOOT_JDK_JAVAC_PATH=`$FIND $BOOT_JDK_SUPPORT_DIR | $GREP "/bin/javac"`
144             if test "x$BOOT_JDK_JAVAC_PATH" != x; then
145               BOOT_JDK_FOUND=maybe
146               BOOT_JDK=$($DIRNAME $($DIRNAME $BOOT_JDK_JAVAC_PATH))
147             else
148               BOOT_JDK_FOUND=no
149             fi
150           ;;
151         * )
152             BOOT_JDK_FOUND=no
153           ;;
154       esac
155     else
156       BOOT_JDK_FOUND=no
157     fi
158     AC_MSG_NOTICE([Found potential Boot JDK using configure arguments])
159   fi
160 ])
161 
162 # Test: Is $JAVA_HOME set?
163 AC_DEFUN([BOOTJDK_CHECK_JAVA_HOME],
164 [
165   if test "x$JAVA_HOME" != x; then
166     JAVA_HOME_PROCESSED="$JAVA_HOME"
167     UTIL_FIXUP_PATH(JAVA_HOME_PROCESSED, NOFAIL)
168     if test "x$JAVA_HOME_PROCESSED" = x || test ! -d "$JAVA_HOME_PROCESSED"; then
169       AC_MSG_NOTICE([Your JAVA_HOME points to a non-existing directory!])
170     else
171       # Aha, the user has set a JAVA_HOME
172       # let us use that as the Boot JDK.
173       BOOT_JDK="$JAVA_HOME_PROCESSED"
174       BOOT_JDK_FOUND=maybe
175       AC_MSG_NOTICE([Found potential Boot JDK using JAVA_HOME])
176     fi
177   fi
178 ])
179 
180 # Test: Is there a java or javac in the PATH, which is a symlink to the JDK?
181 AC_DEFUN([BOOTJDK_CHECK_JAVA_IN_PATH_IS_SYMLINK],
182 [
183   UTIL_LOOKUP_PROGS(JAVAC_CHECK, javac, , NOFIXPATH)
184   UTIL_LOOKUP_PROGS(JAVA_CHECK, java, , NOFIXPATH)
185   BINARY="$JAVAC_CHECK"
186   if test "x$JAVAC_CHECK" = x; then
187     BINARY="$JAVA_CHECK"
188   fi
189   if test "x$BINARY" != x; then
190     # So there is a java(c) binary, it might be part of a JDK.
191     # Lets find the JDK/JRE directory by following symbolic links.
192     # Linux/GNU systems often have links from /usr/bin/java to
193     # /etc/alternatives/java to the real JDK binary.
194     UTIL_REMOVE_SYMBOLIC_LINKS(BINARY)
195     BOOT_JDK=`dirname "$BINARY"`
196     BOOT_JDK=`cd "$BOOT_JDK/.."; pwd`
197     if test -x "$BOOT_JDK/bin/javac" && test -x "$BOOT_JDK/bin/java"; then
198       # Looks like we found ourselves an JDK
199       BOOT_JDK_FOUND=maybe
200       AC_MSG_NOTICE([Found potential Boot JDK using java(c) in PATH])
201     fi
202   fi
203 ])
204 
205 # Test: Is there a /usr/libexec/java_home? (Typically on MacOSX)
206 # $1: Argument to the java_home binary (optional)
207 AC_DEFUN([BOOTJDK_CHECK_LIBEXEC_JAVA_HOME],
208 [
209   if test -x /usr/libexec/java_home; then
210     BOOT_JDK=`/usr/libexec/java_home $1`
211     BOOT_JDK_FOUND=maybe
212     AC_MSG_NOTICE([Found potential Boot JDK using /usr/libexec/java_home $1])
213   fi
214 ])
215 
216 # Test: On MacOS X, can we find a boot jdk using /usr/libexec/java_home?
217 AC_DEFUN([BOOTJDK_CHECK_MACOSX_JAVA_LOCATOR],
218 [
219   if test "x$OPENJDK_TARGET_OS" = xmacosx; then
220     # First check at user selected default
221     BOOTJDK_DO_CHECK([BOOTJDK_CHECK_LIBEXEC_JAVA_HOME()])
222     # If that did not work out (e.g. too old), try explicit versions instead
223     for ver in $DEFAULT_ACCEPTABLE_BOOT_VERSIONS ; do
224       BOOTJDK_DO_CHECK([BOOTJDK_CHECK_LIBEXEC_JAVA_HOME([-v $ver])])
225     done
226   fi
227 ])
228 
229 # Look for a jdk in the given path. If there are multiple, try to select the newest.
230 # If found, set BOOT_JDK and BOOT_JDK_FOUND.
231 # $1 = Path to directory containing jdk installations.
232 # $2 = String to append to the found JDK directory to get the proper JDK home
233 AC_DEFUN([BOOTJDK_FIND_BEST_JDK_IN_DIRECTORY],
234 [
235   BOOT_JDK_PREFIX="$1"
236   BOOT_JDK_SUFFIX="$2"
237   ALL_JDKS_FOUND=`$LS "$BOOT_JDK_PREFIX" 2> /dev/null | $SORT -r`
238   if test "x$ALL_JDKS_FOUND" != x; then
239     for JDK_TO_TRY in $ALL_JDKS_FOUND ; do
240       BOOTJDK_DO_CHECK([
241         BOOT_JDK="${BOOT_JDK_PREFIX}/${JDK_TO_TRY}${BOOT_JDK_SUFFIX}"
242         if test -d "$BOOT_JDK"; then
243           BOOT_JDK_FOUND=maybe
244           AC_MSG_NOTICE([Found potential Boot JDK using well-known locations (in $BOOT_JDK_PREFIX/$JDK_TO_TRY)])
245         fi
246       ])
247     done
248   fi
249 ])
250 
251 # Call BOOTJDK_FIND_BEST_JDK_IN_DIRECTORY, but use the given
252 # environmental variable as base for where to look.
253 # $1 Name of an environmal variable, assumed to point to the Program Files directory.
254 AC_DEFUN([BOOTJDK_FIND_BEST_JDK_IN_WINDOWS_VIRTUAL_DIRECTORY],
255 [
256   if test "x[$]$1" != x; then
257     VIRTUAL_DIR="[$]$1/Java"
258     UTIL_FIXUP_PATH(VIRTUAL_DIR, NOFAIL)
259     if test "x$VIRTUAL_DIR" != x; then
260       BOOTJDK_FIND_BEST_JDK_IN_DIRECTORY($VIRTUAL_DIR)
261     fi
262   fi
263 ])
264 
265 # Test: Is there a JDK installed in default, well-known locations?
266 AC_DEFUN([BOOTJDK_CHECK_WELL_KNOWN_LOCATIONS],
267 [
268   if test "x$OPENJDK_TARGET_OS" = xwindows; then
269     BOOTJDK_DO_CHECK([BOOTJDK_FIND_BEST_JDK_IN_WINDOWS_VIRTUAL_DIRECTORY([ProgramW6432])])
270     BOOTJDK_DO_CHECK([BOOTJDK_FIND_BEST_JDK_IN_WINDOWS_VIRTUAL_DIRECTORY([PROGRAMW6432])])
271     BOOTJDK_DO_CHECK([BOOTJDK_FIND_BEST_JDK_IN_WINDOWS_VIRTUAL_DIRECTORY([PROGRAMFILES])])
272     BOOTJDK_DO_CHECK([BOOTJDK_FIND_BEST_JDK_IN_WINDOWS_VIRTUAL_DIRECTORY([ProgramFiles])])
273     BOOTJDK_DO_CHECK([BOOTJDK_FIND_BEST_JDK_IN_DIRECTORY([/cygdrive/c/Program Files/Java])])
274   elif test "x$OPENJDK_TARGET_OS" = xmacosx; then
275     BOOTJDK_DO_CHECK([BOOTJDK_FIND_BEST_JDK_IN_DIRECTORY([/Library/Java/JavaVirtualMachines],[/Contents/Home])])
276     BOOTJDK_DO_CHECK([BOOTJDK_FIND_BEST_JDK_IN_DIRECTORY([/System/Library/Java/JavaVirtualMachines],[/Contents/Home])])
277   elif test "x$OPENJDK_TARGET_OS" = xlinux; then
278     BOOTJDK_DO_CHECK([BOOTJDK_FIND_BEST_JDK_IN_DIRECTORY([/usr/lib/jvm])])
279   fi
280 ])
281 
282 # Check that a command-line tool in the Boot JDK is correct
283 # $1 = name of variable to assign
284 # $2 = name of binary
285 AC_DEFUN([BOOTJDK_CHECK_TOOL_IN_BOOTJDK],
286 [
287   # Use user overridden value if available, otherwise locate tool in the Boot JDK.
288   UTIL_REQUIRE_SPECIAL($1,
289     [
290       AC_MSG_CHECKING([for $2 [[Boot JDK]]])
291       $1=$BOOT_JDK/bin/$2
292       if test ! -x [$]$1 && test ! -x [$]$1.exe; then
293         AC_MSG_RESULT(not found)
294         AC_MSG_NOTICE([Your Boot JDK seems broken. This might be fixed by explicitly setting --with-boot-jdk])
295         AC_MSG_ERROR([Could not find $2 in the Boot JDK])
296       fi
297       AC_MSG_RESULT(\[$]BOOT_JDK/bin/$2)
298       UTIL_FIXUP_EXECUTABLE($1)
299       AC_SUBST($1)
300     ])
301 ])
302 
303 # Setup CLASSPATH environment variable
304 AC_DEFUN([BOOTJDK_SETUP_CLASSPATH],
305 [
306   AC_ARG_WITH([classpath], [AS_HELP_STRING([--with-classpath],
307       [Optional classpath to set as CLASSPATH to all Java invocations @<:@none@:>@])])
308 
309   if test "x$CLASSPATH" != x; then
310     AC_MSG_WARN([CLASSPATH is set in the environment. This will be ignored. Use --with-classpath instead.])
311   fi
312 
313   CLASSPATH=
314 
315   if test "x$with_classpath" != x && test "x$with_classpath" != xyes &&
316       test "x$with_classpath" != xno ; then
317     CLASSPATH="$with_classpath"
318     AC_MSG_CHECKING([for classpath to use for all Java invocations])
319     AC_MSG_RESULT([$CLASSPATH])
320   fi
321 
322   AC_SUBST(CLASSPATH)
323 ])
324 
325 ################################################################################
326 #
327 # We need a Boot JDK to bootstrap the build.
328 #
329 
330 AC_DEFUN_ONCE([BOOTJDK_SETUP_BOOT_JDK],
331 [
332   BOOT_JDK_FOUND=no
333   AC_ARG_WITH(boot-jdk, [AS_HELP_STRING([--with-boot-jdk],
334       [path to Boot JDK (used to bootstrap build) @<:@probed@:>@])])
335 
336   AC_ARG_WITH(boot-jdk-jvmargs, [AS_HELP_STRING([--with-boot-jdk-jvmargs],
337   [specify additional arguments to be passed to Boot JDK tools @<:@none@:>@])])
338 
339   USER_BOOT_JDK_OPTIONS="$with_boot_jdk_jvmargs"
340 
341   # We look for the Boot JDK through various means, going from more certain to
342   # more of a guess-work. After each test, BOOT_JDK_FOUND is set to "yes" if
343   # we detected something (if so, the path to the jdk is in BOOT_JDK). But we
344   # must check if this is indeed valid; otherwise we'll continue looking.
345 
346   # Test: Is bootjdk explicitly set by command line arguments?
347   BOOTJDK_DO_CHECK([BOOTJDK_CHECK_ARGUMENTS])
348   if test "x$with_boot_jdk" != x && test "x$BOOT_JDK_FOUND" = xno; then
349     # Having specified an argument which is incorrect will produce an instant failure;
350     # we should not go on looking
351     AC_MSG_ERROR([The path given by --with-boot-jdk does not contain a valid Boot JDK])
352   fi
353 
354   # Test: Is $JAVA_HOME set?
355   BOOTJDK_DO_CHECK([BOOTJDK_CHECK_JAVA_HOME])
356 
357   # Test: On MacOS X, can we find a boot jdk using /usr/libexec/java_home?
358   BOOTJDK_DO_CHECK([BOOTJDK_CHECK_MACOSX_JAVA_LOCATOR])
359 
360   # Test: Is there a java or javac in the PATH, which is a symlink to the JDK?
361   BOOTJDK_DO_CHECK([BOOTJDK_CHECK_JAVA_IN_PATH_IS_SYMLINK])
362 
363   # Test: Is there a JDK installed in default, well-known locations?
364   BOOTJDK_DO_CHECK([BOOTJDK_CHECK_WELL_KNOWN_LOCATIONS])
365 
366   # If we haven't found anything yet, we've truly lost. Give up.
367   if test "x$BOOT_JDK_FOUND" = xno; then
368     HELP_MSG_MISSING_DEPENDENCY([openjdk])
369     AC_MSG_NOTICE([Could not find a valid Boot JDK. $HELP_MSG])
370     AC_MSG_NOTICE([This might be fixed by explicitly setting --with-boot-jdk])
371     AC_MSG_ERROR([Cannot continue])
372   fi
373 
374   AC_SUBST(BOOT_JDK)
375 
376   # Setup tools from the Boot JDK.
377   BOOTJDK_CHECK_TOOL_IN_BOOTJDK(JAVA, java)
378   BOOTJDK_CHECK_TOOL_IN_BOOTJDK(JAVAC, javac)
379   BOOTJDK_CHECK_TOOL_IN_BOOTJDK(JAVADOC, javadoc)
380   BOOTJDK_CHECK_TOOL_IN_BOOTJDK(JAR, jar)
381 
382   # Finally, set some other options...
383 
384   # Determine if the boot jdk jar supports the --date option
385   if $JAR --help 2>&1 | $GREP -q -e "--date=TIMESTAMP"; then
386     BOOT_JDK_JAR_SUPPORTS_DATE=true
387   else
388     BOOT_JDK_JAR_SUPPORTS_DATE=false
389   fi
390   AC_MSG_CHECKING([if Boot JDK jar supports --date=TIMESTAMP])
391   AC_MSG_RESULT([$BOOT_JDK_JAR_SUPPORTS_DATE])
392   AC_SUBST(BOOT_JDK_JAR_SUPPORTS_DATE)
393 
394   # When compiling code to be executed by the Boot JDK, force compatibility with the
395   # oldest supported bootjdk.
396   OLDEST_BOOT_JDK=`$ECHO $DEFAULT_ACCEPTABLE_BOOT_VERSIONS \
397       | $TR " " "\n" | $SORT -n | $HEAD -n1`
398   # -Xlint:-options is added to avoid "warning: [options] system modules path not set in conjunction with -source"
399   BOOT_JDK_SOURCETARGET="-source $OLDEST_BOOT_JDK -target $OLDEST_BOOT_JDK -Xlint:-options"
400   AC_SUBST(BOOT_JDK_SOURCETARGET)
401 
402   # Check if the boot jdk is 32 or 64 bit
403   if $JAVA -version 2>&1 | $GREP -q "64-Bit"; then
404     BOOT_JDK_BITS="64"
405   else
406     BOOT_JDK_BITS="32"
407   fi
408   AC_MSG_CHECKING([if Boot JDK is 32 or 64 bits])
409   AC_MSG_RESULT([$BOOT_JDK_BITS])
410 
411   # Try to enable CDS
412   AC_MSG_CHECKING([for local Boot JDK Class Data Sharing (CDS)])
413   BOOT_JDK_CDS_ARCHIVE=$CONFIGURESUPPORT_OUTPUTDIR/classes.jsa
414   UTIL_ADD_JVM_ARG_IF_OK([-XX:+UnlockDiagnosticVMOptions -XX:-VerifySharedSpaces -XX:SharedArchiveFile=$BOOT_JDK_CDS_ARCHIVE],boot_jdk_cds_args,[$JAVA])
415 
416   if test "x$boot_jdk_cds_args" != x; then
417     # Try creating a CDS archive
418     $JAVA $boot_jdk_cds_args -Xshare:dump > /dev/null 2>&1
419     if test $? -eq 0; then
420       BOOTJDK_USE_LOCAL_CDS=true
421       AC_MSG_RESULT([yes, created])
422     else
423       # Generation failed, don't use CDS.
424       BOOTJDK_USE_LOCAL_CDS=false
425       AC_MSG_RESULT([no, creation failed])
426     fi
427   else
428     BOOTJDK_USE_LOCAL_CDS=false
429     AC_MSG_RESULT([no, -XX:SharedArchiveFile not supported])
430   fi
431 
432   BOOTJDK_SETUP_CLASSPATH
433 ])
434 
435 AC_DEFUN_ONCE([BOOTJDK_SETUP_BOOT_JDK_ARGUMENTS],
436 [
437   ##############################################################################
438   #
439   # Specify jvm options for anything that is run with the Boot JDK.
440   # Not all JVM:s accept the same arguments on the command line.
441   #
442   AC_MSG_CHECKING([flags for boot jdk java command] )
443 
444   # Force en-US environment
445   UTIL_ADD_JVM_ARG_IF_OK([-Duser.language=en -Duser.country=US],boot_jdk_jvmargs,[$JAVA])
446 
447   if test "x$BOOTJDK_USE_LOCAL_CDS" = xtrue; then
448     # Use our own CDS archive
449     UTIL_ADD_JVM_ARG_IF_OK([$boot_jdk_cds_args -Xshare:auto],boot_jdk_jvmargs,[$JAVA])
450   else
451     # Otherwise optimistically use the system-wide one, if one is present
452     UTIL_ADD_JVM_ARG_IF_OK([-Xshare:auto],boot_jdk_jvmargs,[$JAVA])
453   fi
454 
455   # Finally append user provided options to allow them to override.
456   UTIL_ADD_JVM_ARG_IF_OK([$USER_BOOT_JDK_OPTIONS],boot_jdk_jvmargs,[$JAVA])
457 
458   AC_MSG_RESULT([$boot_jdk_jvmargs])
459 
460   # For now, general JAVA_FLAGS are the same as the boot jdk jvmargs
461   JAVA_FLAGS=$boot_jdk_jvmargs
462   AC_SUBST(JAVA_FLAGS)
463 
464   AC_MSG_CHECKING([flags for boot jdk java command for big workloads])
465 
466   # Starting amount of heap memory.
467   UTIL_ADD_JVM_ARG_IF_OK([-Xms64M],boot_jdk_jvmargs_big,[$JAVA])
468   BOOTCYCLE_JVM_ARGS_BIG=-Xms64M
469 
470   # Maximum amount of heap memory.
471   JVM_HEAP_LIMIT_32="768"
472   # Running a 64 bit JVM allows for and requires a bigger heap
473   JVM_HEAP_LIMIT_64="1600"
474   JVM_HEAP_LIMIT_GLOBAL=`expr $MEMORY_SIZE / 2`
475   if test "$JVM_HEAP_LIMIT_GLOBAL" -lt "$JVM_HEAP_LIMIT_32"; then
476     JVM_HEAP_LIMIT_32=$JVM_HEAP_LIMIT_GLOBAL
477   fi
478   if test "$JVM_HEAP_LIMIT_GLOBAL" -lt "$JVM_HEAP_LIMIT_64"; then
479     JVM_HEAP_LIMIT_64=$JVM_HEAP_LIMIT_GLOBAL
480   fi
481   if test "$JVM_HEAP_LIMIT_GLOBAL" -lt "512"; then
482     JVM_HEAP_LIMIT_32=512
483     JVM_HEAP_LIMIT_64=512
484   fi
485 
486   if test "x$BOOT_JDK_BITS" = "x32"; then
487     JVM_MAX_HEAP=$JVM_HEAP_LIMIT_32
488   else
489     JVM_MAX_HEAP=$JVM_HEAP_LIMIT_64
490   fi
491   UTIL_ADD_JVM_ARG_IF_OK([-Xmx${JVM_MAX_HEAP}M],boot_jdk_jvmargs_big,[$JAVA])
492 
493   AC_MSG_RESULT([$boot_jdk_jvmargs_big])
494 
495   JAVA_FLAGS_BIG=$boot_jdk_jvmargs_big
496   AC_SUBST(JAVA_FLAGS_BIG)
497 
498   if test "x$OPENJDK_TARGET_CPU_BITS" = "x32"; then
499     BOOTCYCLE_MAX_HEAP=$JVM_HEAP_LIMIT_32
500   else
501     BOOTCYCLE_MAX_HEAP=$JVM_HEAP_LIMIT_64
502   fi
503   BOOTCYCLE_JVM_ARGS_BIG="$BOOTCYCLE_JVM_ARGS_BIG -Xmx${BOOTCYCLE_MAX_HEAP}M"
504   AC_MSG_CHECKING([flags for bootcycle boot jdk java command for big workloads])
505   AC_MSG_RESULT([$BOOTCYCLE_JVM_ARGS_BIG])
506   AC_SUBST(BOOTCYCLE_JVM_ARGS_BIG)
507 
508   AC_MSG_CHECKING([flags for boot jdk java command for small workloads])
509 
510   # Use serial gc for small short lived tools if possible
511   UTIL_ADD_JVM_ARG_IF_OK([-XX:+UseSerialGC],boot_jdk_jvmargs_small,[$JAVA])
512   UTIL_ADD_JVM_ARG_IF_OK([-Xms32M],boot_jdk_jvmargs_small,[$JAVA])
513   UTIL_ADD_JVM_ARG_IF_OK([-Xmx512M],boot_jdk_jvmargs_small,[$JAVA])
514   UTIL_ADD_JVM_ARG_IF_OK([-XX:TieredStopAtLevel=1],boot_jdk_jvmargs_small,[$JAVA])
515 
516   AC_MSG_RESULT([$boot_jdk_jvmargs_small])
517 
518   JAVA_FLAGS_SMALL=$boot_jdk_jvmargs_small
519   AC_SUBST(JAVA_FLAGS_SMALL)
520 
521   # Don't presuppose SerialGC is present in the buildjdk. Also, we cannot test
522   # the buildjdk, but on the other hand we know what it will support.
523   BUILD_JAVA_FLAGS_SMALL="-Xms32M -Xmx512M -XX:TieredStopAtLevel=1"
524   AC_SUBST(BUILD_JAVA_FLAGS_SMALL)
525 
526   JAVA_TOOL_FLAGS_SMALL=""
527   for f in $JAVA_FLAGS_SMALL; do
528     JAVA_TOOL_FLAGS_SMALL="$JAVA_TOOL_FLAGS_SMALL -J$f"
529   done
530   AC_SUBST(JAVA_TOOL_FLAGS_SMALL)
531 ])
532 
533 # BUILD_JDK: the location of the latest JDK that can run
534 #   on the host system and supports the target class file version
535 #   generated in this JDK build.  This variable should only be
536 #   used after the launchers are built.
537 #
538 
539 # Execute the check given as argument, and verify the result.
540 # If the JDK was previously found, do nothing.
541 # $1 A command line (typically autoconf macro) to execute
542 AC_DEFUN([BOOTJDK_CHECK_BUILD_JDK],
543 [
544   if test "x$BUILD_JDK_FOUND" = xno; then
545     # Execute the test
546     $1
547 
548     # If previous step claimed to have found a JDK, check it to see if it seems to be valid.
549     if test "x$BUILD_JDK_FOUND" = xmaybe; then
550       # Do we have a bin/java?
551       if test ! -x "$BUILD_JDK/bin/java"; then
552         AC_MSG_NOTICE([Potential Build JDK found at $BUILD_JDK did not contain bin/java; ignoring])
553         BUILD_JDK_FOUND=no
554       elif test ! -x "$BUILD_JDK/bin/jlink"; then
555         AC_MSG_NOTICE([Potential Build JDK found at $BUILD_JDK did not contain bin/jlink; ignoring])
556         BUILD_JDK_FOUND=no
557       elif test ! -x "$BUILD_JDK/bin/jmod"; then
558         AC_MSG_NOTICE([Potential Build JDK found at $BUILD_JDK did not contain bin/jmod; ignoring])
559         BUILD_JDK_FOUND=no
560       elif test ! -x "$BUILD_JDK/bin/javac"; then
561         # Do we have a bin/javac?
562         AC_MSG_NOTICE([Potential Build JDK found at $BUILD_JDK did not contain bin/javac; ignoring])
563         AC_MSG_NOTICE([(This might be a JRE instead of an JDK)])
564         BUILD_JDK_FOUND=no
565       else
566         # Oh, this is looking good! We probably have found a proper JDK. Is it the correct version?
567         # Additional [] needed to keep m4 from mangling shell constructs.
568         [ BUILD_JDK_VERSION=`"$BUILD_JDK/bin/java" -version 2>&1 | $AWK '/version "[0-9a-zA-Z\._\-]+"/ {print $ 0; exit;}'` ]
569 
570         # Extra M4 quote needed to protect [] in grep expression.
571         [FOUND_CORRECT_VERSION=`echo $BUILD_JDK_VERSION | $EGREP "\"$VERSION_FEATURE([\.+-].*)?\""`]
572         if test "x$FOUND_CORRECT_VERSION" = x; then
573           AC_MSG_NOTICE([Potential Build JDK found at $BUILD_JDK is incorrect JDK version ($BUILD_JDK_VERSION); ignoring])
574           AC_MSG_NOTICE([(Your Build JDK must be version $VERSION_FEATURE)])
575           BUILD_JDK_FOUND=no
576         else
577           # We're done!
578           BUILD_JDK_FOUND=yes
579           UTIL_FIXUP_PATH(BUILD_JDK)
580           AC_MSG_CHECKING([for Build JDK])
581           AC_MSG_RESULT([$BUILD_JDK])
582           AC_MSG_CHECKING([Build JDK version])
583           BUILD_JDK_VERSION=`"$BUILD_JDK/bin/java" -version 2>&1 | $TR '\n\r' '  '`
584           AC_MSG_RESULT([$BUILD_JDK_VERSION])
585         fi # end check jdk version
586       fi # end check java
587     fi # end check build jdk found
588   fi
589 ])
590 
591 # By default the BUILD_JDK is the JDK_OUTPUTDIR.  If the target architecture
592 # is different than the host system doing the build (e.g. cross-compilation),
593 # a special BUILD_JDK is built as part of the build process.  An external
594 # prebuilt BUILD_JDK can also be supplied.
595 AC_DEFUN([BOOTJDK_SETUP_BUILD_JDK],
596 [
597   AC_ARG_WITH(build-jdk, [AS_HELP_STRING([--with-build-jdk],
598       [path to JDK of same version as is being built@<:@the newly built JDK@:>@])])
599 
600   CREATE_BUILDJDK=false
601   EXTERNAL_BUILDJDK=false
602   BUILD_JDK_FOUND="no"
603   if test "x$with_build_jdk" != "x"; then
604     BOOTJDK_CHECK_BUILD_JDK([
605       if test "x$with_build_jdk" != x; then
606         BUILD_JDK=$with_build_jdk
607         BUILD_JDK_FOUND=maybe
608         AC_MSG_NOTICE([Found potential Build JDK using configure arguments])
609       fi
610     ])
611     EXTERNAL_BUILDJDK=true
612   else
613     if test "x$COMPILE_TYPE" = "xcross"; then
614       BUILD_JDK="\$(BUILDJDK_OUTPUTDIR)/jdk"
615       BUILD_JDK_FOUND=yes
616       CREATE_BUILDJDK=true
617       AC_MSG_CHECKING([for Build JDK])
618       AC_MSG_RESULT([yes, will build it for the host platform])
619     else
620       BUILD_JDK="\$(JDK_OUTPUTDIR)"
621       BUILD_JDK_FOUND=yes
622       AC_MSG_CHECKING([for Build JDK])
623       AC_MSG_RESULT([yes, will use output dir])
624     fi
625   fi
626 
627   # Since these tools do not yet exist, we cannot use UTIL_FIXUP_EXECUTABLE to
628   # detect the need of fixpath
629   JMOD="$BUILD_JDK/bin/jmod"
630   UTIL_ADD_FIXPATH(JMOD)
631   JLINK="$BUILD_JDK/bin/jlink"
632   UTIL_ADD_FIXPATH(JLINK)
633   AC_SUBST(JMOD)
634   AC_SUBST(JLINK)
635 
636   if test "x$BUILD_JDK_FOUND" != "xyes"; then
637     AC_MSG_CHECKING([for Build JDK])
638     AC_MSG_RESULT([no])
639     AC_MSG_ERROR([Could not find a suitable Build JDK])
640   fi
641 
642   AC_SUBST(CREATE_BUILDJDK)
643   AC_SUBST(BUILD_JDK)
644   AC_SUBST(EXTERNAL_BUILDJDK)
645 ])
646 
647 # The docs-reference JDK is used to run javadoc for the docs-reference targets.
648 # If not set, the reference docs will be built using the interim javadoc.
649 AC_DEFUN([BOOTJDK_SETUP_DOCS_REFERENCE_JDK],
650 [
651   AC_ARG_WITH(docs-reference-jdk, [AS_HELP_STRING([--with-docs-reference-jdk],
652       [path to JDK to use for building the reference documentation])])
653 
654   AC_MSG_CHECKING([for docs-reference JDK])
655   if test "x$with_docs_reference_jdk" != "x"; then
656     DOCS_REFERENCE_JDK="$with_docs_reference_jdk"
657     AC_MSG_RESULT([$DOCS_REFERENCE_JDK])
658     DOCS_REFERENCE_JAVADOC="$DOCS_REFERENCE_JDK/bin/javadoc"
659     if test ! -x "$DOCS_REFERENCE_JAVADOC"; then
660       AC_MSG_ERROR([docs-reference JDK found at $DOCS_REFERENCE_JDK did not contain bin/javadoc])
661     fi
662     UTIL_FIXUP_EXECUTABLE(DOCS_REFERENCE_JAVADOC)
663   else
664     AC_MSG_RESULT([no, using interim javadoc for the docs-reference targets])
665     # By leaving this empty, Docs.gmk will revert to the default interim javadoc
666     DOCS_REFERENCE_JAVADOC=
667   fi
668 
669   AC_SUBST(DOCS_REFERENCE_JAVADOC)
670 ])