#!/bin/sh
# test we are root
if [ "$(id -u)" != "0" ]; then
   exit 1
fi

# wxwidgets make error: exception handling disabled, use '-fexceptions
export CFLAGS="-mtune=generic -Os -pipe"
export CXXFLAGS="-mtune=generic -Os -pipe -fexceptions "

P1=wxWidgets
P=wxwidgets
V=3.2.4
SRC=$P1-$V
USER=`cat /etc/sysconfig/tcuser`
LIST="compiletc submitqc gtk3-dev libnotify-dev gst-plugins-base-dev webkitgtk-gtk3-dev \
boost-1.84-dev gspell-dev git"
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/$P1/$P1/archive/refs/tags/v$V.tar.gz "  $USER
tar xvf v$V*gz
cd $SRC
./configure --prefix=/usr/local --localstatedir=/var --disable-tests --disable-debug_flag  \
--with-gtk=3 --with-liblzma  --without-nanosvg

# Which GUI toolkit should wxWidgets use?                 GTK+ 3 with support for GTK+ printing libnotify
# Should wxWidgets be compiled into single library?       no
# Should wxWidgets be linked as a shared library?         yes
# Should wxWidgets support Unicode?                       yes (using wchar_t)
# What level of wxWidgets compatibility should be enabled?
#     wxWidgets 2.8  no
#     wxWidgets 3.0  yes
#  Which libraries should wxWidgets use?
# STL       no
# jpeg      sys
# png       sys
# regex     sys
# tiff      sys
# lzma      sys
# zlib      sys
# expat     sys
# libmspack no
# sdl       no

make -j5 # 4M
make install-strip DESTDIR=/tmp/$P
cd /tmp

# dev
#####
mkdir -p $P-dev/usr/local/lib/pkgconfig
mkdir -p $P-dev/usr/local/lib/wx
mkdir -p $P-dev/usr/local/share
mv $P/usr/local/include $P-dev/usr/local/
mv $P/usr/local/share/aclocal $P-dev/usr/local/share
mv $P/usr/local/lib/wx/include $P-dev/usr/local/lib/wx
# NOTE ..lib/wx/config/gtk3-unicode-3.2 must remain in main TCE otherwise broken sym link 
# dev setup.h contains string #define wxUSE_STL 0

# no locale
rm -rf  $P/usr/local/share/locale

