-
-
Notifications
You must be signed in to change notification settings - Fork 54
/
builder.sh
159 lines (127 loc) · 4.64 KB
/
builder.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
#!/bin/bash
set -e
# Initialize and configure
export MACOSX_DEPLOYMENT_TARGET="10.15"
# Remove unnecessary directories if running in GitHub Actions
if [ -n "$GITHUB_ACTIONS" ]; then
for dir in "nekoray" "v2ray-core" "sing-box-extra" "sing-box" "libneko" "Xray-core" "sing-quic" ; do
[ -d "$dir" ] && rm -rf "$dir"
done
else
if ! rmdir nekoray v2ray-core sing-box-extra sing-box libneko Xray-core sing-quic 2> /dev/null; then
echo "clean and ready..."
fi
fi
# Clone or update repositories with a function
clone_or_update_repo() {
local repo="$1"
local url="$2"
if [ -d "$repo" ]; then
git -C "$repo" reset --hard
git -C "$repo" fetch --all --tags --prune
else
git clone --recursive "$url" "$repo"
fi
if [ -n "$(git -C "$repo" tag --list)" ]; then
git -C "$repo" checkout "$(git -C "$repo" describe --tags $(git -C "$repo" rev-list --tags --max-count=1))"
fi
}
# Array to store repository URLs
repos=("nekoray=https://github.com/MatsuriDayo/nekoray.git"
"v2ray-core=https://github.com/MatsuriDayo/v2ray-core.git")
# Clone or update repositories using the function
for repo_info in "${repos[@]}"; do
repo=${repo_info%%=*}
url=${repo_info#*=}
clone_or_update_repo "$repo" "$url"
done
# Check and install dependencies if not already installed
command -v "brew" >/dev/null 2>&1 || {
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
}
check_and_install() {
local cmd="$1"
local package="$2"
command -v "$cmd" >/dev/null 2>&1 || {
echo "$cmd could not be found, installing $package"
brew install "$package"
}
}
# Array to store dependencies
dependencies=("golang" "cmake" "ninja" "curl" "qt@5")
# Check and install dependencies using the function
for dep in "${dependencies[@]}"; do
check_and_install "$dep" "$dep"
done
# installation path of qt@5 install by brew
info=$(brew info qt@5)
installation_path=$(echo "$info" | grep "Cellar/qt@5" | awk -F ' ' '{print $1}')
# Set environment variables for Qt5 and macdeployqt path for macOS
export PATH="$installation_path/bin:$PATH"
export LDFLAGS="-L$installation_path/lib"
export CPPFLAGS="-I$installation_path/include"
export QT_QPA_PLATFORM_PLUGIN_PATH="$installation_path/plugins"
# export PKG_CONFIG_PATH="/usr/local/opt/qt@5/lib/pkgconfig"
nRoot=$(pwd)
nPath=$(pwd)/nekoray
# Clean build directory or create it if it does not exist
if [ -d "$nPath/build" ]; then
read -p "Do you want to clean 'build' and 'libs/deps' directories? [y/n] " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
exit 1
fi
rm -rf "$nPath/libs/deps" "$nPath/build"
fi
mkdir -p "$nPath/build"
# Get and build dependencies
cd $nPath
bash libs/get_source.sh
bash libs/build_deps_all.sh
# Build nekoray using CMake and Ninja
cd "$nPath/build"
cmake -GNinja -DCMAKE_PREFIX_PATH=$installation_path -DCMAKE_BUILD_TYPE=Release -DNKR_PACKAGE_MACOS=1 ..
ninja
cd "$nPath"
nApp="$nPath/build/nekoray.app"
# Deploy frameworks using macdeployqt
macdeployqt "$nApp" -verbose=3
# Download data files for both amd64 and arm64
curl -fLso "$nApp/Contents/MacOS/geoip.dat" "https://github.com/Loyalsoldier/v2ray-rules-dat/releases/latest/download/geoip.dat"
curl -fLso "$nApp/Contents/MacOS/geosite.dat" "https://github.com/v2fly/domain-list-community/releases/latest/download/dlc.dat"
curl -fLso "$nApp/Contents/MacOS/geoip.db" "https://github.com/SagerNet/sing-geoip/releases/latest/download/geoip.db"
curl -fLso "$nApp/Contents/MacOS/geosite.db" "https://github.com/SagerNet/sing-geosite/releases/latest/download/geosite.db"
# Copy fa_IR.qm and zh_CN.qm to nekoray.app/Contents/MacOS
for file in "fa_IR.qm" "zh_CN.qm" "ru_RU.qm"; do
cp "$nPath/build/$file" "$nApp/Contents/MacOS"
done
# Remove updater shortcut if exists
cd "$nApp/Contents/MacOS/"
[ -f "updater" ] && rm updater
cd "$nPath"
# Build nekoray for both amd64 and arm64
for arch in "amd64" "arm64"; do
rm -rf "$nPath/build/nekoray_$arch.app"
cp -r "$nApp" "$nPath/build/nekoray_$arch.app"
done
rm -rf "$nApp"
neko_common="github.com/matsuridayo/libneko/neko_common"
cd "$nRoot/v2ray-core"
version_v2ray=$(git log --pretty=format:'%h' -n 1)
cd "$nPath"
version_standalone="nekoray-"$(cat "$nPath/nekoray_version.txt")
# Build nekobox_core and nekoray_core for both amd64 and arm64
for arch in "amd64" "arm64"; do
GOOS="darwin" GOARCH=$arch bash libs/build_go.sh
cp -a "$nPath/deployment/macos-$arch/." "$nPath/build/nekoray_$arch.app/Contents/MacOS/"
done
# Zip nekoray by arch
for arch in "amd64" "arm64"; do
TEMP_PATH=$(pwd)
cd "$nPath/build"
zip -r "nekoray_$arch.zip" "nekoray_$arch.app"
cd "$TEMP_PATH"
done
echo "Build finished and output files are in $nPath/build"
cd "$nPath"
open "$nPath/build"