#!/bin/sh
#  we are root

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

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

LIST="compiletc submitqc5 wget imlib2-dev Xorg-7.7-dev libexif-dev  "
for Z in $LIST
    do 
    su -c "tce-load -i $Z" $USER
done

# wget fails for http://feh.finalrewind.org/feh-2.13.1.tar.bz2
# use a browser to RH click and save as target

tar jxvf $P-2.13.1.tar.bz2
cd $P*
make curl=0 exif=1
mkdir -p /tmp/$P
make install DESTDIR=/tmp/$P
cd /tmp

# strip
#####
strip --strip-all $P/usr/local/bin/*

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

# add icon pathway
###############
echo 'X-FullPathIcon=/usr/local/share/feh/images/feh.png'\
 >> $P/usr/local/share/applications/$P.desktop

# add MIT license to all software
##########################
mkdir -p $P/usr/local/share/doc/$P
cp -f $P-2.13.1/COPYING $P/usr/local/share/doc/$P/
cp -f $P-2.13.1/COPYING $P-doc/usr/local/share/doc/$P/

# create TCZ
###########
LIST2="$P $P-doc "
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 depend files
################
echo 'imlib2.tcz
libexif.tcz
libXinerama.tcz
 ' > $P.tcz.dep

# create info files let submitqc5 add size
echo "Title:          feh.tcz  TESTING
Description:    Image viewer 
Version:        2.13.1
Author:         see -doc/AUTHORS
Original-site:  http://feh.finalrewind.org/
Copying-policy: see COPYING
Size:		
Extension_by:   gordon64
Tags:           image viewer
Comments:       Image viewer. 
                x86 maintainer=Juanito, Averyeng
                I acknowledge that I have complied with the 
                MIT license in using this software.

                compiled for Corepure64
Change-log:     2015/09/01 first version
Current:        2015/09/01
" > $P.tcz.info

echo "Title:          feh-doc.tcz  
Description:    docs for feh
Version:        2.13.1
Author:         see -doc/AUTHORS
Original-site:  http://feh.finalrewind.org/
Copying-policy: see COPYING
Size:		
Extension_by:   gordon64
Tags:           feh
Comments:       Image viewer. 
                x86 maintainer=Juanito, Averyeng
                I acknowledge that I have complied with the 
                MIT license in using this software.

                compiled for Corepure64
Change-log:     2015/09/01 first version
Current:        2015/09/01
" > $P-doc.tcz.info

submitqc5