#!/bin/sh
#

EXT=libnghttp2
TCZ=/tmp/$EXT/TCZ

sudo rm -rf /tmp/$EXT

# load the following .tcz's to build the full package
#		jemalloc-dev libxml2-dev openssl-dev libevent-dev

for a in compiletc bash squashfs-tools 
	do tce-load -i $a
done

make clean
./configure \
	--enable-lib-only \
	|| exit

make || exit

if [ $(grep -q '^install-strip:' Makefile) ]; then
	make install-strip DESTDIR=$TCZ-dev
else
	make install DESTDIR=$TCZ-dev
	for a in $(find $TCZ-dev -type f); do file -b $a | grep -q '^ELF .*not stripped$' && strip $a; done
fi

mkdir -p $TCZ/usr/local/share
mkdir -p $TCZ/usr/local/lib
mv $TCZ-dev/usr/local/share/nghttp2 $TCZ/usr/local/share
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

