#!/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 "

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

cd /tmp
/usr/local/bin/wget -nc --no-check-certificate \
https://github.com/$P/pkgconf/archive/refs/tags/$P-$V.tar.gz
tar xvf $SRC*gz
cd $SRC
meson setup --prefix=/usr/local -Dstrip=true -Ddebug=false -Dtests=disabled build
# debug : false
# prefix: /usr/local
# strip : true
# tests : disabled
ninja -C build # seconds
cd build
DESTDIR=/tmp/$P ninja install
cd /tmp

# dev
#####
mkdir -p $P-dev/usr/local/lib $P-dev/usr/local/share
mv $P/usr/local/include $P-dev/usr/local/
mv $P/usr/local/lib/pkgconfig $P-dev/usr/local/lib
mv $P/usr/local/share/aclocal $P-dev/usr/local/share

# doc
######
mkdir -p $P-doc/usr/local/share
mv $P/usr/local/share/man $P-doc/usr/local/share/

# main
###### quick clean up
rm -rf $P/usr/local/share/doc/$P
mkdir -p $P/usr/local/share/doc/$P
cp $SRC/COPYING $P/usr/local/share/doc/$P/

# TCZ them
#######
LIST="$P $P-dev $P-doc"
for Z in $LIST
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:          pkgconf-dev.tcz
Description:    dev files
Version:        2.5.1
Author:         https://github.com/pkgconf/pkgconf/blob/master/AUTHORS
Original-site:  https://github.com/pkgconf/pkgconf
Copying-policy: accompanied
Size:           16K
Extension_by:   aus9 @linuxquestions.org
Tags:           compile
Comments:       development
                
Change-log:     2025/11/22
Current:        2025/11/22 '  > $P-dev.tcz.info
echo 'pkgconf.tcz' > $P-dev.tcz.dep

echo 'Title:          pkgconf-doc.tcz
Description:    man pages
Version:        2.5.1
Author:         https://github.com/pkgconf/pkgconf/blob/master/AUTHORS
Original-site:  https://github.com/pkgconf/pkgconf
Copying-policy: accompanied
Size:           16K
Extension_by:   aus9 @linuxquestions.org
Tags:           compile
Comments:       -
                
Change-log:     2025/11/22
Current:        2025/11/22 '  > $P-doc.tcz.info
echo 'man-db.tcz' > $P-doc.tcz.dep

echo 'Title:          pkgconf.tcz
Description:    package compiler and linker metadata toolkit 
Version:        2.5.1
Author:         https://github.com/pkgconf/pkgconf/blob/master/AUTHORS
Original-site:  https://github.com/pkgconf/pkgconf
Copying-policy: accompanied
Size:           56K
Extension_by:   aus9 @linuxquestions.org
Tags:           compile
Comments:        It is a superset of the functionality provided by 
                 pkg-config from freedesktop.org, but does not provide 
                 bug-compatibility with it
                
Change-log:     2025/11/22
Current:        2025/11/22 '  > $P.tcz.info
readelf -d $P/usr/local/bin/* | grep 'NEEDED'
# [libpkgconf.so.7] this TCE
readelf -d $P/usr/local/lib/*.so | grep 'NEEDED' # rootfs
# no dep

submitqc --libs
rm -rf *.zsync

# submitqc changes /usr/local/share/aclocal/pkg.m4 to 755...ignore

