#!/bin/sh
# we are root

P=taglib
USER=`cat /etc/sysconfig/tcuser`

LIST="compiletc submitqc6 cmake  "
for Z in $LIST
    do 
    su -c "tce-load -i $Z" $USER
done

cd /tmp
su -c "/usr/local/bin/wget -nc  \
https://github.com/taglib/taglib/releases/download/v1.9.1/taglib-1.9.1.tar.gz \                                
" $USER 

# we are root for rest of commands
tar xvf $P-*.tar.gz
cd $P-*
##########################
cmake -DCMAKE_C_FLAGS="-mtune=generic -Os -pipe -march=i486 -mtune=i686" \
-DCMAKE_CXX_FLAGS="-mtune=generic -Os -pipe -march=i486 -mtune=i686" \
-DCMAKE_INSTALL_PREFIX=/usr/local 

touch /tmp/mark
make install
find /usr/local -newer /tmp/mark > /tmp/list-libtag
# make about 30 seconds

# create TCZ folders
####################
cd /tmp    
mkdir -p $P/usr/local/lib
mkdir -p $P-dev/usr/local/bin
mkdir -p $P-dev/usr/local/lib/pkgconfig
mkdir -p $P-dev/usr/local/include

UBIN=/usr/local/bin
UINC=/usr/local/include
ULIB=/usr/local/lib
UPKG=/usr/local/lib/pkgconfig

# start the moves
# Juanito advises the bin file belongs in dev TCZ
mv $UBIN/taglib* $P-dev/usr/local/bin/
mv $UINC/$P $P-dev/usr/local/include/
mv $ULIB/libtag* $P/usr/local/lib/
mv $UPKG/taglib* $P-dev/usr/local/lib/pkgconfig/
 
# Strip 
#######
cd $P/usr/local
strip --strip-unneeded lib/*.so*
cd /tmp

# too many authors add doc to main
######################
mkdir -p $P/usr/local/share/doc/$P
cp -f $P-*/AUTHORS $P/usr/local/share/doc/$P/

# 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

# create depend files
######################
echo "taglib.tcz" > $P-dev.tcz.dep

# create info files let submitqc5 add size
###################
echo 'Title:          taglib.tcz  
Description:    Audio Meta-Data Library
Version:        1.9.1
Author:         see doc/AUTHORS       
Original-site:  http://taglib.github.io/
Copying-policy: LGPL/MPL
Size:		
Extension_by:   gordons64
Tags:           taglib
Comments:       TagLib is a library for reading and 
                editing the meta-data of several popular audio formats
 
               	 Compiled for x86 6.x
Change-log:     2008/08/22 First version Jason W,
                2008/12/11 Rebuilt for i486, size, cramfs Jason W,
                2010/01/18 Updated to 1.6.1 Arslan S.
                2010/07/25 Updated to 1.6.3 Arslan S.
Current:        2015/09/04 v 1.9.1 gordon64 
' > $P.tcz.info

echo 'Title:          taglib-dev.tcz  
Description:    TagLib devs
Version:        1.9.1
Author:         see main doc/AUTHORS       
Original-site:  http://taglib.github.io/
Copying-policy: LGPL/MPL
Size:		
Extension_by:   gordons64
Tags:           taglib
Comments:       developement files
 
               	 Compiled for x86 6.x
Change-log:     2008/08/22 First version Jason W,
                2008/12/11 Rebuilt for i486, size, cramfs Jason W,
                2010/01/18 Updated to 1.6.1 Arslan S.
                2010/07/25 Updated to 1.6.3 Arslan S.
Current:        2015/09/04 v 1.9.1 gordon64 
' > $P-dev.tcz.info

submitqc6