#!/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=wl-clipboard
V=2.2.1
SRC=$P-$V
USER=`cat /etc/sysconfig/tcuser`
LIST="compiletc submitqc meson wayland-dev wayland-protocols-dev cmake "
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/bugaevc/$P/archive/refs/tags/v$V.tar.gz " $USER
tar xvf  v$V*gz
cd $SRC
# leaping ahead....no option in meson configure build > /tmp/configure to disable FISH
meson setup --prefix=/usr/local -Dstrip=true -Ddebug=false -Dzshcompletiondir=no -Dfishcompletiondir=no -Dbuildtype=plain build
# debug           : false
# zshcompletiondir: no
# prefix          : /usr/local
# strip           : true
# zshcompletiondir : no

cd build
ninja # seconds
DESTDIR=/tmp/$P ninja install
cd /tmp

# main
######
# unable to disable man pages 
rm -rf $P/usr/local/share/man

mkdir -p $P/usr/local/share/doc/$P
echo 'GPL v 3' > $P/usr/local/share/doc/$P/COPYING

# TCZ them
#######
LIST="$P "
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:          wl-clipboard.tcz 
Description:    command tool for wayland copy or paste 
Version:        2.2.1
Author:         Sergey Bugaev
Original-site:  https://github.com/bugaevc/wl-clipboard
Copying-policy: GPL v3
Size:           36K	
Extension_by:   aus9 
Tags:           wayland clipboard 
Comments:       Wayland copy and paste command line tool
                
                Usage link
                https://github.com/bugaevc/wl-clipboard
                 
Change-log:     2019/06/17 v 1.0.0 on 10x  
                2020/07/10 v 2.0.0 on 11x
                2023/04/24 v 2.1.0 on 14x  
Current:        2025/03/14 v 2.2.1 on 16x    ' > $P.tcz.info

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

echo 'wayland.tcz' > $P.tcz.dep

submitqc --libs
rm -rf *.zsync