# main
#####
mkdir -p $P/usr/local/share/doc/$P
cp $SRC/docs/licence.txt $P/usr/local/share/doc/$P
strip --strip-unneeded $P/usr/local/lib/*.so*
strip --strip-unneeded $P/usr/local/bin/wxrc-3.2
strip --strip-unneeded $P/usr/local/lib/*.so*
strip --strip-unneeded $P/usr/local/lib/wx/3.2/web-extensions/*.so
# /usr/local/lib/wx/config/gtk3-unicode-3.2 is a script

# pass 1 submitqc fixed
chmod 755 $P/usr/local/share/bakefile/presets/wx_presets.py

# TCZ them
###########
LIST2="$P $P-dev "
for Z in $LIST2
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
done

ls -hal

echo 'Title:          wxwidgets-dev.tcz
Description:    dev files
Version:        3.2.4
Author:         wxWidgets Team
Original-site:  https://github.com/wxWidgets/wxWidgets/
Copying-policy: see licence.txt
Size:           2.1M          
Extension_by:   aus9 @linuxquestions.org
Tags:           gui gtk+ gtk3
Comments:       Development
                
Change-log:     2017/10/16 v 3.0.3 (Juanito)
                2019/10/03 v 3.0.4 on 10x 
Current:        2024/05/13 v 3.2.4 on 15x (aus9)  ' > $P-dev.tcz.info   

echo 'wxwidgets.tcz
gtk3-dev.tcz
libnotify-dev.tcz 
gst-plugins-base-dev.tcz  
webkitgtk-gtk3-dev.tcz 
boost-1.84-dev.tcz 
gspell-dev.tcz
git.tcz                        ' > $P-dev.tcz.dep

# Repo has glu-dev but depends -> tiff-dev -> gdk-pixbuf2-dev -> gtk3-dev

echo 'Title:          wxwidgets.tcz
Description:    c++ gui framework
Version:        3.2.4
Author:         wxWidgets Team
Original-site:  https://github.com/wxWidgets/wxWidgets/
Copying-policy: https://github.com/wxWidgets/wxWidgets/blob/master/docs/licence.txt
Size:           5.6M           
Extension_by:   aus9 @linuxquestions.org
Tags:           gui gtk+ gtk3
Comments:       c++ framework for advanced gui applications using native controls
                
Change-log:     2017/10/16 v 3.0.3 (Juanito)
                2019/10/03 v 3.0.4 on 10x 
Current:        2024/05/13 v 3.2.4 on 15x (aus9)                     ' > $P.tcz.info

readelf -d $P/usr/local/bin/wxrc-3.2 | grep 'NEEDED' # ignore TCBs
#libwx_baseu_xml-3.2.so.0]libwx_baseu-3.2.so.0]this TCE
#libexpat.so.1]expat2 -> fontconfig -> cairo -> pango -> gtk3 (found below)
#libsecret-1.so.0] libsecret -> webkitgtk-gtk3 (below)
#libgio-2.0.so.0]libgobject-2.0.so.0]libglib-2.0.so.0]glib2 -> cairo -> pango -> gtk3
#libcurl.so.4]curl
#liblzma.so.5]liblzma -> libtiff -> gdk-pixbuf2 -> gtk3
#libpcre2-32.so.0]pcre21042
readelf -d $P/usr/local/lib/*.so | grep 'NEEDED' # ignore dupes
#libgtk-3.so.0]#libgdk-3.so.0]gtk3
#libpangocairo-1.0.so.0]libpango-1.0.so.0]libpangoft2-1.0.so.0] pango -> gtk3
#libharfbuzz.so.0]harfbuzz -> freetype -> fontconfig -> cairo -> pango -> gtk3
#libatk-1.0.so.0]at-spi2-core -> gtk3
#libcairo-gobject.so.2]libcairo.so.2]cairo -> pango -> gtk3
#libgdk_pixbuf-2.0.so.0]gdk-pixbuf2 -> gtk3
#libgthread-2.0.so.0]glib2 -> cairo -> pango -> gtk3
#libX11.so.6]libX11 -> cairo -> pango -> gtk3
#libXxf86vm.so.1]libXxf86vm ->  libGL -> libEGL (below)
#libSM.so.6]libSM
#libxkbcommon.so.0]libxkbcommon -> gtk3
#libgspell-1.so.2]gspell
#libenchant-2.so.2]enchant2 -> gspell
#libnotify.so.4]libnotify
#libXtst.so.6]libXtst -> at-spi2-core -> gtk3
#libfontconfig.so.1]fontconfig -> cairo -> pango -> gtk3
#libfreetype.so.6]freetype -> fontconfig -> cairo -> pango -> gtk3
#libpng16.so.16]libpng -> cairo -> pango -> gtk3
#libjpeg.so.62]libjpeg-tubo -> libtiff -> gdk-pixbuf2 -> gtk3
#libtiff.so.5]libtiff -> gdk-pixbuf2 -> gtk3
#libwx_gtk3u_core-3.2.so.0] this TCE
#libGL.so.1]libGL -> libEGL
#libGLU.so.1]glu 
#libEGL.so.1]libEGL
#libwayland-egl.so.1]libwayland-client.so.0]wayland -> libEGL
#libgstplayer-1.0.so.0] gst-plugins-bad 
#libgstvideo-1.0.so.0]  gst-plugins-base.tcz -> gst-plugins-bad
#libgstbase-1.0.so.0]libgstreamer-1.0.so.0] gstreamer -> gst-plugins-base -> gst-plugins-bad
#libwx_gtk3u_html-3.2.so.0]#libwx_baseu_xml-3.2.so.0]#libwx_gtk3u_core-3.2.so.0]#libwx_baseu-3.2.so.0] this TCE
#libjavascriptcoregtk-4.1.so.0]webkitgtk-gtk3.tcz
readelf -d $P/usr/local/lib/wx/3.2/web-extensions/*.so | grep 'NEEDED' # ignore dupes
#libwebkit2gtk-4.1.so.0 -> webkitgtk-gtk3 
#libsoup-3.0.so.0]libsoup3

# pass 1 submitqc adds libXt.tcz
echo 'gtk3.tcz
webkitgtk-gtk3.tcz
curl.tcz
pcre21042.tcz
libEGL.tcz
libSM.tcz
gspell.tcz
libnotify.tcz
glu.tcz
gst-plugins-bad.tcz
libsoup3.tcz 
libXt.tcz        ' > $P.tcz.dep

# pass 1 for errors
submitqc --libs
rm -rf *.zsync

