Skip to content

Commit 92034a9

Browse files
committed
Merge branch 'dj/runtime-prefix'
A build-time option has been added to allow Git to be told to refer to its associated files relative to the main binary, in the same way that has been possible on Windows for quite some time, for Linux, BSDs and Darwin. * dj/runtime-prefix: Makefile: quote $INSTLIBDIR when passing it to sed Makefile: remove unused @@PERLLIBDIR@@ substitution variable mingw/msvc: use the new-style RUNTIME_PREFIX helper exec_cmd: provide a new-style RUNTIME_PREFIX helper for Windows exec_cmd: RUNTIME_PREFIX on some POSIX systems Makefile: add Perl runtime prefix support Makefile: generate Perl header from template file
2 parents c988f64 + 64f982b commit 92034a9

14 files changed

+412
-55
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
/GIT-LDFLAGS
44
/GIT-PREFIX
55
/GIT-PERL-DEFINES
6+
/GIT-PERL-HEADER
67
/GIT-PYTHON-VARS
78
/GIT-SCRIPT-DEFINES
89
/GIT-USER-AGENT

Makefile

+115-13
Original file line numberDiff line numberDiff line change
@@ -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

445468
GIT-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

483508
prefix = $(HOME)
@@ -502,7 +527,9 @@ bindir_relative = $(patsubst $(prefix)/%,%,$(bindir))
502527
mandir_relative = $(patsubst $(prefix)/%,%,$(mandir))
503528
infodir_relative = $(patsubst $(prefix)/%,%,$(infodir))
504529
gitexecdir_relative = $(patsubst $(prefix)/%,%,$(gitexecdir))
530+
localedir_relative = $(patsubst $(prefix)/%,%,$(localedir))
505531
htmldir_relative = $(patsubst $(prefix)/%,%,$(htmldir))
532+
perllibdir_relative = $(patsubst $(prefix)/%,%,$(perllibdir))
506533

507534
export prefix bindir sharedir sysconfdir gitwebdir perllibdir localedir
508535

@@ -1670,10 +1697,27 @@ ifdef HAVE_BSD_SYSCTL
16701697
BASIC_CFLAGS += -DHAVE_BSD_SYSCTL
16711698
endif
16721699

1700+
ifdef HAVE_BSD_KERN_PROC_SYSCTL
1701+
BASIC_CFLAGS += -DHAVE_BSD_KERN_PROC_SYSCTL
1702+
endif
1703+
16731704
ifdef HAVE_GETDELIM
16741705
BASIC_CFLAGS += -DHAVE_GETDELIM
16751706
endif
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+
16771721
ifeq ($(TCLTK_PATH),)
16781722
NO_TCLTK = NoThanks
16791723
endif
@@ -1758,11 +1802,13 @@ mandir_relative_SQ = $(subst ','\'',$(mandir_relative))
17581802
infodir_relative_SQ = $(subst ','\'',$(infodir_relative))
17591803
perllibdir_SQ = $(subst ','\'',$(perllibdir))
17601804
localedir_SQ = $(subst ','\'',$(localedir))
1805+
localedir_relative_SQ = $(subst ','\'',$(localedir_relative))
17611806
gitexecdir_SQ = $(subst ','\'',$(gitexecdir))
17621807
gitexecdir_relative_SQ = $(subst ','\'',$(gitexecdir_relative))
17631808
template_dir_SQ = $(subst ','\'',$(template_dir))
17641809
htmldir_relative_SQ = $(subst ','\'',$(htmldir_relative))
17651810
prefix_SQ = $(subst ','\'',$(prefix))
1811+
perllibdir_relative_SQ = $(subst ','\'',$(perllibdir_relative))
17661812
gitwebdir_SQ = $(subst ','\'',$(gitwebdir))
17671813

17681814
SHELL_PATH_SQ = $(subst ','\'',$(SHELL_PATH))
@@ -1773,6 +1819,31 @@ TCLTK_PATH_SQ = $(subst ','\'',$(TCLTK_PATH))
17731819
DIFF_SQ = $(subst ','\'',$(DIFF))
17741820
PERLLIB_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
19992073
PERL_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))
20172105
GIT-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
20252126
perllibdir:
20262127
@echo '$(perllibdir_SQ)'
@@ -2168,6 +2269,7 @@ endif
21682269
exec-cmd.sp exec-cmd.s exec-cmd.o: GIT-PREFIX
21692270
exec-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

21862288
gettext.sp gettext.s gettext.o: GIT-PREFIX
21872289
gettext.sp gettext.s gettext.o: EXTRA_CPPFLAGS = \
2188-
-DGIT_LOCALE_PATH='"$(localedir_SQ)"'
2290+
-DGIT_LOCALE_PATH='"$(localedir_relative_SQ)"'
21892291

21902292
http-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

23462448
perl/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
28032905
endif
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

cache.h

+1
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,7 @@ static inline enum object_type object_type(unsigned int mode)
428428
#define GIT_ICASE_PATHSPECS_ENVIRONMENT "GIT_ICASE_PATHSPECS"
429429
#define GIT_QUARANTINE_ENVIRONMENT "GIT_QUARANTINE_PATH"
430430
#define GIT_OPTIONAL_LOCKS_ENVIRONMENT "GIT_OPTIONAL_LOCKS"
431+
#define GIT_TEXT_DOMAIN_DIR_ENVIRONMENT "GIT_TEXTDOMAINDIR"
431432

