#!/bin/sh
# test we are root
if [ "$USER" != "root" ] ; then
   echo "Run as root please, exiting." 
   exit 1                                                      
fi

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

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

cd /tmp
/usr/local/bin/wget -nc --no-check-certificate \
https://sourceforge.net/projects/linuxconsole/files/$SRC.tar.bz2
tar jxvf $SRC*
cd $SRC
make prefix=/usr/local
make install DESTDIR=/tmp/$P # NO STRIP
cd /tmp

# doc
#####
mkdir -p $P-doc/usr/local/share/doc/$P
mv $P/usr/local/share/man $P-doc/usr/local/share
cp $SRC/README $P-doc/usr/local/share/doc/$P
mv $P/lib/udev $P-doc/usr/local/share/doc/$P
rm -rf $P/lib

# main
###### 
mkdir -p $P/usr/local/share/doc/$P
echo 'GPL v 2' > $P/usr/local/share/doc/$P/COPYING
strip --strip-unneeded $P/usr/local/bin/* # ignore scripts saying not elf


# TCZ them
#######
LIST="$P $P-doc"
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:          linuxconsoletools-doc.tcz  
Description:    man page, README + udev rule
Version:        1.8.1
Author:         linuxconsoletools Team
Original-site:  https://sourceforge.net/projects/linuxconsole/
Copying-policy: GPL v 2
Size:           16K
Extension_by:   aus9  
Tags:           joystick gamepad game
Comments:       Contains an udev rule for manufacturer=vendor=04d8 
                Read the README but use root powers to 
                copy and edit any relevant udev rule to 
                /etc/udev/rules.d then run
                $ sudo udevadm control --reload-rules
                $ udevadm trigger
                This device is no longer on sale AFAIK   
                
Change-log:     2025/12/27 v 1.8.1 on 16x
Current:        2025/12/27  ' > $P-doc.tcz.info
echo 'man-db.tcz ' > $P-doc.tcz.dep

echo 'Title:          linuxconsoletools.tcz  
Description:    test and configure mainly game devices as below
Version:        1.8.1
Author:         linuxconsoletools Team
Original-site:  https://sourceforge.net/projects/linuxconsole/
Copying-policy: GPL v 2
Size:           48K
Extension_by:   aus9  
Tags:           joystick gamepad game
Comments:       I did not need any udev rule YMMV
                udev rule are in the doc TCE
                
                ffmvforce requires sdl2.tcz 

                Normal testing of joystick =
                $ jstest --normal /dev/input/js0
                (and press buttons, triggers etc)   
                
Change-log:     2025/12/27 v 1.8.1 on 16x
Current:        2025/12/27 ' > $P.tcz.info
readelf -d $P/usr/local/bin/ffmvforce | grep 'NEEDED'
# libSDL2-2.0.so.0 sdl2

# no dep no submitqc

# submitqc --libs
# rm -rf *.zsync


