-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sh
executable file
·62 lines (51 loc) · 1.29 KB
/
build.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
#!/bin/bash
bin_name="gedis"
bin_path="bin"
version="2.3.0"
log_dir=$bin_path/logs
flags=(-tags netgo -ldflags '-extldflags "-static" -s -w')
declare -a os=("linux" "darwin")
declare -a arch=("amd64" "arm64" "arm")
declare -a incompatible=("darwin-armv7")
if [ -d "$bin_path" ]; then
rm -rf "$bin_path"
fi
mkdir "$bin_path"
while [[ $# -gt 0 ]]; do
key="$1"
case $key in
-race)
flags+=(-race)
shift
;;
*)
echo "Unrecognized option: $key"
shift
;;
esac
done
for os_target in "${os[@]}"
do
for arch_target in "${arch[@]}"
do
if [[ " ${incompatible[*]} " == *"$os_target-$arch_target"* ]]; then
continue
fi
export GOOS=$os_target
export GOARCH=$arch_target
output_path="$bin_path/$bin_name-$version-$os_target-$arch_target"
go build "${flags[@]}" -o "$output_path/$bin_name"
if [ $? -eq 0 ]; then
echo "Build successful for $os_target-$arch_target"
cp LICENSE.md "$output_path/LICENSE.md"
if [ -n "$(find "$output_path" -type f)" ]; then
tar -czf "$output_path.tar.gz" $output_path
echo "Compressed $os_target-$arch_target"
else
echo "Output folder is empty. Skipping compression."
fi
else
echo "Build failed for $os_target-$arch_target"
fi
done
done