#!/bin/sh

[ `id -u` = 0 ] || { echo "must be root"; exit 1; }

export CFLAGS="-march=i486 -mtune=i686 -Os -pipe"
export CXXFLAGS="-march=i486 -mtune=i686 -Os -pipe -fno-exceptions -fno-rtti"
export CPPFLAGS="-I/usr/local/include"
export LDFLAGS="-L/usr/local/lib"
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:/usr/lib/pkgconfig

MIRROR="http://tint2.googlecode.com/svn/trunk/"
PACKAGE="tint2-svn"
SEP="-"
VERSION="r280"
EXT="tcz"
DESCRIPTION="Panel for openbox     (TESTING)"
AUTHORS="thilor77"
HOMEPAGE="http://code.google.com/p/tint2/"
LICENSE="GPLv2"
ME="Kingdomcome"
DEPS="cairo.tczl expat2.tczl fontconfig.tczl glib2.tczl graphics-libs-1.tczl
      libglade.tczl libxml2.tczl pango.tczl pixman.tczl"
BUILDDEPS="autoconf.tcz automake.tcz cairo-devs.tcz expat2-devs.tcz
           fontconfig-devs.tcz glib2-dev.tcz imlib2-dev.tcz
	   libxml2-devs.tcz libglade-devs.tcz pango-devs.tcz
           pixman-devs.tcz svn.tczl Xorg-7.4-dev.tcz gtk2-devs.tcz
           python.tczl python-dev.tcz pygtk.tczl pygtk-dev.tcz
           pycairo-dev.tcz libffi-dev.tcz pygobject-dev.tcz"
FLAGS="--prefix=/usr/local"
DOCS="usr/local/share/"

TCUSER=`cat /etc/sysconfig/tcuser`
SRC="${PACKAGE}${SEP}${VERSION}.tar.gz"
THISDIR=`pwd`
PKGDIR="${THISDIR}/${PACKAGE}"
SRCDIR="${PKGDIR}/tint2-read-only"

environment(){
   for each in compiletc.tcz squashfs-tools-4.0.tcz ${DEPS} ${BUILDDEPS}; do
      sudo -u ${TCUSER} tce-load -w -i ${each}
   done
   [ -d "${PKGDIR}" ] && rm -rf ${PKGDIR}
   mkdir -p ${PKGDIR}/tmp
   cd ${PKGDIR} && svn checkout ${MIRROR} tint2-read-only
   tar czf ${SRC} tint2-read-only
}

buildit(){
   cd ${SRCDIR}
   ./autogen.sh
   ./configure ${FLAGS}
   make
   make DESTDIR=${PKGDIR}/tmp install
}

workit(){
   cd ${PKGDIR}/tmp
   rm -rf ${DOCS}

   mkdir -p usr/local/share/doc/License
   cp ${SRCDIR}/COPYING usr/local/share/doc/License/${PACKAGE}.txt

   find usr/ | xargs file | grep "executable" | grep ELF | grep "not stripped" | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null
   find usr/ | xargs file | grep "shared object" | grep ELF | grep "not stripped" | cut -f 1 -d : | xargs strip -g 2> /dev/null

   mkdir -p usr/local/tce.installed
cat <<EOF> usr/local/tce.installed/${PACKAGE}
#!/bin/sh

tcuser=\$(cat /etc/sysconfig/tcuser)

busybox cp -a /tmp/tcloop/tint2-svn/usr/local/etc/xdg/tint2/* /usr/local/etc/xdg/tint2/
[ -f /home/\${tcuser}/.config/tint2/tint2rc ] || {
   mkdir -p /home/\${tcuser}/.config/tint2
   busybox cp -p /usr/local/etc/skel/.config/tint2/tint2rc /home/\${tcuser}/.config/tint2/tint2rc
   chown -R ${tcuser}:staff /home/\${tcuser}/.config/tint2
}
EOF
   chmod 775 usr/local/tce.installed/${PACKAGE}

   mkdir -p usr/local/tce.menu
cat <<EOF> usr/local/tce.menu/${PACKAGE}
<JWM>
  <Program label="tint2svn">tint2</Program>
</JWM>
EOF
   chmod 644 usr/local/tce.menu/${PACKAGE}

#   mkdir -p usr/local/tce.icons
#cat <<EOF> usr/local/tce.icons/${PACKAGE}
#i:
#t:
#c:
#EOF
#   chmod 644 usr/local/tce.icons/*

#dont clobber tc setup
   chown -R root:staff usr/local/tce.*
   chmod 775 usr/local/tce.*

#package specific stuff
   tar xzf ${THISDIR}/tint2rcs.tgz
   mkdir -p usr/local/etc/skel/.config/tint2
   ln -sf /usr/local/etc/xdg/tint2/tint2rc usr/local/etc/skel/.config/tint2
   chown -R 1001:50 usr/local/etc/skel/.config
}

packageit(){
   cd ${PKGDIR}/tmp
   for dir in `ls`; do
      find ${dir} -not -type d | sort >> ../${PACKAGE}.${EXT}.list
   done
   mksquashfs . ../${PACKAGE}.${EXT}
   cd ${PKGDIR}
   md5sum ${PACKAGE}.${EXT} > ${PACKAGE}.${EXT}.md5.txt
   [ -f "${PACKAGE}.${EXT}.dep" ] && rm -f ${PACKAGE}.${EXT}.dep
   for each in ${DEPS}; do echo ${each} >> ${PACKAGE}.${EXT}.dep; done
size=`du -h ${PACKAGE}.${EXT} | cut -f 1`
today=`date +%Y/%m/%d`
cat <<EOF> ${PACKAGE}.${EXT}.info
Title:		${PACKAGE}.${EXT}
Description:	${DESCRIPTION}
Version:	${VERSION}
Author:		${AUTHORS}
Original-site:	${HOMEPAGE}
Copying-policy:	${LICENSE}
Size:		${size}
Extension_by:	${ME}
Comments:	A panel for openbox. It will run on other WMs, but will
		not show buttons for task.
		Requires cairo, pango, glib2, pixman, fontconfig,
		graphics-libs-1, expat2, libglade, and libxml2.
		
		New configuration gui tint2wizard optionally depends on
		pygtk and deps
		
		This extension is PPI compatible
Change-log:	2009/10/14 First Version
		2009/11/02 Bumped to r247
Current:	${today} Bumped to r280
EOF
}
#2009/10/14 First Version
#2009/11/02 bumped to 247
#2009/11/25 bumped to 280

#here we go

environment
buildit
workit
packageit
