#!/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=genius
V=1.0.27
SRC=$P-$V
USER=`cat /etc/sysconfig/tcuser`
LIST="compiletc submitqc intltool readline-dev mpfr-dev amtk-dev vte-2.91-dev  "
for Z in $LIST
    do 
    su -c "tce-load -i $Z" $USER
done

ln -s /usr/local/include/ncursesw/curses.h /usr/local/include/
ln -s /usr/local/include/ncursesw/term.h /usr/local/include/

cd /tmp
su -c "/usr/local/bin/wget -nc --no-check-certificate \
https://download.gnome.org/sources/$P/1.0/$SRC.tar.xz " $USER
tar xvf $SRC*xz
cd $SRC

./configure prefix=/usr/local --localstatedir=/var --libexecdir=/usr/local/lib/genius  \
--enable-static=no --disable-gtksourceview LIBS="-L/usr/local/lib -lncursesw" \
NCURSES_CFLAGS="-I/usr/local/include/ncursesw" NCURSES_LIBS="-L/usr/local/lib -lncursesw"

# Source code location:	     .
# Compiler:		     gcc
# GNOME frontend:	     yes
# Using GtkSourceView:	     no
make -j5 # 25 seconds
make install-strip DESTDIR=/tmp/$P 
cd /tmp

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

# genius-gui....original exe is actually gnome-genius but I want both next to each other in Apps
########################
mkdir -p $P-gui/usr/local/bin
mv $P/usr/local/bin/gnome-$P $P-gui/usr/local/bin
mkdir -p $P-gui/usr/local/share
mv $P/usr/local/share/applications $P-gui/usr/local/share/
cd $P-gui/usr/local/bin
ln -s gnome-genius genius-gui
cd /tmp

# desktop
#########
mkdir -p $P-gui/usr/local/share/pixmaps
cp $P/usr/local/share/icons/hicolor/48x48/apps/gnome-genius.png $P-gui/usr/local/share/pixmaps/genius-gui.png
DESK1=$P-gui/usr/local/share/applications/gnome-$P.desktop
DESK2=$P-gui/usr/local/share/applications/$P-gui.desktop
mv $DESK1 $DESK2
sed 's|gnome-genius|genius-gui|' -i $DESK2
echo 'X-FullPathIcon=/usr/local/share/pixmaps/genius-gui.png' >> $DESK2 


# split out docs except the manual as its needed in cli 
##################
## strings against main bin suggests needs gel dir
mkdir -p $P-doc/usr/local/share/$P
mv $P/usr/local/share/$P/examples $P-doc/usr/local/share/$P
mv $P/usr/local/share/$P/$P-graph.png $P-doc/usr/local/share/$P
mv $P/usr/local/share/$P/help $P-doc/usr/local/share/$P

