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

export CFLAGS="-mtune=generic -Os -pipe"
export CXX="-mtune=generic -Os -pipe -fno-exceptions -fno-rtti "

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

cd /tmp
su -c "/usr/local/bin/wget -nc \
http://download.savannah.nongnu.org/releases/man-db/$SRC.tar.xz " $USER
xz -d $SRC*xz && tar xvf $SRC*tar
cd $SRC
./configure --prefix=/usr/local --disable-automatic-update --disable-setuid
make -j5 # 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
#####
mkdir -p $P-dev/usr/local/lib/$P
mv $P/usr/local/lib/man-db/*a $P-dev/usr/local/lib/$P/
chmod 644 $P-dev/usr/local/lib/$P/*a

# 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-dev $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-dev.tcz
Description:    dev files
Version:        2.11.2
Author:         Colin Watson
Original-site:  http://savannah.nongnu.org/projects/man-db
Copying-policy: GPL v3
Size:           4.0K
Extension_by:   aus9 
Tags:           man-db man
Comments:       dev files

Change-log:     2015/07/07 v 2.7.1 (gordon64)
                2018/02/08 v 2.8.2 on 9x (aus9)
Current:        2023/04/06 v 2.11.2 on 14x  '  > $P-dev.tcz.info

echo 'man-db.tcz 
libtool.tcz 
intltool.tcz 
libpipeline-dev.tcz
gdbm-dev.tcz 
groff.tcz 
db-dev.tcz ' > $P-dev.tcz.dep

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:     2015/07/07 v 2.7.1 (gordon64)
                2018/02/08 v 2.8.2 on 9x (aus9)
                2019/01/08 v 2.8.4 on 10x
Current:        2023/04/06 v 2.11.2 on 14x  '  > $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:     2015/07/07 v 2.7.1 (gordon64)
                2018/02/08 v 2.8.2 on 9x (aus9)
                2019/01/08 v 2.8.4 on 10x
Current:        2023/04/06 v 2.11.2 on 14x   '  > $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:           328K
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:     2015/07/07 v 2.7.1 (gordon64)
                2018/02/08 v 2.8.2 on 9x (aus9)
                2019/01/08 v 2.8.4 on 10x
Current:        2023/04/06 v 2.11.2 on 14x ' > $P.tcz.info

readelf -d $P/usr/local/bin/mandb | grep 'NEEDED'
# [libmandb-2.11.2.so] this TCE
# [libman-2.11.2.so] "
# [libgdbm.so.6] gdbm
# [libz.so.1] TCB
# [libpipeline.so.1] libpipeline
# [libc.so.6] TCB

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


submitqc --libs
