#!/bin/sh
# test we are root
if [ "$(id -u)" != "0" ]; then
   exit 1
fi

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

P=mtools
V=4.0.44
SRC=$P-$V
USER=`cat /etc/sysconfig/tcuser`
LIST="compiletc submitqc libX11-dev  "
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 \
http://ftp.gnu.org/gnu/$P/$SRC.tar.bz2  "  $USER
tar jxvf $SRC*bz2
cd $SRC
./configure --prefix=/usr/local --with-x 
find . -name Makefile -type f -exec sed -i 's/-O2//g' {} \;
make -j4 # seconds
make install DESTDIR=/tmp/$P # no strip rule
cd /tmp

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

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

strip --strip-unneeded $P/usr/local/bin/*

# TCZ them
###########
LIST2="$P $P-doc "
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
        sed 's|usr|/usr|g' -i /tmp/$Z.tcz.list
	cd /tmp
done

ls -hal

cat >> $P-doc.tcz.info <<'EOF'
Title:          mtools-doc.tcz
Description:    man pages
Version:        4.0.44
Author:         Main-Alain Knaff & David Niemi
                amuFormat.sh-Feuz Stefan & Adam Tkac
Original-site:  https://www.gnu.org/software/mtools/ 
Copying-policy: GPL v3 
Size:           56K 
Extension_by:   aus9 @linuxquestions.org
Tags:	        dos disk utilitiy
Comments:       man pages or Online manual
                https://www.gnu.org/software/mtools/manual/mtools.html
                
Change-log:     2024/08/07 v 4.0.44
Current:        2024/08/07        
EOF
echo 'man-db.tcz ' > $P-doc.tcz.dep

cat >> $P.tcz.info <<'EOF'
Title:          mtools.tcz
Description:    dos disk utilities
Version:        4.0.44
Author:         Main-Alain Knaff & David Niemi
                amuFormat.sh-Feuz Stefan & Adam Tkac
Original-site:  https://www.gnu.org/software/mtools/ 
Copying-policy: GPL v3 
Size:           120K 
Extension_by:   aus9 @linuxquestions.org
Tags:	        dos disk utilitiy
Comments:       collection of utilities to access ms-dos disks from 
                linux without mounting them

                Online manual
                https://www.gnu.org/software/mtools/manual/mtools.html
                
Change-log:     2015/02/11 v 4.0.17 (Juanito)
Current:        2024/08/07 v 4.0.44 (aus9)        
EOF
readelf -d $P/usr/local/bin/* | grep 'NEEDED'
# libXau.so.6 libXau
# libX11.so.6 libX11

echo 'libXau.tcz 
libX11.tcz   ' > $P.tcz.dep

submitqc --libs
rm -rf *.zsync

