#!/bin/bash
# test we are root
if [ "$(id -u)" != "0" ]; then
   echo "run as root now exitting"
   exit 1
fi

CFLAGS="-mtune=generic -Os -pipe"
CXX="g++ -flto -fuse-linker-plugin -mtune=generic -Os -pipe \
-fno-exceptions -fno-rtti" 
#perl5
P=gtk2
V=2.24.32
SRC=gtk+-2.24.32
USER=`cat /etc/sysconfig/tcuser`
LIST="compiletc submitqc gettext glib2-dev atk-dev atk-gir gdk-pixbuf2-dev \
gdk-pixbuf2-gir cups2-dev gobject-introspection-dev pango-dev pango-gir  "
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://ftp.gnome.org/pub/gnome/sources/gtk+/2.24/gtk+-$V.tar.xz " $USER
mkdir $P
xz -d gt*xz && tar xvf gt*tar
cd $SRC
./configure --enable-cups --disable-debug --enable-introspection=yes
# FAILS --enable-static=no....checking whether to build static libraries... no.
# FAILS make check
# make takes about 1 minute but install takes 2 min
make -j9
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

# 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/
mv $P/usr/local/lib/*a $P-dev/usr/local/lib/
chmod 644 $P-dev/usr/local/lib/*a 

mkdir -p $P-dev/usr/local/lib/gtk-2.0/modules
mv $P/usr/local/lib/gtk-2.0/include $P-dev/usr/local/lib/gtk-2.0/
mv $P/usr/local/lib/gtk-2.0/modules/*a $P-dev/usr/local/lib/gtk-2.0/modules/
chmod 644 $P-dev/usr/local/lib/gtk-2.0/modules/*a
mkdir -p $P-dev/usr/local/lib/gtk-2.0/2.10.0
cd $P-dev/usr/local/lib/gtk-2.0/2.10.0
mkdir engines immodules printbackends
cd /tmp
mv $P/usr/local/lib/gtk-2.0/2.10.0/engines/*a $P-dev/usr/local/lib/gtk-2.0/2.10.0/engines/
mv $P/usr/local/lib/gtk-2.0/2.10.0/immodules/*a $P-dev/usr/local/lib/gtk-2.0/2.10.0/immodules/
mv $P/usr/local/lib/gtk-2.0/2.10.0/printbackends/*a $P-dev/usr/local/lib/gtk-2.0/2.10.0/printbackends/
chmod 644 $P-dev/usr/local/lib/gtk-2.0/2.10.0/engines/*
chmod 644 $P-dev/usr/local/lib/gtk-2.0/2.10.0/immodules/*a
chmod 644 $P-dev/usr/local/lib/gtk-2.0/2.10.0/printbackends/*a

mkdir -p $P-dev/usr/local/share
mv $P/usr/local/share/aclocal $P-dev/usr/local/share/

# gir
#####
mkdir -p $P-gir/usr/local/lib/
mv $P/usr/local/lib/girepository-1.0 $P-gir/usr/local/lib/
mkdir -p $P-gir/usr/local/share
mv $P/usr/local/share/gir* $P-gir/usr/local/share/

# doc
#####
mkdir -p $P-doc/usr/local/share/doc/$P
mv $P/usr/local/share/gtk-doc/html $P-doc/usr/local/share/doc/$P/
rm -rf $P/usr/local/share/gtk-doc
mv $P/usr/local/share/gtk-2.0/demo $P-doc/usr/local/share/doc/$P/
rm -rf $P/usr/local/share/gtk-2.0
cp $SRC/AUTHORS $P-doc/usr/local/share/doc/$P
cp $SRC/COPYING $P-doc/usr/local/share/doc/$P

# main
#####
mkdir -p $P/usr/local/share/doc/$P
echo 'see doc tcz for COPYING' > $P/usr/local/share/doc/$P/COPYING

# tce.install
#############
mkdir -p $P/usr/local/tce.installed
cat >> $P/usr/local/tce.installed/$P <<'EOF'
#!/bin/sh
# credits bmarkus
/usr/local/bin/gdk-pixbuf-query-loaders --update-cache
/usr/local/bin/gtk-query-immodules-2.0 > /usr/local/etc/gtk-2.0/gtk.immodules
EOF
chown -R tc:staff $P/usr/local/tce.installed
chmod -R 755 $P/usr/local/tce.installed

# TCZ them
#######
LIST="$P $P-doc $P-dev $P-gir"
for Z in $LIST
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

echo 'gtk2.tcz
gettext.tcz 
glib2-dev.tcz 
atk-dev.tcz 
atk-gir.tcz 
gdk-pixbuf2-dev.tcz 
gdk-pixbuf2-gir.tcz 
cups2-dev.tcz 
gobject-introspection-dev.tcz 
pango-dev.tcz 
pango-gir.tcz 
perl5.tcz' > $P-dev.tcz.dep

echo 'atk.tcz 
pango.tcz 
gdk-pixbuf2.tcz 
shared-mime-info.tcz
Xorg-7.7-lib.tcz ' > $P.tcz.dep

echo 'Title:          gtk2.tcz
Description:    Gimp Tool Kit
Version:        2.24.32
Author:         see -doc/AUTHORS
Original-site:  http://www.gtk.org
Copying-policy: LGPL v2
Size:		
Extension_by:   aus9 at gmx dot com
Tags:           gtk 
Comments:       Gimp Tool Kit
 
                Compiled for 9x 
Change-log:     2014/01/18 First v 2.24.20 (bmarkus)
Current:        2018/06/14 v -> 2.24.32 add cups backend (aus9)  ' > $P.tcz.info

echo 'Title:          gtk2-gir.tcz
Description:    gir files for gtk2
Version:        2.24.32
Author:         see -doc/AUTHORS
Original-site:  http://www.gtk.org
Copying-policy: LGPL v2
Size:		
Extension_by:   aus9 at gmx dot com
Tags:           gtk 
Comments:       introspection files for gtk2

                Compiled for 9x 
Change-log:     2014/01/18 First v 2.24.20 (bmarkus)
Current:        2018/06/14 v -> 2.24.32 add cups backend (aus9)  ' > $P-gir.tcz.info

echo 'Title:          gtk2-dev.tcz
Description:    dev files 
Version:        2.24.32
Author:         see -doc/AUTHORS
Original-site:  http://www.gtk.org
Copying-policy: LGPL v2
Size:		
Extension_by:   aus9 at gmx dot com
Tags:           gtk
Comments:       Development files

                Compiled for 9x 
Change-log:     2014/01/18 First v 2.24.20 (bmarkus)
Current:        2018/06/14 v -> 2.24.32 add cups backend (aus9) ' > $P-dev.tcz.info

echo 'Title:          gtk2.24-doc.tcz
Description:    docs 
Version:        2.24.32
Author:         see -doc/AUTHORS
Original-site:  http://www.gtk.org
Copying-policy: LGPL v2
Size:		
Extension_by:   aus9 at gmx dot com
Tags:           gtk 
Comments:       Docs

                Compiled for 9x 
Change-log:     2014/01/18 First v 2.24.20 (bmarkus)
Current:        2018/06/14 v -> 2.24.32 add cups backend (aus9)   ' > $P-doc.tcz.info


submitqc --libs
