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

cd /tmp
URL=http://tinycorelinux.net/14.x/x86_64/tcz/src/leafpad
su -c "/usr/local/bin/wget -nc --no-check-certificate \
$URL/0001-fix-format-security-error-from-gcc.patch \
$URL/leafpad-0.8.19.tar.gz "  $USER

tar xvf $SRC*gz
cd $SRC
patch -Np1 < ../0001-fix-format-security-error-from-gcc.patch

./configure --prefix=/usr/local
make -j5 # takes 10 secs
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
gzip $P-doc/usr/local/share/man/man1/*

# 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 v 2' > $P/usr/local/share/doc/$P/COPYING

# we can reduce size by svg xpm
rm -rf $P/usr/local/share/icons/hicolor/scalable
rm -rf $P/usr/local/share/pixmaps/leafpad.xpm

# TCZ them
###########
LIST="$P $P-doc $P-locale  "
for Z in $LIST
do
	mksquashfs $Z $Z.tcz
	md5sum $Z.tcz > $Z.tcz.md5.txt
	cd $Z
	find . -not -type d | cut -c 2- | sort > /tmp/$Z.tcz.list
	cd /tmp
done

ls -hal

echo 'Title:          leafpad-doc.tcz
Description:    man page
Version:        0.8.19
Author:         Tarot Osuji
Original-site:  https://github.com/tarot231/leafpad
Copying-policy: GPL v2
Size:           4.0K
Extension_by:   aus9 @linuxquestions.org
Tags:           gtk2 text editor
Comments:       man page compressed tested ok

Change-log:     2024/12/21 v 0.8.19 on 15x
Current:        2024/12/21 ' > $P-doc.tcz.info
echo 'man-db.tcz' > $P-doc.tcz.dep

echo 'Title:          leafpad-locale.tcz
Description:    leafpad locales
Version:        0.8.19
Author:         Tarot Osuji
Original-site:  https://github.com/tarot231/leafpad
Copying-policy: GPL v2
Size:           104K
Extension_by:   aus9 @linuxquestions.org
Tags:           gtk2 text editor
Comments:       locales untested by me

Change-log:     2014/12/22 v 0.8.18.1 on 6x (maluvia)
                2023/04/03 v 0.8.19 on 14x (aus9) 
Current:        2024/12/21 manpage to doc TCE on 15x   '> $P-locale.tcz.info
echo 'leafpad.tcz' > $P-locale.tcz.dep

echo 'Title:          leafpad.tcz
Description:    gtk2 GUI text editor
Version:        0.8.19
Author:         Tarot Osuji
Original-site:  https://github.com/tarot231/leafpad
Copying-policy: GPL v2
Size:           48K
Extension_by:   aus9 @linuxquestions.org
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

                Optional mupdf is much smaller than evince for print preview
                1) choose print to file will default to ~/output.pdf 
                unless you change it.....then click on print to create file
                2) $ mupdf /pathway2/output.pdf 

                You may see an ignorable adwaita theme error if not loaded.

Change-log:     2014/12/22 v 0.8.18.1 on 6x (maluvia)
                2023/04/03 v 0.8.19 on 14x (aus9) 
Current:        2024/12/21 manpage to doc - delete svg/xpm files on 15x  '> $P.tcz.info

readelf -d /usr/local/bin/$P | grep 'NEEDED'
[libgtk-x11-2.0.so.0][libgdk-x11-2.0.so.0]gtk2
[libpangocairo-1.0.so.0][libpangoft2-1.0.so.0][libpango-1.0.so.0]pango gtk2 
[libatk-1.0.so.0] at-spi2-core  gtk2
[libcairo.so.2] cairo pango gtk2
[libgdk_pixbuf-2.0.so.0]gdk-pixbuf2 gtk2
[libgio-2.0.so.0][libglib-2.0.so.0][libgobject-2.0.so.0]glib2 cairo pango gtk2
#[libharfbuzz.so.0] harfbuzz freetype cairo pango gtk2
[libfontconfig.so.1] fontconfig cairo pango gtk2
[libfreetype.so.6]freetype fontconfig cairo pango gtk2

echo 'gtk2.tcz' > $P.tcz.dep

submitqc --libs
rm -rf *.zsync

# test printer ok
