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

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

# note unusual source variable
P=tilda
V=2.0.0
SRC=$P-$P-$V
USER=`cat /etc/sysconfig/tcuser`
LIST="compiletc submitqc vte-2.91-dev libconfuse-dev automake gettext-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 \
https://github.com/lanoxx/$P/archive/refs/tags/$P-$V.tar.gz  " $USER 
tar xvf $P*gz
chown -R root:root $SRC
cd $SRC

mkdir build && cd build
../autogen.sh
cd ../
./configure --prefix=/usr/local 
# tilda 2.0.0 # altho autogen and configure are kind of same, I make explicit
# prefix:              /usr/local
# datarootdir:         ${prefix}/share
# datadir:             ${datarootdir}
# pkgdatadir:          ${datarootdir}/tilda
# source code location:.
# compiler:            gcc
# cflags:              -mtune=generic -Os -pipe -std=c99 -std=c99 
# Maintainer mode:     yes
# VTE:                           
# Use *_DISABLE_DEPRECATED
make -j5 # seconds
make install-strip DESTDIR=/tmp/$P
cd /tmp

# doc
#####
mkdir -p $P-doc/usr/local/share/doc/$P
mv $P/usr/local/share/man $P-doc/usr/local/share/
cp $SRC/README.md $P-doc/usr/local/share/doc/$P
cp $SRC/docs/* $P-doc/usr/local/share/doc/$P
mv $SRC/images $P-doc/usr/local/share/doc/$P
# submit finds wrong perm
chmod 755 $P-doc/usr/local/share/doc/$P/images
chmod 644 $P-doc/usr/local/share/doc/$P/images/*.png

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

# main 
# desktop stuff there are 2
################
DESK1=$P/usr/local/share/applications/$P.desktop
DESK2=$P/usr/local/share/applications/$P-dbus.desktop
echo 'X-FullPathIcon=/usr/local/share/pixmaps/tilda.png' >> $DESK1
echo 'X-FullPathIcon=/usr/local/share/pixmaps/tilda.png' >> $DESK2

mkdir -p $P/usr/local/share/doc/$P
echo 'GPL v2' > $P/usr/local/share/doc/$P/COPYING

# TCZ them
###########
LIST2="$P $P-doc $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-doc.tcz
Description:    man page & help
Version:        2.0.0
Author:         Sebastian Geiger    
Original-site:  https://github.com/lanoxx/tilda
Copying-policy: GPL v2
Size:           344K
Extension_by:   aus9 @ linuxquestions.org  
Tags:           terminal gtk3 
Comments:       man page & lots of helpful stuff
                
Change-log:     2024/04/03 v 2.0.0 on 15x first version
Current:        2024/04/03                               ' > $P-doc.tcz.info
echo 'man-db.tcz    ' > $P-doc.tcz.dep

echo 'Title:          tilda-locale.tcz
Description:    locales for tilda
Version:        2.0.0
Author:         Sebastian Geiger    
Original-site:  https://github.com/lanoxx/tilda
Copying-policy: GPL v2
Size:           96K
Extension_by:   aus9 @ linuxquestions.org  
Tags:           terminal gtk3 locale
Comments:       For non-English users of tilda.
                not tested by me
                
Change-log:     2024/04/03 v 2.0.0 on 15x first version
Current:        2024/04/03                               ' > $P-locale.tcz.info
echo 'tilda.tcz    ' > $P-locale.tcz.dep

echo 'Title:          tilda.tcz
Description:    gtk3 terminal with rollup function as below
Version:        2.0.0
Author:         Sebastian Geiger    
Original-site:  https://github.com/lanoxx/tilda
Copying-policy: GPL v2
Size:           76K
Extension_by:   aus9 @ linuxquestions.org  
Tags:           terminal gtk3
Comments:       Recommend you read all info tilda-doc TCE please 
                as it affects keybindings, configs etc

                Note it is important to know that while tilda is active,
                if you wish to do things outside tilda, press F1 to roll it up
                otherwise you can not escape tilda. And other instances F2 etc

                2 main ways to exit tilda are Ctrl + Shift + q or $ exit
                Key bindings can now change.

                On Wayland, you may prefer enable dbus (Optional dep) -
                enable dbus and use dbus desktop that claims
                "/usr/local/bin/tilda --dbus"

                in mc TCE, arrow down works but you may like to try vifm TCE

Change-log:     2020/07/22 v 1.5.0 on 11x dep vte (rudock1) 
Current:        2024/04/03 v 2.0.0 on 15x dep vte-2.91-gtk3 (aus9)         ' > $P.tcz.info

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

echo 'vte-2.91-gtk3.tcz
libconfuse.tcz  ' > $P.tcz.dep

# no icon or gtk-update used in dep

submitqc --libs
rm -rf *.zsync


