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

# impossible slow finalize using cdrkit, go back to cdrtools
export CFLAGS="-mtune=generic -Os -pipe"
export CXXFLAGS="-mtune=generic -Os -pipe -fno-exceptions -fno-rtti"

P=brasero
V=3.12.3
SRC=$P-$V
USER=`cat /etc/sysconfig/tcuser`
LIST="compiletc submitqc cdrtools dvd+rw-tools gobject-introspection-dev gst-plugins-bad-dev \
gtk3-gir intltool itstool libburn-dev libcanberra-dev libisofs-dev libnotify-dev nautilus-dev totem-pl-parser-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://download.gnome.org/sources/$P/3.12/$SRC.tar.xz  " $USER 
tar xvf $SRC*xz
cd $SRC
# simplifly the plugins
sed 's|brasero3/plugins|brasero-plugins|' -i configure
# due to make warning below I disabled gir
# brasero-media.c:520: Warning: BraseroMedia: GObject-Introspection specific....
./configure --prefix=/usr/local --disable-gtk-doc --enable-nautilus --enable-introspection=no

# ignores both --disable-static --enable-static=no 
# Using GTK+ 3
# Update caches              : yes
# Build Nautilus extension   : no why not?
# Build inotify              : yes
# Build search pane          : yes
# Build playlist pane        : yes
# Build Preview pane         : yes
# Plugins installed in : ${exec_prefix}/lib/brasero-plugins  
# Build cdrdao plugins       : yes 
# Build cdrtools plugins     : yes
# Build cdrkit plugins       : yes
# Build growisofs plugins    : yes
# Build libburnia plugins    : yes
# Build GObject-Introspection: no
find . -name Makefile -type f -exec sed -i 's/-O2/ /g' {} \;
make -j5 # 40sec with gir and warnings to 20s
make install-strip DESTDIR=/tmp/$P
cd /tmp

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

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

# locale
#########
mkdir -p $P-locale/usr/local/share
mv $P/usr/local/share/locale $P-locale/usr/local/share
mv $P/usr/local/share/help $P-locale/usr/local/share/

# main
######
mkdir -p $P/usr/local/share/doc/$P
echo 'GPL v2' > $P/usr/local/share/doc/$P/COPYING
mkdir -p $P/usr/local/share/pixmaps
cp $P/usr/local/share/icons/hicolor/48x48/apps/brasero.png $P/usr/local/share/pixmaps
APP=$P/usr/local/share/applications/$P.desktop
echo 'X-FullPathIcon=/usr/local/share/pixmaps/brasero.png' >> $APP

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

# TCZ them
###########
LIST2="$P $P-locale "
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:          brasero-locale.tcz
Description:    language files inc help
Version:        3.12.3
Author:         Philippe Rouquier         
Original-site:  https://download.gnome.org/sources/brasero 
Copying-policy: GPL v2
Size:           3.5M
Extension_by:   aus9 @ linuxquestions.org
Tags:           audio burn isofs cd dvd gtk3 
Comments:       includes help locales and EN_GB	
                
Change-log:     2024/05/16 v 3.12.13  on 15x 
Current:        2024/05/16                          ' > $P-locale.tcz.info
echo 'brasero.tcz                                   ' > $P-locale.tcz.dep

echo 'Title:          brasero.tcz
Description:    cd/dvd burning application
Version:        3.12.3
Author:         Philippe Rouquier         
Original-site:  https://download.gnome.org/sources/brasero 
Copying-policy: GPL v2
Size:           1.2M 
Extension_by:   aus9 @ linuxquestions.org
Tags:           audio burn isofs cd dvd gtk3 
Comments:       Audio cds depend on your player support. 
                wav mp3 ogg opus supported. While adding files
                to audio project, ensure the type remains audio disc.
                Burnt audio discs do not get mounted, open with a 
                media player eg qmplay2 vlc etc
                If you can mount it, its a data cd.
 
                Basically any file can be added to a data disc.
                Mount issues are similar to disc images below.

                TC isohybrid images and other images need to be
                set manually, they are iso9660 types.
                Disc images, data discs need mounting after
                burn with $ mnttool                 

                A blank disc will never mount.
                                
