--- bzip2.c~0	2010-09-11 05:04:53.000000000 +0300
+++ bzip2.c	2012-02-13 12:39:34.000000000 +0200
@@ -34,7 +34,7 @@
 --*/
 #define BZ_LCCWIN32  0
 
-#if defined(_WIN32) && !defined(__CYGWIN__)
+#if defined(_WIN32) && !defined(__CYGWIN__) && !defined(__MINGW32__)
 #undef  BZ_LCCWIN32
 #define BZ_LCCWIN32 1
 #undef  BZ_UNIX
@@ -72,7 +72,9 @@
 #   include <utime.h>
 #   include <unistd.h>
 #   include <sys/stat.h>
-#   include <sys/times.h>
+#   ifndef __MINGW32__
+#      include <sys/times.h>
+#   endif
 
 #   define PATH_SEP    '/'
 #   define MY_LSTAT    lstat
@@ -94,7 +96,7 @@
 #      define NORETURN /**/
 #   endif
 
-#   ifdef __DJGPP__
+#   if defined(__DJGPP__) || defined(__MINGW32__)
 #     include <io.h>
 #     include <fcntl.h>
 #     undef MY_LSTAT
@@ -108,6 +110,11 @@
                                   O_BINARY );           \
            ERROR_IF_MINUS_ONE ( retVal );               \
         } while ( 0 )
+#     define IS_PATH_SEP(C)  ((C) == '/' || (C) == '\\')
+#     ifdef __MINGW32__
+#       define fchmod(x,y)   0
+#       define fchown(x,y,z) 0
+#     endif
 #   endif
 
 #   ifdef __CYGWIN__
@@ -222,7 +229,26 @@
 static void*   myMalloc     ( Int32 );
 static void    applySavedFileAttrToOutputFile ( IntNative fd );
 
+#if defined (_WIN32) && !defined (__CYGWIN__)
+/*---------------------------------------------------*/
+/*--- A more accurate implementation of isatty    ---*/
+/*--- for MS-Windows.  The standard one returns   ---*/
+/*--- non-zero for the null device.               ---*/
+/*--- (Stolen from gnulib with cosmetic changes.) ---*/
+/*---------------------------------------------------*/
+
+#include <windows.h>
+
+int w32_isatty ( int fd )
+{
+  if (_isatty(fd))
+    return (((long) (HANDLE) _get_osfhandle(fd)) & 3) == 3;
+  return 0;
+}
+
+#define isatty(x)  w32_isatty(x)
 
+#endif
 
 /*---------------------------------------------------*/
 /*--- An implementation of 64-bit ints.  Sigh.    ---*/
@@ -954,7 +980,7 @@
    the interim permissions required. (--- --- rw-).
 
    For non-Unix platforms, if we are not worrying about
-   security issues, simple this simply behaves like fopen.
+   security issues, this simply behaves like fopen.
 */
 static
 FILE* fopen_output_safely ( Char* name, const char* mode )
