#!/bin/sh
# test we are root
if [ "$USER" != "root" ] ; then
   echo "Run as root please, exiting." 
   exit 1                                                      
fi

export CFLAGS="-mtune=generic -Os -pipe"
export CXX="g++ -flto -fuse-linker-plugin -mtune=generic -Os -pipe "

P=xfce4-terminal
V=0.8.4
USER=`cat /etc/sysconfig/tcuser`
LIST="compiletc submitqc intltool gtk3-dev vte-dev libxfce4ui-dev
gnome-icon-theme"
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 \
http://archive.xfce.org/src/apps/$P/0.8/$P-$V.tar.bz2 " $USER 
tar jxvf $P*bz2
mkdir $P
cd $P-$V
./configure --disable-debug 
###############################
# Build Configuration:
# Debug support:           no
# Man Pages:               yes 
#################################################
make -j5
make install-strip DESTDIR=/tmp/$P
cd /tmp

# doc
#####
mkdir -p $P-doc/usr/local/share/doc/$P
mkdir -p $P-doc/usr/local/share/man
cp $P-$V/AUTHORS $P-doc/usr/local/share/doc/$P
cp $P-$V/COPYING $P-doc/usr/local/share/doc/$P
mv $P/usr/local/share/man/man1 $P-doc/usr/local/share/man

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

# dev none use source
#####

# main
#####
mkdir -p $P/usr/local/share/doc/$P
echo 'see doc tcz for license' > $P/usr/local/share/doc/$P/COPYING

# desktop
# icon comes from a number of icon TCZs I chose gnome
mkdir -p $P/usr/local/share/pixmaps
G=/tmp/tcloop/gnome-icon-theme/usr/local/share/icons/gnome/48x48/apps/utilities-terminal.png
cp $G $P/usr/local/share/pixmaps/
echo 'X-FullPathIcon=/usr/local/share/pixmaps/utilities-terminal.png' >> \
$P/usr/local/share/applications/$P.desktop

# TCZ them
#######
LIST="$P $P-doc $P-locale "
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
done

echo 'xfce4-terminal.tcz
intltool.tcz
gtk3-dev.tcz
vte-dev.tcz
libxfce4ui-dev.tcz' > $P-dev.tcz.dep

echo 'man-db.tcz
ncurses5.tcz' > $P-doc.tcz.dep

echo 'man-db.tcz
ncurses5.tcz' > $P-locale.tcz.dep

echo 'gtk3.tcz
vte.tcz
gsettings-desktop-schemas.tcz
libxfce4ui.tcz' > $P.tcz.dep

echo 'xfce4-terminal.tcz' > $P-locale.tcz.dep

echo 'Title:          xfce4-terminal.tcz  
Description:    xfce terminal
Version:        0.8.4
Author:         see doc for authors  
Original-site:  xfce.org
Copying-policy: GPL v2
Size:		
Extension_by:   aus9 at gmx dot com
Tags:           xfce terminal
Comments:       xfce terminal can run outside XFCE
                
                If you like using TABS recommend you  
                pulldown View and click --show toolbar                       
 
                Compiled for 64 9.x
Change-log:     2018/02/02  First version 
Current:        2018/02/02
' > $P.tcz.info

echo 'Title:          xfce4-terminal-doc.tcz
Description:    docs
Version:        0.8.4
Author:         see doc for authors 
Original-site:  xfce.org
Copying-policy: GPL v2
Size:		
Extension_by:   aus9 at gmx dot com
Tags:           xfce 
Comments:       man pages English only
                See the locale TCZ if you need
                your native language please.
                
                Compiled for 64 9.x
Change-log:     2018/02/02  First version 
Current:        2018/02/02 
' > $P-doc.tcz.info

echo 'Title:          xfce4-terminal-locale.tcz
Description:    locales and man locales
Version:        0.8.4
Author:         see doc for authors 
Original-site:  xfce.org
Copying-policy: GPL v2
Size:		
Extension_by:   aus9 at gmx dot com
Tags:           xfce 
Comments:       for non-english users untested

                contains man pages for locales 

                Compiled for 64 9.x
Change-log:     2018/02/02  First version 
Current:        2018/02/02
' > $P-locale.tcz.info

submitqc --libs

# gsettings is to provide org.gnome.desktop \
# if you choose system font

# in openbox command=xfce4-terminal runs with some minor errors
# in loading....... various issues due to schemas from gsettings-desktop-schemas
# in running from a terminal, the..... session manager.... refers to an XFCE component
# also to enable or disable anti-alias another XFCE component needs to be 
# submitted but they not yet ready. Terminal from wbar runs fine though.