github.com/kayoticsully/syncthing@v0.8.9-0.20140724133906-c45a2fdc03f8/build.sh (about) 1 #!/usr/bin/env bash 2 3 export COPYFILE_DISABLE=true 4 export GO386=387 # Don't use SSE on 32 bit builds 5 6 distFiles=(README.md LICENSE CONTRIBUTORS) # apart from the binary itself 7 version=$(git describe --always --dirty) 8 date=$(git show -s --format=%ct) 9 user=$(whoami) 10 host=$(hostname) 11 host=${host%%.*} 12 bldenv=${ENVIRONMENT:-default} 13 ldflags="-w -X main.Version $version -X main.BuildStamp $date -X main.BuildUser $user -X main.BuildHost $host -X main.BuildEnv $bldenv" 14 15 check() { 16 if ! command -v godep >/dev/null ; then 17 echo "Error: no godep. Try \"$0 setup\"." 18 exit 1 19 fi 20 } 21 22 build() { 23 check 24 godep go build $* -ldflags "$ldflags" ./cmd/syncthing 25 godep go build $* -ldflags "$ldflags" ./cmd/discosrv 26 } 27 28 assets() { 29 check 30 godep go run cmd/genassets/main.go gui > auto/gui.files.go 31 } 32 33 test-cov() { 34 echo "mode: set" > coverage.out 35 fail=0 36 37 for dir in $(go list ./...) ; do 38 godep go test -coverprofile=profile.out $dir || fail=1 39 if [ -f profile.out ] ; then 40 grep -v "mode: set" profile.out >> coverage.out 41 rm profile.out 42 fi 43 done 44 45 exit $fail 46 } 47 48 test() { 49 check 50 go vet ./... 51 godep go test -cpu=1,2,4 ./... 52 } 53 54 sign() { 55 if git describe --exact-match 2>/dev/null >/dev/null ; then 56 # HEAD is a tag 57 id=BCE524C7 58 if gpg --list-keys "$id" >/dev/null 2>&1 ; then 59 gpg -ab -u "$id" "$1" 60 fi 61 fi 62 } 63 64 tarDist() { 65 name="$1" 66 rm -rf "$name" 67 mkdir -p "$name" 68 cp syncthing "${distFiles[@]}" "$name" 69 sign "$name/syncthing" 70 tar zcvf "$name.tar.gz" "$name" 71 rm -rf "$name" 72 } 73 74 zipDist() { 75 name="$1" 76 rm -rf "$name" 77 mkdir -p "$name" 78 for f in "${distFiles[@]}" ; do 79 GOARCH="" GOOS="" go run cmd/todos/main.go < "$f" > "$name/$f.txt" 80 done 81 cp syncthing.exe "$name" 82 sign "$name/syncthing.exe" 83 zip -r "$name.zip" "$name" 84 rm -rf "$name" 85 } 86 87 deps() { 88 check 89 godep save ./cmd/... 90 } 91 92 setup() { 93 echo Installing godep... 94 go get -u github.com/tools/godep 95 echo Installing go vet... 96 go get -u code.google.com/p/go.tools/cmd/vet 97 } 98 99 xdr() { 100 for f in discover/packets files/leveldb protocol/message ; do 101 go run cmd/genxdr/main.go -- "${f}.go" > "${f}_xdr.go" 102 done 103 } 104 105 case "$1" in 106 "") 107 shift 108 export GOBIN=$(pwd)/bin 109 godep go install $* -ldflags "$ldflags" ./cmd/... 110 ;; 111 112 race) 113 build -race 114 ;; 115 116 guidev) 117 echo "Syncthing is already built for GUI developments. Try:" 118 echo " STGUIASSETS=~/someDir/gui syncthing" 119 ;; 120 121 test) 122 test 123 ;; 124 125 test-cov) 126 test-cov 127 ;; 128 129 tar) 130 rm -f *.tar.gz *.zip 131 test || exit 1 132 assets 133 build 134 135 eval $(go env) 136 name="syncthing-$GOOS-$GOARCH-$version" 137 138 tarDist "$name" 139 ;; 140 141 all) 142 rm -f *.tar.gz *.zip 143 test || exit 1 144 assets 145 146 for os in darwin-amd64 linux-386 linux-amd64 freebsd-amd64 windows-amd64 windows-386 ; do 147 export GOOS=${os%-*} 148 export GOARCH=${os#*-} 149 150 build 151 152 name="syncthing-$os-$version" 153 case $GOOS in 154 windows) 155 zipDist "$name" 156 rm -f syncthing.exe 157 ;; 158 *) 159 tarDist "$name" 160 rm -f syncthing 161 ;; 162 esac 163 done 164 165 export GOOS=linux 166 export GOARCH=arm 167 168 origldflags="$ldflags" 169 170 export GOARM=7 171 ldflags="$origldflags -X main.GoArchExtra v7" 172 build 173 tarDist "syncthing-linux-armv7-$version" 174 175 export GOARM=6 176 ldflags="$origldflags -X main.GoArchExtra v6" 177 build 178 tarDist "syncthing-linux-armv6-$version" 179 180 export GOARM=5 181 ldflags="$origldflags -X main.GoArchExtra v5" 182 build 183 tarDist "syncthing-linux-armv5-$version" 184 185 ;; 186 187 upload) 188 tag=$(git describe) 189 shopt -s nullglob 190 for f in *.tar.gz *.zip *.asc ; do 191 relup calmh/syncthing "$tag" "$f" 192 done 193 ;; 194 195 deps) 196 deps 197 ;; 198 199 assets) 200 assets 201 ;; 202 203 setup) 204 setup 205 ;; 206 207 xdr) 208 xdr 209 ;; 210 211 *) 212 echo "Unknown build parameter $1" 213 ;; 214 esac