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

CFLAGS="-mtune=generic -Os -pipe"
CXX="g++ -flto -fuse-linker-plugin -mtune=generic -Os -pipe -fno-exceptions -fno-rtti"

P=menu-cache
V=1.1.0
SRC=$P-$V
USER=`cat /etc/sysconfig/tcuser`

LIST="compiletc submitqc libfm-extra gtk-doc"
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/lxde/$SRC.tar.xz   "  $USER
mkdir $P
xz -d $P*xz && tar xvf $P*tar
cd $SRC
# below ignored my disable static----we need /etc for configs   make takes seconds
./configure --disable-static --sysconfdir=/etc --disable-gtk-doc 
make check
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
done

ls -hal

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

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://downloads.sourceforge.net/pcmanfm
Copying-policy: GLGPL v2.1
Size:           48K          		
Extension_by:   aus9
Tags:           menu-cache      
Comments:       A library to speed up the manipulation 
                for freedesktop.org defined application menus

                compiled for 10x
Change-log:     2014/01/18 First version, 0.5.0 (bmarkus)
                2015/08/20 v 0.7.0  (gordon64)
Current:        2019/02/11 v 1.1.0 (aus9) ' > $P.tcz.info

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://downloads.sourceforge.net/pcmanfm
Copying-policy: GLGPL v2.1
Size:           4.0K          		
Extension_by:   aus9
Tags:           menu-cache      
Comments:       Developement files
                
                compiled for 10x
Change-log:     2014/01/18 First version, 0.5.0 (bmarkus)
                2015/08/20 v 0.7.0  (gordon64)
Current:        2019/02/11 v 1.1.0 (aus9) ' > $P-dev.tcz.info

submitqc --libs
