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

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

# pcre21042-dev already installs below
# add languages for configure status
P=swig
V=4.2.1
SRC=$P-$V
USER=`cat /etc/sysconfig/tcuser`
LIST="compiletc submitqc perl5 lua-5.4-dev lua-5.4 tcl8.6-dev boost-1.78-dev "
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://sourceforge.net/projects/$P/files/$P/$SRC/$SRC.tar.gz   " $USER 
tar xvf $SRC*gz
cd $SRC
# --disable-static not an option this build
./configure prefix=/usr/local  --localstatedir=/var --without-clisp --without-maximum-compile-warnings 

# The SWIG test-suite and examples are configured for the following languages:
# lua perl5 python tcl
make -j5 # 13 seconds
make install DESTDIR=/tmp/$P # no strip
cd /tmp

strip --strip-unneeded $P/usr/local/bin/*

mkdir -p $P/usr/local/share/doc/$P
echo 'GPL v3' > $P/usr/local/share/doc/$P/COPYING

# TCZ them
###########
LIST2="$P "
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:           swig.tcz
Description:     Simplified Wrapper and Interface Generator
Version:         4.2.1
Author:          swig team
Original-site:   https://www.swig.org
Copying-policy:  GPL v3
Size:            1.6M
Extension_by:    aus9 @ linuxquestions.org
Tags:            compiler 
Comments:        SWIG is a compiler that integrates C and C++ with languages
                 Perl5, Python3.9, Tcl8.6, Lua5.4 
                 Other languages not compiled
                 May optionally use boost-dev

                 online docs at original site                

Change-log:     2016/01/26 v 3.0.8 (Juanito) 
                2020/11/19 v 3.0.12
Current:        2024/03/15 v 4.2.1 on 15x (aus9) ' > $P.tcz.info

readelf -d $P/usr/local/bin/swig | grep 'NEEDED'
readelf -d $P/usr/local/bin/ccache-swig | grep 'NEEDED' # no extras

##delete TCBs
#libpcre2-8.so.0] pce21042

echo 'pcre21042.tcz  ' > $P.tcz.dep

submitqc --libs
rm -rf *.zsync


