From e0c94ac47a4ec4378f1341158d82a6af3ffe4c96 Mon Sep 17 00:00:00 2001 From: jahoti Date: Wed, 13 Oct 2021 00:00:00 +0000 Subject: Add VPATH and Haketilo version to the makefile as part of configure. --- Makefile.in | 11 +++-------- build.sh | 4 ++-- configure | 12 ++++-------- shell_utils.sh | 13 +++++++++++++ upload_amo.sh | 13 ------------- write_makefile.sh | 13 +++++++++++-- 6 files changed, 33 insertions(+), 33 deletions(-) diff --git a/Makefile.in b/Makefile.in index dcc1863..7a0e0e5 100644 --- a/Makefile.in +++ b/Makefile.in @@ -12,6 +12,8 @@ # CC0 1.0 Universal License for more details. SHELL = /bin/sh +VPATH = <> +VERSION = <> # Configuration goes here @@ -50,12 +52,5 @@ distclean: clean Makefile: config.status Makefile.in record.conf ./config.status -config.status: +config.status: record.conf cp "$(srcdir)"/write_makefile.sh config.status - -Makefile.in: - cp "$(srcdir)"/Makefile.in . - -record.conf: - @echo File record.conf not found; rebuild by running configure - @exit 1 diff --git a/build.sh b/build.sh index d3307d4..97d9c6e 100755 --- a/build.sh +++ b/build.sh @@ -3,8 +3,6 @@ # Copyright (C) 2021 Wojtek Kosior # Redistribution terms are gathered in the `copyright' file. -. ./shell_utils.sh - handle_export_line() { if [ "x$1" = "xEXPORTS_START" ]; then if [ "$STATE" = "before_block" ]; then @@ -317,6 +315,8 @@ main() { fi UPDATE_URL="$3" + + . ./shell_utils.sh build_main } diff --git a/configure b/configure index 3e12cbb..98d2ec5 100755 --- a/configure +++ b/configure @@ -59,17 +59,13 @@ case "${TARGET:-all}" in *) echo Invalid target "'$1'" >&2; exit 2;; esac -# Write record.conf -echo UPDATE_URL = "$UPDATE_URL" > record.conf +# Write record.conf (LEAVE SRCDIR FIRST) +echo srcdir = "$SRCDIR" > record.conf echo default_target = "$TARGET" >> record.conf -echo srcdir = "$SRCDIR" >> record.conf +echo UPDATE_URL = "$UPDATE_URL" >> record.conf -# Prepare environment for and run write_makefile.sh (as config.status) -if [ ! -e Makefile.in ]; then - cp "$SRCDIR"/Makefile.in . -fi - +# Prepare and run write_makefile.sh (as config.status) if [ ! -e config.status ]; then cp "$SRCDIR"/write_makefile.sh config.status fi diff --git a/shell_utils.sh b/shell_utils.sh index 30dfead..5fd24ff 100644 --- a/shell_utils.sh +++ b/shell_utils.sh @@ -43,3 +43,16 @@ map_del() { sanitize() { echo "$1" | tr /.- _ } + +escape_regex_special() { + ech "$1" | sed 's/\([]\.*?{},()[-]\)/\\\1/g' +} + +# Note: We don't actually parse JSON. We extract needed keys with sed regexes +# which does not work in the general case but is sufficient for now. +get_json_key() { + local KEY_REG="$(escape_regex_special "$1")" + ech "$2" | + sed 's/\(.*"'"$KEY_REG"'"[[:space:]]*:[[:space:]]*"\([^"]*\)"\)\?.*/\2/' | + grep . | head -1 +} diff --git a/upload_amo.sh b/upload_amo.sh index 2d16c63..2f519c8 100755 --- a/upload_amo.sh +++ b/upload_amo.sh @@ -40,19 +40,6 @@ sha256hmac() { base64url "$(ech "$2" | openssl dgst -sha256 -hmac "$1" -binary -)" } -escape_regex_special() { - ech "$1" | sed 's/\([]\.*?{},()[-]\)/\\\1/g' -} - -# Note: We don't actually parse JSON. We extract needed keys with sed regexes -# which does not work in the general case but is sufficient for now. -get_json_key() { - local KEY_REG="$(escape_regex_special "$1")" - ech "$2" | - sed 's/\(.*"'"$KEY_REG"'"[[:space:]]*:[[:space:]]*"\([^"]*\)"\)\?.*/\2/' | - grep . | head -1 -} - get_manifest_key() { get_json_key "$1" "$(unzip -p "$2" manifest.json)" } diff --git a/write_makefile.sh b/write_makefile.sh index 118635b..6aca660 100755 --- a/write_makefile.sh +++ b/write_makefile.sh @@ -14,8 +14,17 @@ # CC0 1.0 Universal License for more details. if [ ! -e record.conf ]; then - echo "Record of configuration 'record.conf' does not exist." >&2 + echo Record of configuration "'record.conf'" does not exist. >&2 exit 1 +elif [ "$(head -n 1 record.conf | cut -c -9)x" != "srcdir = x" ]; then + echo Record of configuration "'record.conf'" is invalid. >&2 + exit 2 fi -sed '/^# Configuration goes here$/r record.conf' < Makefile.in > Makefile +SRCDIR="$(head -n 1 record.conf | cut -c 10-)" +. "$SRCDIR"/shell_utils.sh +VERSION=$(get_json_key version "$(cat "$SRCDIR"/manifest.json)") + +sed '/^# Configuration goes here$/r record.conf +s|<>|'"$SRCDIR"'| +s/<>/'$VERSION/ < "$SRCDIR"/Makefile.in > Makefile -- cgit v1.2.3