Change-log:     2013/12/15 v 3.10.0 (Juanito)
                2015/01/20 v 3.12.0
Current:        2024/05/16 v 3.12.13 on 15x (aus9) ' > $P.tcz.info

readelf -d $P/usr/local/bin/* | grep 'NEEDED' # del dupes and TCBs
#libbrasero-media3.so.1]libbrasero-burn3.so.1]libbrasero-utils3.so.1]this TCE
#libnotify.so.4]libnotify
#libcanberra-gtk3.so.0]libcanberra.so.0]libcanberra (provides gst pipeline support )
#libX11.so.6]libX11 -> cairo -> pango -> gtk3 -> libcanberra
#[libgthread-2.0.so.0]libgmodule-2.0.so.0]libgio-2.0.so.0]libgobject-2.0.so.0]libglib-2.0.so.0] continued next line
#######                                                              glib2 -> cairo -> pango -> gtk3 -> libcanberra
#libgstvideo-1.0.so.0]libgstaudio-1.0.so.0]libgsttag-1.0.so.0]libgstpbutils-1.0.so.0]gst-plugins-base -> good
#libgstbase-1.0.so.0]libgstreamer-1.0.so.0] gstreamer -> gst-plugins-base (-> good bad ugly) see below
#libgtk-3.so.0]libgdk-3.so.0]gtk3 -> libcanberra
#libatk-1.0.so.0] at-spi2-core -> gtk3 -> libcanberra
#libpangocairo-1.0.so.0]libpango-1.0.so.0] pango -> gtk3 -> libcanberra
#libharfbuzz.so.0]harfbuzz
#libgdk_pixbuf-2.0.so.0]gdk-pixbuf2 -> gtk3 -> libcanberra
#libcairo-gobject.so.2]libcairo.so.2]cairo -> pango -> gtk3 -> libcanberra
#libxml2.so.2]libxml2 -> tracker3 --------------------------but on testing we need tracker-miners3
#libtracker-sparql-3.0.so.0] tracker3 -> tracker-miners3
#libtotem-plparser.so.18]totem-pl-parser
#libSM.so.6]libSM
#libICE.so.6]libICE
readelf -d $P/usr/local/lib/$P-plugins/*.so | grep 'NEEDED' | less # 21 PAGES 
#libburn.so.4]on page 12 libburn 
#libisofs.so.6]page 12 libisofs
#  gstreamer TEST finds more deps
# from Juanito $ gst-launch-1.0 playbin uri=file:///$HOME/mp3/without-you.mp3 audio-sink=autoaudiosink
# ERROR: pipeline could not be constructed needs min of 
# libcdda_paranoia.so.0 -> cdparanoia & libgraphene-1.0.so.0 -> graphene....REPEAT for next error
# audio-sink" in element "playbin" -> libgstaasink.so':called libaa ->  aalib ....REPEAT for next error
# then need min of plugins good to get next missing TCE for mp3 its mpg123
#### 
# nautilus did not build & add the dvd TCEs # last 2 for update-mime and gtkupdate 
# submitqc pass1 adds extras at bottom of dep libEGL.tcz
# pass2 attempt to load brasero WARNINGS I treat as errors

# test 
# Failed to load plugin '/usr/local/lib/gstreamer-1.0/libgstaasink.so': libaa.so.1 -> aalib---gst pipeline support
# /usr/local/lib/gstreamer-1.0/libgstdv.so': libdv.so.4   -> libdv
# /usr/local/lib/gstreamer-1.0/libgstmpg123.so': libmpg123.so -> mpg123....mp3 support 
# /usr/local/lib/gstreamer-1.0/libgsttaglib.so': libtag.so.1 -> taglib
# /usr/local/lib/gstreamer-1.0/libgstvpx.so': libvpx.so.6 -> libvpx18.tcz
# /usr/local/lib/gstreamer-1.0/libgstwavpack.so': libwavpack.so -> wavpack

# add support for cd/dvd extra to readelfs as per submitqc
# test no tracker-miners3.tcz  but only tracker3, if add miners delete totem-parser
# test 
# WARNING **: 11:35:51.562: Failed to inhibit the system from suspending: 
# GDBus.Error:org.freedesktop.DBus.Error.ServiceUnknown: The name org.gnome.SessionManager 
# was not provided by any .service files
# solved? internet suggests load gnome-power-manager & dconf??.
# Could not establish a connection to Tracker: The name org.freedesktop.Tracker3.Miner.Files
# solved by adding back tracker-miner3
# test $ brasero -g (gives more errors)

# gtk-update has libEGL dvd*tools has libburn/libisofs in Apps
# cdrkit conflicts with cdrtools load it first by putting at bottom of dep list

echo 'libnotify.tcz
libcanberra.tcz  
gst-plugins-good.tcz
tracker-miners3.tcz
libSM.tcz
libICE.tcz
cdparanoia.tcz
graphene.tcz 
aalib.tcz
libdv.tcz
mpg123.tcz
taglib.tcz  
libvpx18.tcz
wavpack.tcz 
libdvdcss.tcz
dvd+rw-tools.tcz 
libGLESv2.tcz 
shared-mime-info.tcz
gtk-update-icon-cache.tcz 
cdrkit.tcz   '  > $P.tcz.dep

submitqc --libs
rm -rf *.zsync


# test video dvd....$ brasero -g SNIP
#BraseroBurn: (at brasero-caps-plugin.c:456) New caps required Audio RAW RAW (little endian)AUDIO UNDEFINED DTS WAV MP2 AC3 VIDEO UNDEFINED VCD Video DVD Metadata Information format accepts files 
#BraseroBurn: (at brasero-caps-plugin.c:545) Created new caps Audio RAW RAW (little endian)AUDIO UNDEFINED DTS WAV MP2 AC3 VIDEO UNDEFINED VCD Video DVD Metadata Information 
#BraseroBurn: (at brasero-caps-plugin.c:456) New caps required Audio RAW RAW (little endian)AUDIO UNDEFINED DTS WAV MP2 AC3 VIDEO UNDEFINED VCD Video DVD format accepts files 
#BraseroBurn: (at brasero-caps-plugin.c:545) Created new caps Audio RAW RAW (little endian)AUDIO UNDEFINED DTS WAV MP2 AC3 VIDEO UNDEFINED VCD Video DVD 
# mplex" GStreamer plugin could not be found
# mpeg2enc" GStreamer plugin could not be found
# avenc_mp2" GStreamer plugin could not be found
# avenc_ac3" GStreamer plugin could not be found

# BELOW not needed loading to make audio cd/isohybrid image or normal data images
#(gst-plugin-scanner:10637): GStreamer-WARNING **: 15:28:15.466: Failed to load plugin 
#'/usr/local/lib/gstreamer-1.0/libgstflac.so': libFLAC.so.8: cannot open shared object file: No such file or directory
#(gst-plugin-scanner:10637): GStreamer-WARNING **: 15:28:15.479: Failed to load plugin 
#'/usr/local/lib/gstreamer-1.0/libgstlame.so': libmp3lame.so.0: cannot open shared object file: No such file or directory
#(gst-plugin-scanner:10637): GStreamer-WARNING **: 15:28:15.486: Failed to load plugin '
#/usr/local/lib/gstreamer-1.0/libgstpulseaudio.so': libpulse.so.0: cannot open shared object file: No such file or directory
#(gst-plugin-scanner:10637): GStreamer-WARNING **: 15:28:15.501: Failed to load plugin '
#/usr/local/lib/gstreamer-1.0/libgstspeex.so': libspeex.so.1: cannot open shared object file: No such file or directory
#(gst-plugin-scanner:10637): GStreamer-WARNING **: 15:28:15.509: Failed to load plugin '
# /usr/local/lib/gstreamer-1.0/libgstvideo4linux2.so': libv4l2.so.0: cannot open shared object file: No such file or directory


