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

CFLAGS="-march=i486 -mtune=i686 -Os -pipe   " 
CXXFLAGS="-march=i486 -mtune=i686 -Os -pipe -fno-exceptions -fno-rtti  "
echo $CFLAGS && echo $CXXFLAGS

P=tilda
V=1.5.4
SRC=$P-$V
USER=`cat /etc/sysconfig/tcuser`
LIST="compiletc squashfs-tools wget vte-2.91-dev intltool confuse3-dev automake gettext-dev"
for Z in $LIST
    do 
    su -c "tce-load -i $Z" $USER
done

# list may be larger than loaded
cd /usr/local/lib
rm -rf *.la
rm -rf gcc/i486-pc-linux-gnu/12.2.0/plugin/libcp1plugin.la
rm -rf gcc/i486-pc-linux-gnu/12.2.0/plugin/libcc1plugin.la
rm -rf gcc/i486-pc-linux-gnu/12.2.0/liblto_plugin.la
cd /tmp
rm -rf /usr/lib/*.la
find / -name *.la

su -c "/usr/local/bin/wget -nc --no-check-certificate \
https://github.com/lanoxx/$P/archive/refs/tags/$P-$V.tar.gz  " $USER 
tar xvf $P*gz
mv $P-$P-$V $SRC
cd $SRC
sh autogen.sh  
make -j4  # seconds
make install-strip DESTDIR=/tmp/$P
cd /tmp

# locale 
######
mkdir -p $P-locale/usr/local/share
mv $P/usr/local/share/locale $P-locale/usr/local/share 

# main 
####
# desktop - icon
################
echo 'X-FullPathIcon=/usr/local/share/pixmaps/tilda.png' >> $P/usr/local/share/applications/$P.desktop
mkdir -p $P/usr/local/share/doc/$P
echo 'GPL v2' > $P/usr/local/share/doc/$P/COPYING
cp $SRC/README.md $P/usr/local/share/doc/$P/


# TCZ them
###########
LIST2="$P $P-locale"
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

echo 'Title:          tilda-locale.tcz
Description:    locales for tilda
Version:        1.5.4
Author:         Sebastian Geiger
Original-site:  https://github.com/lanoxx/tilda
Copying-policy: GPL v2
Size:           72K
Extension_by:   aus9
Tags:           terminal locale 
Comments:       For non-English users of tilda.
                not tested by me

Change-log:     2023/08/03 v 1.5.4 14.x
Current:        2023/08/03              ' > $P-locale.tcz.info
echo 'tilda.tcz    ' > $P-locale.tcz.dep

echo 'Title:           tilda.tcz
Description:     drop down gtk3 terminal
Version:         1.5.4
Author:          Sebastian Geiger
Original-site:   https://github.com/lanoxx/tilda
Copying-policy:  GPL v2
Size:            76K
Extension_by:    aus9
Tags:            terminal gtk3
Comments:        This is a gtk3 terminal. Features include search bar,
                 make your own keyboard combinations (keybindings), 
                 toggle visible or not use F1 key 
                 but with so many options please see Readme.md

                 Please check config under $HOME/.config/
                 Suggest scrollbar be made true

                 You need to hide it on jwm to move to another workspace!

Change-log:      2023/08/03 v 1.5.4 14.x 
Current:         2023/08/03            ' > $P.tcz.info

readelf -d $P/usr/local/bin/tilda | grep 'NEEDED'
#########################remove TCBs
#libgtk-3.so.0]libgdk-3.so.0] gtk3 vte-2.91 
#libpango-1.0.so.0]pango gtk3 "
#libgdk_pixbuf-2.0.so.0]gdk-pixbuf2 -> vte-2.91
#libgio-2.0.so.0]libgobject-2.0.so.0]libglib-2.0.so.0] glib2 vte-2.91
#libvte-2.91.so.0]vte-2.91
#libconfuse.so.1]confuse3
#libX11.so.6]libX11

echo 'vte-2.91.tcz
confuse3.tcz
libX11.tcz
ncursesw-terminfo.tcz
adwaita-icon-theme.tcz  ' > $P.tcz.dep

