Improve detection of JDK location for JNI #551
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Currently on anything other than Debian it is necessary to manually point the build to the JDK location. There is a rudimentary mechanism for automatic detection, but we can do better. Let’s make sure that running
make themis_jni
‘just works’ for all operating systems that we support.We need to have correct include path to be able to access JNI headers. These are installed by JDK somewhere into the system. Normally there are two paths: generic path where "jni.h" is located and a platform-specific directory (usually a subdirectory under the generic path).
First of all, there is user override. If JDK_INCLUDE_PATH contains anything, that’s considered our include path. Prepend
-I
to every directory in that list and use that.Otherwise we try to detect the paths automatically. Debian and Ubuntu packages distribute a
java_defaults.mk
makefile which conveniently defines C compiler flags in thejvm_includes
variable. Check if that file exists via Make magic, include it, and use that variable. Notethat this file requires the dpkg-dev package to be installed in addition to JDK package (e.g., openjdk-11-jdk for Debian 10 Buster).
Other systems are not so nice. JNI headers are usually installed into JAVA_HOME. If JAVA_HOME environment variable is not set then ask Java. The includes are usually located under the
include
directory in the home directory plus there is an platform-specific subdirectory. On macOS it's calleddarwin
. Many Linux distributions uselinux
(CentOS certainly does).If automatic detection does not work, use JDK_INCLUDE_PATH. Typically you’ll need something like this:
P.S. Android uses its own magic for building the library correctly, see
jni/Android.mk
.Checklist
Benchmark results are attached(not applicable)Example projects and code samples are updated if needed(no API changes)