Move computation of absolute paths from Makefile to runtime (in preparation for RUNTIME_PREFIX)
This commit prepares the Makefile for relocatable binaries (called RUNTIME_PREFIX). Such binaries will be able to be moved together with the system configuration files to a different directory, requiring to compute the prefix at runtime. In a first step, we make all paths relative in the Makefile and teach system_path() to add the prefix instead. We used to compute absolute paths in the Makefile and passed them to C as defines. We now pass relative paths to C and call system_path() to add the prefix at runtime. Signed-off-by: Steffen Prohaska <prohaska@zib.de> Acked-by: Johannes Sixt <j6t@kdbg.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Steffen Prohaska committed
Jan 18, 2009 at 13:00 UTC
026fa0d5ad9538ca76838070861531c037d7b9ba
3 files changed
+36
-23
Makefile
+26
-16
@@ -179,28 +179,32 @@ STRIP ?= strip
179
# Among the variables below, these:
180
# gitexecdir
181
# template_dir
182
+# mandir
183
+# infodir
184
# htmldir
185
# ETC_GITCONFIG (but not sysconfdir)
184
-# can be specified as a relative path ../some/where/else (which must begin
185
-# with ../); this is interpreted as relative to $(bindir) and "git" at
186
+# can be specified as a relative path some/where/else;
187
+# this is interpreted as relative to $(prefix) and "git" at
188
# runtime figures out where they are based on the path to the executable.
189
# This can help installing the suite in a relocatable way.
190
191
prefix = $(HOME)
190
-bindir = $(prefix)/bin
191
-mandir = $(prefix)/share/man
192
-infodir = $(prefix)/share/info
193
-gitexecdir = $(prefix)/libexec/git-core
192
+bindir_relative = bin
193
+bindir = $(prefix)/$(bindir_relative)
194
+mandir = share/man
195
+infodir = share/info
196
+gitexecdir = libexec/git-core
197
sharedir = $(prefix)/share
195
-template_dir = $(sharedir)/git-core/templates
196
-htmldir=$(sharedir)/doc/git-doc
198
+template_dir = share/git-core/templates
199
+htmldir = share/doc/git-doc
200
ifeq ($(prefix),/usr)
201
sysconfdir = /etc
202
+ETC_GITCONFIG = $(sysconfdir)/gitconfig
203
else
204
sysconfdir = $(prefix)/etc
205
+ETC_GITCONFIG = etc/gitconfig
206
endif
207
lib = lib
203
-ETC_GITCONFIG = $(sysconfdir)/gitconfig
208
# DESTDIR=
209
210
# default configuration for gitweb
@@ -1086,6 +1090,7 @@ ETC_GITCONFIG_SQ = $(subst ','\'',$(ETC_GITCONFIG))
1090
1091
DESTDIR_SQ = $(subst ','\'',$(DESTDIR))
1092
bindir_SQ = $(subst ','\'',$(bindir))
1093
+bindir_relative_SQ = $(subst ','\'',$(bindir_relative))
1094
mandir_SQ = $(subst ','\'',$(mandir))
1095
infodir_SQ = $(subst ','\'',$(infodir))
1096
gitexecdir_SQ = $(subst ','\'',$(gitexecdir))
@@ -1251,7 +1256,12 @@ git.o git.spec \
1256
$(QUIET_CC)$(CC) -o $*.o -c $(ALL_CFLAGS) $<
1257
1258
exec_cmd.o: exec_cmd.c GIT-CFLAGS
1254
- $(QUIET_CC)$(CC) -o $*.o -c $(ALL_CFLAGS) '-DGIT_EXEC_PATH="$(gitexecdir_SQ)"' $<
1259
+ $(QUIET_CC)$(CC) -o $*.o -c $(ALL_CFLAGS) \
1260
+ '-DGIT_EXEC_PATH="$(gitexecdir_SQ)"' \
1261
+ '-DBINDIR="$(bindir_relative_SQ)"' \
1262
+ '-DPREFIX="$(prefix_SQ)"' \
1263
+ $<
1264
+
1265
builtin-init-db.o: builtin-init-db.c GIT-CFLAGS
1266
$(QUIET_CC)$(CC) -o $*.o -c $(ALL_CFLAGS) -DDEFAULT_GIT_TEMPLATE_DIR='"$(template_dir_SQ)"' $<
1267
@@ -1407,17 +1417,17 @@ remove-dashes:
1417
1418
### Installation rules
1419
1410
-ifeq ($(firstword $(subst /, ,$(template_dir))),..)
1411
-template_instdir = $(bindir)/$(template_dir)
1412
-else
1420
+ifeq ($(abspath $(template_dir)),$(template_dir))
1421
template_instdir = $(template_dir)
1422
+else
1423
+template_instdir = $(prefix)/$(template_dir)
1424
endif
1425
export template_instdir
1426
1417
-ifeq ($(firstword $(subst /, ,$(gitexecdir))),..)
1418
-gitexec_instdir = $(bindir)/$(gitexecdir)
1419
-else
1427
+ifeq ($(abspath $(gitexecdir)),$(gitexecdir))
1428
gitexec_instdir = $(gitexecdir)
1429
+else
1430
+gitexec_instdir = $(prefix)/$(gitexecdir)
1431
endif
1432
gitexec_instdir_SQ = $(subst ','\'',$(gitexec_instdir))
1433
export gitexec_instdir
builtin-help.c
+2
-2
@@ -329,7 +329,7 @@ static void setup_man_path(void)
329
* old_path, the ':' at the end will let 'man' to try
330
* system-wide paths after ours to find the manual page. If
331
* there is old_path, we need ':' as delimiter. */
332
- strbuf_addstr(&new_path, GIT_MAN_PATH);
332
+ strbuf_addstr(&new_path, system_path(GIT_MAN_PATH));
333
strbuf_addch(&new_path, ':');
334
if (old_path)
335
strbuf_addstr(&new_path, old_path);
@@ -375,7 +375,7 @@ static void show_man_page(const char *git_cmd)
375
static void show_info_page(const char *git_cmd)
376
{
377
const char *page = cmd_to_page(git_cmd);
378
- setenv("INFOPATH", GIT_INFO_PATH, 1);
378
+ setenv("INFOPATH", system_path(GIT_INFO_PATH), 1);
379
execlp("info", "info", "gitman", page, NULL);
380
}
381
exec_cmd.c
+8
-5
@@ -9,11 +9,14 @@ static const char *argv0_path;
9
10
const char *system_path(const char *path)
11
{
12
- if (!is_absolute_path(path) && argv0_path) {
13
- struct strbuf d = STRBUF_INIT;
14
- strbuf_addf(&d, "%s/%s", argv0_path, path);
15
- path = strbuf_detach(&d, NULL);
16
- }
12
+ static const char *prefix = PREFIX;
13
+ struct strbuf d = STRBUF_INIT;
14
+
15
+ if (is_absolute_path(path))
16
+ return path;
17
+
18
+ strbuf_addf(&d, "%s/%s", prefix, path);
19
+ path = strbuf_detach(&d, NULL);
20
return path;
21
}
22