syncthing/build.sh

118 lines
1.9 KiB
Bash
Raw Normal View History

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