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

# dictionaries are built after these TCES 

# error: cannot use ‘typeid’ with ‘-fno-rtti’
export CFLAGS="-mtune=generic -Os -pipe"  
export CXXFLAGS="-mtune=generic -Os -pipe -fno-exceptions "

P=aspell
V=0.60.8.1
SRC=$P-$V
USER=`cat /etc/sysconfig/tcuser`
LIST="compiletc submitqc gettext-dev libtool-dev  "
for Z in $LIST 
    do 
    su -c "tce-load -i $Z" $USER
done

# above contains ncursesw-dev

# configure ok but make BORKS without fix fatal error: curses.h: No such file or directory...ditto term.h
ln -s /usr/local/include/ncursesw/curses.h /usr/local/include/
ln -s /usr/local/include/ncursesw/term.h /usr/local/include/

URL=https://ftp.gnu.org/gnu/$P/dict
cd /tmp
su -c "/usr/local/bin/wget -nc --no-check-certificate \
$URL/$P-$V.tar.gz  " $USER
tar xvf $SRC*gz

cd $SRC
./configure --prefix=/usr/local --localstatedir=/var --enable-curses=/usr/local/lib/libncursesw.so \
--enable-curses-include=/usr/local/include/ncursesw 
make -j4  # 8 seconds
make install-strip DESTDIR=/tmp/$P
cd /tmp

# locale
#########
mkdir -p $P-locale/usr/local/share
mv $P/usr/local/share/locale $P-locale/usr/local/share

# doc
#####
mkdir -p $P-doc/usr/local/share/
mv $P/usr/local/share/info $P-doc/usr/local/share/
mv $P/usr/local/share/man $P-doc/usr/local/share/
mv $P/usr/local/lib/aspell-0.60/*.info $P-doc/usr/local/share/info

# dev
#####
mkdir -p $P-dev/usr/local/
mv $P/usr/local/include $P-dev/usr/local/
rm -rf  $P/usr/local/lib/*.la 
rm -rf $P/usr/local/lib/aspell-0.60/*.la

# main
######
mkdir -p $P/usr/local/share/doc/$P
echo 'LGPL v 2.1' > $P/usr/local/share/doc/$P/COPYING

# fix perl pathway
sed 's|usr/bin/perl|usr/local/bin/perl|' -i $P/usr/local/bin/$P-import

# TCZ them
#######
LIST="$P $P-dev $P-doc $P-locale "
for Z in $LIST
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 # Juanito does have gettext libtool TCEs in dev dep

echo 'Title:          aspell-dev.tcz
Description:    dev files
Version:        0.60.6.1
Author:         Aspell Team
Original-site:  https://ftp.gnu.org/gnu/aspell
Copying-policy: LGPL v 2.1
Size:           12K
Extension_by:   aus9 @linuxquestions.org
Tags:           spell check
Comments:       Development
                
Change-log:     2013/12/16 v 0.60.6.1 (Juanito)
                2018/11/12 recompiled against ncursesw
                2019/01/02 patched and recompiled on 10.x
Current:        2024/10/26 v 0.60.8.1 (aus9) ' > $P-dev.tcz.info
echo 'aspell.tcz 
ncursesw-dev.tcz '  > $P-dev.tcz.dep

echo 'Title:          aspell-doc.tcz
Description:    man and info pages
Version:        0.60.6.1
Author:         Aspell Team
Original-site:  https://ftp.gnu.org/gnu/aspell
Copying-policy: LGPL v 2.1
Size:           144K
Extension_by:   aus9 @linuxquestions.org
Tags:           spell check
Comments:       -
                
Change-log:     2024/10/26 v 0.60.8.1
Current:        2024/10/26  ' > $P-doc.tcz.info
echo 'man-db.tcz ' > $P-doc.tcz.dep

echo 'Title:          aspell-locale.tcz
Description:    language files
Version:        0.60.6.1
Author:         Aspell Team
Original-site:  https://ftp.gnu.org/gnu/aspell
Copying-policy: LGPL v 2.1
Size:           464K
Extension_by:   aus9 @linuxquestions.org
Tags:           spell check
Comments:       not dictionary files this TCE
                translates the executables
                
Change-log:     2024/10/26 v 0.60.8.1
Current:        2024/10/26  ' > $P-locale.tcz.info
echo 'aspell.tcz ' > $P-locale.tcz.dep

echo 'Title:          aspell.tcz
Description:    spell checker
Version:        0.60.6.1
Author:         Aspell Team
Original-site:  https://ftp.gnu.org/gnu/aspell
Copying-policy: LGPL v 2.1
Size:           668K
Extension_by:   aus9 @linuxquestions.org
Tags:           spell check
Comments:       interactive spell checking program and library
                
                Upgraders - please change your boot list as below
                We now have some non-EN dictionary TCEs
                Choose your dictionary and IT has a dep of this TCE
                aspell-en depends on aspell.tcz
                aspell-es depends on aspell-locale which depends on aspell.tcz 
                Ditto other dictionaries

                Basic use and follow the prompts
                $ aspell -c /pathway2/file
                
Change-log:     2013/12/16 v 0.60.6.1 (Juanito)
                2018/11/12 recompiled against ncursesw
                2019/01/02 patched and recompiled on 10.x
Current:        2024/10/26 v 0.60.8.1 (aus9) '  > $P.tcz.info
readelf -d $P/usr/local/bin/* | grep 'NEEDED'
# [libncursesw.so.6] ncursesw
# [libaspell.so.15] this TCE 
readelf -d $P/usr/local/lib/*.so | grep 'NEEDED' # no extras
readelf -d $P/usr/local/lib/aspell-0.60/*so | grep 'NEEDED' # no extras

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

submitqc --libs
rm -rf *.zsync

