forked from supranational/blst
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
executable file
·86 lines (75 loc) · 2.76 KB
/
build.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/bin/sh -e
JAVA_PACKAGE=${JAVA_PACKAGE:-supranational.blst}
# figure out if this script was source-d
if [ `dirname "$0"` -ef "$PWD" ]; then
TOP="$PWD"
elif [ -n "$OLDPWD" -a "$OLDPWD/$0" -ef `basename "$0"` ]; then
TOP="$PWD"
else
TOP=`dirname "$0"`
fi
TOP=`(cd "$TOP"/.. && echo $PWD)`
# figure out JAVA_HOME if not set by caller
if [ "x$JAVA_HOME" = "x" -a -x /usr/libexec/java_home ]; then
JAVA_HOME=`/usr/libexec/java_home 2>/dev/null || true`
fi
if [ "x$JAVA_HOME" = "x" ]; then
JAVA_HOME=`java -XshowSettings:properties -version 2>&1 | \
awk 'BEGIN { FS="=[ \t]*" } /java\.home/ { print $2 }'`
fi
if [ ! -d "$JAVA_HOME" ]; then
echo "JAVA_HOME='$JAVA_HOME' is not a directory" 1>&2
exit 1
fi
if [ ! -d "$JAVA_HOME"/include ]; then
if [ -d "$JAVA_HOME"/../include ]; then
JAVA_HOME=`dirname "$JAVA_HOME"`
else
echo "JAVA_HOME='$JAVA_HOME' is not a JDK" 1>&2
exit 1
fi
fi
# spot jni_md.h, which is included from jni.h
JNI_MD=`ls "$JAVA_HOME"/include/*/jni_md.h`
JNI_MD=`dirname "$JNI_MD"`
PKG=`echo $JAVA_PACKAGE | tr . /`
mkdir -p $PKG
if [ ! -f blst_wrap.cpp -o "$TOP"/blst.swg -nt blst_wrap.cpp \
-o "$TOP"/blst.hpp -nt blst_wrap.cpp \
-o "$TOP"/blst.h -nt blst_wrap.cpp \
-o ! -f $PKG/blst.java ]; then
(set -x; swig -c++ -java -package $JAVA_PACKAGE -outdir $PKG \
-o blst_wrap.cpp "$TOP"/blst.swg)
fi
if [ ! -f $PKG/blst.class -o $PKG/blst.java -nt $PKG/blst.class ]; then
(set -x; "$JAVA_HOME"/bin/javac $PKG/*.java)
fi
# ask blstJNI how does it name the shared library
SO_NAME=$PKG/`"$JAVA_HOME"/bin/java $PKG/blstJNI 2>/dev/null`
LIBBLST_A=libblst.a
if [ -f "$TOP"/libblst.a -a "$TOP"/libblst.a -nt "$TOP"/blst.h ]; then
LIBBLST_A="$TOP"/libblst.a
elif [ ! -f libblst.a -o "$TOP"/blst.h -nt libblst.a ]; then
$TOP/../build.sh "$@"
fi
if [ ! -f $SO_NAME -o blst_wrap.cpp -nt $SO_NAME \
-o $LIBBLST_A -nt $SO_NAME ]; then
mkdir -p `dirname $SO_NAME`
case $SO_NAME in
*.so) LDFLAGS=${LDFLAGS:--Wl,-Bsymbolic};;
*.dll) LDFLAGS=${LDFLAGS:--static-libstdc++};;
esac
if [ "x$CXX" = "x" ]; then
CXX=g++
which c++ >/dev/null 2>&1 && CXX=c++
fi
STD=`${CXX} -dM -E -x c++ /dev/null | \
awk '{ if($2=="__cplusplus" && $3<"2011") print "-std=c++11"; }'`
(set -x; ${CXX} -shared -o $SO_NAME -fPIC ${STD} \
-I"$JAVA_HOME"/include -I"$JNI_MD" -I"$TOP" \
-O -Wall -Wno-unused-function blst_wrap.cpp \
$LIBBLST_A ${LDFLAGS})
fi
if [ ! -f $JAVA_PACKAGE.jar -o $SO_NAME -nt $JAVA_PACKAGE.jar ]; then
(set -x; "$JAVA_HOME"/bin/jar cf $JAVA_PACKAGE.jar $PKG/*.class $PKG/*/*/*)
fi