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

# prev build was libxfceui this is last in set

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=parole
V=1.0.5
SRC=$P-$V
USER=`cat /etc/sysconfig/tcuser`
# gst-plugins-base
LIST="compiletc squashfs-tools zsync wget libxfce4ui-dev taglib-dev  \
dbus-glib-dev libnotify-dev gstreamer-dev  gst-plugins-base-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 \
http://archive.xfce.org/src/apps/parole/1.0/$SRC.tar.bz2"  $USER
mkdir $P
tar jxvf $SRC*bz2
cd $SRC
./configure --prefix=/usr/local	 --disable-debug --disable-nls --disable-mpris2-plugin --disable-notify-plugin
# prefix:                  /usr/local 
# pixmapsdir:              /usr/local/share/parole/pixmaps
# Debug:                   no
# Building plugin api docs:no
# GStreamer API version:   1.0
# GTK+ version:            GTK+-3
# Optional dependencies:
# Clutter Backend:         blacklisted
# Taglib:                  yes
# Plugins to build:
# Notify:                  no
# System Tray icon:        yes
# MPRIS2:                  no
###############################
make -j5 # takes 35 secs
make install-strip DESTDIR=/tmp/$P
cd /tmp

# no dev
#########
rm -rf $P/usr/local/include
rm -rf $P/usr/local/lib/$P-0/*la
rm -rf $P/usr/local/lib/pkgconfig

# no locale
#########
rm -rf  $P/usr/local/share/locale

# main
#######
mkdir -p $P/usr/local/share/pixmaps
cp $P/usr/local/share/icons/hicolor/48x48/apps/$P.png $P/usr/local/share/pixmaps/
APP=$P/usr/local/share/applications/$P.desktop
# leave the other desktop intact for reduced error messages

echo '[Desktop Entry]
Name=Parole Media Player
Icon=parole
Exec=parole %F
Terminal=false
Type=Application
Categories=GTK;AudioVideo;Player;Video;
StartupNotify=true
MimeType=application/mxf;application/ogg;application/ram;application/sdp;application/smil;application/smil+xml;application/vnd.apple.mpegurl;application/vnd.ms-wpl;application/vnd.rn-realmedia;application/x-extension-m4a;application/x-extension-mp4;application/x-flac;application/x-flash-video;application/x-matroska;application/x-netshow-channel;application/x-ogg;application/x-quicktime-media-link;application/x-quicktimeplayer;application/x-shorten;application/x-smil;application/xspf+xml;audio/3gpp;audio/ac3;audio/AMR;audio/AMR-WB;audio/basic;audio/flac;audio/midi;audio/mp2;audio/mp4;audio/mpeg;audio/mpegurl;audio/ogg;audio/prs.sid;audio/vnd.rn-realaudio;audio/x-aiff;audio/x-ape;audio/x-flac;audio/x-gsm;audio/x-it;audio/x-m4a;audio/x-matroska;audio/x-mod;audio/x-mp3;audio/x-mpeg;audio/x-mpegurl;audio/x-ms-asf;audio/x-ms-asx;audio/x-ms-wax;audio/x-ms-wma;audio/x-musepack;audio/x-pn-aiff;audio/x-pn-au;audio/x-pn-realaudio;audio/x-pn-realaudio-plugin;audio/x-pn-wav;audio/x-pn-windows-acm;audio/x-realaudio;audio/x-real-audio;audio/x-s3m;audio/x-sbc;audio/x-scpls;audio/x-speex;audio/x-stm;audio/x-tta;audio/x-wav;audio/x-wavpack;audio/x-vorbis;audio/x-vorbis+ogg;audio/x-xm;image/vnd.rn-realpix;image/x-pict;misc/ultravox;text/google-video-pointer;text/x-google-video-pointer;video/3gp;video/3gpp;video/dv;video/divx;video/fli;video/flv;video/mp2t;video/mp4;video/mp4v-es;video/mpeg;video/msvideo;video/ogg;video/quicktime;video/vivo;video/vnd.divx;video/vnd.mpegurl;video/vnd.rn-realvideo;video/vnd.vivo;video/webm;video/x-anim;video/x-avi;video/x-flc;video/x-fli;video/x-flic;video/x-flv;video/x-m4v;video/x-matroska;video/x-mpeg;video/x-mpeg2;video/x-ms-asf;video/x-ms-asx;video/x-msvideo;video/x-ms-wm;video/x-ms-wmv;video/x-ms-wmx;video/x-ms-wvx;video/x-nsv;video/x-ogm+ogg;video/x-theora+ogg;video/x-totem-stream;x-content/video-dvd;x-content/video-vcd;x-content/video-svcd;x-scheme-handler/mms;x-scheme-handler/mmsh;
X-FullPathIcon=/usr/local/share/pixmaps/parole.png

Actions=Play;Previous;Next;' > $APP

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

echo '#!/bin/sh
USER=`cat /etc/sysconfig/tcuser`
[ -d /run/user/$USER ] || mkdir -p /run/user/$USER
export XDG_RUNTIME_DIR=/run/user/$USER ' > $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
###########
LIST="$P "
for Z in $LIST
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:          parole.tcz  
Description:    gtk3 media player 
Version:        1.0.5
Author:         Ali Abdallah, Simon Steinbeiss & Sean Davis
Original-site:  https://docs.xfce.org/apps/parole/start
Copying-policy: GPL v2
Size:           280K		
Extension_by:   aus9
Tags:           gtk3 video audio player  
Comments:       Online docs with extra links here
                https://docs.xfce.org/apps/parole/start
                home config is 
                ~/.config/xfce4/xfconf/xfce-perchannel-xml/parole.xml
                
                AUDIO - Set up Alsa first, Read apulse for 
                analog users on how to swap index.
                               
                VIDEO (I own a RPi 4 My suggested config )
                mount partition 1 and edit config.txt so it reads
                [pi4]
                dtoverlay=vc4-kms-v3d-pi4
                max_framebuffers=1
                gpu_mem=256
                hdmi_enable_4kp60=1
                (full reboot)
                
                If RAM less than 1G see
                https://www.raspberrypi.org/documentation/configuration/config-txt/memory.md
                RPi 3 users may need to vary config options YMMV

                Video sub-titles not tested. You may need more fonts.
                
                If you load xscreensaver, $ killall xscreensaver

                Fullscreen mp4 on large monitors more likely to glitch/drop frames
                On my 22 inch, my AAC encoded mp4 file, full screen causes jerky
                unwatchable video. With above settings plays OK with resized 
                18 inch window.

Change-log:     2020/10/22 original v 1.0.5 on 12x 
Current:        2020/10/22   '> $P.tcz.info

echo 'gtk3.tcz
libxfce4ui.tcz
taglib.tcz
dbus-glib.tcz
gst-plugins-good.tcz
gst-plugins-bad.tcz
gst-plugins-ugly.tcz 
gst-libav.tcz 
alsa.tcz   ' > $P.tcz.dep

