#!/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"
# REFERENCES ......https://wiki.archlinux.org/title/JWM mainly for $ jwm -p

P=jwm-full
V=2.4.6
SRC1=jwm-$V
SRC2=squashfs-root
USER=`cat /etc/sysconfig/tcuser`
LIST="compiletc submitqc libjpeg-turbo-dev libpng-dev libXmu-dev libXft-dev libXinerama-dev \
libXpm-dev pango-dev librsvg-dev gettext-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://github.com/joewing/jwm/releases/download/v$V/jwm-$V.tar.xz \
http://tinycorelinux.net/15.x/x86_64/tcz/jwm-full.tcz "  $USER
unsquashfs jwm-full.tcz
rm -rf jwm-full.tcz
######################## + svg support

tar xvf jwm-$V*xz
cd $SRC1
./configure --prefix=/usr/local --with-libintl-prefix=/usr/local 
# Confirm:  yes
# Icon:     yes
# Cairo:    yes
# RSVG:     yes
# PNG:      yes
# JPEG:     yes
# XBM:      yes
# XPM:      yes
# XFT:      yes
# XRender:  yes
# Pango:    yes
# Shape:    yes
# Xmu:      yes
# Xinerama: yes
# Debug:    no
make -j4  # 5s 
make install DESTDIR=/tmp/$P # strip fails
cd /tmp

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

# locale
#########
mkdir -p $P-locale/usr/local/share
mv $P/usr/local/share/locale $P-locale/usr/local/share

# main
#####

