#!/bin/sh # Build the mihomo core with the kit's patches (tools/core/*.patch) for the # architectures router/mihomo-kit.sh core_update knows. Needs git and Go. # tools/core/build.sh v1.19.32 ts1 -> dist/mihomo-linux--v1.19.32-ts1.gz # Upload the .gz files to a release and set MIHOMO_VERSION / MIHOMO_BASE in # router/mihomo-kit.sh. Drop this once upstream has the fixes. set -eu tag=${1:?usage: tools/core/build.sh } suffix=${2:?usage: tools/core/build.sh } version=$tag-$suffix cd "$(dirname "$0")" here=$(pwd) work=$here/work dist=$here/dist rm -rf "$work" mkdir -p "$work" "$dist" git clone -q --depth 1 --branch "$tag" https://github.com/MetaCubeX/mihomo.git "$work/mihomo" cd "$work/mihomo" for p in "$here"/*.patch; do git apply "$p" echo "applied ${p##*/}" done buildtime=$(date -u '+%a %b %d %H:%M:%S UTC %Y') # for t in arm64:arm64: amd64:amd64: armv7:arm:GOARM=7 mips-softfloat:mips:GOMIPS=softfloat \ mipsle-softfloat:mipsle:GOMIPS=softfloat; do name=${t%%:*} rest=${t#*:} goarch=${rest%%:*} extra=${rest#*:} out=$dist/mihomo-linux-$name-$version # same flags as the upstream Makefile env CGO_ENABLED=0 GOOS=linux GOARCH="$goarch" $extra go build -tags with_gvisor -trimpath \ -ldflags "-X 'github.com/metacubex/mihomo/constant.Version=$version' \ -X 'github.com/metacubex/mihomo/constant.BuildTime=$buildtime' -w -s -buildid=" \ -o "$out" . gzip -9 -f "$out" echo "built ${out##*/}.gz" done rm -rf "$work"