]> git.ipfire.org Git - thirdparty/git.git/commitdiff
Makefile: extract script to massage Perl scripts
authorPatrick Steinhardt <ps@pks.im>
Fri, 6 Dec 2024 13:24:43 +0000 (14:24 +0100)
committerJunio C Hamano <gitster@pobox.com>
Fri, 6 Dec 2024 22:52:09 +0000 (07:52 +0900)
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>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Makefile
contrib/buildsystems/CMakeLists.txt
generate-perl.sh [new file with mode: 0755]

index 0e289d1dbcbfa48e4566fb3e6d4eedd87ae2d141..e33c5b966c7c6cc9ea5d8a072458f11221a21513 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -2606,16 +2606,8 @@ 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 $@+ && \
+$(SCRIPT_PERL_GEN): % : %.perl generate-perl.sh GIT-PERL-DEFINES GIT-PERL-HEADER GIT-VERSION-FILE
+       $(QUIET_GEN)$(SHELL_PATH) generate-perl.sh ./GIT-BUILD-OPTIONS ./GIT-VERSION-FILE GIT-PERL-HEADER "$<" "$@+" && \
        mv $@+ $@
 
 PERL_DEFINES := $(subst $(space),:,$(PERL_DEFINES))
index ecaae8965cd43d4a5a36201b8760296b52147dc2..5cb9a209366e80ef141c6349fea9ddedb2f83d1a 100644 (file)
@@ -852,19 +852,41 @@ foreach(script ${git_shell_scripts})
 endforeach()
 
 #perl scripts
-parse_makefile_for_scripts(git_perl_scripts "SCRIPT_PERL" ".perl")
+parse_makefile_for_scripts(git_perl_scripts "SCRIPT_PERL" "")
 
 #create perl header
 file(STRINGS ${CMAKE_SOURCE_DIR}/perl/header_templates/fixed_prefix.template.pl perl_header )
 string(REPLACE "@PATHSEP@" ":" perl_header "${perl_header}")
 string(REPLACE "@INSTLIBDIR@" "${INSTLIBDIR}" perl_header "${perl_header}")
+file(WRITE ${CMAKE_BINARY_DIR}/PERL-HEADER ${perl_header})
+
+add_custom_command(OUTPUT "${CMAKE_BINARY_DIR}/GIT-VERSION-FILE"
+       COMMAND "${SH_EXE}" "${CMAKE_SOURCE_DIR}/GIT-VERSION-GEN"
+               "${CMAKE_SOURCE_DIR}"
+               "${CMAKE_SOURCE_DIR}/GIT-VERSION-FILE.in"
+               "${CMAKE_BINARY_DIR}/GIT-VERSION-FILE"
+       DEPENDS ${SH_EXE} "${CMAKE_SOURCE_DIR}/GIT-VERSION-GEN"
+               "${CMAKE_SOURCE_DIR}/GIT-VERSION-FILE.in"
+       VERBATIM)
 
 foreach(script ${git_perl_scripts})
-       file(STRINGS ${CMAKE_SOURCE_DIR}/${script}.perl content NEWLINE_CONSUME)
-       string(REPLACE "#!/usr/bin/perl" "#!/usr/bin/perl\n${perl_header}\n" content "${content}")
-       string(REPLACE "@GIT_VERSION@" "${PROJECT_VERSION}" content "${content}")
-       file(WRITE ${CMAKE_BINARY_DIR}/${script} ${content})
+       string(REPLACE ".perl" "" perl_gen_path "${script}")
+
+       add_custom_command(OUTPUT "${CMAKE_BINARY_DIR}/${perl_gen_path}"
+               COMMAND "${SH_EXE}" "${CMAKE_SOURCE_DIR}/generate-perl.sh"
+                       "${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS"
+                       "${CMAKE_BINARY_DIR}/GIT-VERSION-FILE"
+                       "${CMAKE_BINARY_DIR}/PERL-HEADER"
+                       "${CMAKE_SOURCE_DIR}/${script}"
+                       "${CMAKE_BINARY_DIR}/${perl_gen_path}"
+               DEPENDS "${CMAKE_SOURCE_DIR}/generate-perl.sh"
+                       "${CMAKE_SOURCE_DIR}/${script}"
+                       "${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS"
+                       "${CMAKE_BINARY_DIR}/GIT-VERSION-FILE"
+               VERBATIM)
+       list(APPEND perl_gen ${CMAKE_BINARY_DIR}/${perl_gen_path})
 endforeach()
+add_custom_target(perl-gen ALL DEPENDS ${perl_gen})
 
 #python script
 file(STRINGS ${CMAKE_SOURCE_DIR}/git-p4.py content NEWLINE_CONSUME)
diff --git a/generate-perl.sh b/generate-perl.sh
new file mode 100755 (executable)
index 0000000..9507252
--- /dev/null
@@ -0,0 +1,27 @@
+#!/bin/sh
+
+set -e
+
+if test $# -ne 5
+then
+       echo >&2 "USAGE: $0 <GIT_BUILD_OPTIONS> <GIT_VERSION_FILE> <PERL_HEADER> <INPUT> <OUTPUT>"
+       exit 1
+fi
+
+GIT_BUILD_OPTIONS="$1"
+GIT_VERSION_FILE="$2"
+PERL_HEADER="$3"
+INPUT="$4"
+OUTPUT="$5"
+
+. "$GIT_BUILD_OPTIONS"
+. "$GIT_VERSION_FILE"
+
+sed -e '1{' \
+    -e "       s|#!.*perl|#!$PERL_PATH|" \
+    -e "       r $PERL_HEADER" \
+    -e '       G' \
+    -e '}' \
+    -e "s/@GIT_VERSION@/$GIT_VERSION/g" \
+    "$INPUT" >"$OUTPUT"
+chmod a+x "$OUTPUT"