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

export CFLAGS="-Os -pipe -march=armv6zk -mtune=arm1176jzf-s -mfpu=vfp"
export CXXFLAGS="-Os -pipe -fno-exceptions -fno-rtti -march=armv6zk \
-mtune=arm1176jzf-s -mfpu=vfp"

P=ghostscript
V=9.52
SRC=$P-$V
USER=`cat /etc/sysconfig/tcuser`
LIST="compiletc wget squashfs-tools zsync xz cups-dev cairo-dev libjpeg-turbo-dev lcms2-dev libXt-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://github.com/ArtifexSoftware/ghostpdl-downloads/releases/download/gs952/$SRC.tar.xz  " $USER
xz -d $SRC*xz && tar xvf $SRC.tar
cd $SRC
rm -rf expat freetype lcms2mt jpeg libpng 
./configure --prefix=/usr/local --with-system-libtiff --localstatedir=/var --enable-dynamic --disable-compile-inits
####################################################
make -j5 # 3.5 minutes
mkdir /tmp/$P
make install DESTDIR=/tmp/$P
cd /tmp

# doc
###### 
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/

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

# TCZ them
#######
LIST="$P $P-doc "
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
        zsyncmake $Z.tcz
done

ls -hal

echo 'Title:          ghostscript-doc.tcz
Description:    gs docs
Version:        9.52
Author:         Artifex Software Inc.
Original-site:  https://www.ghostscript.com/
Copying-policy: see LICENSE
Size:           9.3M
Extension_by:   aus9
Tags:           postscript ps pdf
Comments:       docs

Change-log:     2016/11/29 Original 9.20 (bmarkus)
                2017/11/04 -> 9.22 (Juanito)
Current:        2020/09/09 -> 9.52 (aus9)  ' > $P-doc.tcz.info

echo 'Title:          ghostscript.tcz
Description:    An interpreter for the PostScript language and for PDF
Version:        9.52
Author:         Artifex Software Inc.
Original-site:  https://www.ghostscript.com/
Copying-policy: see LICENSE
Size:           12M
Extension_by:   aus9
Tags:           postscript ps pdf
Comments:       used to display pdf or for printing
                PDF display terminal command
                $ gs -dSAFER -dBATCH filename.pdf

Change-log:     2016/11/29 Original 9.20 (bmarkus)
                2017/11/04 -> 9.22 (Juanito)
Current:        2020/09/09 -> 9.52 (aus9)  ' > $P.tcz.info

 
echo 'libcups.tcz
lcms2.tcz
fontconfig.tcz
libpng.tcz' > $P.tcz.dep

