#!/bin/bash
# test we are root
if [ "$(id -u)" != "0" ]; then
   echo "run as root now exitting"
   exit 1
fi

export CFLAGS="-mtune=generic -Os -pipe"
export CXX="-mtune=generic -Os -pipe -fno-exceptions -fno-rtti"

P=swaybg
V=1.2.1
SRC=$P-$V
USER=`cat /etc/sysconfig/tcuser`
LIST="compiletc squashfs-tools wget cmake meson wayland-dev wayland-protocols-dev cairo-dev gdk-pixbuf2-dev "    
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://github.com/swaywm/$P/releases/download/v$V/$SRC.tar.gz" $USER
tar xvf $SRC*gz
cd $SRC

mkdir build && cd build
meson setup --prefix=/usr/local -Dstrip=true -Ddebug=false -Dgdk-pixbuf=enabled -Dman-pages=disabled
# debug     : false
# gdk-pixbuf: enabled
# man-pages : disabled
# prefix    : /usr/local
# strip     : true
meson configure 
ninja  # seconds
DESTDIR=/tmp/$P ninja install
cd /tmp

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

# TCZ them
#######
LIST="$P  "
for Z in $LIST
do
	mksquashfs $Z $Z.tcz
	md5sum $Z.tcz > $Z.tcz.md5.txt
	cd $Z
	find usr -not -type d > /tmp/$Z.tcz.list
        sed 's|usr|/usr|g' -i /tmp/$Z.tcz.list
	cd /tmp
done

ls -hal

echo 'Title:          swaybg.tcz 
Description:    wallpaper tool for wayland desktops
Version:        1.2.1
Author:         Drew DeVault
Original-site:  https://github.com/swaywm/swaybg
Copying-policy: Accompanied 
Size:           16K		
Extension_by:   aus9 
Tags:           wayland wallpaper background
Comments:       Although used by sway can be used by
                any wayland compositor that supports
                wlr-layer-shell protocol & wl_output version 4.
                  
Change-log:     2023/09/20 v 1.2.0 on 14.x 
Current:        2025/03/12 v 1.2.1  on 16x upstream site changed  ' > $P.tcz.info

readelf -d $P/usr/local/bin/* | grep 'NEEDED' # cull duplicates TCBs
#[libcairo.so.2] cairo 
#[libgdk_pixbuf-2.0.so.0] gdk-pixbuf2
#[libgobject-2.0.so.0]glib2 cairo
#[libwayland-client.so.0]wayland 

echo 'cairo.tcz
gdk-pixbuf2.tcz
wayland.tcz       ' > $P.tcz.dep

submitqc --libs
rm -rf *.zsync




