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

# dep of gphoto2

export CFLAGS="-march=armv8-a+crc -mtune=cortex-a72 -Os -pipe" 
export CXXFLAGS="-march=armv8-a+crc -mtune=cortex-a72 -Os -pipe \
-fno-exceptions -fno-rtti"

P=popt
V=1.18
SRC=$P-$V
USER=`cat /etc/sysconfig/tcuser`

LIST="compiletc squashfs-tools wget zsync  "
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 \
http://ftp.rpm.org/$P/releases/$P-1.x/$SRC.tar.gz"  $USER
mkdir $P
tar xvf $SRC*gz
cd $SRC
./configure --prefix=/usr/local --disable-static --disable-nls 
make -j5 # takes 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/
mv $P/usr/local/lib/*a $P-dev/usr/local/lib/
chmod 644 $P-dev/usr/local/lib/*a 

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

# TCZ them
###########
LIST="$P $P-dev "
for Z in $LIST
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
        zsyncmake $Z.tcz
done

ls -hal

echo 'Title:          popt-dev.tcz
Description:    dev files
Version:        1.18
Author:         https://github.com/rpm-software-management/popt/graphs/contributors
Original-site:  https://github.com/rpm-software-management/popt
Copying-policy: accompanied
Size:           8K
Extension_by:   aus9
Tags:           parser
Comments:       dev files

Change-log:     2020/11/04 Original v 1.18 on 12x
Current:        2020/11/04 ' > $P-dev.tcz.info
     
echo 'Title:          popt.tcz
Description:    commandline option parser 
Version:        1.18
Author:         https://github.com/rpm-software-management/popt/graphs/contributors
Original-site:  https://github.com/rpm-software-management/popt
Copying-policy: accompanied
Size:           24K
Extension_by:   aus9
Tags:           parser
Comments:       Its similar to getopt
             
Change-log:     2020/11/04 Original v 1.18 on 12x
Current:        2020/11/04 ' > $P.tcz.info 

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

