#!/bin/sh
CWD=`pwd`
TMP=${TMP:-/tmp}
PKG=/tmp/package-devel32

VERSION=1.2.3
ARCH=${ARCH:-x86_64}
BUILD=2
DISTRO=${DISTRO:-slamd64}

if [ $DISTRO = slackware ]; then
	PKGARCH=$ARCH
else
	PKGARCH=${ARCH}_${DISTRO}
fi

if [ $DISTRO = slamd64 ]; then
	LIBSUFFIX=${LIBSUFFIX:-64}
else
	LIBSUFFIX=${LIBSUFFIX:-}
fi

#rm -rf $PKG
mkdir -p $PKG
cd $TMP
rm -rf zlib-$VERSION
tar jxvf $CWD/zlib-$VERSION.tar.bz2
cd zlib-$VERSION
chown -R root.root .
find . -perm 777 -exec chmod 755 {} \;
find . -perm 664 -exec chmod 644 {} \;
export CFLAGS="$CFLAGS -fPIC"
./configure \
  --prefix=/usr
make clean
make
./configure \
  --prefix=/usr \
  --libdir=/usr/lib$LIBSUFFIX \
  --shared
make
mkdir -p $PKG/usr/lib$LIBSUFFIX $PKG/lib$LIBSUFFIX
cp -a libz.a libz.so* $PKG/usr/lib$LIBSUFFIX
chmod 755 $PKG/usr/lib$LIBSUFFIX/*
chmod 644 $PKG/usr/lib$LIBSUFFIX/libz.a

( cd $PKG
  find . | xargs file | grep "executable" | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null
  find . | xargs file | grep "shared object" | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null
)