Skip to content

Instantly share code, notes, and snippets.

@supersonictw
Last active February 29, 2020 10:32
Show Gist options
  • Save supersonictw/9b654536f80a7b1001283b790f0c677f to your computer and use it in GitHub Desktop.
Save supersonictw/9b654536f80a7b1001283b790f0c677f to your computer and use it in GitHub Desktop.
To auto-compile programs for every platforms Go supported
#!/bin/bash
# autocompile_golang.bash
# To auto-compile programs for every platforms Go supported
# (c)2020 Star Inc. (https://starinc.xyz)
# https://golang.org/doc/install/source#environment
GOOS_LIST=('android' 'darwin' 'linux')
GOARCH_LIST=('386' 'amd64' 'arm' 'arm64')
BUILD_LOG_LIST='.compile_log'
case $1 in
"build" )
echo '' > $BUILD_LOG_LIST
for GOOS in "${GOOS_LIST[@]}"
do
for GOARCH in "${GOARCH_LIST[@]}"
do
echo "[Building]" $3'_'$GOOS'_'$GOARCH
go build -o $3'_'$GOOS'_'$GOARCH $2
echo $3'_'$GOOS'_'$GOARCH >> $BUILD_LOG_LIST
done
done
;;
"clean" )
if [ -f $BUILD_LOG_LIST ]; then
exec < $BUILD_LOG_LIST
while read item
do
rm $item
done
rm $BUILD_LOG_LIST
else
echo "Nothing to be clean."
fi
;;
* )
echo "Usage: bash $0 <args>"
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment