#!/bin/sh
#

EXT=libnet
TCZ=/tmp/$EXT/TCZ

sudo rm -rf /tmp/$EXT

DEPS=""

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

export CC="gcc -mtune=generic -Os -pipe"
export CXX="g++ -mtune=generic -Os -pipe -fno-exceptions -fno-rtti"

./configure \
	|| exit

sed -i -e '/^SUBDIRS/s/doc//' Makefile
make || exit

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

mkdir -p $TCZ/usr/local/lib
mv $TCZ-dev/usr/local/lib/*.so* $TCZ/usr/local/lib

sudo chown -R root.root $TCZ*

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

