#!/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=xfconf
V=4.13.4
USER=`cat /etc/sysconfig/tcuser`
LIST="compiletc submitqc dbus-glib-dev \
intltool unzip cpanm libxfce4util-dev"
for Z in $LIST 
    do 
    su -c "tce-load -i $Z" $USER
done

# create perl modules but don't submit
#####################
cpanm ExtUtils::Depends ExtUtils::PkgConfig Glib
#  check for this output ->  3 distributions installed
 
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 --enable-checks --disable-debug
#####################################################################################
### checking for perl modules: ExtUtils::Depends, ExtUtils::PkgConfig, Glib... yes
####################################################################################
make -j5
make install-strip DESTDIR=/tmp/$P
cd /tmp

# dev
#####
ZZ=/usr/local/lib/perl5/site_perl/5.24.0/x86_64-linux-thread-multi/Xfce4/Xfconf/Install
mkdir -p $P-dev$ZZ
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/
mv $P$ZZ/xfconfperl.h $P-dev$ZZ/
mv $P$ZZ/xfconfperl-autogen.h $P-dev$ZZ/
chmod 644 $P-dev/usr/local/lib/*a

# locale
#########
cd /tmp
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
mv $P/usr/local/share/man $P-doc/usr/local/share
rm -rf $P/usr/local/share/gtk-doc

# main
######
# SO not stripped next line is pathway 
# $P/usr/local/lib/perl5/site_perl/5.24.0/x86_64-linux-thread-multi/auto/Xfce4/Xfconf
mkdir -p $P/usr/local/share/doc/$P
echo 'see doc tcz for license' > $P/usr/local/share/doc/$P/COPYING
chmod 755 $P/usr/local/lib/lib$P-0.so.2.0.0
Z=$P/usr/local/lib/perl5/site_perl/5.24.0/x86_64-linux-thread-multi/auto/Xfce4/Xfconf/
chmod 755 $Z/Xfconf.so
# I was unable to strip the so under $Z 
# using submitqc --strip also FAILS to strip that shared object

# TCZ
#######
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 'xfconf.tcz
dbus-glib-dev.tcz
intltool.tcz
unzip.tcz
cpanm.tcz
libxfce4util-dev.tcz' > $P-dev.tcz.dep

echo 'dbus-glib.tcz
libxfce4util.tcz' > $P.tcz.dep

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

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

echo 'Title:          xfconf.tcz  
Description:    xfce config storage
Version:        4.13.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:       xfce config storage system
                WARNING if you need to use Xfconf.pm 
                load cpanm then run
                $ sudo cpanm ExtUtils::Depends ExtUtils::PkgConfig Glib                      
 
                Compiled for 64 9.x
Change-log:     2018/01/02  First version 
Current:        2018/01/02
' > $P.tcz.info

echo 'Title:          xfconf-doc.tcz
Description:    man pages and some docs
Version:        4.13.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:       Contains man page and some docs
                
                Compiled for 64 9.x
Change-log:     2018/01/02  First version 
Current:        2018/01/02 
' > $P-doc.tcz.info

echo 'Title:          xfconf-dev.tcz
Description:    dev files for xfconf
Version:        4.13.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:       Development files

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


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

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

submitqc --libs

# in openbox command=xfconf-query -l -> with dbus not running or running GIVES
#Channels:
 # thunar
 # load some more and result is

# xfconf-query -l -> Channels:
  # xfce4-keyboard-shortcuts
  # thunar
  # xfce4-panel
