#!/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-settings
V=4.13.1
SRC=$P-$V
USER=`cat /etc/sysconfig/tcuser`
LIST="compiletc submitqc intltool exo-dev libnotify-dev \
libxklavier-dev libXcursor-dev upower-dev libXrandr-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/4.13/$SRC.tar.bz2 " $USER

mkdir $P
tar jxvf $P*bz2
cd $SRC
./configure --enable-debug=no --enable-sound-settings \
--enable-xcursor --enable-xrandr --enable-libxklavier \
--enable-pluggable-dialogs
#######################################################
# Build Configuration:

# Installation prefix:       /usr/local
# Debug Support:             no
# Xrandr support:            yes
# UPower support:            yes
# Libnotify support:         yes
# Xcursor support:           yes
# Xorg libinput support:     no
# Embedded settings dialogs  yes
# Sounds settings support    yes
# Libxklavier support:       yes
# Mime settings (gio-unix):  yes
######################################################## 
make -j5
make install-strip DESTDIR=/tmp/$P
cd /tmp

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

# main
#####
mkdir -p $P/usr/local/share/doc/$P
cp $SRC/AUTHORS $P/usr/local/share/doc/$P/
cp $SRC/COPYING $P/usr/local/share/doc/$P/

# the desktops only appear in XFCE
# mouse themes changes needs xfsettingsd to be OK
# so upower and libnotify need loading and
# dbus on

tce.install
#############
mkdir -p $P/usr/local/tce.installed

cat >> $P/usr/local/tce.installed/$P <<'EOF'
#!/bin/sh
/usr/local/etc/init.d/dbus restart
EOF
chown -R root:staff $P/usr/local/tce.installed
chmod -R 755 $P/usr/local/tce.installed


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

echo 'xfce4-settings.tcz
intltool.tcz
exo-dev.tcz 
libnotify-dev.tcz
libXcursor-dev.tcz
libxklavier-dev.tcz
upower-dev.tcz
libXrandr-dev.tcz ' > $P-dev.tcz.dep

echo 'adwaita-icon-theme.tcz
exo.tcz
garcon.tcz
libxklavier.tcz
libXrandr.tcz
upower.tcz
libnotify.tcz 
Ant-Dracula-Blue.tcz' > $P.tcz.dep

echo 'Title:          xfce4-settings.tcz  
Description:    xfce settings
Version:        4.13.1
Author:         see AUTHORS  
Original-site:  xfce.org
Copying-policy: GPL v2
Size:           		
Extension_by:   aus9 at gmx dot com
Tags:           xfce 
Comments:       XFCE uses xfce4-settings-manager. Please use the
                manager rather than specific settings apps except 
                for next paragraph.

                Mouse and keyboard (kb) changes will not be effective 
                unless:
                1) xfce4-session is loaded
                2) dbus is running (install script starts it)
                3) Applications -> Settings -> Session and Startup
                   click TAB for Application Autostart 
                ** Ensure the box for xfsettingsd is ticked please 
                
                For mouse theme changes please go thru the manager 
                and will not take effect until you click All Settings 
                to exit up one level. YMMV
                
                Keyboard settings will be restricted until you load 
                xfce4-xkb-plugin and xfce4-session. 

                If a TCZ is not loaded, its icon will not appear in 
                the settings GUI eg session and startup

                In Settings -> Appearance -> TAB=Style
                Raleigh is a gtk2 theme and cause issues for this 
                gtk3 build.  Which is why I have given you Ant-Dracula-Blue theme.
                If you accidently click on Raleigh, just click on whatever
                theme you have loaded if you do not like Ant-Dracula-Blue.

                Untested by me, if you need Assistive Technologies 
                click panel 1 Applications -> Settings 
                -> (Session and startup) -> (TAB) Application Autostart 
                and tick the box for AT-SPI please.....and
                Settings -> System -> Accessibility -> tick the box
                then check the other TABS please

                Sometimes change display resolution fails for me.
                YMMV. If it happens to you, try arandr.tcz
                                                ##########   
                For bootup to a preferred resolution consider
                using a boot (cheat) code. Or, xrandr command set
                probably in your /opt/bootlocal.sh

                Optional dependencies --see their info files please.
                In case I submit more xfwm4 themes search Apps using
                tag search xfce please
                #####################
                xfce4-xkb-plugin.tcz 
                xfce4-power-manager.tcz
                                
                Compiled for 64 9.x
Change-log:     2018/03/11  First version 
                2018/04/06  recompiled against newer exo 
Current:        2018/04/20  Discuss Raleigh theme ' > $P.tcz.info

echo 'Title:          xfce4-settings-locale.tcz
Description:    locales
Version:        4.13.1
Author:         see 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  recompiled against newer exo' > $P-locale.tcz.info

submitqc  --libs
