### this file is sourced not run
PKGVER=800.0
PKGBUILD=1
PKGARCH=x86_64

###
TARBALL=busybox-2017.03.tar.bz2
MD5SUM=36de4b4a8458aa2ed06e79a235ed974d
#SRC_URL=http://busybox.net/downloads/$TARBALL
SRC_URL=http://distro.ibiblio.org/fatdog/source/800/$TARBALL

SLACKREQ=  # build-time only:  musl and musl-libc-headers
SLACKDESC="fatdog-bins: fatdog-bins $PKGVER (Fatdog misc binaries)  
fatdog-bins:  
fatdog-bins: These are Fatdog-specific binaries used by many Fatdog scripts. 
fatdog-bins: Contains: systz, show-ucs-data, autologin. 
fatdog-bins: Obsolete utils: cddetect_quick, ipmon
fatdog-bins: 
fatdog-bins: Specialised busybox versions for optimised running:
fatdog-bins: - init, inotifyd, logger, getty, crond, login, sleep
fatdog-bins: (init, sleep and inotifyd are static, the rest is shared).
fatdog-bins: 
fatdog-bins:  
"

STANDALONE_APPLETS="cron logger getty login inotifyd sleep" 
STANDALONE_APPLETS_STATIC="inotifyd sleep init"
SU_APPLETS="cron login"
# init is special, see note below

### default pkg_download
### default pkg_prepare

### build
pkg_build() {
	cd /tmp/pkg
	
	# build our own binaries first
	gcc -o systz fix-sys_tz.c &&
	gcc -o cddetect_quick cddetect_quick.c &&
	gcc -o ipmon ipmon2.c &&
	gcc -o show-ucs-data show-ucs-data.c &&
	gcc -o autologin autologin.c &&
	
	# install them
	install -m755 systz /sbin &&
	install -m755 cddetect_quick /sbin &&
	ln -s cddetect_quick /sbin/cddetect &&
	install -m755 ipmon /usr/bin &&
	install -m755 show-ucs-data /usr/bin &&
	install -m755 autologin /bin &&

	# now build busybox binaries
	cd /tmp/busybox* &&	
	for applet in $STANDALONE_APPLETS; do
		cp /tmp/pkg/bb-configs/bb-config-${applet}* .config &&
		make oldconfig && make &&
		install -m755 busybox /bin/busybox-$applet &&
		case $SU_APPLETS in
			*$applet*) chmod +s /bin/busybox-$applet
		esac
		make clean distclean || return 1
	done &&

	# build static busybox binaries if possible
	if type musl-gcc > /dev/null && [ -d /usr/musl/kernel/include ]; then
		for applet in $STANDALONE_APPLETS_STATIC; do
			cp /tmp/pkg/bb-configs/bb-config-${applet}* .config &&
			echo "CONFIG_STATIC=y" >> .config &&
			sed -i -e 's|--as-needed|--as-needed -I/usr/musl/kernel/include|' .config &&
			make oldconfig && make CC=musl-gcc &&
			install -m755 busybox /bin/busybox-$applet &&
			case $SU_APPLETS in
				*$applet*) chmod +s /bin/busybox-$applet
			esac
			make clean distclean || return 1
		done &&
		echo "Using NEW init" &&
		echo "Using STATIC $STANDALONE_APPLETS_STATIC"		
	else
		# if can't build static init, use our old init
		cp /tmp/pkg/busybox-init /bin && echo "Using OLD init" &&
		echo "Using SHARED $STANDALONE_APPLETS_STATIC"
	fi &&

	# our install script, too long to be included in the recipe
	mkdir -p /install &&
	install -m644 /tmp/pkg/doinst.sh /install &&
	
	pkg_build_slackdesc
}

