#!/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="g++ -flto -fuse-linker-plugin -mtune=generic -Os -pipe "

P=man-db
V=2.8.2
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://ftp.yzu.edu.tw/nongnu/$P/$P-$V.tar.xz " $USER
mkdir $P
xz -d $P*xz && tar xvf $P*tar
cd $P-$V 
./configure --disable-automatic-update --disable-setuid
make -j5
make install-strip DESTDIR=/tmp/$P

# locale
#########
cd /tmp
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/es $P-locale/usr/local/share/man/
mv $P/usr/local/share/man/it $P-locale/usr/local/share/man/

# doc
#####
mkdir -p $P-doc/usr/local/share/doc/$P
cp $P-$V/docs/COPYING $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/
cp $P-$V/README $P-doc/usr/local/share/doc/$P

# the readme shows colin watson 2014 as last author

# dev
#####
mkdir -p $P-dev/usr/local/lib/$P
mv $P/usr/local/lib/$P/*a $P-dev/usr/local/lib/$P/
chmod 644 $P-dev/usr/local/lib/$P/*a 
###############
# there is no pc file

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

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

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

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

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

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

echo 'Title:          man-db.tcz
Description:    terminal software mainly to read man pages 
Version:        2.8.2
Author:         Colin Watson 
Original-site:  http://savannah.nongnu.org/projects/man-db
Copying-policy: GPL v2
Size:		264K
Extension_by:   aus9 at gmx dot com
Tags:           man-db man
Comments:       terminal software to read man pages eg
                $ 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
               
                Compiled for 9.x
Change-log:     2015/07/07 First version (gordon64)
Current:        2018/0/08 2.7.1 -> 2.8.2 (aus9) ' > $P.tcz.info

echo 'Title:          man-db-doc.tcz
Description:    docs
Version:        2.8.2
Author:         Colin Watson
Original-site:  http://savannah.nongnu.org/projects/man-db
Copying-policy: GPL v2
Size:		
Extension_by:   aus9 at gmx dot com
Tags:           man-db man
Comments:       Some docs

                Compiled for 9.x
Change-log:     2015/07/07 First version (gordon64)
Current:        2018/0/08 2.7.1 -> 2.8.2 (aus9)' > $P-doc.tcz.info

echo 'Title:          man-db-dev.tcz
Description:    dev files 
Version:        2.8.2
Author:         Colin Watson
Original-site:  http://savannah.nongnu.org/projects/man-db
Copying-policy: GPL v2
Size:		
Extension_by:   aus9 at gmx dot com
Tags:           man-db man
Comments:       Development files

                Compiled for 9.x
Change-log:     2015/07/07 First version (gordon64)
Current:        2018/0/08 2.7.1 -> 2.8.2 (aus9) ' > $P-dev.tcz.info


echo 'Title:          man-db-locale.tcz
Description:    locales
Version:        2.8.2
Author:         Colin Watson 
Original-site:  http://savannah.nongnu.org/projects/man-db
Copying-policy: GPL v2
Size:		
Extension_by:   aus9 at gmx dot com
Tags:           locale man-db man 
Comments:       for non-english users untested.
                Contains Spanish and Italian man pages too.

                Compiled for 9.x
Change-log:     2015/07/07 First version (gordon64)
Current:        2018/0/08 2.7.1 -> 2.8.2 (aus9)' > $P-locale.tcz.info

submitqc --libs
