#!/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=boost
V=1.74.0
SRC=boost_1_74_0
USER=`cat /etc/sysconfig/tcuser`
LIST="compiletc wget squashfs-tools zsync "
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://dl.bintray.com/boostorg/release/1.74.0/source/boost_1_74_0.tar.bz2 " $USER
tar jxvf $P*bz2 # takes 1.25 minutes
cd $SRC
./bootstrap.sh --prefix=/usr/local # one minute
./b2 stage -j5 link=shared variant=release threading=multi runtime-link=shared # takes 15.5 minutes 
# passive cooled case RPi4 hits 40C
touch /tmp/mark
./b2 install link=shared variant=release threading=multi runtime-link=shared # takes 2 minutes
cd /tmp

# main
######
mkdir -p $P/usr/local/share/doc/$P
cp $SRC/LICENSE_1_0.txt $P/usr/local/share/doc/$P/LICENCE
mkdir -p $P/usr/local/lib
mv /usr/local/lib/lib$P* $P/usr/local/lib

# dev
#####
mkdir -p $P-dev/usr/local/include
mv /usr/local/include/$P $P-dev/usr/local/include
mkdir -p $P-dev/usr/local/lib/
mv $P/usr/local/lib/*a $P-dev/usr/local/lib/
# only 2 .a much less than TC64 
# no need for  $P-dev/usr/local/lib/pkgconfig

# TCZ them
#######  
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:          boost-dev.tcz
Description:    boost devs 
Version:        1.74.0
Author:         https://www.boost.org/doc/libs/1_74_0/
Original-site:  https://www.boost.org/
Copying-policy: accompanied
Size:           13.6M
Extension_by:   aus9
Tags:           C++ library
Comments:       dev files

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

echo 'Title:          boost.tcz
Description:    portable C++ source libraries 
Version:        1.74.0
Author:         https://www.boost.org/doc/libs/1_74_0/
Original-site:  https://www.boost.org/
Copying-policy: accompanied
Size:           3.3M
Extension_by:   aus9
Tags:           C++ library
Comments:       Boost provides a set of free peer-reviewed portable 
                C++ source libraries. It includes libraries for linear 
                algebra, pseudorandom number generation, multithreading, 
                image processing, regular expressions and unit testing. 

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

echo 'boost.tcz' > $P-dev.tcz.dep

