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

export CFLAGS="-march=armv8-a+crc -mtune=cortex-a72 -Os -pipe" 
export CXXFLAGS="-march=armv8-a+crc -mtune=cortex-a72 -Os -pipe \
-fno-exceptions -fno-rtti"

P=apulse
V=0.1.13
SRC=$P-$V
USER=`cat /etc/sysconfig/tcuser`
LIST="compiletc squashfs-tools zsync wget libasound-dev glib2-dev cmake"
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/i-rinat/$P/archive/v$V.zip"  $USER
unzip v$V*zip

mkdir $P
cd $SRC
mkdir build && cd build
cmake -DCMAKE_INSTALL_PREFIX=/usr/local  -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_FLAGS="-s" ../
make -j5 # seconds
make install DESTDIR=/tmp/$P
cd /tmp

# no doc
#####
rm -rf $P/usr/local/share/man 

# main
######
mkdir -p $P/usr/local/share/doc/$P
cp  $SRC/LICENSE.MIT $P/usr/local/share/doc/$P/LICENCE

# TCZ them
###########
LIST2="$P "
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
        zsyncmake $Z.tcz
done

ls -hal

echo 'Title:          apulse.tcz
Description:    PulseAudio emulation for ALSA
Version:        0.1.13
Author:         Rinat Ibragimov 
Original-site:  https://github.com/i-rinat/apulse
Copying-policy: accompanied
Size:           48K
Extension-by:   aus9
Tags:           alsa
Comments:       Designed to allow (mainly) firefox to run 
                without pulseaudio. 
                $ tce-load -i alsa-utils
                $ speaker-test 
                # ......Optional adjust alsamixer levels
                $ apulse firefox https://youtu.be/enuOArEfqGo

Change-log:     2020/10/05 Original 0.1.13 on 12x
                2020/10/21 only analog sound card now visible YMMV
Current:        2020/11/01 rebuilt against updated libasound  ' > $P.tcz.info 

echo 'alsa.tcz' > $P.tcz.dep



