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

CFLAGS="-mtune=generic -Os -pipe"
CXX="-mtune=generic -Os -pipe -fno-exceptions -fno-rtti"

P=leafpad
PATCH=0001-fix-format-security-error-from-gcc.patch
V=0.8.19
SRC=$P-$V
USER=`cat /etc/sysconfig/tcuser`
LIST="compiletc submitqc gettext perl5 gtk2-dev libtool-dev automake intltool"
    for Z in $LIST
    do 
    su -c "tce-load -i $Z" $USER
done

cd /tmp
URL=https://raw.githubusercontent.com/archlinux/svntogit-packages/packages/$P/trunk
su -c "/usr/local/bin/wget -nc --no-check-certificate \
https://download.savannah.gnu.org/releases/$P/$SRC.tar.gz \
$URL/0001-fix-format-security-error-from-gcc.patch "  $USER

tar xvf $SRC*gz
cd $SRC
patch -Np1 < ../$PATCH

./configure --prefix=/usr/local
make -j5 # takes 10 secs
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
#######
APP=$P/usr/local/share/applications/$P.desktop
echo 'X-FullPathIcon=/usr/local/share/pixmaps/leafpad.png' >> $APP

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

rm -rf $P/usr/local/share/man

# TCZ them
###########
LIST="$P $P-locale  "
for Z in $LIST
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:          leafpad-locale.tcz
Description:    leafpad locales
Version:        0.8.18.1
Author:         Tarot Osuji
Original-site:  https://github.com/tarot231/leafpad
Copying-policy: GPL v2
Size:           104K
Extension_by:   aus9
Tags:           gtk2 text editor
Comments:       locales untested by me

Change-log:     2014/12/22 v 0.8.18.1 on 6x (maluvia)
Current:        2023/04/03 v 0.8.19 on 14x (aus9)   '> $P-locale.tcz.info

echo 'Title:          leafpad.tcz
Description:    gtk2 GUI text editor
Version:        0.8.18.1
Author:         Tarot Osuji
Original-site:  https://github.com/tarot231/leafpad
Copying-policy: GPL v2
Size:           60K
Extension_by:   aus9
Tags:           gtk2 text editor
Comments:       May support UTF-8
                Keybindings are:
                Ctrl-N New ....Ctrl-O Open
                Ctrl-S Save...Shift-Ctrl-S Save As
                Ctrl-W Close....Ctrl-P Print
                Ctrl-Q Quit...Ctrl-Z Undo
                Shift-Ctrl-Z (Ctrl-Y) Redo
                Ctrl-X Cut...Ctrl-C Copy
                Ctrl-V Paste..Ctrl-A Select All
                Ctrl-F Find..Ctrl-G (F3) Find Next
                Shift-Ctrl-G (Shift-F3) Find Previous
                Ctrl-H (Ctrl-R) Replace
                Ctrl-J Jump To
                Ctrl-T Always on Top
                Ctrl-Tab toggle tab width
                
                Tab with selection bound  multi-line indent
                Shift-Tab with selection bound multi-line unindent

                online man page
                https://github.com/tarot231/leafpad/blob/main/data/leafpad.1

                I use evince for print preview. Read cups, gutenprint or hplip
                if you need to print from leafpad please

Change-log:     2014/12/22 v 0.8.18.1 on 6x (maluvia)
Current:        2023/04/03 v 0.8.19 on 14x (aus9)   '> $P.tcz.info

echo 'leafpad.tcz' > $P-locale.tcz.dep

readelf -d /usr/local/bin/$P | grep 'NEEDED'
[libgtk-x11-2.0.so.0]    gtk2
[libgdk-x11-2.0.so.0]     "
[libpangocairo-1.0.so.0] pango gtk2 
[libatk-1.0.so.0]        atk  gtk2
[libcairo.so.2]          cairo
[libgdk_pixbuf-2.0.so.0] gdk-pixbu2 
[libgio-2.0.so.0]        glib2 gtk2
[libpangoft2-1.0.so.0]   pango gtk2
[libpango-1.0.so.0]              "
[libgobject-2.0.so.0]    glib2 gtk2
[libglib-2.0.so.0]               "
[libfontconfig.so.1] fontconfig cairo
[libfreetype.so.6]   freetype cairo
[libpthread.so.0] TCB
[libc.so.6]       "               
[libgcc_s.so.1]   "

echo 'gtk2.tcz
cairo.tcz
gdk-pixbuf2.tcz ' > $P.tcz.dep


submitqc --libs

# test printer ok
