#!/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 "
 
P=dmenu
V=5.3
SRC=$P-$V
USER=`cat /etc/sysconfig/tcuser`
LIST="compiletc submitqc wayland-dev libX11-dev libXft-dev libXinerama-dev freetype-dev "
for Z in $LIST 
    do 
    su -c "tce-load -i $Z" $USER
done

URL=https://tools.suckless.org/dmenu/patches
cd /tmp
su -c "/usr/local/bin/wget -nc --no-check-certificate \
https://dl.suckless.org/tools/$SRC.tar.gz  \
$URL/center/dmenu-center-5.2.diff " $USER
tar xvf $SRC*gz
cd $SRC

# fix pathways
sed 's|X11R6/include|local/include/X11|' -i config.mk
sed 's|X11R6/lib|local/lib|' -i config.mk
sed 's|include/freetype2|local/include/freetype2|' -i config.mk

# apply patches
patch <../dmenu-center-5.2.diff

make -j5 # seconds
make install DESTDIR=/tmp/$P
cd /tmp

# no doc
######
rm -rf $P/usr/local/share/man 

# main
######
mkdir -p $P/usr/local/share/doc/$P
cp $SRC/LICENSE  $P/usr/local/share/doc/$P/

strip --strip-unneeded $P/usr/local/bin/$P
strip --strip-unneeded $P/usr/local/bin/stest

# 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:          dmenu.tcz   
Description:    Dynamic Menu Launcher for X or wayland
Version:        5.3
Author:         Hiltjo Posthuma
Original-site:  https://tools.suckless.org/dmenu/
Copying-policy: accompanied
Size:           20K
Extension_by:   aus9 
Tags:           launcher menu
Comments:       A tool that can search executables on X 
                or wayland compositors. When active, you type a 
                command and it attempts to launch the highlighted entry 
                when you press the Enter key. Search is exact spelling 
                but not all letters needed.
                Can search pathway $HOME/.local/bin

                Lets type exit gives 2 selections exitcheck.sh and exittc
                If you press the TAB key you are selecting the hightlighted item
                which in example =  exitcheck.sh and exittc disappears
                Therefore avoid using the TAB key.  If you press -> arrow key,
                you can choose to highlight a different selection choice.
                If exitcheck.sh is your target (its already highlighted) 
                press enter. Otherwise type more letters eg exitt...
                to get one selection or use arrow keys to hightlight it.

                If your desktop allows it, create a keyboard  (KB) shortcut
                If you change your mind, or mis-type....press Escape key
                to exit dmenu. While dmenu is active, you can not use KB shortcuts.

                If your search input is for a non-executable (eg) zzz
                you lose all hits and if you forget to Escape and press enter 
                you are launching a missing executable called zzz and will get
                a not found error. 

                How to run on X (tested on jwm-full)
                ###############
                $ dmenu_run 
                For a large font eg
                $ dmenu_run -fn sans-20
 
                How to run on Sway
                ##################
                Press keys logo (and) d to start dmenu
                Follow above for the rest.

                How to run on labwc or weston
                #########################
                Same as X unless you have a launcher icon on weston
                
                Possible Glitches
                #################
                On flwm, dmenu may cover any open app that is
                at the top of your monitor. So to close an app,
                you may have to either launch an app or press escape,
                while dmenu active.
                You can safely ignore any msg about
                /home/<name>/.cache/dmenu_run: No such file or directory
                that file is created, after first run is complete
                                
Change-log:     2018/07/26 Original 4.8 on 9x 
                2020/06/28 v 4.9 on 11x
                2023/03/15 v 5.2 on 14x 
                2023/11/01 recompiled with center patch for -c option (GNUser)
Current:        2025/03/14 v 5.3 on 16x  (aus9) ' > $P.tcz.info

readelf -d $P/usr/local/bin/$P | grep 'NEEDED'
# libX11.so.6]   libX11    libXinerama  
# libXinerama.so.1]   libXinerama
# libfontconfig.so.1] fontconfig  -> libXft
# libXft.so.2]   libXft

echo 'libXinerama.tcz
libXft.tcz ' > $P.tcz.dep

submitqc --libs
rm -rf *.zsync

#$ test tab key...dot local bin
