@@ -434,6 +434,29 @@ all::
434434#
435435# When cross-compiling, define HOST_CPU as the canonical name of the CPU on
436436# which the built Git will run (for instance "x86_64").
437+ #
438+ # Define RUNTIME_PREFIX to configure Git to resolve its ancillary tooling and
439+ # support files relative to the location of the runtime binary, rather than
440+ # hard-coding them into the binary. Git installations built with RUNTIME_PREFIX
441+ # can be moved to arbitrary filesystem locations. RUNTIME_PREFIX also causes
442+ # Perl scripts to use a modified entry point header allowing them to resolve
443+ # support files at runtime.
444+ #
445+ # When using RUNTIME_PREFIX, define HAVE_BSD_KERN_PROC_SYSCTL if your platform
446+ # supports the KERN_PROC BSD sysctl function.
447+ #
448+ # When using RUNTIME_PREFIX, define PROCFS_EXECUTABLE_PATH if your platform
449+ # mounts a "procfs" filesystem capable of resolving the path of the current
450+ # executable. If defined, this must be the canonical path for the "procfs"
451+ # current executable path.
452+ #
453+ # When using RUNTIME_PREFIX, define HAVE_NS_GET_EXECUTABLE_PATH if your platform
454+ # supports calling _NSGetExecutablePath to retrieve the path of the running
455+ # executable.
456+ #
457+ # When using RUNTIME_PREFIX, define HAVE_WPGMPTR if your platform offers
458+ # the global variable _wpgmptr containing the absolute path of the current
459+ # executable (this is the case on Windows).
437460
438461GIT-VERSION-FILE : FORCE
439462 @$(SHELL_PATH ) ./GIT-VERSION-GEN
@@ -471,6 +494,8 @@ ARFLAGS = rcs
471494# mandir
472495# infodir
473496# htmldir
497+ # localedir
498+ # perllibdir
474499# This can help installing the suite in a relocatable way.
475500
476501prefix = $(HOME )
@@ -492,10 +517,12 @@ lib = lib
492517# DESTDIR =
493518pathsep = :
494519
495- localedir_relative = $(patsubst $(prefix ) /% ,% ,$(localedir ) )
496520mandir_relative = $(patsubst $(prefix ) /% ,% ,$(mandir ) )
497521infodir_relative = $(patsubst $(prefix ) /% ,% ,$(infodir ) )
522+ gitexecdir_relative = $(patsubst $(prefix ) /% ,% ,$(gitexecdir ) )
523+ localedir_relative = $(patsubst $(prefix ) /% ,% ,$(localedir ) )
498524htmldir_relative = $(patsubst $(prefix ) /% ,% ,$(htmldir ) )
525+ perllibdir_relative = $(patsubst $(prefix ) /% ,% ,$(perllibdir ) )
499526
500527export prefix bindir sharedir sysconfdir gitwebdir perllibdir localedir
501528
@@ -1654,10 +1681,27 @@ ifdef HAVE_BSD_SYSCTL
16541681 BASIC_CFLAGS += -DHAVE_BSD_SYSCTL
16551682endif
16561683
1684+ ifdef HAVE_BSD_KERN_PROC_SYSCTL
1685+ BASIC_CFLAGS += -DHAVE_BSD_KERN_PROC_SYSCTL
1686+ endif
1687+
16571688ifdef HAVE_GETDELIM
16581689 BASIC_CFLAGS += -DHAVE_GETDELIM
16591690endif
16601691
1692+ ifneq ($(PROCFS_EXECUTABLE_PATH ) ,)
1693+ procfs_executable_path_SQ = $(subst ','\'',$(PROCFS_EXECUTABLE_PATH))
1694+ BASIC_CFLAGS += '-DPROCFS_EXECUTABLE_PATH="$(procfs_executable_path_SQ)"'
1695+ endif
1696+
1697+ ifdef HAVE_NS_GET_EXECUTABLE_PATH
1698+ BASIC_CFLAGS += -DHAVE_NS_GET_EXECUTABLE_PATH
1699+ endif
1700+
1701+ ifdef HAVE_WPGMPTR
1702+ BASIC_CFLAGS += -DHAVE_WPGMPTR
1703+ endif
1704+
16611705ifeq ($(TCLTK_PATH ) ,)
16621706NO_TCLTK = NoThanks
16631707endif
@@ -1747,6 +1791,7 @@ gitexecdir_SQ = $(subst ','\'',$(gitexecdir))
17471791template_dir_SQ = $(subst ','\'',$(template_dir ) )
17481792htmldir_relative_SQ = $(subst ','\'',$(htmldir_relative ) )
17491793prefix_SQ = $(subst ','\'',$(prefix ) )
1794+ perllibdir_relative_SQ = $(subst ','\'',$(perllibdir_relative ) )
17501795gitwebdir_SQ = $(subst ','\'',$(gitwebdir ) )
17511796
17521797SHELL_PATH_SQ = $(subst ','\'',$(SHELL_PATH ) )
@@ -1757,6 +1802,31 @@ TCLTK_PATH_SQ = $(subst ','\'',$(TCLTK_PATH))
17571802DIFF_SQ = $(subst ','\'',$(DIFF ) )
17581803PERLLIB_EXTRA_SQ = $(subst ','\'',$(PERLLIB_EXTRA ) )
17591804
1805+ # RUNTIME_PREFIX's resolution logic requires resource paths to be expressed
1806+ # relative to each other and share an installation path.
1807+ #
1808+ # This is a dependency in:
1809+ # - Git's binary RUNTIME_PREFIX logic in (see "exec_cmd.c").
1810+ # - The runtime prefix Perl header (see
1811+ # "perl/header_templates/runtime_prefix.template.pl").
1812+ ifdef RUNTIME_PREFIX
1813+
1814+ ifneq ($(filter /% ,$(firstword $(gitexecdir_relative ) ) ) ,)
1815+ $(error RUNTIME_PREFIX requires a relative gitexecdir, not : $(gitexecdir ) )
1816+ endif
1817+
1818+ ifneq ($(filter /% ,$(firstword $(localedir_relative ) ) ) ,)
1819+ $(error RUNTIME_PREFIX requires a relative localedir, not : $(localedir ) )
1820+ endif
1821+
1822+ ifndef NO_PERL
1823+ ifneq ($(filter /% ,$(firstword $(perllibdir_relative ) ) ) ,)
1824+ $(error RUNTIME_PREFIX requires a relative perllibdir, not : $(perllibdir ) )
1825+ endif
1826+ endif
1827+
1828+ endif
1829+
17601830# We must filter out any object files from $(GITLIBS),
17611831# as it is typically used like:
17621832#
@@ -1977,34 +2047,64 @@ git.res: git.rc GIT-VERSION-FILE GIT-PREFIX
19772047# This makes sure we depend on the NO_PERL setting itself.
19782048$(SCRIPT_PERL_GEN ) : GIT-BUILD-OPTIONS
19792049
1980- ifndef NO_PERL
1981- $(SCRIPT_PERL_GEN ) :
2050+ # Used for substitution in Perl modules. Disabled when using RUNTIME_PREFIX
2051+ # since the locale directory is injected.
2052+ perl_localedir_SQ = $(localedir_SQ )
19822053
2054+ ifndef NO_PERL
2055+ PERL_HEADER_TEMPLATE = perl/header_templates/fixed_prefix.template.pl
19832056PERL_DEFINES = $(PERL_PATH_SQ ) :$(PERLLIB_EXTRA_SQ ) :$(perllibdir_SQ )
1984- $(SCRIPT_PERL_GEN ) : % : % .perl GIT-PERL-DEFINES GIT-VERSION-FILE
2057+
2058+ PERL_DEFINES := $(PERL_PATH_SQ ) $(PERLLIB_EXTRA_SQ ) $(perllibdir_SQ )
2059+ PERL_DEFINES += $(RUNTIME_PREFIX )
2060+
2061+ # Support Perl runtime prefix. In this mode, a different header is installed
2062+ # into Perl scripts.
2063+ ifdef RUNTIME_PREFIX
2064+
2065+ PERL_HEADER_TEMPLATE = perl/header_templates/runtime_prefix.template.pl
2066+
2067+ # Don't export a fixed $(localedir) path; it will be resolved by the Perl header
2068+ # at runtime.
2069+ perl_localedir_SQ =
2070+
2071+ endif
2072+
2073+ PERL_DEFINES += $(gitexecdir ) $(perllibdir ) $(localedir )
2074+
2075+ $(SCRIPT_PERL_GEN ) : % : % .perl GIT-PERL-DEFINES GIT-PERL-HEADER GIT-VERSION-FILE
19852076 $(QUIET_GEN )$(RM ) $@ $@ + && \
1986- INSTLIBDIR=' $(perllibdir_SQ)' && \
1987- INSTLIBDIR_EXTRA=' $(PERLLIB_EXTRA_SQ)' && \
1988- INSTLIBDIR=" $$ INSTLIBDIR$$ {INSTLIBDIR_EXTRA:+:$$ INSTLIBDIR_EXTRA}" && \
19892077 sed -e ' 1{' \
19902078 -e ' s|#!.*perl|#!$(PERL_PATH_SQ)|' \
1991- -e ' h' \
1992- -e ' s=.*=use lib (split(/$(pathsep)/, $$ENV{GITPERLLIB} || "' " $$ INSTLIBDIR" ' "));=' \
1993- -e ' H' \
1994- -e ' x' \
2079+ -e ' rGIT-PERL-HEADER' \
2080+ -e ' G' \
19952081 -e ' }' \
19962082 -e ' s/@@GIT_VERSION@@/$(GIT_VERSION)/g' \
19972083 $< > $@ + && \
19982084 chmod +x $@ + && \
19992085 mv $@ + $@
20002086
2087+ PERL_DEFINES := $(subst $(space ) ,:,$(PERL_DEFINES ) )
20012088GIT-PERL-DEFINES : FORCE
20022089 @FLAGS=' $(PERL_DEFINES)' ; \
20032090 if test x" $$ FLAGS" ! = x" ` cat $@ 2> /dev/null` " ; then \
20042091 echo >&2 " * new perl-specific parameters" ; \
20052092 echo " $$ FLAGS" > $@ ; \
20062093 fi
20072094
2095+ GIT-PERL-HEADER : $(PERL_HEADER_TEMPLATE ) GIT-PERL-DEFINES Makefile
2096+ $(QUIET_GEN )$(RM ) $@ && \
2097+ INSTLIBDIR=' $(perllibdir_SQ)' && \
2098+ INSTLIBDIR_EXTRA=' $(PERLLIB_EXTRA_SQ)' && \
2099+ INSTLIBDIR=" $$ INSTLIBDIR$$ {INSTLIBDIR_EXTRA:+:$$ INSTLIBDIR_EXTRA}" && \
2100+ sed -e ' s=@@PATHSEP@@=$(pathsep)=g' \
2101+ -e ' s=@@INSTLIBDIR@@=' $$ INSTLIBDIR' =g' \
2102+ -e ' s=@@PERLLIBDIR@@=' $(perllibdir_SQ ) ' =g' \
2103+ -e ' s=@@PERLLIBDIR_REL@@=$(perllibdir_relative_SQ)=g' \
2104+ -e ' s=@@GITEXECDIR_REL@@=$(gitexecdir_relative_SQ)=g' \
2105+ -e ' s=@@LOCALEDIR_REL@@=$(localedir_relative_SQ)=g' \
2106+ $< > $@ + && \
2107+ mv $@ + $@
20082108
20092109.PHONY : gitweb
20102110gitweb :
@@ -2149,6 +2249,7 @@ endif
21492249exec_cmd.sp exec_cmd.s exec_cmd.o : GIT-PREFIX
21502250exec_cmd.sp exec_cmd.s exec_cmd.o : EXTRA_CPPFLAGS = \
21512251 ' -DGIT_EXEC_PATH="$(gitexecdir_SQ)"' \
2252+ ' -DGIT_LOCALE_PATH="$(localedir_relative_SQ)"' \
21522253 ' -DBINDIR="$(bindir_relative_SQ)"' \
21532254 ' -DFALLBACK_RUNTIME_PREFIX="$(prefix_SQ)"'
21542255
@@ -2326,7 +2427,7 @@ endif
23262427
23272428perl/build/lib/% .pm : perl/% .pm
23282429 $(QUIET_GEN ) mkdir -p $(dir $@ ) && \
2329- sed -e ' s|@@LOCALEDIR@@|$(localedir_SQ )|g' \
2430+ sed -e ' s|@@LOCALEDIR@@|$(perl_localedir_SQ )|g' \
23302431 -e ' s|@@NO_PERL_CPAN_FALLBACKS@@|$(NO_PERL_CPAN_FALLBACKS_SQ)|g' \
23312432 < $< > $@
23322433
@@ -2801,7 +2902,7 @@ ifndef NO_TCLTK
28012902endif
28022903 $(RM) GIT-VERSION-FILE GIT-CFLAGS GIT-LDFLAGS GIT-BUILD-OPTIONS
28032904 $(RM) GIT-USER-AGENT GIT-PREFIX
2804- $(RM) GIT-SCRIPT-DEFINES GIT-PERL-DEFINES GIT-PYTHON-VARS
2905+ $(RM) GIT-SCRIPT-DEFINES GIT-PERL-DEFINES GIT-PERL-HEADER GIT- PYTHON-VARS
28052906ifdef MSVC
28062907 $(RM) $(patsubst %.o,%.o.pdb,$(OBJECTS))
28072908 $(RM) $(patsubst %.exe,%.pdb,$(OTHER_PROGRAMS))
0 commit comments