#!/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=dosfstools
V=
SRC=$P-git
USER=`cat /etc/sysconfig/tcuser`
LIST="compiletc submitqc git automake gettext-dev "
for Z in $LIST
    do 
    su -c "tce-load -i $Z" $USER
done

cd /tmp
su -c "git clone \
https://github.com/$P/$P.git "  $USER
mv $P $SRC
cd $SRC
sh autogen.sh
./configure --prefix=/usr/local --localstatedir=/var --enable-compat-symlinks
find . -name Makefile -type f -exec sed -i 's/-g -O2//g' {} \; 
make -j4 # seconds
make install-strip DESTDIR=/tmp/$P 
cd /tmp

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

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

# 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:          dosfstools-doc.tcz
Description:    man pages
Version:        git-2024/08/08
Author:         Pali Rohár 
Original-site:  https://github.com/dosfstools/dosfstools 
Copying-policy: GPL v3 
Size:           16K 
Extension_by:   aus9 @linuxquestions.org
Tags:           dos fs tools
Comments:       man pages 
                
Change-log:     2024/08/08 v git-2024/08/08
Current:        2024/08/08       
EOF
echo 'man-db.tcz ' > $P-doc.tcz.dep

cat >> $P.tcz.info <<'EOF'
Title:          dosfstools.tcz
Description:    dos disk utilities
Version:        git-2024/08/08
Author:         Pali Rohár 
Original-site:  https://github.com/dosfstools/dosfstools
Copying-policy: GPL v3 
Size:           76K 
Extension_by:   aus9 @linuxquestions.org
Tags:           dos fs tools
Comments:       dos file system tools
                Highly recommended that you load
                glibc_gconv, dosfstools & mtools before
                launching $ sudo gparted

                On an 8G usb 2.0, a move and resize may
                take 15 minutes YMMV
                
Change-log:     2015/01/04 v 3.0.26 (Juanito)
                2021/05/26 v 4.2
Current:        2024/08/07 v git 2024/08/08 (aus9)        
EOF
readelf -d $P/usr/local/sbin/* | grep 'NEEDED' # TCB only
# no dep

submitqc --libs
rm -rf *.zsync

