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

# assume its same for ALL XFCE packages
# checking if gcc supports -fno-rtti -fno-exceptions... no
export CFLAGS="-mtune=generic -Os -pipe"
export CXX="g++ -flto -fuse-linker-plugin -mtune=generic -Os -pipe "

P=libxfce4util
V=4.13.1
USER=`cat /etc/sysconfig/tcuser`

LIST="compiletc submitqc intltool glib2-dev gtk-doc "
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://mirror.vinahost.vn/xfce/src/xfce/$P/4.13/$P-$V.tar.bz2  " $USER  
mkdir $P
tar jxvf $P*bz2
cd $P-$V
./configure --disable-debug
#############################
# Build Configuration:
# Debug Support:  no
# GNU Visibility: 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
#####
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 'libxfce4util.tcz
intltool.tcz 
glib2-dev.tcz 
gtk-doc.tcz' > $P-dev.tcz.dep 

echo 'libxfce4util.tcz' > $P-locale.tcz.dep

# no deps for main this is the first of many builds

echo 'Title:          libxfce4util.tcz  
Description:    XFCE utility library
Version:        4.13.1
Author:         see doc for authors  
Original-site:  xfce.org
Copying-policy: LGPL v2
Size:		
Extension_by:   aus9 at gmx dot com
Tags:           xfce 
Comments:       basic utility library for XFCE                    
 
                Compiled for 64 9.x
Change-log:     2018/01/01  First version 
Current:        2018/01/01
' > $P.tcz.info

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

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

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

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

echo 'Title:          libxfce4util-locale.tcz
Description:    locales
Version:        4.13.1
Author:         see doc for authors 
Original-site:  xfce.org
Copying-policy: LGPL 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/01/01  First version 
Current:        2018/01/01
' > $P-locale.tcz.info

submitqc --libs

# nothing useful to test so early in builds at script one stage
