#!/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 CXXFLAGS="-mtune=generic -Os -pipe -fno-exceptions -fno-rtti"

P=grim
V=1.4.1
SRC=$P-$V
USER=`cat /etc/sysconfig/tcuser`
LIST="compiletc submitqc meson wayland-dev pixman-dev libjpeg-turbo-dev libpng-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://git.sr.ht/~emersion/$P/refs/download/v$V/$SRC.tar.gz   " $USER
tar xvf $SRC.*gz
cd $SRC

meson setup --prefix=/usr/local -Dstrip=true -Ddebug=false -Dman-pages=disabled build 
# debug : false
# prefix: /usr/local
# strip : true
# man-pages: disabled
ninja -C build # seconds
cd build
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:          grim.tcz 
Description:    GRab IMages on wayland desktops 
Version:        1.4.1
Author:         emersion
Original-site:  https://sr.ht/~emersion/grim/
Copying-policy: Accompanied 
Size:           16K
Extension_by:   aus9 @linuxquestions.org
Tags:           wayland screen capture
Comments:       screenshot app limited to its current terminal and 
                can only be used on wayland desktops 
                Better still see TCE=slurp 
                grim is a dep of slurp

                Usage: grim -h
                default images go to $HOME/Pictures
                  
                online how to use
                https://git.sr.ht/~emersion/grim
                                               
Change-log:     2019/06/16 v 1.2.0 on 10x 
                2020/07/02 v 1.3.0 on 11x
                2023/04/22 v 1.4.0 on 14x
Current:        2024/03/31 v 1.4.1 on 15x      ' > $P.tcz.info

readelf -d $P/usr/local/bin/$P | grep 'NEEDED'
#[libpixman-1.so.0] pixman
#[libpng16.so.16] libpng
#[libwayland-client.so.0] wayland
#[libjpeg.so.62] libjpeg-turbo

echo 'pixman.tcz
libpng.tcz
wayland.tcz
libjpeg-turbo.tcz ' > $P.tcz.dep

submitqc --libs
rm -rf *.zsync