@@ -1082,7 +1108,7 @@
 static 
 Bool containsDubiousChars ( Char* name )
 {
-#  if BZ_UNIX
+#  if BZ_UNIX && !defined(__MINGW32__) && !defined(__DJGPP__)
    /* On unix, files can contain any characters and the file expansion
     * is performed by the shell.
     */
@@ -1807,7 +1833,7 @@
    /*-- Set up signal handlers for mem access errors --*/
    signal (SIGSEGV, mySIGSEGVorSIGBUScatcher);
 #  if BZ_UNIX
-#  ifndef __DJGPP__
+#  if !defined(__DJGPP__) && defined(SIGBUS)
    signal (SIGBUS,  mySIGSEGVorSIGBUScatcher);
 #  endif
 #  endif
@@ -1818,7 +1844,7 @@
    copyFileName ( progNameReally, argv[0] );
    progName = &progNameReally[0];
    for (tmp = &progNameReally[0]; *tmp != '\0'; tmp++)
-      if (*tmp == PATH_SEP) progName = tmp + 1;
+     if (IS_PATH_SEP(*tmp)) progName = tmp + 1;
 
 
    /*-- Copy flags from env var BZIP2, and 
@@ -1951,7 +1977,7 @@
    if (srcMode == SM_F2F) {
       signal (SIGINT,  mySignalCatcher);
       signal (SIGTERM, mySignalCatcher);
-#     if BZ_UNIX
+#     if BZ_UNIX && defined(SIGHUP)
       signal (SIGHUP,  mySignalCatcher);
 #     endif
    }
--- bzip2recover.c~0	2010-09-11 05:18:40.000000000 +0300
+++ bzip2recover.c	2012-02-13 12:22:09.067167800 +0200
@@ -475,6 +475,15 @@
          } else {
             ++split;
 	 }
+#if defined(_WIN32) && !defined(__CYGWIN__)
+	 /* Support mix of both styles of slashes.  */
+	 {
+	   char *pslash = strrchr (split, '/');
+
+	   if (pslash)
+	     split = pslash + 1;
+	 }
+#endif
 	 /* Now split points to the start of the basename. */
          ofs  = split - outFileName;
          sprintf (split, "rec%5d", wrBlock+1);
--- bzlib.h~0	2010-09-11 05:08:42.000000000 +0300
+++ bzlib.h	2012-02-13 12:32:36.190249500 +0200
@@ -75,21 +75,39 @@
 #include <stdio.h>
 #endif
 
-#ifdef _WIN32
+#if defined(_WIN32) && !defined(__CYGWIN__)
 #   include <windows.h>
 #   ifdef small
       /* windows.h define small to char */
 #      undef small
 #   endif
-#   ifdef BZ_EXPORT
-#   define BZ_API(func) WINAPI func
-#   define BZ_EXTERN extern
-#   else
-   /* import windows dll dynamically */
-#   define BZ_API(func) (WINAPI * func)
-#   define BZ_EXTERN
-#   endif
+#   ifndef __GNUC__
+       /* Use these rules only for non-gcc native windows builds.  */
+#      ifdef BZ_EXPORT
+#      define BZ_API(func) WINAPI func
+#      define BZ_EXTERN extern
+#      else
+       /* import windows dll dynamically */
+#      define BZ_API(func) (WINAPI * func)
+#      define BZ_EXTERN
+#      endif
+#  else
+       /* For gcc on native win32, use import library trampoline       */
+       /* functions on DLL import.  This avoids requiring clients to   */
+       /* use special compilation flags depending on whether eventual  */
+       /* link will be against static libbz2 or against DLL, at the    */
+       /* expense of a small loss of efficiency. */
+
+       /* Because libbz2 does not export any DATA items, GNU ld's      */
+       /* "auto-import" is not a factor; the MinGW-built DLL can be    */
+       /* used by other compilers, provided an import library suitable */
+       /* for that compiler is (manually) constructed using the .def   */
+       /* file and the appropriate tool. */
+#      define BZ_API(func) func
+#      define BZ_EXTERN extern
+#  endif
 #else
+    /* non-win32 platforms, and Cygwin.  */
 #   define BZ_API(func) func
 #   define BZ_EXTERN extern
 #endif
--- NUL	1970-01-01 02:00:00.000000000 +0200
+++ build.bat	2012-02-13 12:51:05.471499500 +0200
@@ -0,0 +1,6 @@
+@echo off
+Rem Batch file to build bzip2 on MS-Windows with MinGW
+
+make BIGFILES= USERCFLAGS="-gdwarf-2 -g3" PREFIX=d:/usr EXEEXT=.exe
+
+make -f Makefile.dll BIGFILES= USERCFLAGS="-gdwarf-2 -g3" USERDLLFLAGS="-gdwarf-2 -g3" PREFIX=d:/usr EXEEXT=.exe
--- Makefile~	2012-02-13 07:56:27.611989500 +0200
+++ Makefile	2012-02-16 13:31:41.017703000 +0200
@@ -20,9 +20,11 @@
 RANLIB=ranlib
 LDFLAGS=
 EXEEXT=
+USERCFLAGS=
+LN_S=ln -s
 
 BIGFILES=-D_FILE_OFFSET_BITS=64
-CFLAGS=-Wall -Winline -O2 -g $(BIGFILES) $(USERFLAGS)
+CFLAGS=-Wall -Winline -O3 -g $(BIGFILES) $(USERCFLAGS)
 
 # Where you want it installed when you do 'make install'
 PREFIX=/usr/local
@@ -67,43 +69,52 @@
 	@cat words3
 
 install: bzip2$(EXEEXT) bzip2recover$(EXEEXT)
-	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
-	if ( test ! -d $(PREFIX)/man/man1 ) ; then mkdir -p $(PREFIX)/man/man1 ; fi
-	if ( test ! -d $(PREFIX)/include ) ; then mkdir -p $(PREFIX)/include ; fi
-	cp -f bzip2 $(PREFIX)/bin/bzip2
-	cp -f bzip2 $(PREFIX)/bin/bunzip2
-	cp -f bzip2 $(PREFIX)/bin/bzcat
-	cp -f bzip2recover $(PREFIX)/bin/bzip2recover
-	chmod a+x $(PREFIX)/bin/bzip2
-	chmod a+x $(PREFIX)/bin/bunzip2
-	chmod a+x $(PREFIX)/bin/bzcat
-	chmod a+x $(PREFIX)/bin/bzip2recover
-	cp -f bzip2.1 $(PREFIX)/man/man1
-	chmod a+r $(PREFIX)/man/man1/bzip2.1
+	-mkdir $(PREFIX)/bin
+	-mkdir $(PREFIX)/lib
+	-mkdir $(PREFIX)/share
+	-mkdir $(PREFIX)/share/man
+	-mkdir $(PREFIX)/share/man/man1
+	-mkdir $(PREFIX)/include
+	cp -f bzip2$(EXEEXT) $(PREFIX)/bin/bzip2$(EXEEXT)
+	cp -f bzip2$(EXEEXT) $(PREFIX)/bin/bunzip2$(EXEEXT)
+	cp -f bzip2$(EXEEXT) $(PREFIX)/bin/bzcat$(EXEEXT)
+	cp -f bzip2recover$(EXEEXT) $(PREFIX)/bin/bzip2recover$(EXEEXT)
+	chmod a+x $(PREFIX)/bin/bzip2$(EXEEXT)
+	chmod a+x $(PREFIX)/bin/bunzip2$(EXEEXT)
+	chmod a+x $(PREFIX)/bin/bzcat$(EXEEXT)
+	chmod a+x $(PREFIX)/bin/bzip2recover$(EXEEXT)
+	cp -f bzip2.1 $(PREFIX)/share/man/man1
+	chmod a+r $(PREFIX)/share/man/man1/bzip2.1
 	cp -f bzlib.h $(PREFIX)/include
 	chmod a+r $(PREFIX)/include/bzlib.h
 	cp -f libbz2.a $(PREFIX)/lib
 	chmod a+r $(PREFIX)/lib/libbz2.a
 	cp -f bzgrep $(PREFIX)/bin/bzgrep
-	ln -s -f $(PREFIX)/bin/bzgrep $(PREFIX)/bin/bzegrep
-	ln -s -f $(PREFIX)/bin/bzgrep $(PREFIX)/bin/bzfgrep
+	$(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
+	$(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
+	$(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
-	chmod a+r $(PREFIX)/man/man1/bzmore.1
-	chmod a+r $(PREFIX)/man/man1/bzdiff.1
-	echo ".so man1/bzgrep.1" > $(PREFIX)/man/man1/bzegrep.1
-	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
+	cp -f bzgrep.1 bzmore.1 bzdiff.1 $(PREFIX)/share/man/man1
+	chmod a+r $(PREFIX)/share/man/man1/bzgrep.1
+	chmod a+r $(PREFIX)/share/man/man1/bzmore.1
+	chmod a+r $(PREFIX)/share/man/man1/bzdiff.1
+	echo ".so man1/bzgrep.1" > $(PREFIX)/share/man/man1/bzegrep.1
+	echo ".so man1/bzgrep.1" > $(PREFIX)/share/man/man1/bzfgrep.1
+	echo ".so man1/bzmore.1" > $(PREFIX)/share/man/man1/bzless.1
+	echo ".so man1/bzdiff.1" > $(PREFIX)/share/man/man1/bzcmp.1
+
+install-strip: install
+	strip $(PREFIX)/bin/bzip2$(EXEEXT)
+	strip $(PREFIX)/bin/bunzip2$(EXEEXT)
+	strip $(PREFIX)/bin/bzip2recover$(EXEEXT)
+	strip $(PREFIX)/bin/bzcat$(EXEEXT)
+	strip --strip-debug $(PREFIX)/lib/libbz2.a
+	chmod 644 $(PREFIX)/lib/libbz2.a && ranlib $(PREFIX)/lib/libbz2.a
 
 clean: 
 	rm -f *.o libbz2.a bzip2 bzip2recover \
--- Makefile.orig	2010-09-11 04:46:02.000000000 +0300
+++ Makefile	2012-02-16 13:31:41.017703000 +0200
@@ -19,9 +19,12 @@
 AR=ar
 RANLIB=ranlib
 LDFLAGS=
+EXEEXT=
+USERCFLAGS=
+LN_S=ln -s
 
 BIGFILES=-D_FILE_OFFSET_BITS=64
-CFLAGS=-Wall -Winline -O2 -g $(BIGFILES)
+CFLAGS=-Wall -Winline -O3 -g $(BIGFILES) $(USERCFLAGS)
 
 # Where you want it installed when you do 'make install'
 PREFIX=/usr/local
@@ -35,25 +38,21 @@
       decompress.o \
       bzlib.o
 
-all: libbz2.a bzip2 bzip2recover test
+all: libbz2.a bzip2$(EXEEXT) bzip2recover$(EXEEXT) test
 
-bzip2: libbz2.a bzip2.o
-	$(CC) $(CFLAGS) $(LDFLAGS) -o bzip2 bzip2.o -L. -lbz2
+bzip2$(EXEEXT): libbz2.a bzip2.o
+	$(CC) $(CFLAGS) $(LDFLAGS) -o $@ bzip2.o -L. -lbz2
 
-bzip2recover: bzip2recover.o
-	$(CC) $(CFLAGS) $(LDFLAGS) -o bzip2recover bzip2recover.o
+bzip2recover$(EXEEXT): bzip2recover.o
+	$(CC) $(CFLAGS) $(LDFLAGS) -o $@ bzip2recover.o
 
 libbz2.a: $(OBJS)
 	rm -f libbz2.a
 	$(AR) cq libbz2.a $(OBJS)
-	@if ( test -f $(RANLIB) -o -f /usr/bin/ranlib -o \
-		-f /bin/ranlib -o -f /usr/ccs/bin/ranlib ) ; then \
-		echo $(RANLIB) libbz2.a ; \
-		$(RANLIB) libbz2.a ; \
-	fi
+	$(RANLIB) libbz2.a
 
 check: test
-test: bzip2
+test: bzip2$(EXEEXT)
 	@cat words1
 	./bzip2 -1  < sample1.ref > sample1.rb2
 	./bzip2 -2  < sample2.ref > sample2.rb2
@@ -61,7 +60,7 @@
 	./bzip2 -d  < sample1.bz2 > sample1.tst
 	./bzip2 -d  < sample2.bz2 > sample2.tst
 	./bzip2 -ds < sample3.bz2 > sample3.tst
-	cmp sample1.bz2 sample1.rb2 
+	cmp sample1.bz2 sample1.rb2
 	cmp sample2.bz2 sample2.rb2
 	cmp sample3.bz2 sample3.rb2
 	cmp sample1.tst sample1.ref
@@ -69,44 +68,53 @@
 	cmp sample3.tst sample3.ref
 	@cat words3
 
-install: bzip2 bzip2recover
-	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
-	if ( test ! -d $(PREFIX)/man/man1 ) ; then mkdir -p $(PREFIX)/man/man1 ; fi
-	if ( test ! -d $(PREFIX)/include ) ; then mkdir -p $(PREFIX)/include ; fi
-	cp -f bzip2 $(PREFIX)/bin/bzip2
-	cp -f bzip2 $(PREFIX)/bin/bunzip2
-	cp -f bzip2 $(PREFIX)/bin/bzcat
-	cp -f bzip2recover $(PREFIX)/bin/bzip2recover
-	chmod a+x $(PREFIX)/bin/bzip2
-	chmod a+x $(PREFIX)/bin/bunzip2
-	chmod a+x $(PREFIX)/bin/bzcat
-	chmod a+x $(PREFIX)/bin/bzip2recover
-	cp -f bzip2.1 $(PREFIX)/man/man1
-	chmod a+r $(PREFIX)/man/man1/bzip2.1
+install: bzip2$(EXEEXT) bzip2recover$(EXEEXT)
+	-mkdir $(PREFIX)/bin
+	-mkdir $(PREFIX)/lib
+	-mkdir $(PREFIX)/share
+	-mkdir $(PREFIX)/share/man
+	-mkdir $(PREFIX)/share/man/man1
+	-mkdir $(PREFIX)/include
+	cp -f bzip2$(EXEEXT) $(PREFIX)/bin/bzip2$(EXEEXT)
+	cp -f bzip2$(EXEEXT) $(PREFIX)/bin/bunzip2$(EXEEXT)
+	cp -f bzip2$(EXEEXT) $(PREFIX)/bin/bzcat$(EXEEXT)
+	cp -f bzip2recover$(EXEEXT) $(PREFIX)/bin/bzip2recover$(EXEEXT)
+	chmod a+x $(PREFIX)/bin/bzip2$(EXEEXT)
+	chmod a+x $(PREFIX)/bin/bunzip2$(EXEEXT)
+	chmod a+x $(PREFIX)/bin/bzcat$(EXEEXT)
+	chmod a+x $(PREFIX)/bin/bzip2recover$(EXEEXT)
+	cp -f bzip2.1 $(PREFIX)/share/man/man1
+	chmod a+r $(PREFIX)/share/man/man1/bzip2.1
 	cp -f bzlib.h $(PREFIX)/include
 	chmod a+r $(PREFIX)/include/bzlib.h
 	cp -f libbz2.a $(PREFIX)/lib
 	chmod a+r $(PREFIX)/lib/libbz2.a
 	cp -f bzgrep $(PREFIX)/bin/bzgrep
-	ln -s -f $(PREFIX)/bin/bzgrep $(PREFIX)/bin/bzegrep
-	ln -s -f $(PREFIX)/bin/bzgrep $(PREFIX)/bin/bzfgrep
+	$(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
+	$(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
+	$(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
-	chmod a+r $(PREFIX)/man/man1/bzmore.1
-	chmod a+r $(PREFIX)/man/man1/bzdiff.1
-	echo ".so man1/bzgrep.1" > $(PREFIX)/man/man1/bzegrep.1
-	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
+	cp -f bzgrep.1 bzmore.1 bzdiff.1 $(PREFIX)/share/man/man1
+	chmod a+r $(PREFIX)/share/man/man1/bzgrep.1
+	chmod a+r $(PREFIX)/share/man/man1/bzmore.1
+	chmod a+r $(PREFIX)/share/man/man1/bzdiff.1
+	echo ".so man1/bzgrep.1" > $(PREFIX)/share/man/man1/bzegrep.1
+	echo ".so man1/bzgrep.1" > $(PREFIX)/share/man/man1/bzfgrep.1
+	echo ".so man1/bzmore.1" > $(PREFIX)/share/man/man1/bzless.1
+	echo ".so man1/bzdiff.1" > $(PREFIX)/share/man/man1/bzcmp.1
+
+install-strip: install
+	strip $(PREFIX)/bin/bzip2$(EXEEXT)
+	strip $(PREFIX)/bin/bunzip2$(EXEEXT)
+	strip $(PREFIX)/bin/bzip2recover$(EXEEXT)
+	strip $(PREFIX)/bin/bzcat$(EXEEXT)
+	strip --strip-debug $(PREFIX)/lib/libbz2.a
+	chmod 644 $(PREFIX)/lib/libbz2.a && ranlib $(PREFIX)/lib/libbz2.a
 
 clean: 
 	rm -f *.o libbz2.a bzip2 bzip2recover \
--- Makefile-libbz2_so	2010-09-11 05:07:52.000000000 +0300
+++ Makefile.dll	2012-02-16 13:34:42.111267900 +0200
@@ -1,8 +1,6 @@
-
+# -*- mode: Makefile -*-
 # This Makefile builds a shared version of the library, 
-# libbz2.so.1.0.6, with soname libbz2.so.1.0,
-# at least on x86-Linux (RedHat 7.2), 
-# with gcc-2.96 20000731 (Red Hat Linux 7.1 2.96-98).  
+# libbz2-1.0.6.dll, at least with MinGW GCC on MS-Windows
 # Please see the README file for some important info 
 # about building the library like this.
 
@@ -24,7 +22,9 @@
 SHELL=/bin/sh
 CC=gcc
 BIGFILES=-D_FILE_OFFSET_BITS=64
-CFLAGS=-fpic -fPIC -Wall -Winline -O2 -g $(BIGFILES)
+CFLAGS=-Wall -Winline -O3 -g $(BIGFILES) $(USERCFLAGS)
+DLLFLAGS=$(USERDLLFLAGS)
+EXEEXT=
 
 OBJS= blocksort.o  \
       huffman.o    \
@@ -35,13 +35,20 @@
       bzlib.o
 
 all: $(OBJS)
-	$(CC) -shared -Wl,-soname -Wl,libbz2.so.1.0 -o libbz2.so.1.0.6 $(OBJS)
-	$(CC) $(CFLAGS) -o bzip2-shared bzip2.c libbz2.so.1.0.6
-	rm -f libbz2.so.1.0
-	ln -s libbz2.so.1.0.6 libbz2.so.1.0
+	$(CC) $(DLLFLAGS) -shared $(OBJS) -o libbz2-1.0.6.dll -Wl,--enable-auto-image-base -Xlinker -out-implib -Xlinker libbz2.dll.a
+	$(CC) $(CFLAGS) -o bzip2-shared$(EXEEXT) bzip2.c libbz2.dll.a
+
+install: all
+	-mkdir $(PREFIX)/bin
+	-mkdir $(PREFIX)/lib
+	cp -f libbz2-1.0.6.dll $(PREFIX)/bin
+	cp -f libbz2.dll.a $(PREFIX)/lib
+
+install-strip: install
+	strip --strip-unneeded $(PREFIX)/bin/libbz2-1.0.6.dll
 
 clean: 
-	rm -f $(OBJS) bzip2.o libbz2.so.1.0.6 libbz2.so.1.0 bzip2-shared
+	rm -f $(OBJS) bzip2.o libbz2-1.0.6.dll bzip2-shared$(EXEEXT)
 
 blocksort.o: blocksort.c
 	$(CC) $(CFLAGS) -c blocksort.c
