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

# redone after updated flac libvorbis

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 flac-dev speex-dev libvorbis-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 --enable-vcut
# 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 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 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
Comments:       split from vorbis-tools
                Optional dep for locales= vorbis-tools-locale
                man page in vorbis-tools-doc TCE

                Can play *.oga *.ogg *.ogv files
                but ogv means you will lack the video and
                just get the audio stream

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

echo 'libvorbis.tcz
libao.tcz
curl.tcz
flac.tcz
speex.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
Comments:       Also contains man page for TCE=ogg123 
                
Change-log:     2025/01/12 v 1.4.2 on 15x
Current:        2025/12/17 v 1.4.3 on 16x  ' > $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 locale
Comments:       untested by me
                
Change-log:     2025/01/12 v 1.4.2 on 15x
Current:        2025/12/17 v 1.4.3 on 16x     ' > $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 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 ogg123 out (aus9)
Current:        2025/12/17 v 1.4.3 on 16x   ' > $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
 
echo 'libvorbis.tcz
flac.tcz' > $P.tcz.dep

submitqc --libs
rm -rf *.zsync
