#!/bin/sh
#

EXT=iftop
TCZ=/tmp/$EXT/TCZ

sudo rm -rf /tmp/$EXT

DEPS="perl5 libpcap-dev ncurses-dev"

NOTFOUND=""
for a in compiletc bash file squashfs-tools $DEPS
         do tce-load -i $a || tce-load -iwl $a || NOTFOUND=x
done
test -z "$NOTFOUND" || exit

#make clean

grep -q 'curseslib -ltinfo' configure || sed -i -e '/-l\$curseslib"/s/-l\$curseslib/-l$curseslib -ltinfo/' configure

./configure \
	--prefix=/usr/local \
	--sysconfdir=/usr/local/etc \
	--localstatedir=/var \
	|| exit

make || exit

make install DESTDIR=$TCZ
for a in $(find $TCZ -type f); do file -b $a | grep -q '^ELF .*not stripped$' && strip --strip-unneeded $a; done

sudo chown -R root.root $TCZ*

mksquashfs $TCZ/ /tmp/$EXT/$EXT.tcz -noappend
