boot-jdk.m4 revision 457:3156dff953b1
150533Smpp#
250533Smpp# Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved.
33229Spst# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
471112Sru#
571112Sru# This code is free software; you can redistribute it and/or modify it
671112Sru# under the terms of the GNU General Public License version 2 only, as
771112Sru# published by the Free Software Foundation.  Oracle designates this
871112Sru# particular file as subject to the "Classpath" exception as provided
971112Sru# by Oracle in the LICENSE file that accompanied this code.
1071112Sru#
1171112Sru# This code is distributed in the hope that it will be useful, but WITHOUT
1271112Sru# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1371112Sru# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
1471112Sru# version 2 for more details (a copy is included in the LICENSE file that
1571112Sru# accompanied this code).
1671112Sru#
1771112Sru# You should have received a copy of the GNU General Public License version
1899500Scharnier# 2 along with this work; if not, write to the Free Software Foundation,
1971112Sru# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
2099500Scharnier#
2171112Sru# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
223229Spst# or visit www.oracle.com if you need additional information or have any
233229Spst# questions.
243229Spst#
2571112Sru
263229Spst# Fixes paths on windows to be mixed mode short.
2771112SruAC_DEFUN([BOOTJDK_WIN_FIX_PATH],
2871112Sru[
2971112Sru    if test "x$OPENJDK_BUILD_OS" = "xwindows"; then
303229Spst        AC_PATH_PROG(CYGPATH, cygpath)
3171112Sru        tmp="[$]$1"
3271112Sru        # Convert to C:/ mixed style path without spaces.
333229Spst        tmp=`$CYGPATH -s -m "$tmp"`
343229Spst        $1="$tmp"
353229Spst    fi
3671112Sru])
373229Spst
3871112SruAC_DEFUN([BOOTJDK_MISSING_ERROR],
3971112Sru[
4071112Sru    AC_MSG_NOTICE([This might be fixed by explicitely setting --with-boot-jdk])
413229Spst    AC_MSG_ERROR([Cannot continue])
4271112Sru])
433229Spst
4471112Sru###############################################################################
453229Spst#
4671112Sru# We need a Boot JDK to bootstrap the build. 
473229Spst#
48140414Sru
49140414SruAC_DEFUN_ONCE([BOOTJDK_SETUP_BOOT_JDK],
50140414Sru[
51140414SruBOOT_JDK_FOUND=no
52140414SruAC_ARG_WITH(boot-jdk, [AS_HELP_STRING([--with-boot-jdk],
53140414Sru    [path to Boot JDK (used to bootstrap build) @<:@probed@:>@])])
54140414Sru                    
55140414Sruif test "x$with_boot_jdk" != x; then
56140414Sru    BOOT_JDK=$with_boot_jdk
57140414Sru    BOOT_JDK_FOUND=yes
5871112Srufi
5971112Sruif test "x$BOOT_JDK_FOUND" = xno; then
6071112Sru    BDEPS_CHECK_MODULE(BOOT_JDK, boot-jdk, xxx, [BOOT_JDK_FOUND=yes], [BOOT_JDK_FOUND=no])
6199500Scharnierfi
6271112Sru
6371112Sruif test "x$BOOT_JDK_FOUND" = xno; then
6471112Sru    if test "x$JAVA_HOME" != x; then
6571112Sru        if test ! -d "$JAVA_HOME"; then
6671112Sru            AC_MSG_NOTICE([Your JAVA_HOME points to a non-existing directory!])
6771112Sru            BOOTJDK_MISSING_ERROR
6871112Sru        fi
6971112Sru        # Aha, the user has set a JAVA_HOME
7071112Sru        # let us use that as the Boot JDK.
7171112Sru        BOOT_JDK="$JAVA_HOME"
7271112Sru        BOOT_JDK_FOUND=yes
7371112Sru        # To be on the safe side, lets check that it is a JDK.
743229Spst        if test -x "$BOOT_JDK/bin/javac" && test -x "$BOOT_JDK/bin/java"; then
753229Spst            JAVAC="$BOOT_JDK/bin/javac"
7671112Sru            JAVA="$BOOT_JDK/bin/java"
7771112Sru            BOOT_JDK_FOUND=yes
78        else
79            AC_MSG_NOTICE([Your JAVA_HOME points to a JRE! The build needs a JDK! Please point JAVA_HOME to a JDK. JAVA_HOME=[$]JAVA_HOME])
80            BOOTJDK_MISSING_ERROR
81        fi            
82    fi
83fi
84
85if test "x$BOOT_JDK_FOUND" = xno; then
86    AC_PATH_PROG(JAVAC_CHECK, javac)
87    AC_PATH_PROG(JAVA_CHECK, java)
88    BINARY="$JAVAC_CHECK"
89    if test "x$JAVAC_CHECK" = x; then
90        BINARY="$JAVA_CHECK"
91    fi
92    if test "x$BINARY" != x; then
93        # So there is a java(c) binary, it might be part of a JDK.
94        # Lets find the JDK/JRE directory by following symbolic links.
95        # Linux/GNU systems often have links from /usr/bin/java to 
96        # /etc/alternatives/java to the real JDK binary.
97	WHICHCMD_SPACESAFE(BINARY,[path to javac])
98        REMOVE_SYMBOLIC_LINKS(BINARY)
99        BOOT_JDK=`dirname $BINARY`
100        BOOT_JDK=`cd $BOOT_JDK/..; pwd`
101        if test -x $BOOT_JDK/bin/javac && test -x $BOOT_JDK/bin/java; then
102            JAVAC=$BOOT_JDK/bin/javac
103            JAVA=$BOOT_JDK/bin/java
104            BOOT_JDK_FOUND=yes
105        fi
106    fi
107fi
108
109if test "x$BOOT_JDK_FOUND" = xno; then
110    # Try the MacOSX way.
111    if test -x /usr/libexec/java_home; then
112        BOOT_JDK=`/usr/libexec/java_home`
113        if test -x $BOOT_JDK/bin/javac && test -x $BOOT_JDK/bin/java; then
114            JAVAC=$BOOT_JDK/bin/javac
115            JAVA=$BOOT_JDK/bin/java
116            BOOT_JDK_FOUND=yes
117        fi
118    fi
119fi
120
121if test "x$BOOT_JDK_FOUND" = xno; then
122    AC_PATH_PROG(JAVA_CHECK, java)
123    if test "x$JAVA_CHECK" != x; then
124        # There is a java in the path. But apparently we have not found a javac 
125        # in the path, since that would have been tested earlier.
126        if test "x$OPENJDK_TARGET_OS" = xwindows; then
127            # Now if this is a windows platform. The default installation of a JDK
128            # actually puts the JRE in the path and keeps the JDK out of the path!
129            # Go look in the default installation location.
130            BOOT_JDK=/cygdrive/c/Program\ Files/Java/`ls /cygdrive/c/Program\ Files/Java | grep jdk | sort -r | head --lines 1`
131            if test -d "$BOOT_JDK"; then
132                BOOT_JDK_FOUND=yes
133            fi
134        fi
135        if test "x$BOOT_JDK_FOUND" = xno; then
136            HELP_MSG_MISSING_DEPENDENCY([openjdk])
137            AC_MSG_NOTICE([Found a JRE, not not a JDK! Please remove the JRE from your path and put a JDK there instead. $HELP_MSG])
138            BOOTJDK_MISSING_ERROR
139        fi
140    else
141        HELP_MSG_MISSING_DEPENDENCY([openjdk])
142        AC_MSG_NOTICE([Could not find a JDK. $HELP_MSG])
143        BOOTJDK_MISSING_ERROR
144    fi
145fi
146
147BOOTJDK_WIN_FIX_PATH(BOOT_JDK)
148
149# Now see if we can find the rt.jar, or its nearest equivalent.
150BOOT_RTJAR="$BOOT_JDK/jre/lib/rt.jar"
151SPACESAFE(BOOT_RTJAR,[the path to the Boot JDK rt.jar (or nearest equivalent)])
152
153BOOT_TOOLSJAR="$BOOT_JDK/lib/tools.jar"
154SPACESAFE(BOOT_TOOLSJAR,[the path to the Boot JDK tools.jar (or nearest equivalent)])
155
156if test ! -f $BOOT_RTJAR; then
157    # On MacOSX it is called classes.jar
158    BOOT_RTJAR=$BOOT_JDK/../Classes/classes.jar
159    if test ! -f $BOOT_RTJAR; then
160        AC_MSG_NOTICE([Cannot find the rt.jar or its equivalent!])
161        AC_MSG_NOTICE([This typically means that configure failed to automatically find a suitable Boot JDK])
162        BOOTJDK_MISSING_ERROR
163    fi
164    # Remove the .. 
165    BOOT_RTJAR="`cd ${BOOT_RTJAR%/*} && pwd`/${BOOT_RTJAR##*/}"
166    # The tools.jar is part of classes.jar
167    BOOT_TOOLSJAR="$BOOT_RTJAR"
168fi
169
170AC_SUBST(BOOT_JDK)
171AC_SUBST(BOOT_RTJAR)
172AC_SUBST(BOOT_TOOLSJAR)
173AC_MSG_CHECKING([for Boot JDK])
174AC_MSG_RESULT([$BOOT_JDK])
175AC_MSG_CHECKING([for Boot rt.jar])
176AC_MSG_RESULT([$BOOT_RTJAR])
177AC_MSG_CHECKING([for Boot tools.jar])
178AC_MSG_RESULT([$BOOT_TOOLSJAR])
179
180# Use the java tool from the Boot JDK.
181AC_MSG_CHECKING([for java in Boot JDK])
182JAVA=$BOOT_JDK/bin/java
183if test ! -x $JAVA; then
184    AC_MSG_NOTICE([Could not find a working java])
185    BOOTJDK_MISSING_ERROR
186fi
187BOOT_JDK_VERSION=`$JAVA -version 2>&1 | head -n 1`
188AC_MSG_RESULT([yes $BOOT_JDK_VERSION])
189AC_SUBST(JAVA)
190
191# Extra M4 quote needed to protect [] in grep expression.
192[FOUND_VERSION_78=`echo $BOOT_JDK_VERSION | grep  '\"1\.[78]\.'`]
193if test "x$FOUND_VERSION_78" = x; then
194    HELP_MSG_MISSING_DEPENDENCY([openjdk])
195    AC_MSG_NOTICE([Your boot-jdk must be version 7 or 8. $HELP_MSG])
196    BOOTJDK_MISSING_ERROR
197fi
198
199# When compiling code to be executed by the Boot JDK, force jdk7 compatibility.
200BOOT_JDK_SOURCETARGET="-source 7 -target 7"
201AC_SUBST(BOOT_JDK_SOURCETARGET)
202
203# Use the javac tool from the Boot JDK.
204AC_MSG_CHECKING([for javac in Boot JDK])
205JAVAC=$BOOT_JDK/bin/javac
206if test ! -x $JAVAC; then
207    AC_MSG_ERROR([Could not find a working javac])
208fi
209AC_MSG_RESULT(yes)
210AC_SUBST(JAVAC)
211AC_SUBST(JAVAC_FLAGS)
212
213# Use the javah tool from the Boot JDK.
214AC_MSG_CHECKING([for javah in Boot JDK])
215JAVAH=$BOOT_JDK/bin/javah
216if test ! -x $JAVAH; then
217    AC_MSG_NOTICE([Could not find a working javah])
218    BOOTJDK_MISSING_ERROR
219fi
220AC_MSG_RESULT(yes)
221AC_SUBST(JAVAH)
222
223# Use the jar tool from the Boot JDK.
224AC_MSG_CHECKING([for jar in Boot JDK])
225JAR=$BOOT_JDK/bin/jar
226if test ! -x $JAR; then
227    AC_MSG_NOTICE([Could not find a working jar])
228    BOOTJDK_MISSING_ERROR
229fi
230AC_SUBST(JAR)
231AC_MSG_RESULT(yes)
232
233# Use the rmic tool from the Boot JDK.
234AC_MSG_CHECKING([for rmic in Boot JDK])
235RMIC=$BOOT_JDK/bin/rmic
236if test ! -x $RMIC; then
237    AC_MSG_NOTICE([Could not find a working rmic])
238    BOOTJDK_MISSING_ERROR
239fi
240AC_SUBST(RMIC)
241AC_MSG_RESULT(yes)
242
243# Use the native2ascii tool from the Boot JDK.
244AC_MSG_CHECKING([for native2ascii in Boot JDK])
245NATIVE2ASCII=$BOOT_JDK/bin/native2ascii
246if test ! -x $NATIVE2ASCII; then
247    AC_MSG_NOTICE([Could not find a working native2ascii])
248    BOOTJDK_MISSING_ERROR
249fi
250AC_MSG_RESULT(yes)
251AC_SUBST(NATIVE2ASCII)
252])
253
254AC_DEFUN_ONCE([BOOTJDK_SETUP_BOOT_JDK_ARGUMENTS],
255[
256##############################################################################
257#
258# Specify options for anything that is run with the Boot JDK.
259#
260AC_ARG_WITH(boot-jdk-jvmargs, [AS_HELP_STRING([--with-boot-jdk-jvmargs],
261	[specify JVM arguments to be passed to all invocations of the Boot JDK, overriding the default values,
262     e.g --with-boot-jdk-jvmargs="-Xmx8G -enableassertions"])])
263
264if test "x$with_boot_jdk_jvmargs" = x; then
265    # Not all JVM:s accept the same arguments on the command line.
266    # OpenJDK specific increase in thread stack for JDK build,
267    # well more specifically, when running javac.
268    if test "x$BUILD_NUM_BITS" = x32; then
269       STACK_SIZE=768
270    else
271       # Running Javac on a JVM on a 64-bit machine, the stack takes more space
272       # since 64-bit pointers are pushed on the stach. Apparently, we need
273       # to increase the stack space when javacing the JDK....
274       STACK_SIZE=1536
275    fi
276
277    # Minimum amount of heap memory.
278    ADD_JVM_ARG_IF_OK([-Xms64M],boot_jdk_jvmargs,[$JAVA])
279    if test "x$OPENJDK_TARGET_OS" = "xmacosx"; then
280        # Why does macosx need more heap? Its the huge JDK batch.
281        ADD_JVM_ARG_IF_OK([-Xmx1600M],boot_jdk_jvmargs,[$JAVA])
282    else
283        ADD_JVM_ARG_IF_OK([-Xmx1100M],boot_jdk_jvmargs,[$JAVA])
284    fi
285    # When is adding -client something that speeds up the JVM?
286    # ADD_JVM_ARG_IF_OK([-client],boot_jdk_jvmargs,[$JAVA])
287    ADD_JVM_ARG_IF_OK([-XX:PermSize=32m],boot_jdk_jvmargs,[$JAVA])
288    ADD_JVM_ARG_IF_OK([-XX:MaxPermSize=160m],boot_jdk_jvmargs,[$JAVA])
289    ADD_JVM_ARG_IF_OK([-XX:ThreadStackSize=$STACK_SIZE],boot_jdk_jvmargs,[$JAVA])
290    # Disable special log output when a debug build is used as Boot JDK...
291    ADD_JVM_ARG_IF_OK([-XX:-PrintVMOptions -XX:-UnlockDiagnosticVMOptions -XX:-LogVMOutput],boot_jdk_jvmargs,[$JAVA])
292fi
293
294AC_SUBST(BOOT_JDK_JVMARGS, $boot_jdk_jvmargs)
295])
296