#!/bin/bash
# test we are root
if [ "$(id -u)" != "0" ]; then
   echo "run as root now exitting"
   exit 1
fi

export CFLAGS="-march=armv8-a+crc -mtune=cortex-a72 -Os -pipe" 
export CXXFLAGS="-march=armv8-a+crc -mtune=cortex-a72 -Os -pipe \
-fno-exceptions -fno-rtti"

P=dmenu
V=5.0
SRC=$P-$V
USER=`cat /etc/sysconfig/tcuser`
LIST="compiletc squashfs-tools wget zsync libX11-dev libXft-dev libXinerama-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://dl.suckless.org/tools/dmenu-5.0.tar.gz " $USER
mkdir $P
tar xvf $SRC*gz
cd $SRC

# fix some pathways for TC
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
make -j5 # seconds
make install 
# make install reveals install pathways
cd /tmp

# main
######
mkdir -p $P/usr/local/share/doc/$P
cp $SRC/LICENSE  $P/usr/local/share/doc/$P/

mkdir -p $P/usr/local/bin
mv /usr/local/bin/$P* $P/usr/local/bin
mv /usr/local/bin/stest $P/usr/local/bin
strip --strip-unneeded $P/usr/local/bin/$P
strip --strip-unneeded $P/usr/local/bin/stest

# no doc
######
rm -rf  /usr/local/share/man/

# 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
        zsyncmake $Z.tcz
done

ls -hal

echo 'Title:          dmenu.tcz 
Description:    Dynamic Menu Launcher for X or Sway
Version:        5.0
Author:         Hiltjo Posthuma
Original-site:  https://tools.suckless.org/dmenu/
Copying-policy: MIT/X Consortium
Size:           16K
Extension_by:   aus9 
Tags:           launcher menu
Comments:       A tool that can search executables on X (or Sway) 
                Then attempts to launch the highlighted entry           
                when you press the Enter key. Search is not a fuzzy but exact.

                How to run on X (tested on jwm)
                ###############
                $ dmenu_run 
                For a large font $ dmenu_run -fn sans-20

                Search bar will appear at top of your monitor
                
                Use arrow keys with numlock OFF to navigate to
                your target command or type more letters

                If you pressed enter, you are attempting to 
                launch the highlighted item and dmenu closes.
                Be aware not all commands are meant to be run 
                without parameters - options etc 

                If you change your mind press the Escape key. 
                While dmenu is active, you lose kb combos.

                If your search input is for a non-executable (eg) "lll" 
                you lose all hits and if you forget to Escape and press enter 
                you are launching a missing executable called "lll" and will get
                a not found error. 
                
                How to run on Sway
                ##################
                Press keys logo (and) d to start dmenu
                Follow above for the rest.
                
                Possible Glitches
                #################
                On fvwm, 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/tc/.cache/dmenu_run: No such file or directory
                ^ that file is created, its a list of executables

                On aarch64 you may need to press return key to 
                get back to prompt
                 
Change-log:     2020/10/04 v 5.0 on 12x
Current:        2020/10/04 ' > $P.tcz.info

