Clean up build.sh

This commit is contained in:
Jakob Borg 2014-03-02 23:55:08 +01:00
parent 0618e2b9b4
commit 0afcb5b7e7
2 changed files with 82 additions and 39 deletions

3
.gitignore vendored
View File

@ -1,3 +1,4 @@
syncthing syncthing
syncthing.exe
*.tar.gz *.tar.gz
dist *.zip

View File

@ -2,48 +2,90 @@
export COPYFILE_DISABLE=true export COPYFILE_DISABLE=true
distFiles=(README.md LICENSE) # apart from the binary itself
version=$(git describe --always) 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 ./assets.sh | gofmt > auto/gui.files.go
go get -d go get -d
go test ./... }
fi
if [[ -z $1 ]] ; then test() {
go build -ldflags "-X main.Version $version" ./cmd/syncthing go test ./...
elif [[ $1 == "tar" ]] ; then }
go build -ldflags "-X main.Version $version" ./cmd/syncthing \
&& mkdir syncthing-dist \ tarDist() {
&& cp syncthing README.md LICENSE syncthing-dist \ name="$1"
&& tar zcvf syncthing-dist.tar.gz syncthing-dist \ mkdir -p "$name"
&& rm -rf syncthing-dist cp syncthing "${distFiles[@]}" "$name"
elif [[ $1 == "all" ]] ; then tar zcvf "$name.tar.gz" "$name"
rm -rf "$buildDir" rm -rf "$name"
mkdir -p "$buildDir" || exit 1 }
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 export GOARM=7
for os in darwin-amd64 linux-amd64 linux-arm freebsd-amd64 windows-amd64 ; do for os in darwin-amd64 linux-amd64 linux-arm freebsd-amd64 windows-amd64 ; do
echo "$os"
export name="syncthing-$os"
export GOOS=${os%-*} export GOOS=${os%-*}
export GOARCH=${os#*-} export GOARCH=${os#*-}
go build -ldflags "-X main.Version $version" ./cmd/syncthing
mkdir -p "$name" build
cp README.md LICENSE "$name"
name="syncthing-$os-$version"
case $GOOS in case $GOOS in
windows) windows)
cp syncthing.exe "$buildDir/$name.exe" zipDist "$name"
mv syncthing.exe "$name" rm -f syncthing.exe
zip -qr "$buildDir/$name.zip" "$name"
;; ;;
*) *)
cp syncthing "$buildDir/$name" tarDist "$name"
mv syncthing "$name" rm -f syncthing
tar zcf "$buildDir/$name.tar.gz" "$name"
;; ;;
esac esac
rm -r "$name"
done done
fi ;;
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