Project

General

Profile

Download (2.33 KB) Statistics
| Branch: | Tag: | Revision:

haketilo / build.sh @ e7c425cc

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
    errcho "usage:  $0 [OPTION]... BROWSER"
14
    errcho
15
    errcho "the -- preceding long forms is optional"
16
    errcho "browsers:"
17
    errcho "    -C, chromium:     build for Chromium and derivatives"
18
    errcho "    -M, mozilla:      build for Firefox and derivatives"
19
    errcho "options:"
20
    errcho "    -b, build [LOC]:  set file/directory to use for building"
21
    errcho "    -f, force:        delete the build directory if it exists"
22
    errcho "                      instead of throwing an error."
23
    errcho "    -h, help:         print usage information and exit"
24
    errcho "    -o, output [LOC]: set output file/directory"
25
    errcho "    -z, zip_ext:      pack the extension as a file"
26
    errcho "    -7, 7zip:         use the '7z' command instead of 'zip'"
27
    
28
    exit $EXIT_STATUS
29
}
30

    
31
. ./lib_build.sh
32

    
33
BROWSER=''
34
BUILDDIR=''
35
MAKEZIP=0
36
FORCE=0
37
ZIP_COMMAND='zip -r'
38

    
39
while [ "x$1" != x ]; do
40
    case "$1" in
41
	-C | chromium | --chromium) BROWSER=chromium;;
42
	-M | mozilla | --mozilla)   BROWSER=mozilla;;
43
	-b | output | --build)      BUILDDIR="$2"
44
	                            shift;;
45
	-f | force | --force)       FORCE=1;;
46
	-h | help | --help)         print_usage;;
47
	-o | output | --output)     OUTPUT="$2"
48
	                            shift;;
49
	-z | zip_ext | --zip_ext)   MAKEZIP=1;;
50
	-7 | 7zip | --7zip)         ZIP_COMMAND='7z a';;
51
	*)                          print_usage 2 Unrecognized option "'$1'.";;
52
    esac
53
    shift
54
done
55

    
56
if [ "x$BROWSER" = x ]; then
57
    print_usage 1 No browser was specified.
58
fi
59

    
60
BUILDDIR="${BUILDDIR:-build_$BROWSER}"
61
if [ -e "$BUILDDIR" ]; then
62
    if [ $FORCE = 0 ]; then
63
	errcho "Build directory '$BUILDDIR' exists."
64
	exit 3
65
    else
66
	rm -rf "$BUILDDIR"
67
    fi
68
fi
69

    
70
if [ "x$OUTPUT" = x ]; then
71
    case "$MAKEZIP$BROWSER" in
72
	0*)        OUTPUT=build_$BROWSER;;
73
	1chromium) OUTPUT=build.crx;;
74
	1mozilla)  OUTPUT=build.xpi;;
75
    esac
76
fi
77

    
78
if [ -e "$OUTPUT" ]; then
79
    errcho "Output location '$OUTPUT' exists."
80
    exit 3
81
fi
82

    
83
mkdir "$BUILDDIR"
84
main
85
if [ $MAKEZIP = 1 ]; then
86
    make_zip
87
    mv "$BUILDDIR"/build.zip "$OUTPUT"
88
    rm -rf "$BUILDDIR"
89
elif [ "$BUILDDIR" != "$OUTPUT" ]; then
90
    mv "$BUILDDIR" "$OUTPUT"
91
fi
(2-2/9)