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

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

URL=http://busybox.net/downloads/
PKG=busybox
VER=1.24.2
COMP=tar.bz2
DESC="BusyBox - The Swiss Army Knife of Embedded Linux"
DEPS=
CAT=BuildingBlock

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

build() {
	cd ${PKG}-${VER}
	cp -a ../DOTconfig .
	mv DOTconfig .config
	make oldconfig
	make $MKFLG
	[ "$?" -eq 0 ] || exit 1
	make install
	mv _install ../$PKG-$VER-$ARCH
	cd -
}
	
package() {
	echo "wait..."
	# 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
	cp -af ${PKG}-${VER}/.config DOTconfig
	install -m 0644 DOTconfig ./$PKG-$VER-$ARCH/usr/share/doc
	if [ "$DESKTOP" ];then
		install -d -m 0755 ./$PKG-$VER-$ARCH/usr/share/applications
		cat $DESKTOP > ./$PKG-$VER-$ARCH/usr/share/applications/$DESKTOP
	fi
	[ -f ./pinstall.sh ] && install -m 0755 pinstall.sh ./$PKG-$VER-$ARCH/
	[ -f ./puninstall.sh ] && install -m 0755 puninstall.sh ./$PKG-$VER-$ARCH/
	find ./$PKG-$VER-$ARCH -type f -name '*cache' -delete
	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}-${VER}
	rm *.files 2>/dev/null
	echo "done!"
}

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