#!/bin/sh
# test we are root
if [ "$USER" != "root" ] ; then
   echo "Run as root please, exiting." 
   exit 1                                                      
fi

# checking if gcc supports -fno-rtti -fno-exceptions... no
export CFLAGS="-mtune=generic -Os -pipe"
export CXX="g++ -flto -fuse-linker-plugin -mtune=generic -Os -pipe "

P=libpipeline
V=1.5.0
USER=`cat /etc/sysconfig/tcuser`
LIST="compiletc submitqc "
for Z in $LIST 
    do 
    su -c "tce-load -i $Z" $USER
done

cd /tmp
su -c "/usr/local/bin/wget -nc \
http://ftp.yzu.edu.tw/nongnu/$P/$P-$V.tar.gz " $USER
mkdir $P
tar xvf $P*gz
cd $P-$V 
./configure 
make -j5
make install-strip DESTDIR=/tmp/$P
cd /tmp

# doc
#####
mkdir -p $P-doc/usr/local
mv $P/usr/local/share $P-doc/usr/local/

# dev
#####
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/lib/pkgconfig $P-dev/usr/local/lib/
chmod 644 $P-dev/usr/local/lib/*a 

# main
#####
mkdir -p $P/usr/local/share/doc/$P
cp $P-$V/COPYING $P/usr/local/share/doc/$P/

# TCZ them
#######
LIST="$P $P-doc $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
done

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

echo 'Title:          libpipeline.tcz
Description:    a C library 
Version:        1.5.0
Author:         Colin Watson
Original-site:  http://libpipeline.nongnu.org/
Copying-policy: GPL v3
Size:		
Extension_by:   aus9 at gmx dot com
Tags:           libpipeline 
Comments:       library is used to safely construct pipelines 
                between subprocesses
                
                Compiled for 9.x
Change-log:     2015/07/07 First version (gordon64)
Current:        2018/03/08 1.4.0 -> v 1.5.0 (aus9)   '  > $P.tcz.info

echo 'Title:          libpipeline-doc.tcz
Description:    docs
Version:        1.5.0
Author:         Colin Watson 
Original-site:  http://libpipeline.nongnu.org/
Copying-policy: GPL v3
Size:		
Extension_by:   aus9 at gmx dot com
Tags:           libpipeline
Comments:       Some docs

                Compiled for 9.x
Change-log:     2015/07/07 First version (gordon64)
Current:        2018/03/08 1.4.0 -> v 1.5.0 (aus9) ' > $P-doc.tcz.info

echo 'Title:          libpipeline-dev.tcz
Description:    dev files 
Version:        1.5.0
Author:         Colin Watson  
Original-site:  http://libpipeline.nongnu.org/
Copying-policy: GPL v3
Size:		
Extension_by:   aus9 at gmx dot com
Tags:           libpipeline 
Comments:       Development files

                Compiled for 9.x
Change-log:     2015/07/07 First version (gordon64)
Current:        2018/03/08 1.4.0 -> v 1.5.0 (aus9) ' > $P-dev.tcz.info


submitqc --libs