#!/bin/sh
CWD=`pwd`
#PKG=/tmp/package-imagemagick
PKG=/
#rm -rf $PKG
#mkdir -p $PKG

# NOTE:  This is to cope with ImageMagick version numbers such as 5.4.7-4,
# which occur fairly often (but not always).  If these numbers are all the same,
# then this is not one of those versions.

# This is a bit messy, so we'll explain it well.  :-)

# This is the base version number, which is needed to cd into the source tree
BASEVER=5.5.7

# This is the version number used in the source tarball filename
FILEVER=5.5.7-10

# This is the version number used in the package, where a version number cannot
# contain a '-'
PKGVER=5.5.7_10

# Not used.
#ARCH=i486
#BUILD=1

cd /tmp
tar xjvf $CWD/ImageMagick-$FILEVER.tar.bz2
cd ImageMagick-$BASEVER
chown -R root.root .
find . -perm 777 -exec chmod 755 {} \;
find . -perm 666 -exec chmod 644 {} \;
CFLAGS="-O2 -march=i486 -mcpu=i686" \
CXXFLAGS="-O2 -march=i486 -mcpu=i686" \
./configure --prefix=/usr/X11R6 \
            --program-prefix= \
            --enable-16bit-pixel \
            --with-x \
            --with-frozenpaths=no \
            --enable-static=no \
            --enable-shared \
            --with-perl \
            i486-slackware-linux
make

# Trust me, this isn't worth the effort.
#make install DESTDIR=$PKG

make install

# not with PKG=/ you don't
#( cd $PKG/usr/X11R6/bin
#  chown -R root.bin .
#  strip * )
#( cd $PKG/usr/X11R6/lib
#  strip --strip-unneeded *.so* )
#gzip -9 $PKG/usr/X11R6/man/man?/*

mkdir -p $PKG/usr/doc/ImageMagick-$FILEVER
cp -a www/* $PKG/usr/doc/ImageMagick-$FILEVER
cp -a *.txt $PKG/usr/doc/ImageMagick-$FILEVER
## Makefile bug workaround:
#mkdir -p $PKG/usr/man/man3
#cat /usr/man/man3/Image::Magick.3 | gzip -9c > $PKG/usr/man/man3/Image::Magick.3.gz 
mkdir -p $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc

# A great way to drop random files and include shiny new packaging bugs:
#cd $PKG
#makepkg -l y -c n ../imagemagick-$PKGVER-$ARCH-$BUILD.tgz

