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

export CFLAGS="-march=armv8-a+crc -mtune=cortex-a72 -Os -pipe " 
export CXXFLAGS="-march=armv8-a+crc -mtune=cortex-a72 -Os -pipe  "

P=poppler
V=20.09.0
SRC=$P-$V
USER=`cat /etc/sysconfig/tcuser`
   
LIST="compiletc wget squashfs-tools zsync xz cmake perl5 lcms2-dev cairo-dev gobject-introspection-dev \
libpthread-stubs boost-dev glib2-dev"
for Z in $LIST
    do 
    su -c "tce-load -i $Z" $USER
done

# poppler looks wrong place
ln -s /usr/local/include/nss /usr/include/nss

cd /tmp
su -c "/usr/local/bin/wget -nc --no-check-certificate \
https://$P.freedesktop.org/$SRC.tar.xz" $USER
mkdir $P
xz -d *xz && tar xvf $P*tar
cd $SRC
mkdir build && cd build 
U=/usr/local
cmake -LAH -DCMAKE_INSTALL_PREFIX=$U -DCMAKE_INSTALL_LIBDIR=$U/lib -DCMAKE_BUILD_TYPE=Release \
-DENABLE_XPDF_HEADERS=ON -DENABLE_QT4=OFF -DENABLE_QT5=OFF -DENABLE_QT6:BOOL=OFF -DBUILD_QT6_TESTS:BOOL=OFF \
-DBUILD_GTK_TESTS:BOOL=OFF -dBUILD_QT5_TESTS:BOOL=OFF -DENABLE_LIBOPENJPEG=none -DENABLE_GOBJECT_INTROSPECTION:BOOL=Off \
-DCMAKE_VERBOSE_MAKEFILE=TRUE -DENABLE_UNSTABLE_API_ABI_HEADERS=ON ../
######################################################################################
# Building Poppler with support for:
# font configuration:   fontconfig
# splash output:        yes
# cairo output:         yes
# qt5 wrapper:          no
# qt6 wrapper:          no
# glib wrapper:         yes
# introspection:        yes
# gtk-doc:              no
# cpp wrapper:          yes
# use libjpeg:          yes
# use libpng:           yes
# use libtiff:          yes
# use zlib compress:    yes
# use zlib uncompress:  no
# use nss3:             no
# use curl:             no
# use libopenjpeg2:     no
# use lcms2:            yes
# use boost:            yes
# command line utils:   yes
# fuzz target:          no
# test data dir:        /tmp/poppler-20.09.0/../test
#########################################################
make -j5 # takes 4.5 minutes
make -j5 install/strip DESTDIR=/tmp/$P
cd /tmp

# smaller repo
rm -rf $P/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/

# TCZ them
#######  
LIST="$P $P-dev "
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:          poppler-dev.tcz
Description:    poppler devs
Version:        20.09.0
Author:         Albert Astals Cid (forked from Derek Noonburg xpdf)
Original-site:  https://github.com/poppler/poppler
Copying-policy: GPL v2
Size:           372K
Extension_by:   aus9
Tags:           pdf
Comments:       dev files

Change-log:     2020/09/25 Original v 20.09.0 on 12x 
Current:        22020/11/09 rebuilt for glib2 for sane support  ' > $P-dev.tcz.info

echo 'Title:          poppler.tcz
Description:    a library for rendering PDF files
Version:        20.09.0
Author:         Albert Astals Cid (forked from Derek Noonburg xpdf)
Original-site:  https://github.com/poppler/poppler
Copying-policy: GPL v2
Size:           1.4M
Extension_by:   aus9
Tags:           pdf
Comments:       library for rendering PDF files, and examining or
                modifying their structure.  Poppler originally 
                came from the XPDF
                $ pdftotext sample.pdf /tmp/sample.txt

Change-log:     2020/09/25 Original v 20.09.0 on 12x 
Current:        2020/11/09 rebuilt for glib2 for sane support   ' > $P.tcz.info

echo 'poppler.tcz 
cmake.tcz 
perl5.tcz 
lcms2-dev.tcz 
cairo-dev.tcz 
gobject-introspection-dev.tcz 
libpthread-stubs.tcz 
boost-dev.tcz
glib2-dev.tcz' > $P-dev.tcz.dep
echo 'liblcms2.tcz
cairo.tcz
libtiff.tcz
glib2.tcz ' > $P.tcz.dep

