#!/bin/sh
CWD=`pwd`
TMP=/tmp
PKG=$TMP/package-t1lib
VERSION=5.1.2
ARCH=alpha
BUILD=1
TARGET=$ARCH-alphaslack-linux

( cd $TMP
tar xf $CWD/t1lib-$VERSION.tar.bz2
cd t1lib-$VERSION
chown -R root.root .
find . -perm 664 -exec chmod 644 {} \;
find . -perm 600 -exec chmod 644 {} \;
find . -perm 444 -exec chmod 644 {} \;
find . -perm 400 -exec chmod 644 {} \;
find . -perm 440 -exec chmod 644 {} \;
find . -perm 777 -exec chmod 755 {} \;
find . -perm 775 -exec chmod 755 {} \;
find . -perm 511 -exec chmod 755 {} \;
find . -perm 711 -exec chmod 755 {} \;
find . -perm 555 -exec chmod 755 {} \;
./configure \
 --prefix=/usr \
 --mandir=/usr/man \
 --infodir=/usr/info \
 --enable-static=no \
 --build=$TARGET
make || exit 1
mkdir -p $PKG/usr
make install prefix=$PKG/usr
( 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
)
chmod 755 $PKG/usr/lib/*.so
chown -R root.bin $PKG/usr/bin
mkdir -p $PKG/usr/doc/t1lib-$VERSION
rm -rf $PKG/usr/share/t1lib/doc
cp -a Fonts $PKG/usr/share/t1lib
/bin/ls $PKG/usr/share/t1lib/Fonts/afm/*.afm /usr/X11R6/lib/X11/fonts/Type1/*.afm | sort | uniq | wc -l | sed -e 's/ //g' > $PKG/usr/share/t1lib/FontDataBase
( cd $PKG/usr/share/t1lib/Fonts/afm ; /bin/ls *.afm ; cd /usr/X11R6/lib/X11/fonts/Type1 ; /bin/ls *.afm ) | sort | uniq >> $PKG/usr/share/t1lib/FontDataBase
cat << EOF > $PKG/usr/share/t1lib/t1lib.config
This is a configuration file for t1lib

FONTDATABASE=/usr/share/t1lib/FontDataBase
ENCODING=/usr/share/t1lib/Fonts/enc
AFM=/usr/share/t1lib/Fonts/afm:/usr/X11R6/lib/X11/fonts/Type1
TYPE1=/usr/share/t1lib/Fonts/type1:/usr/X11R6/lib/X11/fonts/Type1
EOF
chown -R root.root $PKG/usr/share/t1lib
mkdir -p $PKG/etc/profile.d
cat << EOF > $PKG/etc/profile.d/t1lib.sh
T1LIB_CONFIG=/usr/share/t1lib/t1lib.config
export T1LIB_CONFIG
EOF
cat << EOF > $PKG/etc/profile.d/t1lib.csh
setenv T1LIB_CONFIG /usr/share/t1lib/t1lib.config
EOF
chmod 755 $PKG/etc/profile.d/*
cp -a Changes LGPL LICENSE Makefile Makefile.in README.t1lib-$VERSION README.t1python README.win32 $PKG/usr/doc/t1lib-$VERSION
chmod 644 $PKG/usr/doc/t1lib-$VERSION/*
chown -R root.root $PKG/usr/doc/t1lib-$VERSION/*
mkdir -p $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc
cd $PKG
makepkg -l y -c n $TMP/t1lib-$VERSION-$ARCH-$BUILD.tgz
) 2>&1 | tee $TMP/t1lib.build.log
