aboutsummaryrefslogtreecommitdiff
path: root/build.sh
blob: 1486073cdc242704f2d7307a569ec748b1da8292 (plain)
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
#!/bin/sh

# This file is part of Haketilo
#
# Copyright (C) 2021, Wojtek Kosior
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the CC0 1.0 Universal License as published by
# the Creative Commons Corporation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# CC0 1.0 Universal License for more details.

set -e

. ./shell_utils.sh

print_usage() {
    printf 'usage:  %s mozilla|chromium [source directory] [update url]\n' \
	   "$0" >&2
}

call_awk() {
    local BROWSER_UPCASE="$(printf %s "$BROWSER" | tr '[:lower:]' '[:upper:]')"
    awk -f compute_scripts.awk -- -M manifest.json -D "$BROWSER_UPCASE" \
	-D MV2 --output=files-to-copy --write-js-deps --write-html-deps \
	--output-dir="$BUILDDIR"
}

main() {
    if [ "x$1" = "xmozilla" -o "x$1" = "xchromium" ]; then
	BROWSER=$1
    else
	print_usage
	exit 1
    fi

    SRCDIR="${2:-.}"
    if [ -d "$SRCDIR" ]; then
	BUILDDIR="$(realpath $BROWSER-unpacked)"
	rm -rf "$BUILDDIR"
	mkdir "$BUILDDIR"
	cd "$SRCDIR"
    else
	print_usage
	exit 2
    fi

    UPDATE_URL="$3"
    if [ -n "$3" ]; then
	printf 'possibility of using an update url is currently unimplemented' \
	       >&2
	exit 1
    fi

    FILES_TO_COPY="$(call_awk)"
    for FILE in $FILES_TO_COPY; do
	FILEDIR="$(printf %s "$FILE" | sed 's_[^/]*$_/_')"
	if [ -n "$FILEDIR" -a ! -d "$BUILDDIR/$FILEDIR" ]; then
	    mkdir -p "$BUILDDIR/$FILEDIR"
	fi
	cp "$FILE" "$BUILDDIR/$FILE"
    done

    cp -r README.md copyright licenses/ "$BUILDDIR"
}

main "$@"