forked from nativelibs4java/BridJ
-
Notifications
You must be signed in to change notification settings - Fork 0
/
BuildNative
executable file
·179 lines (156 loc) · 3.54 KB
/
BuildNative
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
#!/bin/bash
function failed() {
echo "$@"
exit 1
}
cd `dirname $0`
BASE_DIR=$PWD
export DYNCALL_HOME=$BASE_DIR/dyncall
DYNCALL_DIFF=$BASE_DIR/src/main/cpp/bridj/dyncall.diff
if [[ ! -d "$DYNCALL_HOME" ]]
then
$BASE_DIR/admin/checkout_and_patch_dyncall.sh $DYNCALL_DIFF || failed "Failed to checkout and patch dyncall"
fi
cd $DYNCALL_HOME
hg diff > $DYNCALL_DIFF
cd $BASE_DIR
MAKE_CMD=make
if [[ "`which gmake`" != "" ]]; then
MAKE_CMD=gmake
fi
UNAME_ARCH=`uname -m`
UNAME_OS=`uname -s | sed s/_NT-.*/_NT/`
function get_arch() {
if [[ -n "$ARCH" ]]; then
echo "$ARCH"
elif [[ "$UNAME_OS" == "SunOS" ]]; then
if [ "`isainfo -n`" = "amd64" ]; then
echo "x64"
else
echo "x86"
fi
elif [[ "$UNAME_OS" == "Darwin" ]]; then
echo "universal"
else
case $UNAME_ARCH in
i86pc|i386|i486|i586|i686|x86)
echo x86
;;
x86_64|amd64)
echo x64
;;
arm*)
if [[ -d /lib/arm-linux-gnueabihf ]] ; then
echo "armhf"
elif [[ -d /lib/arm-linux-gnueabi ]] ; then
echo "armel"
else
failed "Unknown Linux arm flavour: please edit $0 and Platform.java"
fi
;;
esac
fi
}
function get_os() {
case $UNAME_OS in
WindowsNT)
echo "windows"
;;
Darwin)
echo "darwin"
;;
Linux)
echo "linux"
;;
SunOS)
echo "sunos"
;;
OpenBSD)
echo "openbsd"
;;
FreeBSD|GNU/kFreeBSD)
echo "freebsd"
;;
NetBSD)
echo "netbsd"
;;
esac
}
function get_os_arch() {
case $OS in
windows)
case $ARCH in
x86)
echo win32
;;
x64)
echo win64
;;
esac
;;
*)
echo ${OS}_${ARCH}
;;
esac
}
CMDS=$@
if [[ -z "$BRIDJ_TARGETS" ]]; then
BRIDJ_TARGETS="default"
if [[ -n "$ANDROID_NDK_HOME" ]] ; then
BRIDJ_TARGETS="$BRIDJ_TARGETS android" ;
fi
fi
if [[ "$1" != "clean" && "$FAST" != "1" ]]; then
mvn generate-sources
fi
function build_libraries() {
export NATIVE_ARCH=`ARCH="" get_arch`
export ARCH=`get_arch`
export OS_ARCH=`get_os_arch`
for BRIDJ_TARGET in $BRIDJ_TARGETS ; do
case $BRIDJ_TARGET in
default)
cd $DYNCALL_HOME
local DYNCALL_CONFIGURE_ARGS=""
if [[ "$ARCH" != "$NATIVE_ARCH" ]]; then
DYNCALL_CONFIGURE_ARGS="--target-$ARCH"
fi
sh ./configure $DYNCALL_CONFIGURE_ARGS
$MAKE_CMD $@ || failed "Failed building dyncall"
export DYNCALL_HOME
export OS
export ARCH
export CONFIG
export OUT_DIR=$BASE_DIR/src/main/resources/org/bridj/lib/$OS_ARCH
export OBJ_DIR=target/build/${OS}_${ARCH}_${CONFIG}
export DYNCALL_BUILD_DIR=build_out/${OS}_${ARCH}_gcc_${CONFIG}
cd $BASE_DIR/src/main/cpp/bridj
$MAKE_CMD $@ || failed "Build of lib failed"
export OUT_DIR=$BASE_DIR/src/test/resources/org/bridj/lib/$OS_ARCH
cd $BASE_DIR/src/test/cpp/test
$MAKE_CMD $@ || failed "Build of test lib failed"
cd $BASE_DIR/src/test/cpp/dependsOnTest
$MAKE_CMD $@ || failed "Build of dependsOnTest lib failed"
;;
android)
$BASE_DIR/src/main/cpp/bridj/MakeAndroid.sh $@
;;
esac
done
}
export OS=`get_os`
if [[ "$DEBUG" == "1" ]]; then
CONFIG=debug
else
CONFIG=release
fi
if [[ $OS =~ sunos ]]; then
ARCH=x86 build_libraries $@
ARCH=x64 build_libraries $@
else
if [[ $OS =~ darwin ]]; then
export AS=llvm-as
export CC=llvm-gcc
fi
build_libraries $@
fi