-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathbuild-site.sh
executable file
·67 lines (62 loc) · 1.85 KB
/
build-site.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/bin/bash
compile() {
os=$1
arch=$2
LINK_FLAGS="-w -s -buildid=rscgo-production -v -extldflags=-static -X main.version=$tag"
BUILD_FLAGS="-trimpath -smallframes -pack -buildid=rscgo-production -v -complete -nolocalimports -v"
EXECUTABLE="./bin/site-$os-$arch"
if [[ $os == 'windows' ]]; then
EXECUTABLE="$EXECUTABLE.exe"
fi
# if [[ $arch == 'amd64' && $os == 'linux' || $arch == 'amd64' && $os == 'freebsd' ]]; then
# echo 'Position-independent executable files supported on target OS; enabling...'
# LINK_FLAGS="-buildmode pie $LINK_FLAGS"
# fi
CGO_ENABLED=0 CC=gcc GOOS=$os GOARCH=$arch go build -o "$EXECUTABLE" -gcflags="$BUILD_FLAGS" -tags=netgo -ldflags="$LINK_FLAGS -extld=ldd" pkg/website.go
}
listTargets() {
echo "Available targets (os/arch):"
echo `go tool dist list`
exit
}
if [[ $1 == 'all' ]]; then
for os in `go tool dist list |sed -e 's/\// /g' |cut -d' ' -f1 |sort |uniq`; do
for arch in `go tool dist list |grep $os |sed 's/\// /g' |cut -d' ' -f2`; do
compile $os $arch
done
OS=`echo $tuple |cut -f1 -d' '`
ARCH=`echo $tuple |cut -f2 -d' '`
echo $OS $ARCH
# for ARCH in `go tool dist list |sed -e 's/\// /g' |cut -f2 -d' ' |sort |uniq`; do
# done
done
if [[ `pidof site` != "" ]]; then
pkill site
cp "bin/site-`go env GOHOSTOS`-`go env GOHOSTARCH`" 'bin/site'
screen ./bin/site -v
exit
fi
cp "bin/site-`go env GOHOSTOS`-`go env GOHOSTARCH`" 'bin/site'
exit
fi
unset OS
for arch in `go tool dist list|sed -e 's/\// /g' |cut -f1 -d' ' |sort |uniq`; do
if [[ $1 == $arch ]]; then
OS=$arch
break
fi
done
for os in `go tool dist list|sed -e 's/\// /g' |cut -f2 -d' ' |sort |uniq`; do
if [[ $2 == $os ]]; then
ARCH=$os
break
fi
done
if [[ -z $OS ]]; then
OS=`go env GOHOSTOS`
fi
if [[ -z $ARCH ]]; then
ARCH=`go env GOHOSTARCH`
fi
compile $OS $ARCH
cp bin/site-`go env GOHOSTOS`-`go env GOHOSTARCH` bin/site