#!/bin/sh
# run as root please
# multiple passes to update each so first installs are live installs

export CFLAGS="-O2 -pipe -march=i486 -mtune=i686"
export CXXFLAGS="-O2 -pipe -fno-exceptions -fno-rtti -march=i486 -mtune=i686"
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:/usr/lib/pkgconfig


M=menu-cache
L=libfm
USER=`cat /etc/sysconfig/tcuser`

LIST="compiletc submitqc6 xz glib2-dev intltool pango-dev cairo-dev gtk2-dev menu-cache-dev libfm-dev"
for Z in $LIST
    do 
    su -c "tce-load -i $Z" $USER
done

cd /tmp
su -c "wget http://jaist.dl.sourceforge.net/project/lxde/\
menu-cache/menu-cache%200.7.x/menu-cache-0.7.0.tar.xz\
 " $USER 

su -c "wget http://internode.dl.sourceforge.net/project/pcmanfm/\
PCManFM%20%2B%20Libfm%20%28tarball%20release%29/LibFM/libfm-1.2.3.tar.xz \                                  
" $USER 

# create minor fix
ln -s /usr/local/bin/file /usr/bin/file

# start pass ONE with libfm using existing menu-cache
#                ############# 
# configure defaults to /usr/local but error --sysconfdir=/usr/local/etc
# no stripping needed for pass ONE and TWO
xz -d $L-1.2.3.tar.xz
tar xvf $L-1.2.3.tar
cd $L-1.2.3
./configure  --sysconfdir=/etc
make -j5
make test
touch /tmp/mark1
make install
find /usr/local -newer /tmp/mark1 -not -type d  > /tmp/listlibfm
find /etc -newer /tmp/mark1 -not -type d  >> /tmp/listlibfm

# the listlibfm proves files have changed so we have new libfm running
# start pass TWO to update menu-cache using libfm running in ram drive
#                 #######################
cd /tmp
xz -d $M-0.7.0.tar.xz
tar xvf $M-0.7.0.tar
cd $M-0.7.0
./configure  --prefix=/usr/local 
make -j5
touch /tmp/mark2
make install
find /usr/local -newer /tmp/mark2 -not -type d  > /tmp/listmenucache
# the listmenucacche proves files have changed so we have new menucache running

#########################################
# now do true builds using new live updates
###########################################

# libfm first  Pass THREE
#####################
cd /tmp/$L-1.2.3
make clean
./configure  --sysconfdir=/etc
##   Libfm 1.2.3 Configuration Summary:
#     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:        yes
#Build demo program src/demo/libfm-demo:                 no
#Build with custom actions support (requires Vala):      yes
#Large file support:                                     yes
#GIO module for preferred apps (for glib < 2.28 only):   not required
#Build libfm-gtk for Gtk+ version:                       2.0
#Build API doc with gtk-doc (recommended for make dist): no

make -j5
make test
mkdir -p /tmp/$L
make install DESTDIR=/tmp/$L 

