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

# non standard build to defeat wbar error

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

P=pipewalker
V=1.1
SRC=/usr/local/share/pipewalker/pipewalker-1.1
USER=`cat /etc/sysconfig/tcuser`
LIST="compiletc submitqc git meson cmake wayland-dev sdl2_image-dev imagemagick"
for Z in $LIST 
    do 
    su -c "tce-load -i $Z" $USER
done

cd /
mkdir -p /usr/local/share/$P
cd /usr/local/share/$P
/usr/local/bin/wget -nc --no-check-certificate \
https://github.com/artemsen/pipewalker/archive/refs/tags/v1.1.tar.gz
tar xvf v*gz
rm -rf v*gz
cd $SRC
mkdir build && cd build 
meson setup -Ddebug=false -Dstrip=true 
# debug: true... strip: true
ninja # seconds 
DESTDIR=/tmp/$P ninja install
cd /tmp

# doc
######
mkdir -p $P-doc/usr/local/share
mv $P/usr/local/share/man $P-doc/usr/local/share

# main
######
mkdir -p $P/usr/local/share/doc/$P 
cp $SRC/LICENSE $P/usr/local/share/doc/$P/COPYING

# deskop stuff
##############
mkdir -p $P/usr/local/share/pixmaps
OLDPNG=$P/usr/local/share/icons/hicolor/64x64/apps/pipewalker.png
NEWPNG=$P/usr/local/share/pixmaps/$P.png
convert $OLDPNG -scale 48x48 $NEWPNG
rm -rf $P/usr/local/share/icons

DESK=$P/usr/local/share/applications/$P.desktop
sed '12d' -i $DESK # deletes keyword line
sed 's|Game;LogicGame;|Applications|' -i $DESK
echo 'X-FullPathIcon=/usr/local/share/pixmaps/pipewalker.png' >> $DESK

# wbar fix
############
# pipewalker was borking unless it found my original pathway to the images and sound files
# so now move that data dir into my PKG
mkdir -p $P/usr/local/share/pipewalker/pipewalker-1.1
mv /usr/local/share/pipewalker/pipewalker-1.1/data $P/usr/local/share/pipewalker/pipewalker-1.1
rm -rf $P/usr/local/share/games # that has the sub files but not the dir=data
# submitqc fixes
chmod 755 $P/usr/local/share/pipewalker/pipewalker-1.1/data
chmod 644 $P/usr/local/share/pipewalker/pipewalker-1.1/data/*

# 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:          pipewalker-doc.tcz
Description:    man page
Version:        1.1
Author:         Artem Senichev 
Original-site:  https://github.com/artemsen/pipewalker
Copying-policy: accompanied
Size:           4.0K
Extension_by:   aus9 @linuxquestions.org
Tags:           game
Comments:       -

Change-log:     2025/12/06 v 1.1 on 16x
Current:        2025/12/06'  > $P-doc.tcz.info 
echo 'man-db.tcz ' > $P-doc.tcz.dep

echo 'Title:          pipewalker.tcz
Description:    game - connect pipes & pcs
Version:        1.1
Author:         Artem Senichev 
Original-site:  https://github.com/artemsen/pipewalker
Copying-policy: accompanied
Size:           744K
Extension_by:   aus9 @linuxquestions.org
Tags:           game
Comments:       Runs on Xorg or wayland. Unable to test
                libX desktops. Setup your sound first. 
                Sound tested for alsa only.
                                       
Change-log:     2025/12/06 v 1.1 on 16x
Current:        2025/12/06'  > $P.tcz.info

readelf -d $P/usr/local/bin/* | grep 'NEEDED'
#[libSDL2-2.0.so.0] sdl2 image
#[libSDL2_image-2.0.so.0] sdl2_image
echo 'sdl2_image.tcz' > $P.tcz.dep

submitqc --libs
rm -rf *.zsync


