#!/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 -fno-exceptions -fno-rtti"

P=jgmenu
V=4.7.0
SRC=$P-$V
USER=`cat /etc/sysconfig/tcuser`
LIST="compiletc submitqc libX11-dev libXrandr-dev pango-dev libxml2-dev "
    for Z in $LIST
    do 
    su -c "tce-load -i $Z" $USER
done

cd /tmp
rm -rf *.gz # make sure no others exist
rm -rf *.sh # we moving a sh here....make sure no others exist
/usr/local/bin/wget -nc --no-check-certificate \
https://github.com/$P/$P/archive/refs/tags/v$V.tar.gz
tar xvf v*gz
cd $SRC
./configure --prefix=/usr/local --disable-svg 
#[ OK ] pkg-config...[ OK ] x11...[ OK ] xrandr...[ OK ] cairo..[ OK ] pango...[ OK ] pangocairo..[ OK ] glib-2.0
find . -name Makefile -type f -exec sed -i 's/-g -O2//g' {} \;
make -j6 # 3 seconds
make install DESTDIR=/tmp/$P # install-strip failes
cd /tmp

# doc 
##########
mkdir -p $P-doc/usr/local/share
mv $P/usr/local/share/man $P-doc/usr/local/share/
rm -rf $P-doc/usr/local/share/man/man1/jgmenu-pmenu.1 # pmenu not built needs python
rm -rf $P-doc/usr/local/share/man/man1/jgmenu-lx.1    # lx not built needs lxmenu

