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

# cheat off LFS, pulsaudio-dev dep of ffmeg5dev,  wayland-dev dep libEGL-dev dep librsvg-dev dep ffmpeg4-dev
export CFLAGS="-mtune=generic -Os -pipe"
export CXXFLAGS="-mtune=generic -Os -pipe "

P=audacious-plugins
V=4.3.1
SRC=$P-$V
USER=`cat /etc/sysconfig/tcuser`
LIST="compiletc submitqc audacious-dev curl-dev faad-dev ffmpeg5-dev \
libnotify-dev libxml2-dev mpg123-dev neon-dev opusfile-dev pipewire-dev wavpack-dev  "
for Z in $LIST
    do 
    su -c "tce-load -i $Z" $USER
done

ls /usr/local/tce.installed/ | grep libav* | grep 4  # we want no  no av*4 have loaded 

cd /tmp
su -c "/usr/local/bin/wget -nc --no-check-certificate \
https://distfiles.audacious-media-player.org/$SRC.tar.bz2   " $USER 
tar jxvf $SRC*bz2
cd $SRC
sed '16 a #include <libxml/parser.h>' -i src/scrobbler2/scrobbler.h
./configure --prefix=/usr/local --localstatedir=/var --disable-qt --disable-oss4 --disable-pipewire
  
# Install path:                           /usr/local/lib/audacious
# GTK+ support:                           yes
# Qt support:                             no

# Audio Formats
# Audio CD:                               yes
# Free Lossless Audio Codec:              yes
# Ogg Vorbis:                             yes
# Opus:                                   yes
# MIDI (via FluidSynth):                  no
# MPEG-1 Layer I/II/III (via mpg123):     yes
# MPEG-2/4 AAC:                           yes
# WavPack:                                yes

# External Decoders
# FFmpeg:                                 yes
# libsndfile:                             yes

# Chiptunes
# AdLib synthesizer (adplug):             no
# Commodore 64 audio (sid):               no
# Game Music Emu (spc, nsf, gbs, etc.):   yes
# ModPlug:                                no
# OpenMPT:                                no
# Nintendo DS audio (xsf):                yes
# PlayStation audio (psf/psf2):           yes
# Vortex Tracker (vtx):                   yes

# Other Inputs
# Metronome:                              yes
# Tone Generator:                         yes

# Effects
# Bauer stereophonic-to-binaural (bs2b):  no
# Bitcrusher:                             yes
# Channel Mixer:                          yes
# Crystalizer:                            yes
# Dynamic Range Compressor:               yes
# Echo/Surround:                          yes
# Extra Stereo:                           yes
# LADSPA Host (requires GTK+):            yes
# Sample Rate Converter:                  no
# Silence Removal:                        yes
# SoX Resampler:                          no
# Speed and Pitch:                        no
# Voice Removal:                          yes

# Outputs
# Advanced Linux Sound Architecture:      yes
# Jack Audio Connection Kit:              no
# Open Sound System:                      no
# PipeWire:                               no
# PulseAudio:                             yes
# Simple DirectMedia Layer:               yes
# Sndio:                                  no
# Win32 waveOut:                          no
# FileWriter:                             yes
# MP3 encoding:                           yes
# Vorbis encoding:                        yes
# FLAC encoding:                          yes

# Playlists
# Cue sheets:                             no
# M3U playlists:                          yes
# Microsoft ASX (legacy):                 yes
# Microsoft ASX 3.0:                      yes
# PLS playlists:                          yes
# XML Sharable Playlist Format (XSPF):    yes

# Transports
# FTP, SFTP, SMB (via GIO):               yes
# HTTP/HTTPS (via neon):                  yes
# MMS (via libmms):                       no

# General
# Ampache browser (requires Qt):          no
# Delete Files:                           yes
# libnotify OSD:                          yes
# Linux Infrared Remote Control (LIRC):   no
# MPRIS 2 Server:                         yes
# Scrobbler 2.0:                          yes
# Song Change:                            yes
  
# GTK+ Support                          
# GTK Interface:                          yes
# Winamp Classic Interface:               yes
# Album Art:                              yes
# Blur Scope:                             yes
# OpenGL Spectrum Analyzer:               yes
# Playlist Manager:                       yes
# Search Tool:                            yes
# Spectrum Analyzer (2D):                 yes
# Status Icon:                            yes
# X11 Global Hotkeys:                     yes
# X11 On-Screen Display (aosd):           yes

find . -name buildsys.mk -type f -exec sed -i 's/-g -O2//g' {} \;
make -j5 # 20 seconds
make install DESTDIR=/tmp/$P # no strip
cd /tmp

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

# main
######
mkdir -p $P/usr/local/share/doc/$P
cp $SRC/COPYING $P/usr/local/share/doc/$P/COPYING-main

DIR=/tmp/$P/usr/local/lib/audacious
LIST2="Container Effect General Input Output Transport Visualization"
for Z in $LIST2
do
	cd $DIR/$Z
        strip --strip-unneeded *
done
cd /tmp

# TCZ them
#######
LIST="$P $P-locale "
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
done

ls -hal

echo 'Title:          audacious-plugins-locale.tcz
Description:    language files
Version:        4.3.1
Author:         plugin framework = audacious developers
                specific plugins  see below       
