-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcompile.sh
executable file
·72 lines (58 loc) · 1.41 KB
/
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
62
63
64
65
66
67
68
69
70
71
72
#!/bin/bash
SYSTEMS=( windows linux freebsd )
ARCHS=( 386 amd64 amd64p32 arm arm64 ppc ppc64 )
function usage() {
echo "Usage: ${0##*/} [ -h|--help ] [ -t|--target <system> ] [ -a|--arch <arch> ]"
echo ""
echo " Valid systems:"
for i in "${SYSTEMS[@]}"; do
echo " * ${i}"
done
echo ""
echo " Valid architectures:"
for i in "${ARCHS[@]}"; do
echo " * ${i}"
done
echo ""
exit 1
}
options=$(getopt -n "${0##*/}" -o "ht:a:" -l "help,target:,arch:" -- "$@")
[ $? -eq 0 ] || usage
eval set -- "$options"
MAKE_TARGET="all"
while true; do
case $1 in
-t|--target)
shift
REGEX=$(echo "${SYSTEMS[@]}" | sed 's/[[:space:]]/|/g')
[[ ! "$1" =~ ^($REGEX)$ ]] && {
echo "Incorrect system '$1' provided"
usage
}
export GOOS=$1
;;
-a|--arch)
shift
REGEX=$(echo "${ARCHS[@]}" | sed 's/[[:space:]]/|/g')
[[ ! "$1" =~ ^($REGEX)$ ]] && {
echo "Incorrect architecture '$1' provided"
usage
}
export GOARCH=$1
;;
-h|--help) usage ;;
--) shift
break
;;
esac
shift
done
MESSAGE=""
if [ ! -z "${GOOS}" ]; then
MESSAGE="[\e[34m::\e[0m] Crosscompiling for: ${GOOS}"
fi
if [ ! -z "${GOARCH}" ]; then
MESSAGE="${MESSAGE} (${GOARCH})"
fi
[ ! -z "${MESSAGE}" ] && echo -e "" $MESSAGE
make -B ${MAKE_TARGET}