forked from YouROK/TorrServer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild-all.sh
executable file
·125 lines (105 loc) · 4.13 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
#!/bin/bash
PLATFORMS=""
PLATFORMS="$PLATFORMS linux/amd64 linux/386"
PLATFORMS="$PLATFORMS windows/amd64 windows/386" # arm compilation not available for Windows
PLATFORMS="$PLATFORMS darwin/amd64" # amd64 only as of go1.5
PLATFORMS="$PLATFORMS freebsd/amd64"
PLATFORMS="$PLATFORMS linux/mips linux/mipsle linux/mips64 linux/mips64le" # experimental in go1.6
#PLATFORMS="$PLATFORMS linux/arm linux/arm64"
#PLATFORMS="$PLATFORMS linux/ppc64 linux/ppc64le aix/ppc"
# PLATFORMS="$PLATFORMS netbsd/amd64" # amd64 only as of go1.6
# PLATFORMS="$PLATFORMS openbsd/amd64" # amd64 only as of go1.6
# PLATFORMS="$PLATFORMS dragonfly/amd64" # amd64 only as of go1.5
# PLATFORMS="$PLATFORMS plan9/amd64 plan9/386" # as of go1.4
# PLATFORMS="$PLATFORMS solaris/amd64" # as of go1.3
PLATFORMS_ARM="linux"
##############################################################
# Shouldn't really need to modify anything below this line. #
##############################################################
type setopt >/dev/null 2>&1
export GOPATH="${PWD}"
GOBIN="/usr/local/go/bin/go"
go run build_web.go
go clean -i -r -x -cache
$GOBIN version
LDFLAGS="'-s -w'"
SCRIPT_NAME=$(basename "$0")
FAILURES=""
SOURCE_FILE="dist/TorrServer"
CURRENT_DIRECTORY=${PWD##*/}
OUTPUT=${SOURCE_FILE:-$CURRENT_DIRECTORY} # if no src file given, use current dir name
for PLATFORM in $PLATFORMS; do
GOOS=${PLATFORM%/*}
GOARCH=${PLATFORM#*/}
BIN_FILENAME="${OUTPUT}-${GOOS}-${GOARCH}"
if [[ "${GOOS}" == "windows" ]]; then BIN_FILENAME="${BIN_FILENAME}.exe"; fi
if [[ "${GOOS}" == "linux" ]]; then
CMD="CGO_ENABLED=0 GOOS=${GOOS} GOARCH=${GOARCH} ${GOBIN} build -ldflags=${LDFLAGS} -o ${BIN_FILENAME} main"
else
CMD="GOOS=${GOOS} GOARCH=${GOARCH} ${GOBIN} build -ldflags=${LDFLAGS} -o ${BIN_FILENAME} main"
fi
echo "${CMD}"
eval $CMD || FAILURES="${FAILURES} ${PLATFORM}"
done
# ARM builds
if [[ $PLATFORMS_ARM == *"linux"* ]]; then
CMD="GOOS=linux GOARCH=arm64 ${GOBIN} build -ldflags=${LDFLAGS} -o ${OUTPUT}-linux-arm64 main"
echo "${CMD}"
eval $CMD || FAILURES="${FAILURES} ${PLATFORM}"
fi
for GOOS in $PLATFORMS_ARM; do
GOARCH="arm"
# build for each ARM version
for GOARM in 7 6 5; do
BIN_FILENAME="${OUTPUT}-${GOOS}-${GOARCH}${GOARM}"
CMD="GOARM=${GOARM} GOOS=${GOOS} GOARCH=${GOARCH} ${GOBIN} build -ldflags=${LDFLAGS} -o ${BIN_FILENAME} main"
echo "${CMD}"
eval "${CMD}" || FAILURES="${FAILURES} ${GOOS}/${GOARCH}${GOARM}"
done
done
#####################################
### Android build section
#####
export CGO_ENABLED=1
export GOOS=android
# GOBIN="/usr/local/go116b/bin/go"
$GOBIN version
export NDK_TOOLCHAIN=$GOPATH/toolchain
export CC=$NDK_TOOLCHAIN/bin/armv7a-linux-androideabi21-clang
export CXX=$NDK_TOOLCHAIN/bin/armv7a-linux-androideabi21-clang++
export GOARCH=arm
export GOARM=7
BIN_FILENAME="dist/TorrServer-${GOOS}-${GOARCH}${GOARM}"
CMD="${GOBIN} build -ldflags=${LDFLAGS} -o ${BIN_FILENAME} main"
echo "${CMD}"
eval "${CMD}" || FAILURES="${FAILURES} ${GOOS}/${GOARCH}${GOARM}"
export CC=$NDK_TOOLCHAIN/bin/aarch64-linux-android21-clang
export CXX=$NDK_TOOLCHAIN/bin/aarch64-linux-android21-clang++
export GOARCH=arm64
export GOARM=""
BIN_FILENAME="dist/TorrServer-${GOOS}-${GOARCH}${GOARM}"
CMD="${GOBIN} build -ldflags=${LDFLAGS} -o ${BIN_FILENAME} main"
echo "${CMD}"
eval "${CMD}" || FAILURES="${FAILURES} ${GOOS}/${GOARCH}${GOARM}"
export CC=$NDK_TOOLCHAIN/bin/i686-linux-android21-clang
export CXX=$NDK_TOOLCHAIN/bin/i686-linux-android21-clang++
export GOARCH=386
export GOARM=""
BIN_FILENAME="dist/TorrServer-${GOOS}-${GOARCH}${GOARM}"
CMD="${GOBIN} build -ldflags=${LDFLAGS} -o ${BIN_FILENAME} main"
echo "${CMD}"
eval "${CMD}" || FAILURES="${FAILURES} ${GOOS}/${GOARCH}${GOARM}"
export CC=$NDK_TOOLCHAIN/bin/x86_64-linux-android21-clang
export CXX=$NDK_TOOLCHAIN/bin/x86_64-linux-android21-clang++
export GOARCH=amd64
export GOARM=""
BIN_FILENAME="dist/TorrServer-${GOOS}-${GOARCH}${GOARM}"
CMD="${GOBIN} build -ldflags=${LDFLAGS} -o ${BIN_FILENAME} main"
echo "${CMD}"
eval "${CMD}" || FAILURES="${FAILURES} ${GOOS}/${GOARCH}${GOARM}"
# eval errors
if [[ "${FAILURES}" != "" ]]; then
echo ""
echo "${SCRIPT_NAME} failed on: ${FAILURES}"
exit 1
fi