# main
#######
rm -rf $P/usr/local/lib/jgmenu/*.py # python not a dep
rm -rf $P/usr/local/lib/jgmenu/jgmenu-lx # lxmenu not built
rm -rf $P/usr/local/lib/jgmenu/*.py # python not a dep
rm -rf $P/usr/local/lib/jgmenu/jgmenu-themes.sh # gtktheme not compiled

# TWO strips
##############
# prepare to strip move sh out then back in afterwards....bin has only sh so leave it and do full command
DIR=$P/usr/local/lib/jgmenu/
mv $DIR/*.sh /tmp
strip --strip-unneeded $DIR/*
mv *.sh $DIR/
strip --strip-unneeded $P/usr/local/bin/$P

# CONTINUE
rm -rf $P/usr/local/share/applications $P/usr/local/share/icons
mkdir -p $P/usr/local/share/doc/$P
echo 'GPL v 2' > $P/usr/local/share/doc/$P/COPYING

# jgmenurc and pointer
######################
mkdir -p $P/usr/local/share/$P/files
echo '#!/bin/sh
jgmenu --at-pointer ' > $P/usr/local/share/$P/files/pointer
chmod 755 $P/usr/local/share/$P/files/pointer

echo '# verbosity = 0
stay_alive = 0
# persistent = 0
# hide_on_startup = 0
# csv_cmd = apps
# tint2_look = 0
# position_mode = fixed
# edge_snap_x = 30
# terminal_exec = x-terminal-emulator
# terminal_args = -e
# monitor = 0
# hover_delay = 100
# hide_back_items = 1
# columns = 1
# tabs = 120
# menu_margin_x = 0
# menu_margin_y = 0
# menu_width = 200
# menu_height_min = 0
# menu_height_max = 0
# menu_height_mode = static
# menu_padding_top = 5
# menu_padding_right = 5
# menu_padding_bottom = 5
# menu_padding_left = 5
# menu_radius = 1
# menu_border = 0
# menu_halign = left
# menu_valign = bottom
# menu_gradient_pos = none
# sub_spacing = 1
# sub_padding_top = auto
# sub_padding_right = auto
# sub_padding_bottom = auto
# sub_padding_left = auto
# sub_hover_action = 1
# item_margin_x = 3
# item_margin_y = 3
# item_height = 25
# item_padding_x = 4
# item_radius = 1
# item_border = 0
# item_halign = left
# sep_height = 5
# sep_halign = left
# sep_markup = 
# font = 
# font_fallback = xtg
# icon_size = 22
# icon_text_spacing = 10
# icon_norm_alpha = 100
# icon_sel_alpha = 100
# icon_theme = 
# icon_theme_fallback = xtg
# arrow_string = ▸
# arrow_width = 15
# search_empty_string = &lt;empty&gt;
# search_markup = 
# color_menu_bg = #000000 100
# color_menu_bg_to = #000000 100
# color_menu_border = #eeeeee 8
# color_norm_bg = #000000 00
# color_norm_fg = #eeeeee 100
# color_sel_bg = #ffffff 20
# color_sel_fg = #eeeeee 100
# color_sel_border = #eeeeee 8
# color_sep_fg = #ffffff 20
# color_scroll_ind = #eeeeee 40
# color_title_fg = #eeeeee 50
# color_title_bg = #000000 0
# color_title_border = #000000 0
# csv_name_format = %n (%g)
# csv_single_window = 0
# csv_no_dirs = 0
# csv_i18n = 
# csv_no_duplicates = 0 ' > $P/usr/local/share/$P/files/jgmenurc

# tce.install
############# 
mkdir -p  $P/usr/local/tce.installed
echo '#!/bin/sh
# create config as default was stay alive which IMHO was messy
USER=`cat /etc/sysconfig/tcuser`
DIR1=/home/$USER/.config/jgmenu  && FILE1=$DIR1/jgmenurc && SRC1=/usr/local/share/jgmenu/files/jgmenurc
[ -d $DIR1 ]  || mkdir -p $DIR1  
[ -f $FILE1 ] || cp $SRC1 $DIR1/ && chmod 644 $FILE1 && chown -R $USER:staff $DIR1 

# create wrapper script for either mouse or kb users
DIR2=/home/$USER/.local/bin && FILE2=$DIR2/pointer && SRC2=/usr/local/share/jgmenu/files/pointer
[ -d $DIR2 ]  || mkdir -p $DIR2  
[ -f $FILE2 ] || cp $SRC2 $DIR2/ && chmod 755 $FILE2 && chown -R $USER:staff $DIR2   ' > $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 $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:          jgmenu-doc.tcz
Description:    man pages
Version:        4.7.0
Author:         Johan Malm & contributors
Original-site:  https://github.com/jgmenu/jgmenu
Copying-policy: GPL v 2
Size:           24K
Extension_by:   aus9 @linuxquestions.org
Tags:           menu 
Comments:       Also has a tutorial but note that I crippled
                many extra features to reduce dependencies.

                What does jg mean?
                Johan's Gmenu

Change-log:     2026/10/19 v 4.7.0 on 17x 
Current:        2026/10/19 "  > $P-doc.tcz.info
echo 'man-db.tcz' > $P-doc.tcz.dep

echo 'Title:          jgmenu.tcz
Description:    menu generator for X11, also supports keyboard inputs
                Runs on wayland with xwayland enabled 
Version:        4.7.0
Author:         Johan Malm & contributors
Original-site:  https://github.com/jgmenu/jgmenu
Copying-policy: GPL v 2
Size:           152K
Extension_by:   aus9 @linuxquestions.org
Tags:           menu 
Comments:       Tested on icewm and sway. 
                On first load you get ~/.config/jgmenu/jgmenurc with only stay alive
                turned off by me. This means menu will exit gracefully. 

                How to use 
                ########## KB=keyboard
                menu can be used as a cascading menu = normal or
                by inputting keys which automatically converts to search mode.
                
                On first load you also get ~/.local/bin/pointer command
                
                KB shortcut is easier, I show the terminal command first
                run $ pointer #--- do not press enter yet.
                Move your cursor to a position on the screen you prefer. 
                This will be where the "normal" menu top left hand corner appears.
                Press enter in the terminal -> cascading "normal" menu appears 
                2) If your desktop supports KB shortcuts create an unused one to launch  
                   pointer eg on icewm key "Alt+b" pointer  
                3) If you have a lot of apps loaded, mouse may be faster but you can 
                   go into search mode by typing executable name 
                   Typing unknown value will report empty list
                4) eg inputting cp (for cpanel) brings up one hit=Control Panel
                    but to bring up apps...use pp as inputting ap fails for me. YMMV   

                 KB hints---assuming no mouse detected etc
                 #########
                 However you launch jgmenu, when menu appears, without a mouse you need 
                 to get "focus" into that menu. This how I do it ...press the space key
                 so menu goes into search mode and reports "empty list"
                 (Of course you can start typing the executable name too here)
                 Next press Escape....which takes you from search mode to normal mode.
                 Now you can use down arrow to navigate down thru the menus or 
                 right arrow to peek into each menu and use left arrow to come back
                 If you see your target press enter against it.
                
                 Pressing ESCAPE when you are in "normal" menu mode will exit the menu
                 ... no matter where you are in the menu

Change-log:     2026/10/19 v 4.7.0 on 17x 
Current:        2026/10/19   ' > $P.tcz.info

readelf -d $P/usr/local/bin/* | grep 'NEEDED' 
#libX11.so.6]libX11
#libXrandr.so.2]libXrandr
#libpng16.so.16]libpng
#libpangocairo-1.0.so.0]#libpango-1.0.so.0]pango
#libgobject-2.0.so.0]#libglib-2.0.so.0]glib2
#libharfbuzz.so.0]harfbuzz
#libcairo.so.2] cairo pango


readelf -d $P/usr/local/lib/$P/* | grep 'NEEDED' # ignore sh script errors reported 
# libxml2.so.2 libxml2

echo 'libxml2.tcz
libXrandr.tcz
pango.tcz ' > $P.tcz.dep

submitqc --libs
rm -rf *.zsync

