#!/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 -fno-exceptions -fno-rtti "

P=vorbis-tools
O=ogg123
V=1.4.3
SRC=$P-$V
USER=`cat /etc/sysconfig/tcuser`
LIST="compiletc submitqc curl-dev libao-dev opusfile-dev curl-dev "    
for Z in $LIST 
    do 
    su -c "tce-load -i $Z" $USER
done

cd /tmp
/usr/local/bin/wget -nc --no-check-certificate \
https://ftp.osuosl.org/pub/xiph/releases/vorbis/$SRC.tar.gz
tar xvf $SRC*gz
cd $SRC
./configure --prefix=/usr/local --disable-static --localstatedir=/var --without-kate --with-speex
# no kate so will NOT be built with Kate lyrics support....so no oggenc
find . -name Makefile -type f -exec sed -i 's/-pg -g -O2//g' {} \;
find . -name Makefile -type f -exec sed -i 's/-g -O2//g' {} \;
find . -name Makefile -type f -exec sed -i 's/-O2//g' {} \;
make -j6 # 3 seconds
# make creates       codec_opus.o
make install-strip DESTDIR=/tmp/$P
cd /tmp

# ogg123
########
mkdir -p $O/usr/local/bin
mv $P/usr/local/bin/$O $O/usr/local/bin
mkdir -p $O/usr/local/share/doc/$O
echo 'GPL v 2' > $O/usr/local/share/doc/$O/COPYING

# vorbis-tools doc
################## move main here and start afresh for main
mkdir -p $P-doc/usr/local/share
mv $P/usr/local/share/man $P-doc/usr/local/share
mv $P/usr/local/share/doc $P-doc/usr/local/share/
cp $SRC/AUTHORS $P-doc/usr/local/share/doc/$P

# 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 
echo 'GPL v 2' > $P/usr/local/share/doc/$P/COPYING

# TCZ them
#######
LIST="$P $P-doc $P-locale $O "
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:          ogg123.tcz
Description:    CLI ogg or opus player
Version:        1.4.3
Author:         see doc TCE/AUTHORS
Original-site:  https://ftp.osuosl.org/pub/xiph/releases/vorbis
Copying-policy: GPL v 2
Size:           40K
Extension_by:   aus9 @linuxquestions.org
Tags:           audio player ogg opus
Comments:       Play *.oga *.ogg *.ogv files
                but ogv means you will lack the video and
                just get the audio stream

                Play *.opus but you need to follow the info for libao
                and config ~/.libao to either default_driver=alsa or
                default_driver=pulse

                Split from vorbis-tools. 
                Optional TCE for locales=vorbis-tools-locale
                man page in vorbis-tools-doc TCE

Change-log:     2025/01/12 v 1.4.2 on 15x
                2025/12/17 v 1.4.3 on 16x 
Current:        2026/10/02 rebuilt against updated libao + opus support on 17x  ' > $O.tcz.info
readelf -d $O/usr/local/bin/$O | grep 'NEEDED'
# libvorbisfile.so.3]#libvorbis.so.0]libvorbis
# libao.so.4]libao
# libnsl.so.3 libnsl
# libcurl.so.4]curl
# libFLAC.so.8]flac
# libogg.so.0]libogg libvorbis
# libspeex.so.1]speex
# libopusfile.so.0] opusfile

echo 'curl.tcz
flac.tcz
libao.tcz
libnsl.tcz
libvorbis.tcz
speex.tcz 
opusfile.tcz   ' > $O.tcz.dep

echo 'Title:          vorbis-tools-doc.tcz
Description:    man pages + 1 doc
Version:        1.4.2
Author:         see doc TCE/AUTHORS
Original-site:  https://ftp.osuosl.org/pub/xiph/releases/vorbis
Copying-policy: GPL v 2
Size:           16K
Extension_by:   aus9 @linuxquestions.org
Tags:           ogg opus
Comments:       Also contains man page for TCE=ogg123 
                
Change-log:     2025/01/12 v 1.4.2 on 15x
                2025/12/17 v 1.4.3 on 16x 
Current:        2026/10/02 rebuilt against updated libao + opus support on 17x  ' > $P-doc.tcz.info
echo 'man-db.tcz ' > $P-doc.tcz.dep

echo 'Title:          vorbis-tools-locale.tcz
Description:    language files
Version:        1.4.2
Author:         see doc TCE/AUTHORS
Original-site:  https://ftp.osuosl.org/pub/xiph/releases/vorbis
Copying-policy: GPL v 2
Size:           468K
Extension_by:   aus9 @linuxquestions.org
Tags:           ogg opus locale
Comments:       untested by me
                
Change-log:     2025/01/12 v 1.4.2 on 15x
                2025/12/17 v 1.4.3 on 16x 
Current:        2026/10/02 rebuilt against updated libao + opus support on 17x    ' > $P-locale.tcz.info
echo 'vorbis-tools.tcz' > $P-locale.tcz.dep

echo 'Title:          vorbis-tools.tcz
Description:    tools for ogg codec 
Version:        1.4.2
Author:         see doc TCE/AUTHORS
Original-site:  https://ftp.osuosl.org/pub/xiph/releases/vorbis
Copying-policy: GPL v 2
Size:           76K
Extension_by:   aus9 @linuxquestions.org
Tags:           ogg opus audio 
Comments:       CLI tools for ogg codec but 
                ogg123 split into separate TCE
                
Change-log:     2018/01/29 v 1.4.0  (Juanito)
                2025/01/12 v 1.4.2  split out ogg123  (aus9)
                2025/12/17 v 1.4.3 on 16x 
Current:        2026/10/02 rebuilt against updated libao + opus support on 17x   ' > $P.tcz.info

readelf -d $P/usr/local/bin/* | grep 'NEEDED' 
#libvorbisfile.so.3]#libvorbis.so.0] #libvorbisenc.so.2] libvorbis
#libogg.so.0]libogg  libvorbis
#libFLAC.so.8] flac.......... no speex or opusfile here!
 
echo 'libvorbis.tcz
flac.tcz' > $P.tcz.dep

submitqc --libs
rm -rf *.zsync
