#!/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=lzip
V=1.21
SRC=$P-$V
USER=`cat /etc/sysconfig/tcuser`
LIST="compiletc wget zsync 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://mirror.freedif.org/GNU-Sa/$P/$SRC.tar.gz"  $USER
tar xvf $SRC*gz
mkdir $P
cd $SRC
./configure --prefix=/usr/local 
make -j5 # about 10 secs
make install-strip DESTDIR=/tmp/$P
cd /tmp

# doc
#####
SHARE=usr/local/share
mkdir -p $P-doc/$SHARE/doc/$P
mv $P/usr/local/share/man $P-doc/$SHARE
mv $P/usr/local/share/info $P-doc/$SHARE
cp $SRC/README $P-doc/$SHARE/doc/$P

# TCZ them
###########
LIST2="$P $P-doc"
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:          lzip-doc.tcz
Description:    lzip docs  
Version:        1.21
Author:         Antonio Diaz Diaz
Original-site:  https://mirror.freedif.org/GNU-Sa/lzip/
Copying-policy: LGPL v2 
Size:           32K
Extension_by:   aus9
Tags:           compression lzma
Comments:       info, man pages and README
                
Change-log:     2020/09/01 Original 1.21 on 12x
Current:        2020/09/01 ' > $P-doc.tcz.info 

echo 'Title:          lzip.tcz
Description:    lossless data compressor  
Version:        1.21
Author:         Antonio Diaz Diaz
Original-site:  https://mirror.freedif.org/GNU-Sa/lzip/
Copying-policy: LGPL v2 
Size:           56K
Extension_by:   aus9
Tags:           compression lzma
Comments:       see doc for various help files
                
Change-log:     2020/09/01 Original 1.21 on 12x
Current:        2020/09/01 ' > $P.tcz.info
