#!/bin/sh
# test we are root
if [ "$USER" != "root" ] ; then
   echo "Run as root please, exiting." 
   exit 1                                                      
fi
# config says #########-fno-rtti -fno-exceptions... no
export CFLAGS="-mtune=generic -Os -pipe"
export CXX="g++ -flto -fuse-linker-plugin -mtune=generic -Os -pipe " 

P=libast
SRC=libast-0.7
USER=`cat /etc/sysconfig/tcuser`

# fails on vte-dev even with sym link 
LIST="compiletc submitqc "
for Z in $LIST
    do 
    su -c "tce-load -i $Z" $USER
done

cd /tmp
su -c "wget -nc http://www.eterm.org/download/libast-0.7.tar.gz \                        
" $USER 

# we are root for rest of commands
tar xvf $P*gz
cd $P*
./configure  --prefix=/usr/local 
make -j3
mkdir -p /tmp/$P
make install DESTDIR=/tmp/$P

# Strip executables
cd /tmp/$P
# bin is a script N/A
find . | xargs file | grep "shared object" | grep ELF | grep "not stripped" | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null


# create dev
###############
cd /tmp
mkdir -p $P-dev/usr/local/lib
mv $P/usr/local/include $P-dev/usr/local/
mv $P/usr/local/lib/*a $P-dev/usr/local/lib/
mv $P/usr/local/share $P-dev/usr/local/

# extras for main cleanup
#########################
mkdir -p $P/usr/local/share/doc/$P
touch $P/usr/local/share/doc/$P/COPYING

# TCZ them
#######
LIST2="$P $P-dev"
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
	cd /tmp
done

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


# create info files let submitqc add size

echo 'Title:          libast.tcz  
Description:    Library of Assorted Spiffy Things
Version:        0.7
Author:         Michael Jennings   
Original-site:  http://www.eterm.org/
Copying-policy: none known
Size:		
Extension_by:   aus9
Tags:           libast  
Comments:       dep for eterm
                         
 
                Compiled for Corepure64 8.x
Change-log:     2017/08/02 First version 
Current:        2017/08/02 
' > $P.tcz.info

echo 'Title:          libast-dev.tcz
Description:    dev files for libast
Version:        0.7 
Author:         Michael Jennings
Original-site:  http://www.eterm.org/
Copying-policy: none known
Size:		
Extension_by:   aus9
Tags:           libast 
Comments:       Development files

                Compiled for Corepure64 8.x
Change-log:     2017/08/02 First version 
Current:        2017/08/02  
' > $P-dev.tcz.info


submitqc