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


# tested wbar even tho png is 128x128 it displays and opens

# in the past lxterminal compile on aterm due to vte conflicts
# no longer applies

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

P=lxterminal
V=0.4.0
SRC=$P-$V
USER=`cat /etc/sysconfig/tcuser`
LIST="compiletc submitqc wget xz vte-2.91-dev intltool"
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://downloads.sourceforge.net/lxde/$SRC.tar.xz   " $USER 
xz -d $SRC*xz && tar xvf $SRC*tar
cd $SRC
./configure --enable-gtk3 --disable-man  

make -j5 # 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
################
mkdir -p $P/usr/local/share/pixmaps
ICON=$P/usr/local/share/icons/hicolor/128x128/apps/
cp $ICON/$P.png $P/usr/local/share/pixmaps/
echo 'X-FullPathIcon=/usr/local/share/pixmaps/lxterminal.png' >> $P/usr/local/share/applications/$P.desktop

# xterm
#########
cat >> $P/usr/local/bin/$P-xterm <<'EOF'
#!/bin/busybox sh
# lxterminal xterm wrapper for Tiny Core Linux 5.x
# By bmarkus
# v1.0 - October 15, 2013

a=0
c=""

for v in $*
do
  if [ $a == 0 ]
  then
    if [ "$v" == "-g" ]
    then
      a=1
      c="--geometry="
    elif [ "$v" == "-e" ]
    then
      a=2
      c=$c$v" "
    fi
  elif [ $a == 1 ]
  then
    a=0
    c=$c$v" "
  elif [ $a == 2 ]
  then
    c=$c$v" "
  fi
done

lxterminal $c
EOF
chmod 775 $P/usr/local/bin/lxterminal-xterm

# tce.installed 
###############

mkdir -p $P/usr/local/tce.installed
echo '#!/bin/sh
# force xterm to lxterminal even if aterm loaded first
[ -f /usr/local/bin/xterm ] || rm -rf /usr/local/bin/xterm
ln -s /usr/local/bin/lxterminal-xterm /usr/local/bin/xterm ' > $P/usr/local/tce.installed/$P 
chown root:staff -R $P/usr/local/tce.installed
chmod -R 775 $P/usr/local/tce.installed

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

# set nicer font for O vs 0 and increase size
sed 's|Monospace 10|mononoki 15|' -i $P/usr/local/share/lxterminal/lxterminal.conf

# use online manpage
rm -rf $P/usr/local/share/man

# 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:          lxterminal-locale.tcz
Description:    locales for lxterminal
Version:        0.4.0
Author:         lxterminal team
Original-site:  http://sourceforge.net/projects/lxde/files
Copying-policy: GPL v2
Size:           128K
Extension_by:   aus9
Tags:           terminal locale 
Comments:       For non-English users of lxterminal.
                not tested by me
                
Change-log:     2015/08/01 First version  (gordon64)
                2018/10/14 0.3 -> 0.3.2 (aus9)  
                2019/01/03 recompiled for gnutls35
Current:        2023/03/16 v 0.4.0 on 14x ' > $P-locale.tcz.info


echo 'Title:           lxterminal.tcz
Description:     gtk3 terminal for libX or wayland
Version:         0.4.0
Author:          lxterminal team
Original-site:   http://sourceforge.net/projects/lxde/files
Copying-policy:  GPL v2
Size:            48K
Extension_by:    you
Tags:            terminal utf8
Comments:        This is a gtk3 terminal capable of UTF-8 display.
                 Allows multiple tabs. Online man page is here
                 https://linuxcommandlibrary.com/man/lxterminal

                 If not in Xorg, to adjust fontname or its size edit
                  .config/lxterminal/lxterminal.conf

                 Optional deps:  More font TCEs, load fontconfig
                 then load lxterminal please.

                 apps (GUI) can work with lxterminal due to xterm setup

Change-log:     2015/08/01 First version (gordon64) 
                2018/10/14 0.3 -> 0.3.2 (aus9)  
                2019/01/03 recompiled for gnutls35
Current:        2023/03/16 v 0.4.0 on 14x' > $P.tcz.info

readelf -d $P/usr/local/bin/lxterminal | grep 'NEEDED'
#####################################
# 0x0000000000000001 (NEEDED)  Shared library: [libglib-2.0.so.0]     glib2 -> vte-2.91
# 0x0000000000000001 (NEEDED)  Shared library: [libgtk-3.so.0]         gtk3   -> vte-2.91
# 0x0000000000000001 (NEEDED)  Shared library: [libgdk-3.so.0]              "
# 0x0000000000000001 (NEEDED)  Shared library: [libz.so.1]                  TCB
# 0x0000000000000001 (NEEDED)  Shared library: [libpangocairo-1.0.so.0]   pango -> vte-2.91
# 0x0000000000000001 (NEEDED)  Shared library: [libpango-1.0.so.0]          "     
# 0x0000000000000001 (NEEDED)  Shared library: [libharfbuzz.so.0]         harfbuzz
# 0x0000000000000001 (NEEDED)  Shared library: [libatk-1.0.so.0]         atk -> vte-2.91
# 0x0000000000000001 (NEEDED)  Shared library: [libcairo-gobject.so.2]   cairo -> vte-2.91
# 0x0000000000000001 (NEEDED)  Shared library: [libcairo.so.2]             "
# 0x0000000000000001 (NEEDED)  Shared library: [libgdk_pixbuf-2.0.so.0]  gdk-pixbuf2 -> gtk3...vte-2.91
# 0x0000000000000001 (NEEDED)  Shared library: [libgio-2.0.so.0]         glib2 -> vte-2.91
# 0x0000000000000001 (NEEDED)  Shared library: [libgobject-2.0.so.0]           "
# 0x0000000000000001 (NEEDED)  Shared library: [libvte-2.91.so.0]             vte-2.91
# 0x0000000000000001 (NEEDED)  Shared library: [libX11.so.6]                 libX11 -> gtk3
# 0x0000000000000001 (NEEDED)  Shared library: [libpthread.so.0]              TCB
# 0x0000000000000001 (NEEDED)  Shared library: [libc.so.6]                     "
################################

echo 'vte-2.91.tcz
harfbuzz.tcz
adwaita-icon-theme.tcz 
mononoki-ttf-fonts.tcz  ' > $P.tcz.dep

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

submitqc --libs