#!/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=wl-clipboard
V=2.1.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/bugaevc/$P/archive/refs/tags/v$V.zip " $USER
unzip v$V*zip
cd $SRC
meson setup --prefix=/usr/local -Dstrip=true -Ddebug=false -Dzshcompletiondir=no
# debug           : false
# prefix          : /usr/local
# strip           : true
# zshcompletiondir: no
cd build
ninja # seconds
DESTDIR=/tmp/$P ninja install
cd /tmp

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

mkdir -p $P/usr/local/share/doc/$P
echo 'GPL v3' > $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 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:          wl-clipboard.tcz 
Description:    command tool for WayLand copy or paste 
Version:        2.1.0
Author:         Sergey Bugaev
Original-site:  https://github.com/bugaevc/wl-clipboard
Copying-policy: GPL v3
Size:           32K	
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
Current:        2023/04/24 v 2.1.0 on 14x     ' > $P.tcz.info

readelf -d $P/usr/local/bin/wl* | grep 'NEEDED'
# one duplicate of
# [libwayland-client.so.0] wayland
# [libc.so.6]

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

submitqc --libs
