# util-linux
# Builds from https://github.com/puppylinux-woof-CE/petbuilds
# File auto generated by ./mk_petbuild.sh. Edit as necessary.

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

URL=https://www.kernel.org/pub/linux/utils/util-linux/v2.21
PKG=util-linux
VER=2.21.2
COMP=tar.xz
DESC="utilities for linux"
DEPS=
CAT=BuildingBlock
DESKTOP=util-linux.desktop
BUILD=
CWD=$(pwd)
[ -z "$MWD" ] && MWD=$(dirname $CWD)
[ -z "$BUILD" ] && BUILD=$DEF_BUILD
# comment these 2 below if you use a custom package() function
[ -f "$DESKTOP" ] || DESKTOP=not
[ -z "$DEPS" ] && DEPS=not

ARCH=$(uname -m)
case $ARCH in # set in build.conf
 *64) 	LIBDIR=$LIBCONF64 ;;
 arm*)	LIBDIR=$LIBCONFarm;;
 *) 	LIBDIR=$LIBCONF32 ;;
esac

patch_me() {
	cd ${PKG}-${VER}
	echo '' > libblkid/src/f2fs.c
	for i in ../*patch;do
		echo "applyin $i"
		patch -Np1 --verbose < $i
	done
	cd -
}

build() {
	cd ${PKG}-${VER}
	./configure --prefix=/usr \
				--localstatedir=/var \
				--sysconfdir=/etc \
				--libdir=/usr/${LIBDIR} \
				--enable-f2fs
	[ "$?" -eq 0 ] || exit
	make $MKFLG
	[ "$?" -eq 0 ] || exit
	make DESTDIR=$CWD/${PKG}-install install
	cd -
}

package() {
	# add this recipe
	install -d -m 0755 ./${PKG}-install/usr/src/dev
	cat ${PKG}.petbuild > ./${PKG}-install/usr/src/dev/${PKG}-build-recipe
	# SPECIAL - mv mount and umount
	echo "fixing mount, umount"
	(cd ./${PKG}-install/bin;mv mount mount-FULL;mv umount umount-FULL)
	echo "fixing losetup"
	(cd ./${PKG}-install/sbin;mv losetup losetup-FULL)
	sleep 2
	# split
	get_files ${PKG}-install ${PKG}-${VER}-${ARCH}_${BUILD}
	(cd ${PKG}-${VER}; $MWD/split.sh ../${PKG}-install $BUILD)
	if [ -f "$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}_${BUILD}"|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}-${VER}.${COMP}
extract ${PKG}-${VER}.${COMP}
patch_me
build_configure $PKG $VER $LIBDIR
package
