#!/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.4.1
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/scdoc/snapshot/$SRC.tar.xz " $USER
xz -d $SRC*xz && tar xvf $SRC*tar
cd $SRC
make PREFIX=/usr/local
make PREFIX=/usr/local install
cd /tmp

# 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 'man-db.tcz' > $P-doc.tcz.dep

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


echo 'Title:          scdoc.tcz 
Description:    small man page generator 
Version:        1.4.1
Author:         Drew DeVault
Original-site:  https://git.sr.ht/%7Esircmpwn/scdoc/
Copying-policy: Accompanied 
Size:		
Extension_by:   aus9 at gmx dot com
Tags:           man-db man 
Comments:       Simple man page generator 
                written in C99

                Input files must use the UTF-8 encoding

                Compiled for 9x 
Change-log:     2018/07/24 first version 
Current:        2018/07/24  ' > $P.tcz.info

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

                Compiled for 9x 
Change-log:     2018/07/24 first version 
Current:        2018/07/24  ' > $P-doc.tcz.info

submitqc --libs
