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

CFLAGS="-march=i486 -mtune=i686 -Os -pipe" 
CXXFLAGS="-march=i486 -mtune=i686 -Os -pipe -fno-exceptions -fno-rtti"

P=numlockx
V=1.2
SRC=$P-$V
USER=`cat /etc/sysconfig/tcuser`
LIST="compiletc submitqc libX11-dev libXtst-dev "
for Z in $LIST
    do 
    su -c "tce-load -i $Z" $USER
done

# list may be larger than loaded
cd /usr/local/lib
rm -rf *.la
rm -rf gcc/i486-pc-linux-gnu/12.2.0/plugin/libcp1plugin.la
rm -rf gcc/i486-pc-linux-gnu/12.2.0/plugin/libcc1plugin.la
rm -rf gcc/i486-pc-linux-gnu/12.2.0/liblto_plugin.la
cd /tmp
rm -rf /usr/lib/*.la

su -c "/usr/local/bin/wget -nc --no-check-certificate \
https://github.com/rg3/$P/releases/download/$V/$SRC.tar.gz   " $USER 
tar xvf $SRC*gz
cd $SRC
./configure --prefix=/usr/local x_includes=/usr/local/include/X11 x_libraries=/usr/local/lib
make -j5 # seconds
# ignore -> autoheader: not found as we are using configure
make install-strip DESTDIR=/tmp/$P
cd /tmp

# main 
####
mkdir -p $P/usr/local/share/doc/$P
cp $SRC/LICENSE $P/usr/local/share/doc/$P

# TCZ them
###########
LIST2="$P "
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:           numlockx.tcz
Description:     tool to turn numlock on/off/toggle 
Version:         1.2
Author:          Lubos Lunak - xkb stuff Oswald Buddenhagen
Original-site:   https://github.com/rg3/numlockx
Copying-policy:  accompanied
Size:            8.0K
Extension_by:    aus9
Tags:            numpad numlock
Comments:        For autostart ... numlock on ... for Xorg
                 $ echo 'numlockx on' > $HOME/.X.d/numlock

                 original site not found
                 https://devel-home.kde.org/~seli/numlockx                 

Change-log:      2010/12/04 v 1.2 (Martynas Brijunas - mbrijun)
Current:         2023/07/31 new download site (aus9) " > $P.tcz.info

readelf -d $P/usr/local/bin/numlockx | grep 'NEEDED'
# [libXtst.so.6] libXtst
# [libXext.so.6] libXext
# [libX11.so.6] libX11

echo 'libXtst.tcz 
libXext.tcz
libX11.tcz' > $P.tcz.dep

submitqc --libs

rm -rf *.zsync

