# Install-prefix when building should not be hardcoded

7 messages from 2022-10-04 to 2022-10-06. Participants: darkdragon, Đoàn Trần Công Danh, Junio C Hamano.
Thread: https://gitlist.dev/t/58560

## darkdragon, 2022-10-04 07:38

Subject: Install-prefix when building should not be hardcoded
Message-ID: <CAAOCJVAML0axQXbYZncT945SuG3-GfmDtDQ4_8cnkQmF_SZtHw@mail.gmail.com>
URL: https://gitlist.dev/e/CAAOCJVAML0axQXbYZncT945SuG3-GfmDtDQ4_8cnkQmF_SZtHw%40mail.gmail.com

```
Even though in Makefile, it is stated that git will figure out
gitexecdir at runtime based on the path to the executable, there are
many output files where $(prefix) will be hardcoded. Even git
--exec-path will print out $(compile_prefix)/libexec/git-core instead
of using run_prefix.

Example: We are building git in Docker at a separate stage to /deploy
(since /usr/local is populated with our compiler toolchain). The final
image is assembled by copying the contents of /deploy to /usr/local.
Commands like "git submodule" will fail because of the wrong git exec
path. Searching via "grep -r /deploy" in /deploy after make install
yields many results.

```

## Đoàn Trần Công Danh, 2022-10-04 07:57

Subject: Re: Install-prefix when building should not be hardcoded
Message-ID: <YzvnadnAYce0dIpi@danh.dev>
URL: https://gitlist.dev/e/YzvnadnAYce0dIpi%40danh.dev
In-Reply-To: <CAAOCJVAML0axQXbYZncT945SuG3-GfmDtDQ4_8cnkQmF_SZtHw@mail.gmail.com>

```
On 2022-10-04 09:38:24+0200, darkdragon <darkdragon-001@web.de> wrote:
> Even though in Makefile, it is stated that git will figure out
> gitexecdir at runtime based on the path to the executable, there are
> many output files where $(prefix) will be hardcoded. Even git
> --exec-path will print out $(compile_prefix)/libexec/git-core instead
> of using run_prefix.

I'm not sure about this part.

> Example: We are building git in Docker at a separate stage to /deploy
> (since /usr/local is populated with our compiler toolchain). The final
> image is assembled by copying the contents of /deploy to /usr/local.
> Commands like "git submodule" will fail because of the wrong git exec
> path. Searching via "grep -r /deploy" in /deploy after make install
> yields many results.

But you may be interested in $(DESTDIR)

	make prefix=/usr/local all
	make prefix=/usr/local DESTDIR=/deploy install

Does that work for you?

-- 
Danh

```

## darkdragon, 2022-10-04 08:40

Subject: Re: Install-prefix when building should not be hardcoded
Message-ID: <CAAOCJVD+NHqhwRQnnz-krLfK=_4_Yaa5MhKhVv5GY9-fi4kEqw@mail.gmail.com>
URL: https://gitlist.dev/e/CAAOCJVD%2BNHqhwRQnnz-krLfK%3D_4_Yaa5MhKhVv5GY9-fi4kEqw%40mail.gmail.com
In-Reply-To: <YzvnadnAYce0dIpi@danh.dev>

```
Thanks for the hint to DESTDIR, it helps!

Nevertheless, I would like to point towards the following section in
the [MAKEFILE][1]:
ˋˋˋMakefile
# Among the variables below, these:
# gitexecdir
# ...
# can be specified as a relative path some/where/else;
# this is interpreted as relative to $(prefix) and "git" at
# runtime figures out where they are based on the path to the executable.
# ...
# This can help installing the suite in a relocatable way.
# ...
gitexecdir = libexec/git-core
ˋˋˋ

[1]: https://github.com/git/git/blob/master/Makefile#L525-L547

On Tue, Oct 4, 2022 at 9:57 AM Đoàn Trần Công Danh <congdanhqx@gmail.com> wrote:
>
> On 2022-10-04 09:38:24+0200, darkdragon <darkdragon-001@web.de> wrote:
> > Even though in Makefile, it is stated that git will figure out
> > gitexecdir at runtime based on the path to the executable, there are
> > many output files where $(prefix) will be hardcoded. Even git
> > --exec-path will print out $(compile_prefix)/libexec/git-core instead
> > of using run_prefix.
>
> I'm not sure about this part.
>
> > Example: We are building git in Docker at a separate stage to /deploy
> > (since /usr/local is populated with our compiler toolchain). The final
> > image is assembled by copying the contents of /deploy to /usr/local.
> > Commands like "git submodule" will fail because of the wrong git exec
> > path. Searching via "grep -r /deploy" in /deploy after make install
> > yields many results.
>
> But you may be interested in $(DESTDIR)
>
>         make prefix=/usr/local all
>         make prefix=/usr/local DESTDIR=/deploy install
>
> Does that work for you?
>
> --
> Danh

```

## Junio C Hamano, 2022-10-05 19:34

Subject: Re: Install-prefix when building should not be hardcoded
Message-ID: <xmqqczb6oyie.fsf@gitster.g>
URL: https://gitlist.dev/e/xmqqczb6oyie.fsf%40gitster.g
In-Reply-To: <YzvnadnAYce0dIpi@danh.dev>

