summaryrefslogtreecommitdiffstats
path: root/build.sh
diff options
context:
space:
mode:
authorJakob Borg <jakob@nym.se>2014-03-02 23:55:08 +0100
committerJakob Borg <jakob@nym.se>2014-03-02 23:55:08 +0100
commit0afcb5b7e760bef94a6b078759856964b6941ed0 (patch)
treec642dd9c6f14622a7a6a4c576c1a282d66cc86c3 /build.sh
parent0618e2b9b4feec98b13ed9a6d7b2f22cc9c52c3f (diff)
Clean up build.sh
Diffstat (limited to 'build.sh')
-rwxr-xr-xbuild.sh122
1 files changed, 82 insertions, 40 deletions
diff --git a/build.sh b/build.sh
index e36c7175d4..e335eda5ce 100755
--- a/build.sh
+++ b/build.sh
@@ -2,48 +2,90 @@
export COPYFILE_DISABLE=true
+distFiles=(README.md LICENSE) # apart from the binary itself
version=$(git describe --always)
-buildDir=dist
-if [[ $fast != yes ]] ; then
+build() {
+ go build -ldflags "-w -X main.Version $version" ./cmd/syncthing
+}
+
+prepare() {
./assets.sh | gofmt > auto/gui.files.go
go get -d
+}
+
+test() {
go test ./...
-fi
-
-if [[ -z $1 ]] ; then
- go build -ldflags "-X main.Version $version" ./cmd/syncthing
-elif [[ $1 == "tar" ]] ; then
- go build -ldflags "-X main.Version $version" ./cmd/syncthing \
- && mkdir syncthing-dist \
- && cp syncthing README.md LICENSE syncthing-dist \
- && tar zcvf syncthing-dist.tar.gz syncthing-dist \
- && rm -rf syncthing-dist
-elif [[ $1 == "all" ]] ; then
- rm -rf "$buildDir"
- mkdir -p "$buildDir" || exit 1
-
- export GOARM=7
- for os in darwin-amd64 linux-amd64 linux-arm freebsd-amd64 windows-amd64 ; do
- echo "$os"
- export name="syncthing-$os"
- export GOOS=${os%-*}
- export GOARCH=${os#*-}
- go build -ldflags "-X main.Version $version" ./cmd/syncthing
- mkdir -p "$name"
- cp README.md LICENSE "$name"
- case $GOOS in
- windows)
- cp syncthing.exe "$buildDir/$name.exe"
- mv syncthing.exe "$name"
- zip -qr "$buildDir/$name.zip" "$name"
- ;;
- *)
- cp syncthing "$buildDir/$name"
- mv syncthing "$name"
- tar zcf "$buildDir/$name.tar.gz" "$name"
- ;;
- esac
- rm -r "$name"
- done
-fi
+}
+
+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