#!/bin/sh
# test we are root
if [ "$(id -u)" != "0" ]; then
   exit 1
fi

export CFLAGS="-mtune=generic -Os -pipe"
export CXXFLAGS="-mtune=generic -Os -pipe -fno-exceptions -fno-rtti "

P=libnfnetlink
V=1.0.2
SRC=$P-$V
USER=`cat /etc/sysconfig/tcuser`
LIST="compiletc submitqc    "
for Z in $LIST
    do 
    su -c "tce-load -i $Z" $USER
done

cd /tmp
su -c "/usr/local/bin/wget -nc --no-check-certificate \
https://www.netfilter.org/projects/$P/files/$SRC.tar.bz2  "  $USER
tar jxvf $SRC*bz2
cd $SRC
./configure --prefix=/usr/local 
find . -name Makefile -type f -exec sed -i 's/-O2//g' {} \;
make -j4 # seconds
make install-strip DESTDIR=/tmp/$P
cd /tmp

# dev
##### 
mkdir -p $P-dev/usr/local/lib/
mv $P/usr/local/include $P-dev/usr/local/
mv $P/usr/local/lib/pkgconfig $P-dev/usr/local/lib/
rm -rf  $P/usr/local/lib/*.la 

# main
#####
mkdir -p $P/usr/local/share/doc/$P
echo 'GPL v 2' > $P/usr/local/share/doc/$P/COPYING

# TCZ them
###########
LIST2="$P $P-dev "
for Z in $LIST2
do
	mksquashfs $Z $Z.tcz
	md5sum $Z.tcz > $Z.tcz.md5.txt
	cd $Z
	find . -not -type d | cut -c 2- | sort > /tmp/$Z.tcz.list
	cd /tmp
done

ls -hal

echo 'Title:          libnfnetlink-dev.tcz
Description:    dev files
Version:        1.0.2
Author:         Netfilter Team & Pablo Neira Ayuso
Original-site:  https://www.netfilter.org/projects/libnfnetlink
Copying-policy: GPL v 2 
Size:           8.0K 
Extension_by:   aus9 @linuxquestions.org
Tags:           firewall
Comments:       development
                
Change-log:     2024/11/16 v 1.0.2
Current:        2024/11/16' > $P-dev.tcz.info  
echo 'libnfnetlink.tcz' > $P-dev.tcz.dep

echo 'Title:          libnfnetlink.tcz
Description:    lib for netfilter related kernel/userspace communication
Version:        1.0.2
Author:         Netfilter Team & Pablo Neira Ayuso
Original-site:  https://www.netfilter.org/projects/libnfnetlink
Copying-policy: GPL v 2 
Size:           12K 
Extension_by:   aus9 @linuxquestions.org
Tags:           firewall
Comments:       It is used as a foundation for other, netfilter
                subsystem specific libraries such as libnfnetlink_conntrack, 
                libnfnetlink_log and libnfnetlink_queue.
                
Change-log:     2024/11/16 v 1.0.2
Current:        2024/11/16' > $P.tcz.info      

readelf -d $P/usr/local/lib/*.so | grep 'NEEDED' # TCB only

submitqc --libs
rm -rf *.zsync

