summaryrefslogtreecommitdiff
blob: bb1ace8634575c817ac1f78527a9721d60a42edc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
From 6684f694a9ff6e2d720b3eb5042c6aad5f686d9d Mon Sep 17 00:00:00 2001
From: Avery Pennarun <apenwarr@gmail.com>
Date: Thu, 1 Apr 2010 19:34:03 -0400
Subject: [PATCH 4/7] Add a 'make install' target.

Also change main.py to search around in appropriate places for the installed
library files.  By default, if your bup is in /usr/bin/bup, it'll look in
/usr/lib/bup.  (It drops two words off the end of the filename and adds
/lib/bup to the end.)

This also makes the Debian packager at
	http://git.debian.org/collab-maint/bup
actually produce a usable package.
---
 Makefile |   22 ++++++++++++++++++++++
 main.py  |   12 ++++++++++--
 2 files changed, 32 insertions(+), 2 deletions(-)

diff --git a/Makefile b/Makefile
index 40cae28..217b852 100644
--- a/Makefile
+++ b/Makefile
@@ -21,6 +21,28 @@ default: all
 
 all: cmds bup lib/bup/_hashsplit$(SOEXT) \
 	Documentation/all
+
+INSTALL=install
+MANDIR=$(DESTDIR)/usr/share/man
+DOCDIR=$(DESTDIR)/usr/share/doc/bup
+BINDIR=$(DESTDIR)/usr/bin
+LIBDIR=$(DESTDIR)/usr/lib/bup
+install: all
+	$(INSTALL) -d $(MANDIR)/man1 $(DOCDIR) $(BINDIR) \
+		$(LIBDIR)/bup $(LIBDIR)/cmd
+	$(INSTALL) -o 0 -g 0 -m 0644 \
+		$(wildcard Documentation/*.1) \
+		$(MANDIR)/man1
+	$(INSTALL) -o 0 -g 0 -m 0644 \
+		$(wildcard Documentation/*.html) \
+		$(DOCDIR)
+	$(INSTALL) -o 0 -g 0 -m 0755 bup $(BINDIR)
+	$(INSTALL) -o 0 -g 0 -m 0755 \
+		$(wildcard cmd/bup-*) \
+		$(LIBDIR)/cmd
+	$(INSTALL) -o 0 -g 0 -m 0644 \
+		$(wildcard lib/bup/*.so lib/bup/*.py) \
+		$(LIBDIR)/bup
 	
 %/all:
 	$(MAKE) -C $* all
diff --git a/main.py b/main.py
index 77ec76b..0ac7abc 100755
--- a/main.py
+++ b/main.py
@@ -5,10 +5,18 @@ import sys, os, subprocess, signal, getopt
 argv = sys.argv
 exe = argv[0]
 exepath = os.path.split(exe)[0] or '.'
+exeprefix = os.path.split(os.path.abspath(exepath))[0]
 
 # fix the PYTHONPATH to include our lib dir
-libpath = os.path.join(exepath, 'lib')
-cmdpath = os.path.join(exepath, 'cmd')
+if os.path.exists("%s/lib/bup/cmd/." % exeprefix):
+    # installed binary in /.../bin.
+    # eg. /usr/bin/bup means /usr/lib/bup/... is where our libraries are.
+    cmdpath = "%s/lib/bup/cmd" % exeprefix
+    libpath = "%s/lib/bup" % exeprefix
+else:
+    # running from the src directory without being installed first
+    cmdpath = os.path.join(exepath, 'cmd')
+    libpath = os.path.join(exepath, 'lib')
 sys.path[:0] = [libpath]
 os.environ['PYTHONPATH'] = libpath + ':' + os.environ.get('PYTHONPATH', '')
 os.environ['BUP_MAIN_EXE'] = os.path.abspath(exe)
-- 
1.7.0.4