Git fork

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 <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

authored by

Patrick Steinhardt and committed by
Junio C Hamano
e4b48804 c2a3b847

+56 -15
+2 -10
Makefile
··· 2606 2606 2607 2607 PERL_DEFINES += $(gitexecdir) $(perllibdir) $(localedir) 2608 2608 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 "$<" "$@+" && \ 2619 2611 mv $@+ $@ 2620 2612 2621 2613 PERL_DEFINES := $(subst $(space),:,$(PERL_DEFINES))
+27 -5
contrib/buildsystems/CMakeLists.txt
··· 852 852 endforeach() 853 853 854 854 #perl scripts 855 - parse_makefile_for_scripts(git_perl_scripts "SCRIPT_PERL" ".perl") 855 + parse_makefile_for_scripts(git_perl_scripts "SCRIPT_PERL" "") 856 856 857 857 #create perl header 858 858 file(STRINGS ${CMAKE_SOURCE_DIR}/perl/header_templates/fixed_prefix.template.pl perl_header ) 859 859 string(REPLACE "@PATHSEP@" ":" perl_header "${perl_header}") 860 860 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) 861 871 862 872 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}) 867 888 endforeach() 889 + add_custom_target(perl-gen ALL DEPENDS ${perl_gen}) 868 890 869 891 #python script 870 892 file(STRINGS ${CMAKE_SOURCE_DIR}/git-p4.py content NEWLINE_CONSUME)
+27
generate-perl.sh
··· 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"