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

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

P=aqualung
V=2.0
SRC=$P-$V
USER=`cat /etc/sysconfig/tcuser`
LIST="compiletc submitqc gtk3-dev alsa-dev libcdio-paranoia-dev libXcursor-dev libepoxy-dev \
lame-dev  libsamplerate-dev intltool libmad-dev wavpack-dev libXcomposite-dev libXinerama-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://github.com/jeremyevans/$P/releases/download/$V/$SRC.tar.gz"  $USER
tar xvf $SRC*gz
cd $SRC
# src =sample rate converter (must have)
./configure --prefix=/usr/local --without-ifp --without-jack --without-ladspa \
--without-lavc  --without-lua --without-mod --without-mpc  --without-oss --without-pulse  \
--without-sndio --without-speex --with-alsa --with-flac --with-lame --with-mpeg --with-src \
--with-cdda --with-cddb --with-vorbis --with-vorbisenc --disable-podcast  --disable-rpath

# LADSPA plugin support        : no
# CDDA (Audio CD) support      : yes (found)
# CDDB support                 : yes (found)
# Sample Rate Converter support: yes
# iRiver iFP driver support    : no
# JACK port management support : no
# Loop playback support        : yes
# Systray support              : yes
# Podcast support              : no
# Lua extension support        : no

#      Decoding support:
# sndfile (WAV, AIFF, AU, etc.)   : yes (found)
# Free Lossless Audio Codec (FLAC): yes
# Ogg Vorbis                      : yes 
# Ogg Speex                       : no
# MPEG Audio (MPEG 1-2.5 Layer I-III): yes 
# MOD Audio (MOD, S3M, XM, IT, etc.) : no
# Musepack                           : no
# Monkey's Audio Codec               : not found
# WavPack                            : yes (found)
# LAVC (AC3, AAC, WavPack, WMA, etc.): no
#               Encoding support:
# sndfile (WAV)                   : yes (found)
# Free Lossless Audio Codec (FLAC): yes
# Ogg Vorbis                      : yes 
# LAME (MP3)                      : yes 
#             Output driver support:
# sndio Audio      : no
# OSS Audio        : no
# ALSA Audio       : yes (found)
# JACK Audio Server  no
# PulseAudio       : no
# Win32 Sound API:  not supported on linux-gnu
#######################################
make -j6  # 5 seconds 
make install-strip DESTDIR=/tmp/$P
cd /tmp

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


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

# main
#####
# they are of no use so
rm -rf $P/usr/local/share/doc
# no desktop was compiled make a basic one
mkdir -p $P/usr/local/share/pixmaps
cp $P/usr/local/share/aqualung/icon_48.png $P/usr/local/share/pixmaps/$P.png
APP=$P/usr/local/share/applications
mkdir -p $APP
echo '[Desktop Entry]
Name=aqualung
Exec=aqualung
Terminal=false
StartupNotify=true
Type=Application
Categories=Audio;Player
Icon=aqualung
X-FullPathIcon=/usr/local/share/pixmaps/aqualung.png'  > $APP/$P.desktop

mkdir -p $P/usr/local/share/doc/$P
echo 'GPL v2' >> $P/usr/local/share/doc/$P/COPYING

# TCZ them
###########
LIST2="$P  $P-locale $P-doc"
for Z in $LIST2
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:          aqualung-doc.tcz
Description:    man page
Version:        2.0
Author:         Tom Szilagyi
Original-site:  http://aqualung.jeremyevans.net/
Copying-policy: GPL v2 
Size:           8.0K          		
Extension_by:   aus9  
Tags:           man page
Comments:       -

Change-log:     2020/05/16 v 1.0 on 11x
Current:        2025/11/16 v 2.0 on 16x no podcast gtk2->3 more codecs -skins are now themes ' > $P-doc.tcz.info
echo 'man-db.tcz' > $P-doc.tcz.dep

echo 'Title:          aqualung-locale.tcz
Description:    language files 
Version:        2.0
Author:         Tom Szilagyi
Original-site:  http://aqualung.jeremyevans.net/
Copying-policy: GPL v2 
Size:           404K          		
Extension_by:   aus9  
Tags:           gtk3 audio player rip ripper
Comments:       untested by me

