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

# build order is libfm-extra-dev menu-cache libfm then pcmanfm
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"

P1=libfm
P=$P1-extra-dev
V=1.3.1
SRC=$P1-$V
USER=`cat /etc/sysconfig/tcuser`
LIST="compiletc wget squashfs-tools zsync intltool glib2-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://downloads.sourceforge.net/pcmanfm/$SRC.tar.xz   "  $USER
mkdir $P
xz -d *xz && tar xvf *tar
cd $SRC
# configure recommends etc/
./configure  --prefix=/usr/local --sysconfdir=/etc --with-extra-only \
--with-gtk=no --disable-static
##################################
# prefix:           /usr/local
# sysconfdir:       /etc
# Enable compiler flags and other support for debugging:no
# Build udisks support (Linux only, experimental):   no
# Build with libexif for faster thumbnail loading:   no
# Build demo program src/demo/libfm-demo:            no
# Build with custom actions support (requires Vala): no
# Large file support:  yes
# GIO module for preferred apps (for glib < 2.28 only): not required
# Build libfm-gtk for Gtk+ version: none
# Build API doc with gtk-doc (recommended for make dist): no
####################################################   
make check # takes seconds
make install-strip DESTDIR=/tmp/$P
cd /tmp

# main
#######
chmod 644 $P/usr/local/lib/*a

mkdir -p $P/usr/local/share/doc/$P
echo 'see https://github.com/lxde/libfm/blob/master/AUTHORS for license
' > $P/usr/local/share/doc/$P/COPYING

# I end up with 2 real files when a sym link should do
rm -rf $P/usr/local/include/libfm

mkdir -p $P/usr/local/tce.installed
echo '#!/bin/sh
P=libfm-extra-dev
LOOP=/tmp/tcloop/$P/usr/local/include
[ -d /usr/local/include/libfm ] || ln -s $LOOP/libfm-1.0 /usr/local/include/libfm
' > $P/usr/local/tce.installed/$P 
chown -R root:staff $P/usr/local/tce.installed
chmod -R 775 $P/usr/local/tce.installed

# TCZ them
###########
LIST="$P"
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
        zsyncmake $Z.tcz
done

ls -hal

echo 'Title:          libfm-extra-dev.tcz
Description:    building dep for menu-cache
Version:        1.3.1
Author:         https://github.com/lxde/libfm/blob/master/AUTHORS
Original-site:  https://downloads.sourceforge.net/pcmanfm
Copying-policy: GPL v2
Size:           16K
Extension_by:   aus9
Tags:           pcmanfm
Comments:       Building dep for menu-cache

Change-log:     2020/09/06 v 1.3.1 for 12x
Current:        2020/09/06
' > $P.tcz.info

echo 'intltool.tcz 
glib2-dev.tcz '> $P.tcz.dep
