Skip to content

Commit ccfba9e

Browse files
pks-tgitster
authored andcommitted
Makefile: use "generate-perl.sh" to massage Perl library
Extend "generate-perl.sh" such that it knows to also massage the Perl library files. There are two major differences: - We do not read in the Perl header. This is handled by matching on whether or not we have a Perl shebang. - We substitute some more variables, which we read in via our GIT-BUILD-OPTIONS. Adapt both our Makefile and the CMake build instructions to use this. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e4b4880 commit ccfba9e

File tree

4 files changed

+27
-22
lines changed

4 files changed

+27
-22
lines changed

GIT-BUILD-OPTIONS.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
SHELL_PATH=@SHELL_PATH@
22
TEST_SHELL_PATH=@TEST_SHELL_PATH@
33
PERL_PATH=@PERL_PATH@
4+
PERL_LOCALEDIR=@PERL_LOCALEDIR@
5+
NO_PERL_CPAN_FALLBACKS=@NO_PERL_CPAN_FALLBACKS@
46
DIFF=@DIFF@
57
PYTHON_PATH=@PYTHON_PATH@
68
TAR=@TAR@

Makefile

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3095,13 +3095,9 @@ endif
30953095
NO_PERL_CPAN_FALLBACKS_SQ = $(subst ','\'',$(NO_PERL_CPAN_FALLBACKS))
30963096
endif
30973097

3098-
perl/build/lib/%.pm: perl/%.pm GIT-PERL-DEFINES
3098+
perl/build/lib/%.pm: perl/%.pm generate-perl.sh GIT-BUILD-OPTIONS GIT-VERSION-FILE GIT-PERL-DEFINES
30993099
$(call mkdir_p_parent_template)
3100-
$(QUIET_GEN) \
3101-
sed -e 's|@LOCALEDIR@|$(perl_localedir_SQ)|g' \
3102-
-e 's|@NO_GETTEXT@|$(NO_GETTEXT_SQ)|g' \
3103-
-e 's|@NO_PERL_CPAN_FALLBACKS@|$(NO_PERL_CPAN_FALLBACKS_SQ)|g' \
3104-
< $< > $@
3100+
$(QUIET_GEN)$(SHELL_PATH) generate-perl.sh ./GIT-BUILD-OPTIONS ./GIT-VERSION-FILE GIT-PERL-HEADER "$<" "$@"
31053101

31063102
perl/build/man/man3/Git.3pm: perl/Git.pm
31073103
$(call mkdir_p_parent_template)
@@ -3168,6 +3164,8 @@ GIT-BUILD-OPTIONS: FORCE
31683164
-e "s|@SHELL_PATH@|\'$(SHELL_PATH_SQ)\'|" \
31693165
-e "s|@TEST_SHELL_PATH@|\'$(TEST_SHELL_PATH_SQ)\'|" \
31703166
-e "s|@PERL_PATH@|\'$(PERL_PATH_SQ)\'|" \
3167+
-e "s|@PERL_LOCALEDIR@|\'$(perl_localedir_SQ)\'|" \
3168+
-e "s|@NO_PERL_CPAN_FALLBACKS@|\'$(NO_PERL_CPAN_FALLBACKS_SQ)\'|" \
31713169
-e "s|@DIFF@|\'$(DIFF)\'|" \
31723170
-e "s|@PYTHON_PATH@|\'$(PYTHON_PATH_SQ)\'|" \
31733171
-e "s|@TAR@|\'$(TAR)\'|" \

contrib/buildsystems/CMakeLists.txt

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -853,6 +853,9 @@ endforeach()
853853

854854
#perl scripts
855855
parse_makefile_for_scripts(git_perl_scripts "SCRIPT_PERL" "")
856+
#perl modules
857+
file(GLOB_RECURSE perl_modules "${CMAKE_SOURCE_DIR}/perl/*.pm")
858+
list(TRANSFORM perl_modules REPLACE "${CMAKE_SOURCE_DIR}/" "")
856859

857860
#create perl header
858861
file(STRINGS ${CMAKE_SOURCE_DIR}/perl/header_templates/fixed_prefix.template.pl perl_header )
@@ -869,9 +872,12 @@ add_custom_command(OUTPUT "${CMAKE_BINARY_DIR}/GIT-VERSION-FILE"
869872
"${CMAKE_SOURCE_DIR}/GIT-VERSION-FILE.in"
870873
VERBATIM)
871874

