summaryrefslogtreecommitdiffstats
path: root/patches/01_properly-support-shared-library.patch
blob: 6536ccead601636106e4659ec9f259daa42db75e (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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
Author: "P. J. McDermott" <pj@pehjota.net>
Subject: Properly support a shared library

diff -Naur src.orig/Makefile src/Makefile
--- src.orig/Makefile	2010-09-10 18:46:02.000000000 -0400
+++ src/Makefile	2014-06-11 12:35:03.717651900 -0400
@@ -23,6 +23,9 @@
 BIGFILES=-D_FILE_OFFSET_BITS=64
 CFLAGS=-Wall -Winline -O2 -g $(BIGFILES)
 
+SONAME=libbz2.so.1.0
+VERSION=1.0.6
+
 # Where you want it installed when you do 'make install'
 PREFIX=/usr/local
 
@@ -35,14 +38,17 @@
       decompress.o \
       bzlib.o
 
-all: libbz2.a bzip2 bzip2recover test
+all: libbz2.so.$(VERSION) libbz2.a bzip2 bzip2recover
 
-bzip2: libbz2.a bzip2.o
+bzip2: libbz2.so.$(VERSION) bzip2.o
-	$(CC) $(CFLAGS) $(LDFLAGS) -o bzip2 bzip2.o -L. -lbz2
+	$(CC) $(CFLAGS) $(LDFLAGS) -o bzip2 bzip2.o libbz2.so.$(VERSION)
 
 bzip2recover: bzip2recover.o
 	$(CC) $(CFLAGS) $(LDFLAGS) -o bzip2recover bzip2recover.o
 
+libbz2.so.$(VERSION): $(OBJS:.o=.sho)
+	$(CC) -o $@ -shared -Wl,-soname,$(SONAME) $(OBJS:.o=.sho) -lc
+
 libbz2.a: $(OBJS)
 	rm -f libbz2.a
 	$(AR) cq libbz2.a $(OBJS)
@@ -55,11 +61,17 @@
 check: test
 test: bzip2
 	@cat words1
+	LD_PRELOAD=./libbz2.so.$(VERSION) \
 	./bzip2 -1  < sample1.ref > sample1.rb2
+	LD_PRELOAD=./libbz2.so.$(VERSION) \
 	./bzip2 -2  < sample2.ref > sample2.rb2
+	LD_PRELOAD=./libbz2.so.$(VERSION) \
 	./bzip2 -3  < sample3.ref > sample3.rb2
+	LD_PRELOAD=./libbz2.so.$(VERSION) \
 	./bzip2 -d  < sample1.bz2 > sample1.tst
+	LD_PRELOAD=./libbz2.so.$(VERSION) \
 	./bzip2 -d  < sample2.bz2 > sample2.tst
+	LD_PRELOAD=./libbz2.so.$(VERSION) \
 	./bzip2 -ds < sample3.bz2 > sample3.tst
 	cmp sample1.bz2 sample1.rb2 
 	cmp sample2.bz2 sample2.rb2
@@ -87,6 +99,8 @@
 	chmod a+r $(PREFIX)/man/man1/bzip2.1
 	cp -f bzlib.h $(PREFIX)/include
 	chmod a+r $(PREFIX)/include/bzlib.h
+	cp -f libbz2.so.$(VERSION) $(PREFIX)/lib
+	chmod a+r $(PREFIX)/lib/libbz2.so.$(VERSION)
 	cp -f libbz2.a $(PREFIX)/lib
 	chmod a+r $(PREFIX)/lib/libbz2.a
 	cp -f bzgrep $(PREFIX)/bin/bzgrep
@@ -109,29 +123,20 @@
 	echo ".so man1/bzdiff.1" > $(PREFIX)/man/man1/bzcmp.1
 
 clean: 
-	rm -f *.o libbz2.a bzip2 bzip2recover \
+	rm -f *.o *.sho libbz2.so* libbz2.a bzip2 bzip2recover \
 	sample1.rb2 sample2.rb2 sample3.rb2 \
 	sample1.tst sample2.tst sample3.tst
 
-blocksort.o: blocksort.c
+.SUFFIXES:
+.SUFFIXES: .c .o .sho
+
+blocksort.sho: blocksort.c
 	@cat words0
-	$(CC) $(CFLAGS) -c blocksort.c
+	$(CC) $(CFLAGS) -D_REENTRANT -fPIC -c -o $@ $?
-huffman.o: huffman.c
-	$(CC) $(CFLAGS) -c huffman.c
-crctable.o: crctable.c
-	$(CC) $(CFLAGS) -c crctable.c
-randtable.o: randtable.c
-	$(CC) $(CFLAGS) -c randtable.c
-compress.o: compress.c
-	$(CC) $(CFLAGS) -c compress.c
-decompress.o: decompress.c
-	$(CC) $(CFLAGS) -c decompress.c
-bzlib.o: bzlib.c
-	$(CC) $(CFLAGS) -c bzlib.c
-bzip2.o: bzip2.c
-	$(CC) $(CFLAGS) -c bzip2.c
-bzip2recover.o: bzip2recover.c
-	$(CC) $(CFLAGS) -c bzip2recover.c
+.c.o:
+	$(CC) $(CFLAGS) -D_REENTRANT -c -o $@ $<
+.c.sho:
+	$(CC) $(CFLAGS) -D_REENTRANT -fPIC -c -o $@ $<
 
 
 distclean: clean