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

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

P=feh
V=3.10.2
SRC=$P-$V
USER=`cat /etc/sysconfig/tcuser`
# libwebp1-dev is recursive dep below
LIST="compiletc submitqc libX11-dev imlib2-dev curl-dev libexif-dev \
libXinerama-dev libXt-dev file-dev "
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://$P.finalrewind.org/$SRC.tar.bz2 "  $USER

tar jxvf $SRC*bz2
cd $SRC
make prefix=/usr/local magic=1 exif=1 help=0 debug=0 xinerama=1 # 15 seconds
make install DESTDIR=/tmp/$P
cd /tmp

# feh -v gives compile switches info
# no docs
##########
rm -rf $P/usr/local/share/doc 
rm -rf $P/usr/local/share/man 
DIR=$P/usr/local/share/doc/$P
rm -rf $DIR/AUTHORS $DIR/Changelog $DIR/README.md $DIR/TODO $DIR/examples

# main + remove svg files
###### configure debug=0 fails to strip
strip --strip-unneeded $P/usr/local/bin/$P
mkdir -p $P/usr/local/share/pixmaps
cp $P/usr/local/share/icons/hicolor/48x48/apps/$P.png $P/usr/local/share/pixmaps
echo 'X-FullPathIcon=/usr/local/share/pixmaps/feh.png' >> $P/usr/local/share/applications/$P.desktop
rm -rf $P/usr/local/share/icons/hicolor/scalable
rm -rf $P/usr/local/share/feh/images/feh.svg
mkdir -p $P/usr/local/share/doc/$P
cp $SRC/COPYING $P/usr/local/share/doc/$P/

# tce.install
#############
mkdir -p $P/usr/local/tce.installed
cat << EOF >> $P/usr/local/tce.installed/$P 
#!/bin/sh
gtk-update-icon-cache -q -f -t /usr/local/share/icons/hicolor
EOF
chown root:staff -R $P/usr/local/tce.installed
chmod -R 775 $P/usr/local/tce.installed

# TCZ them
###########
LIST2="$P "
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
        sed 's|usr|/usr|g' -i /tmp/$Z.tcz.list
	cd /tmp
done

ls -hal

echo 'Title:          feh.tcz
Description:    libX image viewer 
Version:        3.10.2
Author:         feh team 
Original-site:  http://feh.finalrewind.org/
Copying-policy: accompanied
Size:           144K          		
Extension_by:   aus9 @ linuxquestions.org
Tags:           image viewer gif png jpeg tiff webp
Comments:       x11 image viewer aimed mostly at terminal users
                online help https://man.finalrewind.org/1/feh/
                feh can view online images,  example
                $  feh https://i.imgur.com/w5a44h6.jpeg

                slideshow is the default mode so run feh in your
                photo/pictures dir without any switch. 
                wbar feh icon will bork unless you have an image
                in your home dir

                Images not supported .jp2 .svg 
                Optional dependencies:
                giflib7 for .gif (shows first animation) 
                libwebp1 for .webp 
            
Change-log:     2015/09/01 first version
                2017/06/19 v 2.9.0  -> 2.13.1 (juanito)
                2018/09/06 v 2.13.1 -> 2.27.1 (aus9) 
                2020/04/19 v 3.4 + gtk2 dep for icon cache updates
                2023/03/13 v 3.9.1  on 14x add webp support
Current:        2023/03/14 v 3.10.2 on 15x
 ' > $P.tcz.info

readelf -d $P/usr/local/bin/$P | grep 'NEEDED'
####### there is no webp?...TCBs ignored
#libcurl.so.4] curl
#libmagic.so.1]file
#libXinerama.so.1] libXinerama
#libexif.so.12] libexif
#libpng16.so.16] libpng -> imlib2
#libX11.so.6] libX11 -> libXext -> imlib2      
#libImlib2.so.1] imlib2
# webp support is in imlib2...check it
# readelf -d /usr/local/lib/libImlib2.so | grep 'NEEDED' - not showing?
# Juanito 14x compile says support shows up in configure status

# gtk-update-icon-cache for install script
echo 'gtk-update-icon-cache.tcz
curl.tcz
file.tcz
libXinerama.tcz
libexif.tcz
imlib2.tcz
hicolor-icon-theme.tcz
libjpeg-turbo-bin.tcz
jpegexiforient.tcz' > $P.tcz.dep

submitqc --libs
