#!/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"
export LDFLAGS="-Wl,-O1"

P=fdkaac
V=1.0.0
SRC=$P-$V
USER=`cat /etc/sysconfig/tcuser`

LIST="compiletc submitqc autoconf automake  fdk-aac-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://github.com/nu774/$P/archive/$V.zip"  $USER
unzip $V.zip
mkdir $P
cd $SRC
autoreconf -i
./configure
make -j5  # takes seconds
make install-strip DESTDIR=/tmp/$P
cd /tmp

# doc
##########
mkdir -p $P-doc/usr/local/share/
mv  $P/usr/local/share/man $P-doc/usr/local/share

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

# TCZ them
###########
LIST2="$P $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:          fdkaac-doc.tcz
Description:    man page only
Version:        1.0.0
Author:         inside main TCE for COPYING
Original-site:  https://github.com/nu774/fdkaac
Copying-policy: see COPYING
Size:           4.0K          		
Extension_by:   aus9 
Tags:           aac 
Comments:       man page

Change-log:     2020/05/11 first version  11x
Current:        2020/05/11
 ' > $P-doc.tcz.info

echo 'Title:          fdkaac.tcz
Description:    command line encoder frontend for libfdk-aac  
Version:        1.0.0
Author:         inside main TCE for COPYING
Original-site:  https://github.com/nu774/fdkaac
Copying-policy: see COPYING
Size:           36K         		
Extension_by:   aus9  
Tags:           aac m4a
Comments:       Used by asunder for AAC support
                Can encode as M4A or AAC
                If you want to do other things I suggest you view the 
                man page from the doc TCE.
                   
                
Change-log:     2020/05/11 first version  11x
Current:        2020/05/11 
' > $P.tcz.info

echo 'man-db.tcz' > $P-doc.tcz.dep
echo ' fdk-aac.tcz' > $P.tcz.dep

submitqc --libs
