Autoconf test for JNI includes dir

I am working on a script configuration for a JNI wrapper. One of the configuration options is the path to jni.h What is a good quick and dirty Autoconf test for whether this parameter is correct for compiling C ++? You can assume that you are working on Linux and g++ is available.

Alternatively, is there a way to get javah (or a helper tool) to give me this path directly?

+4
source share
2 answers

Checking the headers is simple; just use AC_CHECK_HEADER . If this is in a strange place (i.e. the compiler does not know), it is reasonable to expect users to install CPPFLAGS .

The hard part is actually hosting libjvm . Usually you do not want to mess with this; but you can specify the dlopen location by default if it is not set at JAVA_HOME runtime.

But I have no better solution than the requirement to set JAVA_HOME during setup. There are too many changes in the way this material is deployed on different operating systems (even for Linux distributions). This is what I do:

 AC_CHECK_HEADER([jni.h], [have_jni=yes]) AC_ARG_VAR([JAVA_HOME], [Java Runtime Environment (JRE) location]) AC_ARG_ENABLE([java-feature], [AC_HELP_STRING([--disable-java-feature], [disable Java feature])]) case $target_cpu in x86_64) JVM_ARCH=amd64 ;; i?86) JVM_ARCH=i386 ;; *) JVM_ARCH=$target_cpu ;; esac AC_SUBST([JVM_ARCH]) AS_IF([test X$enable_java_feature != Xno], [AS_IF([test X$have_jni != Xyes], [AC_MSG_FAILURE([The Java Native Interface is required for Java feature.])]) AS_IF([test -z "$JAVA_HOME"], [AC_MSG_WARN([JAVA_HOME has not been set. JAVA_HOME must be set at run time to locate libjvm.])], [save_LDFLAGS=$LDFLAGS LDFLAGS="-L$JAVA_HOME/lib/$JVM_ARCH/client -L$JAVA_HOME/lib/$JVM_ARCH/server $LDFLAGS" AC_CHECK_LIB([jvm], [JNI_CreateJavaVM], [LIBS=$LIBS], [AC_MSG_WARN([no libjvm found at JAVA_HOME])]) LDFLAGS=$save_LDFLAGS ])]) 
+5
source

Then there is a simple way: http://www.gnu.org/software/autoconf-archive/ax_jni_include_dir.html

Sometimes it’s best to use standard recipes.

+5
source

Source: https://habr.com/ru/post/1277408/


All Articles