# This is based on Slackware's build script.

NAME=espgs
VERSION=8.15.3
SOURCE=http://ftp.rz.tu-bs.de/pub/mirror/ftp.easysw.com/ftp/pub/ghostscript/$VERSION/espgs-$VERSION-source.tar.bz2
BUILD=${BUILD:-1}
OPTIMIZE=${OPTIMIZE:-"-O2 -pipe -fno-strict-aliasing"}
ROOT_REQUIRED=1

build() {
	_explode 0

	# OK, first we need the IJS library and include files.
	# Since it doesn't use an soname, and is very small (about 20K)
	# there's no good reason to compile it shared, and it would be
	# likely to be a bad idea anyway as the author says the protocol
	# is still very much in flux.
	cd $TMP/espgs-$VERSION/ijs
	rm -f install.sh missing
	ln -sf $DATADIR/automake-1.9/{install-sh,missing} .
	_configure
	make
	make install DESTDIR=$PKG
	_chfix
	_chgrp_bin
	_tmp_pkg 0

	# Now the main source is compiled:
	cd $TMP/espgs-$VERSION
	# Build the version with X11/CUPS/Omni/gimp-print/etc support:
	_configure \
		--enable-cups \
		--with-drivers=ALL \
		--with-ijs \
		--with-gimp-print \
		--with-omni \
		--with-x
	make clean
	make
	make install_prefix=$PKG install
	
	# Now make a "basic" version of gs:
	_configure \
		--enable-cups \
		--with-drivers=ALL \
		--with-ijs \
		--with-gimp-print \
		--with-omni \
		--with-x=no
	make clean
	make
	cat bin/gs > $PKG$BINDIR/gs-no-x11
	chmod 0755 $PKG$BINDIR/gs-no-x11

	mkdir -p $PKG$DOCDIR/espgs-$VERSION
	(
		SHORTVER=$(echo "$VERSION" | sed 's,^\([0-9]*\.[0-9]*\).*$,\1,')
		cd $PKG$DOCDIR/espgs-*
		rm -rf doc examples
		ln -sf $DATADIR/ghostscript/$SHORTVER/doc doc
		ln -sf $DATADIR/ghostscript/$SHORTVER/examples examples
	)

	_chfix
	_chgrp_bin
}
