#!/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"
P=lbreakouthd
V=1.2.4
SRC=$P-$V
USER=`cat /etc/sysconfig/tcuser`
LIST="compiletc submitqc gettext-dev sdl_sound-dev sdl2-dev sdl2_image-dev sdl2_mixer-dev sdl2_ttf-dev "
for Z in $LIST
    do 
    su -c "tce-load -i $Z" $USER
done

cd /tmp 
URL=https://raw.githubusercontent.com/void-linux/void-packages/refs/heads/master/srcpkgs/lbreakouthd/patches
/usr/local/bin/wget -nc --no-check-certificate \
https://sourceforge.net/projects/lgames/files/$P/$SRC.tar.gz \
$URL/uint.patch
tar xvf $SRC*gz
cd $SRC 
patch -Np1 < ../uint.patch
./configure --prefix=/usr/local  --with-configdir=.config/lbreakouthd
make -j6 # 5 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.2.4
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:           52K
Extension_by:   aus9 @linuxquestions.org
Tags:           game 
Comments:       not tested by me

Change-log:     2025/01/08 v 1.1.9 on 15x
Current:        2026/10/26 v 1.2.4 on 17x  ' > $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.2.4
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:           4.6M
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
                Tested on Xorg and wayland

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

readelf -d $P/usr/local/bin/$P | grep 'NEEDED' 
#libSDL2_mixer-2.0.so.0]sdl2_mixer
#libSDL2_image-2.0.so.0]sdl2_image
#libSDL2_ttf-2.0.so.0]sdl2_ttf
#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    ' > $P.tcz.dep

# submitqc --libs --no-fix # 17x still wants to make images 755
# rm -rf *.zsync

