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

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

URL=http://distro.ibiblio.org/puppylinux/sources/g/
PKG=guess_fstype
SRC=guess_fs
VER=20140626
COMP=tar.gz
DESC="utility to guess the filesystem in use"
DEPS=
CAT=BuildingBlock
BUILD=
CWD=$(pwd)
[ -z "$MWD" ] && MWD=$(dirname $CWD)
[ -z "$BUILD" ] && BUILD=$DEF_BUILD

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

patch() {
	cd ${SRC}-${VER}
	type musl-gcc 2>&1 > /dev/null
	case $? in
		0) #patch Makefile for static
			sed -i 's%^#CC%CC%' Makefile ;;
		*) echo "using gcc" ;;
	esac
	cd -
}

build() {
	# since not X compiling forget build triplet
	cd ${SRC}-${VER}
	make
	[ "$?" -eq 0 ] || exit
	install -d -m 0755 $CWD/${PKG}-${VER}-${ARCH}_${BUILD}/usr/bin
	install -m 0755 $PKG $CWD/${PKG}-${VER}-${ARCH}_${BUILD}/usr/bin
	strip --strip-unneeded $CWD/${PKG}-${VER}-${ARCH}_${BUILD}/usr/bin/$PKG
	make clean
	cd -
}
	
package() {
	# add this recipe
	install -d -m 0755 ./${PKG}-${VER}-${ARCH}_${BUILD}/usr/share/doc
	cat ${PKG}.petbuild > ./${PKG}-${VER}-${ARCH}_${BUILD}/usr/share/doc/$PKG-build-recipe
	if [ "$DESKTOP" ];then
		install -d -m 0755 ./${PKG}-${VER}-${ARCH}_${BUILD}/usr/share/applications
		cat $DESKTOP > ./${PKG}-${VER}-${ARCH}_${BUILD}/usr/share/applications/$DESKTOP
	fi
	# delete any icon cache or library cache
	find ./${PKG}-${VER}-${ARCH}_${BUILD} -type f -name '*cache' -delete
	[ -f ./pinstall.sh ] && install -m 0755 pinstall.sh ./${PKG}-${VER}-${ARCH}_${BUILD}/
	[ -f ./puninstall.sh ] && install -m 0755 puninstall.sh ./${PKG}-${VER}-${ARCH}_${BUILD}/
	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 ${SRC}-${VER}
	rm *.files 2>/dev/null
	echo "done!"
}

# main
retrieve ${SRC}-${VER}.${COMP}
extract ${SRC}-${VER}.${COMP}
patch
build
package	
