blob: cfe8f58928d4df6659f26693631a181f9de77e12 [file] [log] [blame]
Ed Warnickecb9cada2015-12-08 15:45:58 -07001# ===========================================================================
2# http://www.gnu.org/software/autoconf-archive/ax_check_java_home.html
3# ===========================================================================
4#
5# SYNOPSIS
6#
7# AX_CHECK_JAVA_HOME
8#
9# DESCRIPTION
10#
11# Check for Sun Java (JDK / JRE) installation, where the 'java' VM is in.
12# If found, set environment variable JAVA_HOME = Java installation home,
13# else left JAVA_HOME untouch, which in most case means JAVA_HOME is
14# empty.
15#
16# LICENSE
17#
18# Copyright (c) 2008 Gleen Salmon <gleensalmon@yahoo.com>
19#
20# This program is free software; you can redistribute it and/or modify it
21# under the terms of the GNU General Public License as published by the
22# Free Software Foundation; either version 2 of the License, or (at your
23# option) any later version.
24#
25# This program is distributed in the hope that it will be useful, but
26# WITHOUT ANY WARRANTY; without even the implied warranty of
27# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
28# Public License for more details.
29#
30# You should have received a copy of the GNU General Public License along
31# with this program. If not, see <http://www.gnu.org/licenses/>.
32#
33# As a special exception, the respective Autoconf Macro's copyright owner
34# gives unlimited permission to copy, distribute and modify the configure
35# scripts that are the output of Autoconf when processing the Macro. You
36# need not follow the terms of the GNU General Public License when using
37# or distributing such scripts, even though portions of the text of the
38# Macro appear in them. The GNU General Public License (GPL) does govern
39# all other use of the material that constitutes the Autoconf Macro.
40#
41# This special exception to the GPL applies to versions of the Autoconf
42# Macro released by the Autoconf Archive. When you make and distribute a
43# modified version of the Autoconf Macro, you may extend this special
44# exception to the GPL to apply to your modified version as well.
45
46#serial 6
47
48AU_ALIAS([AC_CHECK_JAVA_HOME], [AX_CHECK_JAVA_HOME])
49
50AC_DEFUN([AX_CHECK_JAVA_HOME],
51[AC_MSG_CHECKING([for JAVA_HOME])
52# We used a fake loop so that we can use "break" to exit when the result
53# is found.
54while true
55do
56 # If the user defined JAVA_HOME, don't touch it.
57 test "${JAVA_HOME+set}" = set && break
58
59 # On Mac OS X 10.5 and following, run /usr/libexec/java_home to get
60 # the value of JAVA_HOME to use.
61 # (http://developer.apple.com/library/mac/#qa/qa2001/qa1170.html).
62 JAVA_HOME=`/usr/libexec/java_home 2>/dev/null`
63 test x"$JAVA_HOME" != x && break
64
65 # See if we can find the java executable, and compute from there.
66 TRY_JAVA_HOME=`ls -dr /usr/java/* 2> /dev/null | head -n 1`
67 if test x$TRY_JAVA_HOME != x; then
68 PATH=$PATH:$TRY_JAVA_HOME/bin
69 fi
70 AC_PATH_PROG([JAVA_PATH_NAME], [java])
71 if test "x$JAVA_PATH_NAME" != x; then
72 JAVA_HOME=`echo $JAVA_PATH_NAME | sed "s/\(.*\)[[/]]bin[[/]]java.*/\1/"`
73 break
74 fi
75
76 AC_MSG_NOTICE([Could not compute JAVA_HOME])
77 break
78done
79AC_MSG_RESULT([$JAVA_HOME])
80])