# Bin
######
strip --strip-unneeded $P/usr/local/bin/jwm
cp $SRC2/usr/local/bin/jwm_* $P/usr/local/bin
# even tho unpacked as root they became tc:staff fix
chown root:root $P/usr/local/bin/*
rm -rf $P/usr/local/bin/jwm_ondemand # has issue as per discovered by $ jwm -p

# Minor bin fixes
##########
sed 's|jwm_ondemand||' -i $P/usr/local/bin/jwm_initmenu 
sed 's|aterm|xterm|' -i   $P/usr/local/bin/jwm_menu_common 
# I will now ignore altering /usr/local/etc/system.jwmrc

# add important roberts files but some need adjusting so some clean create
########################################################
mkdir -p $P/usr/local/share/jwm/tce
cp $SRC2/usr/local/share/jwm/tce/menu* $P/usr/local/share/jwm/tce/
cp $SRC2/usr/local/share/jwm/tce/.jwm* $P/usr/local/share/jwm/tce/

# update tray
##############
# 15x tray is already good tweak it further
TRAY=$P/usr/local/share/jwm/tce/.jwmrc-tray 
sed '16,17d' -i $TRAY # delete services and screenshot as they are ugly with no proper icon
sed '14d' -i $TRAY  # delete flrun 
sed '12d' -i $TRAY # delete "basic" editor

# update keys
############# 15x keys already good tweak it....
KEYS=$P/usr/local/share/jwm/tce/.jwmrc-keys
sed 's|leafpad|l3afpad|' -i $KEYS
# below frees up R as Z unlikely used by members 
sed 's|"r"|"z"|' -i $KEYS
# A + End is better than A + e so free up e
sed '38d' -i $KEYS

# update jwmrc
#############
RC=$P/usr/local/share/jwm/tce/.jwmrc
sed 's|pcmanfm|aterm|' -i $RC
sed 's|4|5|' -i $RC  # this changes first found 4 workspaces -> 5

mkdir -p $P/usr/local/share/doc/$P
cp $SRC1/LICENSE $P/usr/local/share/doc/$P

# tce.install
############# 
mkdir -p $P/usr/local/tce.installed
cat >> $P/usr/local/tce.installed/$P <<'EOF'
#!/bin/sh
echo 'jwm' > /etc/sysconfig/desktop
EOF
chown -R root:staff $P/usr/local/tce.installed
chmod -R 775 $P/usr/local/tce.installed

# TCZ them
###########
LIST2="$P $P-doc $P-locale  "
for Z in $LIST2
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:          jwm-full-doc.tcz
Description:    man page
Version:        2.4.6
Author:         Joe Wingbermuehle
Original-site:  http://joewing.net/projects/jwm
Copying-policy: accompanied
Size:           16K
Extension_by:   aus9 @linuxquestions.org   
Tags:           window manager 
Comments:       see also
                http://joewing.net/projects/jwm/config.html
                http://joewing.net/projects/jwm/guide.html

Change-log:     2024/11/08 v 2.4.5 on 15x too many to list here
Current:        2025/03/30 v 2.4.6 on 16x, some keys now use Alt, + svg support" > $P-doc.tcz.info
echo 'man-db.tcz' > $P-doc.tcz.dep 

echo "Title:          jwm-full-locale.tcz
Description:    language files
Version:        2.4.6
Author:         Joe Wingbermuehle
Original-site:  http://joewing.net/projects/jwm
Copying-policy: accompanied
Size:           52K
Extension_by:   aus9 @linuxquestions.org   
Tags:           window manager 
Comments:       not tested by me

Change-log:     2024/11/08 v 2.4.5 on 15x, too many to list here 
Current:        2025/03/30 v 2.4.6 on 16x, some keys now use Alt, + svg support" > $P-locale.tcz.info
echo 'jwm-full.tcz' > $P-locale.tcz.dep

echo "Title:          jwm-full.tcz
Description:    Joe's Window Manager 
Version:        2.4.6
Author:         Joe Wingbermuehle
Original-site:  http://joewing.net/projects/jwm
Copying-policy: accompanied
Documentation:  http://joewing.net/projects/jwm/config.shtml
Size:           116K
Extension_by:   aus9 @linuxquestions.org   
Tags:           window manager 
Comments:       JWM is a floating desktop, that supports workspaces. 
                Includes some scripts (c) Robert Shingledecker. 
                Ondemand support removed due to errors seen in $ jwm -p
                On my AMD APU I needed Xorg 2 or 3d
                                                 
                Before making changes, backup target file...make changes then run $ jwm -p 
                If needed, fix -> restart jwm from menu -> re-run $ jwm -p
                                    
                Optional TCEs
                jwm-themes, xfontsel
                lxde-icon-theme  if you add new tray launchers
                volumeicon but you may need to change color of its tray icon if you are using a 
                ......a dark theme like skeuos-gtk-themes

Change-log:     2014/12/01 v 2.2.2  on 5x  (maluvia)
                2024/11/08 v 2.4.5 on 15x, changes listed in 15x comments as many changes  -svg support (aus9)
Current:        2025/03/30 v 2.4.6 on 16x, some keys now use Alt,  + svg support" > $P.tcz.info

readelf -d $P/usr/local/bin/jwm | grep 'NEEDED' 
#libX11.so.6]libX11 libXext libXinerama
#libpng16.so.16]libpng freetype fontconfig libXft pango librsvg
#librsvg-2.so.2 librsvg
#libgio-2.0.so.0libgobject-2.0.so.0 libglib-2.0.so.0 glib2 harfbuzz freetype fontconfig libXft pango librsvg
#libgdk_pixbuf-2.0.so.0] gdk-pixbuf2 librsvg
#libcairo.so.2] cairo  pango librsvg
#libjpeg.so.62]libjpeg-turbo......librsvg
#libXft.so.2]libXft pango librsvg
#libXrender.so.1]libXrender libXft pango librsvg
#[libpangoxft-1.0.so.0]libpangoft2-1.0.so.0]libpango-1.0.so.0]pango librsvg
#libharfbuzz.so.0]harfbuzz freetype fontconfig libXft pango librsvg
#libfontconfig.so.1]fontconfig libXft pango librsvg
#libfreetype.so.6]freetype fontconfig libXft pango librsvg
#libXpm.so.4]libXpm
#libXext.so.6]libXext libXinerama
#libXmu.so.6]libXmu
#libXinerama.so.1]libXinerama

# comparing to jwm.tcz  it has a dep of fribidi but its not showing up above? 

echo 'libXinerama.tcz
librsvg.tcz
libXpm.tcz
libXmu.tcz
' > $P.tcz.dep

submitqc --libs  # submit wants a newline end of main dep
rm -rf *.zsync

