diff mbox series

[RFC,v2,13/24] Makefile: extract script to massage Perl scripts

Message ID 7f567d7ce237460e37b8eae29d14c453f95f3e94.1728485139.git.ps@pks.im (mailing list archive)
State New
Headers show
Series Modernize our build system | expand

Commit Message

Patrick Steinhardt Oct. 9, 2024, 2:56 p.m. UTC
Extract the script to inject various build-time parameters into our Perl
scripts into a standalone script. This is done such that we can reuse it
in other build systems.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 Makefile         | 10 +---------
 generate-perl.sh | 22 ++++++++++++++++++++++
 2 files changed, 23 insertions(+), 9 deletions(-)
 create mode 100755 generate-perl.sh
diff mbox series

Patch

diff --git a/Makefile b/Makefile
index 0d542c58f3a..50fbc4f29d0 100644
--- a/Makefile
+++ b/Makefile
@@ -2605,15 +2605,7 @@  endif
 PERL_DEFINES += $(gitexecdir) $(perllibdir) $(localedir)
 
 $(SCRIPT_PERL_GEN): % : %.perl GIT-PERL-DEFINES GIT-PERL-HEADER GIT-VERSION-FILE
-	$(QUIET_GEN) \
-	sed -e '1{' \
-	    -e '	s|#!.*perl|#!$(PERL_PATH_SQ)|' \
-	    -e '	r GIT-PERL-HEADER' \
-	    -e '	G' \
-	    -e '}' \
-	    -e 's/@@GIT_VERSION@@/$(GIT_VERSION)/g' \
-	    $< >$@+ && \
-	chmod +x $@+ && \
+	$(QUIET_GEN)$(SHELL_PATH) generate-perl.sh $(GIT_VERSION) GIT-PERL-HEADER "$(PERL_PATH_SQ)" "$<" "$@+" && \
 	mv $@+ $@
 
 PERL_DEFINES := $(subst $(space),:,$(PERL_DEFINES))
diff --git a/generate-perl.sh b/generate-perl.sh
new file mode 100755
index 00000000000..b9e04d6f42a
--- /dev/null
+++ b/generate-perl.sh
@@ -0,0 +1,22 @@ 
+#!/bin/sh
+
+if test $# -ne 5
+then
+	echo "USAGE: $0 <GIT_VERSION> <PERL_HEADER> <PERL_PATH> <PERL_SCRIPT> <OUT>" >&2
+	exit 1
+fi
+
+GIT_VERSION="$1"
+PERL_HEADER="$2"
+PERL_PATH="$3"
+PERL_SCRIPT="$4"
+OUT="$5"
+
+sed -e '1{' \
+    -e "	s|#!.*perl|#!$PERL_PATH|" \
+    -e "	r $PERL_HEADER" \
+    -e '	G' \
+    -e '}' \
+    -e "s/@@GIT_VERSION@@/$GIT_VERSION/g" \
+    "$PERL_SCRIPT" >"$OUT"
+chmod a+x "$OUT"