Change-log:     2020/05/16 v 1.0 on 11x
Current:        2025/11/16 v 2.0 on 16x no podcast gtk2->3 more codecs -skins are now themes ' > $P-locale.tcz.info
echo 'aqualung.tcz' > $P-locale.tcz.dep

echo 'Title:          aqualung.tcz
Description:    gtk3 graphical cd audio player and ripper
                Plays local wav, flac, ogg & mp3 files as below 
Version:        2.0
Author:         Tom Szilagyi
Original-site:  http://aqualung.jeremyevans.net/
Copying-policy: GPL v2 
Size:           420K          		
Extension_by:   aus9  
Tags:           gtk3 audio player rip ripper
Comments:       Ensure sound works for Alsa as pulseaudio disabled.
                If your device is not hw0,0 run aplay -l then try
                $ aqualung ‐d plughw:1,2 (eg)
                https://aqualung.jeremyevans.net/manual/aqualung-doc.html
                Below I assume you are RIGHT handed mouse user
 
                There is about 5 second delay before play button works. YMMV
                If you try to add a file and it does not appear in your list,
                its not a format I have compiled support for.

                Click the MS or PL buttons  to toggle on/off the music 
                store or playlist. For a right hand mouse user, RH click nearly 
                anywhere in the GUI, will bring up a control panel.
                You will probably want to adjust DSP -> sample rate converter

                There is a volume slider and a left-right channel slider at top.

                To play audio cd ensure MS button is on. 
                 -------CD Audio should appear in store.
                Double Left click it to add to your playlist.
                Click the playlist entry. Cick play to play entire cd.
                To play a specific track, click the button to the left of 
                cd-name and choose track then click play at top. 
                Or use the MS playlist menu to add a specific track 
                 to your playlist.

                To rip try $ mkdir -p $HOME/rips...start GUI               
                After seeing below CD Audio, your cd album name in MS,
                RH click that name, select rip in context menu 
                In source TAB - choose all or one track etc
                In output TAB - change dir to /home/tc/rips
                ....wav has no options while flac, ogg & mp3 have options
                In Paranoia TAB I leave defaults alone YMMV  

                To play local files try
                $ cd media-file-dir
                $ aqualung file1 file2 etc
                GUI appears -> click the play button
                click next track button if bored                

                Dark gtk themes make it hard to see some buttons.
                                     
Change-log:     2020/05/16 v 1.0 on 11x
                2024/04/22 v 1.2 on 15x
Current:        2025/11/16 v 2.0 on 16x no podcast gtk2->3 more codecs -skins are now themes ' > $P.tcz.info

readelf -d $P/usr/local/bin/$P | grep 'NEEDED'
#libxml2.so.2] libxml2 gtk3
#libgtk-3.so.0]#libgdk-3.so.0]gtk3
#libpangocairo-1.0.so.0]#libpango-1.0.so.0]pango gtk3
#libharfbuzz.so.0]harfbuzz gtk3
#libatk-1.0.so.0]at-spi2-core gtk3
#libcairo-gobject.so.2]#libcairo.so.2]cairo gtk3
#libgdk_pixbuf-2.0.so.0]gdk-pixbuf2 gtk3
#libgio-2.0.so.0]libgobject-2.0.so.0]libglib-2.0.so.0]libgthread-2.0.so.0]glib2 gtk3
#libasound.so.2]libasound 
#libFLAC.so.8] flac libsamplerate
#libmp3lame.so.0]lame 
#libmad.so.0]libmad
#libsndfile.so.1]libsndfile libsamplerate
#libvorbis.so.0]#libvorbisfile.so.3]libvorbisenc.so.2] libvorbis  libsamplerate
#libogg.so.0]libogg libsamplerate
#libwavpack.so.1]wavpack
#libsamplerate.so.0]libsamplerate
#libcdio_paranoia.so.2]libcdio_cdda.so.2]libcdio.so.18]libcdio-paranoia
#libcddb.so.2]libcddb libcdio-paranoia

echo 'gtk3.tcz
libasound.tcz
lame.tcz
libmad.tcz
libsamplerate.tcz
wavpack.tcz
libcdio-paranoia.tcz' > $P.tcz.dep

submitqc --libs
rm -rf *.zsync
