forked from starifly/NekoBoxForAndroid
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmieru.sh
More file actions
executable file
·75 lines (64 loc) · 2.4 KB
/
Copy pathmieru.sh
File metadata and controls
executable file
·75 lines (64 loc) · 2.4 KB
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
#!/bin/bash
# Build the Mieru client binary for all Android ABIs and install them as
# bundled native executables (app/executableSo/<abi>/libmieru.so).
#
# This lets NekoBox run Mieru profiles without the separate external plugin
# (moe.matsuri.exe.mieru). PluginManager.initNativeInternal resolves
# "mieru-plugin" -> libmieru.so from nativeLibraryDir.
#
# Usage: ./run lib mieru
set -e
set -o pipefail
source "buildScript/init/env.sh"
if [ -z "$ANDROID_NDK_HOME" ]; then
echo "Error: ANDROID_NDK_HOME is not set (NDK required to cross-compile Mieru)." >&2
exit 1
fi
# Mieru release tag to build from source.
MIERU_VERSION="${MIERU_VERSION:-v3.34.0}"
DEPS="$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64/bin"
# macOS NDK host dirs are darwin-x86_64 / darwin-arm64; fall back if linux is absent.
if [ ! -d "$DEPS" ]; then
DEPS="$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/darwin-x86_64/bin"
fi
if [ ! -d "$DEPS" ]; then
DEPS="$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/darwin-arm64/bin"
fi
if [ ! -d "$DEPS" ]; then
echo "Error: NDK LLVM toolchain not found under $ANDROID_NDK_HOME (unsupported host or NDK layout)." >&2
exit 1
fi
WORK="$(pwd)/.mieru-build"
OUT="$(pwd)/app/executableSo"
# Fetch source (shallow clone at the pinned tag). Re-clone fresh if the existing
# checkout is missing or its git operations fail (e.g. corrupted by a prior build).
need_clone=1
if [ -d "$WORK/.git" ]; then
if git -C "$WORK" fetch --depth 1 origin "refs/tags/$MIERU_VERSION" \
&& git -C "$WORK" checkout -q FETCH_HEAD; then
need_clone=0
else
echo ">> existing $WORK is unusable; re-cloning"
fi
fi
if [ "$need_clone" -eq 1 ]; then
rm -rf "$WORK"
git clone --depth 1 --branch "$MIERU_VERSION" https://github.com/enfein/mieru.git "$WORK"
fi
pushd "$WORK" >/dev/null
build_abi() {
local abi="$1" goarch="$2" cc="$3" goarm="$4"
echo ">> building libmieru.so for $abi"
mkdir -p "$OUT/$abi"
env GOOS=android GOARCH="$goarch" ${goarm:+GOARM=$goarm} CGO_ENABLED=1 \
CC="$DEPS/$cc" \
go build -trimpath -ldflags='-s -w' \
-o "$OUT/$abi/libmieru.so" ./cmd/mieru
}
build_abi "arm64-v8a" "arm64" "aarch64-linux-android21-clang"
build_abi "armeabi-v7a" "arm" "armv7a-linux-androideabi21-clang" "7"
build_abi "x86" "386" "i686-linux-android21-clang"
build_abi "x86_64" "amd64" "x86_64-linux-android21-clang"
popd >/dev/null
echo ">> installed Mieru binaries:"
ls -la "$OUT"/*/libmieru.so