-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild.sh
More file actions
75 lines (66 loc) · 2.51 KB
/
Copy pathbuild.sh
File metadata and controls
75 lines (66 loc) · 2.51 KB
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
#!/bin/bash
PLATFORMS="darwin/amd64 darwin/arm64" # amd64 is for intel, arm64 is for apple silicon chips.
PLATFORMS="$PLATFORMS windows/amd64 windows/386" # arm compilation not available for Windows
PLATFORMS="$PLATFORMS linux/amd64 linux/386"
# ARMBUILDS lists the platforms that are currently supported. From this list
# we generate the following architectures:
#
# ARM64 (aka ARMv8) <- only supported on linux and darwin builds (go1.6)
# ARMv7
# ARMv6
# ARMv5
#
# Some words of caution from the master:
#
# @dfc: you'll have to use gomobile to build for darwin/arm64 [and others]
# @dfc: that target expects that you're bulding for a mobile phone
# @dfc: iphone 5 and below, ARMv7, iphone 3 and below ARMv6, iphone 5s and above arm64
#
PLATFORMS_ARM="linux"
#PLATFORMS_ARM="linux freebsd netbsd"
##############################################################
# Shouldn't really need to modify anything below this line. #
##############################################################
type setopt >/dev/null 2>&1
SCRIPT_NAME=`basename "$0"`
FAILURES=""
SOURCE_FILE=`echo $@ | sed 's/\.go//'`
CURRENT_DIRECTORY=${PWD##*/}
OUTPUT=${SOURCE_FILE:-$CURRENT_DIRECTORY} # if no src file given, use current dir name
#prepare version.go
# These are the values we want to pass for VERSION and BUILD
# git tag 1.0.1
VERSION=$(git describe --tags)
BUILD=$(date '+%Y%m%d%H%M')
LDFLAGS="-ldflags \"-w -s -X dashboard-sanitizer/config.Version=${VERSION} -X dashboard-sanitizer/config.Build=${BUILD}\""
for PLATFORM in $PLATFORMS; do
GOOS=${PLATFORM%/*}
GOARCH=${PLATFORM#*/}
BIN_FILENAME="binaries/${GOOS}-${GOARCH}/${OUTPUT}"
if [[ "${GOOS}" == "windows" ]]; then BIN_FILENAME="${BIN_FILENAME}.exe"; fi
CMD="GOOS=${GOOS} GOARCH=${GOARCH} go build ${LDFLAGS} -o ${BIN_FILENAME} $@"
echo "${CMD}"
eval $CMD || FAILURES="${FAILURES} ${PLATFORM}"
done
# ARM builds
if [[ $PLATFORMS_ARM == *"linux"* ]]; then
CMD="GOOS=linux GOARCH=arm64 go build ${LDFLAGS} -o binaries/linux-arm64/${OUTPUT} $@"
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="binaries/${GOOS}-${GOARCH}${GOARM}/${OUTPUT}"
CMD="GOARM=${GOARM} GOOS=${GOOS} GOARCH=${GOARCH} go build ${LDFLAGS} -o ${BIN_FILENAME} $@"
echo "${CMD}"
eval "${CMD}" || FAILURES="${FAILURES} ${GOOS}/${GOARCH}${GOARM}"
done
done
# eval errors
if [[ "${FAILURES}" != "" ]]; then
echo ""
echo "${SCRIPT_NAME} failed on: ${FAILURES}"
exit 1
fi