Hello! This would be my first contribution to the Git project, so please accept my apology in advance for any mistakes and let me know what I can do better. This patch expands support for the RUNTIME_PREFIX configuration flag, currently only used on Windows builds, to include Linux, Darwin, and FreeBSD. When Git is built with RUNTIME_PREFIX enabled, it resolves its ancillary paths relative to the runtime location of its executable rather than hard-coding them at compile-time, allowing a Git installation to be deployed to a path other than the one in which it was installed. It was useful to create Git distribution bundles that could unpack fully-functional Git deployments to arbitrary locations in support of the Chromium project. Chromium has been using Git bundles built with a patch similar to this one on its Linux and Mac continuous integration fleet (plus some developer systems) for almost a year now. RUNTIME_PREFIX remains an optional configuration flag, so standard Git builds will not see any changes. However, with this patch applied, Linux, Darwin, and FreeBSD users can now optionally use "config.mak" to enable RUNTIME_PREFIX and build relocatable Git distributions. An example "config.mak" that builds relocatable Git binaries for Linux/Mac is: # BEGIN: config.mak RUNTIME_PREFIX = YesPlease gitexecdir = libexec/git-core template_dir = share/git-core/templates sysconfdir = etc # END: config.mak Implementation notes: It is unfortunately not straightforward to resolve the full absolute path of the currently-running binary. On some operating systems, notably Windows, this path is executively supplied as argv[0]. On other operating systems, however, argv[0] is supplied by the invoker (shell, script, kernel, etc.), and is not a reliable source of information about the running Git binary. The specific method that this patch employs for binary directory resolution varies depending on the operating system. On Linux and FreeBSD, Git resolves "/proc/self/exe" and "/proc/curproc/file" respectively. On Darwin, Git uses the "_NSGetExecutablePath" function. On all operating systems, notably Windows, Git continues to fall back to resolution against argv[0] when it is an absolute path. When RUNTIME_PREFIX is enabled, the resolved runtime path needs to be passed to ancillary Git tools for their own resolution requirements: - C-source Git programs will use the EXEC_PATH_ENVIRONMENT environment variable that Git already exports, ensuring that any launched tools use the same runtime prefix as the entry point. - PERL tooling needs to know how to locate Git's support libraries. When RUNTIME_PREFIX is configured, Git now exports the GITPERLLIB environment variable, a mechanism that Git's PERL tooling supports that appears to be built for testing. PERL scripts installed using MakeMaker incorporate the builder system's PERL version into their installation path, making it inconsistent to hard-code; consequently, this patch opts to disable MakeMaker for RUNTIME_PREFIX builds in order to deterministically control the destination of Git's support libraries. - Git also exports the GIT_TEXTDOMAINDIR environment variable when RUNTIME_PREFIX is set so that its locale configuration can be leveraged by Git tooling gettext(). Please note that this patch affects Windows Git builds, since the Windows Git project uses RUNTIME_PREFIX to support arbitrary installation paths. Notably, PERL scripts are now always installed without MakeMaker (if they weren't before), and EXEC_PATH_ENVIRONMENT is preferred by tools instead of re-resolving argv[0]. Chromium uses the stock redistributable Windows Git package, so I haven't had an opportunity to test this patch on that platform. Please take a look and let me know what you think. Thanks! -Dan Dan Jacques (1): exec_cmd: RUNTIME_PREFIX on some POSIX systems Makefile | 29 ++++++-- builtin/receive-pack.c | 2 +- cache.h | 2 + common-main.c | 4 +- config.mak.uname | 4 ++ exec_cmd.c | 189 +++++++++++++++++++++++++++++++++++++++++++------ exec_cmd.h | 6 +- gettext.c | 7 +- git.c | 7 +- http-backend.c | 2 +- shell.c | 2 +- upload-pack.c | 2 +- 12 files changed, 217 insertions(+), 39 deletions(-) -- 2.15.0.448.gf294e3d99a-goog