summaryrefslogtreecommitdiff
path: root/build.sh
diff options
context:
space:
mode:
Diffstat (limited to 'build.sh')
-rwxr-xr-xbuild.sh149
1 files changed, 22 insertions, 127 deletions
diff --git a/build.sh b/build.sh
index d0958a1..8d5b97e 100755
--- a/build.sh
+++ b/build.sh
@@ -17,137 +17,18 @@ set -e
. ./shell_utils.sh
-as_json_list() {
- while true; do
- if [ "x" = "x$2" ]; then
- printf '\\n\t\t"%s"\\n\t' "$1"
- return
- fi
- printf '\\n\t\t"%s",' "$1"
- shift
- done
-}
-
-as_html_list() {
- while [ "x" != "x$1" ]; do
- printf '\\n <script src="/%s"></script>' "$1"
- shift
- done
-}
-
-compute_scripts() {
- local DIRS="$1"
- local ROOT_SCRIPT="$2"
-
- local AVAILABLE="$(find $DIRS -name '[^.#]*.js')"
-
- awk -f compute_scripts.awk script_dependencies "$ROOT_SCRIPT" $AVAILABLE
-}
-
-build_main() {
- local ALL_SCRIPTDIRS='background html common content'
-
- local ALL_SCRIPTS_AVAILABLE="$(find $ALL_SCRIPTDIRS -name '[^.#]*.js')"
-
- local SCRIPT
- for SCRIPT in $ALL_SCRIPTS_AVAILABLE; do
- map_set SCRIPTS_UNUSED $(sanitize $SCRIPT) yes
- done
-
- local ROOT=background/main.js
- local SCRIPTS_BG="$( compute_scripts 'common/ background/' $ROOT)"
-
- local ROOT=content/main.js
- local SCRIPTS_CONTENT="$( compute_scripts 'common/ content/' $ROOT)"
-
- local ROOT=html/display-panel.js
- local SCRIPTS_POPUP="$( compute_scripts 'common/ html/' $ROOT)"
-
- local ROOT=html/options_main.js
- local SCRIPTS_OPTIONS="$( compute_scripts 'common/ html/' $ROOT)"
-
- local BGSCRIPTS="$( as_json_list $SCRIPTS_BG )"
- local CONTENTSCRIPTS="$( as_json_list $SCRIPTS_CONTENT )"
- local POPUPSCRIPTS="$( as_html_list $SCRIPTS_POPUP )"
- local OPTIONSSCRIPTS="$( as_html_list $SCRIPTS_OPTIONS )"
-
- for SCRIPT in $SCRIPTS_BG $SCRIPTS_CONTENT $SCRIPTS_POPUP $SCRIPTS_OPTIONS
- do
- map_del SCRIPTS_UNUSED $(sanitize $SCRIPT)
- done
-
- for DIR in $(find $ALL_SCRIPTDIRS -type d); do
- mkdir -p "$BUILDDIR"/$DIR
- done
-
- CHROMIUM_UPDATE_URL=''
- GECKO_APPLICATIONS=''
-
- if [ "x$UPDATE_URL" != x ]; then
- UPDATE_URL=",\n \"update_url\": \"$UPDATE_URL\""
- fi
-
- if [ "$BROWSER" = "chromium" ]; then
- CHROMIUM_UPDATE_URL="$UPDATE_URL"
- else
- GECKO_APPLICATIONS="\n\
- \"applications\": {\n\
- \"gecko\": {\n\
- \"id\": \"{6fe13369-88e9-440f-b837-5012fb3bedec}\",\n\
- \"strict_min_version\": \"60.0\"$UPDATE_URL\n\
- }\n\
- },"
- fi
-
- sed "\
-s^_GECKO_APPLICATIONS_^$GECKO_APPLICATIONS^
-s^_CHROMIUM_UPDATE_URL_^$CHROMIUM_UPDATE_URL^
-s^_BGSCRIPTS_^$BGSCRIPTS^
-s^_CONTENTSCRIPTS_^$CONTENTSCRIPTS^" \
- < manifest.json > "$BUILDDIR"/manifest.json
-
- ./process_html_file.sh html/display-panel.html |
- sed "s^_POPUPSCRIPTS_^$POPUPSCRIPTS^" \
- > "$BUILDDIR"/html/display-panel.html
-
- ./process_html_file.sh html/options.html |
- sed "s^_OPTIONSSCRIPTS_^$OPTIONSSCRIPTS^" \
- > "$BUILDDIR"/html/options.html
-
- for FILE in $ALL_SCRIPTS_AVAILABLE; do
- FILEKEY=$(sanitize "$FILE")
- if [ "x$(map_get SCRIPTS_UNUSED $FILEKEY)" = "xyes" ]; then
- printf 'WARNING! %s not used\n' "$FILE" >&2
- else
- awk -f compute_scripts.awk wrapped_code "$FILE" > "$BUILDDIR"/$FILE
- fi
- done
-
- ./write_exports_init.sh "$BROWSER" "$BUILDDIR" default_settings.json
-
- cp -r copyright licenses/ "$BUILDDIR"
- cp dummy "$BUILDDIR"
- cp html/*.css "$BUILDDIR"/html
- mkdir "$BUILDDIR"/icons
- cp icons/*.png "$BUILDDIR"/icons
-
- if [ "$BROWSER" = "chromium" ]; then
- for MOZILLA_FILE in $(find "$BUILDDIR" -name "MOZILLA_*"); do
- printf '\n' > "$MOZILLA_FILE"
- done
- fi
- if [ "$BROWSER" = "mozilla" ]; then
- for CHROMIUM_FILE in $(find "$BUILDDIR" -name "CHROMIUM_*"); do
- printf '\n' > "$CHROMIUM_FILE"
- done
- fi
-}
-
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:]')"
+ nawk -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
@@ -168,8 +49,22 @@ main() {
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
- build_main
+ cp -r README.md copyright licenses/ "$BUILDDIR"
}
main "$@"