#!/bin/sh
# test we are root
if [ "$USER" != "root" ] ; then
   echo "Run as root please, exiting." 
   exit 1                                                      
fi

CFLAGS="-march=i486 -mtune=i686 -Os -pipe   " 
CXXFLAGS="-march=i486 -mtune=i686 -Os -pipe -fno-exceptions -fno-rtti  "
echo $CFLAGS && echo $CXXFLAGS

P=man-db
V=2.11.2
SRC=$P-$V
USER=`cat /etc/sysconfig/tcuser`
LIST="compiletc squashfs-tools wget libtool intltool \
libpipeline-dev gdbm-dev groff db-dev "
for Z in $LIST 
    do 
    su -c "tce-load -i $Z" $USER
done

# list may be larger than loaded
cd /usr/local/lib
rm -rf *.la
rm -rf gcc/i486-pc-linux-gnu/12.2.0/plugin/libcp1plugin.la
rm -rf gcc/i486-pc-linux-gnu/12.2.0/plugin/libcc1plugin.la
rm -rf gcc/i486-pc-linux-gnu/12.2.0/liblto_plugin.la
cd /tmp
rm -rf /usr/lib/*.la
find / -name *.la

su -c "/usr/local/bin/wget -nc \
http://download.savannah.nongnu.org/releases/man-db/$SRC.tar.xz " $USER
tar xvf $SRC*xz
cd $SRC
./configure --prefix=/usr/local --disable-automatic-update --disable-setuid
make -j4 # 10 seconds
make install-strip DESTDIR=/tmp/$P
cd /tmp

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

# dev needed to compile man-pages- but built on TC64 as any arch
#####
rm -rf $P/usr/local/lib/man-db/*.la 

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

# main
#####
# for systemd
rm -rf $P/lib/

mkdir -p $P/usr/local/share/doc/$P
echo 'GPL v3' > $P/usr/local/share/doc/$P/COPYING

# TCZ them
#######
LIST="$P $P-doc $P-locale"
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:          man-db-doc.tcz
Description:    docs
Version:        2.11.2
Author:         Colin Watson
Original-site:  http://savannah.nongnu.org/projects/man-db
Copying-policy: GPL v3
Size:           120K
Extension_by:   aus9 
Tags:           man-db man
Comments:       Some docs and man pages

Change-log:     2023/08/22 v 2.11.2 on 14x
Current:        2023/08/22  '  > $P-doc.tcz.info

echo 'man-db.tcz ' > $P-doc.tcz.dep

echo 'Title:          man-db-locale.tcz
Description:    locales
Version:        2.11.2
Author:         Colin Watson 
Original-site:  http://savannah.nongnu.org/projects/man-db
Copying-policy: GPL v3
Size:           312K		
Extension_by:   aus9 
Tags:           locale man-db man 
Comments:       for non-english users untested.
                Contains Italian man pages

Change-log:     2023/08/22 v 2.11.2 on 14x
Current:        2023/08/22   '  > $P-locale.tcz.info

echo 'man-db.tcz ' > $P-locale.tcz.dep

echo 'Title:          man-db.tcz
Description:    man page viewer 
Version:        2.11.2
Author:         Colin Watson 
Original-site:  http://savannah.nongnu.org/projects/man-db
Copying-policy: GPL v3
Size:           400K
Extension_by:   aus9 
Tags:           man-db man
Comments:       terminal software to read man pages 
                $ man <man-page-name>
 
                WARNING setting setuid for user=man has not been compiled so 
                $ mandb -t (and some others) will fail. Most people will only
                want to read man pages and not create them here. IMHO
               
Change-log:     2023/08/22 v 2.11.2 on 14x
Current:        2023/08/22 ' > $P.tcz.info

readelf -d $P/usr/local/bin/* | grep 'NEEDED' # delete lots of duplications
# [libmandb-2.11.2.so] this TCE
# [libman-2.11.2.so] "
# [libgdbm.so.6] gdbm
# [libpipeline.so.1] libpipeline
readelf -d $P/usr/local/sbin/* | grep 'NEEDED' # no extra
readelf -d $P/usr/local/lib/$P/*.so | grep 'NEEDED' # no extra
readelf -d $P/usr/local/libexec/$P/* | grep 'NEEDED' # no extra

echo 'gdbm.tcz
libpipeline.tcz 
groff.tcz 
less.tcz  ' > $P.tcz.dep

