#!/bin/bash
#
#  fox Slackbuild Script
#  Copyright (C) 2006-2008  C. J. Meidlinger <cj@meidlinger.org>
#
############################
#                          #
#  Vars                    #
#                          #
################################################################################

SOURCE_NAME=fox
SOURCE_VERSION=1.6.33
PACKAGE_VERSION=1
build_dir=`pwd`
PKG_DIR=$build_dir/pkg
PKG_BUILDER="C. J. Meidlinger <cj@meidlinger.org>"
PKG_BUILDER_INITIALS=cjm
PATCHES=

############################
#                          #
#  unpack source           #
#                          #
################################################################################

tar -xzvf ${SOURCE_NAME}-${SOURCE_VERSION}.tar.gz
for t in $PATCHES; do 
     ( cd ${SOURCE_NAME}-*/ && patch -p1 < ../$t )
done

############################
#                          #
#  configure and compile   #
#                          #
################################################################################

( cd ${SOURCE_NAME}-*/ \
     &&  CFLAGS="-O2 -march=i486 -mtune=i686" ./configure --prefix=/usr --sysconfdir=/etc --localstatedir=/var --mandir=/usr/man --datadir=/usr/share --with-xft=yes --enable-release --disable-static --enable-threadsafe \
     &&  make \
     &&  chown -R root.root . \
     &&  find . -perm 777 -exec chmod 755 {} \; \
     &&  find . -perm 555 -exec chmod 755 {} \; \
     &&  find . -perm 444 -exec chmod 644 {} \; \
     &&  find . -perm 666 -exec chmod 644 {} \; \
     &&  find . -perm 664 -exec chmod 644 {} \; \
     &&  make install DESTDIR=$PKG_DIR )

############################
#                          #
#  build package           #
#                          #
################################################################################

#
#  slack-desc
#
mkdir -p $PKG_DIR/install
cat > $PKG_DIR/install/slack-desc << EOF
# HOW TO EDIT THIS FILE:
# The "handy ruler" below makes it easier to edit a package description. Line
# up the first '|' above the ':' following the base package name, and the '|'
# on the right side marks the last column you can put a character in. You must
# make exactly 11 lines for the formatting to be correct. It's also
# customary to leave one space after the ':'.

            |-----handy-ruler------------------------------------------------------|
$SOURCE_NAME: $SOURCE_NAME $SOURCE_VERSION (GUI Toolkit written in C++)
$SOURCE_NAME:
$SOURCE_NAME: FOX is a C++ based Toolkit for developing Graphical User Interfaces
$SOURCE_NAME: easily and effectively. It offers a wide, and growing, collection of
$SOURCE_NAME: Controls, and provides state of the art facilities such as drag and
$SOURCE_NAME: drop, selection, as well as OpenGL widgets for 3D graphical
$SOURCE_NAME: manipulation. FOX also implements icons, images, and user-convenience
$SOURCE_NAME: features such as status line help, and tooltips. Tooltips may even
$SOURCE_NAME: be used for 3D objects!
$SOURCE_NAME:
$SOURCE_NAME: Package created by $PKG_BUILDER 
EOF

#
#  slack-required
#
#cat > $PKG_DIR/install/slack-required << EOF
#
#EOF


#
#  documentation
#
mkdir -p $PKG_DIR/usr/doc/${SOURCE_NAME}-${SOURCE_VERSION}
for t in `ls $build_dir/$SOURCE_NAME*/ | grep -i "install\|readme\|copy\|license\|news\|todo\|author\|about\|change\|thank\|bug\|legal"`; do 
     cp $build_dir/$SOURCE_NAME*/$t $PKG_DIR/usr/doc/${SOURCE_NAME}-${SOURCE_VERSION}
done
cp ${PATCHES} $PKG_DIR/usr/doc/${SOURCE_NAME}-${SOURCE_VERSION}

rm $PKG_DIR/usr/doc/${SOURCE_NAME}-${SOURCE_VERSION}/install-sh 
rm $PKG_DIR/usr/doc/${SOURCE_NAME}-${SOURCE_VERSION}/mkinstalldirs

if [ -d "$PKG_DIR/usr/doc/${SOURCE_NAME}" ] ; then
	mv $PKG_DIR/usr/doc/${SOURCE_NAME}/* $PKG_DIR/usr/doc/${SOURCE_NAME}-${SOURCE_VERSION}
	rm -rf $PKG_DIR/usr/doc/${SOURCE_NAME}
fi
if [ -d "$PKG_DIR/usr/share/doc/${SOURCE_NAME}-1.6" ] ; then
	mv $PKG_DIR/usr/share/doc/${SOURCE_NAME}-1.6/* $PKG_DIR/usr/doc/${SOURCE_NAME}-${SOURCE_VERSION}
	rm -rf $PKG_DIR/usr/share/doc
fi
#
# SlackBuild
#
mkdir -p $PKG_DIR/usr/src/slackbuilds/${SOURCE_NAME}-${SOURCE_VERSION}
cp ${SOURCE_NAME}.SlackBuild $PKG_DIR/usr/src/slackbuilds/${SOURCE_NAME}-${SOURCE_VERSION}
chmod 755 $PKG_DIR/usr/src/slackbuilds/${SOURCE_NAME}-${SOURCE_VERSION}/${SOURCE_NAME}.SlackBuild

#
#  gzip man pages
#
for t in `find $PKG_DIR/usr/man/ -type f` ; do
     gzip $t
done

#
#  gzip info pages
#
rm $PKG_DIR/usr/info/dir
for t in `find $PKG_DIR/usr/info/ -type f` ; do
     gzip $t
done

#
#  perms (for pre-11.0 slacks)
#
#chgrp -R bin $PKG_DIR/usr/bin $PKG_DIR/bin $PKG_DIR/sbin $PKG_DIR/usr/sbin $PKG_DIR/usr/X11R6/bin

#
#  strip binaries
#
(cd $PKG_DIR ; find . | xargs file | grep "current ar archive" | cut -f 1 -d : | xargs strip --strip-debug )
(cd $PKG_DIR ; find . | xargs file | grep "executable" | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded )
(cd $PKG_DIR ; find . | xargs file | grep "shared object" | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded )

#
# doinst.sh
#

#cat > $PKG_DIR/install/doinst.sh << EOF
#!/bin/sh
#insert_new () {
#	filename=\$1
#	if [ ! -f \$filename ] ; then
#		mv \$filename.new \$filename
#	fi
#}
#insert_new etc/configfile.conf

#
# remove cruft
#
rm -r $PKG_DIR/usr/share

#
#  package
#
( cd $PKG_DIR && chown root:root . && chmod 755 . && makepkg -l y -c n ../${SOURCE_NAME}-${SOURCE_VERSION}-i486-${PACKAGE_VERSION}${PKG_BUILDER_INITIALS}.tgz )
