| 1 |
dnl --------------------------------------------------------------------------- |
| 2 |
dnl Copyright (C) 2009-2011 FuseSource Corp. |
| 3 |
dnl http://fusesource.com |
| 4 |
dnl |
| 5 |
dnl Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 |
dnl you may not use this file except in compliance with the License. |
| 7 |
dnl You may obtain a copy of the License at |
| 8 |
dnl |
| 9 |
dnl http://www.apache.org/licenses/LICENSE-2.0 |
| 10 |
dnl |
| 11 |
dnl Unless required by applicable law or agreed to in writing, software |
| 12 |
dnl distributed under the License is distributed on an "AS IS" BASIS, |
| 13 |
dnl WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 |
dnl See the License for the specific language governing permissions and |
| 15 |
dnl limitations under the License. |
| 16 |
dnl --------------------------------------------------------------------------- |
| 17 |
dnl --------------------------------------------------------------------------- |
| 18 |
dnl SYNOPSIS: |
| 19 |
dnl |
| 20 |
dnl WITH_JNI_JDK() |
| 21 |
dnl |
| 22 |
dnl Adds the --with-jni-jdk=PATH option. If not provided, it searches |
| 23 |
dnl for the JDK in the default OS locations. |
| 24 |
dnl |
| 25 |
dnl This macro calls: |
| 26 |
dnl AC_SUBST(JNI_JDK) |
| 27 |
dnl AC_SUBST(JNI_EXTRA_CFLAGS) |
| 28 |
dnl AC_SUBST(JNI_EXTRA_LDFLAGS) |
| 29 |
dnl |
| 30 |
dnl AUTHOR: <a href="http://hiramchirino.com">Hiram Chrino</a> |
| 31 |
dnl --------------------------------------------------------------------------- |
| 32 |
|
| 33 |
AC_DEFUN([WITH_JNI_JDK], |
| 34 |
[ |
| 35 |
AC_PREREQ([2.61]) |
| 36 |
AC_ARG_WITH(jni-jdk, |
| 37 |
[AS_HELP_STRING([--with-jni-jdk=PATH], |
| 38 |
[Location of the Java Development Kit. Defaults to your JAVA_HOME setting and falls back to where it is typically installed on your OS])], |
| 39 |
[ |
| 40 |
if test "$withval" = "no" || test "$withval" = "yes"; then |
| 41 |
AC_MSG_ERROR([--with-jni-jdk: PATH to JDK not supplied]) |
| 42 |
fi |
| 43 |
CHECK_JNI_JDK([$withval], [], [AC_MSG_ERROR([JDK not found. Invalid --with-jni-jdk PATH])]) |
| 44 |
],[ |
| 45 |
|
| 46 |
if test -n "$JAVA_HOME" ; then |
| 47 |
AC_MSG_NOTICE([JAVA_HOME was set, checking to see if it's a JDK we can use...]) |
| 48 |
CHECK_JNI_JDK([$JAVA_HOME], [], []) |
| 49 |
fi |
| 50 |
|
| 51 |
__JNI_GUESS=`which javac` |
| 52 |
AS_IF(test -z "$JNI_JDK" && test -n "$__JNI_GUESS", [ |
| 53 |
AC_MSG_NOTICE([javac was on your path, checking to see if it's part of a JDK we can use...]) |
| 54 |
# transitively resolve the symbolic links to javac |
| 55 |
while file -h "$__JNI_GUESS" 2>/dev/null | grep " symbolic link to " >/dev/null; do |
| 56 |
__JNI_LINK=$( file -h $__JNI_GUESS | sed 's/.*symbolic link to //' | sed "s/'$//" | sed 's/^`//' ) |
| 57 |
__JNI_GUESS=$(cd $(dirname $__JNI_GUESS); cd $(dirname $__JNI_LINK); echo "$(pwd)/$(basename $__JNI_LINK)") |
| 58 |
done |
| 59 |
# move 2 dirs up to the home dir... |
| 60 |
__JNI_GUESS=$(dirname $(dirname $__JNI_GUESS)) |
| 61 |
CHECK_JNI_JDK([$__JNI_GUESS], [], [],[]) |
| 62 |
],[]) |
| 63 |
|
| 64 |
AS_IF(test -z "$JNI_JDK", [ |
| 65 |
case "$host_os" in |
| 66 |
darwin*) __JNI_GUESS="/System/Library/Frameworks/JavaVM.framework";; |
| 67 |
freebsd*) __JNI_GUESS=$(env JAVAVM_DRYRUN=yes /usr/local/bin/java | grep '^JAVA_HOME' | cut -c11-);; |
| 68 |
*) __JNI_GUESS="/usr";; |
| 69 |
esac |
| 70 |
AC_MSG_NOTICE([Taking a guess as to where your OS installs the JDK by default...]) |
| 71 |
CHECK_JNI_JDK([$__JNI_GUESS], [], [AC_MSG_ERROR([JDK not found. Please use the --with-jni-jdk option])]) |
| 72 |
],[]) |
| 73 |
]) |
| 74 |
]) |
| 75 |
|
| 76 |
dnl --------------------------------------------------------------------------- |
| 77 |
dnl |
| 78 |
dnl JNI_CHECK_JDK_HOME(PATH, [ACTION-SUCCESS], [ACTION-FAILURE]) |
| 79 |
dnl |
| 80 |
dnl Tests to see if the given path is a valid JDK home location with |
| 81 |
dnl with a JNI headers and library that can be compiled against. |
| 82 |
dnl |
| 83 |
dnl This macro calls: |
| 84 |
dnl |
| 85 |
dnl AC_SUBST(JNI_JDK) |
| 86 |
dnl AC_SUBST(JNI_EXTRA_CFLAGS) |
| 87 |
dnl AC_SUBST(JNI_EXTRA_LDFLAGS) |
| 88 |
dnl |
| 89 |
dnl AUTHOR: <a href="http://hiramchirino.com">Hiram Chrino</a> |
| 90 |
dnl --------------------------------------------------------------------------- |
| 91 |
AC_DEFUN([CHECK_JNI_JDK],[ |
| 92 |
AC_PREREQ([2.61]) |
| 93 |
__JNI_JDK_HOME="$1" |
| 94 |
AC_MSG_CHECKING(if '$__JNI_JDK_HOME' is a JDK) |
| 95 |
|
| 96 |
__JNI_INCLUDE="$__JNI_JDK_HOME/include" |
| 97 |
# OSX had to be a little different. |
| 98 |
case "$host_os" in |
| 99 |
darwin*) |
| 100 |
AS_IF(test -r "$__JNI_JDK_HOME/Headers/jni.h",[ |
| 101 |
__JNI_INCLUDE="$__JNI_JDK_HOME/Headers"; |
| 102 |
]) |
| 103 |
esac |
| 104 |
|
| 105 |
|
| 106 |
AS_IF(test -r "$__JNI_INCLUDE/jni.h",[ |
| 107 |
# Also include the os specific include dirs in the JNI_CFLAGS |
| 108 |
__JNI_CFLAGS="-I$__JNI_INCLUDE" |
| 109 |
case "$host_os" in |
| 110 |
darwin*) __JNI_INCLUDE_EXTRAS="darwin";; |
| 111 |
freebsd*) __JNI_INCLUDE_EXTRAS="freebsd";; |
| 112 |
linux*) __JNI_INCLUDE_EXTRAS="linux genunix";; |
| 113 |
openbsd*) __JNI_INCLUDE_EXTRAS="openbsd";; |
| 114 |
osf*) __JNI_INCLUDE_EXTRAS="alpha";; |
| 115 |
solaris*) __JNI_INCLUDE_EXTRAS="solaris";; |
| 116 |
mingw*) __JNI_INCLUDE_EXTRAS="win32";; |
| 117 |
cygwin*) __JNI_INCLUDE_EXTRAS="win32";; |
| 118 |
*) __JNI_INCLUDE_EXTRAS="genunix";; |
| 119 |
esac |
| 120 |
|
| 121 |
for f in $__JNI_INCLUDE_EXTRAS ; do |
| 122 |
if test -d "$__JNI_INCLUDE/$f"; then |
| 123 |
__JNI_CFLAGS="$__JNI_CFLAGS -I$__JNI_INCLUDE/$f" |
| 124 |
fi |
| 125 |
done |
| 126 |
|
| 127 |
saved_CPPFLAGS="$CPPFLAGS" |
| 128 |
CPPFLAGS="$CPPFLAGS $__JNI_CFLAGS" |
| 129 |
JNI_VERSION="1_2" |
| 130 |
AC_LANG_PUSH(C) |
| 131 |
AC_COMPILE_IFELSE( |
| 132 |
[AC_LANG_PROGRAM([[@%:@include <jni.h>]],[[ |
| 133 |
#ifndef JNI_VERSION_$JNI_VERSION |
| 134 |
# error JNI version $JNI_VERSION is not supported. |
| 135 |
#endif |
| 136 |
]]) |
| 137 |
],[ |
| 138 |
|
| 139 |
JNI_JDK=$"$__JNI_JDK_HOME" |
| 140 |
JNI_EXTRA_CFLAGS="$__JNI_CFLAGS" |
| 141 |
AC_SUBST(JNI_JDK) |
| 142 |
AC_SUBST(JNI_EXTRA_CFLAGS) |
| 143 |
case $host_os in |
| 144 |
darwin*) |
| 145 |
JNI_EXTRA_LDFLAGS="-shrext .jnilib -dynamiclib" ;; |
| 146 |
esac |
| 147 |
AC_SUBST(JNI_EXTRA_LDFLAGS) |
| 148 |
|
| 149 |
|
| 150 |
AC_MSG_RESULT([yes]) |
| 151 |
$2 |
| 152 |
],[ |
| 153 |
AC_MSG_RESULT([no]) |
| 154 |
$3 |
| 155 |
]) |
| 156 |
AC_LANG_POP() |
| 157 |
CPPFLAGS="$saved_CPPFLAGS" |
| 158 |
],[ |
| 159 |
AC_MSG_RESULT([no]) |
| 160 |
$3 |
| 161 |
]) |
| 162 |
]) |
| 163 |
|