-
Notifications
You must be signed in to change notification settings - Fork 77
/
BuildNative
executable file
·215 lines (193 loc) · 4.65 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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
#!/bin/bash
set -eu
# set -x
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
if which hg 2>/dev/null ; then
hg diff > $DYNCALL_DIFF
fi
cd $BASE_DIR
UNAME_ARCH=`uname -m`
UNAME_OS=`uname -s | sed s/_NT-.*/_NT/`
function get_arch() {
if [[ "$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
;;
aarch64)
echo arm64
;;
arm*)
if [[ -d /lib/arm-linux-gnueabihf ]] ; then
echo "armhf"
# echo "arm32v7"
# echo "arm"
elif [[ -d /lib/arm-linux-gnueabi ]] ; then
echo "armel"
# echo "arm32v5"
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 build_libraries() {
local OS="$1"
local ARCH="$2"
shift 2
local CMAKE_FLAGS=( "$@" )
local RESOURCES=()
local TEST_RESOURCES=()
# if [[ "${FAST:-0}" != "1" ]]; then
# mvn generate-sources
# fi
if [[ "$OS" == "android" ]]; then
$BASE_DIR/src/main/cpp/bridj/MakeAndroid.sh $@
return 0
fi
if [[ "${DEBUG:-0}" == "1" ]]; then
CMAKE_FLAGS+=( -DCMAKE_BUILD_TYPE=Debug )
else
CMAKE_FLAGS+=( -DCMAKE_BUILD_TYPE=RelWithDebInfo )
# CMAKE_FLAGS+=( -DCMAKE_BUILD_TYPE=Release )
fi
case "$OS" in
windows)
# CMAKE_FLAGS+=( -G "Visual Studio 17 2022" )
# case "$ARCH" in
# x86)
# CMAKE_FLAGS+=( -A Win32 )
# ;;
# x64)
# CMAKE_FLAGS+=( -A x64 )
# ;;
# arm)
# CMAKE_FLAGS+=( -A ARM )
# ;;
# arm64)
# CMAKE_FLAGS+=( -A ARM64 )
# ;;
# *)
# echo "Unknown arch: $ARCH" >&2
# exit 1
# esac
RESOURCES+=( bridj.dll )
TEST_RESOURCES+=( test.dll dependsOnTest.dll )
;;
darwin)
case "$ARCH" in
x64)
CMAKE_FLAGS+=( -DCMAKE_OSX_ARCHITECTURES=x86_64 )
;;
arm64)
CMAKE_FLAGS+=( -DCMAKE_OSX_ARCHITECTURES=arm64 )
;;
universal)
echo "WARNING: Universal builds don't work yet as JDK does not have fat binaries"
CMAKE_FLAGS+=( -DCMAKE_OSX_ARCHITECTURES="x86_64 arm64" )
;;
esac
RESOURCES+=( libbridj.dylib )
TEST_RESOURCES+=( libtest.dylib libdependsOnTest.dylib )
;;
*)
RESOURCES+=( libbridj.so )
TEST_RESOURCES+=( libtest.so libdependsOnTest.so )
;;
esac
OS_ARCH=${OS}_${ARCH}
OUT=$BASE_DIR/target/$OS_ARCH
if [[ "${DEBUG:-0}" == "1" ]]; then
OUT="${OUT}_debug"
fi
echo "# Building for $OS on $ARCH into $OUT with cmake flags ${CMAKE_FLAGS[*]}"
mkdir -p $OUT
cd $OUT
if [[ "${CMAKE:-1}" != "0" ]]; then
cmake ../.. "${CMAKE_FLAGS[@]}"
fi
# TODO: Different command for VS build on Windows
make -j10
echo "Copying resources for $OS_ARCH"
# RESOURCES_DEST=$BASE_DIR/target/classes/org/bridj/lib/$OS_ARCH
# TEST_RESOURCES_DEST=$BASE_DIR/target/test-classes/org/bridj/lib/$OS_ARCH
# RESOURCES_DEST=$BASE_DIR/target/generated-resources/org/bridj/lib/$OS_ARCH
# TEST_RESOURCES_DEST=$BASE_DIR/target/generated-test-resources/org/bridj/lib/$OS_ARCH
RESOURCES_DEST=$BASE_DIR/src/main/resources/org/bridj/lib/$OS_ARCH
TEST_RESOURCES_DEST=$BASE_DIR/src/test/resources/org/bridj/lib/$OS_ARCH
mkdir -p "$RESOURCES_DEST"
mkdir -p "$TEST_RESOURCES_DEST"
cp "${RESOURCES[@]}" "$RESOURCES_DEST"
cp "${TEST_RESOURCES[@]}" "$TEST_RESOURCES_DEST"
}
if [[ -z "${OS:-}" ]]; then
OS="$(get_os)"
fi
if [[ "${ARCH:-all}" == "all" ]]; then
case $OS in
sunos)
build_libraries sunos x86 "$@"
build_libraries sunos x64 "$@"
;;
windows)
# See README.md on how to download the JDKs needed here
build_libraries windows x64 -DFORCE_JAVA_HOME=${JAVA_HOME_X64} "$@"
build_libraries windows arm64 -DFORCE_JAVA_HOME=${JAVA_HOME_ARM64} "$@"
;;
darwin)
build_libraries darwin x64 "$@"
build_libraries darwin arm64 "$@"
;;
*)
ARCH="$(get_arch)"
build_libraries $OS $ARCH "$@"
esac
else
ARCH=${ARCH:-$(get_arch)}
build_libraries $OS $ARCH "$@"
fi