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

export CFLAGS="-mtune=generic -Os -pipe"
export CXXFLAGS="-mtune=generic -Os -pipe -fexceptions "

P=wofi
SRC=$P-git
USER=`cat /etc/sysconfig/tcuser`
LIST="compiletc submitqc meson cmake gtk3-dev mercurial "
for Z in $LIST 
    do 
    su -c "tce-load -i $Z" $USER
done

cd /tmp
su -c "hg clone https://hg.sr.ht/~scoopta/wofi " $USER
mv $P $SRC
cd $SRC
rm -rf build # helps if missing things check
meson setup --prefix=/usr/local -Dstrip=true -Ddebug=false  build
# wofi hg
# debug : false
# prefix: /usr/local
# strip : true
cd build
ninja  # 5 seconds
DESTDIR=/tmp/$P ninja install
cd /tmp

# dev
####
mkdir -p $P-dev/usr/local
mv $P/usr/local/include $P-dev/usr/local/
mv $P/usr/local/lib $P-dev/usr/local

# doc
#####
mkdir -p $P-doc/usr/local/share
mv $P/usr/local/share/man $P-doc/usr/local/share

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

# TCZ them
#######
LIST="$P $P-dev $P-doc "
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:          wofi-dev.tcz 
Description:    dev files
Version:        git-20241010
Author:         scoopta
Original-site:  https://hg.sr.ht/~scoopta/wofi
Copying-policy: GPL v 3
Size:           4.0K		
Extension_by:   aus9 @linuxquestions.org 
Tags:           wayland launcher wlroots
Comments:       May be needed if you wish to develop 
                third party modes
                see $ man wofi.3
              
Change-log:     2024/10/10 v git-20241010 on 15x
Current:        2024/10/10  ' > $P-dev.tcz.info
echo 'wofi.tcz
gtk3-dev.tcz ' > $P-dev.tcz.dep

echo 'Title:          wofi-doc.tcz 
Description:    many man pages
Version:        git-20241010
Author:         scoopta
Original-site:  https://hg.sr.ht/~scoopta/wofi
Copying-policy: GPL v 3
Size:           28K		
Extension_by:   aus9 @linuxquestions.org 
Tags:           wayland launcher wlroots
Comments:       $ man wofi is for main executable
                $ man wofi.<number> for some that share wofi name
                eg man.3 wofi.5 wofi.7
                See the list for other man pages.
              
Change-log:     2024/10/10 v git-20241010 on 15x
Current:        2024/10/10  ' > $P-doc.tcz.info
echo 'man-db.tcz' > $P-doc.tcz.dep

echo 'Title:          wofi.tcz 
Description:    wlroots based launcher
Version:        git-20241010
Author:         scoopta
Original-site:  https://hg.sr.ht/~scoopta/wofi
Copying-policy: GPL v 3
Size:           44K		
Extension_by:   aus9 @linuxquestions.org 
Tags:           wayland launcher wlroots
Comments:       For labwc or sway  - 3 built in modes

                run  - searches $PATH for executables and allows them 
                       to be run by selecting them.
                drun - searches $XDG_DATA_HOME/applications and 
                       $XDG_DATA_DIRS/applications for desktop files and 
                       allows them to be run by selecting them.
                dmenu - reads from stdin and displays options which when selected 
                        will be output to stdout.
                        Unable to get third mode working YMMV

                $ wofi -S run   -> displays a list of executables without needing dmenu
                $ wofi -S drun  -> displays desktop file executables without showing icons  
                $ wofi -S drun  -I  -> displays desktop executables and their icons # that I for India 

                While wofi (popup) is open, keyboard locked to wofi until you 
                press Escape key to exit wofi OR arrow down to a selection and 
                press enter to launch your selection OR type in search box, a 
                command which reduces display of results, press enter against that selection.

                Normal search are case sensitive even if -M=fuzzy used.
                eg input le, results include leafpad, less, filetool.sh
                eg input LE -> no results even if fuzzy used
              
Change-log:     2024/10/10 v git-20241010 on 15x
Current:        2024/10/10  ' > $P.tcz.info

readelf -d $P/usr/local/bin/$P | grep 'NEEDED'
# libgtk-3.so.0]#libgdk-3.so.0] gtk3 
# libpango-1.0.so.0] pango -  gtk3
# libcairo.so.2 cairo - pango -  gtk3
# libgdk_pixbuf-2.0.so.0 gdk-pixbuf2-  gtk3
# libgio-2.0.so.0]#libgobject-2.0.so.0]#libglib-2.0.so.0]glib2
# libwayland-client.so.0] wayland

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

submitqc --libs
rm -rf *.zsync

