#!/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=garcon
V=0.6.1
USER=`cat /etc/sysconfig/tcuser`
LIST="compiletc submitqc libxfce4ui-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://mirror.vinahost.vn/xfce/src/xfce/$P/0.6/$P-$V.tar.bz2 " $USER 
mkdir $P
tar jxvf $P*bz2
cd $P-$V 
./configure --disable-debug
############################
# Build Configuration:
# Debug Support:  no
# GTK2 support:  yes
##########################
make -j5
make install-strip DESTDIR=/tmp/$P
cd /tmp

# 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

# 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/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/

# main
#####
# create copying file
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 'garcon.tcz' > $P-locale.tcz.dep

echo 'garcon.tcz
libxfce4ui-dev.tcz' > $P-dev.tcz.dep

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

echo 'Title:          garcon.tcz  
Description:    freedesktop.org compliant menu 
Version:        0.6.1
Author:         see doc for authors  
Original-site:  xfce.org
Copying-policy: LGPL v2 and doc=GFDL
Size:		
Extension_by:   aus9 at gmx dot com
Tags:           xfce 
Comments:       freedesktop.org compliant menu 
                implementation of GLib and GIO 
                for XFCE

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

echo 'Title:          garcon-doc.tcz
Description:    docs
Version:        0.6.1
Author:         see doc for authors 
Original-site:  xfce.org
Copying-policy: LGPL v2 and doc=GFDL
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/03/11 ' > $P-doc.tcz.info

echo 'Title:          garcon-dev.tcz
Description:    dev files for garcon
Version:        0.6.1
Author:         see doc for authors 
Original-site:  xfce.org
Copying-policy: LGPL v2 and doc=GFDL
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/03/11 ' > $P-dev.tcz.info


echo 'Title:          garcon-locale.tcz
Description:    locales
Version:        0.6.1
Author:         see doc for authors 
Original-site:  xfce.org
Copying-policy: LGPL v2 and doc=GFDL
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/03/11 ' > $P-locale.tcz.info

submitqc --libs