syncthing/build.sh

114 lines
1.7 KiB
Bash
Raw Normal View History

2014-03-17 18:15:59 +01:00
#!/usr/bin/env bash
2013-12-22 00:16:49 +01:00
export COPYFILE_DISABLE=true
2014-03-02 23:55:08 +01:00
distFiles=(README.md LICENSE) # apart from the binary itself
2013-12-22 00:16:49 +01:00
version=$(git describe --always)
2014-03-02 23:55:08 +01:00
build() {
2014-03-24 07:37:26 +01:00
if command -v godep >/dev/null ; then
2014-03-22 21:33:18 +01:00
godep=godep
else
echo "Warning: no godep, using \"go get\" instead."
echo "Try \"go get github.com/tools/godep\"."
go get -d ./cmd/syncthing
godep=
fi
${godep} go build -ldflags "-w -X main.Version $version" ./cmd/syncthing
2014-03-02 23:55:08 +01:00
}
prepare() {
go run cmd/assets/assets.go gui > auto/gui.files.go
2014-03-02 23:55:08 +01:00
}
test() {
2014-03-22 17:06:15 +01:00
go test -cpu=1,2,4 ./...
}
2014-03-02 23:55:08 +01:00
2014-03-22 21:38:01 +01:00
sign() {
id=BCE524C7
if gpg --list-keys "$id" >/dev/null 2>&1 ; then
gpg -ab -u "$id" "$1"
fi
}
2014-03-02 23:55:08 +01:00
tarDist() {
name="$1"
rm -rf "$name"
2014-03-02 23:55:08 +01:00
mkdir -p "$name"
cp syncthing "${distFiles[@]}" "$name"
2014-03-22 21:38:01 +01:00
sign "$name/syncthing"
2014-03-02 23:55:08 +01:00
tar zcvf "$name.tar.gz" "$name"
rm -rf "$name"
}
zipDist() {
name="$1"
rm -rf "$name"
2014-03-02 23:55:08 +01:00
mkdir -p "$name"
cp syncthing.exe "${distFiles[@]}" "$name"
2014-03-22 21:38:01 +01:00
sign "$name/syncthing.exe"
2014-03-02 23:55:08 +01:00
zip -r "$name.zip" "$name"
rm -rf "$name"
}
case "$1" in
"")
build
;;
2014-03-22 21:33:18 +01:00
test)
test
;;
2014-03-02 23:55:08 +01:00
tar)
rm -f *.tar.gz *.zip
2014-03-02 23:55:08 +01:00
prepare
test || exit 1
build
eval $(go env)
name="syncthing-$GOOS-$GOARCH-$version"
tarDist "$name"
;;
all)
rm -f *.tar.gz *.zip
2014-03-02 23:55:08 +01:00
prepare
test || exit 1
export GOARM=7
for os in darwin-amd64 linux-amd64 linux-arm freebsd-amd64 ; do
2014-03-02 23:55:08 +01:00
export GOOS=${os%-*}
export GOARCH=${os#*-}
build
2014-03-02 23:55:08 +01:00
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 *.tar.gz *.zip *.asc ; do
2014-03-02 23:55:08 +01:00
relup calmh/syncthing "$tag" "$f"
done
;;
*)
echo "Unknown build parameter $1"
;;
esac