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

export CFLAGS="-mtune=generic -Os -pipe"
export CXXFLAGS="-mtune=generic -Os -pipe -fexceptions "

P=audacious
V=4.5.1
SRC=$P-$V
USER=`cat /etc/sysconfig/tcuser`
LIST="compiletc submitqc gtk2-dev gettext "
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://distfiles.$P-media-player.org/$SRC.tar.bz2   " $USER 
tar jxvf $SRC*bz2
cd $SRC
./configure --prefix=/usr/local --localstatedir=/var --disable-qt  --disable-dbus --enable-gtk2
# disable dbus does not build audtool so dbus needed   
# Install path:                           /usr/local
# D-Bus support:                          yes
# GTK+ support:                           yes
# Qt support:                             no
# libarchive support:                     no
# Valgrind analysis support:              no
find . -name buildsys.mk -type f -exec sed -i 's/-g -O2//g' {} \;
make -j5 # 10 seconds
make install DESTDIR=/tmp/$P # no strip
cd /tmp

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

# dev
#####
mkdir -p $P-dev/usr/local/lib/
mv $P/usr/local/include $P-dev/usr/local
mv $P/usr/local/lib/pkgconfig $P-dev/usr/local/lib/

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

# main
######
# audacious expects docs non-std pathway u loc share $P (not doc $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/audacious.png' >> $P/usr/local/share/applications/$P.desktop

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

