-
Notifications
You must be signed in to change notification settings - Fork 8
/
build-all.sh
executable file
·490 lines (370 loc) · 13.6 KB
/
build-all.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
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
#!/bin/bash
setupBuildEnv()
{
if [ ! -d "$INIT_DIR/cache/android-ndk" ]; then
echo "Downloading NDK..."
curl --output "cache/$NDK_FILENAME" -#L "$NDK_URL"
echo "Unpacking NDK..."
7z x "cache/$NDK_FILENAME" -aoa -o"cache" &> /dev/null
mv "cache/$(unzip -Z1 "cache/$NDK_FILENAME" | cut -d "/" -f 1 | head -n 1)" "cache/android-ndk"
rm -f "cache/$NDK_FILENAME"
echo ""
fi
if [ ! -d "$INIT_DIR/cache/llvm-mingw" ]; then
echo "Downloading llvm-mingw..."
curl --output "cache/$MINGW_FILENAME" -#L "$MINGW_URL"
echo "Unpacking llvm-mingw..."
tar -xf "cache/$MINGW_FILENAME" -C "cache"
mv "cache/$(tar -tf "cache/$MINGW_FILENAME" | cut -d "/" -f 1 | head -n 1)" "cache/llvm-mingw"
rm -f "cache/$MINGW_FILENAME"
echo ""
fi
export PATH=$INIT_PATH:$INIT_DIR/cache/android-ndk/toolchains/llvm/prebuilt/linux-x86_64/bin:$INIT_DIR/cache/llvm-mingw/bin
export ANDROID_SDK="$1"
export ARCH="$2"
export CC=$ARCH-linux-android$ANDROID_SDK-clang
export CXX=$CC++
export TOOLCHAIN_VERSION="$ARCH-linux-android-4.9"
export TOOLCHAIN_TRIPLE="$ARCH-linux-android"
export PKG_CONFIG_PATH="$PREFIX/share/pkgconfig:$PREFIX/lib/pkgconfig"
export PKG_CONFIG_LIBDIR="$PREFIX/lib/pkgconfig"
}
applyPatches()
{
for patch in $(find $INIT_DIR/packages/$package -name "*.patch" | sort); do
echo "- Applying '$(basename $patch)' for '$package'..."
patch -p1 < "$patch" -ts
if [ $? != 0 ]; then
echo "- Error on Applying Patch '$(basename $patch)' on '$package'"
exit
fi
done
echo ""
$RUN_POST_APPLY_PATCH
}
downloadAndExtractPackage()
{
if [ -e "$INIT_DIR/cache/$package" ]; then
echo "-- Package '$package' already downloaded."
else
echo "-- Downloading '$package'..."
curl --output "$INIT_DIR/cache/$package" -# -L $SRC_URL
fi
local ARCHIVE_MIME_TYPE=$(file -b --mime-type $INIT_DIR/cache/$package)
case $ARCHIVE_MIME_TYPE in "application/x-xz"|"application/gzip"|"application/x-bzip2")
ARCHIVE_BASE_FOLDER=$(tar -tf "$INIT_DIR/cache/$package" | cut -d "/" -f 1 | head -n 1)
if [ ! -f "$ARCHIVE_BASE_FOLDER" ]; then
tar -xf "$INIT_DIR/cache/$package"
fi
;;
*)
ARCHIVE_BASE_FOLDER=$(unzip -Z1 "$INIT_DIR/cache/$package" | cut -d "/" -f 1 | head -n 1)
if [ ! -f "$ARCHIVE_BASE_FOLDER" ]; then
unzip -o "$INIT_DIR/cache/$package" 1> /dev/null
fi
esac
mv $ARCHIVE_BASE_FOLDER $package
}
gitDownload()
{
if [ -d "$INIT_DIR/cache/$package" ]; then
echo "-- Package '$package' already downloaded."
git clone "$INIT_DIR/cache/$package" &> /dev/zero
else
echo "-- Git Cloning '$package'..."
git clone --no-checkout $GIT_URL "$INIT_DIR/cache/$package" &> /dev/zero
git clone "$INIT_DIR/cache/$package" &> /dev/zero
fi
cd $package
if [ -n "$GIT_COMMIT" ]; then
git checkout $GIT_COMMIT &> /dev/zero
fi
git checkout . &> /dev/zero
git submodule update --init --recursive &> /dev/zero
cd ..
}
setupPackage()
{
unset PKG_VER PKG_CATEGORY PKG_PRETTY_NAME \
GIT_URL SRC_URL GIT_COMMIT \
HOST_BUILD_FOLDER HOST_BUILD_MAKE HOST_BUILD_CONFIGURE_ARGS HOST_BUILD_CFLAGS HOST_BUILD_CXXFLAGS HOST_BUILD_LDFLAGS \
CONFIGURE_ARGS MESON_ARGS CMAKE_ARGS \
RUN_POST_APPLY_PATCH RUN_POST_BUILD RUN_POST_CONFIGURE \
CFLAGS CPPFLAGS LDFLAGS LIBS OVERRIDE_PREFIX OVERRIDE_PKG_CONFIG_PATH \
BLACKLIST_ARCHITECTURE BUILD_IN_SRC VK_DRIVER_LIB
package=$1
. "$INIT_DIR/packages/$package/build.sh"
if [ -n "$GIT_COMMIT" ]; then
PKG_VER=$(echo $PKG_VER | sed "s/\[gss\]/$(echo $GIT_COMMIT | cut -c1-7)/g")
fi
if [ ! -f "$INIT_DIR/built-pkgs/$package-$PKG_VER-$ARCHITECTURE.rat" ]; then
if [ -e "$INIT_DIR/workdir/$package/build.sh" ]; then
echo "-- Package '$package' already configured."
else
if [ "$BLACKLIST_ARCHITECTURE" == "$ARCHITECTURE" ]; then
echo "-- Warning: '$package' will not be built."
else
if [ -n "$SRC_URL" ]; then
downloadAndExtractPackage
elif [ -n "$GIT_URL" ]; then
gitDownload
elif [ -n "$BUILD_IN_SRC" ]; then
mkdir -p $package
cp -rf "$INIT_DIR/packages/$package/"* $package
rm $package/build.sh
fi
cd $package
applyPatches
echo "export CFLAGS=\"$CFLAGS\" LIBS=\"$LIBS\" CPPFLAGS=\"$CPPFLAGS\" LDFLAGS=\"$LDFLAGS\"" > build.sh
echo "export DESTDIR=\"$INIT_DIR/workdir/$package/destdir-pkg\"" >> build.sh
PREFIX_DIR=$PREFIX
if [ -n "$OVERRIDE_PREFIX" ]; then
PREFIX_DIR=$OVERRIDE_PREFIX
fi
if [ "$OVERRIDE_PKG_CONFIG_PATH" != "" ]; then
echo "export PKG_CONFIG_PATH=$OVERRIDE_PKG_CONFIG_PATH" >> build.sh
else
echo "export PKG_CONFIG_PATH=$PKG_CONFIG_PATH" >> build.sh
fi
if [ -e "./configure" ] && [ -n "$CONFIGURE_ARGS" ]; then
if [ -n "$HOST_BUILD_CONFIGURE_ARGS" ]; then
echo "mkdir -p $HOST_BUILD_FOLDER" >> build.sh
echo "cd $HOST_BUILD_FOLDER" >> build.sh
echo "env -i bash -l -c \"../configure $HOST_BUILD_CONFIGURE_ARGS\"" >> build.sh
echo "$HOST_BUILD_MAKE" >> build.sh
echo 'cd $OLDPWD' >> build.sh
fi
echo "../configure --libdir=$PREFIX_DIR/lib --prefix=$PREFIX_DIR $CONFIGURE_ARGS" >> build.sh
echo "$RUN_POST_CONFIGURE" >> build.sh
if [ -e "$INIT_DIR/packages/$package/post-configure.sh" ]; then
echo "$INIT_DIR/packages/$package/post-configure.sh" >> build.sh
fi
echo "make -j $(nproc)" >> build.sh
if [ -e "$INIT_DIR/packages/$package/custom-make-install.sh" ]; then
echo "$INIT_DIR/packages/$package/custom-make-install.sh" >> build.sh
else
echo "make -j $(nproc) install" >> build.sh
fi
elif [ -e "autogen.sh" ] && [ -n "$CONFIGURE_ARGS" ]; then
echo "cd .." >> build.sh
echo "./autogen.sh" >> build.sh
echo "cd build_dir" >> build.sh
echo "../configure --libdir=$PREFIX_DIR/lib --prefix=$PREFIX_DIR $CONFIGURE_ARGS" >> build.sh
echo "$RUN_POST_CONFIGURE" >> build.sh
if [ -e "$INIT_DIR/packages/$package/post-configure.sh" ]; then
echo "$INIT_DIR/packages/$package/post-configure.sh" >> build.sh
fi
echo "make -j $(nproc)" >> build.sh
if [ -e "$INIT_DIR/packages/$package/custom-make-install.sh" ]; then
echo "$INIT_DIR/packages/$package/custom-make-install.sh" >> build.sh
else
echo "make -j $(nproc) install" >> build.sh
fi
elif [ -e "./CMakeLists.txt" ] && [ -n "$CMAKE_ARGS" ]; then
echo "cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=$PREFIX_DIR -DCMAKE_INSTALL_LIBDIR=$PREFIX_DIR/lib $CMAKE_ARGS .." >> build.sh
echo "make -j $(nproc)" >> build.sh
if [ -e "$INIT_DIR/packages/$package/custom-make-install.sh" ]; then
echo "$INIT_DIR/packages/$package/custom-make-install.sh" >> build.sh
else
echo "make -j $(nproc) install" >> build.sh
fi
elif [ -e "./meson.build" ] && [ -n "$MESON_ARGS" ]; then
echo "meson setup -Dbuildtype=release --cross-file=$INIT_DIR/meson-cross-file-$ARCHITECTURE -Dprefix=$PREFIX_DIR $MESON_ARGS .." >> build.sh
if [ -e "$INIT_DIR/packages/$package/post-configure.sh" ]; then
echo "$INIT_DIR/packages/$package/post-configure.sh" >> build.sh
fi
echo "ninja -j $(nproc)" >> build.sh
if [ -e "$INIT_DIR/packages/$package/custom-make-install.sh" ]; then
echo "$INIT_DIR/packages/$package/custom-make-install.sh" >> build.sh
else
echo "ninja -j $(nproc) install" >> build.sh
fi
elif [ -e "Configure" ] && [ -n "$OPENSSL_FLAGS" ]; then
echo "../Configure --prefix=$PREFIX_DIR $OPENSSL_FLAGS" >> build.sh
if [ -e "$INIT_DIR/packages/$package/post-configure.sh" ]; then
echo "$INIT_DIR/packages/$package/post-configure.sh" >> build.sh
fi
echo "make -j $(nproc)" >> build.sh
echo "make -j $(nproc) DESTDIR=\"\$DESTDIR\" install_sw" >> build.sh
elif [ -e "Makefile" ]; then
echo "cd .." >> build.sh
echo "make -j $(nproc)" >> build.sh
echo "make -j $(nproc) install" >> build.sh
echo "cd build_dir" >> build.sh
else
echo "Unsupported build system. Stopping..."
exit 1
fi
if [ -e "$INIT_DIR/packages/$package/post-install.sh" ]; then
echo "$INIT_DIR/packages/$package/post-install.sh" >> build.sh
fi
echo 'echo $? > exit_code' >> build.sh
echo "$PKG_PRETTY_NAME" >> pkg-pretty-name
echo "$PKG_VER" >> pkg-ver
echo "$PKG_CATEGORY" >> pkg-category
if [ "$PKG_CATEGORY" == "VulkanDriver" ]; then
echo "$VK_DRIVER_LIB" >> vk-driver-lib
fi
git -C "$INIT_DIR" log -1 --format="%H" -- "packages/$package" > pkg-commit
chmod +x build.sh
cd ..
echo $package >> index
fi
fi
fi
}
setupPackages()
{
cd "$INIT_DIR/workdir"
mkdir -p "$PREFIX/include"
for package in $PACKAGES; do
packageFullPath=$(ls "$INIT_DIR/built-pkgs/$package"*"$ARCHITECTURE.rat" 2> /dev/zero)
packageCommitFullPath=$(ls "$INIT_DIR/built-pkgs/$package"*"$ARCHITECTURE.commit" 2> /dev/zero)
if [ -f "$packageFullPath" ]; then
packageCommit=$(cat "$packageCommitFullPath")
actualCommit=$(git -C "$INIT_DIR" log -1 --format="%H" -- "packages/$package")
if [ "$packageCommit" == "$actualCommit" ]; then
installBuiltPackage "$packageFullPath"
else
echo "Warning: Package '$package' already built, But it's source is changed. Removing..."
rm -f "$packageFullPath"
rm -f "$packageCommitFullPath"
fi
fi
done
for package in $PACKAGES; do
setupPackage $package
done
}
installBuiltPackage()
{
local package=$1
if [ ! -e "$APP_ROOT_DIR/packages/$(basename $package .rat)" ]; then
echo "-- Installing '$(basename $package .rat)'"
mkdir -p $APP_ROOT_DIR/packages
unzip -o "$package" -d "$APP_ROOT_DIR" &> /dev/zero
touch $APP_ROOT_DIR/makeSymlinks.sh
bash $APP_ROOT_DIR/makeSymlinks.sh
rm -f $APP_ROOT_DIR/makeSymlinks.sh
touch $APP_ROOT_DIR/packages/$(basename $package .rat)
fi
}
compileAll()
{
echo ""
echo "-- Starting Building --"
echo ""
for package in $(cat "$INIT_DIR/workdir/index"); do
local packageBuildDir="$INIT_DIR/workdir/$package/build_dir"
local packageDestDirPkg="$INIT_DIR/workdir/$package/destdir-pkg"
mkdir -p "$packageBuildDir"
mkdir -p "$packageDestDirPkg"
cd "$INIT_DIR/workdir/$package/build_dir"
touch exit_code
pkgVersion="$(cat ../pkg-ver)"
pkgCategory="$(cat ../pkg-category)"
pkgCommit="$(cat ../pkg-commit)"
pkgPrettyName="$(cat ../pkg-pretty-name)"
vkDriverLib=""
if [ "$pkgCategory" == "VulkanDriver" ]; then
vkDriverLib="$(cat ../vk-driver-lib)"
fi
pkgLocalChanged="$(git -C "$INIT_DIR" status --short "packages/$package")"
if [ -n "$pkgLocalChanged" ]; then
echo "Source Files for Package '$package' was changed. Reconfiguring..."
echo ""
cd "$INIT_DIR/workdir"
rm -rf "$package"
setupPackage $package
mkdir -p "$packageBuildDir"
mkdir -p "$packageDestDirPkg"
cd "$packageBuildDir"
touch exit_code
pkgVersion="$(cat ../pkg-ver)"
pkgCategory="$(cat ../pkg-category)"
pkgCommit="$(cat ../pkg-commit)"
if [ "$pkgCategory" == "VulkanDriver" ]; then
vkDriverLib="$(cat ../vk-driver-lib)"
fi
fi
if [ -f "$INIT_DIR/built-pkgs/$package-$pkgVersion-$ARCHITECTURE.rat" ]; then
echo "-- Package '$package' already built."
else
echo "-- Compiling Package '$package'..."
../build.sh 1> "$INIT_DIR/logs/$package-log.txt" 2> "$INIT_DIR/logs/$package-error_log.txt"
if [ "$?" != "0" ]; then
echo "- Package: '"$package"' failed to compile. Check logs"
exit 0
fi
if [ ! -d "$packageDestDirPkg/data/data/com.micewine.emu" ]; then
echo "- Package: '"$package"' failed to compile. Check logs"
exit 0
fi
cp -rf "$packageDestDirPkg/data/data/com.micewine.emu/"* "/data/data/com.micewine.emu"
find "$packageDestDirPkg" -type f > "$INIT_DIR/logs/$package-package-files.txt"
echo $pkgCommit > "$INIT_DIR/built-pkgs/$package-$pkgVersion-$ARCHITECTURE.commit"
if [ ! -n "$pkgPrettyName" ]; then
pkgPrettyName=$package
fi
$INIT_DIR/create-rat-pkg.sh "$package" "$pkgPrettyName" "$vkDriverLib" "$ARCHITECTURE" "$pkgVersion" "$pkgCategory" "$packageDestDirPkg" "$INIT_DIR/built-pkgs" 0
fi
done
}
showHelp()
{
echo "Usage: $0 ARCHITECTURE [OPTIONS]"
echo ""
echo "Options:"
echo " --help: Show this message and exit."
echo " --clean-workdir: Clean workdir (for a clean compiling)."
echo " --clean-cache: Clean cache of downloaded packages."
echo ""
echo "Available Architectures:"
echo " x86_64"
echo " aarch64"
}
if [ $# -lt 1 ]; then
showHelp
exit 0
fi
case $1 in "aarch64"|"x86_64")
export ARCHITECTURE=$1
;;
"--help")
showHelp
exit 0
;;
*)
printf "Error: Unsupported Architecture \"$1\" Specified.\n\n"
showHelp
exit 0
esac
export APP_ROOT_DIR=/data/data/com.micewine.emu
export PREFIX=$APP_ROOT_DIR/files/usr
if [ ! -e "$PREFIX" ]; then
sudo mkdir -p "$PREFIX"
sudo chown -R $(whoami):$(whoami) "$APP_ROOT_DIR"
sudo chmod 755 -R "$APP_ROOT_DIR"
fi
export NDK_URL="https://dl.google.com/android/repository/android-ndk-r26b-linux.zip"
export NDK_FILENAME="${NDK_URL##*/}"
export MINGW_URL="https://github.com/mstorsjo/llvm-mingw/releases/download/20240619/llvm-mingw-20240619-ucrt-ubuntu-20.04-x86_64.tar.xz"
export MINGW_FILENAME="${MINGW_URL##*/}"
export PACKAGES="$(cat packages/index)"
export INIT_DIR="$PWD"
export INIT_PATH="$PATH"
case $* in "--clean-cache")
rm -rf cache
esac
case $* in "--clean-workdir")
rm -rf workdir
esac
rm -rf logs
mkdir -p {workdir,logs,cache,built-pkgs}
setupBuildEnv 29 $ARCHITECTURE
setupPackages
compileAll
cd "$INIT_DIR"
mkdir -p "$INIT_DIR/cache/libc++_shared/files/usr/lib"
cp "$INIT_DIR/cache/android-ndk/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/$ARCHITECTURE-linux-android/libc++_shared.so" "$INIT_DIR/cache/libc++_shared/files/usr/lib"
./create-rat-pkg.sh "libc++_shared" "Android C++ Library" "" "$ARCHITECTURE" "1.0" "library" "$INIT_DIR/cache/libc++_shared" "$INIT_DIR/built-pkgs"