syncthing/build.sh

92 lines
1.3 KiB
Bash
Raw Normal View History

2013-12-21 16:16:49 -07:00
#!/bin/bash
export COPYFILE_DISABLE=true
2014-03-02 15:55:08 -07:00
distFiles=(README.md LICENSE) # apart from the binary itself
2013-12-21 16:16:49 -07:00
version=$(git describe --always)
2014-03-02 15:55:08 -07:00
build() {
go build -ldflags "-w -X main.Version $version" ./cmd/syncthing
}
prepare() {
2014-02-23 05:54:23 -07:00
./assets.sh | gofmt > auto/gui.files.go
2014-01-09 15:00:23 -07:00
go get -d
2014-03-02 15:55:08 -07:00
}
test() {
2014-01-06 07:50:15 -07:00
go test ./...
2014-03-02 15:55:08 -07:00
}
tarDist() {
name="$1"
mkdir -p "$name"
cp syncthing "${distFiles[@]}" "$name"
tar zcvf "$name.tar.gz" "$name"
rm -rf "$name"
}
zipDist() {
name="$1"
mkdir -p "$name"
cp syncthing.exe "${distFiles[@]}" "$name"
zip -r "$name.zip" "$name"
rm -rf "$name"
}
case "$1" in
"")
build
;;
tar)
rm -f *.tar.gz *.zip
prepare
test || exit 1
build
eval $(go env)
name="syncthing-$GOOS-$GOARCH-$version"
tarDist "$name"
;;
all)
rm -f *.tar.gz *.zip
prepare
test || exit 1
export GOARM=7
for os in darwin-amd64 linux-amd64 linux-arm freebsd-amd64 windows-amd64 ; do
export GOOS=${os%-*}
export GOARCH=${os#*-}
build
name="syncthing-$os-$version"
case $GOOS in
windows)
zipDist "$name"
rm -f syncthing.exe
;;
*)
tarDist "$name"
rm -f syncthing
;;
esac
done
;;
upload)
tag=$(git describe)
shopt -s nullglob
for f in *gz *zip ; do
relup calmh/syncthing "$tag" "$f"
done
;;
*)
echo "Unknown build parameter $1"
;;
esac