#!/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=fdk-aac
V=2.0.3
SRC=$P-$V
USER=`cat /etc/sysconfig/tcuser`
LIST="compiletc submitqc    "
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/opencore-amr/files/$P/$SRC.tar.gz" $USER 
tar xvf $SRC*gz
cd $SRC 
./configure --prefix=/usr/local --disable-static --localstatedir=/var 
find . -name Makefile -type f -exec sed -i 's/-g -O2//g' {} \;
make -j4 # 20 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
cp $SRC/NOTICE $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:          fdk-aac-dev.tcz
Description:    dev files
Version:        2.0.3       
Author:         Fraunhofer Institute for Integrated Circuits IIS        
Original-site:  https://sourceforge.net/projects/opencore-amr/  
Copying-policy: accompanied
Size:           80K
Extension_by:   aus9 @linuxquestons.org   
Tags:           audio  aac
Comments:       Development
                Author in German
                Fraunhofer-Gesellschaft zur Förderung der angewandten
                Forschung e.V.
                
Change-log:     2018/01/29 v 0.1.5 (Juanito)
Current:        2024/06/22 v 2.0.3 on 15x (aus9)    ' > $P-dev.tcz.info
echo 'fdk-aac.tcz ' > $P-dev.tcz.dep

echo 'Title:          fdk-aac.tcz
Description:    aac library
Version:        2.0.3       
Author:         Fraunhofer Institute for Integrated Circuits IIS
Original-site:  https://sourceforge.net/projects/opencore-amr/  
Copying-policy: accompanied
Size:           604K
Extension_by:   aus9 @linuxquestons.org   
Tags:           audio  aac
Comments:       Fraunhofer FDK AAC is an open-source library for 
                encoding and decoding digital audio in the 
                Advanced Audio Coding (AAC) format.
                Optional frontend TCE=fdkaac

                Author in German
                Fraunhofer-Gesellschaft zur Förderung der angewandten
                Forschung e.V. 
                
Change-log:     2018/01/29 v 0.1.5 (Juanito)
Current:        2024/06/22 v 2.0.3 on 15x (aus9)    ' > $P.tcz.info

readelf -d $P/usr/local/lib/*.so | grep 'NEEDED' # only TCBs
# no dep

submitqc --libs
rm -rf *.zsync

# dep check so number changes but no apparent damage?
depends-on.sh fdk-aac # avidemux.tcz fdk-aac-dev.tcz fdkaac.tcz
/tmp/tcloop/avidemux/usr/local/lib$ readelf -d *.so | grep libfdk # no hits
/tmp/tcloop/avidemux/usr/local/lib$ ldd *.so | grep libfdk # no hits


