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

# checking if gcc supports -fno-rtti -fno-exceptions... no
export CFLAGS="-mtune=generic -Os -pipe"
export CXXFLAGS="-mtune=generic -Os -pipe "

P=mpg123
V=1.32.6
SRC=$P-$V
USER=`cat /etc/sysconfig/tcuser`
LIST="compiletc submitqc alsa-dev pulseaudio-dev sdl2-dev portaudio-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://sourceforge.net/projects/$P/files/$P/$V/$SRC.tar.bz2  " $USER 
tar jxvf $SRC*bz2
cd $SRC # with optim* should remove need for -O2 sed
./configure --prefix=/usr/local --disable-static --localstatedir=/var --with-optimization=0 \
--with-audio=alsa,dummy,portaudio,pulse,sdl 

# Install path ............ /usr/local
# Components .............. programs libmpg123 libout123 libout123-modules libsyn123
# CPU Optimization ........ x86-64
# Compiler Optimization ... 0
# Use yasm (for AVX only) . disabled
# Gapless Support ......... enabled
# Debugging ............... disabled
# Terminal control ........ posix
# Extreme debugging ....... disabled
# Seek table size ......... 1000
# FIFO support ............ enabledv
# Buffer .................. enabled
# External network ........ exec
# Internal network type ... posix
# IPv6 (getaddrinfo) ...... enabled
# largefile sensitive ..... no
# default offsets ......... 64
# explicit 64 bit offsets . no
# forced 64 bit offsets ... no
# only portable API ....... no

# Core libmpg123 features:
# Layer I ................. enabled
# Layer II ................ enabled
# Layer III ............... enabled
# NtoM resampling ......... enabled
# downsampled decoding .... enabled
# Feeder/buffered input ... enabled
# ID3v2 parsing ........... enabled
# String API .............. enabled
# ICY parsing/conversion .. enabled
# Error/warning messages .. enabled
# Win32 Unicode File Open.. unneeded
# Feature Report Function.. enabled
# Output formats (nofpu will disable all but 16 or 8 bit!):
# 8 bit integer ........... enabled
# 16 bit integer .......... enabled
# 32/24 bit integer ....... enabled
# real (32 bit float) ..... enabled
# Equalizer ............... enabled
# Optimization detail:
# Integer conversion ...... quality
# IEEE 754 hackery ........ enabled
# New/old WRITE_SAMPLE .... disabled
# new Huffman scheme ...... enabled
# runtime tables .......... disabled

# Note: Disabling core features is not commonly done and some combinations might
# not build/work. If you encounter such a case, help yourself (and provide
# a patch) or just poke the maintainers.

# libsyn123 special cases . enabled

# Modules ................. enabled
# Checked audio modules ... alsa dummy portaudio pulse sdl
# Detected audio support .. alsa dummy portaudio pulse sdl
# Runtime order ........... alsa portaudio pulse sdl

# CPPFLAGS=' -DOPT_MULTI -DOPT_X86_64 -DOPT_GENERIC -DOPT_GENERIC_DITHER -DREAL_IS_FLOAT -DOPT_AVX '
# CFLAGS=' -mtune=generic -Os -pipe'
# PROG_LIBS='-lm '
# (derived from LIBS, only used for end-user binaries and modules)
# LIBDL=''
# LIBMPG123_LIBS='-lm '
# LIBSYN123_LIBS='-lm'
# LIBOUT123_LIBS=' -lm '

# there is no longer any -g nor any -O2 in Makefile....see Optimization and CFLAGS above
make -j5 # seconds
make install-strip 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
#####
rm -rf $P/usr/local/lib/*.la 
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/

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

# TCZ them
###########
LIST2="$P $P-dev $P-doc"
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:          mpg123-dev.tcz
Description:    dev files
Version:        1.32.6
Author:         https://github.com/madebr/mpg123/blob/master-with-github-ci/AUTHORS
Original-site:  http://mpg123.org/
Copying-policy: multiple see COPYING
Size:           72K
Extension_by:   aus9 @linuxquestions.org
Tags:           audio player mpeg mp3
Comments:       Development
                
Change-log:     2016/02/07 v 1.23.0 (Juanito)
                2016/11/20 recompiled for updated pulseaudio
                2020/07/21 v 1.26.3 (Sashank999)
Current:        2024/05/26 v 1.32.6 + sdl2, portaudio support (aus9)   ' > $P-dev.tcz.info
echo 'mpg123.tcz
alsa-dev.tcz 
pulseaudio-dev.tcz 
sdl2-dev.tcz
portaudio-dev.tcz ' > $P-dev.tcz.dep

echo 'Title:          mpg123-doc.tcz
Description:    man pages
Version:        1.32.6
Author:         https://github.com/madebr/mpg123/blob/master-with-github-ci/AUTHORS
Original-site:  http://mpg123.org/
Copying-policy: multiple see COPYING
Size:           20K
Extension_by:   aus9 @linuxquestions.org
Tags:           man
Comments:       man pages
                
Change-log:     2016/02/07 v 1.23.0 (Juanito)
                2016/11/20 recompiled for updated pulseaudio
                2020/07/21 v 1.26.3 (Sashank999)
Current:        2024/05/26 v 1.32.6 + sdl2, portaudio support (aus9)   ' > $P-doc.tcz.info
echo 'man-db.tcz ' > $P-doc.tcz.dep

echo 'Title:          mpg123.tcz
Description:    console or terminal mp3 player
Version:        1.32.6
Author:         https://github.com/madebr/mpg123/blob/master-with-github-ci/AUTHORS
Original-site:  http://mpg123.org/
Copying-policy: multiple see COPYING
Size:           336K
Extension_by:   aus9 @linuxquestions.org
Tags:           audio player mpeg mp3
Comments:       supports alsa, portaudio,pulseaudio or sdl2
                Which needs to be setup first please.

                First use try  $ mpg123 Dir-name/*
                (then input h) to see navigation keybindings
                eg q to quit, space to pause/unpause
                f to forward to next track,
                - to reduce volume, + to increase 

                You can change output device by reading 
                $ man mpg123 or mpg123 --longhelp
                $ mpg123 --list-devices
                (eg) $ mpg123 -a surround41 <path2file.mp3>

                TCE can stream by $ tce-load curl (then eg url)
$ mpg123 --network curl http://stream.zeno.fm/2ptupyw61fxvv
                
Change-log:     2016/02/07 v 1.23.0 (Juanito)
                2016/11/20 recompiled for updated pulseaudio
                2020/07/21 v 1.26.3 (Sashank999)
Current:        2024/05/26 v 1.32.6 + sdl2, portaudio support (aus9)    ' > $P.tcz.info

readelf -d $P/usr/local/lib/*.so | grep 'NEEDED' # only TCBs
readelf -d $P/usr/local/lib/$P/*.so | grep 'NEEDED'
# libasound.so.2] libasound
#libportaudio.so.2] portaudio
# libpulse-simple.so.0]libpulse.so.0] libpulseaudio
# libSDL2-2.0.so.0] sdl2
readelf -d $P/usr/local/bin/* | grep 'NEEDED'
# libmpg123.so.0]libout123.so.0] this TCE
# libsyn123.so.0]there is a libsyn123 TCE but I am using inbuilt!

echo 'libasound.tcz
portaudio.tcz
libpulseaudio.tcz
sdl2.tcz ' > $P.tcz.dep

submitqc --libs
rm -rf *.zsync

