-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
180 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
#!/bin/sh | ||
|
||
set -e | ||
|
||
# to cross-compile: | ||
# https://blog.filippo.io/easy-windows-and-linux-cross-compilers-for-macos/ | ||
# brew install FiloSottile/musl-cross/musl-cross | ||
# brew install mingw-w64 | ||
|
||
# to use some windows libs: | ||
# export GOOS=windows; go get "github.com/lxn/win" | ||
# export GOOS=windows; go get "gopkg.in/Knetic/govaluate.v3" | ||
# export GOOS=windows; go get -u -v "golang.org/x/crypto/..." (with the ...) | ||
|
||
BUILD="$(uname -n)/$(uname -r)/$(date +'%Y-%m-%d/%T')" | ||
|
||
OSARCH="$(uname -m)" | ||
|
||
#LDFLAGS="$LDFLAGS -linkmode=internal" | ||
|
||
#GCFLAGS="$GCFLAGS -l" | ||
|
||
#LOOPVAR=S | ||
if [[ $LOOPVAR == "S" ]]; then | ||
GCFLAGS="$GCFLAGS -d=loopvar=2" | ||
export GOEXPERIMENT=loopvar | ||
fi | ||
|
||
echo "name = [$1]" | ||
echo "goos = [$2]" | ||
echo "goarch = [$3]" | ||
echo "os = [$4]" | ||
echo "arch = [$5]" | ||
echo "extension = [$6]" | ||
echo "version = [$7]" | ||
echo "output = [$8]" | ||
|
||
export GOOS="$2" | ||
export GOARCH="$3" | ||
echo "--> will build $GOOS-$GOARCH" | ||
FILE="/tmp/$1$4$5$7$6" | ||
|
||
if [[ "$GOOS" == "windows" ]]; then | ||
export CC="x86_64-w64-mingw32-gcc" | ||
elif [[ "$GOARCH" == "amd64" && "$OSARCH" == "arm64" ]]; then | ||
export CC="clang -arch x86_64 -mmacosx-version-min=10.14" | ||
fi | ||
|
||
#CGO_ENABLED=$_CGO_ENABLED \ | ||
#GOEXPERIMENT="$_GOEXPERIMENT" \ | ||
|
||
# move the .syso out of the way for non-windows builds | ||
SYSO=resource.syso | ||
[ ! -f $SYSO ] || mv -vf $SYSO ../$SYSO | ||
if [[ "$GOOS" == "windows" ]]; then | ||
[ ! -f ../$SYSO ] || cp -v ../$SYSO $SYSO | ||
fi | ||
# a .syso file will cause an 'ld: warning' | ||
go build \ | ||
-ldflags "-s -w $LDFLAGS -X main.build=$BUILD" \ | ||
-gcflags=all="$GCFLAGS" \ | ||
-o "$FILE" | ||
|
||
if [[ "$COMPRESS" == "upx" ]]; then | ||
upx --lzma "$FILE" || echo "Could not run UPX, skipping" | ||
else | ||
echo "Not compressing" | ||
fi | ||
|
||
mkdir -p "$8" | ||
mv -f "$FILE" "$8/" | ||
echo "<-- did build $GOOS-$GOARCH" |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
#!/bin/sh | ||
|
||
set -e | ||
|
||
SOURCE="${PWD}/source" | ||
RELEASE="${PWD}/release" | ||
PACKED="${PWD}/packed" | ||
|
||
# convert to NFD to enhance compatibility with tools | ||
NAME=$(iconv -t UTF-8-MAC <<< "${PWD##*/}") | ||
|
||
function gob { | ||
pushd "$SOURCE" | ||
gobuild.sh "$NAME" "$1" "$2" '' '' "$3" '' "$RELEASE/$OS" | ||
popd | ||
} | ||
|
||
function pack_if_requested { | ||
if [[ "$PACK" != "" ]]; then | ||
if [[ "$OS" == "mac" ]]; then | ||
PACKED_NAME="$NAME-$OS-$ARCHS-$PACK.dmg" | ||
rm -f "$PACKED/$PACKED_NAME" | ||
create-dmg \ | ||
--window-pos 200 120 \ | ||
--window-size 640 540 \ | ||
--icon "$NAME.app" 170 110 \ | ||
--app-drop-link 470 110 \ | ||
--icon-size 160 \ | ||
--background "$RELEASE/$OS/$NAME.app/Contents/Resources/installer-mac.jpeg" \ | ||
"$PACKED/$PACKED_NAME" "$RELEASE/$OS" | ||
else | ||
PACKED_NAME="$NAME-$OS-$ARCHS-$PACK.zip" | ||
rm -f "$PACKED/$PACKED_NAME" | ||
pushd "$RELEASE/$OS" | ||
zip -9r "$PACKED/$PACKED_NAME" * | ||
popd | ||
fi | ||
fi | ||
} | ||
|
||
function list_package { | ||
find "$RELEASE/$OS" -type f -ls | ||
echo "<-- did list $OS package." | ||
} | ||
|
||
export CGO_ENABLED=1 | ||
|
||
echo "Building $NAME..." | ||
|
||
pushd "$SOURCE" | ||
find . -name .DS_Store -ls -delete | ||
. prepare.sh | ||
popd | ||
|
||
OS='mac' | ||
export COMPRESS= | ||
OSARCH="$(uname -m)" | ||
if [[ "$OSARCH" == "arm64" ]]; then | ||
# unsupported GOOS/GOARCH pair darwin/386 | ||
# gob 'darwin' '386' '-i386' | ||
gob 'darwin' 'amd64' '-amd64' | ||
gob 'darwin' 'arm64' '-arm64' | ||
BIN="$RELEASE/$OS/$NAME" | ||
echo "Creating universal binary" | ||
lipo -create -output "$BIN" "$BIN-amd64" "$BIN-arm64" | ||
rm -v "$BIN-amd64" | ||
rm -v "$BIN-arm64" | ||
ARCHS="amd64+arm64" | ||
else | ||
gob 'darwin' 'amd64' '' | ||
ARCHS="amd64" | ||
fi | ||
echo "--> will create $OS package..." | ||
mkdir -p "$RELEASE/$OS/$NAME.app/Contents" | ||
rsync -av --delete-after "$SOURCE/packaging/$OS/" "$RELEASE/$OS/$NAME.app/Contents/" | ||
mkdir -p "$RELEASE/$OS/$NAME.app/Contents/MacOS/config" | ||
rsync -av --delete-after "$SOURCE/config/$OS/" "$RELEASE/$OS/$NAME.app/Contents/MacOS/config" | ||
mv -f "$RELEASE/$OS/$NAME" "$RELEASE/$OS/$NAME.app/Contents/MacOS" | ||
echo "<-- did create $OS package." | ||
pack_if_requested | ||
list_package | ||
echo pkill -x $NAME || true | ||
pkill -x $NAME || true | ||
echo "<-- did stop $OS app -->" | ||
if [[ "$OSARCH" == "arm64" ]]; then | ||
echo "<-- did skip launch $OS app -->" | ||
else | ||
sleep 2 | ||
open -a "$RELEASE/$OS/$NAME.app" | ||
echo "<-- did launch $OS app -->" | ||
fi | ||
|
||
OS='win' | ||
export COMPRESS='upx' | ||
export LDFLAGS="-H=windowsgui" | ||
gob 'windows' 'amd64' '.exe' | ||
ARCHS="amd64" | ||
echo "--> will create $OS package..." | ||
rsync -av --delete-after "$SOURCE/config/$OS/" "$RELEASE/$OS/config" | ||
echo "<-- did create $OS package." | ||
pack_if_requested | ||
find "$RELEASE/$OS" -type f -ls | ||
echo "<-- did list $OS package." | ||
|
||
echo "Done." |