#!/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=exo
V=0.12.0
USER=`cat /etc/sysconfig/tcuser`
LIST="compiletc submitqc garcon-dev "
for Z in $LIST 
    do 
    su -c "tce-load -i $Z" $USER
done

cd /tmp

# build perl modules
######################
cpanm URI::Escape URI::file URI::URL

# continue 
##########
su -c "/usr/local/bin/wget -nc --no-check-certificate \
https://mirror.vinahost.vn/xfce/src/xfce/$P/0.12/$P-$V.tar.bz2 " $USER 
mkdir $P
tar jxvf $P*bz2
cd $P-$V 
./configure --disable-debug --enable-gio-unix
make check
make install-strip DESTDIR=/tmp/$P
cd /tmp

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

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

# dev
#####
mkdir -p $P-dev/usr/local/lib
mv $P/usr/local/include $P-dev/usr/local/
mv $P/usr/local/lib/*a $P-dev/usr/local/lib/
mv $P/usr/local/lib/pkgconfig $P-dev/usr/local/lib/
chmod 644 $P-dev/usr/local/lib/*a 

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

# TCZ them
#######
LIST="$P $P-doc $P-dev $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 'exo.tcz' > $P-locale.tcz.dep

echo 'exo.tcz
garcon-dev.tcz 
cpanm.tcz ' > $P-dev.tcz.dep

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

echo 'libxfce4ui.tcz ' > $P.tcz.dep

echo 'Title:          exo.tcz  
Description:    xfce support library
Version:        0.12.0
Author:         see doc for authors  
Original-site:  xfce.org
Copying-policy: GPL v2
Size:		
Extension_by:   aus9 at gmx dot com
Tags:           xfce 
Comments:       XFCE uses command exo-preferred-applications

                Warning: command=exo-compose-mail may need some 
                perl modules that have not been included but 
                you can build by loading cpanm and running
                $ sudo cpanm URI::Escape URI::file URI::URL
                --but exo-compose-mail untested by me
                
                Compiled for 64 9.x
Change-log:     2018/03/11  First version 
Current:        2018/04/06 0.11.5 -> 0.12.0' > $P.tcz.info

echo 'Title:          exo-doc.tcz
Description:    docs
Version:        0.12.0
Author:         see doc for authors 
Original-site:  xfce.org
Copying-policy: GPL v2
Size:		
Extension_by:   aus9 at gmx dot com
Tags:           xfce 
Comments:       Some docs

                Compiled for 64 9.x
Change-log:     2018/03/11  First version 
Current:        2018/04/06 0.11.5 -> 0.12.0 ' > $P-doc.tcz.info

echo 'Title:          exo-dev.tcz
Description:    dev files for exo
Version:        0.12.0
Author:         see doc for authors 
Original-site:  xfce.org
Copying-policy: GPL v2
Size:		
Extension_by:   aus9 at gmx dot com
Tags:           xfce 
Comments:       Development files

                Compiled for 64 9.x
Change-log:     2018/03/11  First version 
Current:        2018/04/06 0.11.5 -> 0.12.0 ' > $P-dev.tcz.info


echo 'Title:          exo-locale.tcz
Description:    locales
Version:        0.12.0
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

                Compiled for 64 9.x
Change-log:     2018/03/11  First version 
Current:        2018/04/06 0.11.5 -> 0.12.0 ' > $P-locale.tcz.info

submitqc --libs