Skip to content

Commit adfaa66

Browse files
committed
update buld makefile
1 parent 311df38 commit adfaa66

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
run:
22
go run *.go -o ./tmp
33
build:
4-
go build -o image-compressor
4+
go build -o image-compressor

build.sh

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/usr/bin/env bash
2+
package=$1
3+
4+
if [[ -z "$package" ]]; then
5+
echo "usage: $0 <package-name>"
6+
exit 1
7+
fi
8+
9+
package_name=$(basename "$package")
10+
11+
platforms=("linux/amd64" "linux/arm64")
12+
13+
for platform in "${platforms[@]}"; do
14+
IFS='/' read -ra platform_split <<< "$platform"
15+
GOOS=${platform_split[0]}
16+
GOARCH=${platform_split[1]}
17+
output_name="$package_name"-"$GOOS"-"$GOARCH"
18+
19+
if [ "$GOOS" = "windows" ]; then
20+
output_name+='.exe'
21+
fi
22+
echo "CGO_ENABLE=1 GOOS='$GOOS' GOARCH='$GOARCH' go build -o '$output_name' '$package'"
23+
env CGO_ENABLE=1 GOOS="$GOOS" GOARCH="$GOARCH" go build -o "$output_name" "$package"
24+
25+
if [ $? -ne 0 ]; then
26+
echo 'An error has occurred! Aborting the script execution...'
27+
exit 1
28+
fi
29+
done

0 commit comments

Comments
 (0)