432433
/*
433434
* Environment variable used in handshaking the wire protocol.

common-main.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,14 @@ int main(int argc, const char **argv)
3232
*/
3333
sanitize_stdfds();
3434

35+
git_resolve_executable_dir(argv[0]);
36+
3537
git_setup_gettext();
3638

3739
initialize_the_repository();
3840

3941
attr_start();
4042

41-
git_extract_argv0_path(argv[0]);
42-
4343
restore_sigpipe_to_default();
4444

4545
return cmd_main(argc, argv);

compat/mingw.c

+2-3
Original file line numberDiff line numberDiff line change
@@ -2221,7 +2221,7 @@ void mingw_startup(void)
22212221
die_startup();
22222222

22232223
/* determine size of argv and environ conversion buffer */
2224-
maxlen = wcslen(_wpgmptr);
2224+
maxlen = wcslen(wargv[0]);
22252225
for (i = 1; i < argc; i++)
22262226
maxlen = max(maxlen, wcslen(wargv[i]));
22272227
for (i = 0; wenv[i]; i++)
@@ -2241,8 +2241,7 @@ void mingw_startup(void)
22412241
buffer = malloc_startup(maxlen);
22422242

22432243
/* convert command line arguments and environment to UTF-8 */
2244-
__argv[0] = wcstoutfdup_startup(buffer, _wpgmptr, maxlen);
2245-
for (i = 1; i < argc; i++)
2244+
for (i = 0; i < argc; i++)
22462245
__argv[i] = wcstoutfdup_startup(buffer, wargv[i], maxlen);
22472246
for (i = 0; wenv[i]; i++)
22482247
environ[i] = wcstoutfdup_startup(buffer, wenv[i], maxlen);

config.mak.uname

+9
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ ifeq ($(uname_S),Linux)
3737
HAVE_GETDELIM = YesPlease
3838
SANE_TEXT_GREP=-a
3939
FREAD_READS_DIRECTORIES = UnfortunatelyYes
40+
PROCFS_EXECUTABLE_PATH = /proc/self/exe
4041
endif
4142
ifeq ($(uname_S),GNU/kFreeBSD)
4243
HAVE_ALLOCA_H = YesPlease
@@ -111,6 +112,7 @@ ifeq ($(uname_S),Darwin)
111112
BASIC_CFLAGS += -DPROTECT_HFS_DEFAULT=1
112113
HAVE_BSD_SYSCTL = YesPlease
113114
FREAD_READS_DIRECTORIES = UnfortunatelyYes
115+
HAVE_NS_GET_EXECUTABLE_PATH = YesPlease
114116
endif
115117
ifeq ($(uname_S),SunOS)
116118
NEEDS_SOCKET = YesPlease
@@ -205,6 +207,7 @@ ifeq ($(uname_S),FreeBSD)
205207
HAVE_PATHS_H = YesPlease
206208
GMTIME_UNRELIABLE_ERRORS = UnfortunatelyYes
207209
HAVE_BSD_SYSCTL = YesPlease
210+
HAVE_BSD_KERN_PROC_SYSCTL = YesPlease
208211
PAGER_ENV = LESS=FRX LV=-c MORE=FRX
209212
FREAD_READS_DIRECTORIES = UnfortunatelyYes
210213
endif
@@ -217,6 +220,8 @@ ifeq ($(uname_S),OpenBSD)
217220
BASIC_LDFLAGS += -L/usr/local/lib
218221
HAVE_PATHS_H = YesPlease
219222
HAVE_BSD_SYSCTL = YesPlease
223+
HAVE_BSD_KERN_PROC_SYSCTL = YesPlease
224+
PROCFS_EXECUTABLE_PATH = /proc/curproc/file
220225
endif
221226
ifeq ($(uname_S),MirBSD)
222227
NO_STRCASESTR = YesPlease
@@ -235,6 +240,8 @@ ifeq ($(uname_S),NetBSD)
235240
USE_ST_TIMESPEC = YesPlease
236241
HAVE_PATHS_H = YesPlease
237242
HAVE_BSD_SYSCTL = YesPlease
243+
HAVE_BSD_KERN_PROC_SYSCTL = YesPlease
244+
PROCFS_EXECUTABLE_PATH = /proc/curproc/exe
238245
endif
239246
ifeq ($(uname_S),AIX)
240247
DEFAULT_PAGER = more
@@ -350,6 +357,7 @@ ifeq ($(uname_S),Windows)
350357
SNPRINTF_RETURNS_BOGUS = YesPlease
351358
NO_SVN_TESTS = YesPlease
352359
RUNTIME_PREFIX = YesPlease
360+
HAVE_WPGMPTR = YesWeDo
353361
NO_ST_BLOCKS_IN_STRUCT_STAT = YesPlease
354362
NO_NSEC = YesPlease
355363
USE_WIN32_MMAP = YesPlease
@@ -499,6 +507,7 @@ ifneq (,$(findstring MINGW,$(uname_S)))
499507
NO_SVN_TESTS = YesPlease
500508
NO_PERL_MAKEMAKER = YesPlease
501509
RUNTIME_PREFIX = YesPlease
510+
HAVE_WPGMPTR = YesWeDo
502511
NO_ST_BLOCKS_IN_STRUCT_STAT = YesPlease
503512
NO_NSEC = YesPlease
504513
USE_WIN32_MMAP = YesPlease

0 commit comments

Comments
 (0)