#!/bin/bash
# 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=scdoc
V=1.9.4
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://git.sr.ht/~sircmpwn/$P/archive/$V.tar.gz " $USER
tar xvf $V*gz
cd $SRC
make PREFIX=/usr/local
make PREFIX=/usr/local install
cd /tmp

# dev
#####
mkdir -p $P-dev/usr/local/lib/pkgconfig 
mv /usr/local/lib/pkgconfig/$P.pc $P-dev/usr/local/lib/pkgconfig 

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

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

mkdir -p $P/usr/local/bin
mv /usr/local/bin/$P $P/usr/local/bin
strip --strip-unneeded $P/usr/local/bin/$P
###########################################################
echo 'scdoc.tcz' > $P-dev.tcz.dep
echo 'man-db.tcz' > $P-doc.tcz.dep

# TCZ them
#######
LIST="$P $P-doc $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
done

ls -hal

echo 'Title:          scdoc.tcz 
Description:    small man page generator 
Version:        1.9.4
Author:         Drew DeVault
Original-site:  https://git.sr.ht/%7Esircmpwn/scdoc/
Copying-policy: Accompanied 
Size:	            320K
Extension_by:   aus9 at gmx dot com
Tags:           man-db man sway
Comments:       Simple man page generator 
                Written in C99, Input files must use the UTF-8 encoding

                Used to build sway.

                Compiled for 10x 
Change-log:     2018/07/24 first version  v1.4.1 
                2019/04/04 -> v 1.9.4 on 10x 
Current:        2019/04/25 add dev pkg' > $P.tcz.info

echo 'Title:          scdoc-doc.tcz 
Description:    man page  
Version:        1.9.4
Author:         Drew DeVault
Original-site:  https://git.sr.ht/%7Esircmpwn/scdoc/
Copying-policy: Accompanied 
Size:           4.0K
Extension_by:   aus9 at gmx dot com
Tags:           man-db man sway
Comments:       man page for scdoc 

                Compiled for 10x 
Change-log:     2018/07/24 first version  v1.4.1 
                2019/04/04 -> v 1.9.4 on 10x 
Current:        2019/04/25 add dev pkg' > $P-doc.tcz.info

echo 'Title:          scdoc-dev.tcz 
Description:    dev for scdoc  
Version:        1.9.4
Author:         Drew DeVault
Original-site:  https://git.sr.ht/%7Esircmpwn/scdoc/
Copying-policy: Accompanied 
Size:           4.0K
Extension_by:   aus9 at gmx dot com
Tags:           man-db man sway
Comments:       pc file only calls the exe 

                Compiled for 10x 
Change-log:     2019/04/25 first version  v 1.9.4
Current:        2019/04/25  ' > $P-dev.tcz.info

submitqc --libs
