syncthing/build.sh

150 lines
2.4 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
version=$(git describe --always --dirty)
2014-04-19 16:38:11 +02:00
date=$(date +%s)
user=$(whoami)
host=$(hostname -s)
ldflags="-w -X main.Version $version -X main.BuildStamp $date -X main.BuildUser $user -X main.BuildHost $host"
2013-12-22 00:16:49 +01:00
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 "$ldflags" ./cmd/syncthing
${godep} go build -ldflags "$ldflags" ./cmd/stcli
2014-03-02 23:55:08 +01:00
}
assets() {
godep go run cmd/assets/assets.go gui > auto/gui.files.go
2014-03-02 23:55:08 +01:00
}
test() {
godep go test -cpu=1,2,4 ./...
}
2014-03-02 23:55:08 +01:00
2014-03-22 21:38:01 +01: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 21:38:01 +01:00
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"
}
2014-04-08 15:14:36 +02:00
deps() {
godep save ./cmd/syncthing ./cmd/assets ./cmd/stcli ./discover/cmd/discosrv
}
2014-03-02 23:55:08 +01:00
case "$1" in
"")
2014-04-09 23:00:23 +02:00
shift
build $*
2014-03-02 23:55:08 +01:00
;;
race)
build -race
;;
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
test || exit 1
assets
2014-03-02 23:55:08 +01:00
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
test || exit 1
assets
2014-03-02 23:55:08 +01:00
2014-04-01 10:48:09 +02:00
for os in darwin-amd64 linux-386 linux-amd64 freebsd-amd64 windows-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
2014-03-31 05:59:40 +02:00
export GOOS=linux
export GOARCH=arm
export GOARM=7
build
tarDist "syncthing-linux-armv7-$version"
export GOARM=6
build
tarDist "syncthing-linux-armv6-$version"
2014-03-02 23:55:08 +01:00
;;
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
;;
2014-04-08 15:14:36 +02:00
deps)
deps
;;
assets)
assets
;;
2014-03-02 23:55:08 +01:00
*)
echo "Unknown build parameter $1"
;;
esac