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

export CFLAGS="-mtune=generic -Os -pipe"
export CXX="-mtune=generic -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

cd /tmp
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:        Try this please for autostart numlock on 
                 $ mkdir $HOME/.X.d # if missing
                 $ echo 'numlockx on' > $HOME/.X.d/numlock                 

Change-log:     2015/08/01 v 1.2 debian source on 6.x  
Current:        2023/05/28 changed to github source 14.x   ' > $P.tcz.info

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

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

submitqc --libs

