# bzip2, ftp://sourceware.cygnus.com/pub/bzip2/

name=bzip2
version=1.0.2
source=($name-$version.tar.gz)

build() {
    cd $name-$version
    make -f Makefile-libbz2_so
    make
    mkdir -p $PKG/usr/include
    cp -a bzlib.h $PKG/usr/include
    chown root.root $PKG/usr/include/bzlib.h
    chmod 644 $PKG/usr/include/bzlib.h
    mkdir -p $PKG/bin
    mkdir -p $PKG/lib
    mkdir -p $PKG/usr/lib
    cp -a libbz2.a $PKG/usr/lib/libbz2.a
    cp -a libbz2.so.1.0.2 $PKG/lib/libbz2.so.1.0.2
    chown root.root $PKG/usr/lib/libbz2.a $PKG/lib/libbz2.so.1.0.2
    chmod 644 $PKG/usr/lib/libbz2.a
    chmod 755 $PKG/lib/libbz2.so.1.0.2
    strip bzip2-shared bzip2recover
    cat bzip2-shared > $PKG/bin/bzip2
    cat bzip2recover > $PKG/bin/bzip2recover
    cat bzip2.1 | gzip -9c > $PKG/usr/man/man1/bzip2.1.gz
    echo '.so man1/bzip2.1' | gzip -9c > $PKG/usr/man/man1/bzip2recover.1.gz
    ( cd $PKG/lib ; rm -rf libbz2.so.1.0 )
    ( cd $PKG/lib ; ln -sf libbz2.so.1.0.2 libbz2.so.1.0 )
    ( cd $PKG/usr/lib ; rm -rf libbz2.so )
    ( cd $PKG/usr/lib ; ln -sf /lib/libbz2.so.1.0 libbz2.so )
    ( cd $PKG/bin ; chmod 755 bzip2 )
    ( cd $PKG/bin ; rm -rf bunzip2 )
    ( cd $PKG/bin ; ln -sf bzip2 bunzip2 )
}
