### this file is sourced not run
PKGVER=1.27.0.git.2017.03
PKGBUILD=1
PKGARCH=x86_64

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

SLACKREQ=
SLACKDESC="busybox: busybox $PKGVER (All-in-one utilities)  
busybox:  
busybox: BusyBox combines tiny versions of many common UNIX utilities into a 
busybox: single small executable. It provides replacements for most of the 
busybox: utilities you usually find in GNU fileutils, shellutils, etc. The 
busybox: utilities in BusyBox generally have fewer options than their 
busybox: full-featured GNU cousins; however, the options that are included 
busybox: provide the expected functionality and behave very much like their 
busybox: GNU counterparts. BusyBox provides a fairly complete environment for 
busybox: any small or embedded system.  
busybox:
"

STATIC= # yes 
CROSS_COMPILER_PATH=/opt/abo64/bin
CROSS_COMPILE=x86_64-

### default pkg_download
### prepare
pkg_prepare() {
	pkg_prepare_default &&
	
	# patches and default config
	cd tmp/busybox* &&
	patch -Np1 -i ../pkg/busybox-1.22-20130821-guess_fstype-applet.patch &&
	patch -Np1 -i ../pkg/fatdog-ntpd-script.patch &&
	
	# undo a series of dowait-related patches which breaks fatdog-control-panel
	patch -Rp1 -i ../pkg/upstream-use-sigsuspend.patch &&
	patch -Rp1 -i ../pkg/upstream-use-pause-in-wait.patch &&
	patch -Rp1 -i ../pkg/upstream-dowait-signal-race.patch &&

	# upstream patches fixing stuff (inetd, unshare)
	for p in 1b51090 2fee2bc b5a0d9d; do
		patch -Np1 -i ../pkg/commit-$p || return 1
	done &&

	# upstream fixes for ntpd - make it more reliable
	patch -Np1 -i ../pkg/upstream-ntpd-dns-fix.patch &&	
	patch -Np1 -i ../pkg/upstream-ntpd-dns-fix2.patch &&
	patch -Np1 -i ../pkg/upstream-ntpd-dns-fix3.patch &&
	patch -Np1 -i ../pkg/upstream-ntpd-fix-11mins.patch &&

	true	
}

### default pkg_package
### build
pkg_build() {
	cd /tmp/busybox*
	if [ $STATIC ]; then
		cp ../pkg/bb-config-initrd-1.27.0.git.2017.03 .config
		[ -d $CROSS_COMPILER_PATH ] || { echo "Cannot find cross compiler"; return 1; }
		PATH=$PATH:$CROSS_COMPILER_PATH
		MAKEFLAGS="$MAKEFLAGS CROSS_COMPILE=$CROSS_COMPILE"
	else
		cp ../pkg/bb-config-fatdog-1.27.0.git.2017.03 .config
	fi
	
	make oldconfig && # make defconfig
	make $MAKEFLAGS &&
	
	# install binary and udhcpc script; note: NO SYMLINK CREATED
	cp busybox /bin &&
	cp docs/busybox.1 /usr/share/man/man1 &&
	cp docs/BusyBox.txt /usr/share/doc &&
	mkdir -pv /usr/share/udhcpc /usr/share/bbscript &&
	install -m755 examples/udhcp/simple.script /usr/share/udhcpc/default.script &&
	install -m755 examples/zcip.script examples/var_service/ntpd/ntp.script /usr/share/bbscript &&
	
	# samples
	cp -v examples/udhcp/udhcpd.conf /etc &&
	cp -v examples/inetd.conf /etc &&
	cp -v examples/dnsd.conf /etc &&
	cp -v examples/mdev_fat.conf /etc &&
	cp -v examples/mdev.conf.change_blockdev.sh	/etc &&
	sed -n '/\* httpd.conf/,/\/\*/ p' networking/httpd.c  > /etc/bb-httpd.conf &&
	#sh &&
	
	# applet list for further symlinking during SFS building later
	./busybox --list-full > /bin/busybox-applet-list &&
	pkg_build_slackdesc
}
 

