-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmake.bash
150 lines (134 loc) · 4.26 KB
/
make.bash
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#!/bin/bash
set -ex
REVSION=$(git rev-list --count HEAD)
LDFLAGS="-s -w -X main.version=r${REVSION}"
GOOS=${GOOS:-$(go env GOOS)}
GOARCH=${GOARCH:-$(go env GOARCH)}
CGO_ENABLED=${CGO_ENABLED:-$(go env CGO_ENABLED)}
REPO=$(git rev-parse --show-toplevel)
PACKAGE=$(basename ${REPO})
if [ "${CGO_ENABLED}" = "0" ]; then
BUILDROOT=${REPO}/build/${GOOS}_${GOARCH}
else
BUILDROOT=${REPO}/build/${GOOS}_${GOARCH}_cgo
fi
STAGEDIR=${BUILDROOT}/stage
OBJECTDIR=${BUILDROOT}/obj
DISTDIR=${BUILDROOT}/dist
if [ "${GOOS}" == "windows" ]; then
PROM_EXE="${PACKAGE}.exe"
PROM_STAGEDIR="${STAGEDIR}"
PROM_DISTCMD="7za a -y -mx=9 -m0=lzma -mfb=128 -md=64m -ms=on"
PROM_DISTEXT=".7z"
elif [ "${GOOS}" == "darwin" ]; then
PROM_EXE="${PACKAGE}"
PROM_STAGEDIR="${STAGEDIR}"
PROM_DISTCMD="env BZIP=-9 tar cvjpf"
PROM_DISTEXT=".tar.bz2"
elif [ "${GOARCH:0:3}" == "arm" ]; then
PROM_EXE="${PACKAGE}"
PROM_STAGEDIR="${STAGEDIR}"
PROM_DISTCMD="env BZIP=-9 tar cvjpf"
PROM_DISTEXT=".tar.bz2"
elif [ "${GOARCH:0:4}" == "mips" ]; then
PROM_EXE="${PACKAGE}"
PROM_STAGEDIR="${STAGEDIR}"
PROM_DISTCMD="env GZIP=-9 tar cvzpf"
PROM_DISTEXT=".tar.gz"
else
PROM_EXE="${PACKAGE}"
PROM_STAGEDIR="${STAGEDIR}/${PACKAGE}"
PROM_DISTCMD="env XZ_OPT=-9 tar cvJpf"
PROM_DISTEXT=".tar.xz"
fi
PROM_DIST=${DISTDIR}/${PACKAGE}_${GOOS}_${GOARCH}-r${REVSION}${PROM_DISTEXT}
if [ "${CGO_ENABLED}" = "1" ]; then
PROM_DIST=${DISTDIR}/${PACKAGE}_${GOOS}_${GOARCH}_cgo-r${REVSION}${PROM_DISTEXT}
fi
PROM_GUI_EXE=${REPO}/assets/taskbar/${GOARCH}/promgui.exe
if [ ! -f "${PROM_GUI_EXE}" ]; then
PROM_GUI_EXE=${REPO}/assets/packaging/promgui.exe
fi
OBJECTS=${OBJECTDIR}/${PROM_EXE}
SOURCES="${REPO}/README.md \
${REPO}/assets/packaging/gae.user.json.example \
${REPO}/httpproxy/filters/auth/auth.json \
${REPO}/httpproxy/filters/autoproxy/17monipdb.dat \
${REPO}/httpproxy/filters/autoproxy/autoproxy.json \
${REPO}/httpproxy/filters/autoproxy/gfwlist.txt \
${REPO}/httpproxy/filters/autoproxy/ip.html \
${REPO}/httpproxy/filters/autorange/autorange.json \
${REPO}/httpproxy/filters/direct/direct.json \
${REPO}/httpproxy/filters/gae/gae.json \
${REPO}/httpproxy/filters/php/php.json \
${REPO}/httpproxy/filters/rewrite/rewrite.json \
${REPO}/httpproxy/filters/stripssl/stripssl.json \
${REPO}/httpproxy/httpproxy.json"
if [ "${GOOS}" = "windows" ]; then
SOURCES="${SOURCES} \
${PROM_GUI_EXE} \
${REPO}/assets/packaging/addto-startup.vbs \
${REPO}/assets/packaging/get-latest-prom.cmd"
elif [ "${GOOS}_${GOARCH}_${CGO_ENABLED}" = "linux_arm_0" ]; then
SOURCES="${SOURCES} \
${REPO}/assets/packaging/prom.sh \
${REPO}/assets/packaging/get-latest-prom.sh"
GOARM=${GORAM:-5}
elif [ "${GOOS}_${GOARCH}_${CGO_ENABLED}" = "linux_arm_1" ]; then
SOURCES="${SOURCES} \
${REPO}/assets/packaging/prom.sh \
${REPO}/assets/packaging/get-latest-prom.sh"
CC=${ARM_CC:-arm-linux-gnueabihf-gcc}
GOARM=${GORAM:-5}
elif [ "${GOOS}" = "darwin" ]; then
SOURCES="${SOURCES} \
${REPO}/assets/packaging/promgui.command \
${REPO}/assets/packaging/get-latest-prom.sh"
else
SOURCES="${SOURCES} \
${REPO}/assets/packaging/get-latest-prom.sh \
${REPO}/assets/packaging/promgui.desktop \
${REPO}/assets/packaging/promgui.png \
${REPO}/assets/packaging/promgui.py \
${REPO}/assets/packaging/prom.sh"
fi
build () {
mkdir -p ${OBJECTDIR}
env GOOS=${GOOS} \
GOARCH=${GOARCH} \
GOARM=${GOARM} \
CGO_ENABLED=${CGO_ENABLED} \
CC=${CC} \
go build -v -ldflags="${LDFLAGS}" -o ${OBJECTDIR}/${PROM_EXE} .
}
dist () {
mkdir -p ${DISTDIR} ${STAGEDIR} ${PROM_STAGEDIR}
cp ${OBJECTS} ${SOURCES} ${PROM_STAGEDIR}
pushd ${STAGEDIR}
${PROM_DISTCMD} ${PROM_DIST} *
popd
}
check () {
PROM_WAIT_SECONDS=0 ${PROM_STAGEDIR}/${PROM_EXE}
}
clean () {
rm -rf ${BUILDROOT}
}
case $1 in
build)
build
;;
dist)
dist
;;
check)
check
;;
clean)
clean
;;
*)
build
dist
;;
esac