-
Notifications
You must be signed in to change notification settings - Fork 159
/
build.sh
61 lines (52 loc) · 1.71 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
#!/usr/bin/env bash
NOW=$(date '+%Y%m%d-%H%M%S')
BASE=$(dirname $(readlink -f "$0"))
TMP=$BASE/tmp
CODENAME="user"
BUILDNAME=$NOW
UPX=$BASE/upx
cleanup () { rm -rf $TMP; }
trap cleanup INT TERM ERR
build_v2() {
cd $BASE/v2ray-core
echo ">>> Update source code name ..."
sed -i "s/^[ \t]\+codename.\+$/\tcodename = \"${CODENAME}\"/;s/^[ \t]\+build.\+$/\tbuild = \"${BUILDNAME}\"/;" core.go
echo ">>> Compile v2ray ..."
cd main
if [[ $GOARCH == "mips" || $GOARCH == "mipsle" ]];then
env CGO_ENABLED=0 go build -o $TMP/v2ray -ldflags "-s -w"
env CGO_ENABLED=0 GOMIPS=softfloat go build -o $TMP/v2ray_softfloat -ldflags "-s -w"
elif [[ $GOOS == "windows" ]];then
env CGO_ENABLED=0 go build -o $TMP/v2ray.exe -ldflags "-s -w"
env CGO_ENABLED=0 go build -o $TMP/wv2ray.exe -ldflags "-s -w -H windowsgui"
elif [[ $GOARCH == "armv5" ]];then
env CGO_ENABLED=0 GOARCH=arm GOARM=5 go build -o $TMP/v2ray -ldflags "-s -w"
elif [[ $GOARCH == "armv6" ]];then
env CGO_ENABLED=0 GOARCH=arm GOARM=6 go build -o $TMP/v2ray -ldflags "-s -w"
elif [[ $GOARCH == "armv7" ]];then
env CGO_ENABLED=0 GOARCH=arm GOARM=7 go build -o $TMP/v2ray -ldflags "-s -w"
elif [[ $GOARCH == "arm64" ]];then
env CGO_ENABLED=0 GOARCH=arm64 go build -o $TMP/v2ray -ldflags "-s -w"
else
env CGO_ENABLED=0 go build -o $TMP/v2ray -ldflags "-s -w"
fi
cd ..
git checkout -- core.go
}
packzip() {
echo ">>> Generating zip package"
cd $TMP
$UPX --best --lzma *
tar -czvf $BASE/bin/v2ray-${GOOS}-${GOARCH}.tar.gz *
cd $BASE
}
GOOS=$1
GOARCH=$2
export GOOS GOARCH
export PATH=$PATH:/usr/local/go/bin
export GOROOT=/usr/local/go
go version
echo "Build ARGS: GOOS=${GOOS} GOARCH=${GOARCH}"
build_v2
packzip
cleanup