### this file is sourced not run
PKGVER=10.00.0
PKGBUILD=1
PKGARCH=x86_64

# source: james - based on BLFS recipe for ghostscript 10.00.0
TARBALL=ghostpdl-10.0.0.tar.xz
MD5SUM=745160b588456443c0dfc16478c5ec69
SRC_URL=https://github.com/ArtifexSoftware/ghostpdl-downloads/releases/download/gs1000/$TARBALL
BUNDLE=

SLACKREQ='cups fontconfig freetype2 lcms2 libjpeg-turbo libpng libtiff libopenjpeg2 cairo'
SLACKDESC="ghostpdl: ghostpdl $PKGVER (Postscript/PCL/XPS renderer)
ghostpdl: 
ghostpdl: GhostPDL is a versatile printer-description-language (PDL) 
ghostpdl: interpreter with ability to render them into many different targets. 
ghostpdl: The following PDL are supported: Postscript, PCL, and XPS.
ghostpdl: 
ghostpdl: https://www.ghostscript.com/
ghostpdl: 
ghostpdl: Note: this package includes ghostscript functionality. If you install
ghostpdl: this package you don't need to install ghostscript.
ghostpdl:
"
SLACKCON=ghostscript # this package includes ghostscript

### default pkg_download
### prepare
pkg_prepare() {
	pkg_prepare_default &&
	cd tmp/ghostpdl* &&
	patch -Np1 -i ../pkg/upstream-cve-2023-36664.patch &&
	patch -Np1 -i ../pkg/upstream-cve-2023-36664-part2.patch &&
	true
}

### package
pkg_package() {
	# add our extra stuff: pdf-writer (cups-pdf) backend and its ppd
	mkdir -p usr/$LIBDIR/cups/backend &&
	install -m500 $CHROOT_DIR/tmp/pkg/pdf-writer usr/$LIBDIR/cups/backend &&
	mkdir -p etc/cups/ppd &&
	install -m644 $CHROOT_DIR/tmp/pkg/CUPS-PDF.ppd etc/cups/ppd
}

### build
pkg_build() {
	cd /tmp/ghostpdl* 

	# this will prevent installation to complete, so clean it out first
	rm -rf /usr/share/ghostscript &&
	
	# delete obsolete library
	rm -rf zlib freetype lcms2mt jpeg libpng openjpeg &&

	# start build
	./configure --prefix=/usr --libdir=/usr/$LIBDIR --disable-compile-inits \
	--with-system-libtiff  &&

	{ make $MAKEFLAGS    || make ;    } && 
	{ make $MAKEFLAGS so || make so ; } &&
	make install &&

	make soinstall &&	
	install -v -m644 base/*.h /usr/include/ghostscript &&
	ln -v -s ghostscript /usr/include/ps &&
	ln -sfvn ../ghostscript/$PKGVER/doc /usr/share/doc/ghostscript-$PKGVER &&
	cp -a examples/ /usr/share/ghostscript/$PKGVER &&

	# install ghostpcl fonts & make sure ghostpcl knows where to find them
	cp -a pcl/urwfonts /usr/share/ghostscript &&
	mkdir -p /etc/profile.d &&
	cat > /etc/profile.d/ghostpdl.sh << "EOF" &&
# make sure gpcl6 knows where to find its fonts
export PCLFONTSOURCE=/usr/share/ghostscript/urwfonts
EOF
	chmod +x /etc/profile.d/ghostpdl.sh &&

	# install ghostpcl tools
	install -m755 pcl/tools/pcl2pdf{,wr} /usr/bin &&
	
	# install ghostpcl examples
	cp -a pcl/examples /usr/share/ghostscript/$PKGVER/examples/pcl &&
	
	pkg_build_slackdesc	
}

