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

CFLAGS="-mtune=generic -Os -pipe"
CXX="g++ -flto -fuse-linker-plugin -mtune=generic -Os -pipe -fno-exceptions -fno-rtti"

P=hwdata
V=0.369
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://github.com/vcrhonek/$P/archive/refs/tags/v$V.zip"  $USER
unzip v$V.zip
cd $SRC
./configure --prefix=/usr/local --datadir=/usr/local/lib --disable-blacklist
# not stripped at make stage
make install DESTDIR=/tmp/$P
cd /tmp

# dev
#####
mkdir -p $P-dev/usr/local/lib
mv $P/usr/local/lib/pkgconfig $P-dev/usr/local/lib
# below is not defined in pc file
sed 's|${pc_sysrootdir}||' -i $P-dev/usr/local/lib/pkgconfig/$P.pc

# main 
######
mkdir -p $P/usr/local/share/doc/$P
echo 'GPL v2' > $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 usr -not -type d > /tmp/$Z.tcz.list
        sed 's|usr|/usr|g' -i /tmp/$Z.tcz.list
	cd /tmp
done

ls -hal

echo 'Title:          hwdata-dev.tcz
Description:    dev files
Version:        0.369
Author:         Vitezslav Crhonek  
Original-site:  https://github.com/vcrhonek/hwdata
Copying-policy: GPL v2
Size:           4.0K          		
Extension_by:   aus9
Tags:           pci pnp iab oui usb hardware
Comments:       development file
            
Change-log:     2023/04/21 v 0.369 
Current:        2023/04/21  ' > $P-dev.tcz.info

echo 'hwdata.tcz' > $P-dev.tcz.dep

echo 'Title:          hwdata.tcz
Description:    pci,pnp & usb ids
Version:        0.369
Author:         Vitezslav Crhonek  
Original-site:  https://github.com/vcrhonek/hwdata
Copying-policy: GPL v2
Size:           3.0M          		
Extension_by:   aus9
Tags:           pci pnp iab oui usb hardware
Comments:       pci.ids pnp.ids & usb.ids
                Also has iab data which I believe is
                Integrated Access and Backhaul

                Also has oui data which I believe is
                for public mac addresses
            
Change-log:     2023/04/21 v 0.369 
Current:        2023/04/21  ' > $P.tcz.info

# no dep its data only

submitqc --libs
