1
|
#!/bin/sh
|
2
|
|
3
|
# Copyright (C) 2021 jahoti <jahoti@tilde.team>
|
4
|
# Redistribution terms are gathered in the `copyright' file.
|
5
|
|
6
|
print_usage() {
|
7
|
EXIT_STATUS=${1:-0}
|
8
|
if [ "x$1" != x ]; then
|
9
|
shift
|
10
|
errcho "$@"
|
11
|
fi
|
12
|
|
13
|
echo "usage: $0 [OPTION]... BROWSER"
|
14
|
echo
|
15
|
echo "long options can be provided either in the form"
|
16
|
echo "'[OPTION](=[VALUE])' or '--[OPTION] (VALUE)'."
|
17
|
echo "browsers:"
|
18
|
echo " -C, chromium: build for Chromium and derivatives"
|
19
|
echo " -M, mozilla: build for Firefox and derivatives"
|
20
|
echo "options:"
|
21
|
echo " -b, build=[LOC]: set file/directory to use for building"
|
22
|
echo " -h, help: print usage information and exit"
|
23
|
echo " -o, output=[LOC]: set output file/directory"
|
24
|
echo " -s, safe: don't delete existing directories;"
|
25
|
echo " throw an error instead."
|
26
|
echo " -z, zip: pack the extension as a file"
|
27
|
echo
|
28
|
echo "environment variables (optional)"
|
29
|
echo " HAKETILO_ZIP: command to use for generating ZIP files"
|
30
|
echo " HAKETILO_CHROMIUM: command to user to invoke Chromium"
|
31
|
|
32
|
exit $EXIT_STATUS
|
33
|
}
|
34
|
|
35
|
. ./lib_build.sh
|
36
|
|
37
|
BROWSER=''
|
38
|
BUILDDIR=''
|
39
|
MAKEZIP=0
|
40
|
FORCE=1
|
41
|
|
42
|
while [ "x$1" != x ]; do
|
43
|
case "$1" in
|
44
|
-C | --chromium | chromium) BROWSER=chromium;;
|
45
|
-M | --mozilla | mozilla) BROWSER=mozilla;;
|
46
|
-b | --build) BUILDDIR="$2"; shift;;
|
47
|
build=*) BUILDDIR="$(echo "$1" | cut -c 7-)";;
|
48
|
-h | --help | help) print_usage;;
|
49
|
-o | --output) OUTPUT="$2"; shift;;
|
50
|
output=*) OUTPUT="$(echo "$1" | cut -c 8-)";;
|
51
|
-s | --safe | safe) FORCE=0;;
|
52
|
-z | --zip | zip_ext) MAKEZIP=1;;
|
53
|
*) print_usage 2 Unrecognized option "'$1'.";;
|
54
|
esac
|
55
|
shift
|
56
|
done
|
57
|
|
58
|
if [ "x$BROWSER" = x ]; then
|
59
|
print_usage 1 No browser was specified.
|
60
|
fi
|
61
|
|
62
|
|
63
|
if [ $MAKEZIP = 1 ]; then
|
64
|
BUILDDIR="${BUILDDIR:-build_$BROWSER}"
|
65
|
|
66
|
if [ "x$OUTPUT" = x ]; then
|
67
|
case $BROWSER in
|
68
|
chromium) OUTPUT=build.crx;;
|
69
|
mozilla) OUTPUT=build.xpi;;
|
70
|
esac
|
71
|
fi
|
72
|
else
|
73
|
if [ "x$BUILDDIR" = x ]; then
|
74
|
BUILDDIR="${OUTPUT:-build_$BROWSER}"
|
75
|
fi
|
76
|
|
77
|
OUTPUT="${OUTPUT:-$BUILDDIR}"
|
78
|
fi
|
79
|
|
80
|
if [ -e "$BUILDDIR" ]; then
|
81
|
if [ $FORCE = 0 ]; then
|
82
|
errcho "Build directory '$BUILDDIR' exists."
|
83
|
exit 3
|
84
|
else
|
85
|
rm -rf "$BUILDDIR"
|
86
|
fi
|
87
|
fi
|
88
|
|
89
|
if [ -e "$OUTPUT" ]; then
|
90
|
if [ $FORCE = 0 ]; then
|
91
|
errcho "Output location '$OUTPUT' exists."
|
92
|
exit 3
|
93
|
else
|
94
|
rm -rf "$BUILDDIR"
|
95
|
fi
|
96
|
fi
|
97
|
|
98
|
mkdir "$BUILDDIR"
|
99
|
main
|
100
|
if [ $MAKEZIP = 1 ]; then
|
101
|
make_zip
|
102
|
mv "$BUILDDIR"/build.zip "$OUTPUT"
|
103
|
rm -rf "$BUILDDIR"
|
104
|
elif [ "$BUILDDIR" != "$OUTPUT" ]; then
|
105
|
mv "$BUILDDIR" "$OUTPUT"
|
106
|
fi
|