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

export CXXFLAGS="-mtune=generic -Os -pipe -fno-exceptions -fno-rtti "
export CFLAGS="-mtune=generic -Os -pipe"
P=abe
V=1.1
SRC=$P-$V
USER=`cat /etc/sysconfig/tcuser`
LIST="compiletc submitqc sdl-dev  sdl_image-dev  sdl_mixer-dev  sdl_sound-dev imagemagick "
for Z in $LIST
    do 
    su -c "tce-load -i $Z" $USER
done
# already installed input-joystick-6.6.8-tinycore64 libXi-dev libXmu-dev

cd /tmp 
su -c "/usr/local/bin/wget -nc --no-check-certificate \
https://sourceforge.net/projects/abe/files/$P/$SRC/$SRC.tar.gz " $USER 
tar xvf $SRC*gz
cd $SRC 
./configure --prefix=/usr/local  --with-x --with-data-dir=/usr/local/share/abe
make -j4 # seconds
make install-strip DESTDIR=/tmp/$P 
cd /tmp

# main
######
mkdir -p $P/usr/local/share/doc/$P
echo 'GPL v 2' > $P/usr/local/share/doc/$P/COPYING

# missing dirs config should have worked no errors in config.log so fix 
mkdir -p $P/usr/local/share/$P/images
mkdir -p $P/usr/local/share/$P/maps
mkdir -p $P/usr/local/share/$P/sounds

cp $SRC/images/images.tar $P/usr/local/share/$P/images
cp $SRC/maps/*.dat $P/usr/local/share/$P/maps
cp $SRC/sounds/* $P/usr/local/share/$P/sounds # copies wav and 2 ogg files

mkdir -p $P/usr/local/share/pixmaps
cp $SRC/images/images.tar  /tmp
tar xvf images.tar 
convert abe.bmp -resize 48x48 abe.png # FAILS  abe.png: PNG image data, 48 x 35, 8-bit/color RGB, non-interlaced
# lets accept and move on
mv abe.png $P/usr/local/share/pixmaps/
rm -rf *.bmp images.tar # cleanup tmp

mkdir -p $P/usr/local/share/applications
echo '[Desktop Entry]
Name=abe
Exec=abe 
Icon=abe
Terminal=false
Type=Application
Categories=Game;Applications
X-FullPathIcon=/usr/local/share/pixmaps/abe.png' > $P/usr/local/share/applications/abe.desktop

# TCZ them
###########
LIST2="$P "
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:          abe.tcz
Description:    2d scrolling game as below
Version:        1.1
Author:         Gabor Torok, Pedro Izecksohn & Alex Clarck
Original-site:  https://sourceforge.net/projects/abe
Copying-policy: GPL v 2
Size:           3.0M
Extension_by:   aus9 @linuxquestions.org
Tags:           game scrolling
Comments:       A scrolling, platform-jumping, key-collecting, ancient pyramid 
                exploring game, vaguely in the style of similar games for the Commodore+4. 

                (arrow keys=move)  (esc=quit)  (enter=use a balloon)
                space = jump  OR toggle some settings in the settings screen
 
                Optional TCE input-joystick-6.6.8-tinycore64  not tested

                Suggest setup sound first.  First find a wav file. If 
                $ aplay /usr/local/share/sounds/alsa/Noise.wav
                plays a noise you are good to go. If you have been
                using pulse to swap your devices, you may like to try
                https://tinyurl.com/disablehdmi if you need analog sound.
                If sound too difficult to setup
                run $ abe --nosound
               
                $ abe -t # tests video modes available
                If you are not using FM -> desktop files to launch nor
                wbar launchers....try  $ abe 

                GREMLIN, Settings -> space toggle to easy or hard fails for me,
                ditto some other settings. 

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

readelf -d $P/usr/local/bin/$P | grep 'NEEDED' 
 #libSM.so.6]libSM
 #libICE.so.6]libICE
 #libX11.so.6]libX11 libXext libXi
 #libXi.so.6]libXi
 #libXext.so.6]libXext libXi
 #libXmu.so.6]libXmu
 #libSDL-1.2.so.0]sdl
 #libSDL_mixer-1.2.so.0]sdl_mixer
# submitqc reduces deps to 
# ogg file needs libvorbis
echo 'sdl_mixer.tcz
libXi.tcz
sdl.tcz
libXmu.tcz 
libvorbis.tcz ' > $P.tcz.dep

submitqc --libs
rm -rf *.zsync

