-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
executable file
·258 lines (220 loc) · 6.37 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
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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
#!/bin/bash
set -ex
PWD=$(pwd)
PATCHES_ROOT="$PWD/patches"
VENDOR_ROOT="$PWD/vendored"
RESOURCE_ROOT="$PWD/resources"
TOOLS_ROOT="$PWD/tools"
EMSDK_ROOT="$VENDOR_ROOT/emsdk"
OPENRCT_SRCROOT="$PWD/vendored/OpenRCT2"
OPENRCT_BUILDROOT="$PWD/build"
OPENRCT_ASSET_BUILDROOT="$PWD/assets"
OPENRCT_INSTALL_DEST_DIR="$PWD/www"
OPENSSL_ROOT="$VENDOR_ROOT/openssl"
DUKTAPE_ROOT="$VENDOR_ROOT/duktape"
ICU_ROOT="$VENDOR_ROOT/icu/icu4c/source"
SPEEXDSP_ROOT="$VENDOR_ROOT/speexdsp"
JSON_ROOT="$VENDOR_ROOT/json"
ZLIB_ROOT="$VENDOR_ROOT/zlib"
ZIP_ROOT="$VENDOR_ROOT/zip"
OGG_ROOT="$VENDOR_ROOT/ogg"
VORBIS_ROOT="$VENDOR_ROOT/vorbis"
OGG_BUILD="$OGG_ROOT/build"
VORBIS_BUILD="$VORBIS_ROOT/build"
ZIP_BUILDROOT="$ZIP_ROOT/build"
export MAKEFLAGS="-j$(nproc)"
DUKTAPE_DIST="https://duktape.org/duktape-2.6.0.tar.xz"
prepare() {
# Make sure submodules are up to date
git -C $PWD submodule update -i --recursive
# Install/update emsdk
pushd $EMSDK_ROOT
./emsdk install latest
./emsdk activate latest
source ./emsdk_env.sh
popd
# Create the build root for OpenRCT2
if [ ! -d $OPENRCT_BUILDROOT ]; then
mkdir -p $OPENRCT_BUILDROOT
fi
if [ ! -d $OPENRCT_ASSET_BUILDROOT ]; then
mkdir -p $OPENRCT_ASSET_BUILDROOT
fi
}
build_openssl() {
pushd $OPENSSL_ROOT
emmake ./Configure \
-no-asm \
-no-ssl2 \
-no-ssl3 \
-no-comp \
-no-hw \
-no-engine \
-no-deprecated \
-no-dso \
-no-tests \
-shared \
--openssldir=built \
linux-generic32
# Patch Makefile
sed -i='' -e 's/^CC=.*/CC=\$\(CROSS_COMPILE\)cc/' Makefile
sed -i='' -e 's/^CXX=.*/CXX=\$\(CROSS_COMPILE\)\+\+/' Makefile
sed -i='' -e 's/^AR=.*/AR=\$\(CROSS_COMPILE\)ar/' Makefile
sed -i='' -e 's/^RANLIB=.*/RANLIB=\$\(CROSS_COMPILE\)ranlib/' Makefile
# Disable enscriptem optimizations for OpenSSL
sed -i='' -e 's/^CFLAGS=-O3 \(.*\)/CFLAGS=\1/' Makefile
# Build
emmake make build_libs
popd
}
build_zlib() {
pushd $ZLIB_ROOT
emcmake cmake $ZLIB_ROOT
emmake make zlib || emmake make zlib
emmake make install || emmake make install
popd
}
build_ogg() {
mkdir -p $OGG_BUILD
pushd $OGG_BUILD
emcmake cmake $OGG_ROOT
emmake make
emmake make install
popd
}
build_vorbis() {
mkdir -p $VORBIS_BUILD
pushd $VORBIS_BUILD
emcmake cmake $VORBIS_ROOT
emmake make
emmake make install
popd
}
build_zip() {
pushd $ZIP_ROOT
if [ ! -d $ZIP_BUILDROOT ]; then
mkdir -p $ZIP_BUILDROOT
fi
cd $ZIP_BUILDROOT
emcmake cmake $ZIP_ROOT \
-DZLIB_INCLUDE_DIR="$ZLIB_ROOT" \
-DZLIB_LIBRARY="$ZLIB_ROOT/libz.a"
emmake make zip
emmake make install
popd
}
build_duktape() {
pushd $VENDOR_ROOT
# Download and unpack Duktape distributable
rm -rf $DUKTAPE_ROOT
curl -O $DUKTAPE_DIST
tar -xvf duktape*tar*
rm -f duktape*tar*
mv duktape-* duktape
popd
pushd $DUKTAPE_ROOT
# Patch Makefile
sed -i='' -e "s/Darwin/Foobar/" Makefile.sharedlibrary
sed -i='' -e "s|^CC =.*|CC=$EMSDK_ROOT/upstream/emscripten/emcc|" Makefile.sharedlibrary
# Build
emmake make -f Makefile.sharedlibrary
ln -s libduktape.so* libduktape.so
ln -s libduktaped.so* libduktaped.so
popd
}
build_icu() {
pushd $ICU_ROOT
ac_cv_namespace_ok=yes icu_cv_host_frag=mh-linux emmake ./configure \
--enable-release \
--enable-shared \
--disable-icu-config \
--disable-extras \
--disable-icuio \
--disable-layoutex \
--disable-tools \
--disable-tests \
--disable-samples
emmake make
popd
}
build_speexdsp() {
pushd $SPEEXDSP_ROOT
emmake ./autogen.sh
emmake ./configure --enable-shared --disable-neon
emmake make
popd
}
build_openrct2_assets() {
pushd $OPENRCT_ASSET_BUILDROOT
cmake $OPENRCT_SRCROOT -DMACOS_BUNDLE=off -DDISABLE_NETWORK=on -DDISABLE_GUI=off
make openrct2-cli VERBOSE=1
make g2
DESTDIR=. make install
cp -v g2.dat "$OPENRCT_BUILDROOT"
cp -v openrct2-cli "$OPENRCT_BUILDROOT"
cp -vr usr/local/share/openrct2/object usr/local/share/openrct2/sequence .
popd
}
build_openrct2() {
pushd $OPENRCT_BUILDROOT
emcmake env \
PKG_CONFIG_PATH="$EMSDK_ROOT/upstream/emscripten/cache/sysroot/local/lib/pkgconfig:$EMSDK_ROOT/upstream/emscripten/cache/sysroot/lib/pkgconfig:$EMSDK_ROOT/upstream/emscripten/cache/sysroot/share/pkgconfig" \
cmake $OPENRCT_SRCROOT \
-DOPENSSL_INCLUDE_DIR="$OPENSSL_ROOT/include" \
-DOPENSSL_SSL_LIBRARY="$OPENSSL_ROOT/libssl.a" \
-DOPENSSL_CRYPTO_LIBRARY="$OPENSSL_ROOT/libcrypto.a" \
-Dduktape_DIR="$OPENRCT_SRCROOT/cmake" \
-DDUKTAPE_INCLUDE_DIR="$DUKTAPE_ROOT/src" \
-DDUKTAPE_LIBRARY="$DUKTAPE_ROOT/libducktape.so" \
-DICU_INCLUDE_DIR="$ICU_ROOT/common" \
-DICU_LIBRARY="$ICU_ROOT/lib/libicuuc.so" \
-DLIBZIP_LIBRARIES="$ZIP_BUILDROOT/lib/libzip.a" \
-DICU_DT_LIBRARY_RELEASE="$ICU_ROOT/stubdata/libicudata.so" \
-DICU_UC_LIBRARY_RELEASE="$ICU_ROOT/lib/libicuuc.so" \
-DSPEEXDSP_INCLUDE_DIR="$SPEEXDSP_ROOT/include" \
-DSPEEXDSP_LIBRARY="$SPEEXDSP_ROOT/libspeexdsp/.libs/libspeexdsp.a" \
-DDISABLE_HTTP:BOOL=FALSE \
-DDISABLE_TTF:BOOL=TRUE \
-DENABLE_SCRIPTING:BOOL=FALSE \
-DDISABLE_FLAC:BOOL=TRUE \
-DCMAKE_SYSTEM_NAME=Emscripten
DESTDIR=. emmake make install VERBOSE=1
popd
}
master_resources() {
if [ ! -d $OPENRCT_INSTALL_DEST_DIR ]; then
mkdir -p $OPENRCT_INSTALL_DEST_DIR
mkdir -p "$OPENRCT_INSTALL_DEST_DIR/user-data-path"
mkdir -p "$OPENRCT_INSTALL_DEST_DIR/rct2-data-path"
fi
pushd $OPENRCT_INSTALL_DEST_DIR
# Patch clownshoes code
# https://github.com/emscripten-core/emscripten/issues/13219
sed -i='' -e 's/throw "getpwuid: TODO"/return 0/' "$OPENRCT_BUILDROOT/openrct2.js"
cp -v "$RESOURCE_ROOT/index.html" .
cp -v "$OPENRCT_BUILDROOT/openrct2.js" .
cp -v "$OPENRCT_BUILDROOT/openrct2.worker.js" .
cp -v "$OPENRCT_BUILDROOT/openrct2.wasm" .
cp -v "$OPENRCT_BUILDROOT/openrct2.wasm.map" . || true
cp -v "$OPENRCT_BUILDROOT/g2.dat" .
cp -v "$RESOURCE_ROOT/config.ini" "./user-data-path"
cp -vR "$OPENRCT_ASSET_BUILDROOT/g2.dat" "./rct2-data-path"
cp -vR "$OPENRCT_ASSET_BUILDROOT/object" "./rct2-data-path"
cp -vR "$OPENRCT_ASSET_BUILDROOT/sequence" "./rct2-data-path"
cp -vR "$OPENRCT_SRCROOT/data/language" "./rct2-data-path"
# Scan ourseslves to discover assets
$TOOLS_ROOT/gestalt.py -i ./rct2-data-path -o .
popd
}
prepare
build_openssl
build_zlib
build_zip
build_duktape
build_icu
build_speexdsp
build_ogg
build_vorbis
build_openrct2_assets
build_openrct2
master_resources