#!/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=fribidi
V=1.0.10
SRC=$P-$V
USER=`cat /etc/sysconfig/tcuser`
LIST="compiletc wget squashfs-tools zsync glib2-dev libtool-dev python3.8-meson"
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/$P/$P/archive/v$V.zip" $USER
mkdir $P
unzip v$V*zip
cd $SRC
mkdir build && cd  build
meson --strip --prefix=/usr/local -Ddebug=false --buildtype=release -Ddocs=false
meson configure # to check what I may change
ninja # takes 15 seconds
DESTDIR=/tmp/$P ninja install
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/

# TCZ them
#######  no doc as per meson
LIST="$P $P-dev "
for Z in $LIST
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:          fribidi-dev.tcz
Description:    fribidi devs
Version:        1.0.10
Author:         Behdad Esfahbod, Dov Grobgeld, Roozbeh Pournader & Khaled Hosny
Original-site:  https://github.com/fribidi/fribidi/
Copying-policy: LGPL v2.1
Size:           16K
Extension_by:   aus9
Tags:           unicode
Comments:       dev files

Change-log:     2020/08/09 Original v 1.0.9 on 12x (Juanito)
Current:        2020/09/10 -> v 1.0.10 (aus9) ' > $P-dev.tcz.info

echo 'Title:          fribidi.tcz
Description:    Free Implementation of Unicode Bidirectional Algorithm
Version:        1.0.10
Author:         Behdad Esfahbod, Dov Grobgeld, Roozbeh Pournader & Khaled Hosny
Original-site:  https://github.com/fribidi/fribidi/
Copying-policy: LGPL v2.1
Size:           28K
Extension_by:   aus9
Tags:           unicode
Comments:       Supports Arabic and Hebrew alphabets
                Updated for sakura dep

Change-log:     2020/08/09 Original v 1.0.9 on 12x (Juanito)
Current:        2020/09/10 -> v 1.0.10 (aus9)' > $P.tcz.info

echo 'fribidi.tcz 
glib2-dev.tcz 
libtool-dev.tcz 
python3.8-meson.tcz' > $P-dev.tcz.dep
echo 'glib2.tcz ' > $P.tcz.dep
