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

# configure shows....checking command to parse /usr/local/bin/nm -B output 
######from gcc -flto -fuse-linker-plugin -mtune=generic -Os -pipe object... failed
export CFLAGS="-mtune=generic -Os -pipe"
export CXXFLAGS="-mtune=generic -Os -pipe"

M=man-db
USER=`cat /etc/sysconfig/tcuser`

LIST="submitqc5 compiletc xz libpipeline-dev db-dev \
groff intltool gettext flex-dev gdbm-dev \
libwnck-dev valgrind "
for Z in $LIST
    do 
    su -c "tce-load -i $Z" $USER
done

cd /tmp
su -c "/usr/local/bin/wget -nc -t 0 \
http://ftp.yzu.edu.tw/nongnu/man-db/man-db-2.7.1.tar.xz \
man-db-2.7.1.tar.xz" $USER 

# we are root for rest of commands
xz -d $M-2.7.1.tar.xz
tar xvf $M-2.7.1.tar
cd $M-2.7.1
# configure (help) already /usr/local
./configure --disable-automatic-update
make -j3 
mkdir -p /tmp/$M
make install DESTDIR=/tmp/$M

# Strip executables
cd /tmp/$M
find . | xargs file | grep "executable"    | grep ELF | grep "not stripped" | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null
find . | xargs file | grep "shared object" | grep ELF | grep "not stripped" | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null

##############
cd /tmp
##############
# create locale
###############
mkdir -p $M-locale/usr/local/share
mv $M/usr/local/share/locale $M-locale/usr/local/share

# create doc 
############
mkdir -p $M-doc/usr/local/share
mv $M/usr/local/share/man $M-doc/usr/local/share
mv $M/usr/local/share/doc $M-doc/usr/local/share/

# create dev
############
mkdir -p $M-dev/usr/local/lib/man-db
mv $M/usr/local/lib/man-db/*.la $M-dev/usr/local/lib/man-db/
# fix perm
chmod 644 $M-dev/usr/local/lib/man-db/*.la
	
# main 
######
rm -rf $M/usr/local/share

# TCZ them
#######
LIST2="$M $M-doc $M-locale $M-dev"
for Z in $LIST2
do
	mksquashfs $Z $Z.tcz
	md5sum $Z.tcz > $Z.tcz.md5.txt
	cd $Z
	find usr -not -type d > /tmp/$Z.tcz.list
	cd /tmp
done

# create dep files
##################
echo "man-db.tcz" > man-db-locale.tcz.dep
echo "man-db.tcz" > man-db-doc.tcz.dep
echo "man-db.tcz" > man-db-dev.tcz.dep

echo "groff.tcz
bzip2-lib.tcz
pcre.tcz
less.tcz
libpipeline.tcz
gdbm.tcz
" > man-db.tcz.dep

# create info files let submitqc5 add size
###################
echo "Title:          man-db.tcz
Description:    new man page 
Version:        1
Author:         Colin Watson 
Original-site:  http://savannah.nongnu.org/projects/man-db
Copying-policy: GPL v3
Size:		
Extension_by:   gordons64
Tags:           man-db man
Comments:      This replaces the old upstream man.
               
               a terminal based manual pager

		Compiled for Corepure64 6.x
Change-log:     2015/07/07 First version
Current:        2015/07/07
" > man-db.tcz.info

echo "Title:          man-db-doc.tcz
Description:    man page for man-db
Version:        1
Author:         Colin Watson
Original-site:  http://savannah.nongnu.org/projects/man-db
Copying-policy: GPL v3
Size:		
Extension_by:   gordons64
Tags:           man-db 
Comments:      Contains man page 
               Also Spanish and Italian 

		Compiled for Corepure64 6.x
Change-log:     2015/07/07 First version
Current:        2015/07/07 
" > man-db-doc.tcz.info

echo "Title:          man-db-locale.tcz
Description:    locales for man-db
Version:        1
Author:         Colin Watson 
Original-site:  http://savannah.nongnu.org/projects/man-db
Copying-policy: GPL v3
Size:		
Extension_by:   gordons64
Tags:           man-db, locale 
Comments:      For non-English users of man-db.

		Compiled for Corepure64 6.x
Change-log:     2015/07/07 First version
Current:        2015/07/07 
" > man-db-locale.tcz.info

echo "Title:          man-db-dev.tcz
Description:    dev for man-db
Version:        1
Author:         Colin Watson 
Original-site:  http://savannah.nongnu.org/projects/man-db
Copying-policy: GPL v3
Size:		
Extension_by:   gordons64
Tags:           man-db, locale 
Comments:      development files of man-db.

		Compiled for Corepure64 6.x
Change-log:     2015/07/07 First version
Current:        2015/07/07 
" > man-db-dev.tcz.info

submitqc5