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

CFLAGS="-march=i486 -mtune=i686 -Os -pipe   " 
CXXFLAGS="-march=i486 -mtune=i686 -Os -pipe -fno-exceptions -fno-rtti"
echo $CFLAGS && echo $CXXFLAGS

P=lzip
V=1.23 
SRC=$P-$V
USER=`cat /etc/sysconfig/tcuser`
LIST="compiletc squashfs-tools wget  asciidoc \
gettext-dev libtool-dev imlib2-dev perl5 lzip "
for Z in $LIST
    do 
    su -c "tce-load -i $Z" $USER
done

# list may be larger than loaded
cd /usr/local/lib
rm -rf *.la
rm -rf gcc/i486-pc-linux-gnu/12.2.0/plugin/libcp1plugin.la
rm -rf gcc/i486-pc-linux-gnu/12.2.0/plugin/libcc1plugin.la
rm -rf gcc/i486-pc-linux-gnu/12.2.0/liblto_plugin.la
cd /tmp
rm -rf /usr/lib/*.la
find / -name *.la

su -c "/usr/local/bin/wget -nc --no-check-certificate \
http://mirror.downloadvn.com/nongnu/$P/$SRC.tar.gz"  $USER
tar xvf $SRC*gz
cd $SRC
./configure --prefix=/usr/local 
# prefix = /usr/local
# exec_prefix = $(prefix)
# bindir = $(exec_prefix)/bin
# datarootdir = $(prefix)/share
# infodir = $(datarootdir)/info
# mandir = $(datarootdir)/man
# CXX = g++
# CPPFLAGS = 
# CXXFLAGS = -Wall -W -O2
make -j4 # seconds
make install-strip DESTDIR=/tmp/$P
cd /tmp

# no docs
##########
rm -rf $P/usr/local/share

# main
######
mkdir -p $P/usr/local/share/doc/$P
echo 'GPL v2' > $P/usr/local/share/doc/$P/COPYING

# 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
done

ls -hal

echo 'Title:          lzip.tcz
Description:    lzma compression tool
Version:        1.23
Author:         Antonio Diaz Diaz 
Original-site:  http://mirror.downloadvn.com/nongnu/lzip/
Copying-policy: GPL v2 
Size:           68K
Extension_by:   aus9
Tags:           lz lzip archive compression lzma
Comments:       lossless data compressor
                
Change-log:     2023/03/20 v 1.23 on 14.x 
Current:        2023/03/20    ' > $P.tcz.info
readelf -d $P/usr/local/bin/$P | grep 'NEEDED' # no extras

# no dep






