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

# error: ‘dynamic_cast’ not permitted with ‘-fno-rtti’
export CXXFLAGS="-mtune=generic -Os -pipe  "
export CFLAGS="-mtune=generic -Os -pipe"
# ./conftest: error while loading shared libraries: libpcre.so.1: cannot open shared object file: No such file or directory
P=lbreakouthd
V=1.1.9
SRC=$P-$V
USER=`cat /etc/sysconfig/tcuser`
LIST="compiletc submitqc sdl2-dev  sdl2_image-dev  sdl2_mixer-dev  sdl2_sound-dev sdl2_ttf-dev gettext-dev pcre   automake"
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://sourceforge.net/projects/lgames/files/$P/$SRC.tar.gz \
https://raw.githubusercontent.com/void-linux/void-packages/refs/heads/master/srcpkgs/$P/patches/uint.patch" $USER 
tar xvf $SRC*gz
cd $SRC 
patch -Np1 < ../uint.patch
# but was still getting a malloc error so brute fix
sed 's|AC_FUNC_MALLOC||' -i configure.ac
rm -rf configure
aclocal
autoconf
autoheader
automake --add-missing
./configure --prefix=/usr/local  --with-configdir=.config/lbreakouthd
make -j4 # 10 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
######
mkdir -p $P/usr/local/share/doc/$P
echo 'GPL v 3' > $P/usr/local/share/doc/$P/COPYING
mv $P/usr/local/share/lbreakouthd/themes/Standard/SIL-OFL.txt  $P/usr/local/share/doc/$P/COPYING

# lacks locale desktop entries
mkdir -p $P/usr/local/share/pixmaps
cp $P/usr/local/share/icons/hicolor/48x48/apps/$P.png $P/usr/local/share/pixmaps
echo 'X-FullPathIcon=/usr/local/share/pixmaps/lbreakouthd.png'  >> $P/usr/local/share/applications/$P.desktop

# README IS too important sorry 
cp $SRC/README  $P/usr/local/share/doc/$P

# submitqc finds 666 
chmod 644 $P/usr/local/var/lbreakouthd.hscr
# but falsely claims .... Expected 755:.................................NO they are already correct 644
# ./usr/local/share/lbreakouthd/themes/Standard/back1.jpg
# ./usr/local/share/lbreakouthd/themes/Standard/back2.jpg
# ./usr/local/share/lbreakouthd/themes/Standard/back4.jpg

# 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 . -not -type d | cut -c 2- | sort > /tmp/$Z.tcz.list
	cd /tmp
done

ls -hal

echo 'Title:          lbreakouthd-locale.tcz
Description:    language files
Version:        1.1.9
Author:         Original game Michael Speck
                this TCE - LGames
                themes - see /usr/local/share/lbreakouthd/themes/Standard/CREDITS
Original-site:  https://lgames.sourceforge.io/LBreakoutHD/
Copying-policy: main - GPL v 3
                font - SIL Open Font License, Version 1.1
Size:           44K
Extension_by:   aus9 @linuxquestions.org
Tags:           game 
Comments:       not tested by me

Change-log:     2025/01/08 v 1.1.9 on 15x
Current:        2025/01/08  ' > $P-locale.tcz.info
echo 'lbreakouthd.tcz' > $P-locale.tcz.dep

echo 'Title:          lbreakouthd.tcz
Description:    A ball-and-paddle game with nice graphics
Version:        1.1.9
Author:         Original game Michael Speck
                this TCE - LGames
                themes - see /usr/local/share/lbreakouthd/themes/Standard/CREDITS
Original-site:  https://lgames.sourceforge.io/LBreakoutHD/
Copying-policy: main - GPL v 3
                font - SIL Open Font License, Version 1.1
Size:           3.8M
Extension_by:   aus9 @linuxquestions.org
Tags:           game 
Comments:       a fork of lbreakout game by Michael Speck

                Supports 16:9 ratio monitors.  Please read the README which is so 
                important its in this TCE. Some known issues are also discussed here
                https://lgames.sourceforge.io/faq.php

                see ~/.config/lbreakouthd/lbreakouthd.conf
                Optional TCE input-joystick-6.6.8-tinycore64  not tested

Change-log:     2025/01/08 v 1.1.9 on 15x
Current:        2025/01/08    ' > $P.tcz.info

readelf -d $P/usr/local/bin/$P | grep 'NEEDED' 
1.1.9#libSDL2_mixer-2.0.so.0]sdl2_mixer
1.1.9#libSDL2_image-2.0.so.0]sdl2_image
1.1.9#libSDL2_ttf-2.0.so.0]sdl2_ttf
1.1.9#libSDL2-2.0.so.0]sdl2 sd2_mixer
# pcre was a make depend readelf thought not a run but it is
echo 'sdl2_mixer.tcz
sdl2_image.tcz
sdl2_ttf.tcz  
pcre.tcz  ' > $P.tcz.dep

submitqc --libs --no-fix
rm -rf *.zsync

