HOW TO ADD BZIP2 SUPPORT TO ZIP

This document describes how to add bzip2 support to Zip.

Adding bzip2 support by compiling or linking in the bzip2 library
adds the additional bzip2 compression method, which can be selected
instead of the Zip traditional compression method deflation to
compress files and often gives a better compression ratio (perhaps
at the cost of greater CPU time).  The compression method is specified
using the "-Z method" command-line option, where "method" may be
either "deflate" (the default), or "bzip2" (if Zip is built with bzip2
support).  Tested with bzip2 library 1.0.4 and earlier.

Notes

Compression method bzip2 requires a modern unzip.  Before using bzip2
compression in Zip, please verify that a modern UnZip program with bzip2
support will be used to read the resulting zip archive so that entries
compressed with bzip2 (compression method 12) can be read.  Older unzips
probably won't recognize the compression method and will skip those entries.

Note that the Zip source kit does not include the bzip2 library or source
files, but these can be found at "http://www.bzip.org/" for example.  See
below for how to add bzip2 to Zip for various operating systems.

Zip using bzip2 compression is not compatible with the bzip2 application,
but instead provides an additional way to compress files before adding
them to a Zip archive.  It does not replace the bzip2 program itself,
which creates bzip2 archives in a different format that are not
compatible with zip or unzip.
 
The bzip2 code and algorithms are provided under the bzip2 license
(provided in the bzip2 source kit) and what is not covered by that license
is covered under the Info-ZIP license.  Info-ZIP will look at issues
involving the use of bzip2 compression in Zip, but any questions about
the bzip2 code and algorithms or bzip2 licensing, for example, should be
directed to the bzip2 maintainer.


Installation

To build Zip with bzip2 support, Zip generally needs one bzip2 header
file, "bzlib.h", and the object library, typically "libbz2.a", except
in cases where the source files are compiled in directly.  If you
are either compiling the bzip2 library or compiling in the bzip2
source files, we recommend defining the C macro BZ_NO_STDIO, which
excludes alot of standalone error code (not used when bzip2 is
used as a library and makes the library smaller) and provides hooks
that Zip can use to provide better error handling.  However, a
standard bzip2 object library will work, though any errors that bzip2
generates may be more cryptic.

Building the bzip2 library from the bzip2 source files (recommended):

  Download the latest bzip2 package (from "http://www.bzip.org/", for
  example).
     
  Unpack the bzip2 source kit (bzip2-1.0.4.tar.gz was current as of
  this writing, but the latest should work).

  Read the README file in the bzip2 source kit.

  Compile the bzip2 library for your OS, preferably defining
  BZ_NO_STDIO.  Note: On UNIX systems, this may be done automatically
  when building Zip, as explained below.