872-
foreach(script ${git_perl_scripts})
875+
foreach(script ${git_perl_scripts} ${perl_modules})
873876
string(REPLACE ".perl" "" perl_gen_path "${script}")
874877

878+
get_filename_component(perl_gen_dir "${perl_gen_path}" DIRECTORY)
879+
file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/${perl_gen_dir}")
880+
875881
add_custom_command(OUTPUT "${CMAKE_BINARY_DIR}/${perl_gen_path}"
876882
COMMAND "${SH_EXE}" "${CMAKE_SOURCE_DIR}/generate-perl.sh"
877883
"${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS"
@@ -893,19 +899,6 @@ file(STRINGS ${CMAKE_SOURCE_DIR}/git-p4.py content NEWLINE_CONSUME)
893899
string(REPLACE "#!/usr/bin/env python" "#!/usr/bin/python" content "${content}")
894900
file(WRITE ${CMAKE_BINARY_DIR}/git-p4 ${content})
895901

896-
#perl modules
897-
file(GLOB_RECURSE perl_modules "${CMAKE_SOURCE_DIR}/perl/*.pm")
898-
899-
foreach(pm ${perl_modules})
900-
string(REPLACE "${CMAKE_SOURCE_DIR}/perl/" "" file_path ${pm})
901-
file(STRINGS ${pm} content NEWLINE_CONSUME)
902-
string(REPLACE "@LOCALEDIR@" "${LOCALEDIR}" content "${content}")
903-
string(REPLACE "@NO_PERL_CPAN_FALLBACKS@" "" content "${content}")
904-
file(WRITE ${CMAKE_BINARY_DIR}/perl/build/lib/${file_path} ${content})
905-
#test-lib.sh requires perl/build/lib to be the build directory of perl modules
906-
endforeach()
907-
908-
909902
#templates
910903
file(GLOB templates "${CMAKE_SOURCE_DIR}/templates/*")
911904
list(TRANSFORM templates REPLACE "${CMAKE_SOURCE_DIR}/templates/" "")
@@ -1155,6 +1148,8 @@ file(STRINGS ${CMAKE_SOURCE_DIR}/GIT-BUILD-OPTIONS.in git_build_options NEWLINE_
11551148
string(REPLACE "@SHELL_PATH@" "'${SHELL_PATH}'" git_build_options "${git_build_options}")
11561149
string(REPLACE "@TEST_SHELL_PATH@" "'${TEST_SHELL_PATH}'" git_build_options "${git_build_options}")
11571150
string(REPLACE "@PERL_PATH@" "'${PERL_PATH}'" git_build_options "${git_build_options}")
1151+
string(REPLACE "@PERL_LOCALEDIR@" "'${LOCALEDIR}'" git_build_options "${git_build_options}")
1152+
string(REPLACE "@NO_PERL_CPAN_FALLBACKS@" "" git_build_options "${git_build_options}")
11581153
string(REPLACE "@DIFF@" "'${DIFF}'" git_build_options "${git_build_options}")
11591154
string(REPLACE "@PYTHON_PATH@" "'${PYTHON_PATH}'" git_build_options "${git_build_options}")
11601155
string(REPLACE "@TAR@" "'${TAR}'" git_build_options "${git_build_options}")

generate-perl.sh

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,20 @@ OUTPUT="$5"
1818
. "$GIT_VERSION_FILE"
1919

2020
sed -e '1{' \
21+
-e " /^#!.*perl/!b" \
2122
-e " s|#!.*perl|#!$PERL_PATH|" \
2223
-e " r $PERL_HEADER" \
2324
-e ' G' \
2425
-e '}' \
25-
-e "s/@GIT_VERSION@/$GIT_VERSION/g" \
26+
-e "s|@GIT_VERSION@|$GIT_VERSION|g" \
27+
-e "s|@LOCALEDIR@|$PERL_LOCALEDIR|g" \
28+
-e "s|@NO_GETTEXT@|$NO_GETTEXT|g" \
29+
-e "s|@NO_PERL_CPAN_FALLBACKS@|$NO_PERL_CPAN_FALLBACKS|g" \
2630
"$INPUT" >"$OUTPUT"
27-
chmod a+x "$OUTPUT"
31+
32+
case "$INPUT" in
33+
*.perl)
34+
chmod a+x "$OUTPUT";;
35+
*)
36+
;;
37+
esac

0 commit comments

Comments
 (0)