forked from missinglink/pbf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
xcompile.sh
executable file
·126 lines (108 loc) · 4.04 KB
/
xcompile.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#!/bin/bash
set -euo pipefail
# note: works with golang 1.7 but not on 1.8!
# requires 'upx'
SKIP_COMPRESSION=true;
# ensure the compiler exits with status 0
function assert() {
if [[ $1 != 0 ]]; then
echo "one or more architectures failed to compile"
exit $1;
fi
}
# ensure the files were compiled to the correct architecture
declare -A matrix
matrix["build/pbf.darwin-x64"]="Mach-O 64-bit "
matrix["build/pbf.linux-arm"]="ELF 32-bit "
matrix["build/pbf.linux-x64"]="ELF 64-bit "
matrix["build/pbf.win32-x64"]="PE32 executable "
function checkFiles() {
for path in "${!matrix[@]}"
do
expected="$path: ${matrix[$path]}";
actual=$(file $path);
actualArr=($actual);
start=$(printf "%s " "${actualArr[@]:0:3}");
if [ "${start}" != "$expected" ]; then
echo "invalid file architecture: $path"
echo "expected: $expected"
echo "actual: $actual"
echo "start: $start"
exit 1
fi
done
}
echo "[compile] linux x64";
GOOS=linux GOARCH=amd64 go build -ldflags="-s -w" -gcflags=-trimpath=$GOPATH -asmflags=-trimpath=$GOPATH pbf.go;
assert $?;
chmod +x pbf;
mv pbf build/pbf.linux-x64;
$SKIP_COMPRESSION || upx --brute build/pbf.linux-x64;
echo "[compile] linux arm";
GOOS=linux GOARCH=arm go build -ldflags="-s -w" -gcflags=-trimpath=$GOPATH -asmflags=-trimpath=$GOPATH pbf.go;
echo $?;
assert $?;
chmod +x pbf;
mv pbf build/pbf.linux-arm;
$SKIP_COMPRESSION || upx --brute build/pbf.linux-arm;
# echo "[compile] linux i386";
# GOOS=linux GOARCH=386 go build -ldflags="-s -w" -gcflags=-trimpath=$GOPATH -asmflags=-trimpath=$GOPATH pbf.go;
# assert $?;
# chmod +x pbf;
# mv pbf build/pbf.linux-ia32;
# $SKIP_COMPRESSION || upx --brute build/pbf.linux-ia32;
echo "[compile] darwin x64";
GOOS=darwin GOARCH=amd64 go build -ldflags="-s -w" -gcflags=-trimpath=$GOPATH -asmflags=-trimpath=$GOPATH pbf.go;
assert $?;
chmod +x pbf;
mv pbf build/pbf.darwin-x64;
$SKIP_COMPRESSION || upx --brute build/pbf.darwin-x64;
# echo "[compile] darwin i386";
# GOOS=darwin GOARCH=386 go build -ldflags="-s -w" -gcflags=-trimpath=$GOPATH -asmflags=-trimpath=$GOPATH pbf.go;
# assert $?;
# chmod +x pbf;
# mv pbf build/pbf.darwin-ia32;
# $SKIP_COMPRESSION || upx --brute build/pbf.darwin-ia32;
echo "[compile] windows x64";
GOOS=windows GOARCH=386 go build -ldflags="-s -w" -gcflags=-trimpath=$GOPATH -asmflags=-trimpath=$GOPATH -o pbf.exe pbf.go;
assert $?;
chmod +x pbf.exe;
mv pbf.exe build/pbf.win32-x64;
$SKIP_COMPRESSION || upx --brute build/pbf.win32-x64;
# echo "[compile] windows i386";
# GOOS=windows GOARCH=386 go build -ldflags="-s -w" -gcflags=-trimpath=$GOPATH -asmflags=-trimpath=$GOPATH pbf.go;
# assert $?;
# chmod +x pbf.exe;
# mv pbf.exe build/pbf.win32-ia32;
# $SKIP_COMPRESSION || upx --brute build/pbf.win32-ia32;
# echo "[compile] freebsd arm";
# GOOS=freebsd GOARCH=arm go build -ldflags="-s -w" -gcflags=-trimpath=$GOPATH -asmflags=-trimpath=$GOPATH pbf.go;
# assert $?;
# chmod +x pbf;
# mv pbf build/pbf.freebsd-arm;
# $SKIP_COMPRESSION || upx --brute build/pbf.freebsd-arm;
# echo "[compile] freebsd x64";
# GOOS=freebsd GOARCH=amd64 go build -ldflags="-s -w" -gcflags=-trimpath=$GOPATH -asmflags=-trimpath=$GOPATH pbf.go;
# assert $?;
# chmod +x pbf;
# mv pbf build/pbf.freebsd-x64;
# $SKIP_COMPRESSION || upx --brute build/pbf.freebsd-x64;
# echo "[compile] freebsd i386";
# GOOS=freebsd GOARCH=386 go build -ldflags="-s -w" -gcflags=-trimpath=$GOPATH -asmflags=-trimpath=$GOPATH pbf.go;
# assert $?;
# chmod +x pbf;
# mv pbf build/pbf.freebsd-ia32;
# $SKIP_COMPRESSION || upx --brute build/pbf.freebsd-ia32;
# echo "[compile] openbsd i386";
# GOOS=openbsd GOARCH=386 go build -ldflags="-s -w" -gcflags=-trimpath=$GOPATH -asmflags=-trimpath=$GOPATH pbf.go;
# assert $?;
# chmod +x pbf;
# mv pbf build/pbf.openbsd-ia32;
# $SKIP_COMPRESSION || upx --brute build/pbf.openbsd-ia32;
# echo "[compile] openbsd x64";
# GOOS=openbsd GOARCH=amd64 go build -ldflags="-s -w" -gcflags=-trimpath=$GOPATH -asmflags=-trimpath=$GOPATH pbf.go;
# assert $?;
# chmod +x pbf;
# mv pbf build/pbf.openbsd-x64;
# $SKIP_COMPRESSION || upx --brute build/pbf.openbsd-x64;
checkFiles