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

export CFLAGS="-Os -pipe -march=armv6zk -mtune=arm1176jzf-s -mfpu=vfp"
export CXXFLAGS="-Os -pipe -fno-exceptions -fno-rtti -march=armv6zk \
-mtune=arm1176jzf-s -mfpu=vfp"

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:           40K
Extension-by:   aus9
Tags:           alsa
Comments:       Designed to allow (mainly) firefox to run without 
                pulseaudio. Test alsa is working correctly before 
                apulse stuff. (No alsa deps set.)
                $ tce-load -i alsa alsa-utils
                $ speaker-test -D hw:Headphones
                $ speaker-test # for HDMI
                Optional adjust alsamixer levels
                       
                I use analog sound (headphones + firefox)
                Skip to last command if HDMI is acceptable
                Create sound swap file. sudo su needed by me. YMMV
                $ sudo su
                #   echo 'defaults.pcm.card 1
                   defaults.ctl.card 1'  > /etc/asound.conf
                # su tc
                $ apulse firefox https://youtu.be/enuOArEfqGo
                Add etc/asound.conf to your persistance file
                for analog users. 

Change-log:     2020/10/06 Original 0.1.13 on 12x
Current:        2020/10/06 " > $P.tcz.info

