More statics and limit exports to Java methods at link
[ldk-java] / genbindings.sh
index 1bd8f4cb29e994978d869a4a616a34bc097fe55e..2aa8a1e739de2e5113186eede368f8568f3623bf 100755 (executable)
@@ -1,12 +1,22 @@
 #!/bin/sh
-if [ "$1" = "" -o "$2" = "" ]; then
-       echo "USAGE: path/to/rust-lightning \"JNI_CFLAGS\""
+usage() {
+       echo "USAGE: path/to/rust-lightning \"JNI_CFLAGS\" debug"
        echo "For JNI_CFLAGS you probably want -I/usr/lib/jvm/java-11-openjdk-amd64/include/ -I/usr/lib/jvm/java-11-openjdk-amd64/include/linux/"
+       echo "debug should either be true or false"
        exit 1
-fi
+}
+[ "$1" = "" -o "$2" = "" ] && usage
+[ "$3" != "true" -a "$3" != "false" ] && usage
+
 set -e
-./genbindings.py "$1/lightning-c-bindings/include/lightning.h" src/main/java/org/ldk/impl/bindings.java src/main/jni/bindings.c
-javac -h src/main/jni src/main/java/org/ldk/impl/bindings.java
-rm src/main/java/org/ldk/impl/bindings*.class
-clang -g -pthread -ldl -fsanitize=address -Wall -o liblightningjni.so -shared -fPIC -Wno-pointer-sign -Isrc/main/jni -I"$1/lightning-c-bindings/include/" $2 src/main/jni/bindings.c "$1"/target/debug/liblightning.a
-#clang -Wl,--no-undefined -shared-libasan -pthread -ldl -Wall -flto -fuse-ld=lld -O2 -o liblightningjni.so -shared -fPIC -Wno-pointer-sign -Isrc/main/jni -I"$1/lightning-c-bindings/include/" $2 src/main/jni/bindings.c "$1"/target/release/liblightning.a
+mkdir -p src/main/java/org/ldk/enums
+rm -f src/main/java/org/ldk/enums/*.java
+./genbindings.py "$1/lightning-c-bindings/include/lightning.h" src/main/java/org/ldk/impl/bindings.java src/main/java/org/ldk/enums src/main/jni/bindings.c $3
+javac -h src/main/jni src/main/java/org/ldk/enums/*.java src/main/java/org/ldk/impl/bindings.java
+rm src/main/java/org/ldk/enums/*.class src/main/java/org/ldk/impl/bindings*.class
+COMPILE="clang -std=c11 -Wall -Wno-unused-function -Wl,--no-undefined -pthread -ldl -o liblightningjni.so -shared -fPIC -Wno-pointer-sign -Isrc/main/jni -Wl,--version-script=libcode.version"
+if [ "$3" = "true" ]; then
+       $COMPILE -g -fsanitize=address -shared-libasan -I"$1"/lightning-c-bindings/include/ $2 src/main/jni/bindings.c "$1"/lightning-c-bindings/target/debug/libldk.a
+else
+       $COMPILE -flto -fuse-ld=lld -O3 -I"$1"/lightning-c-bindings/include/ $2 src/main/jni/bindings.c "$1"/lightning-c-bindings/target/release/libldk.a
+fi