# Strip 
######
cd /tmp/$L/usr/local
strip --strip-all bin/*
strip --strip-unneeded lib/*.so*
strip --strip-unneeded lib/$L/modules/*.so*
strip --strip-debug lib/*.a
cd /tmp

# create dev
#########
mkdir -p $L-dev/usr/local/lib
mv $L/usr/local/lib/pkgconfig $L-dev/usr/local/lib/
mv $L/usr/local/lib/*a $L-dev/usr/local/lib/
# fix perms
chmod 644 $L-dev/usr/local/lib/*a
mv $L/usr/local/include $L-dev/usr/local/

# create locale
###########
mkdir -p $L-locale/usr/local/share
mv $L/usr/local/share/locale $L-locale/usr/local/share/

# create doc
#########
mkdir -p $L-doc/usr/local/share
mv $L/usr/local/share/man $L-doc/usr/local/share/

# pass FOUR menu-cache
#####################

cd /tmp/$M-0.7.0
make clean
./configure  --prefix=/usr/local 
make -j5
mkdir -p /tmp/$M
make install DESTDIR=/tmp/$M 

# Strip 
#########
cd /tmp/$M/usr/local
strip --strip-all libexec/$M/*
strip --strip-unneeded lib/*.so*
strip --strip-debug lib/*.a
cd /tmp

# create dev
#############
mkdir -p $M-dev/usr/local/lib
mv $M/usr/local/include $M-dev/usr/local/
mv $M/usr/local/lib/pkgconfig $M-dev/usr/local/lib/
mv  $M/usr/local/lib/*a $M-dev/usr/local/lib/
chmod 644 $M-dev/usr/local/lib/*a

# TCZ them
#########
cd /tmp


LIST2="$M $M-dev $L $L-dev $L-doc $L-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
        cd /tmp
done

# add the etc to filelist libfm
cd  $L
find etc -not -type d >> /tmp/$L.tcz.list
cd /tmp

# create dep files
###############
echo "menu-cache.tcz 
glib2-dev.tcz
intltool.tcz 
pango-dev.tcz 
cairo-dev.tcz 
gtk2-dev.tcz 
libfm-dev.tcz
" > $M-dev.tcz.dep

echo "libfm.tcz 
glib2-dev.tcz
intltool.tcz 
pango-dev.tcz 
cairo-dev.tcz 
gtk2-dev.tcz 
menu-cache-dev.tcz
" > $L-dev.tcz.dep

echo "libfm.tcz
" > $L-locale.tcz.dep

echo "gtk2.tcz
menu-cache.tcz
libexif.tcz
" > $L.tcz.dep

# create info files let submitqc5 add size
###############################

echo "Title:          menu-cache.tcz
Description:    Library creating and utilizing menu caches
Version:        0.7.0
Author:         LXDE team, Hong Jen Yee, Andriy Grytsenko
Original-site:  http://sourceforge.net/projects/menu-cache/
Copying-policy: GPL v2 and LGPL-2.1+
Size:          
Extension_by:   gordon64
Tags:           LIBRARY LXDE
Comments:       library creating and utilizing caches to speed up
                the manipulation for freedesktop.org defined application menus. 
                ----
                Compiled for Core 6.x
Change-log:     2015/07/05 First version, 0.6.0 bmarkus
Current:        2015/09/01       
" > $M.tcz.info

echo "Title:          menu-cache-dev.tcz
Description:    dev files for menu-cache
Version:        0.7.0
Author:         LXDE team, Hong Jen Yee, Andriy Grytsenko
Original-site:  http://sourceforge.net/projects/menu-cache/
Copying-policy: GPL v2 and LGPL-2.1+
Size:          
Extension_by:   gordon64
Tags:           LIBRARY LXDE
Comments:       development files only
                ----
                Compiled for Core 6.x
Change-log:     2015/07/05 First version, 0.6.0 bmarkus
Current:        2015/09/01      
" > $M-dev.tcz.info

echo "Title:          libfm.tcz
Description:    Libraries for PCManFM
Version:        1.2.3
Author:         Hon Jen Yee (PCMan)
Original-site:  http://pcmanfm.sourceforge.net
Copying-policy: GPL v2
Size:           
Extension_by:   gordon64
Tags:           LIBRARY
Comments:       libs only
                ----
                Compiled for Core 6.x
Change-log:     2015/07/05 First version, 1.2.3 bmarkus
Current:        2015/09/01 re-compiled for menu-cache update
" > $L.tcz.info

echo "Title:          libfm-locale.tcz
Description:    Locales for libfm
Version:        1.2.3
Author:         Hon Jen Yee (PCMan)
Original-site:  http://pcmanfm.sourceforge.net
Copying-policy: GPL v2
Size:           
Extension_by:   gordon64 
Tags:           LIBRARY
Comments:       Language files
                ----
                Compiled for Core 6.x
Change-log:     2015/07/05 First version, 1.2.3 bmarkus
Current:        2015/09/01 re-compiled for menu-cache update
" > $L-locale.tcz.info

echo "Title:          libfm-doc.tcz
Description:    docs for libfm
Version:        1.2.3
Author:         Hon Jen Yee (PCMan)
Original-site:  http://pcmanfm.sourceforge.net
Copying-policy: GPL v2
Size:           
Extension_by:   gordon64
Tags:           man
Comments:       man pages
                ----
                Compiled for Core 6.x
Change-log:     2015/07/05 First version, 1.2.3 bmarkus
Current:        2015/09/01 re-compiled for menu-cache update
" > $L-doc.tcz.info

echo "Title:          libfm-dev.tcz
Description:    dev files for libfm
Version:        1.2.3
Author:         Hon Jen Yee (PCMan)
Original-site:  http://pcmanfm.sourceforge.net
Copying-policy: GPL v2
Size:           
Extension_by:   gordon64
Tags:           LIBRARY
Comments:       Development files
                ----
                Compiled for Core 6.x
Change-log:     2015/07/05 First version, 1.2.3 bmarkus
Current:        2015/09/01 re-compiled for menu-cache update
" > $L-dev.tcz.info

submitqc6