# Recipe created by recipetool
# recipetool create -o pup-tools_20201010.bb http://distro.ibiblio.org/easyos/source/alphabetical/p/pup-tools-20201010.tar.gz

# 20180417 proxy-setup.bac removed (it is now a shell script).
# 20180729 forgot to compile 'getlocalip'.
# 20181024 vovchik fixed 'pngoverlay', now does not have to be in same folder as the input images.
# 20181216 ...above was not fixed, now is (source v0.1c).
# 20190215 pup_event_frontend_d now detects network changes.
# 20190405 20190215 broken, pup_event_frontend_d rewritten in C.
# 20200919 now have bacon 4.1
# 20200921 now have bacon.sh in files folder. bug fix, ref:
#   https://basic-converter.proboards.com/thread/1183/compile-fail-openembedded-dunfell
# 20201010 ref: https://basic-converter.proboards.com/thread/1188/pngoverlay-bac-compile-fail-bacon

#PR = "r0"
# 20210121 PR_NUM is defined in local.conf...
#PR = "r${@int(PR_NUM) + 1}"

#20200921 now have bacon in files folder...
#DEPENDS = "bacon bacon-hug bacon-hug-imports gtk+ m4-native"
DEPENDS = "gtk+ m4-native"
#DEPENDS = "gtk+ m4-native mesa glib-2.0 glib-2.0-native"

inherit gettext pkgconfig

LICENSE = "GPLv2"
LIC_FILES_CHKSUM = "file://readme.txt;md5=9add27eb01e81e0a682a99520030f7ce"

SRC_URI = "http://distro.ibiblio.org/easyos/source/alphabetical/p/pup-tools-${PV}.tar.gz \
  file://bacon.shV4.1.1 \
  file://hug.bacV0.109"
SRC_URI[md5sum] = "c954fbf93d24ee112b067501013e2c13"
SRC_URI[sha1sum] = "20086333340240f5366ca12436d885c95a428ef5"
SRC_URI[sha256sum] = "dc05d40d7f36e917a2ebc70b458e5c1adb9b318b9a576290d6a61c0367cafa3c"
SRC_URI[sha384sum] = "573399b0c344aa9c2684d1e1df1479351ddb67d9e39d693c637ea25789704c88eefc2003d6c43c817982f20c84a33777"
SRC_URI[sha512sum] = "a8e6ccd1f56482d4d8d0431af79fc3e5536506e18412c3b4a681f2e9d40202a14540820081b152a53310a62c68120544308ae2e4e4b457f5fb43d4bd9d526502"

do_configure() {
    #previously, the bacon-hug recipe would have left these (and bacon recipe left bacon.sh in $TMPDIR):
    #cp -f ${DL_DIR}/hug_imports.bac ${S}/bacon/
    #cp -f ${DL_DIR}/hug.bac ${S}/bacon/
    #however, now have bacon in files folder. OE do_unpack() copies those to $WORKDIR:
    cp -f ${WORKDIR}/hug.bacV0.109 ${S}/bacon/hug.bac
    cp -a -f ${WORKDIR}/bacon.shV4.1.1 ${S}/bacon/bacon.sh
    #...actually, i think could have had "${S}/../" instead of $WORKDIR
    
    #180417 this line was correct for bacon 3.0.2, now needs "<poll.h>" ...
    #190213 this fix is no longer required...
    #sed -i -e 's%^PRAGMA INCLUDE poll.h%PRAGMA INCLUDE <poll.h>%' ${S}/bacon/pup_event_frontend_d.bac
    #20201010 ditto...
    #sed -i -e 's%^PRAGMA INCLUDE sys/inotify.h%PRAGMA INCLUDE <sys/inotify.h>%' ${S}/bacon/pup_event_ipc.bac
    #sed -i -e 's%^PRAGMA INCLUDE poll.h%PRAGMA INCLUDE <poll.h>%' ${S}/bacon/pup_event_ipc.bac
}

