#!/bin/bash
# test we are root some parts based on TC64 build
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=vte
V=0.60.3
SRC=$P-$V
USER=`cat /etc/sysconfig/tcuser`
LIST="compiletc squashfs-tools zsync cmake gtk3-dev gtk3-gir gobject-introspection-dev pcre2-dev icu-dev vala-dev bash gnutls-dev python3.8-meson"
for Z in $LIST
    do
    su -c "tce-load -i $Z" $USER
done

cd /tmp
su -c "wget http://ftp.gnome.org/pub/gnome/sources/$P/0.60/$SRC.tar.xz" $USER
mkdir $P
xz -d $SRC*xz && tar xvf $SRC*tar
cd $SRC
mkdir build && cd build
meson --strip -Ddebug=false -Ddocs=false --prefix=/usr/local --localstatedir=/var \
--libexecdir=/usr/local/lib/vte-2.91 --buildtype=release -D_systemd=false
###################################
# meson takes about 20 secs
# C compiler:   gcc (version 10.1.0)
# C++ compiler: gcc (version 10.1.0)
# Coverage:     false
# Debug:        false
# A11y:         true
# Docs:         false
# FRIBIDI:      true
# GNUTLS:       true
# GTK+ 3.0:     true
# GTK+ 4.0:     false
# ICU:          true
# GIR:          true
# systemd:      false
# Vala:         true
# Prefix:       /usr/local
#######################################
ninja # takes about 1M 20s
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/
mkdir -p $P-dev/usr/local/share
mv $P/usr/local/share/vala $P-dev/usr/local/share
# ^ ^ TC64 has vala here

# gir
#####
mkdir -p $P-gir/usr/local/lib/
mv $P/usr/local/lib/girepository-1.0 $P-gir/usr/local/lib/
mkdir -p $P-gir/usr/local/share
mv $P/usr/local/share/gir* $P-gir/usr/local/share/

# main
#####
mkdir -p $P/usr/local/share/doc/$P
cp $SRC/COPYING.CC-BY-4-0 $P/usr/local/share/doc/$P/LICENCE

# TCZ them
#######
LIST="$P $P-dev $P-gir"
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:          vte-dev.tcz
Description:    vte dev files
Version:        0.60.3
Author:         Nalin Dahyabhai
Original-site:  https://ftp.gnome.org/pub/GNOME/sources/vte
Copying-policy: Creative Commons Attribution 4.0 International
Size:           16K
Extension_by:   aus9
Tags:           gtk3 terminal
Comments:       dev files

Change-log:     2020/09/10 Original v 0.60.3 on 12x 
Current:        2020/09/10  ' > $P-dev.tcz.info

echo 'Title:          vte-gir.tcz
Description:    vte gir files
Version:        0.60.3
Author:         Nalin Dahyabhai
Original-site:  https://ftp.gnome.org/pub/GNOME/sources/vte
Copying-policy: Creative Commons Attribution 4.0 International
Size:           40K
Extension_by:   aus9
Tags:           gtk3 terminal gir
Comments:       gobject-introspection files

Change-log:     2020/09/10 Original v 0.60.3 on 12x 
Current:        2020/09/10  ' > $P-gir.tcz.info

echo 'Title:          vte.tcz
Description:    virtual terminal widget for GTK applications
Version:        0.60.3
Author:         Nalin Dahyabhai
Original-site:  https://ftp.gnome.org/pub/GNOME/sources/vte
Copying-policy: Creative Commons Attribution 4.0 International
Size:           200K
Extension_by:   aus9
Tags:           gtk3 terminal
Comments:       dep of mainly gtk terminals

Change-log:     2020/09/10 Original v 0.60.3 on 12x 
Current:        2020/09/10 ' > $P.tcz.info

echo 'vte.tcz
cmake.tcz 
gtk3-dev.tcz 
gtk3-gir.tcz 
gobject-introspection-dev.tcz 
pcre2-dev.tcz 
icu-dev.tcz 
vala-dev.tcz 
bash.tcz 
gnutls-dev.tcz 
python3.8-meson.tcz ' > $P-dev.tcz.dep
echo 'vte.tcz' > $P-gir.tcz.dep
echo 'gtk3.tcz
pcre2.tcz
icu.tcz ' > $P.tcz.dep

