-
Notifications
You must be signed in to change notification settings - Fork 28
/
.cross_compile.sh
executable file
·62 lines (54 loc) · 2.06 KB
/
.cross_compile.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
set -e
BUILD_VERSION=$(cat version)
BUILD_DATE=$(date "+%F %T")
COMMIT_SHA1=$(git rev-parse HEAD)
TARGET_DIR="dist"
TARGET_NAME="mmh"
PLATFORMS="darwin/amd64 darwin/arm64 linux/386 linux/amd64 linux/arm linux/arm64"
COMMANDS="mcp mcs mcx mec mgo mping mtun"
rm -rf ${TARGET_DIR}
mkdir ${TARGET_DIR}
if [ "$1" == "install" ]; then
echo "install => ${GOPATH}/bin/mmh"
go build -o ${GOPATH}/bin/mmh -ldflags \
"-X 'github.com/mritd/mmh/cmd.Version=${BUILD_VERSION}' \
-X 'github.com/mritd/mmh/cmd.BuildDate=${BUILD_DATE}' \
-X 'github.com/mritd/mmh/cmd.CommitID=${COMMIT_SHA1}'"
for cmd in ${COMMANDS}; do
echo "install => ${GOPATH}/bin/${cmd}"
ln -sf ${GOPATH}/bin/mmh ${GOPATH}/bin/${cmd}
done
elif [ "$1" == "uninstall" ]; then
echo "remove => ${GOPATH}/bin/mmh"
rm -f ${GOPATH}/bin/mmh
for cmd in ${COMMANDS}; do
echo "remove => ${GOPATH}/bin/${cmd}"
rm -f ${GOPATH}/bin/${cmd}
done
elif [ "$1" == "completion" ]; then
for s in bash zsh fish powershell; do
mmh --completion ${s} > docs/completions/mmh.${s}
done
cat docs/completions/mmh.zsh > docs/completions/mmh.ohmyzsh
echo 'compdef _mmh mmh' >> docs/completions/mmh.ohmyzsh
for cmd in ${COMMANDS}; do
echo "compdef _mmh ${cmd}" >> docs/completions/mmh.ohmyzsh
done
else
for pl in ${PLATFORMS}; do
export GOOS=$(echo ${pl} | cut -d'/' -f1)
export GOARCH=$(echo ${pl} | cut -d'/' -f2)
export CGO_ENABLED=0
export TARGET=${TARGET_DIR}/${TARGET_NAME}_${GOOS}_${GOARCH}
if [ "${GOOS}" == "windows" ]; then
export TARGET=${TARGET_DIR}/${cmd}_${GOOS}_${GOARCH}.exe
fi
echo "build => ${TARGET}"
go build -trimpath -o ${TARGET} \
-ldflags "-X 'github.com/mritd/mmh/cmd.Version=${BUILD_VERSION}' \
-X 'github.com/mritd/mmh/cmd.BuildDate=${BUILD_DATE}' \
-X 'github.com/mritd/mmh/cmd.CommitID=${COMMIT_SHA1}' \
-w -s"
done
fi