-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild_compress.sh
executable file
·61 lines (54 loc) · 1.46 KB
/
build_compress.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
#!/bin/bash -e
VERSION="2.3.1"
BINARY_FILENAME="LogRenderer-$VERSION"
OUTPUT_DIR="compiled"
if [ $# -ge 1 ] && [ -n "$1" ] && [ "$1" == "-h" ] || [ "$1" == "--help" ]; then
echo "$BINARY_FILENAME build help:"
echo " -h, --help:"
echo " Display this help"
echo " --dynamic:"
echo " Make the binary dynamically linked"
echo " --nostrip:"
echo " Specify not to strip the binary"
echo " --nocompress:"
echo " Specify not to compress the binary"
exit 0
fi
STATIC=" -extldflags=-static"
TAGS=" -tags osusergo,netgo"
STATIC_MSG=" statically"
STRIP="strip $BINARY_FILENAME"
COMPRESS="xz $BINARY_FILENAME"
FILENAME_EXT=".xz"
while (($#)); do
[[ $1 = -- ]] && {
shift
break
}
[[ $1 = -?* ]] || break
case $1 in
--dynamic)
# remove static 'modifiers'
STATIC=""
TAGS=""
STATIC_MSG=""
;;
--nostrip)
# skip strip command
STRIP=true
;;
--nocompress)
# skip xz command
COMPRESS=true
FILENAME_EXT=""
;;
*)
echo "Unknown option '$1'"
exit 1
;;
esac
shift
done
echo "Building the app (v$VERSION)$STATIC_MSG ..."
(cd src && go build -ldflags="-X 'main.version=$VERSION'$STATIC"$TAGS -o $BINARY_FILENAME && $STRIP && $COMPRESS && mv "$BINARY_FILENAME$FILENAME_EXT" ../$OUTPUT_DIR)
echo "Successfully exported $BINARY_FILENAME to $OUTPUT_DIR/$BINARY_FILENAME$FILENAME_EXT !"