Installation on UNIX (see below for installation on other systems):

  Note:  Zip on UNIX uses the "bzlib.h" include file and the compiled
  "libbz2.a" library to static link to bzip2.  Currently we do not
  support using the shared library (patches welcome).

  The easiest approach may be to drop the two above files in the
  bzip2 directory of the Zip source tree and build Zip using the
  "generic" target, that is, using a command like
    make -f unix/Makefile generic
  If all goes well, make should confirm that it found the files and
  will be compiling in bzip2 by setting the BZIP2_SUPPORT flag and
  then including the libraries while compiling and linking Zip.

  To use bzlib.h and libbz2.a from somewhere else on your system,
  define the "make" macro IZ_BZIP2 to point to that directory.  For
  example:
    make -f unix/Makefile generic IZ_BZIP2=/mybz2
  where /mybz2 might be "/usr/local/src/bzip2/bzip2-1.0.4" on some
  systems.  Only a compiled bzip2 library can be pointed to using
  IZ_BZIP2 and Zip will not compile bzip2 source in other than the
  bzip2 directory.

  If IZ_BZIP2 is not defined, Zip will look for the bzip2 files in
  the "bzip2" directory in the Zip source directory.  The bzip2
  directory is empty in the Zip source distribution (except for
  this install.txt file) and is provided as a place to put the
  bzip2 files.  To use this directory, either drop bzlib.h and
  libbz2.a in it to use the compiled library as noted above or drop
  the contents of the bzip2 source kit in this directory so that
  bzlib.h is directly in the bzip2 directory and Zip will try to
  compile it if no compiled library is already there.


  Unpacking bzip2 so Zip compiles it:

  To make this work, the bzip2 source kit must be unpacked directly
  into the Zip "bzip2" directory.  For example:

      # Unpack the Zip source kit.
      gzip -cd zip30.tar-gz | tar xfo -
      # Move down to the Zip kit's "bzip2" directory, ...
      cd zip30/bzip2
      # ... and unpack the bzip2 source kit there.
      gzip -cd ../../bzip2-1.0.4.tar.gz | tar xfo -
      # Move the bzip2 source files up to the Zip kit's bzip2 directory.
      cd bzip2-1.0.4
      mv * ..
      # Return to the Zip source kit directory, ready to build.
      cd ../..
      # Build Zip.
      make -f unix/Makefile generic


  Using a system bzip2 library:

  If IZ_BZIP2 is not defined and both a compiled library and the bzip2
  source files are missing from the Zip bzip2 directory, Zip will test
  to see if bzip2 is globally defined on the system in the default
  include and library paths and, if found, link in the system bzip2
  library.  This is automatic.


  Preventing inclusion of bzip2:

  To build Zip with _no_ bzip2 support on a system where the automatic
  bzip2 detection scheme will find bzip2, you can specify a bad
  IZ_BZIP2 directory.  For example:

      make -f unix/Makefile generic IZ_BZIP2=no_such_directory

  You can also define NO_BZIP2_SUPPORT to exclude bzip2.


  Verifying bzip2 support in Zip:

  When the Zip build is complete, verify that bzip2 support has been
  enabled by checking the feature list:

      ./zip -v

  If all went well, bzip2 (and its library version) should be listed.


Installation on other systems

  MSDOS:

  Nothing yet.


  WIN32 (Windows NT/2K/XP/2K3/... and Windows 95/98/ME):

  For Windows there seems to be two approaches, either use bzip2
  as a dynamic link library or compile the bzip2 source in directly.
  I have not gotten the static library libbz2.lib to work, but that
  may be me.

  Using bzip2 as a dynamic link library:

    Building bzip2:

    If you have the needed bzlib.h, libbz2.lib, and libbz2.dll files
    you can skip building bzip2.  If not, open the libbz2.dsp project
    and build libbz2.dll

    This creates
      debug/libbz2.lib
    and
      libbz2.dll


    Building Zip:

    Copy libbz2.lib to the bzip2 directory in the Zip source tree.  This
    is needed to compile Zip with bzip2 support.  Also copy the matching
    bzlib.h from the bzip2 source to the same directory.

    Add libbz2.lib to the link list for whatever you are building.  Also
    define the compiler define BZIP2_SUPPORT.

    Build Zip.


    Using Zip with bzip2 as dll:

    Put libbz2.dll in your command path.  This is needed to run Zip with
    bzip2 support.

    Verify that bzip2 is enabled with the command

      zip -v

    You should see bzip2 listed.

  Compiling in bzip2 from the bzip2 source:

    This approach compiles in the bzip2 code directly.  No external
    library is needed.

    Get a copy of the bzip2 source and copy the contents to the bzip2
    directory in the Zip source tree so that bzlib.h is directly in
    the bzip2 directory.

    Use the vc6bz2 project to build Zip.  This project knows of the
    added bzip2 files.

    Verify that bzip2 is enabled with the command

      zip -v


  Windows DLL (WIN32):

  Nothing yet.


  Mac OS X:

  Follow the standard UNIX build procedure.  Mac OS X includes bzip2
  and the UNIX builders should find the bzip2 files in the standard
  places.  Note that the version of bzip2 on your OS may not be
  current and you can instead specify a different library or compile
  your own bzip2 library as noted in the Unix procedures above.


  OS/2:

  Nothing yet.


  VMS (OpenVMS):

  See [.vms]Install_vms.txt for how to enable bzip2 support on VMS.


Last updated 26 March 2007, 15 July 2007, S. Schweda, E. Gordon
