forked from hzyitc/AmlImg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
buildAllPlatforms.sh
41 lines (34 loc) · 1.02 KB
/
buildAllPlatforms.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
#!/bin/bash
PROGRAM="AmlImg"
CLI="./"
OUTPUT="bin/"
LDFLAGS="-s -w"
ver="$(git describe --tags --match "v*" --dirty="" 2>/dev/null || git log -1 --pretty=format:"v0.0.0-%h" 2>/dev/null || echo "v0.0.0")"
[ -n "$(git status --porcelain |& grep -Ev '^\?\?')" ] && ver="$ver-$(date +"%Y%m%d-%H%M%S")"
LDFLAGS="$LDFLAGS -X main.version=$ver"
mkdir -p "${OUTPUT}"
rm -f "${OUTPUT}/${PROGRAM}_"*
platforms=(
linux/386
linux/amd64
linux/arm
linux/arm64
linux/mips/softfloat
linux/mips64
linux/mips64le
linux/mipsle/softfloat
windows/386
windows/amd64
windows/arm
)
# platforms=($(go tool dist list))
for i in "${platforms[@]}"; do
os="$(echo "$i" | awk -F/ '{print $1}')"
arch="$(echo "$i" | awk -F/ '{print $2}')"
mips="$(echo "$i" | awk -F/ '{print $3}')"
[ "$os" == "windows" ] && ext="exe"
filename="${OUTPUT}/${PROGRAM}_${ver}_${os}_${arch}${ext:+.$ext}"
echo "build $filename for $i"
CGO_ENABLED=0 GOOS="${os}" GOARCH="${arch}" GOMIPS="${mips}" \
go build -trimpath -ldflags "$LDFLAGS" -o "${filename}" ${CLI}
done