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

check info

export CFLAGS="-march=armv8-a+crc -mtune=cortex-a72 -Os -pipe" 
export CXXFLAGS="-march=armv8-a+crc -mtune=cortex-a72 -Os -pipe \
-fno-exceptions -fno-rtti"

P=feh
V=3.5
SRC=$P-$V
USER=`cat /etc/sysconfig/tcuser`
# no Xorg-dev
LIST="compiletc squashfs-tools wget zsync libX11-dev imlib2-dev curl-dev libexif-dev \
libXinerama-dev libXt-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://feh.finalrewind.org/$SRC.tar.bz2"  $USER

mkdir $P
tar jxvf $SRC*bz2
cd $SRC
make exif=1
make install DESTDIR=/tmp/$P
cd /tmp

# running of man page reveals 
# Compile-time switches in this build:
#   remote file support: libcurl enabled
#   natural sorting option available
#   Xinerama multi-monitor support enabled
#   builtin EXIF reader available
#   inotify-based auto-reload of changed files disabled

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

# main + remove svg files
######
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/feh/images/feh.svg
rm -rf $P/usr/local/share/icons/hicolor/scalable

mkdir -p $P/usr/local/share/doc/$P
echo 'see doc tcz for license' > $P/usr/local/share/doc/$P/COPYING

# 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 -R root:staff $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
        zsyncmake $Z.tcz
done

ls -hal

echo 'Title:          feh.tcz
Description:    terminal or GUI image viewer
Version:        3.5
Author:         many see doc AUTHORS
Original-site:  http://feh.finalrewind.org/
Copying-policy: MIT
Size:           108K
Extension_by:   aus9
Tags:           image viewer
Comments:       desktop image viewer aimed mostly at terminal users
                Does not work at console

                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. $ feh

Change-log:     2020/09/27 Original 3.5 on 12x
Current:        2020/09/27   ' > $P.tcz.info

echo 'imlib2.tcz
libexif.tcz
libXinerama.tcz
curl.tcz
libjpeg-turbo-bin.tcz' > $P.tcz.dep
