#!/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 -fno-exceptions -fno-rtti "
# checking if gcc supports -fno-rtti -fno-exceptions... no

P=sbc
V=2.0
SRC=$P-$V
USER=`cat /etc/sysconfig/tcuser`
LIST="compiletc submitqc libsndfile-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://mirrors.edge.kernel.org/pub/linux/bluetooth/$SRC.tar.xz  " $USER 
tar xvf $SRC*xz
cd $SRC 
./configure --prefix=/usr/local
make -j4 # seconds
make install-strip DESTDIR=/tmp/$P
cd /tmp

# 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/
rm -rf $P/usr/local/lib/*.la 

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

# TCZ them
###########
LIST2="$P $P-dev "
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:          sbc-dev.tcz
Description:    dev files 
Version:        0.2.1
Author:         sbc Team            
Original-site:  https://mirrors.edge.kernel.org/pub/linux/bluetooth/
Copying-policy: GPL v2
Size:           4.0K           
Extension_by:   aus9 @linuxquestions.org
Tags:           audio alsa bluetooth 
Comments:       Development

Change-log:     2013/11/11 v 1.1 (Juanito)
                2014/04/21 v 1.2
                2014/11/01 v 1.3
Current:        2024/06/21 v 2.0 on 15x (aus9) ' > $P-dev.tcz.info
echo 'sbc.tcz
libsndfile-dev.tcz' > $P-dev.tcz.dep

echo 'Title:          sbc.tcz
Description:    digit audio data transfer 
Version:        0.2.1
Author:         sbc Team            
Original-site:  https://mirrors.edge.kernel.org/pub/linux/bluetooth/
Copying-policy: GPL v2
Size:           68K           
Extension_by:   aus9 @linuxquestions.org
Tags:           audio alsa bluetooth 
Comments:       digital audio encoder and decoder used to transfer data to bluetooth
                audio output devices like headphones or loudspeakers

Change-log:     2013/11/11 v 1.1 (Juanito)
                2014/04/21 v 1.2
                2014/11/01 v 1.3
Current:        2024/06/21 v 2.0 on 15x (aus9) ' > $P.tcz.info

readelf -d $P/usr/local/bin/* | grep 'NEEDED' # only TCBS
readelf -d $P/usr/local/lib/*.so | grep 'NEEDED' # no extras
# strange that libsndfile not showin up
# no dep

submitqc --libs
rm -rf *.zsync

# dep checks
# /tmp/tcloop/bluez/usr/local/lib/bluetooth$ readelf -d * | grep libsbc -> no hits
# /tmp/tcloop/bluez/usr/local/bin$ readelf -d * | grep libsbc -> no hits
# ldd * | grep libsbc -> no hits under bin search.....ditto under lib/bluetooth
# ditto under cups/backend

# /tmp/tcloop/wireshark/usr/local/bin$ ldd * | grep libsbc
# libsbc.so.1 => /usr/local/lib/libsbc.so.1 (0x00007f9290800000)
# libsbc.so.1 => /usr/local/lib/libsbc.so.1 (0x00007fb4cf000000)
# /tmp/tcloop/wireshark/usr/local/lib$ ldd * | grep libsbc
# libsbc.so.1 => /usr/local/lib/libsbc.so.1 (0x00007fca1c800000)
# libsbc.so.1 => /usr/local/lib/libsbc.so.1 (0x00007f5817600000)
# libsbc.so.1 => /usr/local/lib/libsbc.so.1 (0x00007f3527200000)
# readelf -d * | grep libsbc (under the lib dir)
#  0x0000000000000001 (NEEDED)             Shared library: [libsbc.so.1]



