#!/bin/sh
# run as root please

# CREDITS bmarkus for some of his material

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 

P=pcmanfm
USER=`cat /etc/sysconfig/tcuser`

# libfm-dev has heaps in it
LIST="compiletc submitqc6 xz libfm-dev lxde-icon-theme "
for Z in $LIST
    do 
    su -c "tce-load -i $Z" $USER
done

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

su -c "/usr/local/bin/wget \
https://www.dropbox.com/s/4d932v5cb3mghx8/tceinstalled.txt?dl=0 \
-O /tmp/tceinstalled.txt " $USER

xz -d $P-1.2.3.tar.xz
tar xvf $P-1.2.3.tar
cd $P-1.2.3
./configure  --prefix=/usr/local
make -j5
mkdir -p /tmp/$P
make install DESTDIR=/tmp/$P

# Strip 
cd /tmp/$P/usr/local
strip --strip-all bin/*
cd /tmp

# add config file
echo '# DO NOT EDIT! This file will be overwritten by LXAppearance.
# Any customization should be done in ~/.gtkrc-2.0.mine instead.
gtk-theme-name="Raleigh"
gtk-icon-theme-name="nuoveXT2"
gtk-font-name="Sans 10"
gtk-cursor-theme-size=0
gtk-toolbar-style=GTK_TOOLBAR_BOTH
gtk-toolbar-icon-size=GTK_ICON_SIZE_LARGE_TOOLBAR
gtk-button-images=1
gtk-menu-images=1
gtk-enable-event-sounds=1
gtk-enable-input-feedback-sounds=1
gtk-xft-antialias=1
gtk-xft-hinting=1
gtk-xft-hintstyle="hintfull"
include .gtkrc-2.0.mine
' > $P/usr/local/share/$P/.gtkrc-2.0

# create dev
#########
mkdir -p $P-dev/usr/local
mv $P/usr/local/include $P-dev/usr/local/

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

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

# add pixmap add icon pathway
#########################
mkdir -p $P/usr/local/share/pixmaps
ICON=/usr/local/share/icons/nuoveXT2/48x48/apps/system-file-manager.png
cp $ICON $P/usr/local/share/pixmaps/

echo "X-FullPathIcon=/usr/local/share/pixmaps/system-file-manager.png
" >> $P/usr/local/share/applications/$P.desktop

# create tce.installed
################
mkdir -p $P/usr/local/tce.installed

cp tceinstalled.txt  $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
#########
cd /tmp

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

# create dep files
###############
echo "pcmanfm.tcz 
libfm-dev.tcz
lxde-icon-theme.tcz" > $P-dev.tcz.dep

echo "pcmanfm.tcz" > $P-locale.tcz.dep

echo "libfm.tcz
dbus-glib.tcz
cairo.tcz
shared-mime-info.tcz
lxde-icon-theme.tcz
hicolor-icon-theme.tcz
" > $P.tcz.dep

# create info files let submitqc5 add size

echo "Title:          pcmanfm.tcz  TESTING
Description:    Graphical File Manager
Version:        1.2.3
Author:         Hong Jen Yee, Brian Tarricone
Original-site:  http://sourceforge.net/projects/pcmanfm/
Copying-policy: GPL v2
Size:		
Extension_by:   gordons64
Tags:           pcmanfm  file manager
Comments:       Graphical file manager normally for LXDE
                but can run as stand-alone. Runs on GTK2.

                Warning: all partitions may be automounted 
                but no umount in this app. 
                Use the mount tool to un-mount please.

                Running pcmanfm as root does allow un-mount.

                Adjust .config/pcmanfm/default/pcmanfm.conf if
                automount does not suit you, etc
 
                Compiled for x86 6.x
Change-log:     2015/07/05 First version, 1.2.3 bmarkus
Current:        2015/09/01 re-compiled for dependency updates
" > $P.tcz.info

echo "Title:          pcmanfm-dev.tcz
Description:    Dev files for pcmanfm
Version:        1.2.3
Author:         Hong Jen Yee
Original-site:  http://sourceforge.net/projects/pcmanfm/
Copying-policy: GPL v2
Size:		
Extension_by:   gordons64
Tags:           pcmanfm 
Comments:       Development files

                Compiled for x86 6.x
Change-log:     2015/07/05 First version, 1.2.3 bmarkus
Current:        2015/09/01 re-compiled for dependency updates
" > $P-dev.tcz.info

echo "Title:          pcmanfm-doc.tcz
Description:    pcmanfm docs
Version:        1.2.3
Author:         Hong Jen Yee
Original-site:  http://sourceforge.net/projects/pcmanfm/ 
Copying-policy: GPL v2
Size:		
Extension_by:   gordons64
Tags:           pcmanfm 
Comments:       Contains man page
  
                Compiled for x86 6.x
Change-log:     2015/07/05 First version, 1.2.3 bmarkus
Current:        2015/09/01 re-compiled for dependency updates
" > $P-doc.tcz.info

echo "Title:          pcmanfm-locale.tcz
Description:    locales
Version:        1.2.3
Author:         Hong Jen Yee
Original-site:  http://sourceforge.net/projects/pcmanfm/ 
Copying-policy: GPL v2
Size:		
Extension_by:   gordons64
Tags:           pcmanfm locale
Comments:       Language files
  
                Compiled for x86 6.x
Change-log:     2015/07/05 First version, 1.2.3 bmarkus
Current:        2015/09/01 re-compiled for dependency updates
" > $P-locale.tcz.info

submitqc6