@@ -441,6 +441,29 @@ all::
441441#
442442# When cross-compiling, define HOST_CPU as the canonical name of the CPU on
443443# which the built Git will run (for instance "x86_64").
444+ #
445+ # Define RUNTIME_PREFIX to configure Git to resolve its ancillary tooling and
446+ # support files relative to the location of the runtime binary, rather than
447+ # hard-coding them into the binary. Git installations built with RUNTIME_PREFIX
448+ # can be moved to arbitrary filesystem locations. RUNTIME_PREFIX also causes
449+ # Perl scripts to use a modified entry point header allowing them to resolve
450+ # support files at runtime.
451+ #
452+ # When using RUNTIME_PREFIX, define HAVE_BSD_KERN_PROC_SYSCTL if your platform
453+ # supports the KERN_PROC BSD sysctl function.
454+ #
455+ # When using RUNTIME_PREFIX, define PROCFS_EXECUTABLE_PATH if your platform
456+ # mounts a "procfs" filesystem capable of resolving the path of the current
457+ # executable. If defined, this must be the canonical path for the "procfs"
458+ # current executable path.
459+ #
460+ # When using RUNTIME_PREFIX, define HAVE_NS_GET_EXECUTABLE_PATH if your platform
461+ # supports calling _NSGetExecutablePath to retrieve the path of the running
462+ # executable.
463+ #
464+ # When using RUNTIME_PREFIX, define HAVE_WPGMPTR if your platform offers
465+ # the global variable _wpgmptr containing the absolute path of the current
466+ # executable (this is the case on Windows).
444467
445468GIT-VERSION-FILE : FORCE
446469 @$(SHELL_PATH ) ./GIT-VERSION-GEN
@@ -478,6 +501,8 @@ ARFLAGS = rcs
478501# mandir
479502# infodir
480503# htmldir
504+ # localedir
505+ # perllibdir
481506# This can help installing the suite in a relocatable way.
482507
483508prefix = $(HOME )
@@ -502,7 +527,9 @@ bindir_relative = $(patsubst $(prefix)/%,%,$(bindir))
502527mandir_relative = $(patsubst $(prefix ) /% ,% ,$(mandir ) )
503528infodir_relative = $(patsubst $(prefix ) /% ,% ,$(infodir ) )
504529gitexecdir_relative = $(patsubst $(prefix ) /% ,% ,$(gitexecdir ) )
530+ localedir_relative = $(patsubst $(prefix ) /% ,% ,$(localedir ) )
505531htmldir_relative = $(patsubst $(prefix ) /% ,% ,$(htmldir ) )
532+ perllibdir_relative = $(patsubst $(prefix ) /% ,% ,$(perllibdir ) )
506533
507534export prefix bindir sharedir sysconfdir gitwebdir perllibdir localedir
508535
@@ -1670,10 +1697,27 @@ ifdef HAVE_BSD_SYSCTL
16701697 BASIC_CFLAGS += -DHAVE_BSD_SYSCTL
16711698endif
16721699
1700+ ifdef HAVE_BSD_KERN_PROC_SYSCTL
1701+ BASIC_CFLAGS += -DHAVE_BSD_KERN_PROC_SYSCTL
1702+ endif
1703+
16731704ifdef HAVE_GETDELIM
16741705 BASIC_CFLAGS += -DHAVE_GETDELIM
16751706endif
16761707
1708+ ifneq ($(PROCFS_EXECUTABLE_PATH ) ,)
1709+ procfs_executable_path_SQ = $(subst ','\'',$(PROCFS_EXECUTABLE_PATH))
1710+ BASIC_CFLAGS += '-DPROCFS_EXECUTABLE_PATH="$(procfs_executable_path_SQ)"'
1711+ endif
1712+
1713+ ifdef HAVE_NS_GET_EXECUTABLE_PATH
1714+ BASIC_CFLAGS += -DHAVE_NS_GET_EXECUTABLE_PATH
1715+ endif
1716+
1717+ ifdef HAVE_WPGMPTR
1718+ BASIC_CFLAGS += -DHAVE_WPGMPTR
1719+ endif
1720+
16771721ifeq ($(TCLTK_PATH ) ,)
16781722NO_TCLTK = NoThanks
16791723endif
@@ -1758,11 +1802,13 @@ mandir_relative_SQ = $(subst ','\'',$(mandir_relative))
17581802infodir_relative_SQ = $(subst ','\'',$(infodir_relative ) )
17591803perllibdir_SQ = $(subst ','\'',$(perllibdir ) )
17601804localedir_SQ = $(subst ','\'',$(localedir ) )
1805+ localedir_relative_SQ = $(subst ','\'',$(localedir_relative ) )
17611806gitexecdir_SQ = $(subst ','\'',$(gitexecdir ) )
17621807gitexecdir_relative_SQ = $(subst ','\'',$(gitexecdir_relative ) )
17631808template_dir_SQ = $(subst ','\'',$(template_dir ) )
17641809htmldir_relative_SQ = $(subst ','\'',$(htmldir_relative ) )
17651810prefix_SQ = $(subst ','\'',$(prefix ) )
1811+ perllibdir_relative_SQ = $(subst ','\'',$(perllibdir_relative ) )
17661812gitwebdir_SQ = $(subst ','\'',$(gitwebdir ) )
17671813
17681814SHELL_PATH_SQ = $(subst ','\'',$(SHELL_PATH ) )
@@ -1773,6 +1819,31 @@ TCLTK_PATH_SQ = $(subst ','\'',$(TCLTK_PATH))
17731819DIFF_SQ = $(subst ','\'',$(DIFF ) )
17741820PERLLIB_EXTRA_SQ = $(subst ','\'',$(PERLLIB_EXTRA ) )
17751821
1822+ # RUNTIME_PREFIX's resolution logic requires resource paths to be expressed
1823+ # relative to each other and share an installation path.
1824+ #
1825+ # This is a dependency in:
1826+ # - Git's binary RUNTIME_PREFIX logic in (see "exec_cmd.c").
1827+ # - The runtime prefix Perl header (see
1828+ # "perl/header_templates/runtime_prefix.template.pl").
1829+ ifdef RUNTIME_PREFIX
1830+
1831+ ifneq ($(filter /% ,$(firstword $(gitexecdir_relative ) ) ) ,)
1832+ $(error RUNTIME_PREFIX requires a relative gitexecdir, not : $(gitexecdir ) )
1833+ endif
1834+
1835+ ifneq ($(filter /% ,$(firstword $(localedir_relative ) ) ) ,)
1836+ $(error RUNTIME_PREFIX requires a relative localedir, not : $(localedir ) )
1837+ endif
1838+
1839+ ifndef NO_PERL
1840+ ifneq ($(filter /% ,$(firstword $(perllibdir_relative ) ) ) ,)
1841+ $(error RUNTIME_PREFIX requires a relative perllibdir, not : $(perllibdir ) )
1842+ endif
1843+ endif
1844+
1845+ endif
1846+
17761847# We must filter out any object files from $(GITLIBS),
17771848# as it is typically used like:
17781849#
@@ -1993,34 +2064,64 @@ git.res: git.rc GIT-VERSION-FILE
19932064# This makes sure we depend on the NO_PERL setting itself.
19942065$(SCRIPT_PERL_GEN ) : GIT-BUILD-OPTIONS
19952066
1996- ifndef NO_PERL
1997- $(SCRIPT_PERL_GEN ) :
2067+ # Used for substitution in Perl modules. Disabled when using RUNTIME_PREFIX
2068+ # since the locale directory is injected.
2069+ perl_localedir_SQ = $(localedir_SQ )
19982070
2071+ ifndef NO_PERL
2072+ PERL_HEADER_TEMPLATE = perl/header_templates/fixed_prefix.template.pl
19992073PERL_DEFINES = $(PERL_PATH_SQ ) :$(PERLLIB_EXTRA_SQ ) :$(perllibdir_SQ )
2000- $(SCRIPT_PERL_GEN ) : % : % .perl GIT-PERL-DEFINES GIT-VERSION-FILE
2074+
2075+ PERL_DEFINES := $(PERL_PATH_SQ ) $(PERLLIB_EXTRA_SQ ) $(perllibdir_SQ )
2076+ PERL_DEFINES += $(RUNTIME_PREFIX )
2077+
2078+ # Support Perl runtime prefix. In this mode, a different header is installed
2079+ # into Perl scripts.
2080+ ifdef RUNTIME_PREFIX
2081+
2082+ PERL_HEADER_TEMPLATE = perl/header_templates/runtime_prefix.template.pl
2083+
2084+ # Don't export a fixed $(localedir) path; it will be resolved by the Perl header
2085+ # at runtime.
2086+ perl_localedir_SQ =
2087+
2088+ endif
2089+
2090+ PERL_DEFINES += $(gitexecdir ) $(perllibdir ) $(localedir )
2091+
2092+ $(SCRIPT_PERL_GEN ) : % : % .perl GIT-PERL-DEFINES GIT-PERL-HEADER GIT-VERSION-FILE
20012093 $(QUIET_GEN )$(RM ) $@ $@ + && \
2002- INSTLIBDIR=' $(perllibdir_SQ)' && \
2003- INSTLIBDIR_EXTRA=' $(PERLLIB_EXTRA_SQ)' && \
2004- INSTLIBDIR=" $$ INSTLIBDIR$$ {INSTLIBDIR_EXTRA:+:$$ INSTLIBDIR_EXTRA}" && \
20052094 sed -e ' 1{' \
20062095 -e ' s|#!.*perl|#!$(PERL_PATH_SQ)|' \
2007- -e ' h' \
2008- -e ' s=.*=use lib (split(/$(pathsep)/, $$ENV{GITPERLLIB} || "' " $$ INSTLIBDIR" ' "));=' \
2009- -e ' H' \
2010- -e ' x' \
2096+ -e ' rGIT-PERL-HEADER' \
2097+ -e ' G' \
20112098 -e ' }' \
20122099 -e ' s/@@GIT_VERSION@@/$(GIT_VERSION)/g' \
20132100 $< > $@ + && \
20142101 chmod +x $@ + && \
20152102 mv $@ + $@
20162103
2104+ PERL_DEFINES := $(subst $(space ) ,:,$(PERL_DEFINES ) )
20172105GIT-PERL-DEFINES : FORCE
20182106 @FLAGS=' $(PERL_DEFINES)' ; \
20192107 if test x" $$ FLAGS" ! = x" ` cat $@ 2> /dev/null` " ; then \
20202108 echo >&2 " * new perl-specific parameters" ; \
20212109 echo " $$ FLAGS" > $@ ; \
20222110 fi
20232111
2112+ GIT-PERL-HEADER : $(PERL_HEADER_TEMPLATE ) GIT-PERL-DEFINES Makefile
2113+ $(QUIET_GEN )$(RM ) $@ && \
2114+ INSTLIBDIR=' $(perllibdir_SQ)' && \
2115+ INSTLIBDIR_EXTRA=' $(PERLLIB_EXTRA_SQ)' && \
2116+ INSTLIBDIR=" $$ INSTLIBDIR$$ {INSTLIBDIR_EXTRA:+:$$ INSTLIBDIR_EXTRA}" && \
2117+ sed -e ' s=@@PATHSEP@@=$(pathsep)=g' \
2118+ -e " s=@@INSTLIBDIR@@=$$ INSTLIBDIR=g" \
2119+ -e ' s=@@PERLLIBDIR_REL@@=$(perllibdir_relative_SQ)=g' \
2120+ -e ' s=@@GITEXECDIR_REL@@=$(gitexecdir_relative_SQ)=g' \
2121+ -e ' s=@@LOCALEDIR_REL@@=$(localedir_relative_SQ)=g' \
2122+ $< > $@ + && \
2123+ mv $@ + $@
2124+
20242125.PHONY : perllibdir
20252126perllibdir :
20262127 @echo ' $(perllibdir_SQ)'
@@ -2168,6 +2269,7 @@ endif
21682269exec-cmd.sp exec-cmd.s exec-cmd.o : GIT-PREFIX
21692270exec-cmd.sp exec-cmd.s exec-cmd.o : EXTRA_CPPFLAGS = \
21702271 ' -DGIT_EXEC_PATH="$(gitexecdir_SQ)"' \
2272+ ' -DGIT_LOCALE_PATH="$(localedir_relative_SQ)"' \
21712273 ' -DBINDIR="$(bindir_relative_SQ)"' \
21722274 ' -DPREFIX="$(prefix_SQ)"'
21732275
@@ -2185,7 +2287,7 @@ attr.sp attr.s attr.o: EXTRA_CPPFLAGS = \
21852287
21862288gettext.sp gettext.s gettext.o : GIT-PREFIX
21872289gettext.sp gettext.s gettext.o : EXTRA_CPPFLAGS = \
2188- -DGIT_LOCALE_PATH=' "$(localedir_SQ )"'
2290+ -DGIT_LOCALE_PATH=' "$(localedir_relative_SQ )"'
21892291
21902292http-push.sp http.sp http-walker.sp remote-curl.sp imap-send.sp : SPARSE_FLAGS += \
21912293 -DCURL_DISABLE_TYPECHECK
@@ -2345,7 +2447,7 @@ endif
23452447
23462448perl/build/lib/% .pm : perl/% .pm
23472449 $(QUIET_GEN ) mkdir -p $(dir $@ ) && \
2348- sed -e ' s|@@LOCALEDIR@@|$(localedir_SQ )|g' \
2450+ sed -e ' s|@@LOCALEDIR@@|$(perl_localedir_SQ )|g' \
23492451 -e ' s|@@NO_PERL_CPAN_FALLBACKS@@|$(NO_PERL_CPAN_FALLBACKS_SQ)|g' \
23502452 < $< > $@
23512453
@@ -2803,7 +2905,7 @@ ifndef NO_TCLTK
28032905endif
28042906 $(RM) GIT-VERSION-FILE GIT-CFLAGS GIT-LDFLAGS GIT-BUILD-OPTIONS
28052907 $(RM) GIT-USER-AGENT GIT-PREFIX
2806- $(RM) GIT-SCRIPT-DEFINES GIT-PERL-DEFINES GIT-PYTHON-VARS
2908+ $(RM) GIT-SCRIPT-DEFINES GIT-PERL-DEFINES GIT-PERL-HEADER GIT- PYTHON-VARS
28072909
28082910.PHONY : all install profile-clean clean strip
28092911.PHONY : shell_compatibility_test please_set_SHELL_PATH_to_a_more_modern_shell
0 commit comments