#!/bin/sh
# test we are root
if [ "$(id -u)" != "0" ]; then
   echo "run as root now exitting"
   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.9.1
SRC=$P-$V
USER=`cat /etc/sysconfig/tcuser`

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 # 15 seconds
make install DESTDIR=/tmp/$P
cd /tmp

# feh -v gives compile switches info

# no doc
##########
rm -rf $P/usr/local/share/doc 
rm -rf $P/usr/local/share/man 

# 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
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
# submitqc will change this
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.9.1
Author:         feh - feh team 
Original-site:  http://feh.finalrewind.org/
Copying-policy: accompanied
Size:           144K          		
Extension_by:   aus9
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. $ feh

                wbar feh icon will bork unless you have an image
                in your home dir
            
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
Current:        2023/03/13 v 3.9.1  on 14x add webp support
 ' > $P.tcz.info

readelf -d $P/usr/local/bin/$P | grep 'NEEDED'
################################
# 0x0000000000000001 (NEEDED) Shared library: [libcurl.so.4]          curl
# 0x0000000000000001 (NEEDED) Shared library: [libmagic.so.1]         file
# 0x0000000000000001 (NEEDED) Shared library: [libXinerama.so.1]    libXinerama
# 0x0000000000000001 (NEEDED) Shared library: [libexif.so.12]        libexif
# 0x0000000000000001 (NEEDED) Shared library: [libm.so.6]             main
# 0x0000000000000001 (NEEDED) Shared library: [libpng16.so.16]        libpng -> imlib2
# 0x0000000000000001 (NEEDED) Shared library: [libX11.so.6]            libX11  libXext -> imlib2      
# 0x0000000000000001 (NEEDED) Shared library: [libImlib2.so.1]          imlib2
# 0x0000000000000001 (NEEDED) Shared library: [libc.so.6]              main

echo '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
