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

export CFLAGS="-mtune=generic -Os -pipe"
export CXXFLAGS="-mtune=generic -Os -pipe -fno-exceptions -fno-rtti"

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

cd /tmp 
su -c "/usr/local/bin/wget -nc --no-check-certificate \
http://downloads.sourceforge.net/project/$P/$P/$V/$SRC-source.tar.bz2 "  $USER
tar jxvf $SRC*.bz2


cd $SRC
sh make.sh # 2m 10s
# del existing ramdrive files
rm -rf /usr/local/bin/sbcl /usr/local/lib/$P /usr/local/share/man /usr/local/share/doc/$P
touch /tmp/mark
sh install.sh
cd /tmp

# doc
#####
mkdir -p $P-doc/usr/local/share/
mv /usr/local/share/man $P-doc/usr/local/share/man/
gzip $P-doc/usr/local/share/man/man1/*

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

mkdir -p $P/usr/local/bin
mv /usr/local/bin/$P $P/usr/local/bin
strip --strip-unneeded $P/usr/local/bin/$P

mkdir -p $P/usr/local/lib
mv /usr/local/lib/$P $P/usr/local/lib
# scripts make exe data is 644 for asd
chmod 755 $P/usr/local/lib/sbcl/contrib/*
chmod 755 $P/usr/local/lib/sbcl/sbcl.mk
chmod 644 $P/usr/local/lib/sbcl/contrib/*asd

# TCZ them
###########
LIST2="$P $P-doc"
for Z in $LIST2
do
	mksquashfs $Z $Z.tcz
	md5sum $Z.tcz > $Z.tcz.md5.txt
	cd $Z
	find . -not -type d | cut -c 2- | sort > /tmp/$Z.tcz.list
	cd /tmp
done

ls -hal

echo "Title:	          sbcl-doc.tcz
Description:    man page 
Version:        2.4.11
Author:         too many see CREDITS main TCE
Original-site:  http://www.sbcl.org/
Copying-policy: multiple see COPYING - mainly MIT like
Size:           8.0K
Extension-by:   aus9 @linuxquestions.org
Tags:           programming compiler man lisp
Comments:       or  online manual
                http://www.sbcl.org/manual/index.html
               
Change-log:     2024/12/27 v 2.4.11 on 15x
Current:        2024/12/27 " > $P-doc.tcz.info
echo 'man-db.tcz' > $P-doc.tcz.dep

echo "Title:	          sbcl.tcz
Description:    Steel Bank Common Lisp 
Version:        2.4.11
Author:         too many see CREDITS
Original-site:  http://www.sbcl.org/
Copying-policy: multiple see COPYING - mainly MIT like
Size:           17M
Extension-by:   aus9 @linuxquestions.org
Tags:           programming compiler lisp
Comments:       see doc TCE or online manual
                http://www.sbcl.org/manual/index.html
                               
Change-log:     2017/07/10 v 1.3.19 on 8x (andyj) 
Current:        2024/12/27 v 2.4.11 on 15x split man page out(aus9)" > $P.tcz.info

readelf -d $P/usr/local/bin/$P | grep 'NEEDED' # TCBs
#  $P/usr/local/lib/$P/contrib/*fasl are scripts while *asd are data
# no dep

submitqc --libs
rm -rf *.zsync