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

CFLAGS="-mtune=generic -Os -pipe"
CXX="g++ -flto -fuse-linker-plugin -mtune=generic -Os -pipe -fno-exceptions -fno-rtti"

P=slang
V=2.3.3
SRC=$P-$V
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 --no-check-certificate \
https://www.jedsoft.org/releases/$P/$SRC.tar.bz2 "  $USER
tar jxvf $SRC*bz2
cd $SRC
./configure --prefix=/usr/local --with-x
make -j5 
make install DESTDIR=/tmp/$P # strip fails
cd /tmp

# strip now not later

/usr/local/lib/libslang.so.2.3.3
/usr/local/bin/slsh


# dev
#####
mkdir -p $P-dev/usr/local/lib/
mv $P/usr/local/include $P-dev/usr/local/
mv $P/usr/local/lib/pkgconfig $P-dev/usr/local/lib/

# doc
####### the pathway is a little different below
mkdir -p $P-doc/usr/local/share
mv $P/usr/local/share/man $P-doc/usr/local/share/
mv $P/usr/local/share/doc $P-doc/usr/local/share/
mv $P-doc/usr/local/share/doc/slsh $P-doc/usr/local/share/doc/$P/

# shell
######
mkdir -p $P-shell/usr/local/etc
mkdir -p $P-shell/usr/local/share
mv $P/usr/local/bin $P-shell/usr/local/
mv $P/usr/local/etc $P-shell/usr/local/
mv $P/usr/local/share/slsh $P-shell/usr/local/share/

strip --strip-unneeded $P-shell/usr/local/bin/slsh

# main
###### bmarkus has lib files and modules 
mkdir -p $P/usr/local/share/doc/$P
echo 'GPL v2' > $P/usr/local/share/doc/$P/COPYING

strip --strip-unneeded $P/usr/local/lib/lib$P.so.2.3.3
strip --strip-unneeded $P/usr/local/lib/slang/v2/modules/*.so

# TCZ them
###########
LIST2="$P $P-dev $P-doc $P-shell "
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
        sed 's|usr|/usr|g' -i /tmp/$Z.tcz.list
	cd /tmp
done

ls -hal

echo 'Title:          slang-dev.tcz
Description:    dev files
Version:        2.3.3
Author:         John E. Davis
Original-site:  https://www.jedsoft.org/slang/
Copying-policy: GPL v2
Size:           32K
Extension_by:   aus9 @ linuxquestions.org   
Tags:           development 
Comments:       Development files
                Optional dep may be slang-shell?
                
Change-log:     2014/01/18 v 2.2.4 (bmarkus)
Current:        2024/03/23 v 2.3.3  (aus9)     ' > $P-dev.tcz.info
echo 'slang.tcz' > $P-dev.tcz.dep

echo 'Title:          slang-doc.tcz
Description:    man pages and docs
Version:        2.3.3
Author:         John E. Davis
Original-site:  https://www.jedsoft.org/slang/
Copying-policy: GPL v2
Size:           424K
Extension_by:   aus9 @ linuxquestions.org   
Tags:           man help 
Comments:       help to use slang-shell mainly
                
Change-log:     2014/01/18 v 2.2.4 (bmarkus)
Current:        2024/03/23 v 2.3.3  (aus9)     ' > $P-doc.tcz.info
echo 'man-db.tcz' > $P-doc.tcz.dep

echo 'Title:          slang-shell.tcz
Description:    executables files
Version:        2.3.3
Author:         John E. Davis
Original-site:  https://www.jedsoft.org/slang/
Copying-policy: GPL v2
Size:           172K
Extension_by:   aus9 @ linuxquestions.org   
Tags:           slang 
Comments:       help see slang-doc
                slsh=slang shell
                
Change-log:     2014/01/18 v 2.2.4 (bmarkus)
Current:        2024/03/23 v 2.3.3  (aus9)     ' > $P-shell.tcz.info
readelf -d $P-shell/usr/local/bin/* | grep 'NEEDED'
# libslang.so.2 main TCE
echo 'slang.tcz' > $P-shell.tcz.dep

echo 'Title:          slang.tcz
Description:    Multi-platform programmer library
Version:        2.3.3
Author:         John E. Davis
Original-site:  https://www.jedsoft.org/slang/
Copying-policy: GPL v2
Size:           668K
Extension_by:   aus9 @ linuxquestions.org   
Tags:           library 
Comments:       Libraries and modules
                
Change-log:     2014/01/18 v 2.2.4 (bmarkus)
Current:        2024/03/23 v 2.3.3  (aus9)     ' > $P.tcz.info

readelf -d $P/usr/local/lib/lib$P.so | grep 'NEEDED'
# only TCBS....for above and below lines 
readelf -d $P/usr/local/lib/$P/v2/modules/*.so | grep 'NEEDED'


# submitqc --libs used on run 1 but it thinks 
# slang-shell.tcz: Some directory or file permissions were incorrect or non-standard.
# Files - Expected 644:
# ./usr/local/share/slsh/scripts/slprof

# so not used run 2
