--- ./bzlib_private.h.orig	Sat Sep 11 00:41:55 2010
+++ ./bzlib_private.h	Thu Sep 20 22:50:38 2018
@@ -50,7 +50,11 @@
 #define False ((Bool)0)
 
 #ifndef __GNUC__
-#define __inline__  /* */
+# ifdef __sgi
+#  define __inline__ __inline
+# else
+#  define __inline__  /* */
+# endif
 #endif 
 
 #ifndef BZ_NO_STDIO
--- ./bzlib.c.orig	Sat Sep 11 00:38:23 2010
+++ ./bzlib.c	Thu Sep 20 22:50:38 2018
@@ -684,7 +684,7 @@
 
 
 /*---------------------------------------------------*/
-__inline__ Int32 BZ2_indexIntoF ( Int32 indx, Int32 *cftab )
+Int32 BZ2_indexIntoF ( Int32 indx, Int32 *cftab )
 {
    Int32 nb, na, mid;
    nb = 0;
--- ./Makefile.orig	Sat Sep 11 00:46:02 2010
+++ ./Makefile	Sat Sep 22 00:41:10 2018
@@ -15,16 +15,16 @@
 SHELL=/bin/sh
 
 # To assist in cross-compiling
-CC=gcc
-AR=ar
-RANLIB=ranlib
+CC=c99
+RANLIB=
 LDFLAGS=
+SHAREDLIBFLAGS=-fpic -fPIC
 
 BIGFILES=-D_FILE_OFFSET_BITS=64
-CFLAGS=-Wall -Winline -O2 -g $(BIGFILES)
+CFLAGS=-O2 -mips4 -n32 $(BIGFILES)
 
 # Where you want it installed when you do 'make install'
-PREFIX=/usr/local
+PREFIX=/usr/nekoware
 
 
 OBJS= blocksort.o  \
@@ -35,11 +35,14 @@
       decompress.o \
       bzlib.o
 
-all: libbz2.a bzip2 bzip2recover test
+all: libbz2.a libbz2.so bzip2 bzip2-static bzip2recover test
 
-bzip2: libbz2.a bzip2.o
-	$(CC) $(CFLAGS) $(LDFLAGS) -o bzip2 bzip2.o -L. -lbz2
+bzip2: libbz2.so bzip2.o
+	$(CC) $(CFLAGS) $(LDFLAGS) -Wl,-rpath -Wl,$(PREFIX)/lib -o bzip2 bzip2.o libbz2.so.1.0.6
 
+bzip2-static: libbz2.a bzip2.o
+	$(CC) $(CFLAGS) $(LDFLAGS) -o bzip2-static bzip2.o libbz2.a
+
 bzip2recover: bzip2recover.o
 	$(CC) $(CFLAGS) $(LDFLAGS) -o bzip2recover bzip2recover.o
 
@@ -52,15 +55,18 @@
 		$(RANLIB) libbz2.a ; \
 	fi
 
+libbz2.so: $(OBJS)
+	$(CC) $(CFLAGS) $(SHAREDLIBFLAGS) -shared -Wl,-soname -Wl,libbz2.so.1 -Wl,-set_version,sgi1.0.2:sgi1.0.3:sgi1.0.5:sgi1.0.6 -o libbz2.so.1.0.6 $(OBJS)
+
 check: test
-test: bzip2
+test: bzip2-static
 	@cat words1
-	./bzip2 -1  < sample1.ref > sample1.rb2
-	./bzip2 -2  < sample2.ref > sample2.rb2
-	./bzip2 -3  < sample3.ref > sample3.rb2
-	./bzip2 -d  < sample1.bz2 > sample1.tst
-	./bzip2 -d  < sample2.bz2 > sample2.tst
-	./bzip2 -ds < sample3.bz2 > sample3.tst
+	./bzip2-static -1  < sample1.ref > sample1.rb2
+	./bzip2-static -2  < sample2.ref > sample2.rb2
+	./bzip2-static -3  < sample3.ref > sample3.rb2
+	./bzip2-static -d  < sample1.bz2 > sample1.tst
+	./bzip2-static -d  < sample2.bz2 > sample2.tst
+	./bzip2-static -ds < sample3.bz2 > sample3.tst
 	cmp sample1.bz2 sample1.rb2 
 	cmp sample2.bz2 sample2.rb2
 	cmp sample3.bz2 sample3.rb2
@@ -69,7 +75,7 @@
 	cmp sample3.tst sample3.ref
 	@cat words3
 
-install: bzip2 bzip2recover
+install: bzip2 bzip2recover libbz2.a libbz2.so
 	if ( test ! -d $(PREFIX)/bin ) ; then mkdir -p $(PREFIX)/bin ; fi
 	if ( test ! -d $(PREFIX)/lib ) ; then mkdir -p $(PREFIX)/lib ; fi
 	if ( test ! -d $(PREFIX)/man ) ; then mkdir -p $(PREFIX)/man ; fi
@@ -89,15 +95,13 @@
 	chmod a+r $(PREFIX)/include/bzlib.h
 	cp -f libbz2.a $(PREFIX)/lib
 	chmod a+r $(PREFIX)/lib/libbz2.a
+	cp -f libbz2.so.1.0.6 $(PREFIX)/lib
+	chmod a+r $(PREFIX)/lib/libbz2.so.1.0.6
 	cp -f bzgrep $(PREFIX)/bin/bzgrep
-	ln -s -f $(PREFIX)/bin/bzgrep $(PREFIX)/bin/bzegrep
-	ln -s -f $(PREFIX)/bin/bzgrep $(PREFIX)/bin/bzfgrep
 	chmod a+x $(PREFIX)/bin/bzgrep
 	cp -f bzmore $(PREFIX)/bin/bzmore
-	ln -s -f $(PREFIX)/bin/bzmore $(PREFIX)/bin/bzless
 	chmod a+x $(PREFIX)/bin/bzmore
 	cp -f bzdiff $(PREFIX)/bin/bzdiff
-	ln -s -f $(PREFIX)/bin/bzdiff $(PREFIX)/bin/bzcmp
 	chmod a+x $(PREFIX)/bin/bzdiff
 	cp -f bzgrep.1 bzmore.1 bzdiff.1 $(PREFIX)/man/man1
 	chmod a+r $(PREFIX)/man/man1/bzgrep.1
@@ -107,9 +111,46 @@
 	echo ".so man1/bzgrep.1" > $(PREFIX)/man/man1/bzfgrep.1
 	echo ".so man1/bzmore.1" > $(PREFIX)/man/man1/bzless.1
 	echo ".so man1/bzdiff.1" > $(PREFIX)/man/man1/bzcmp.1
+	cd $(PREFIX)/bin && \
+	ln -s -f bzgrep bzegrep && \
+	ln -s -f bzgrep bzfgrep && \
+	ln -s -f bzmore bzless && \
+	ln -s -f bzdiff bzcmp
+	cd $(PREFIX)/lib && \
+	ln -s libbz2.so.1.0.6 libbz2.so.1.0 && \
+	ln -s libbz2.so.1.0.6 libbz2.so.1 && \
+	ln -s libbz2.so.1.0.6 libbz2.so
+
+uninstall:
+	rm -f $(PREFIX)/bin/bzip2
+	rm -f $(PREFIX)/bin/bunzip2
+	rm -f $(PREFIX)/bin/bzcat
+	rm -f $(PREFIX)/bin/bzip2recover
+	rm -f $(PREFIX)/bin/bzgrep
+	rm -f $(PREFIX)/bin/bzmore
+	rm -f $(PREFIX)/bin/bzdiff
+	rm -f $(PREFIX)/bin/bzegrep
+	rm -f $(PREFIX)/bin/bzfgrep
+	rm -f $(PREFIX)/bin/bzless
+	rm -f $(PREFIX)/bin/bzcmp
+	rm -f $(PREFIX)/include/bzlib.h
+	rm -f $(PREFIX)/lib/libbz2.a
+	rm -f $(PREFIX)/lib/libbz2.so.1.0.6
+	rm -f $(PREFIX)/lib/libbz2.so.1.0
+	rm -f $(PREFIX)/lib/libbz2.so.1
+	rm -f $(PREFIX)/lib/libbz2.so
+	rm -f $(PREFIX)/man/man1/bzip2.1
+	rm -f $(PREFIX)/man/man1/bzgrep.1
+	rm -f $(PREFIX)/man/man1/bzmore.1
+	rm -f $(PREFIX)/man/man1/bzdiff.1
+	rm -f $(PREFIX)/man/man1/bzegrep.1
+	rm -f $(PREFIX)/man/man1/bzfgrep.1
+	rm -f $(PREFIX)/man/man1/bzless.1
+	rm -f $(PREFIX)/man/man1/bzcmp.1
 
 clean: 
-	rm -f *.o libbz2.a bzip2 bzip2recover \
+	rm -f *.o libbz2.a libbz2.so bzip2 bzip2-static bzip2recover \
+	libbz2.so.1 libbz2.so.1.0 libbz2.so.1.0.6 \
 	sample1.rb2 sample2.rb2 sample3.rb2 \
 	sample1.tst sample2.tst sample3.tst
 
