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

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

P=wlr-randr
V=0.2.0
SRC=$P-$V
USER=`cat /etc/sysconfig/tcuser`
LIST="compiletc submitqc meson wayland-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/emersion/$P/releases/download/v$V/$SRC.tar.gz " $USER
tar xvf $SRC*gz
cd $SRC
mkdir build && cd build
meson setup --prefix=/usr/local -Ddebug=false -Dstrip=true
# wlr-randr 0.2.0
# User defined options
# debug : false
# prefix: /usr/local
# strip : true
ninja  # 1 second
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/

# TCE
#######
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:          wlr-randr.tcz 
Description:    wayland tool similar to xrandr 
Version:        0.2.0
Author:         wlr-randr Team
Original-site:  https://github.com/emersion/wlr-randr
Copying-policy: Accompanied 
Size:           12K	
Extension_by:   aus9 @linuxquestions.org 
Tags:           wayland randr 
Comments:       $ wlr-randr # reveals output string
                $ wlr-randr --help
(eg)            $ wlr-randr --output HDMI-A-1 --custom-mode 1600x900

                sway TCE sets most things in its config
 
Change-log:     2024/03/30 v 0.2.0 on 15x
Current:        2024/03/30       ' > $P.tcz.info

readelf -d $P/usr/local/bin/$P | grep 'NEEDED'  
# [libwayland-client.so.0]wayland
echo 'wayland.tcz' > $P.tcz.dep

submitqc --libs
rm -rf *.zsync