# main
###### remove dev files
rm -rf $P/usr/local/lib/$P/*.la
rm -rf $P/usr/local/include

# gtksourceview not built so remove it
rm -rf $P/usr/local/share/$P/gtksourceview

mkdir -p $P/usr/local/share/doc/$P
echo 'main is GPL v3 
gtkExtra is LGPL '  > $P/usr/local/share/doc/$P/COPYING

# gtk-update-icon-cache.tcz.....might use in $P-gui?
# in icewm menu already shows icon OK  

# TCZ them
###########
LIST2="$P $P-doc $P-gui $P-locale "
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:          genius-doc.tcz
Description:    English and lang help asbelow
Version:        1.0.27
Author:         Jiri Lebl, Nils Barth, Kai Willadsen & Adrian E. Feiguin        
Original-site:  https://download.gnome.org/sources/genius/1.0/  
Copying-policy: main: GPL v3
                gtkExtra: LGPL
Size:           3.6M		
Extension_by:   aus9 @linuxquestions.org   
Tags:           calculator 
Comments:       Help dir with cs, de, el, es, fr, pt_BR, ru & sv
                sub-directories each with index.html

                The manual called genius.txt had to remain in main TCE
                
Change-log:     2020/03/07 v 1.0.25 (Juanito) 
Current:        2024/04/07 v 10.027 (aus9)         ' > $P-doc.tcz.info
# no dep

echo 'Title:          genius-gui.tcz
Description:    GUI for genius
Version:        1.0.27
Author:         Jiri Lebl, Nils Barth, Kai Willadsen & Adrian E. Feiguin        
Original-site:  https://download.gnome.org/sources/genius/1.0/  
Copying-policy: main: GPL v3
                gtkExtra: LGPL
Size:           488K		
Extension_by:   aus9 @linuxquestions.org   
Tags:           calculator gui gtk+ gtk3
Comments:       Has a dep of genius.tcz
                If you click on Help -> contents, 
                please load TCE=genius-doc and a web browser for the html help

                exe=genius-gui (lowercase) Also see TCE-genius
                
Change-log:     2020/03/07 v 1.0.25 (Juanito) 
Current:        2024/04/07 v 10.027 (aus9)         ' > $P-gui.tcz.info

readelf -d $P-gui/usr/local/bin/* | grep 'NEEDED' # ignore TCBS......IGNORE DEPS OF main TCE
#libgmp.so.10] libfl.so.2]  main TCE dep
#libvte-2.91.so.0] vte-2.91-gtk3 
#libgtk-3.so.0] libgdk-3.so.0] gtk3 -> vte-2.91-gtk3 
#libpangocairo-1.0.so.0]libpango-1.0.so.0]pango->gtk3->vte-2.91-gtk3 
#libharfbuzz.so.0]                                                                  harfbuzz
#libatk-1.0.so.0]at-spi2-core->gtk3->vte-2.91-gtk3 -> main TCE dep
#libcairo-gobject.so.2]libcairo.so.2]cairo->pango->gtk3->vte-2.91-gtk3 
#libgdk_pixbuf-2.0.so.0]gdk-pixbuf2->gtk3->vte-2.91-gtk3 
#libgio-2.0.so.0]#libgobject-2.0.so.0]#libgmodule-2.0.so.0] main TCE dep
echo 'genius.tcz
vte-2.91-gtk3.tcz
harfbuzz.tcz' > $P-gui.tcz.dep

echo 'Title:          genius-locale.tcz
Description:    language support
Version:        1.0.27
Author:         Jiri Lebl, Nils Barth, Kai Willadsen & Adrian E. Feiguin        
Original-site:  https://download.gnome.org/sources/genius/1.0/  
Copying-policy: main: GPL v3
                gtkExtra: LGPL
Size:           1.4M		
Extension_by:   aus9 @linuxquestions.org   
Tags:           calculator cli gui 
Comments:       untested by me
                Note that the genius-doc contains a reduced set 
                of help locales
                
Change-log:     2020/03/07 v 1.0.25 (Juanito) 
Current:        2024/04/07 v 10.027 (aus9)           ' > $P-locale.tcz.info
echo 'genius.tcz' > $P-locale.tcz.dep

echo 'Title:          genius.tcz
Description:    command line calculator
Version:        1.0.27
Author:         Jiri Lebl, Nils Barth, Kai Willadsen & Adrian E. Feiguin        
Original-site:  https://download.gnome.org/sources/genius/1.0/  
Copying-policy: main: GPL v3
                gtkExtra: LGPL
Size:           432K		
Extension_by:   aus9 @linuxquestions.org   
Tags:           calculator cli 
Comments:       general purpose calculator and mathematics tool
                If you need plotting see genius-gui

                At command line $ genius will offer manual or help
                If you wish to read manual in situ, load TCE=links
                But you can read it at non-TC pathway of
                /usr/local/share/genius/genius.txt
                $ quit # to close
                
Change-log:     2020/03/07 v 1.0.25 (Juanito) 
Current:        2024/04/07 v 10.027 (aus9)         ' > $P.tcz.info

readelf -d $P/usr/local/bin/* | grep 'NEEDED' # ignore TCBs
#libgmp.so.10]gmp -> mpfr 
#libfl.so.2]flex
#libgmodule-2.0.so.0]libglib-2.0.so.0]glib2->at-spi2-core->gtk3->vte-2.91-gtk3
#libreadline.so.8] readline
#libmpfr.so.6]mpfr 
#libncursesw.so.6]ncursesw -> readline
readelf -d $P/usr/local/lib/$P/* | grep 'NEEDED' # no extras

echo 'mpfr.tcz
flex.tcz  
readline.tcz        ' > $P.tcz.dep

# Juanito had a empty install script in main?


submitqc --libs
rm -rf *.zsync
# genius-gui opens ok in icewm with menu icons but did not test further
