#!/bin/sh
# test we are root
if [ "$(id -u)" != "0" ]; then
   echo "run as root now exitting"
   exit 1
fi

# pref script was libxfce4util this is next
export CFLAGS="-march=armv8-a+crc -mtune=cortex-a72 -Os -pipe" 
export CXXFLAGS="-march=armv8-a+crc -mtune=cortex-a72 -Os -pipe -fno-exceptions -fno-rtti"

P=xfconf
V=4.18.0
SRC=$P-$V
USER=`cat /etc/sysconfig/tcuser`
LIST="compiletc submitqc libxfce4util-dev dbus-glib-dev cpanm  "
for Z in $LIST
    do 
    su -c "tce-load -i $Z" $USER
done

# list may have more than loaded
cd /usr/local/lib
rm -rf *.la
rm -rf gcc/aarch64-unknown-linux-gnu/12.2.0/plugin/*.la
rm -rf gcc/aarch64-unknown-linux-gnu/12.2.0/*.la
rm -rf gprofng/*.la 
rm -rf python3.8/site-packages/*.la
rm -rf pkcs11/*.la
rm -rf cairo/*.la
rm -rf gtk-2.0/modules/*.la
rm -rf gtk-2.0/2.10.0/printbackends/*.la
rm -rf gtk-2.0/2.10.0/immodules/*.la
rm -rf gtk-2.0/2.10.0/engines/*.la
rm -rf imlib2/loaders/*.la
rm -rf imlib2/filters/*.la
rm -rf gdk-pixbuf-2.0/2.10.0/loaders/*.la
rm -rf libnl/cli
cd /tmp
rm -rf /usr/lib/*.la

cpanm ExtUtils::Depends ExtUtils::PkgConfig Glib
# takes about 1m 25s

su -c "/usr/local/bin/wget -nc --no-check-certificate \
https://archive.xfce.org/xfce/4.18/src/$SRC.tar.bz2"  $USER
tar jxvf $SRC*bz2
cd $SRC
./configure --prefix=/usr/local --enable-checks --disable-debug
# GSettings Backend:         yes
# GObject Introspection:     no
# Vala support:              no
# Bash completion path:      ${datadir}/bash-completion/completions
# Debug:                     no
make -j4 # 20s
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/pkgconfig $P-dev/usr/local/lib/
rm -f  $P/usr/local/lib/*.la 
rm -rf $P/usr/local/lib/gio/modules/*.la

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

# main
#####
rm -rf $P/usr/local/share/gtk-doc
mkdir -p $P/usr/local/share/doc/$P
echo 'GPL v2' > $P/usr/local/share/doc/$P/COPYING

# TCZ them
###########
LIST2="$P $P-dev $P-locale "
for Z in $LIST2
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

ls -hal

echo 'Title:          xfconf-dev.tcz
Description:    dev files
Version:        4.18.0
Author:         Brian J. Tarricone & Stephan Arts 
Original-site:  https://archive.xfce.org/xfce/4.18/src/
Copying-policy: GPL v2
Size:           8.0K
Extension_by:   aus9
Tags:           xfce
Comments:       dev files

Change-log:     2020/10/22 v 4.14.1 on 12.x
Current:        2023/06/20 v 4.18.0 on 14.x   ' > $P-dev.tcz.info
echo 'xfconf.tcz
libxfce4util-dev.tcz
perl5.tcz
dbus-glib.tcz ' > $P-dev.tcz.dep

echo 'Title:          xfconf-locale.tcz
Description:    language files
Version:        4.18.0
Author:         Brian J. Tarricone & Stephan Arts 
Original-site:  https://archive.xfce.org/xfce/4.18/src/
Copying-policy: GPL v2
Size:           212K
Extension_by:   aus9
Tags:           xfce
Comments:       untested by me

Change-log:     2020/10/22 v 4.14.1 on 12.x
Current:        2023/06/20 v 4.18.0 on 14.x   ' > $P-locale.tcz.info
echo 'xfconf.tcz' > $P-locale.tcz.dep

echo 'Title:          xfconf.tcz
Description:    configuration storage system for Xfce
Version:        4.18.0
Author:         Brian J. Tarricone & Stephan Arts  
Original-site:  https://archive.xfce.org/xfce/4.18/src/
Copying-policy: GPL v2
Size:           100K
Extension_by:   aus9
Tags:           xfce
Comments:       configuration storage system for Xfce

Change-log:     2020/10/22 v 4.14.1 on 12.x
Current:        2023/06/20 v 4.18.0 on 14.x   ' > $P.tcz.info

readelf -d $P/usr/local/bin/* | grep 'NEEDED' # delete TCBs and duplicates below
#[libxfconf-0.so.3]this TCE 
#[libxfce4util.so.7] libxfce4util
#[libgio-2.0.so.0] glib2 "
#[libgobject-2.0.so.0]   "
#[libglib-2.0.so.0] 
readelf -d $P/usr/local/lib/*.so | grep 'NEEDED'  
readelf -d $P/usr/local/lib/gio/modules/* | grep 'NEEDED'
readelf -d $P/usr/local/lib/xfce4/$P/xfconfd | grep 'NEEDED'  

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

submitqc --libs

rm -rf *.zsync
