# osmo
# Builds from https://github.com/puppylinux-woof-CE/petbuilds

. ../func
. ../build.conf

URL=http://distro.ibiblio.org/puppylinux/sources/o
PKG=osmo
VER=0.2.10.0-patched
SRC_VER=0.2.10-patched_96dpi_version_libnotify
COMP=tar.gz
DESC="Light weight calendar and organiser"
DEPS=+gtk+2,+libgtkhtml,+libnotify
CAT=Personal
DESKTOP=osmo.desktop
CWD=`pwd`
[ -z "$MWD" ] && MWD=`dirname $CWD`	

ARCH=`uname -m`
case $ARCH in
 *64) LIBDIR=lib64 ;;
 *) LIBDIR=lib ;;
esac

build() {
	mv ${PKG}-${SRC_VER} ${PKG}-${VER}
	# since not X compiling forget build triplet
	cd ${PKG}-${VER}
	./configure --prefix=/usr \
				--localstatedir=/var \
				--sysconfdir=/etc \
				--libdir=/usr/${LIBDIR} #LIBS=-lm 
	[ "$?" -eq 0 ] || build_fail $PKG
	#damn LIBS no work, hack configure.ac
	sed -i 's%\-ltar%\-ltar \-lm%' src/Makefile
	make $MKFLG
	[ "$?" -eq 0 ] || build_fail $PKG
	make DESTDIR=$CWD/$PKG-install install
	[ "$?" -ne 0 ] && build_fail 
	cd -
}
	
package() {
	get_files $PKG-install $PKG-$VER-$ARCH
	(cd ${PKG}-${VER}; $MWD/split.sh ../$PKG-install)
	# add this recipe
	install -d -m 0755 ./$PKG-$VER-$ARCH/usr/share/doc
	cat ${PKG}.petbuild > ./$PKG-$VER-$ARCH/usr/share/doc/$PKG-build-recipe
	if [ "$DESKTOP" ];then
		install -d -m 0755 ./$PKG-$VER-$ARCH/usr/share/applications
		cat $DESKTOP > ./$PKG-$VER-$ARCH/usr/share/applications/$DESKTOP
	fi
	# delete any icon cache or library cache
	find ./$PKG-$VER-$ARCH -type f -name '*cache' -delete
	[ -f ./pinstall.sh ] && install -m 0755 pinstall.sh ./$PKG-$VER-$ARCH/
	[ -f ./puninstall.sh ] && install -m 0755 puninstall.sh ./$PKG-$VER-$ARCH/
	for p in `ls|grep "\-${ARCH}"|grep -v "files$"` ; do
		case $p in
			*_DEV*) DESC="$PKG development"; DEPS=+${PKG} ;;
			*_DOC*) DESC="$PKG documentation"; DEPS=+${PKG} ;;
			*_NLS*) DESC="$PKG locales"; DEPS=+${PKG} ;;
		esac	
		echo "packaging $p"	
		dir2pet -x -s -w="$DESC" -d="$DEPS" -c=$CAT -p=${p} 2>&1 >/dev/null
		rm -r $p
		mv ${p}.pet ../0pets_out
	done
	rm -r $PKG-install
	rm -r ${PKG}-${VER}
	mv -f *.files ../0logs
	echo "done!"
}

# main
retrieve ${PKG}-${SRC_VER}.${COMP}
extract ${PKG}-${SRC_VER}.${COMP}
build
package	