do_compile () {
	# note, 'pwd' reported:
	# /mnt/sdb1/oe/oe-quirky/buildPC/tmp-glibc/work/core2-64-oe-linux/pup-tools/20170607-r0/pup-tools-20170607
	cd bacon
	#[ -d temp1 ] && rm -rf temp1
	mkdir -p temp1
	
	#171102 change inbuilt hug.bac instead of hug_imports.bac & hug.so...
	sed -i -e 's%^REM INCLUDE "/usr/share/BaCon/hug.bac"%INCLUDE "/usr/share/BaCon/hug.bac"%' welcome1stboot.bac
	sed -i -e 's%^INCLUDE "/usr/share/BaCon/hug_imports.bac"%REM INCLUDE "/usr/share/BaCon/hug_imports.bac"%' welcome1stboot.bac
	sed -i -e 's%/usr/share/BaCon%.%' welcome1stboot.bac #hug.bac is local.
    # -n convert to C only, -a rebuild libbacon.a, -p preserve temporary files,
    # -y automatically delete temporary files, -x extract gettext strings...
	#${TMPDIR}/bacon.sh -y -x -n -p -d temp1 welcome1stboot.bac
	./bacon.sh -y -x -n -p -d temp1 welcome1stboot.bac
	cd temp1
	${CC} -fPIC -c welcome1stboot.bac.c ${CFLAGS}
	${CC} -o welcome1stboot welcome1stboot.bac.o -L. -lm  -ldl ${LDFLAGS}
	cd ..
	
	#${TMPDIR}/bacon.sh -y -n -p -d temp1 debdb2pupdb.bac
	./bacon.sh -y -n -p -d temp1 debdb2pupdb.bac
	cd temp1
	${CC} -fPIC -c debdb2pupdb.bac.c ${CFLAGS}
	${CC} -o debdb2pupdb debdb2pupdb.bac.o -L. -lm  -ldl ${LDFLAGS}
	cd ..
	
	#${TMPDIR}/bacon.sh -y -n -p -d temp1 find_cat.bac
	./bacon.sh -y -n -p -d temp1 find_cat.bac
	cd temp1
	${CC} -fPIC -c find_cat.bac.c ${CFLAGS}
	${CC} -o find_cat find_cat.bac.o -L. -lm  -ldl ${LDFLAGS}
	cd ..
	
	#${TMPDIR}/bacon.sh -y -n -p -d temp1 pngoverlay.bac
	./bacon.sh -y -n -p -d temp1 pngoverlay.bac
	cd temp1
	${CC} -fPIC -c pngoverlay.bac.c ${CFLAGS}
	${CC} -o pngoverlay pngoverlay.bac.o -L. -lm  -ldl ${LDFLAGS}
	cd ..
	
	sed -i -e 's%/usr/share/BaCon%.%' popup.bac #hug.bac is local.
	#${TMPDIR}/bacon.sh -y -n -p -d temp1 popup.bac
	./bacon.sh -y -n -p -d temp1 popup.bac
	cd temp1
	${CC} -fPIC -c popup.bac.c ${CFLAGS}
	${CC} -o popup popup.bac.o -L. -lm  -ldl ${LDFLAGS}
	cd ..
	
	#180417 removed...
	##171102 fails at startup, try with inbuilt hug.bac instead of hug.so...
	##oh, found needs "ENTRY" inserted...
	#sed -i -e 's%^REM INCLUDE "/usr/share/BaCon/hug.bac"%INCLUDE "/usr/share/BaCon/hug.bac",ENTRY%' proxy-setup.bac
	#sed -i -e 's%^INCLUDE "/usr/share/BaCon/hug_imports.bac"%REM INCLUDE "/usr/share/BaCon/hug_imports.bac"%' proxy-setup.bac
	#sed -i -e 's%/usr/share/BaCon%.%' proxy-setup.bac #hug_imports.bac, hug.bac are local.
	#${TMPDIR}/bacon.sh -x -y -n -p -d temp1 proxy-setup.bac
	#cd temp1
	#${CC} -fPIC -c proxy-setup.bac.c ${CFLAGS}
	#${CC} -o proxy-setup proxy-setup.bac.o -L. -lm  -ldl ${LDFLAGS}
	#cd ..
	
	#20190405 this has been rewritten in C...
	#${TMPDIR}/bacon.sh -y -n -p -d temp1 pup_event_frontend_d.bac
	#cd temp1
	#${CC} -fPIC -c pup_event_frontend_d.bac.c ${CFLAGS}
	#${CC} -o pup_event_frontend_d pup_event_frontend_d.bac.o -L. -lm  -ldl ${LDFLAGS}
	#cd ..
	
	sed -i -e "s%'CONST IN_MODIFY=2%CONST IN_MODIFY=2%" pup_event_ipc.bac #170608
	#${TMPDIR}/bacon.sh -y -n -p -d temp1 pup_event_ipc.bac
	./bacon.sh -y -n -p -d temp1 pup_event_ipc.bac
	cd temp1
	${CC} -fPIC -c pup_event_ipc.bac.c ${CFLAGS}
	${CC} -o pup_event_ipc pup_event_ipc.bac.o -L. -lm  -ldl ${LDFLAGS}
	cd ..
    cd ..
    
	#20190405 now have pup_event_frontend_d.c ...
	#20200212 now have bitflip.c ...
	cd gcc
	for aFILE in bitflip printcols truncate vercmp getlocalip pup_event_frontend_d
	do
	 ${CC} -o ${aFILE} ${aFILE}.c ${CFLAGS} ${LDFLAGS}
	done
	${CC} -lX11 getcurpos.c -o getcurpos ${CFLAGS} ${LDFLAGS}
	cd ..
}

do_install () {
    install -d ${D}/bin
    install -m755 gcc/vercmp ${D}/bin
    install -d ${D}/usr/bin
    install -m755 gcc/truncate ${D}/usr/bin
    install -d ${D}/usr/sbin
    install -m755 gcc/bitflip ${D}/usr/sbin
    install -m755 gcc/getcurpos ${D}/usr/sbin
    install -m755 gcc/printcols ${D}/usr/sbin
    install -m755 gcc/getlocalip ${D}/usr/sbin
    install -m755 bacon/temp1/pngoverlay ${D}/usr/sbin
    install -m755 bacon/temp1/popup ${D}/usr/sbin
    install -m755 bacon/temp1/welcome1stboot ${D}/usr/sbin
    install -d ${D}/usr/local/petget
    install -m755 bacon/temp1/debdb2pupdb ${D}/usr/local/petget
    install -m755 bacon/temp1/find_cat ${D}/usr/local/petget
    install -d ${D}/usr/local/pup_event
    install -m755 gcc/pup_event_frontend_d ${D}/usr/local/pup_event
    install -m755 bacon/temp1/pup_event_ipc ${D}/usr/local/pup_event
    install -d ${D}/usr/local/simple_network_setup
    #install -m755 bacon/temp1/proxy-setup ${D}/usr/local/simple_network_setup
}

FILES_${PN} += "/usr/local/petget /usr/local/pup_event"

HOMEPAGE = "http://distro.ibiblio.org/easyos/project/woof"
SUMMARY = "Core utilities used in Puppy and derivatives."
