diff mbox series

[RFC,11/21] Makefile: extract script to massage Perl scripts

Message ID ccfa97bd3db21f8868070503651e40e80ccb17b4.1727881164.git.ps@pks.im (mailing list archive)
State Superseded
Headers show
Series Modernize the build system | expand

Commit Message

Patrick Steinhardt Oct. 2, 2024, 3:16 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 de6426a684..f582ccdc98 100644
--- a/Makefile
+++ b/Makefile
@@ -2580,15 +2580,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 0000000000..b9e04d6f42
--- /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"