Project

General

Profile

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

haketilo / build.sh @ 3a90084e

1
#!/bin/sh
2

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

    
16
set -e
17

    
18
. ./shell_utils.sh
19

    
20
as_json_list() {
21
    while true; do
22
	if [ "x" = "x$2" ]; then
23
	    printf '\\n\t\t"%s"\\n\t' "$1"
24
	    return
25
	fi
26
	printf '\\n\t\t"%s",' "$1"
27
	shift
28
    done
29
}
30

    
31
as_html_list() {
32
    while [ "x" != "x$1" ]; do
33
	printf '\\n    <script src="/%s"></script>' "$1"
34
	shift
35
    done
36
}
37

    
38
compute_scripts() {
39
    local DIRS="$1"
40
    local ROOT_SCRIPT="$2"
41

    
42
    local AVAILABLE="$(find $DIRS -name '[^.#]*.js')"
43

    
44
    awk -f compute_scripts.awk script_dependencies "$ROOT_SCRIPT" $AVAILABLE
45
}
46

    
47
build_main() {
48
    local ALL_SCRIPTDIRS='background html common content'
49

    
50
    local ALL_SCRIPTS_AVAILABLE="$(find $ALL_SCRIPTDIRS -name '[^.#]*.js')"
51

    
52
    local SCRIPT
53
    for SCRIPT in $ALL_SCRIPTS_AVAILABLE; do
54
	map_set SCRIPTS_UNUSED $(sanitize $SCRIPT) yes
55
    done
56

    
57
    local ROOT=background/main.js
58
    local SCRIPTS_BG="$(      compute_scripts 'common/ background/' $ROOT)"
59

    
60
    local ROOT=content/main.js
61
    local SCRIPTS_CONTENT="$( compute_scripts 'common/ content/'    $ROOT)"
62

    
63
    local ROOT=html/display-panel.js
64
    local SCRIPTS_POPUP="$(   compute_scripts 'common/ html/'       $ROOT)"
65

    
66
    local ROOT=html/options_main.js
67
    local SCRIPTS_OPTIONS="$( compute_scripts 'common/ html/'       $ROOT)"
68

    
69
    local BGSCRIPTS="$(      as_json_list $SCRIPTS_BG      )"
70
    local CONTENTSCRIPTS="$( as_json_list $SCRIPTS_CONTENT )"
71
    local POPUPSCRIPTS="$(   as_html_list $SCRIPTS_POPUP   )"
72
    local OPTIONSSCRIPTS="$( as_html_list $SCRIPTS_OPTIONS )"
73

    
74
    for SCRIPT in $SCRIPTS_BG $SCRIPTS_CONTENT $SCRIPTS_POPUP $SCRIPTS_OPTIONS
75
    do
76
	map_del SCRIPTS_UNUSED $(sanitize $SCRIPT)
77
    done
78

    
79
    for DIR in $(find $ALL_SCRIPTDIRS -type d); do
80
	mkdir -p "$BUILDDIR"/$DIR
81
    done
82

    
83
    CHROMIUM_UPDATE_URL=''
84
    GECKO_APPLICATIONS=''
85

    
86
    if [ "x$UPDATE_URL" != x ]; then
87
	UPDATE_URL=",\n    \"update_url\": \"$UPDATE_URL\""
88
    fi
89

    
90
    if [ "$BROWSER" = "chromium" ]; then
91
	CHROMIUM_UPDATE_URL="$UPDATE_URL"
92
    else
93
	GECKO_APPLICATIONS="\n\
94
    \"applications\": {\n\
95
	\"gecko\": {\n\
96
	    \"id\": \"{6fe13369-88e9-440f-b837-5012fb3bedec}\",\n\
97
	    \"strict_min_version\": \"60.0\"$UPDATE_URL\n\
98
	}\n\
99
    },"
100
    fi
101

    
102
    sed "\
103
s^_GECKO_APPLICATIONS_^$GECKO_APPLICATIONS^
104
s^_CHROMIUM_UPDATE_URL_^$CHROMIUM_UPDATE_URL^
105
s^_BGSCRIPTS_^$BGSCRIPTS^
106
s^_CONTENTSCRIPTS_^$CONTENTSCRIPTS^" \
107
	< manifest.json > "$BUILDDIR"/manifest.json
108

    
109
    ./process_html_file.sh html/display-panel.html |
110
	sed "s^_POPUPSCRIPTS_^$POPUPSCRIPTS^" \
111
	    > "$BUILDDIR"/html/display-panel.html
112

    
113
    ./process_html_file.sh html/options.html |
114
	sed "s^_OPTIONSSCRIPTS_^$OPTIONSSCRIPTS^" \
115
	    > "$BUILDDIR"/html/options.html
116

    
117
    for FILE in $ALL_SCRIPTS_AVAILABLE; do
118
	FILEKEY=$(sanitize "$FILE")
119
	if [ "x$(map_get SCRIPTS_UNUSED $FILEKEY)" = "xyes" ]; then
120
	    printf 'WARNING! %s not used\n' "$FILE" >&2
121
	else
122
	    awk -f compute_scripts.awk wrapped_code "$FILE" > "$BUILDDIR"/$FILE
123
	fi
124
    done
125

    
126
    ./write_exports_init.sh "$BROWSER" "$BUILDDIR" default_settings.json
127

    
128
    cp -r copyright licenses/ "$BUILDDIR"
129
    cp dummy "$BUILDDIR"
130
    cp html/*.css "$BUILDDIR"/html
131
    mkdir "$BUILDDIR"/icons
132
    cp icons/*.png "$BUILDDIR"/icons
133

    
134
    if [ "$BROWSER" = "chromium" ]; then
135
	for MOZILLA_FILE in $(find "$BUILDDIR" -name "MOZILLA_*"); do
136
	    printf '\n' > "$MOZILLA_FILE"
137
	done
138
    fi
139
    if [ "$BROWSER" = "mozilla" ]; then
140
	for CHROMIUM_FILE in $(find "$BUILDDIR" -name "CHROMIUM_*"); do
141
	    printf '\n' > "$CHROMIUM_FILE"
142
	done
143
    fi
144
}
145

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

    
151
main() {
152
    if [ "x$1" = "xmozilla" -o "x$1" = "xchromium" ]; then
153
	BROWSER=$1
154
    else
155
	print_usage
156
	exit 1
157
    fi
158

    
159
    SRCDIR="${2:-.}"
160
    if [ -d "$SRCDIR" ]; then
161
	BUILDDIR="$(realpath $BROWSER-unpacked)"
162
	rm -rf "$BUILDDIR"
163
	mkdir "$BUILDDIR"
164
	cd "$SRCDIR"
165
    else
166
	print_usage
167
	exit 2
168
    fi
169

    
170
    UPDATE_URL="$3"
171

    
172
    build_main
173
}
174

    
175
main "$@"
(6-6/18)