-
-
Notifications
You must be signed in to change notification settings - Fork 36
/
compile.sh
executable file
·77 lines (67 loc) · 2.61 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
73
74
75
76
77
#!/bin/bash
# note: you will need to follow the guide here to install the tools required
# to cross-compile for different architectures on your host machine.
# http://dave.cheney.net/2015/08/22/cross-compilation-with-go-1-5
# ensure the compiler exits with status 0
function assert() {
if [[ $1 != 0 ]]; then
echo "one or more architectures failed to compile"
exit $1;
fi
}
# check the reported file class matches what's expected
function check() {
actual=$(file -b ${1});
if [[ "${actual}" != "${2}"* ]]; then
echo "invalid file architecture: ${1}"
echo "expected: ${2}"
echo "actual: ${actual}"
echo "-${actual}-${2}-"
exit 1
fi
}
# if the 'UPX' bindary packer is available, use it
# https://upx.github.io/
function compress() {
[ -x "$(command -v upx)" ] && upx "${1}"
}
# ensure build directory exists
rm -rf build; mkdir -p build
echo "[compile] linux arm64";
env GOOS=linux GOARCH=arm64 go build -ldflags="-s -w" -gcflags=-trimpath="${GOPATH}" -asmflags=-trimpath="${GOPATH}";
assert $?;
chmod +x pbf2json;
mv pbf2json build/pbf2json.linux-arm64;
check 'build/pbf2json.linux-arm64' 'ELF 64-bit LSB executable';
compress 'build/pbf2json.linux-arm64';
echo "[compile] linux x64";
env GOOS=linux GOARCH=amd64 go build -ldflags="-s -w" -gcflags=-trimpath="${GOPATH}" -asmflags=-trimpath="${GOPATH}";
assert $?;
chmod +x pbf2json;
mv pbf2json build/pbf2json.linux-x64;
check 'build/pbf2json.linux-x64' 'ELF 64-bit LSB executable';
compress 'build/pbf2json.linux-x64';
echo "[compile] darwin x64";
env GOOS=darwin GOARCH=amd64 go build -ldflags="-s -w" -gcflags=-trimpath="${GOPATH}" -asmflags=-trimpath="${GOPATH}";
assert $?;
chmod +x pbf2json;
mv pbf2json build/pbf2json.darwin-x64;
check 'build/pbf2json.darwin-x64' 'Mach-O 64-bit';
# UPX disabled due to https://github.com/upx/upx/issues/187
# compress 'build/pbf2json.darwin-x64';
echo "[compile] darwin arm64";
env GOOS=darwin GOARCH=arm64 go build -ldflags="-s -w" -gcflags=-trimpath="${GOPATH}" -asmflags=-trimpath="${GOPATH}";
assert $?;
chmod +x pbf2json;
mv pbf2json build/pbf2json.darwin-arm64;
check 'build/pbf2json.darwin-arm64' 'Mach-O 64-bit';
# UPX disabled due to https://github.com/upx/upx/issues/187
# note: this is untested, assumed to be the same bug as above
# compress 'build/pbf2json.darwin-arm64';
echo "[compile] windows x64";
env GOOS=windows GOARCH=amd64 go build -ldflags="-s -w" -gcflags=-trimpath=${GOPATH} -asmflags=-trimpath=${GOPATH} -o pbf2json.exe;
assert $?;
chmod +x pbf2json.exe;
mv pbf2json.exe build/pbf2json.win32-x64;
check 'build/pbf2json.win32-x64' 'PE32+ executable (console) x86-64';
compress 'build/pbf2json.win32-x64';