-
Notifications
You must be signed in to change notification settings - Fork 4
/
build-all.sh
executable file
·114 lines (98 loc) · 2.53 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
#!/bin/bash
PLATFORMS=(
'linux/amd64'
'darwin/arm64'
'linux/arm64'
'linux/arm7'
'linux/arm5'
'linux/386'
'windows/amd64'
'windows/386'
'darwin/amd64'
'freebsd/amd64'
'linux/mips'
'linux/mipsle'
'linux/mips64'
'linux/mips64le'
)
type setopt >/dev/null 2>&1
set_goarm() {
if [[ "$1" =~ arm([5,7]) ]]; then
GOARCH="arm"
GOARM="${BASH_REMATCH[1]}"
GO_ARM="GOARM=${GOARM}"
else
GOARM=""
GO_ARM=""
fi
}
# use softfloat for mips builds
set_gomips() {
if [[ "$1" =~ mips ]]; then
if [[ "$1" =~ mips(64) ]]; then MIPS64="${BASH_REMATCH[1]}"; fi
GO_MIPS="GOMIPS${MIPS64}=softfloat"
else
GO_MIPS=""
fi
}
GOBIN="go"
$GOBIN version
LDFLAGS="'-s -w'"
FAILURES=""
ROOT=${PWD}
OUTPUT="${ROOT}/dist/numParser"
#### Build server
echo "Build"
BUILD_FLAGS="-ldflags=${LDFLAGS}"
#####################################
### X86 build section
#####
for PLATFORM in "${PLATFORMS[@]}"; do
GOOS=${PLATFORM%/*}
GOARCH=${PLATFORM#*/}
set_goarm "$GOARCH"
set_gomips "$GOARCH"
BIN_FILENAME="${OUTPUT}_${GOOS}_${GOARCH}${GOARM}"
if [[ "${GOOS}" == "windows" ]]; then BIN_FILENAME="${BIN_FILENAME}.exe"; fi
CMD="GOOS=${GOOS} GOARCH=${GOARCH} ${GO_ARM} ${GO_MIPS} ${GOBIN} build ${BUILD_FLAGS} -o ${BIN_FILENAME} ./cmd"
echo "${CMD}"
eval "$CMD" || FAILURES="${FAILURES} ${GOOS}/${GOARCH}${GOARM}"
# CMD="../upx -q ${BIN_FILENAME}"; # upx --brute produce much smaller binaries
# echo "compress with ${CMD}"
# eval "$CMD"
done
#####################################
### Android build section
#####
declare -a COMPILERS=(
"arm7:armv7a-linux-androideabi21-clang"
"arm64:aarch64-linux-android21-clang"
"386:i686-linux-android21-clang"
"amd64:x86_64-linux-android21-clang"
)
export NDK_TOOLCHAIN=/Users/yourok/Library/Android/sdk/ndk/23.1.7779620/toolchains/llvm/prebuilt/darwin-x86_64
GOOS=android
for V in "${COMPILERS[@]}"; do
GOARCH=${V%:*}
COMPILER=${V#*:}
export CC="$NDK_TOOLCHAIN/bin/$COMPILER"
export CXX="$NDK_TOOLCHAIN/bin/$COMPILER++"
set_goarm "$GOARCH"
BIN_FILENAME="${OUTPUT}_${GOOS}_${GOARCH}${GOARM}"
CMD="GOOS=${GOOS} GOARCH=${GOARCH} ${GO_ARM} CGO_ENABLED=1 ${GOBIN} build ${BUILD_FLAGS} -o ${BIN_FILENAME} ./cmd"
echo "${CMD}"
eval "${CMD}" || FAILURES="${FAILURES} ${GOOS}/${GOARCH}${GOARM}"
# CMD="../upx -q ${BIN_FILENAME}"; # upx --brute produce much smaller binaries
# echo "compress with ${CMD}"
# eval "$CMD"
done
# eval errors
if [[ "${FAILURES}" != "" ]]; then
echo ""
echo "failed on: ${FAILURES}"
exit 1
fi
rm -rf tmp
mkdir tmp
cp dist/* tmp/
cp -r public tmp/