Original-site:  https://distfiles.audacious-plugins-media-player.org/
Copying-policy: accompanied
Size:           1.6M                      
Extension_by:   aus9 @linuxquestions.org
Tags:           audio player 
Comments:       locales

                plugin authors are not easy to find.
                Instead they are named in the *.h or *.cc files found here
                https://github.com/audacious-media-player/audacious-plugins/tree/master/src
eg https://github.com/audacious-media-player/audacious-plugins/blob/master/src/alsa/alsa.cc 
                
Change-log:     2024/05/30 v 4.3.1 on 15x
Current:        2024/05/30  ' > $P-locale.tcz.info
echo 'audacious-plugins.tcz' > $P-locale.tcz.dep

echo 'Title:          audacious-plugins.tcz
Description:    plugins for audacious
Version:        4.3.1
Author:         plugin framework = audacious developers
                specific plugins  see below        
Original-site:  https://distfiles.audacious-plugins-media-player.org/
Copying-policy: accompanied
Size:           1008K                     
Extension_by:   aus9 @linuxquestions.org
Tags:           audio player 
Comments:       Optional TCES 
                curl & neon for streaming
                faad for aac file formats
                libnotify if you need notifications
                Most other audio files supported
                
                plugin authors are not easy to find.
                Instead they are named in the *.h or *.cc files found here
                https://github.com/audacious-media-player/audacious-plugins/tree/master/src
eg https://github.com/audacious-media-player/audacious-plugins/blob/master/src/alsa/alsa.cc
                
Change-log:     2014/02/11 v 3.4.3 (Juanito)
                2016/02/07 v 3.7.1
                2019/04/19 v 3.9
Current:        2024/05/30 v 4.3.1 on 15x (aus9) ' > $P.tcz.info

DIR=/tmp/$P/usr/local/lib/audacious
LIST2="Container Effect General Input Output Transport Visualization"
for Z in $LIST2
do
	cd $DIR/$Z
        readelf -d *.so | grep 'NEEDED'
        cd /tmp
done
# there were 539 outputs to above, a new record !!
# libavdevice5 AV=libavdevice5.tcz checked Apps gui for AV

#libaudcore.so.5]libaudgui.so.5]libaudtag.so.3] audacious (plugins is a dep of parent)
#libxml2.so.2]libxml2
#libglib-2.0.so.0]libgio-2.0.so.0]libgobject-2.0.so.0]libgmodule-2.0.so.0]glib2->at-spi2-core-> gtk2
#libpangocairo-1.0.so.0]libpango-1.0.so.0]libpangoft2-1.0.so.0]pango->gtk2 
#libharfbuzz.so.0]harfbuzz -> freetype -> fontconfig -> cairo->pango->gtk2  
#libatk-1.0.so.0]at-spi2-core->                                       gtk2
#libcairo-gobject.so.2]libcairo.so.2]cairo -> pango ->                gtk2
#libgdk_pixbuf-2.0.so.0]gdk-pixbuf2 ->                                gtk2
#libXrender.so.1]libXrenderv  -> libXft -> pango ->                   gtk2
#libX11.so.6]libX11 -> pango ->                                       gtk2
#libXcomposite.so.1]libXcomposite ->                                  gtk2
#libnotify.so.4]                                                  libnotify  make optional as per Juanito
#libcurl.so.4]                                                    curl ditto
#libfaad.so.2]                                                    faad ditto
#libcdio_cdda.so.2] libcdio-paranoia = found with                       AV
#libcdio.so.18]libcdio.tcz -> libcdio-paranoia-->                       AV
#libcddb.so.2] libcddb.tcz libcdio.tcz -> libcdio-paranoia ->           AV
#libavcodec.so.59]libavcodec5 = AV....assume Juanito happy avdevice5=   AV 
#libavformat.so.59]libavformat5 =                                       AV
#libavutil.so.57]libavutil5 =                                           AV
#libFLAC.so.8]flac -> libsndfile ->                                     AV
#libmpg123.so.0]                                                  mpg123 
#libopus.so.0]opus ->                                                   AV
#libopusfile.so.0]                                             opusfile 
#libsndfile.so.1]libsndfile ->                                          AV
#libogg.so.0]libogg   ->                                                AV
#libvorbis.so.0]libvorbisenc.so.2]libvorbisfile.so.3]libvorbis          AV
#libwavpack.so.1]                                                wavpack....built in not Juanito way  
#libasound.so.2]libasound                                               AV
#libmp3lame.so.0]lame -> libavcodec5=                                   AV  
#libpulse.so.0]libpulseaudio                                            AV
#libSDL2-2.0.so.0]sdl2                                                  AV
#libneon.so.27]                                                     neon leave out as per Juanito
#libGL.so.1]libGL                                                       AV
#[libfontconfig.so.1]fontconfig -> cairo -> pango ->                    gtk2
#[libfreetype.so.6]freetype -> fontconfig -> cairo -> pango ->          gtk2

echo 'libxml2.tcz
gtk2.tcz
libavdevice5.tcz
mpg123.tcz
opusfile.tcz
wavpack.tcz        ' > $P.tcz.dep

submitqc --libs # Pass 1 tries to add audacious and others
rm -rf *.zsync

# dbus needed as per audacious to build audtool but not needed to run


