#!/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=fuzzel
V=1.13.1
SRC=$P-src
USER=`cat /etc/sysconfig/tcuser`
LIST="compiletc submitqc cmake fontconfig-dev git libxkbcommon-dev meson \
pixman-dev scdoc-dev wayland-dev wayland-protocols-dev    " 
for Z in $LIST 
    do 
    su -c "tce-load -i $Z" $USER
done

cd /tmp
/usr/local/bin/wget -nc --no-check-certificate \
https://codeberg.org/dnkl/$P/archive/$V.tar.gz
tar xvf $V*gz
mv $P $SRC
cd $SRC
mkdir build && cd build
meson setup --prefix=/usr/local -Dbuildtype=plain -Ddebug=false -Dsvg-backend=none \
-Dsystem-nanosvg=disabled -Denable-cairo=disabled -Dstrip=true
# -Ddocs=disabled does not work for me

# fcft 3.3.3
# OT-SVG backend   : nanosvg (bundled)
#    Grapheme shaping : YES
#    Run shaping      : NO
#    Test text shaping: NO
#    Documentation    : NO
# fuzzel 1.13.1
#    Cairo         : NO
#    PNG icons     : libpng
#    SVG icons     : none
#
#  Subprojects
#    fcft          : YES
#    tllist        : YES
#  User defined options
#    buildtype     : plain
#    debug         : false
#    enable-cairo  : disabled 
#    prefix        : /usr/local
#    strip         :true
#    svg-backend   : none
#    system-nanosvg: disabled
# meson configure > /tmp/configure
ninja #  3 seconds
DESTDIR=/tmp/$P ninja install
cd /tmp

# main
######
cd $P/usr/local/share
rm -rf doc fish man zsh
cd /tmp
mkdir -p $P/usr/local/share/doc/$P
cp $SRC/LICENSE $P/usr/local/share/doc/$P/

# tce.install
############# 
mkdir -p $P/usr/local/tce.installed 
echo '#!/bin/sh
USER=`cat /etc/sysconfig/tcuser`
DIR=/home/$USER/.config/fuzzel && FILE=$DIR/fuzzel.ini && SRC=/usr/local/etc/xdg/fuzzel/fuzzel.ini
[ -d $DIR ]  || mkdir -p $DIR
[ -f $FILE ] || cp $SRC $DIR/ && chmod 644 $FILE && chown -R $USER:staff $DIR
  ' > $P/usr/local/tce.installed/$P 
chown -R root:staff $P/usr/local/tce.installed
chmod -R 775 $P/usr/local/tce.installed

# 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:          fuzzel.tcz 
Description:    wlroots Applications launcher with fuzzy search
Version:        1.13.1
Author:         Daniel Eklöf
Original-site:  https://codeberg.org/dnkl/fuzzel
Copying-policy: Accompanied 
Size:           144K
Extension_by:   aus9 
Tags:           wlroots launcher fuzzy
Comments:       Install creates config at ~/.config/fuzzel/fuzzel.ini
                Add font TCEs if you do not like monospace
                Supports hicolor icon set in results
                This TCE mainly searches for *.desktop under
                /usr/local/share/applications so not a full
                launcher like dmenu or wofi This acts more like
                context menu to bring up Applications on libX/Xorg

                Launch from a terminal. You might see the 
                app you want to launch without searching
                -> Either mouse click to launch it OR
                use arrows to highlight line and press enter
                Otherwise start typing your search term
                if nothing found suits you -> press Esc to quit
                If searching is giving only one result, no need
                to complete typing the full word just press enter

                Does not work on woodland

Change-log:     2026/01/09 v 1.13.1 on 17x
Current:        2026/01/09 ' > $P.tcz.info

readelf -d $P/usr/local/bin/$P | grep 'NEEDED'
#libpixman-1.so.0]pixman
#libfontconfig.so.1]fontconfig
#libfreetype.so.6]freetype fontconfig
#libpng16.so.16]libpng freetype fontconfig
#libwayland-client.so.0]#libwayland-cursor.so.0]wayland
#libxkbcommon.so.0]libxkbcommon
#libharfbuzz.so.0]harfbuzz fontconfig

# config uses hicolor

echo 'hicolor-icon-theme.tcz
pixman.tcz
fontconfig.tcz
wayland.tcz
libxkbcommon.tcz ' > $P.tcz.dep

submitqc --libs
rm -rf *.zsync


