#!/bin/sh
# we are root

# OSS already in repo, this builds modules for it and its doc

export CFLAGS="-O2 -pipe -march=i486 -mtune=i686"
export CXXFLAGS="-O2 -pipe -fno-exceptions -fno-rtti -march=i486 -mtune=i686"
P=OSS-modules-3.16.6-tinycore
USER=`cat /etc/sysconfig/tcuser`

LIST="compiletc submitqc6 gtk2-dev libtool autoconf automake \
linux-kernel-sources-env "
for Z in $LIST
    do 
    su -c "tce-load -i $Z" $USER
done

cd /tmp
su -c "wget http://www.4front-tech.com/developer/sources/\
stable/gpl/oss-v4.2-build2011-src-gpl.tar.bz2  " $USER

if [ ! -d /usr/src/linux-3.16.6 ] ; then
echo "linux-kernel-sources-env will be run now"
su -c "linux-kernel-sources-env.sh " $USER 
else
echo "kernel sources found"
fi 

# we are root for rest of commands
tar jxvf oss-*bz2
mkdir /usr/src/oss
mv oss-v4.2-build2011-src-gpl /usr/src
cd /usr/src/oss
UNPACK=/usr/src/oss-v4.2-build2011-src-gpl
$UNPACK/configure
# less than 1 minute to configure---ditto make build
touch /tmp/mark
make build
make install
cd /tmp
find /lib -newer /tmp/mark  > /tmp/modules

# create doc
############
mkdir -p OSS-doc/usr/local/share
mv /usr/share/man OSS-doc/usr/local/share

# don't create dev
####################

# create modules
##################
mkdir -p $P/lib/modules/3.16.6-tinycore/kernel
mv /lib/modules/3.16.6-tinycore/kernel/oss $P/lib/modules/3.16.6-tinycore/kernel/

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

# add pathways to list
######################
cd /tmp/$P
find lib -not -type d >> /tmp/$P.tcz.list
cd /tmp

# create info files let submitqc5 add size
#######################
echo 'Title:          OSS-modules-3.16.6-tinycore.tcz
Description:    OSS kernel modules  
Version:        4.2
Author:         4front-tech.com
Original-site:  http://www.4front-tech.com/developer/sources/stable/gpl/
Copying-policy: GPLv2
Size: 		
Extension_by:   gordon64
Tags:           sound OSS
Comments:       OSS modules for kernel v3.16.6
                Previous maintainers Curaga, coreplayer2
                
                Compiled for x86 6x.               
Change-log:     2015/09/20 first version v4.2 b2011 gordon64
Current:        2015/09/20 
' > $P.tcz.info

echo 'Title:          OSS-doc.tcz
Description:    OSS docs
Version:        4.2
Author:         4front-tech.com
Original-site:  http://www.4front-tech.com/developer/sources/stable/gpl/
Copying-policy: GPLv2
Size: 		
Extension_by:   gordon64
Tags:           sound OSS
Comments:       documents for Open Sound

                Compiled for x86 6x.               
Change-log:     2015/09/20 first version v4.2 b2011 gordon64
Current:        2015/09/20 v4.2 gordon64
' > OSS-doc.tcz.info

submitqc6