strip --strip-unneeded $P/usr/local/lib/*
strip --strip-unneeded $P/usr/local/bin/*

# due to some strange error....use install script to make exe 755 later
mkdir -p $P/usr/local/share/$P/files
mv $P/usr/local/bin/$P  $P/usr/local/share/$P/files

# install script
################
mkdir -p $P/usr/local/tce.installed
cat >> $P/usr/local/tce.installed/$P <<'EOF'
#!/bin/sh
gtk-update-icon-cache -q -f -t /usr/local/share/icons/hicolor
update-mime-database /usr/local/share/mime 

# there is some strange activity with normal build for me, fix below
P=audacious
FILE=/tmp/tcloop/$P/usr/local/share/$P/files/$P
[ -x /usr/local/bin/$P ] || cp $FILE /usr/local/bin/
chmod 755 /usr/local/bin/$P
EOF
chown -R root:staff $P/usr/local/tce.installed
chmod -R 775 $P/usr/local/tce.installed

# TCZ them
#######
LIST="$P $P-dev $P-doc $P-locale "
for Z in $LIST
do
	mksquashfs $Z $Z.tcz
	md5sum $Z.tcz > $Z.tcz.md5.txt
	cd $Z
	find . -not -type d | cut -c 2- | sort > /tmp/$Z.tcz.list
	cd /tmp
done

ls -hal

echo 'Title:          audacious-dev.tcz
Description:    dev files
Version:        4.5.1
Author:         https://github.com/audacious-media-player/audacious/blob/master/AUTHORS         
Original-site:  https://distfiles.audacious-media-player.org/
Copying-policy: multiple see COPYING
Size:           60K           
Extension_by:   aus9 @linuxquestions.org
Tags:           audio media player gtk2
Comments:       This is a dep of audacious-plugins-dev
                
Change-log:     2014/02/11 v 3.4.3 (Juanito)
                2016/02/07 v 3.7.1
                2019/04/19 v 3.9
                2024/05/30 v 4.3.1 on 15x, gtk3->2 (aus9) 
Current:        2025/11/16 v 4.5.1 on 16x change RUN dep order  ' > $P-dev.tcz.info
echo 'audacious.tcz
gtk2-dev.tcz' > $P-dev.tcz.dep

echo 'Title:          audacious-doc.tcz
Description:    man page
Version:        4.5.1
Author:         https://github.com/audacious-media-player/audacious/blob/master/AUTHORS         
Original-site:  https://distfiles.audacious-media-player.org/
Copying-policy: multiple see main TCE, COPYING
Size:           8.0K           
Extension_by:   aus9 @linuxquestions.org
Tags:           audio media player gtk2
Comments:       man page contains keybindings info
                
       Control + Return        Play
       Space, Control + ,      Pause
       Control + .             Stop
       Alt + Up                Previous song
       Alt + Down              Next song
       Right arrow             Seek forward (by default 5 seconds)
       Left arrow              Seek backward (by default 5 seconds)
       Escape                  Scroll to current song
       Control + a             Select all songs in playlist
       Shift + Control + a     Cancel selection
       Control + + (plus)      Increase volume 5 percent
       Control + - (minus)     Decrease volume 5 percent
       Control + s             Toggle shuffle
       Control + r             Toggle repeat
       Control + n             Toggle advancing in playlist
       Control + m             Toggle stopping after current song
       Control + e             Display Equalizer
       Control + y             Display Search Tool
       Control + i             Display Song Information dialog
       Control + k             Display Jump to Time dialog
       Control + j             Display Jump to Song dialog
       Control + p             Display Playlist Manager dialog
       Control + u             Display Queue Manager dialog
       Control + o             Display Open Files dialog
       Shift + Control + o     Display Add Files dialog
       Control + l             Display Open URL dialog
       Shift + Control + l     Display Add URL dialog
                
Change-log:     2024/05/30 v 4.3.1 on 15x
                2024/05/30 v 4.3.1 on 15x, gtk3->2 (aus9) 
Current:        2025/11/16 v 4.5.1 on 16x change RUN dep order  ' > $P-doc.tcz.info
echo 'man-db.tcz' > $P-doc.tcz.dep

echo 'Title:          audacious-locale.tcz
Description:    langauge files
Version:        4.5.1
Author:         https://github.com/audacious-media-player/audacious/blob/master/AUTHORS         
Original-site:  https://distfiles.audacious-media-player.org/
Copying-policy: multiple see COPYING
Size:           476K           
Extension_by:   aus9 @linuxquestions.org
Tags:           audio media player gtk2
Comments:       UPGRADE WARNING audacious-locale is now a dep of
                audacious-plugins-locale. If this TCE is in your boot list
                change it to audacious-plugins-locale.tcz
                
Change-log:     2014/02/11 v 3.4.3 (Juanito)
                2016/02/07 v 3.7.1
                2019/04/19 v 3.9
                2024/05/30 v 4.3.1 on 15x, gtk3->2 (aus9) 
Current:        2025/11/16 v 4.5.1 on 16x change RUN dep order  ' > $P-locale.tcz.info
echo 'audacious.tcz' > $P-locale.tcz.dep

echo 'Title:          audacious.tcz
Description:    gtk2 GUI audio player
Version:        4.5.1
Author:         https://github.com/audacious-media-player/audacious/blob/master/AUTHORS         
Original-site:  https://distfiles.audacious-media-player.org/
Copying-policy: multiple see COPYING
Size:           376K           
Extension_by:   aus9 @linuxquestions.org
Tags:           audio media player gtk2
Comments:       UPGRADE WARNING this TCE is now a dep of
                audacious-plugins. If this TCE is in your boot 
                list change it to audacious-plugins.tcz

                No fuss audio.... pulldown File Settings Audio 
                pulldown audio plugin and choose sdl2
                -> playback should work with no further setup
                alsa or pulseaudio plugins assumes setup. 
                filewriter is not a playback plugin its a write plugin

                To play cd -> Services -> play cd
                See doc info for keybindings 
                
                Some common issues discussed here
                https://audacious-media-player.org/problems

                Optional TCES 
                faad2 for aac file formats
                See streaming or add curl neon mpg123 wavpack opusfile 
                
                Streaming sites (URL)
                ############### If its a true audio URL, mpg123 should stream it. 
                I suggest you bookmark this list of 1196 audio streams by Axel Schneider
                but contains some 404 = stale links
                https://gist.github.com/Axel-Erfurt/3b1965ac233f65a4f968a649c7ae40bf
                
                ERROR=unknown URI scheme is resolved by loading curl and neon
                ERROR=unknown plugin -> close gui open a terminal and run audacious again
                with your target URL, you will see which shared object(s) you are missing 
                eg number 63, I was missing libmpg123.so.0 -> load mpg123 
                Always exit the GUI and restart it to start streaming if you have loaded TCES
                If still error + no more shared objects show up, URL is stale or incomplete             
                
                audtool is CLI player
                                
Change-log:     2014/02/11 v 3.4.3 (Juanito)
                2016/02/07 v 3.7.1
                2019/04/19 v 3.9
                2024/05/30 v 4.3.1 on 15x, gtk3->2 (aus9) 
Current:        2025/11/16 v 4.5.1 on 16x change RUN dep order   ' > $P.tcz.info

readelf -d $P/usr/local/bin/* | grep 'NEEDED'
#libglib-2.0.so.0]libgio-2.0.so.0]libgobject-2.0.so.0glib2 -> at-spi2-core -> gtk2
readelf -d $P/usr/local/share/$P/files/* | grep 'NEEDED'
#libaudcore.so.5]this TCE

readelf -d $P/usr/local/lib/*.so | grep 'NEEDED' 
#libglib-2.0.so.0]libgmodule-2.0.so.0]libgio-2.0.so.0]libgobject-2.0.so.0]glib2 gtk2
#libgtk-x11-2.0.so.0]libgdk-x11-2.0.so.0]gtk2
#libpangocairo-1.0.so.0]libpango-1.0.so.0]libpangoft2-1.0.so.0] pango gtk2
#libatk-1.0.so.0]at-spi2-core gtk2
#libcairo.so.2]cairo gtk2
#libgdk_pixbuf-2.0.so.0]gdk-pixbuf2  gtk2
#libharfbuzz.so.0]harfbuzz  gtk2
#libfontconfig.so.1]fontconfig gtk2
#[libfreetype.so.6]freetype gtk2

ldd audacious/usr/local/bin/audtool
# libpcre2-8.so.0  libpcre21042 gtk2
# libffi.so.8 libffi gtk2
ldd audacious/usr/local/share/audacious/files/audacious # no extras

echo 'gtk2.tcz  ' > $P.tcz.dep

submitqc --libs 
rm -rf *.zsync

