Skip to content

Commit e4b4880

Browse files
pks-tgitster
authored andcommitted
Makefile: extract script to massage Perl scripts
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c2a3b84 commit e4b4880

File tree

3 files changed

+56
-15
lines changed

3 files changed

+56
-15
lines changed

Makefile

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2606,16 +2606,8 @@ endif
26062606

26072607
PERL_DEFINES += $(gitexecdir) $(perllibdir) $(localedir)
26082608

2609-
$(SCRIPT_PERL_GEN): % : %.perl GIT-PERL-DEFINES GIT-PERL-HEADER GIT-VERSION-FILE
2610-
$(QUIET_GEN) \
2611-
sed -e '1{' \
2612-
-e ' s|#!.*perl|#!$(PERL_PATH_SQ)|' \
2613-
-e ' r GIT-PERL-HEADER' \
2614-
-e ' G' \
2615-
-e '}' \
2616-
-e 's/@GIT_VERSION@/$(GIT_VERSION)/g' \
2617-
$< >$@+ && \
2618-
chmod +x $@+ && \
2609+
$(SCRIPT_PERL_GEN): % : %.perl generate-perl.sh GIT-PERL-DEFINES GIT-PERL-HEADER GIT-VERSION-FILE
2610+
$(QUIET_GEN)$(SHELL_PATH) generate-perl.sh ./GIT-BUILD-OPTIONS ./GIT-VERSION-FILE GIT-PERL-HEADER "$<" "$@+" && \
26192611
mv $@+ $@
26202612

26212613
PERL_DEFINES := $(subst $(space),:,$(PERL_DEFINES))

contrib/buildsystems/CMakeLists.txt

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -852,19 +852,41 @@ foreach(script ${git_shell_scripts})
852852
endforeach()
853853

854854
#perl scripts
855-
parse_makefile_for_scripts(git_perl_scripts "SCRIPT_PERL" ".perl")
855+
parse_makefile_for_scripts(git_perl_scripts "SCRIPT_PERL" "")
856856

857857
#create perl header
858858
file(STRINGS ${CMAKE_SOURCE_DIR}/perl/header_templates/fixed_prefix.template.pl perl_header )
859859
string(REPLACE "@PATHSEP@" ":" perl_header "${perl_header}")
860860
string(REPLACE "@INSTLIBDIR@" "${INSTLIBDIR}" perl_header "${perl_header}")
861+
file(WRITE ${CMAKE_BINARY_DIR}/PERL-HEADER ${perl_header})
862+
863+
add_custom_command(OUTPUT "${CMAKE_BINARY_DIR}/GIT-VERSION-FILE"
864+
COMMAND "${SH_EXE}" "${CMAKE_SOURCE_DIR}/GIT-VERSION-GEN"
865+
"${CMAKE_SOURCE_DIR}"
866+
"${CMAKE_SOURCE_DIR}/GIT-VERSION-FILE.in"
867+
"${CMAKE_BINARY_DIR}/GIT-VERSION-FILE"
868+
DEPENDS ${SH_EXE} "${CMAKE_SOURCE_DIR}/GIT-VERSION-GEN"
869+
"${CMAKE_SOURCE_DIR}/GIT-VERSION-FILE.in"
870+
VERBATIM)
861871

862872
foreach(script ${git_perl_scripts})
863-
file(STRINGS ${CMAKE_SOURCE_DIR}/${script}.perl content NEWLINE_CONSUME)
864-
string(REPLACE "#!/usr/bin/perl" "#!/usr/bin/perl\n${perl_header}\n" content "${content}")
865-
string(REPLACE "@GIT_VERSION@" "${PROJECT_VERSION}" content "${content}")
866-
file(WRITE ${CMAKE_BINARY_DIR}/${script} ${content})
873+
string(REPLACE ".perl" "" perl_gen_path "${script}")
874+
875+
add_custom_command(OUTPUT "${CMAKE_BINARY_DIR}/${perl_gen_path}"
876+
COMMAND "${SH_EXE}" "${CMAKE_SOURCE_DIR}/generate-perl.sh"
877+
"${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS"
878+
"${CMAKE_BINARY_DIR}/GIT-VERSION-FILE"
879+
"${CMAKE_BINARY_DIR}/PERL-HEADER"
880+
"${CMAKE_SOURCE_DIR}/${script}"
881+
"${CMAKE_BINARY_DIR}/${perl_gen_path}"
882+
DEPENDS "${CMAKE_SOURCE_DIR}/generate-perl.sh"
883+
"${CMAKE_SOURCE_DIR}/${script}"
884+
"${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS"
885+
"${CMAKE_BINARY_DIR}/GIT-VERSION-FILE"
886+
VERBATIM)
887+
list(APPEND perl_gen ${CMAKE_BINARY_DIR}/${perl_gen_path})
867888
endforeach()
889+
add_custom_target(perl-gen ALL DEPENDS ${perl_gen})
868890

869891
#python script
870892
file(STRINGS ${CMAKE_SOURCE_DIR}/git-p4.py content NEWLINE_CONSUME)

generate-perl.sh

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/bin/sh
2+
3+
set -e
4+
5+
if test $# -ne 5
6+
then
7+
echo >&2 "USAGE: $0 <GIT_BUILD_OPTIONS> <GIT_VERSION_FILE> <PERL_HEADER> <INPUT> <OUTPUT>"
8+
exit 1
9+
fi
10+
11+
GIT_BUILD_OPTIONS="$1"
12+
GIT_VERSION_FILE="$2"
13+
PERL_HEADER="$3"
14+
INPUT="$4"
15+
OUTPUT="$5"
16+
17+
. "$GIT_BUILD_OPTIONS"
18+
. "$GIT_VERSION_FILE"
19+
20+
sed -e '1{' \
21+
-e " s|#!.*perl|#!$PERL_PATH|" \
22+
-e " r $PERL_HEADER" \
23+
-e ' G' \
24+
-e '}' \
25+
-e "s/@GIT_VERSION@/$GIT_VERSION/g" \
26+
"$INPUT" >"$OUTPUT"
27+
chmod a+x "$OUTPUT"

0 commit comments

Comments
 (0)