#!/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 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"

P=menu-cache
V=1.1.0
SRC=$P-$V
USER=`cat /etc/sysconfig/tcuser`
LIST="libfm-extra-dev "
for Z in $LIST
    do
    su -c "tce-load -i $Z" $USER
done

LFS=http://www.linuxfromscratch.org/patches/blfs/svn
cd /tmp
su -c "/usr/local/bin/wget -nc --no-check-certificate \
https://sourceforge.net/projects/lxde/files/$P/1.1/$SRC.tar.xz \
$LFS/menu-cache-1.1.0-consolidated_fixes-1.patch  "  $USER
mkdir $P
xz -d $P*xz && tar xvf $P*tar
cd $SRC
patch -Np1 -i ../menu-cache-1.1.0-consolidated_fixes-1.patch

./configure --prefix=/usr/local --disable-static --enable-debug=no
make check # takes seconds
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/
mv $P/usr/local/lib/*a $P-dev/usr/local/lib/
chmod 644 $P-dev/usr/local/lib/*a

# TCZ them
###########
LIST="$P $P-dev  "
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:          menu-cache-dev.tcz
Description:    dev files
Version:        1.1.0
Author:         see https://github.com/lxde/menu-cache/blob/master/AUTHORS
Original-site:  https://sourceforge.net/projects/lxde/files/menu-cache/
Copying-policy: LGPL v2.1
Size:           4.0K
Extension_by:   aus9
Tags:           menu-cache
Comments:       Dev files

Change-log:     2020/09/06 Original v 1.1.0 on 12x
Current:        2020/09/06 ' > $P-dev.tcz.info

echo 'Title:          menu-cache.tcz
Description:    menu cache Library
Version:        1.1.0
Author:         see https://github.com/lxde/menu-cache/blob/master/AUTHORS
Original-site:  https://sourceforge.net/projects/lxde/files/menu-cache/
Copying-policy: LGPL v2.1
Size:           40K
Extension_by:   aus9
Tags:           menu-cache
Comments:       A library to speed up the manipulation
                for freedesktop.org defined application menus
                recursive dep of pcmanfm

Change-log:     2020/09/06 Original v 1.1.0 on 12x
Current:        2020/09/06 ' > $P.tcz.info

echo 'menu-cache.tcz
libfm-extra-dev.tcz  '> $P-dev.tcz.dep

