Java Developer Guide/Using java-pkg-simple.eclass/JNI creation
From Gentoo Wiki
Jump to:navigation
Jump to:search
An example of JNI creation without scripts for external tools can be found in dev-java/lz4-java:
src_compile() {
...
einfo "Generate native library"
# https://devmanual.gentoo.org/ebuild-writing/functions/src_compile/no-build-system
mkdir -p build/objects/src/jni
mkdir -p build/jni/net/jpountz/util/linux/amd64
"$(tc-getCC)" ${CFLAGS} ${CPPFLAGS} ${LDFLAGS} \
$(java-pkg_get-jni-cflags) \
-Ibuild/jni-headers \
-c -o build/objects/src/jni/net_jpountz_lz4_LZ4JNI.o \
src/jni/net_jpountz_lz4_LZ4JNI.c
"$(tc-getCC)" ${CFLAGS} ${CPPFLAGS} ${LDFLAGS} \
$(java-pkg_get-jni-cflags) \
-Ibuild/jni-headers \
-c -o build/objects/src/jni/net_jpountz_xxhash_XXHashJNI.o \
src/jni/net_jpountz_xxhash_XXHashJNI.c
"$(tc-getCC)" ${CFLAGS} ${CPPFLAGS} ${LDFLAGS} \
-shared \
-Wl,-soname,liblz4-java.so \
-o liblz4-java.so \
build/objects/src/jni/net_jpountz_lz4_LZ4JNI.o \
build/objects/src/jni/net_jpountz_xxhash_XXHashJNI.o -llz4
}
For linking to a system library, lz4 in this case, it is essential to put the arguments in the right order, -llz4 at the end.