Makefile: generate Perl header from template file

Currently, the generated Perl script headers are emitted by commands in the Makefile. This mechanism restricts options to introduce alternative header content, needed by Perl runtime prefix support, and obscures the origin of the Perl script header. Change the Makefile to generate a header by processing a template file and move the header content into the "perl/" subdirectory. The generated header content will now be stored in the "GIT-PERL-HEADER" file. This allows the content of the Perl header to be controlled by changing the path of the template in the Makefile. Signed-off-by: Dan Jacques <dnj@google.com> Thanks-to: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Thanks-to: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Dan Jacques committed Apr 10, 2018 at 11:05 UTC f6a0ad4be71a337e2e8787788a4b467204a4c4bb
3 files changed +18 -11
.gitignore
+1
@@ -3,6 +3,7 @@
3 /GIT-LDFLAGS
4 /GIT-PREFIX
5 /GIT-PERL-DEFINES
6 +/GIT-PERL-HEADER
7 /GIT-PYTHON-VARS
8 /GIT-SCRIPT-DEFINES
9 /GIT-USER-AGENT
Makefile
+16 -11
@@ -1987,20 +1987,15 @@ git.res: git.rc GIT-VERSION-FILE
1987 $(SCRIPT_PERL_GEN): GIT-BUILD-OPTIONS
1988
1989 ifndef NO_PERL
1990 -$(SCRIPT_PERL_GEN):
1991 -
1990 +PERL_HEADER_TEMPLATE = perl/header_templates/fixed_prefix.template.pl
1991 PERL_DEFINES = $(PERL_PATH_SQ):$(PERLLIB_EXTRA_SQ):$(perllibdir_SQ)
1993 -$(SCRIPT_PERL_GEN): % : %.perl GIT-PERL-DEFINES GIT-VERSION-FILE
1992 +
1993 +$(SCRIPT_PERL_GEN): % : %.perl GIT-PERL-DEFINES GIT-PERL-HEADER GIT-VERSION-FILE
1994 $(QUIET_GEN)$(RM) $@ $@+ && \
1995 - INSTLIBDIR='$(perllibdir_SQ)' && \
1996 - INSTLIBDIR_EXTRA='$(PERLLIB_EXTRA_SQ)' && \
1997 - INSTLIBDIR="$$INSTLIBDIR$${INSTLIBDIR_EXTRA:+:$$INSTLIBDIR_EXTRA}" && \
1995 sed -e '1{' \
1996 -e ' s|#!.*perl|#!$(PERL_PATH_SQ)|' \
2000 - -e ' h' \
2001 - -e ' s=.*=use lib (split(/$(pathsep)/, $$ENV{GITPERLLIB} || "'"$$INSTLIBDIR"'"));=' \
2002 - -e ' H' \
2003 - -e ' x' \
1997 + -e ' rGIT-PERL-HEADER' \
1998 + -e ' G' \
1999 -e '}' \
2000 -e 's/@@GIT_VERSION@@/$(GIT_VERSION)/g' \
2001 $< >$@+ && \
@@ -2014,6 +2009,16 @@ GIT-PERL-DEFINES: FORCE
2009 echo "$$FLAGS" >$@; \
2010 fi
2011
2012 +GIT-PERL-HEADER: $(PERL_HEADER_TEMPLATE) GIT-PERL-DEFINES Makefile
2013 + $(QUIET_GEN)$(RM) $@ && \
2014 + INSTLIBDIR='$(perllibdir_SQ)' && \
2015 + INSTLIBDIR_EXTRA='$(PERLLIB_EXTRA_SQ)' && \
2016 + INSTLIBDIR="$$INSTLIBDIR$${INSTLIBDIR_EXTRA:+:$$INSTLIBDIR_EXTRA}" && \
2017 + sed -e 's=@@PATHSEP@@=$(pathsep)=g' \
2018 + -e 's=@@INSTLIBDIR@@='$$INSTLIBDIR'=g' \
2019 + -e 's=@@PERLLIBDIR@@='$(perllibdir_SQ)'=g' \
2020 + $< >$@+ && \
2021 + mv $@+ $@
2022
2023 .PHONY: gitweb
2024 gitweb:
@@ -2793,7 +2798,7 @@ ifndef NO_TCLTK
2798 endif
2799 $(RM) GIT-VERSION-FILE GIT-CFLAGS GIT-LDFLAGS GIT-BUILD-OPTIONS
2800 $(RM) GIT-USER-AGENT GIT-PREFIX
2796 - $(RM) GIT-SCRIPT-DEFINES GIT-PERL-DEFINES GIT-PYTHON-VARS
2801 + $(RM) GIT-SCRIPT-DEFINES GIT-PERL-DEFINES GIT-PERL-HEADER GIT-PYTHON-VARS
2802
2803 .PHONY: all install profile-clean clean strip
2804 .PHONY: shell_compatibility_test please_set_SHELL_PATH_to_a_more_modern_shell
perl/header_templates/fixed_prefix.template.pl new
+1
@@ -0,0 +1 @@
1 +use lib (split(/@@PATHSEP@@/, $ENV{GITPERLLIB} || '@@INSTLIBDIR@@'));