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

# error: ‘...’ handler must be the last handler for its try block [-fpermissive]
export CFLAGS="-mtune=generic -Os -pipe"
export CXXFLAGS="-mtune=generic -Os -pipe -fpermissive "

P=zmusic
V=1.3.0
SRC=ZMusic-1.3.0
USER=`cat /etc/sysconfig/tcuser`
LIST="compiletc submitqc cmake alsa-dev glib2-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://github.com/ZDoom/ZMusic/archive/refs/tags/$V.tar.gz
tar xvf $V*gz
cd $SRC
mkdir build && cd build
# cmake -LAH
cmake -DCMAKE_INSTALL_PREFIX=/usr/local -DCMAKE_INSTALL_LIBDIR=/usr/local/lib -DCMAKE_BUILD_TYPE=Release ../
cmake --build . --parallel 6 # 32 seconds
DESTDIR=/tmp/$P make install
cd /tmp

# dev
#####
mkdir -p $P-dev/usr/local/lib
mv $P/usr/local/include $P-dev/usr/local/
mv $P/usr/local/lib/cmake $P-dev/usr/local/lib
# there is no pc file

# main
######
mkdir -p $P/usr/local/share/doc/$P 
cp $SRC/licenses/* $P/usr/local/share/doc/$P/
strip --strip-unneeded $P/usr/local/lib/*


# TCZ them
#######
LIST="$P $P-dev "
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:          zmusic-dev.tcz
Description:    dev files
Version:        1.3.0
Author:         ZMusic Team
Original-site:  https://github.com/ZDoom/ZMusic
Copying-policy: accompanied
Size:           12K
Extension_by:   aus9 
Tags:           game 
Comments:       no pc file needed
                
Change-log:     2026/01/02 v 1.3.0  on 16x
Current:        2026/01/02  '  > $P-dev.tcz.info
echo 'zmusic.tcz
alsa-dev.tcz
glib2-dev.tcz ' > $P-dev.tcz.dep

echo 'Title:          zmusic.tcz
Description:    Music system of gzdoom
Version:        1.3.0
Author:         ZMusic Team
Original-site:  https://github.com/ZDoom/ZMusic
Copying-policy: accompanied
Size:           3.1M
Extension_by:   aus9 
Tags:           game 
Comments:       gzdoom has been replaced by uzdoom
                
Change-log:     2026/01/02 v 1.3.0  on 16x
Current:        2026/01/02  '  > $P.tcz.info
readelf -d $P/usr/local/lib/*.so | grep 'NEEDED'
# libasound.so.2  libasound
# libglib-2.0.so.0 glib2
echo 'libasound.tcz
glib2.tcz ' > $P.tcz.dep

submitqc --libs
rm -rf *.zsync


