Created
December 29, 2016 02:44
-
-
Save intermernet/2e60c9179961facad9e2f87740ae0877 to your computer and use it in GitHub Desktop.
Cross compile Go project and create archive files for executables
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Set project and executable name | |
PROJ="github.com/Intermernet/ssws" | |
NAME=${PROJ##*/} | |
# Set OS and Architecture lists | |
OSLIST="windows linux darwin" | |
ARCHLIST="x86 amd64" | |
# Set Base, Working and Output directories | |
BASEDIR="/home/mh" | |
OUT="${BASEDIR}/out" | |
WORK="${BASEDIR}/work" | |
# Clean up old build artifacts | |
if [ -d ${OUT} ] | |
then | |
rm ${OUT}/* | |
rmdir ${OUT} | |
fi | |
# Create Work and Output directories | |
mkdir ${OUT} | |
mkdir ${WORK} | |
cd ${WORK} | |
for OS in ${OSLIST} | |
do | |
for ARCH in ${ARCHLIST} | |
do | |
if [ ${OS} == "windows" ] # Windows specific values | |
then | |
EXT=".exe" | |
ZIP="zip" | |
ZEXT=".zip" | |
else # All other OS types | |
EXT="" | |
ZIP="tar cfz" | |
ZEXT=".tgz" | |
fi | |
# Build the executable | |
(export GOOS=${OS}; export GARCH=${ARCH}; go build -o ${WORK}/${NAME}${EXT} ${PROJ}) | |
# Create the archive | |
$ZIP ${OUT}/${NAME}_${OS}_${ARCH}${ZEXT} * | |
# Delete the executable | |
rm ${WORK}/* | |
done | |
done | |
# Remove Work directory | |
rmdir ${WORK} | |
# List output files | |
ls -l ${OUT} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment