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

export CFLAGS="-march=armv8-a+crc -mtune=cortex-a72 -Os -pipe"
export CXXFLAGS="-march=armv8-a+crc -mtune=cortex-a72 -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 "
    for Z in $LIST
    do 
    su -c "tce-load -i $Z" $USER
done

# list may have more than loaded
cd /usr/local/lib
rm -rf *.la
rm -rf gcc/aarch64-unknown-linux-gnu/12.2.0/plugin/*.la
rm -rf gcc/aarch64-unknown-linux-gnu/12.2.0/*.la
rm -rf gprofng/*.la 
rm -rf python3.8/site-packages/*.la
rm -rf pkcs11/*.la
rm -rf cairo/*.la
rm -rf gtk-2.0/modules/*.la
rm -rf gtk-2.0/2.10.0/printbackends/*.la
rm -rf gtk-2.0/2.10.0/immodules/*.la
rm -rf gtk-2.0/2.10.0/engines/*.la
rm -rf imlib2/loaders/*.la
rm -rf imlib2/filters/*.la
rm -rf gdk-pixbuf-2.0/2.10.0/loaders/*.la
cd /tmp
rm -rf /usr/lib/*.la

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 # about 18 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:     2020/09/06 v 0.8.17 on 12.x 
Current:        2023/06/08 v 0.8.18.1 on 14.x    '> $P-locale.tcz.info

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

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:           56K
Extension_by:   aus9
Tags:           gtk2 text editor
Comments:       Supports 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 (or 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

                Can also print read cups, libcups, hplip or gutenprint depending
                on whether your printer is driverless

Change-log:     2020/09/06 v 0.8.17 on 12.x 
Current:        2023/06/08 v 0.8.18.1 on 14.x  '> $P.tcz.info

readelf -d $P/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]               "
# [libharfbuzz.so.0] gtk2
# [libfontconfig.so.1] fontconfig cairo
# [libfreetype.so.6]   freetype cairo

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

submitqc --libs

rm -rf *.zsync