```
Đoàn Trần Công Danh  <congdanhqx@gmail.com> writes:

> On 2022-10-04 09:38:24+0200, darkdragon <darkdragon-001@web.de> wrote:
>> Even though in Makefile, it is stated that git will figure out
>> gitexecdir at runtime based on the path to the executable, there are
>> many output files where $(prefix) will be hardcoded. Even git
>> --exec-path will print out $(compile_prefix)/libexec/git-core instead
>> of using run_prefix.
>
> I'm not sure about this part.

Perhaps it is related to the use of RUNTIME_PREFIX (which I don't
use myself)?

```

## darkdragon, 2022-10-05 20:23

Subject: Re: Install-prefix when building should not be hardcoded
Message-ID: <CAAOCJVAAwgECsJPfm7eHOMmKPewJzxHTKhjwacxPRYWJkSpX_g@mail.gmail.com>
URL: https://gitlist.dev/e/CAAOCJVAAwgECsJPfm7eHOMmKPewJzxHTKhjwacxPRYWJkSpX_g%40mail.gmail.com
In-Reply-To: <xmqqczb6oyie.fsf@gitster.g>

```
On Wed, Oct 5, 2022 at 9:34 PM Junio C Hamano <gitster@pobox.com> wrote:
>
> Đoàn Trần Công Danh  <congdanhqx@gmail.com> writes:
>
> > On 2022-10-04 09:38:24+0200, darkdragon <darkdragon-001@web.de> wrote:
> >> Even though in Makefile, it is stated that git will figure out
> >> gitexecdir at runtime based on the path to the executable, there are
> >> many output files where $(prefix) will be hardcoded. Even git
> >> --exec-path will print out $(compile_prefix)/libexec/git-core instead
> >> of using run_prefix.
> >
> > I'm not sure about this part.
>
> Perhaps it is related to the use of RUNTIME_PREFIX (which I don't
> use myself)?

This seems to do the trick! Thanks a lot!

```

## Junio C Hamano, 2022-10-05 21:21

Subject: Re: Install-prefix when building should not be hardcoded
Message-ID: <xmqqpmf6nf09.fsf@gitster.g>
URL: https://gitlist.dev/e/xmqqpmf6nf09.fsf%40gitster.g
In-Reply-To: <CAAOCJVAAwgECsJPfm7eHOMmKPewJzxHTKhjwacxPRYWJkSpX_g@mail.gmail.com>

```
darkdragon <darkdragon-001@web.de> writes:

> On Wed, Oct 5, 2022 at 9:34 PM Junio C Hamano <gitster@pobox.com> wrote:
>>
>> Đoàn Trần Công Danh  <congdanhqx@gmail.com> writes:
>>
>> > On 2022-10-04 09:38:24+0200, darkdragon <darkdragon-001@web.de> wrote:
>> >> Even though in Makefile, it is stated that git will figure out
>> >> gitexecdir at runtime based on the path to the executable, there are
>> >> many output files where $(prefix) will be hardcoded. Even git
>> >> --exec-path will print out $(compile_prefix)/libexec/git-core instead
>> >> of using run_prefix.
>> >
>> > I'm not sure about this part.
>>
>> Perhaps it is related to the use of RUNTIME_PREFIX (which I don't
>> use myself)?
>
> This seems to do the trick! Thanks a lot!

I guess somebody needs to send a patch to the Makefile to clarify
the comment that led us confused in this thread.  Volunteers?

Thanks.

```

## Đoàn Trần Công Danh, 2022-10-06 01:32

Subject: [PATCH] Makefile: clarify runtime relative gitexecdir
Message-ID: <20221006013205.15015-1-congdanhqx@gmail.com>
URL: https://gitlist.dev/e/20221006013205.15015-1-congdanhqx%40gmail.com
In-Reply-To: <xmqqpmf6nf09.fsf@gitster.g>

```
"git" built with RUNTIME_PREFIX flag turned on could figure out
gitexecdir and other paths as relative to "git" executable.

However, in the section specifies gitexecdir, RUNTIME_PREFIX wasn't
mentioned, thus users may wrongly assume that "git" always locates
gitexecdir as relative path to the executable.

Let's clarify that only "git" built with RUNTIME_PREFIX will locate
gitexecdir as relative path.

Signed-off-by: Đoàn Trần Công Danh <congdanhqx@gmail.com>
---
 Makefile | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/Makefile b/Makefile
index cac3452edb..8a58be440f 100644
--- a/Makefile
+++ b/Makefile
@@ -529,8 +529,9 @@ GIT-VERSION-FILE: FORCE
 #   template_dir
 #   sysconfdir
 # can be specified as a relative path some/where/else;
-# this is interpreted as relative to $(prefix) and "git" at
-# runtime figures out where they are based on the path to the executable.
+# this is interpreted as relative to $(prefix) and "git" built with
+# RUNTIME_PREFIX flag will figure out (at runtime) where they are
+# based on the path to the executable.
 # Additionally, the following will be treated as relative by "git" if they
 # begin with "$(prefix)/":
 #   mandir
-- 
2.38.0.1.ge44e9fe867


```
