#!/bin/sh
CWD=`pwd`
TMP=/tmp
PKG=$TMP/package-gettext
VERSION=0.16.1
ARCH=alpha
BUILD=2
TARGET=$ARCH-alphaslack-linux

rm -rf $PKG
mkdir -p $PKG
( cd $TMP
rm -rf gettext-$VERSION
tar xzf $CWD/gettext-$VERSION.tar.gz
cd gettext-$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 \
 $TARGET || exit
make || exit
make install DESTDIR=$PKG || exit
rm -rf $PKG/usr/lib/libintl.* $PKG/usr/share/locale/locale.alias $PKG/usr/include/libintl.h
chown -R root:bin $PKG/usr/bin
mv $PKG/usr/share/doc $PKG/usr/doc
mv $PKG/usr/doc/gettext $PKG/usr/doc/gettext-$VERSION
( cd $PKG/usr/doc/gettext-$VERSION
  rm -rf javadoc*
  # These take up a ton of space otherwise
  tar cf examples.tar examples
  bzip2 -9 examples.tar
  rm -rf examples
  # Move the HTML docs into a subdirectory:
  mkdir html
  mv *.html html
  tar cf html.tar html
  bzip2 -9 html.tar
  rm -rf html
  # This file isn't in the package, but it's in one you have to install, or there will be
  # bigger problems than this dead link:
  rm -f ABOUT-NLS
  ln -sf /usr/share/gettext/ABOUT-NLS .
  mv ../libasprintf .
)
( cd $PKG/usr/info ; rm -rf dir ; gzip -9 * )
gzip -9 $PKG/usr/man/man?/*
( cd $PKG
  find . | xargs file | grep "executable" | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded
  find . | xargs file | grep "shared object" | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded
)
mkdir -p $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc
cd $PKG
makepkg -l y -c n $TMP/gettext-$VERSION-$ARCH-$BUILD.tgz
) 2>&1 | tee $TMP/gettext.build.log
