Allow the built-in exec path to be relative to the command invocation path
If GIT_EXEC_PATH (the macro that is defined in the Makefile) is relative, it is interpreted relative to the command's invocation path, which usually is $(bindir). The Makefile rules were written with the assumption that $(gitexecdir) is an absolute path. We introduce a separate variable that names the (absolute) installation directory. Signed-off-by: Johannes Sixt <johannes.sixt@telecom.at> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Johannes Sixt committed
Jul 23, 2008 at 21:12 UTC
49fa65a7a8185e81c1098815df607042103b0493
2 files changed
+26
-42
Makefile
+24
-6
@@ -170,6 +170,16 @@ ALL_CFLAGS = $(CFLAGS)
170
ALL_LDFLAGS = $(LDFLAGS)
171
STRIP ?= strip
172
173
+# Among the variables below, these:
174
+# gitexecdir
175
+# template_dir
176
+# htmldir
177
+# ETC_GITCONFIG (but not sysconfdir)
178
+# can be specified as a relative path ../some/where/else (which must begin
179
+# with ../); this is interpreted as relative to $(bindir) and "git" at
180
+# runtime figures out where they are based on the path to the executable.
181
+# This can help installing the suite in a relocatable way.
182
+
183
prefix = $(HOME)
184
bindir = $(prefix)/bin
185
mandir = $(prefix)/share/man
@@ -205,7 +215,7 @@ GITWEB_FAVICON = git-favicon.png
215
GITWEB_SITE_HEADER =
216
GITWEB_SITE_FOOTER =
217
208
-export prefix bindir gitexecdir sharedir htmldir sysconfdir
218
+export prefix bindir sharedir htmldir sysconfdir
219
220
CC = gcc
221
AR = ar
@@ -1321,22 +1331,30 @@ template_instdir = $(template_dir)
1331
endif
1332
export template_instdir
1333
1334
+ifeq ($(firstword $(subst /, ,$(gitexecdir))),..)
1335
+gitexec_instdir = $(bindir)/$(gitexecdir)
1336
+else
1337
+gitexec_instdir = $(gitexecdir)
1338
+endif
1339
+gitexec_instdir_SQ = $(subst ','\'',$(gitexec_instdir))
1340
+export gitexec_instdir
1341
+
1342
install: all
1343
$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(bindir_SQ)'
1326
- $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(gitexecdir_SQ)'
1327
- $(INSTALL) $(ALL_PROGRAMS) '$(DESTDIR_SQ)$(gitexecdir_SQ)'
1344
+ $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
1345
+ $(INSTALL) $(ALL_PROGRAMS) '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
1346
$(INSTALL) git$X git-upload-pack$X git-receive-pack$X git-upload-archive$X '$(DESTDIR_SQ)$(bindir_SQ)'
1347
$(MAKE) -C templates DESTDIR='$(DESTDIR_SQ)' install
1348
$(MAKE) -C perl prefix='$(prefix_SQ)' DESTDIR='$(DESTDIR_SQ)' install
1349
ifndef NO_TCLTK
1350
$(MAKE) -C gitk-git install
1333
- $(MAKE) -C git-gui install
1351
+ $(MAKE) -C git-gui gitexecdir='$(gitexec_instdir_SQ)' install
1352
endif
1353
ifneq (,$X)
1336
- $(foreach p,$(patsubst %$X,%,$(filter %$X,$(ALL_PROGRAMS) $(BUILT_INS) git$X)), $(RM) '$(DESTDIR_SQ)$(gitexecdir_SQ)/$p';)
1354
+ $(foreach p,$(patsubst %$X,%,$(filter %$X,$(ALL_PROGRAMS) $(BUILT_INS) git$X)), $(RM) '$(DESTDIR_SQ)$(gitexec_instdir_SQ)/$p';)
1355
endif
1356
bindir=$$(cd '$(DESTDIR_SQ)$(bindir_SQ)' && pwd) && \
1339
- execdir=$$(cd '$(DESTDIR_SQ)$(gitexecdir_SQ)' && pwd) && \
1357
+ execdir=$$(cd '$(DESTDIR_SQ)$(gitexec_instdir_SQ)' && pwd) && \
1358
if test "z$$bindir" != "z$$execdir"; \
1359
then \
1360
ln -f "$$bindir/git$X" "$$execdir/git$X" || \
exec_cmd.c
+2
-36
@@ -7,40 +7,6 @@ extern char **environ;
7
static const char *argv_exec_path;
8
static const char *argv0_path;
9
10
-static const char *builtin_exec_path(void)
11
-{
12
-#ifndef __MINGW32__
13
- return GIT_EXEC_PATH;
14
-#else
15
- int len;
16
- char *p, *q, *sl;
17
- static char *ep;
18
- if (ep)
19
- return ep;
20
-
21
- len = strlen(_pgmptr);
22
- if (len < 2)
23
- return ep = ".";
24
-
25
- p = ep = xmalloc(len+1);
26
- q = _pgmptr;
27
- sl = NULL;
28
- /* copy program name, turn '\\' into '/', skip last part */
29
- while ((*p = *q)) {
30
- if (*q == '\\' || *q == '/') {
31
- *p = '/';
32
- sl = p;
33
- }
34
- p++, q++;
35
- }
36
- if (sl)
37
- *sl = '\0';
38
- else
39
- ep[0] = '.', ep[1] = '\0';
40
- return ep;
41
-#endif
42
-}
43
-
10
const char *system_path(const char *path)
11
{
12
if (!is_absolute_path(path) && argv0_path) {
@@ -75,7 +41,7 @@ const char *git_exec_path(void)
41
return env;
42
}
43
78
- return builtin_exec_path();
44
+ return system_path(GIT_EXEC_PATH);
45
}
46
47
static void add_path(struct strbuf *out, const char *path)
@@ -99,7 +65,7 @@ void setup_path(void)
65
66
add_path(&new_path, argv_exec_path);
67
add_path(&new_path, getenv(EXEC_PATH_ENVIRONMENT));
102
- add_path(&new_path, builtin_exec_path());
68
+ add_path(&new_path, system_path(GIT_EXEC_PATH));
69
add_path(&new_path, argv0_path);
70
71
if (old_path)