#!/bin/sh -e

make CC="${CC:-cc} $CFLAGS -fPIC $LDFLAGS" -f Makefile-libbz2_so
make CC="${CC:-cc} $CFLAGS -fPIC $LDFLAGS" bzip2recover libbz2.a

for bin in bzip2-shared bzdiff bzgrep bzip2recover bzmore; do
    install -Dm755 "$bin" "$1/pkg/$3/${bin%%-shared}"
done

install -Dm755 libbz2.so.1.0.8 "$1/pkg/$3/libbz2.so.1.0.8"
install -Dm644 libbz2.a        "$1/pkg/$3/libbz2.a"
install -Dm644 bzip2.1         "$1/pkg/$3/man/man1/bzip2.1"
install -Dm644 bzlib.h         "$1/pkg/$3/inc/bzlib.h"

for lib in libbz2.so libbz2.so.1 libbz2.so.1.0; do
    ln -sf libbz2.so.1.0.8 "$1/pkg/$3/$lib"
done

ln -sf bzip2 "$1/pkg/$3/exec/bunzip2"
ln -sf bzip2 "$1/pkg/$3/exec/bzcat"
