aboutsummaryrefslogtreecommitdiffstats
path: root/print/ghostscript7-x11
diff options
context:
space:
mode:
authorhrs <hrs@FreeBSD.org>2015-08-23 01:48:35 +0800
committerhrs <hrs@FreeBSD.org>2015-08-23 01:48:35 +0800
commit52f2507f3ec0cb2b7b96aa2ba867c924e7b8c9a2 (patch)
tree445c3e315f03aa972de87391f921c655e4634f60 /print/ghostscript7-x11
parent069a5644197c0b8b71f45d29221cd5192af4c720 (diff)
downloadfreebsd-ports-gnome-52f2507f3ec0cb2b7b96aa2ba867c924e7b8c9a2.tar.gz
freebsd-ports-gnome-52f2507f3ec0cb2b7b96aa2ba867c924e7b8c9a2.tar.zst
freebsd-ports-gnome-52f2507f3ec0cb2b7b96aa2ba867c924e7b8c9a2.zip
- Split ghostscript into X11-independent and -dependent parts:
* print/ghostscript{7,8,9,9-agpl}-base Installs Ghostscript binary, libgs, and related files. These ports do not depend on X11 libraries (i.e. x11* devices are not available). USES=ghostscript will set dependency on one of them depending on GHOSTSCRIPT_DEFAULT. The default device is set to "display" or "bbox". * print/ghostscript{7,8,9,9-agpl}-x11 Installs a shared library which provides X11 support to the installed Ghostscript binaries. x11* devices will be enabled when the library is available. This depends on *-base (RUN_DEPENDS). USES=ghostscript:x11 will set dependency on one of them. - Fix integer overflow reported as CVE-2015-3228. - Update Uses/ghostscript.mk: * Add x11 keyword. nox11 keyword is now obsolete. * Use packagename in *_DEPENDS line to prevent relationship between -base and -x11 packages from being broken. - Fix x11/nox11 keyword and bump PORTREVISION in ports using USES=ghostscript to update dependency of pre-compiled packages.
Diffstat (limited to 'print/ghostscript7-x11')
-rw-r--r--print/ghostscript7-x11/Makefile50
-rw-r--r--print/ghostscript7-x11/distinfo38
-rw-r--r--print/ghostscript7-x11/files/patch-src-Makefile.in166
-rw-r--r--print/ghostscript7-x11/files/patch-src-configure.ac199
-rw-r--r--print/ghostscript7-x11/files/patch-src-devs.mak65
-rw-r--r--print/ghostscript7-x11/files/patch-src-gconf.c43
-rw-r--r--print/ghostscript7-x11/files/patch-src-gdevijs.c659
-rw-r--r--print/ghostscript7-x11/files/patch-src-gdevl256.c15
-rw-r--r--print/ghostscript7-x11/files/patch-src-gdevpng.c187
-rw-r--r--print/ghostscript7-x11/files/patch-src-gdevvglb.c15
-rw-r--r--print/ghostscript7-x11/files/patch-src-gdevxalt.c31
-rw-r--r--print/ghostscript7-x11/files/patch-src-gnudevs.mak67
-rw-r--r--print/ghostscript7-x11/files/patch-src-gp_unix.c83
-rw-r--r--print/ghostscript7-x11/files/patch-src-gs.mak19
-rw-r--r--print/ghostscript7-x11/files/patch-src-gsalloc.c11
-rw-r--r--print/ghostscript7-x11/files/patch-src-gsmalloc.c11
-rw-r--r--print/ghostscript7-x11/files/patch-src-gxclrast.c15
-rw-r--r--print/ghostscript7-x11/files/patch-src-gxfixed.h46
-rw-r--r--print/ghostscript7-x11/files/patch-src-ibnum.c49
-rw-r--r--print/ghostscript7-x11/files/patch-src-ibnum.h11
-rw-r--r--print/ghostscript7-x11/files/patch-src-icclib.mak11
-rw-r--r--print/ghostscript7-x11/files/patch-src-idebug.c11
-rw-r--r--print/ghostscript7-x11/files/patch-src-idparam.c21
-rw-r--r--print/ghostscript7-x11/files/patch-src-ijs.mak20
-rw-r--r--print/ghostscript7-x11/files/patch-src-int.mak24
-rw-r--r--print/ghostscript7-x11/files/patch-src-iparam.c33
-rw-r--r--print/ghostscript7-x11/files/patch-src-iref.h11
-rw-r--r--print/ghostscript7-x11/files/patch-src-iscan.c11
-rw-r--r--print/ghostscript7-x11/files/patch-src-iscanbin.c83
-rw-r--r--print/ghostscript7-x11/files/patch-src-iscannum.c203
-rw-r--r--print/ghostscript7-x11/files/patch-src-iutil.c11
-rw-r--r--print/ghostscript7-x11/files/patch-src-lib.mak46
-rw-r--r--print/ghostscript7-x11/files/patch-src-unixinst.mak122
-rw-r--r--print/ghostscript7-x11/files/patch-src-zarith.c48
-rw-r--r--print/ghostscript7-x11/files/patch-src-zcontrol.c20
-rw-r--r--print/ghostscript7-x11/files/patch-src-zdict.c29
-rw-r--r--print/ghostscript7-x11/files/patch-src-zdps.c25
-rw-r--r--print/ghostscript7-x11/files/patch-src-zfunc4.c13
-rw-r--r--print/ghostscript7-x11/files/patch-src-zgeneric.c20
-rw-r--r--print/ghostscript7-x11/files/patch-src-ziodev.c11
-rw-r--r--print/ghostscript7-x11/files/patch-src-zmath.c18
-rw-r--r--print/ghostscript7-x11/files/patch-src-zstack.c11
-rw-r--r--print/ghostscript7-x11/files/patch-src-ztype.c34
-rw-r--r--print/ghostscript7-x11/files/patch-src:gdevlbp8.c70
-rw-r--r--print/ghostscript7-x11/files/patch-src:gdevpdff.c59
-rw-r--r--print/ghostscript7-x11/files/patch-src:gdevpdff.h37
-rw-r--r--print/ghostscript7-x11/files/patch-src:gdevpdfs.c41
-rw-r--r--print/ghostscript7-x11/files/patch-src:gdevpdfw.c60
-rw-r--r--print/ghostscript7-x11/files/patch-src:genarch.c34
-rw-r--r--print/ghostscript7-x11/files/patch-src:gxobj.h17
-rw-r--r--print/ghostscript7-x11/files/patch-src:unix-dll.mak87
-rw-r--r--print/ghostscript7-x11/files/patch-src:zmedia2.c25
-rw-r--r--print/ghostscript7-x11/files/patch-src_gdevhl12.c11
-rw-r--r--print/ghostscript7-x11/pkg-descr8
54 files changed, 3065 insertions, 0 deletions
diff --git a/print/ghostscript7-x11/Makefile b/print/ghostscript7-x11/Makefile
new file mode 100644
index 000000000000..a966ae101fec
--- /dev/null
+++ b/print/ghostscript7-x11/Makefile
@@ -0,0 +1,50 @@
+# Created by: Andreas Klemm <andreas@klemm.gtn.com>
+# $FreeBSD$
+
+PORTNAME= ghostscript
+PORTVERSION= 7.07
+PORTREVISION= 32
+CATEGORIES= print
+MASTER_SITES= SF/ghostscript/gnu-gs/${PORTVERSION}/
+PKGNAMESUFFIX= 7-x11
+DIST_SUBDIR= ${PORTNAME}
+
+MAINTAINER= hrs@FreeBSD.org
+COMMENT= Ghostscript 7.x PostScript interpreter, X11 support
+
+LICENSE= GPLv2
+
+CONFLICTS_INSTALL= \
+ gambc-[0-9]* \
+ ghostscript[789]-[0-9]* \
+ ghostscript[789]-nox11-[0-9]* \
+ ghostscript9-agpl-[0-9]* \
+ ghostscript9-agpl-nox11-[0-9]*
+
+USES= autoreconf ghostscript:7 gmake tar:bzip2
+USE_LDCONFIG= yes
+USE_XORG= ice sm x11 xext xt
+GNU_CONFIGURE= yes
+CONFIGURE_ENV= ${MAKE_ENV}
+CONFIGURE_ARGS= --disable-compile-inits \
+ --enable-dynamic \
+ --without-ijs \
+ --with-x \
+ --x-includes=${LOCALBASE}/include \
+ --x-libraries=${LOCALBASE}/lib
+MAKE_ENV= CFLAGS_STANDARD="${CFLAGS}" \
+ XCFLAGS="${XCFLAGS}" XLDFLAGS="${XLDFLAGS}" \
+ EXTRALIBS="${EXTRALIBS}"
+CPPFLAGS+= -I${LOCALBASE}/include
+LDFLAGS+= -L${LOCALBASE}/lib
+XLDFLAGS= -lpthread
+ALL_TARGET= ./obj/X11.so
+INSTALL_TARGET= install-shared
+PLIST_FILES= ${GS_LIBDIR}/X11.so
+
+GS_LIBDIR= lib/${PORTNAME}/${PORTVERSION}
+
+pre-build:
+ ${MKDIR} ${WRKSRC}/obj
+
+.include <bsd.port.mk>
diff --git a/print/ghostscript7-x11/distinfo b/print/ghostscript7-x11/distinfo
new file mode 100644
index 000000000000..469d48f2381f
--- /dev/null
+++ b/print/ghostscript7-x11/distinfo
@@ -0,0 +1,38 @@
+SHA256 (ghostscript/ghostscript-7.07.tar.bz2) = 6d87177a2fd2f08d75dde4b0c5bf45e2b0699d645faa382306f8edbb1531fd35
+SIZE (ghostscript/ghostscript-7.07.tar.bz2) = 4138372
+SHA256 (ghostscript/dmprt-2.01.tar.gz) = c3d8245ae48893856c6b63508262afbf54a3b16c3e606ab07797f46eb9e15ce7
+SIZE (ghostscript/dmprt-2.01.tar.gz) = 44232
+SHA256 (ghostscript/epag-3.09.tar.gz) = ad10eca44c781a5851d5a8993dcd95b2e2b99392cbf2c8372a5a658f3b991b3b
+SIZE (ghostscript/epag-3.09.tar.gz) = 12858
+SHA256 (ghostscript/pcl3-3.3.tar.gz) = 20fc33c741096a88c2aa6f6a03c025cad9bb224729dfffb91673c65c367ac714
+SIZE (ghostscript/pcl3-3.3.tar.gz) = 301470
+SHA256 (ghostscript/gdevcd8.tar.gz) = f52656a951e402f3775fdf09087944dba6f7a58edff17ce350692cee101cccf9
+SIZE (ghostscript/gdevcd8.tar.gz) = 24803
+SHA256 (ghostscript/gdevdj9.c.gz) = 7657dece1c2d9af15b7599e92f3170b9aaf927d429d90e4e928d3d7052fb376f
+SIZE (ghostscript/gdevdj9.c.gz) = 20139
+SHA256 (ghostscript/gimp-print-4.2.7.tar.gz) = a6cfcbb4bf32d12a553252b98e6a6fdb5d44fe37debad4480bbc9326e2c69489
+SIZE (ghostscript/gimp-print-4.2.7.tar.gz) = 5178122
+SHA256 (ghostscript/gdevmd2k-0.2a.tar.gz) = c99d6b4cc026c78729331c99a6d9ced24960c61b356c3a61162d2268274a7e7c
+SIZE (ghostscript/gdevmd2k-0.2a.tar.gz) = 9955
+SHA256 (ghostscript/gdevalps-0.21.tar.gz) = 250f54084bc186237e24233aa3cbffcc192e14b19620876a518b38ffe9b14421
+SIZE (ghostscript/gdevalps-0.21.tar.gz) = 4452
+SHA256 (ghostscript/gdev10v.tar.gz) = 99f51fa42c9223e2c6b3658d82c790cffbf146bd8ef60c89ddba56128c7a40d3
+SIZE (ghostscript/gdev10v.tar.gz) = 6099
+SHA256 (ghostscript/gs7.05-bjc250-v0.756.diff.gz) = aeeaa041a04a3ca95b50c1c1ebc60b7a570668fd110671610c0f21dab07ddd64
+SIZE (ghostscript/gs7.05-bjc250-v0.756.diff.gz) = 16501
+SHA256 (ghostscript/canon-lips4-1.0.0-651.tgz) = e11d11fa9d8645e4102a36d293cdf42498b5fbecc966d0bd104c5aa951c08cae
+SIZE (ghostscript/canon-lips4-1.0.0-651.tgz) = 38835
+SHA256 (ghostscript/gdevlips-2.4.0.tar.gz) = 24164cdc12cb0d03512c2f04ed82fa1e901625504367b8c53cc74134ee9c3047
+SIZE (ghostscript/gdevlips-2.4.0.tar.gz) = 67683
+SHA256 (ghostscript/eplaser-3.1.4-705.tgz) = ed1ccdf6ec613eb5e028786ad59cb3060f00c2ffa8ca5792bfd219514dc69f42
+SIZE (ghostscript/eplaser-3.1.4-705.tgz) = 44523
+SHA256 (ghostscript/gdevmjc-0.8.tar.gz) = cd922677798ce85b7e06d92694bb8b0012bc5d6ed66d6982f20eed471974f05b
+SIZE (ghostscript/gdevmjc-0.8.tar.gz) = 102654
+SHA256 (ghostscript/Samsung-SmartGDI-all-GS.orig.tar.gz) = 2c8c43e2318dd8b143344235ad7ccc203a3a8c4c50419f3967f1a999a92ea430
+SIZE (ghostscript/Samsung-SmartGDI-all-GS.orig.tar.gz) = 10488
+SHA256 (ghostscript/lxm3200-tweaked-20030501.tar.gz) = 9156ca7948158102938b127b356dfcd778e79a271893f56efe7cb65a41f46380
+SIZE (ghostscript/lxm3200-tweaked-20030501.tar.gz) = 39000
+SHA256 (ghostscript/gdevlx50.c) = 668de62188819f5c27f00ab04f1b7b58ff9ff52ac16497429a0637f412112117
+SIZE (ghostscript/gdevlx50.c) = 99428
+SHA256 (ghostscript/gs6.0.lexmark7000.patch) = 509dfc02436639ce6b9f98465ec306dd2e7f9342feded043c78b0c9cf44021df
+SIZE (ghostscript/gs6.0.lexmark7000.patch) = 27361
diff --git a/print/ghostscript7-x11/files/patch-src-Makefile.in b/print/ghostscript7-x11/files/patch-src-Makefile.in
new file mode 100644
index 000000000000..c615c95a9e2a
--- /dev/null
+++ b/print/ghostscript7-x11/files/patch-src-Makefile.in
@@ -0,0 +1,166 @@
+--- src/Makefile.in.orig 2003-04-30 03:33:31.000000000 +0900
++++ src/Makefile.in 2015-08-22 02:16:40.606012000 +0900
+@@ -50,8 +50,10 @@
+ # initialization files (gs_*.ps) and the fonts.
+
+ INSTALL = $(GLSRCDIR)/instcopy -c
+-INSTALL_PROGRAM = $(INSTALL) -m 755
+-INSTALL_DATA = $(INSTALL) -m 644
++INSTALL_PROGRAM = ${BSD_INSTALL_PROGRAM}
++INSTALL_SCRIPT = ${BSD_INSTALL_SCRIPT}
++INSTALL_DATA = ${BSD_INSTALL_DATA}
++INSTALL_SHARED = @INSTALL_SHARED@
+
+ prefix = @prefix@
+ exec_prefix = @exec_prefix@
+@@ -63,6 +65,8 @@
+ datadir = @datadir@
+ gsdir = $(datadir)/ghostscript
+ gsdatadir = $(gsdir)/$(GS_DOT_VERSION)
++gssharedir = @libdir@/ghostscript/$(GS_DOT_VERSION)
++gsincludedir = @includedir@/ghostscript/
+
+ docdir=$(gsdatadir)/doc
+ exdir=$(gsdatadir)/examples
+@@ -142,7 +146,7 @@
+ # some older JPEG streams that violate the standard. If the JPEG
+ # library built from local sources, the patch will be applied.
+
+-SHARE_JPEG=@SHARE_LIBJPEG@
++SHARE_JPEG=1
+ JPEG_NAME=jpeg
+
+ # Define the directory where the PNG library sources are stored,
+@@ -150,14 +154,14 @@
+ # You may need to change this if the libpng version changes.
+ # See libpng.mak for more information.
+
+-SHARE_LIBPNG=@SHARE_LIBPNG@
++SHARE_LIBPNG=1
+ PSRCDIR=@LIBPNGDIR@
+ LIBPNG_NAME=png
+
+ # Define the directory where the zlib sources are stored.
+ # See zlib.mak for more information.
+
+-SHARE_ZLIB=@SHARE_ZLIB@
++SHARE_ZLIB=1
+ ZSRCDIR=@ZLIBDIR@
+ #ZLIB_NAME=gz
+ ZLIB_NAME=z
+@@ -197,15 +201,15 @@
+ CCLD=$(CC)
+
+ # Define the general cc flags, warnings and such.
+-GCFLAGS=@GCFLAGS@
++GCFLAGS=@CPPFLAGS@ @GCFLAGS@ @CFLAGS@
+
+ # Define the added flags for standard, debugging, profiling
+ # and shared object builds.
+
+-CFLAGS_STANDARD=@OPT_CFLAGS@
++CFLAGS_STANDARD?=@OPT_CFLAGS@
+ CFLAGS_DEBUG=-g -O
+ CFLAGS_PROFILE=-pg @OPT_CFLAGS@
+-CFLAGS_SO=-fPIC
++CFLAGS_SO=@DYNAMIC_CFLAGS@
+
+ # Define the other compilation flags. Add at most one of the following:
+ # -DBSD4_2 for 4.2bsd systems.
+@@ -218,7 +222,7 @@
+ # We don't include -ansi, because this gets in the way of the platform-
+ # specific stuff that <math.h> typically needs; nevertheless, we expect
+ # gcc to accept ANSI-style function prototypes and function definitions.
+-XCFLAGS=
++XCFLAGS=@DYNAMIC_FLAGS@
+
+ # defines from autoconf; note that we don't use these at present.
+ ACDEFS=@DEFS@
+@@ -232,9 +236,9 @@
+ # -R /usr/local/xxx/lib:/usr/local/lib
+ # giving the full path names of the shared library directories.
+ # XLDFLAGS can be set from the command line.
+-XLDFLAGS=
+
+-LDFLAGS=$(XLDFLAGS)
++LDFLAGS=@LDFLAGS@
++XLDFLAGS=$(LDFLAGS)
+
+ # Define any extra libraries to link into the executable.
+ # ISC Unix 2.2 wants -linet.
+@@ -243,7 +247,7 @@
+ # Solaris may need -lnsl -lsocket -lposix4.
+ # (Libraries required by individual drivers are handled automatically.)
+
+-EXTRALIBS=
++EXTRALIBS=@LIBS@ @DYNAMIC_LIBS@
+
+ # Define the standard libraries to search at the end of linking.
+ # Most platforms require -lpthread for the POSIX threads library;
+@@ -252,10 +256,7 @@
+ # All reasonable platforms require -lm, but Rhapsody and perhaps one or
+ # two others fold libm into libc and don't require any additional library.
+
+-#STDLIBS=-lpthread -lm
+-
+-# Since the default build is for nosync, don't include pthread lib
+-STDLIBS=-lm
++STDLIBS=@PTHREAD_LIBS@ -lm
+
+ # Define the include switch(es) for the X11 header files.
+ # This can be null if handled in some other way (e.g., the files are
+@@ -279,9 +280,10 @@
+ # should be slotted into XLIBS below and X_PRE_LIBS which should go
+ # before -lX11. We do not handle these and should, but they are empty
+ # on most modern platforms.
+-XLIBDIRS=@X_LIBS@
++XLIBDIRS=@X_LDFLAGS@
+ XLIBDIR=
+-XLIBS=Xt Xext X11
++#XLIBS=Xt Xext X11
++XLIBS=@X_LIBS@
+
+ # Define whether this platform has floating point hardware:
+ # FPU_TYPE=2 means floating point is faster than fixed point.
+@@ -301,15 +303,19 @@
+ # primitives for this platform.
+
+ # If POSIX sync primitives are used, also change the STDLIBS to include
+-# the pthread library.
++# the pthread library. Otherwise use SYNC=nosync
+ #SYNC=posync
+-
+-# Default is No sync primitives since some platforms don't have it (HP-UX)
+-SYNC=nosync
++#SYNC=nosync
++SYNC=@SYNC@
+
+ # programs we use
+ RM=rm -f
+
++# ------ Dynamic loader options ------- #
++SOC_CFLAGS = @SOC_CFLAGS@
++SOC_LIBS = @SOC_LIBS@
++SOC_LOADER = @SOC_LOADER@
++
+ # ------ Devices and features ------ #
+
+ # Choose the language feature(s) to include. See gs.mak for details.
+@@ -385,6 +391,9 @@
+ DEVICE_DEVS19=
+ DEVICE_DEVS20=$(DD)cljet5.dev $(DD)cljet5c.dev
+
++# Shared library target to build.
++GS_SHARED_OBJS=@DYNAMIC_DEVS@
++
+ # ---------------------------- End of options --------------------------- #
+
+ # Define the name of the partial makefile that specifies options --
+@@ -407,6 +416,7 @@
+ # These are the specific warnings we have to turn off to compile those
+ # specific few files that need this. We may turn off others in the future.
+ CC_NO_WARN=$(CC_)
++CC_SHARED=$(CC_) @DYNAMIC_LDFLAGS@
+
+ # ---------------- End of platform-specific section ---------------- #
+
diff --git a/print/ghostscript7-x11/files/patch-src-configure.ac b/print/ghostscript7-x11/files/patch-src-configure.ac
new file mode 100644
index 000000000000..f95ae6826b22
--- /dev/null
+++ b/print/ghostscript7-x11/files/patch-src-configure.ac
@@ -0,0 +1,199 @@
+--- src/configure.ac.orig 2003-04-16 22:59:56.000000000 +0900
++++ src/configure.ac 2015-08-22 02:25:42.002266000 +0900
+@@ -8,6 +8,46 @@
+ AC_PREREQ(2.52)
+ AC_CONFIG_SRCDIR(src/gs.c)
+
++CFLAGS="${CFLAGS:=}"
++CPPFLAGS="${CPPFLAGS:=}"
++CXXFLAGS="${CXXFLAGS:=}"
++LDFLAGS="${LDFLAGS:=}"
++
++dnl --------------------------------------------------
++dnl Local utilities
++dnl --------------------------------------------------
++
++dnl GS_SPLIT_LIBS( LIBS, LINKLINE )
++dnl Split a unix-style link line into a list of
++dnl bare library names. For example, the line
++dnl '-L/usr/X11R6/lib -lX11 -lXt' splits into
++dnl LIB='X11 Xt'
++dnl
++AC_DEFUN([GS_SPLIT_LIBS], [
++# the makefile wants a list of just the library names
++for gs_item in $2; do
++ gs_stripped_item=`echo "$gs_item" | sed -e 's/^-l//'`
++ if test "x$gs_stripped_item" != "x$gs_item"; then
++ $1="$[$1] $gs_stripped_item"
++ fi
++done
++])
++
++dnl GS_SPLIT_LIBPATHS( LIBPATHS, LINKLINE )
++dnl Split a unix-style link line into a list of
++dnl bare search path entries. For example,
++dnl '-L/usr/X11R6/lib -lX11 -L/opt/lib -lXt'
++dnl splits to LIBPATHS='/usr/X11R6/lib /opt/lib'
++dnl
++AC_DEFUN([GS_SPLIT_LIBPATHS], [
++for gs_item in $2; do
++ gs_stripped_item=`echo "$gs_item" | sed -e 's/-L//'`
++ if test "x$gs_stripped_item" != "x$gs_item"; then
++ $1="$[$1] $gs_stripped_item"
++ fi
++done
++])
++
+ dnl --------------------------------------------------
+ dnl Check for programs
+ dnl --------------------------------------------------
+@@ -94,33 +134,15 @@
+ dnl --------------------------------------------------
+
+ AC_CHECK_LIB(m, cos)
+-dnl AC_CHECK_LIB(pthread, pthread_create)
++SYNC="nosync"
++PTHREAD_LIBS=""
++AC_CHECK_LIB(pthread, pthread_create, [
++ SYNC=posync;
++ PTHREAD_LIBS="-lpthread"
++])
++AC_SUBST(SYNC)
++AC_SUBST(PTHREAD_LIBS)
+
+-AC_MSG_CHECKING([for local jpeg library source])
+-dnl At present, we give the local source priority over the shared
+-dnl build, so that the D_MAX_BLOCKS_IN_MCU patch will be applied.
+-dnl A more sophisticated approach would be to test the shared lib
+-dnl to see whether it has already been patched.
+-LIBJPEGDIR=src
+-if test -d jpeg; then
+- AC_MSG_RESULT([jpeg])
+- SHARE_LIBJPEG=0
+- LIBJPEGDIR=jpeg
+-elif test -d jpeg-6b; then
+- AC_MSG_RESULT([jpeg-6b])
+- SHARE_LIBJPEG=0
+- LIBJPEGDIR=jpeg-6b
+-else
+- AC_MSG_RESULT([no])
+- AC_CHECK_LIB(jpeg, jpeg_set_defaults, [SHARE_LIBJPEG=1], [
+- AC_MSG_ERROR([I wasn't able to find a copy
+- of the jpeg library. This is required for compiling
+- ghostscript. Please download a copy of the source, e.g.
+- from http://www.ijg.org/, unpack it at the top level of
+- the gs source tree, and rename the directory to 'jpeg'.
+- ])
+- ])
+-fi
+ AC_SUBST(SHARE_LIBJPEG)
+ AC_SUBST(LIBJPEGDIR)
+
+@@ -211,15 +233,68 @@
+ AC_SUBST(STPLIB)
+ AC_SUBST(STPDEVS)
+
++SOC_CFLAGS=""
++SOC_LIBS=""
++SOC_LOADER="dxmainc.c"
++
++AC_SUBST(SOC_CFLAGS)
++AC_SUBST(SOC_LIBS)
++AC_SUBST(SOC_LOADER)
++
+ dnl optional X11 for display devices
+ AC_PATH_XTRA
+-if test x"$no_x" = x"yes"; then
+- AC_MSG_NOTICE([disabling X11 output devices])
+- X11DEVS=''
+-else
+- X11DEVS='$(DD)x11.dev $(DD)x11alpha.dev $(DD)x11cmyk.dev $(DD)x11gray2.dev $(DD)x11gray4.dev $(DD)x11mono.dev'
++
++X_LDFLAGS=""
++X_CFLAGS=""
++X_DEVS=""
++X_LIBS=""
++
++if test x$with_x != xno; then
++ if test "$x_libraries" = "/usr/lib"; then
++ echo "Ignoring X library directory \"$x_libraries\" requested by configure."
++ x_libraries="NONE"
++ fi
++ if test ! "$x_libraries" = "NONE" -a ! "$x_libraries" = ""; then
++ X_LDFLAGS="-L$x_libraries"
++ if test "$uname" = "SunOS"; then
++ X_LDFLAGS="$X_LDFLAGS -R$x_libraries"
++ fi
++ fi
++
++ if test "$x_includes" = "/usr/include"; then
++ echo "Ignoring X include directory \"$x_includes\" requested by configure."
++ x_includes="NONE"
++ fi
++ if test ! "$x_includes" = "NONE" -a ! "$x_includes" = ""; then
++ X_CFLAGS="-I$x_includes"
++ fi
++
++ SAVELIBS="$LIBS"
++ SAVELDFLAGS="$LDFLAGS"
++ LDFLAGS="$LDFLAGS $X_LDFLAGS"
++
++ AC_CHECK_LIB(X11,XOpenDisplay)
++ AC_CHECK_LIB(Xext,XdbeQueryExtension)
++ AC_CHECK_LIB(Xt,XtAppCreateShell)
++
++ LDFLAGS="$SAVELDFLAGS"
++ LIBS="$SAVELIBS"
++
++ if test "$ac_cv_lib_Xt_XtAppCreateShell" = yes; then
++ X11DEVS="\$(DD)x11.dev \$(DD)x11alpha.dev \$(DD)x11cmyk.dev \$(DD)x11mono.dev \$(DD)x11_.dev \$(DD)x11alt_.dev \$(DD)x11cmyk2.dev \$(DD)x11cmyk4.dev \$(DD)x11cmyk8.dev \$(DD)x11rg16x.dev \$(DD)x11rg32x.dev \$(DD)x11gray2.dev \$(DD)x11gray4.dev"
++ X_DEVS=$X11DEVS
++ # the makefile wants a list of just the library names in X_LIBS
++ GS_SPLIT_LIBS([X_LIBS],
++ [-lXt $X_PRE_LIBS -lXext -lX11 $X_EXTRA_LIBS])
++ fi
+ fi
++
++AC_SUBST(X_LDFLAGS)
++AC_SUBST(X_CFLAGS)
++AC_SUBST(X_LIBS)
++AC_SUBST(X_DEVS)
+ AC_SUBST(X11DEVS)
++AC_SUBST(XLIBS)
+
+ dnl executible name
+ AC_ARG_WITH(gs, AC_HELP_STRING([--with-gs=NAME],
+@@ -236,6 +311,33 @@
+ fi])
+ AC_SUBST(COMPILE_INITS)
+
++dnl Dynamic device support.
++DYNAMIC_CFLAGS=""
++DYNAMIC_DEVS=""
++DYNAMIC_FLAGS=""
++DYNAMIC_LDFLAGS=""
++DYNAMIC_LIBS=""
++INSTALL_SHARED=""
++
++AC_ARG_ENABLE([dynamic], AC_HELP_STRING([--enable-dynamic],
++ [Enable dynamically loaded drivers]),
++[
++ INSTALL_SHARED="install-shared"
++ DYNAMIC_CFLAGS="-fPIC"
++ DYNAMIC_DEVS="\$(GLOBJDIR)/X11.so"
++ DYNAMIC_FLAGS="-DGS_DEVS_SHARED -DGS_DEVS_SHARED_DIR=\\\"\$(gssharedir)\\\""
++ DYNAMIC_LDFLAGS="-fPIC -shared"
++ DYNAMIC_LIBS=""
++ X_DEVS=""
++])
++
++AC_SUBST(DYNAMIC_CFLAGS)
++AC_SUBST(DYNAMIC_DEVS)
++AC_SUBST(DYNAMIC_FLAGS)
++AC_SUBST(DYNAMIC_LDFLAGS)
++AC_SUBST(DYNAMIC_LIBS)
++AC_SUBST(INSTALL_SHARED)
++
+ dnl --------------------------------------------------
+ dnl Check for library functions
+ dnl --------------------------------------------------
diff --git a/print/ghostscript7-x11/files/patch-src-devs.mak b/print/ghostscript7-x11/files/patch-src-devs.mak
new file mode 100644
index 000000000000..707b393b70dd
--- /dev/null
+++ b/print/ghostscript7-x11/files/patch-src-devs.mak
@@ -0,0 +1,65 @@
+--- src/devs.mak.orig 2015-08-21 21:59:44.117097000 +0900
++++ src/devs.mak 2015-08-21 22:02:19.960434000 +0900
+@@ -405,7 +405,7 @@
+ $(ADDMOD) $(DD)lvga256 -lib vga vgagl
+
+ $(GLOBJ)gdevl256.$(OBJ) : $(GLSRC)gdevl256.c $(GDEV) $(memory__h)
+- $(GLCC) $(GLO_)gdevl256.$(OBJ) $(C_) $(GLSRC)gdevl256.c
++ $(GLCCSHARED) $(GLO_)gdevl256.$(OBJ) $(C_) $(GLSRC)gdevl256.c
+
+ vgalib_=$(GLOBJ)gdevvglb.$(OBJ) $(GLOBJ)gdevpccm.$(OBJ)
+ $(DD)vgalib.dev : $(DEVS_MAK) $(vgalib_)
+@@ -413,7 +413,7 @@
+ $(ADDMOD) $(DD)vgalib -lib vga
+
+ $(GLOBJ)gdevvglb.$(OBJ) : $(GLSRC)gdevvglb.c $(GDEV) $(gdevpccm_h) $(gsparam_h)
+- $(GLCC) $(GLO_)gdevvglb.$(OBJ) $(C_) $(GLSRC)gdevvglb.c
++ $(GLCCSHARED) $(GLO_)gdevvglb.$(OBJ) $(C_) $(GLSRC)gdevvglb.c
+
+ ### -------------------------- The X11 device -------------------------- ###
+
+@@ -443,24 +443,24 @@
+ $(GLOBJ)gdevx.$(OBJ) : $(GLSRC)gdevx.c $(GDEVX) $(math__h) $(memory__h)\
+ $(gscoord_h) $(gsdevice_h) $(gsiparm2_h) $(gsmatrix_h) $(gsparam_h)\
+ $(gxdevmem_h) $(gxgetbit_h) $(gxiparam_h) $(gxpath_h)
+- $(GLCC) $(XINCLUDE) $(GLO_)gdevx.$(OBJ) $(C_) $(GLSRC)gdevx.c
++ $(GLCCSHARED) $(XINCLUDE) $(GLO_)gdevx.$(OBJ) $(C_) $(GLSRC)gdevx.c
+
+ $(GLOBJ)gdevxcmp.$(OBJ) : $(GLSRC)gdevxcmp.c $(GDEVX) $(math__h)
+- $(GLCC) $(XINCLUDE) $(GLO_)gdevxcmp.$(OBJ) $(C_) $(GLSRC)gdevxcmp.c
++ $(GLCCSHARED) $(XINCLUDE) $(GLO_)gdevxcmp.$(OBJ) $(C_) $(GLSRC)gdevxcmp.c
+
+ $(GLOBJ)gdevxini.$(OBJ) : $(GLSRC)gdevxini.c $(GDEVX) $(memory__h)\
+ $(gserrors_h) $(gsparamx_h) $(gxdevmem_h) $(gdevbbox_h)
+- $(GLCC) $(XINCLUDE) $(GLO_)gdevxini.$(OBJ) $(C_) $(GLSRC)gdevxini.c
++ $(GLCCSHARED) $(XINCLUDE) $(GLO_)gdevxini.$(OBJ) $(C_) $(GLSRC)gdevxini.c
+
+ # We have to compile gdevxres without warnings, because there is a
+ # const/non-const cast required by the X headers that we can't work around.
+ $(GLOBJ)gdevxres.$(OBJ) : $(GLSRC)gdevxres.c $(std_h) $(x__h)\
+ $(gsmemory_h) $(gstypes_h) $(gxdevice_h) $(gdevx_h)
+- $(CC_NO_WARN) $(GLCCFLAGS) $(XINCLUDE) $(GLO_)gdevxres.$(OBJ) $(C_) $(GLSRC)gdevxres.c
++ $(GLCCSHARED) $(XINCLUDE) $(GLO_)gdevxres.$(OBJ) $(C_) $(GLSRC)gdevxres.c
+
+ $(GLOBJ)gdevxxf.$(OBJ) : $(GLSRC)gdevxxf.c $(GDEVX) $(math__h) $(memory__h)\
+ $(gsstruct_h) $(gsutil_h) $(gxxfont_h)
+- $(GLCC) $(XINCLUDE) $(GLO_)gdevxxf.$(OBJ) $(C_) $(GLSRC)gdevxxf.c
++ $(GLCCSHARED) $(XINCLUDE) $(GLO_)gdevxxf.$(OBJ) $(C_) $(GLSRC)gdevxxf.c
+
+ # Alternate X11-based devices to help debug other drivers.
+ # x11alpha pretends to have 4 bits of alpha channel.
+@@ -510,7 +510,13 @@
+
+ $(GLOBJ)gdevxalt.$(OBJ) : $(GLSRC)gdevxalt.c $(GDEVX) $(math__h) $(memory__h)\
+ $(gsdevice_h) $(gsparam_h) $(gsstruct_h)
+- $(GLCC) $(XINCLUDE) $(GLO_)gdevxalt.$(OBJ) $(C_) $(GLSRC)gdevxalt.c
++ $(GLCCSHARED) $(XINCLUDE) $(GLO_)gdevxalt.$(OBJ) $(C_) $(GLSRC)gdevxalt.c
++
++### Shared library object supporting X11.
++### NON PORTABLE, ONLY UNIX WITH GCC SUPPORT
++
++$(GLOBJ)X11.so : $(x11alt_) $(x11_)
++ $(CCLD) $(LDFLAGS) -shared -o $(GLOBJ)X11.so $(x11alt_) $(x11_) -L${LOCALBASE}/lib -lXt -lSM -lICE -lXext -lX11 $(XLIBDIRS)
+
+ ###### --------------- Memory-buffered printer devices --------------- ######
+
diff --git a/print/ghostscript7-x11/files/patch-src-gconf.c b/print/ghostscript7-x11/files/patch-src-gconf.c
new file mode 100644
index 000000000000..4afa18c6e024
--- /dev/null
+++ b/print/ghostscript7-x11/files/patch-src-gconf.c
@@ -0,0 +1,43 @@
+--- src/gconf.c.orig 2003-01-17 09:49:00.000000000 +0900
++++ src/gconf.c 2015-08-22 01:52:10.741824000 +0900
+@@ -81,7 +81,8 @@
+ /* Set up the device table. */
+ #define device_(dev) (const gx_device *)&dev,
+ #define device2_(dev) &dev,
+-private const gx_device *const gx_device_list[] = {
++static const gx_device *gx_device_list[1024] = {
++ /* as shared library are adding drivers here, so removed constness */
+ #include "gconf.h"
+ 0
+ };
+@@ -149,9 +150,29 @@
+ gs_lib_device_list(const gx_device * const **plist,
+ gs_memory_struct_type_t ** pst)
+ {
++ int i;
++
+ if (plist != 0)
+ *plist = gx_device_list;
+ if (pst != 0)
+ *pst = NULL;
+- return countof(gx_device_list) - 1;
++
++ for (i = 0; i < countof(gx_device_list) - 1; ++i)
++ if (!gx_device_list[i])
++ break;
++ return i;
+ }
++
++#ifdef GS_DEVS_SHARED
++void
++gs_lib_register_device(const gx_device *dev)
++{
++ int i;
++
++ for (i = 0; i < countof(gx_device_list) - 1; ++i)
++ if (!gx_device_list[i]) {
++ gx_device_list[i] = dev;
++ return;
++ }
++}
++#endif
diff --git a/print/ghostscript7-x11/files/patch-src-gdevijs.c b/print/ghostscript7-x11/files/patch-src-gdevijs.c
new file mode 100644
index 000000000000..fed73ce2599f
--- /dev/null
+++ b/print/ghostscript7-x11/files/patch-src-gdevijs.c
@@ -0,0 +1,659 @@
+--- src/gdevijs.c.orig Fri Jan 17 09:49:00 2003
++++ src/gdevijs.c Thu May 26 01:00:57 2005
+@@ -29,15 +29,29 @@
+ * which is a security risk, since any program can be run.
+ * You should use -dSAFER which sets .LockSafetyParams to true
+ * before opening this device.
++ *
++ * 11/26/03 David Suffield
++ * (c) 2003-2004 Copyright Hewlett-Packard Development Company, LP
++ *
++ * 1. Removed hpijs 1.0-1.0.2 workarounds, use hpijs 1.0.3 or higher.
++ * 2. Added krgb support.
++ *
++ * 02/21/05 David Suffield
++ * 1. Fixed segfault issue with 1-bit color space.
++ * 2. Fixed z-order issue with colored text on black rectangle.
++ *
+ */
+
+ #include "unistd_.h" /* for dup() */
+ #include <stdlib.h>
++#include <fcntl.h>
+ #include "gdevprn.h"
+ #include "gp.h"
+ #include "ijs.h"
+ #include "ijs_client.h"
+
++//#define KRGB_DEBUG
++
+ /* This should go into gdevprn.h, or, better yet, gdevprn should
+ acquire an API for changing resolution. */
+ int gdev_prn_maybe_realloc_memory(gx_device_printer *pdev,
+@@ -53,6 +67,14 @@
+ private dev_proc_get_params(gsijs_get_params);
+ private dev_proc_put_params(gsijs_put_params);
+
++/* Following definitions are for krgb support. */
++private dev_proc_create_buf_device(gsijs_create_buf_device);
++private dev_proc_fill_rectangle(gsijs_fill_rectangle);
++private dev_proc_copy_mono(gsijs_copy_mono);
++private dev_proc_fill_mask(gsijs_fill_mask);
++private dev_proc_fill_path(gsijs_fill_path);
++private dev_proc_stroke_path(gsijs_stroke_path);
++
+ private const gx_device_procs gsijs_procs =
+ prn_color_params_procs(gsijs_open, gsijs_output_page, gsijs_close,
+ gx_default_rgb_map_rgb_color, gx_default_rgb_map_color_rgb,
+@@ -85,6 +107,14 @@
+
+ IjsClientCtx *ctx;
+ int ijs_version;
++
++ /* Additional parameters for krgb support. */
++ int krgb_mode; /* 0=false, 1=true */
++ int k_path; /* k plane path, 0=false, 1=true */
++ int k_width; /* k plane width in pixels */
++ int k_band_size; /* k plane buffer size in bytes, byte aligned */
++ unsigned char *k_band; /* k plane buffer */
++ gx_device_procs prn_procs; /* banding playback procedures */
+ };
+
+ #define DEFAULT_DPI 74 /* See gsijs_set_resolution() below. */
+@@ -112,7 +142,12 @@
+ FALSE, /* Tumble_set */
+
+ NULL, /* IjsClient *ctx */
+- 0 /* ijs_version */
++ 0, /* ijs_version */
++ 0, /* krgb_mode */
++ 0, /* k_path */
++ 0, /* k_width */
++ 0, /* k_band_size */
++ NULL /* k_band buffer */
+ };
+
+
+@@ -128,12 +163,254 @@
+
+ /**************************************************************************/
+
+-/* ------ Private definitions ------ */
++/* ---------------- Low-level graphic procedures ---------------- */
++
++static unsigned char xmask[] =
++{
++ 0x80, /* x=0 */
++ 0x40, /* 1 */
++ 0x20, /* 2 */
++ 0x10, /* 3 */
++ 0x08, /* 4 */
++ 0x04, /* 5 */
++ 0x02, /* 6 */
++ 0x01 /* 7 */
++};
++
++private int gsijs_fill_rectangle(gx_device * dev, int x, int y, int w, int h,
++ gx_color_index color)
++{
++ gx_device_ijs *ijsdev = (gx_device_ijs *)((gx_device_forward *)dev)->target;
++
++ if (ijsdev->krgb_mode && ijsdev->k_path && y >= 0 && x >= 0)
++ {
++ int raster = (ijsdev->k_width+7) >> 3;
++ register unsigned char *dest=ijsdev->k_band+(raster*y)+(x >> 3);
++ int dest_start_bit = x & 7;
++ int i,j,w1;
++
++ if (h <= 0 || w <= 0)
++ return 0;
++
++ if ((x+w) > ijsdev->k_width)
++ w1 = ijsdev->k_width - x;
++ else
++ w1 = w;
++
++ /* Note x,y orgin 0,0 is stored first byte 0 left to right. */
++
++ if (color==0x0)
++ {
++ /* Color is black, store in k plane band instead of regular band. */
++ for (j=0; j<h; j++)
++ {
++ for (i=0; i<w1; i++)
++ dest[(dest_start_bit+i)>>3] |= xmask[(dest_start_bit+i)&7];
++ dest+=raster;
++ }
++ return 0;
++ }
++ else
++ {
++ /* Color is not black, remove any k plane bits for z-order dependencies, store in regular band. */
++ for (j=0; j<h; j++)
++ {
++ for (i=0; i<w1; i++)
++ dest[(dest_start_bit+i)>>3] &= ~xmask[(dest_start_bit+i)&7];
++ dest+=raster;
++ }
++ }
++ }
++
++ return (*ijsdev->prn_procs.fill_rectangle)(dev, x, y, w, h, color);
++}
++
++private int gsijs_copy_mono(gx_device * dev, const byte * data,
++ int dx, int draster, gx_bitmap_id id,
++ int x, int y, int w, int height, gx_color_index zero, gx_color_index one)
++{
++ gx_device_ijs *ijsdev = (gx_device_ijs *)((gx_device_forward *)dev)->target;
++
++ // if (ijsdev->krgb_mode && ijsdev->k_path && one==0x0)
++ if (ijsdev->krgb_mode && ijsdev->k_path)
++ {
++ /* Store in k plane band instead of regular band. */
++ int raster = (ijsdev->k_width+7) >> 3; /* raster width in bytes, byte aligned */
++ register unsigned char *dest=ijsdev->k_band+(raster*y)+(x >> 3);
++ register const unsigned char *scan=data+(dx >> 3);
++ int dest_start_bit = x & 7;
++ int scan_start_bit = dx & 7;
++ int i, h=height;
++
++ if (h <= 0 || w <= 0)
++ return 0;
++
++ if (one==0x0)
++ {
++ /* Color is black, store in k plane band instead of regular band. */
++ while (h-- > 0)
++ {
++ for (i=0; i<w; i++)
++ {
++ if (scan[(scan_start_bit+i)>>3] & xmask[(scan_start_bit+i)&7])
++ dest[(dest_start_bit+i)>>3] |= xmask[(dest_start_bit+i)&7];
++ }
++ scan+=draster;
++ dest+=raster;
++ }
++ return 0;
++ }
++ else
++ {
++ /* Color is not black, remove any k plane bits for z-order dependencies, store in regular band. */
++ while (h-- > 0)
++ {
++ for (i=0; i<w; i++)
++ {
++ if (scan[(scan_start_bit+i)>>3] & xmask[(scan_start_bit+i)&7])
++ dest[(dest_start_bit+i)>>3] &= ~xmask[(dest_start_bit+i)&7];
++ }
++ scan+=draster;
++ dest+=raster;
++ }
++ }
++ }
++
++ return (*ijsdev->prn_procs.copy_mono)(dev, data, dx, draster, id, x, y, w, height, zero, one);
++}
++
++/* ---------------- High-level graphic procedures ---------------- */
++
++private int gsijs_fill_mask(gx_device * dev,
++ const byte * data, int dx, int raster, gx_bitmap_id id,
++ int x, int y, int w, int h,
++ const gx_drawing_color * pdcolor, int depth,
++ gs_logical_operation_t lop, const gx_clip_path * pcpath)
++{
++ gx_device_ijs *ijsdev = (gx_device_ijs *)((gx_device_forward *)dev)->target;
++ int code;
++
++ ijsdev->k_path = 1;
++
++ code = (*ijsdev->prn_procs.fill_mask)(dev, data, dx, raster, id, x, y, w, h, pdcolor, depth, lop, pcpath);
++
++ ijsdev->k_path = 0;
++
++ return code;
++}
++
++private int gsijs_fill_path(gx_device * dev, const gs_imager_state * pis,
++ gx_path * ppath, const gx_fill_params * params,
++ const gx_drawing_color * pdcolor,
++ const gx_clip_path * pcpath)
++{
++ gx_device_ijs *ijsdev = (gx_device_ijs *)((gx_device_forward *)dev)->target;
++ int code;
++
++ ijsdev->k_path = 1;
++
++ code = (*ijsdev->prn_procs.fill_path)(dev, pis, ppath, params, pdcolor, pcpath);
++
++ ijsdev->k_path = 0;
++
++ return 0;
++}
++
++private int gsijs_stroke_path(gx_device * dev, const gs_imager_state * pis,
++ gx_path * ppath, const gx_stroke_params * params,
++ const gx_drawing_color * pdcolor,
++ const gx_clip_path * pcpath)
++{
++ gx_device_ijs *ijsdev = (gx_device_ijs *)((gx_device_forward *)dev)->target;
++ int code;
++
++ ijsdev->k_path = 1;
+
+-/* Versions 1.0 through 1.0.2 of hpijs report IJS version 0.29, and
+- require some workarounds. When more up-to-date hpijs versions
+- become ubiquitous, all these workarounds should be removed. */
+-#define HPIJS_1_0_VERSION 29
++ code = (*ijsdev->prn_procs.stroke_path)(dev, pis, ppath, params, pdcolor, pcpath);
++
++ ijsdev->k_path = 0;
++
++ return code;
++}
++
++/* ---------------- krgb banding playback procedures ---------------- */
++
++private int gsijs_get_bits(gx_device_printer * pdev, int y, byte * str, byte ** actual_data)
++{
++ gx_device_ijs *ijsdev = (gx_device_ijs *)pdev;
++ gx_device_clist_common *cdev = (gx_device_clist_common *)pdev;
++ int band_height = cdev->page_info.band_params.BandHeight;
++ int band_number = y/band_height;
++ int raster = (ijsdev->k_width+7) >> 3; /* raster width in bytes, byte aligned */
++ int y1=raster*(y-(band_height*band_number));
++
++ if (y1 == 0)
++ {
++ /* First raster for band, clear k_band. Banding playback occurs on first raster. */
++ memset(ijsdev->k_band, 0, ijsdev->k_band_size);
++ }
++
++ return gdev_prn_get_bits(pdev, y, str, actual_data); /* get raster from regular band */
++}
++
++private int gsijs_k_get_bits(gx_device_printer * pdev, int y, byte ** actual_data)
++{
++ gx_device_ijs *ijsdev = (gx_device_ijs *)pdev;
++ gx_device_clist_common *cdev = (gx_device_clist_common *)pdev;
++ int band_height = cdev->page_info.band_params.BandHeight;
++ int band_number = y/band_height;
++ int raster = (ijsdev->k_width+7) >> 3; /* raster width in bytes, byte aligned */
++ int y1=raster*(y-(band_height*band_number));
++
++ *actual_data = ijsdev->k_band+y1;
++
++ return 0;
++}
++
++private int gsijs_create_buf_device(gx_device **pbdev, gx_device *target,
++ const gx_render_plane_t *render_plane, gs_memory_t *mem, bool for_band)
++{
++ gx_device_ijs *ijsdev = (gx_device_ijs *)target;
++ int n_chan = ijsdev->color_info.num_components;
++ int code = gx_default_create_buf_device(pbdev, target, render_plane, mem, for_band);
++ if (code < 0 || n_chan != 3)
++ return code;
++
++ /* Save buffer (vector) procedures so that we can hook them during banding playback. */
++ ijsdev->prn_procs = (*pbdev)->procs;
++
++ /* Replace buffer procedures with krgb procedures. */
++ set_dev_proc(*pbdev, fill_rectangle, gsijs_fill_rectangle);
++ set_dev_proc(*pbdev, copy_mono, gsijs_copy_mono);
++ set_dev_proc(*pbdev, fill_mask, gsijs_fill_mask);
++ set_dev_proc(*pbdev, fill_path, gsijs_fill_path);
++ set_dev_proc(*pbdev, stroke_path, gsijs_stroke_path);
++
++ return code;
++}
++
++/* See if IJS server supports krgb. Return value: 0=false, 1=true. */
++private int
++gsijs_set_krgb_mode(gx_device_ijs *ijsdev)
++{
++ char buf[256];
++ int n_chan = ijsdev->color_info.num_components;
++ int code;
++
++ if (n_chan != 3)
++ return 0; /* no krgb support, not RGB colorspace */
++
++ buf[0] = 0;
++ code = ijs_client_enum_param(ijsdev->ctx, 0, "ColorSpace", buf, sizeof(buf)-1);
++ if (code >= 0)
++ buf[code] = 0;
++ if (strstr(buf, "KRGB") == NULL)
++ return 0; /* no krgb support */
++
++ return 1; /* krgb is supported */
++}
++
++/* ------ Private definitions ------ */
+
+ private int
+ gsijs_parse_wxh (const char *val, int size, double *pw, double *ph)
+@@ -171,34 +448,6 @@
+ }
+
+ /**
+- * gsijs_set_generic_params_hpijs: Set generic IJS parameters.
+- *
+- * This version is specialized for hpijs 1.0 through 1.0.2, and
+- * accommodates a number of quirks.
+- **/
+-private int
+-gsijs_set_generic_params_hpijs(gx_device_ijs *ijsdev)
+-{
+- char buf[256];
+- int code = 0;
+-
+- /* IjsParams, Duplex, and Tumble get set at this point because
+- they may affect margins. */
+- if (ijsdev->IjsParams) {
+- code = gsijs_client_set_param(ijsdev, "IjsParams", ijsdev->IjsParams);
+- }
+-
+- if (code == 0 && ijsdev->Duplex_set) {
+- int duplex_val;
+-
+- duplex_val = ijsdev->Duplex ? (ijsdev->IjsTumble ? 1 : 2) : 0;
+- sprintf (buf, "%d", duplex_val);
+- code = gsijs_client_set_param(ijsdev, "Duplex", buf);
+- }
+- return code;
+-}
+-
+-/**
+ * gsijs_set_generic_params: Set generic IJS parameters.
+ **/
+ private int
+@@ -209,9 +458,6 @@
+ int i, j;
+ char *value;
+
+- if (ijsdev->ijs_version == HPIJS_1_0_VERSION)
+- return gsijs_set_generic_params_hpijs(ijsdev);
+-
+ /* Split IjsParams into separate parameters and send to ijs server */
+ value = NULL;
+ for (i=0, j=0; (j < ijsdev->IjsParams_size) && (i < sizeof(buf)-1); j++) {
+@@ -252,68 +498,6 @@
+ }
+
+ /**
+- * gsijs_set_margin_params_hpijs: Do margin negotiation with IJS server.
+- *
+- * This version is specialized for hpijs 1.0 through 1.0.2, and
+- * accommodates a number of quirks.
+- **/
+-private int
+-gsijs_set_margin_params_hpijs(gx_device_ijs *ijsdev)
+-{
+- char buf[256];
+- int code = 0;
+-
+- if (code == 0) {
+- sprintf(buf, "%d", ijsdev->width);
+- code = gsijs_client_set_param(ijsdev, "Width", buf);
+- }
+- if (code == 0) {
+- sprintf(buf, "%d", ijsdev->height);
+- code = gsijs_client_set_param(ijsdev, "Height", buf);
+- }
+-
+- if (code == 0) {
+- double printable_width, printable_height;
+- double printable_left, printable_top;
+- float m[4];
+-
+- code = ijs_client_get_param(ijsdev->ctx, 0, "PrintableArea",
+- buf, sizeof(buf));
+- if (code == IJS_EUNKPARAM)
+- /* IJS server doesn't support margin negotiations.
+- That's ok. */
+- return 0;
+- else if (code >= 0) {
+- code = gsijs_parse_wxh(buf, code,
+- &printable_width, &printable_height);
+- }
+-
+- if (code == 0) {
+- code = ijs_client_get_param(ijsdev->ctx, 0, "PrintableTopLeft",
+- buf, sizeof(buf));
+- if (code == IJS_EUNKPARAM)
+- return 0;
+- else if (code >= 0) {
+- code = gsijs_parse_wxh(buf, code,
+- &printable_left, &printable_top);
+- }
+- }
+-
+- if (code == 0) {
+- m[0] = printable_left;
+- m[1] = ijsdev->MediaSize[1] * (1.0 / 72) -
+- printable_top - printable_height;
+- m[2] = ijsdev->MediaSize[0] * (1.0 / 72) -
+- printable_left - printable_width;
+- m[3] = printable_top;
+- gx_device_set_margins((gx_device *)ijsdev, m, true);
+- }
+- }
+-
+- return code;
+-}
+-
+-/**
+ * gsijs_set_margin_params: Do margin negotiation with IJS server.
+ **/
+ private int
+@@ -324,9 +508,6 @@
+ int i, j;
+ char *value;
+
+- if (ijsdev->ijs_version == HPIJS_1_0_VERSION)
+- return gsijs_set_margin_params_hpijs(ijsdev);
+-
+ /* Split IjsParams into separate parameters and send to ijs server */
+ value = NULL;
+ for (i=0, j=0; (j < ijsdev->IjsParams_size) && (i < sizeof(buf)-1); j++) {
+@@ -493,12 +674,18 @@
+ char buf[256];
+ bool use_outputfd;
+ int fd = -1;
++ long max_bitmap = ijsdev->space_params.MaxBitmap;
+
+ if (strlen(ijsdev->IjsServer) == 0) {
+ eprintf("ijs server not specified\n");
+ return gs_note_error(gs_error_ioerror);
+ }
+
++ ijsdev->space_params.MaxBitmap = 0; /* force banding */
++
++ /* Set create_buf_device in printer device, so that we can hook the banding playback procedures. */
++ ijsdev->printer_procs.buf_procs.create_buf_device = gsijs_create_buf_device;
++
+ /* Decide whether to use OutputFile or OutputFD. Note: how to
+ determine this is a tricky question, so we just allow the
+ user to set it.
+@@ -513,6 +700,8 @@
+ if (code < 0)
+ return code;
+
++ ijsdev->space_params.MaxBitmap = max_bitmap;
++
+ if (use_outputfd) {
+ /* Note: dup() may not be portable to all interesting IJS
+ platforms. In that case, this branch should be #ifdef'ed out.
+@@ -572,6 +761,9 @@
+ if (code >= 0)
+ code = gsijs_set_margin_params(ijsdev);
+
++ if (code >= 0)
++ ijsdev->krgb_mode = gsijs_set_krgb_mode(ijsdev);
++
+ return code;
+ };
+
+@@ -631,21 +823,6 @@
+ return min(width, end);
+ }
+
+-private int ijs_all_white(unsigned char *data, int size)
+-{
+- int clean = 1;
+- int i;
+- for (i = 0; i < size; i++)
+- {
+- if (data[i] != 0xFF)
+- {
+- clean = 0;
+- break;
+- }
+- }
+- return clean;
+-}
+-
+ /* Print a page. Don't use normal printer gdev_prn_output_page
+ * because it opens the output file.
+ */
+@@ -656,8 +833,9 @@
+ gx_device_printer *pdev = (gx_device_printer *)dev;
+ int raster = gdev_prn_raster(pdev);
+ int ijs_width, ijs_height;
+- int row_bytes;
++ int row_bytes, k_row_bytes=0;
+ int n_chan = pdev->color_info.num_components;
++ int krgb_mode = ijsdev->krgb_mode;
+ unsigned char *data;
+ char buf[256];
+ double xres = pdev->HWResolution[0];
+@@ -673,13 +851,23 @@
+
+ /* Determine bitmap width and height */
+ ijs_height = gdev_prn_print_scan_lines(dev);
+- if (ijsdev->ijs_version == HPIJS_1_0_VERSION) {
+- ijs_width = pdev->width;
+- } else {
+ ijs_width = gsijs_raster_width(dev);
+- }
++
+ row_bytes = (ijs_width * pdev->color_info.depth + 7) >> 3;
+
++ if (krgb_mode)
++ {
++ gx_device_clist_common *cdev = (gx_device_clist_common *)dev;
++ int band_height = cdev->page_info.band_params.BandHeight;
++ k_row_bytes = (ijs_width + 7) >> 3;
++
++ /* Create banding buffer for k plane. */
++ ijsdev->k_width = ijs_width;
++ ijsdev->k_band_size = band_height * k_row_bytes;
++ if ((ijsdev->k_band = gs_malloc(ijsdev->k_band_size, 1, "gsijs_output_page")) == (unsigned char *)NULL)
++ return gs_note_error(gs_error_VMerror);
++ }
++
+ /* Required page parameters */
+ sprintf(buf, "%d", n_chan);
+ gsijs_client_set_param(ijsdev, "NumChan", buf);
+@@ -688,44 +876,71 @@
+
+ /* This needs to become more sophisticated for DeviceN. */
+ strcpy(buf, (n_chan == 4) ? "DeviceCMYK" :
+- ((n_chan == 3) ? "DeviceRGB" : "DeviceGray"));
++ ((n_chan == 3) ? (krgb_mode ? "KRGB" : "DeviceRGB") : "DeviceGray"));
+ gsijs_client_set_param(ijsdev, "ColorSpace", buf);
+
+- /* If hpijs 1.0, don't set width and height here, because it
+- expects them to be the paper size. */
+- if (ijsdev->ijs_version != HPIJS_1_0_VERSION) {
+- sprintf(buf, "%d", ijs_width);
+- gsijs_client_set_param(ijsdev, "Width", buf);
+- sprintf(buf, "%d", ijs_height);
+- gsijs_client_set_param(ijsdev, "Height", buf);
+- }
++ sprintf(buf, "%d", ijs_width);
++ gsijs_client_set_param(ijsdev, "Width", buf);
++ sprintf(buf, "%d", ijs_height);
++ gsijs_client_set_param(ijsdev, "Height", buf);
+
+ sprintf(buf, "%gx%g", xres, yres);
+ gsijs_client_set_param(ijsdev, "Dpi", buf);
+
++#ifdef KRGB_DEBUG
++ int kfd, rgbfd;
++ char sz[128];
++ kfd = open("/tmp/k.pbm", O_CREAT | O_TRUNC | O_RDWR, 0644);
++ rgbfd = open("/tmp/rgb.ppm", O_CREAT | O_TRUNC | O_RDWR, 0644);
++ snprintf(sz, sizeof(sz), "P4\n#gdevijs test\n%d\n%d\n", ijs_width, ijs_height);
++ write(kfd, sz, strlen(sz));
++ snprintf(sz, sizeof(sz), "P6\n#gdevijs test\n%d\n%d\n255\n", ijs_width, ijs_height);
++ write(rgbfd, sz, strlen(sz));
++#endif
++
+ for (i=0; i<num_copies; i++) {
+ unsigned char *actual_data;
+ ijs_client_begin_cmd (ijsdev->ctx, IJS_CMD_BEGIN_PAGE);
+ status = ijs_client_send_cmd_wait(ijsdev->ctx);
+
+ for (y = 0; y < ijs_height; y++) {
+- code = gdev_prn_get_bits(pdev, y, data, &actual_data);
+- if (code < 0)
+- break;
++ if (krgb_mode)
++ code = gsijs_get_bits(pdev, y, data, &actual_data);
++ else
++ code = gdev_prn_get_bits(pdev, y, data, &actual_data);
++ if (code < 0)
++ break;
++#ifdef KRGB_DEBUG
++ write(rgbfd, actual_data, row_bytes);
++#endif
++ status = ijs_client_send_data_wait(ijsdev->ctx, 0, (char *)actual_data, row_bytes);
++ if (status)
++ break;
+
+- if (ijsdev->ijs_version == HPIJS_1_0_VERSION &&
+- ijs_all_white(actual_data, row_bytes))
+- status = ijs_client_send_data_wait(ijsdev->ctx, 0, NULL, 0);
+- else
+- status = ijs_client_send_data_wait(ijsdev->ctx, 0,
+- (char *)actual_data, row_bytes);
+- if (status)
+- break;
++ if (krgb_mode) {
++ code = gsijs_k_get_bits(pdev, y, &actual_data);
++ if (code < 0)
++ break;
++#ifdef KRGB_DEBUG
++ write(kfd, actual_data, k_row_bytes);
++#endif
++ status = ijs_client_send_data_wait(ijsdev->ctx, 0, (char *)actual_data, k_row_bytes);
++ if (status)
++ break;
++ }
+ }
+ ijs_client_begin_cmd(ijsdev->ctx, IJS_CMD_END_PAGE);
+ status = ijs_client_send_cmd_wait(ijsdev->ctx);
+ }
+
++#ifdef KRGB_DEBUG
++ close(kfd);
++ close(rgbfd);
++#endif
++
++ if(krgb_mode)
++ gs_free(ijsdev->k_band, ijsdev->k_band_size, 1, "gsijs_output_page");
++
+ gs_free_object(pdev->memory, data, "gsijs_output_page");
+
+ endcode = (pdev->buffer_space && !pdev->is_async_renderer ?
+@@ -1029,7 +1244,6 @@
+ dprintf2("ijs: Can't set parameter %s=%s\n", key, value);
+ return code;
+ }
+-
+
+ private int
+ gsijs_set_color_format(gx_device_ijs *ijsdev)
diff --git a/print/ghostscript7-x11/files/patch-src-gdevl256.c b/print/ghostscript7-x11/files/patch-src-gdevl256.c
new file mode 100644
index 000000000000..e11d19f8c2d6
--- /dev/null
+++ b/print/ghostscript7-x11/files/patch-src-gdevl256.c
@@ -0,0 +1,15 @@
+--- src/gdevl256.c.orig 2015-08-22 01:40:41.895138000 +0900
++++ src/gdevl256.c 2015-08-22 01:40:56.016022000 +0900
+@@ -307,3 +307,12 @@
+ gl_line(x0, y0, x1, y1, color);
+ return 0;
+ }
++
++#ifdef GS_DEVS_SHARED
++extern void gs_lib_register_device(const gx_device *dev);
++void
++gs_shared_init(void)
++{
++ gs_lib_register_device(&gs_lvga256_device);
++}
++#endif
diff --git a/print/ghostscript7-x11/files/patch-src-gdevpng.c b/print/ghostscript7-x11/files/patch-src-gdevpng.c
new file mode 100644
index 000000000000..0bb66e2f046d
--- /dev/null
+++ b/print/ghostscript7-x11/files/patch-src-gdevpng.c
@@ -0,0 +1,187 @@
+--- src/gdevpng.c.orig 2003-05-15 19:05:29.000000000 +0900
++++ src/gdevpng.c 2015-02-19 01:59:24.000000000 +0900
+@@ -41,12 +41,6 @@
+ #include "gdevpccm.h"
+ #include "gscdefs.h"
+
+-#define PNG_INTERNAL
+-/*
+- * libpng versions 1.0.3 and later allow disabling access to the stdxxx
+- * files while retaining support for FILE * I/O.
+- */
+-#define PNG_NO_CONSOLE_IO
+ /*
+ * Earlier libpng versions require disabling FILE * I/O altogether.
+ * This produces a compiler warning about no prototype for png_init_io.
+@@ -258,7 +252,7 @@
+ goto done;
+ }
+ /* set error handling */
+- if (setjmp(png_ptr->jmpbuf)) {
++ if (setjmp(png_jmpbuf(png_ptr))) {
+ /* If we get here, we had a problem reading the file */
+ code = gs_note_error(gs_error_VMerror);
+ goto done;
+@@ -268,19 +262,12 @@
+ png_init_io(png_ptr, file);
+
+ /* set the file information here */
+- info_ptr->width = pdev->width;
+- info_ptr->height = pdev->height;
+- /* resolution is in pixels per meter vs. dpi */
+- info_ptr->x_pixels_per_unit =
+- (png_uint_32) (pdev->HWResolution[0] * (100.0 / 2.54));
+- info_ptr->y_pixels_per_unit =
+- (png_uint_32) (pdev->HWResolution[1] * (100.0 / 2.54));
+- info_ptr->phys_unit_type = PNG_RESOLUTION_METER;
+- info_ptr->valid |= PNG_INFO_pHYs;
+ switch (depth) {
+ case 32:
+- info_ptr->bit_depth = 8;
+- info_ptr->color_type = PNG_COLOR_TYPE_RGB_ALPHA;
++ png_set_IHDR(png_ptr, info_ptr, pdev->width, pdev->height,
++ 8, PNG_COLOR_TYPE_RGB_ALPHA,
++ PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT,
++ PNG_FILTER_TYPE_DEFAULT);
+ png_set_invert_alpha(png_ptr);
+ { gx_device_pngalpha *ppdev = (gx_device_pngalpha *)pdev;
+ png_color_16 background;
+@@ -292,51 +279,68 @@
+ png_set_bKGD(png_ptr, info_ptr, &background);
+ }
+ break;
++ case 48:
++ png_set_IHDR(png_ptr, info_ptr, pdev->width, pdev->height,
++ 16, PNG_COLOR_TYPE_RGB,
++ PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT,
++ PNG_FILTER_TYPE_DEFAULT);
++#if defined(ARCH_IS_BIG_ENDIAN) && (!ARCH_IS_BIG_ENDIAN)
++ png_set_swap(png_ptr);
++#endif
++ break;
+ case 24:
+- info_ptr->bit_depth = 8;
+- info_ptr->color_type = PNG_COLOR_TYPE_RGB;
++ png_set_IHDR(png_ptr, info_ptr, pdev->width, pdev->height,
++ 8, PNG_COLOR_TYPE_RGB,
++ PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT,
++ PNG_FILTER_TYPE_DEFAULT);
+ break;
+ case 8:
+- info_ptr->bit_depth = 8;
+- if (gx_device_has_color(pdev))
+- info_ptr->color_type = PNG_COLOR_TYPE_PALETTE;
+- else
+- info_ptr->color_type = PNG_COLOR_TYPE_GRAY;
++ png_set_IHDR(png_ptr, info_ptr, pdev->width, pdev->height,
++ 8, gx_device_has_color(pdev) ?
++ PNG_COLOR_TYPE_PALETTE : PNG_COLOR_TYPE_GRAY,
++ PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT,
++ PNG_FILTER_TYPE_DEFAULT);
+ break;
+ case 4:
+- info_ptr->bit_depth = 4;
+- info_ptr->color_type = PNG_COLOR_TYPE_PALETTE;
++ png_set_IHDR(png_ptr, info_ptr, pdev->width, pdev->height,
++ 4, PNG_COLOR_TYPE_PALETTE,
++ PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT,
++ PNG_FILTER_TYPE_DEFAULT);
+ break;
+ case 1:
+- info_ptr->bit_depth = 1;
+- info_ptr->color_type = PNG_COLOR_TYPE_GRAY;
++ png_set_IHDR(png_ptr, info_ptr, pdev->width, pdev->height,
++ 1, PNG_COLOR_TYPE_PALETTE,
++ PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT,
++ PNG_FILTER_TYPE_DEFAULT);
+ /* invert monocrome pixels */
+ png_set_invert_mono(png_ptr);
+ break;
+ }
+
++ /* resolution is in pixels per meter vs. dpi */
++ png_set_pHYs(png_ptr, info_ptr,
++ (png_uint_32) (pdev->HWResolution[0] * (100.0 / 2.54)),
++ (png_uint_32) (pdev->HWResolution[1] * (100.0 / 2.54)),
++ PNG_RESOLUTION_METER);
++
+ /* set the palette if there is one */
+- if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) {
++ if (png_get_color_type(png_ptr, info_ptr) == PNG_COLOR_TYPE_PALETTE) {
+ int i;
+ int num_colors = 1 << depth;
+ gx_color_value rgb[3];
++ png_color palette[256];
++
++ if (num_colors > 256)
++ num_colors = 256;
+
+- info_ptr->palette =
+- (void *)gs_alloc_bytes(mem, 256 * sizeof(png_color),
+- "png palette");
+- if (info_ptr->palette == 0) {
+- code = gs_note_error(gs_error_VMerror);
+- goto done;
+- }
+- info_ptr->num_palette = num_colors;
+- info_ptr->valid |= PNG_INFO_PLTE;
+ for (i = 0; i < num_colors; i++) {
+ (*dev_proc(pdev, map_color_rgb)) ((gx_device *) pdev,
+ (gx_color_index) i, rgb);
+- info_ptr->palette[i].red = gx_color_value_to_byte(rgb[0]);
+- info_ptr->palette[i].green = gx_color_value_to_byte(rgb[1]);
+- info_ptr->palette[i].blue = gx_color_value_to_byte(rgb[2]);
++ palette[i].red = gx_color_value_to_byte(rgb[0]);
++ palette[i].green = gx_color_value_to_byte(rgb[1]);
++ palette[i].blue = gx_color_value_to_byte(rgb[2]);
+ }
++ png_set_PLTE(png_ptr, info_ptr, palette, num_colors);
+ }
+ /* add comment */
+ strncpy(software_key, "Software", sizeof(software_key));
+@@ -346,15 +350,16 @@
+ text_png.key = software_key;
+ text_png.text = software_text;
+ text_png.text_length = strlen(software_text);
+- info_ptr->text = &text_png;
+- info_ptr->num_text = 1;
++ png_set_text(png_ptr, info_ptr, &text_png, 1);
+
+ /* write the file information */
+ png_write_info(png_ptr, info_ptr);
+
+ /* don't write the comments twice */
++#if 0
+ info_ptr->num_text = 0;
+ info_ptr->text = NULL;
++#endif
+
+ /* Write the contents of the image. */
+ for (y = 0; y < height; y++) {
+@@ -365,8 +370,10 @@
+ /* write the rest of the file */
+ png_write_end(png_ptr, info_ptr);
+
++#if 0
+ /* if you alloced the palette, free it here */
+ gs_free_object(mem, info_ptr->palette, "png palette");
++#endif
+
+ done:
+ /* free the structures */
+@@ -376,6 +383,7 @@
+ return code;
+ }
+
++#if 0
+ /*
+ * Patch around a static reference to a never-used procedure.
+ * This could be avoided if we were willing to edit pngconf.h to
+@@ -393,6 +401,7 @@
+ {
+ }
+ #endif
++#endif
+
+ private int
+ pngalpha_open(gx_device * pdev)
diff --git a/print/ghostscript7-x11/files/patch-src-gdevvglb.c b/print/ghostscript7-x11/files/patch-src-gdevvglb.c
new file mode 100644
index 000000000000..bdacbfbbfca0
--- /dev/null
+++ b/print/ghostscript7-x11/files/patch-src-gdevvglb.c
@@ -0,0 +1,15 @@
+--- src/gdevvglb.c.orig 2015-08-22 01:41:20.966252000 +0900
++++ src/gdevvglb.c 2015-08-22 01:41:35.725091000 +0900
+@@ -373,3 +373,12 @@
+ }
+ return 0;
+ }
++
++#ifdef GS_DEVS_SHARED
++extern void gs_lib_register_device(const gx_device *dev);
++void
++gs_shared_init(void)
++{
++ gs_lib_register_device(&gs_vgalib_device);
++}
++#endif
diff --git a/print/ghostscript7-x11/files/patch-src-gdevxalt.c b/print/ghostscript7-x11/files/patch-src-gdevxalt.c
new file mode 100644
index 000000000000..4d9a88b43fb4
--- /dev/null
+++ b/print/ghostscript7-x11/files/patch-src-gdevxalt.c
@@ -0,0 +1,31 @@
+--- src/gdevxalt.c.orig 2015-08-22 01:42:12.291619000 +0900
++++ src/gdevxalt.c 2015-08-22 01:42:53.871222000 +0900
+@@ -30,6 +30,7 @@
+ #include "gdevx.h"
+
+ extern const gx_device_X gs_x11_device;
++extern const gx_device_X gs_x11alpha_device;
+
+ /*
+ * Define a forwarding device with a cache for the first 16 colors,
+@@ -957,3 +958,20 @@
+ rgb[2] = ((color >> 11) & 0x3ff) * gx_max_color_value / 0x3ff;
+ return -1;
+ }
++
++#ifdef GS_DEVS_SHARED
++extern void gs_lib_register_device(const gx_device *dev);
++void
++gs_shared_init(void)
++{
++ gs_lib_register_device(&gs_x11_device);
++ gs_lib_register_device(&gs_x11alpha_device);
++ gs_lib_register_device(&gs_x11cmyk_device);
++ gs_lib_register_device(&gs_x11cmyk2_device);
++ gs_lib_register_device(&gs_x11cmyk4_device);
++ gs_lib_register_device(&gs_x11cmyk8_device);
++ gs_lib_register_device(&gs_x11gray2_device);
++ gs_lib_register_device(&gs_x11gray4_device);
++ gs_lib_register_device(&gs_x11mono_device);
++}
++#endif
diff --git a/print/ghostscript7-x11/files/patch-src-gnudevs.mak b/print/ghostscript7-x11/files/patch-src-gnudevs.mak
new file mode 100644
index 000000000000..d6e15432bf52
--- /dev/null
+++ b/print/ghostscript7-x11/files/patch-src-gnudevs.mak
@@ -0,0 +1,67 @@
+--- src/gnudevs.mak.orig 2003-02-10 03:12:48.000000000 +0900
++++ src/gnudevs.mak 2015-08-22 00:20:45.754922000 +0900
+@@ -66,64 +66,6 @@
+ $(DD)sxlcrt.dev : $(sxlcrt_) $(DD)page.dev
+ $(SETPDEV) $(DD)sxlcrt $(sxlcrt_)
+
+-
+-### -------------------- Gimp-Print (stp) driver -------------------###
+-
+-# To include this driver add '$(DD)stp.dev' to your DEVICE_DEVS
+-# line and define 'STPLIB=gimpprint' in your top-level makefile.
+-# See http://gimp-print.sourceforge.net/ for more information.
+-
+-stp_=$(GLOBJ)gdevstp.$(OBJ)
+-
+-$(DD)stp.dev : $(stp_) $(DD)page.dev
+- $(SETPDEV) $(DD)stp $(stp_)
+- $(ADDMOD) $(DD)stp -lib $(STPLIB)
+-
+-$(GLOBJ)gdevstp.$(OBJ) : $(GLSRC)gdevstp.c \
+- $(gdevprn_h) $(gdevpccm_h) $(gsparam_h)
+- $(GLCC) $(GLO_)gdevstp.$(OBJ) $(C_) $(GLSRC)gdevstp.c
+-
+-
+-### -------------- cdj850 - HP 850c Driver under development ------------- ###
+-
+-cdeskjet8_=$(GLOBJ)gdevcd8.$(OBJ) $(HPPCL)
+-
+-# Author: Uli Wortmann (uliw@erdw.ethz.ch), Martin Gerbershagen (ger@ulm.temic.de)
+-# Printer: HP 670
+-$(DD)cdj670.dev : $(cdeskjet8_) $(DD)page.dev
+- $(SETPDEV2) $(DD)cdj670 $(cdeskjet8_)
+-
+-# Author: Uli Wortmann (uliw@erdw.ethz.ch)
+-# Printer: HP 850
+-$(DD)cdj850.dev : $(cdeskjet8_) $(DD)page.dev
+- $(SETPDEV2) $(DD)cdj850 $(cdeskjet8_)
+-
+-# Author: Uli Wortmann (uliw@erdw.ethz.ch), Martin Gerbershagen (ger@ulm.temic.de)
+-# Printer: HP 890
+-$(DD)cdj890.dev : $(cdeskjet8_) $(DD)page.dev
+- $(SETPDEV2) $(DD)cdj890 $(cdeskjet8_)
+-
+-# Author: Uli Wortmann (uliw@erdw.ethz.ch), Martin Gerbershagen (ger@ulm.temic.de)
+-# Printer: HP 1600
+-$(DD)cdj1600.dev : $(cdeskjet8_) $(DD)page.dev
+- $(SETPDEV2) $(DD)cdj1600 $(cdeskjet8_)
+-
+-$(GLOBJ)gdevcd8.$(OBJ) : $(GLSRC)gdevcd8.c $(PDEVH) $(math__h)\
+- $(gsparam_h) $(gxlum_h) $(gdevpcl_h)
+- $(GLCC) $(GLO_)gdevcd8.$(OBJ) $(C_) $(GLSRC)gdevcd8.c
+-
+-### -------------- cdj880 - HP 880c Driver under development ------------- ###
+-### Since this driver is in the development phase it is not distributed ###
+-### with Ghostscript, but is available from ###
+-### http://www.proaxis.com/~mgelhaus/linux/software/hp880c/hp880c.html ###
+-
+-### NOTE: Depends on the presence of the cdj850 section above. ###
+-
+-# Author: Matthew Gelhaus (mgelhaus@proaxis.com)
+-# Printer: HP 880c
+-$(DD)cdj880.dev : $(cdeskjet8_) $(DD)page.dev
+- $(SETPDEV2) $(DD)cdj880 $(cdeskjet8_)
+-
+ ### ------------- cdj970 - HP 970Cxi Driver under development ------------- ###
+
+ cdeskjet9_=$(GLOBJ)gdevdj9.$(OBJ) $(HPPCL)
diff --git a/print/ghostscript7-x11/files/patch-src-gp_unix.c b/print/ghostscript7-x11/files/patch-src-gp_unix.c
new file mode 100644
index 000000000000..85f56e3cc021
--- /dev/null
+++ b/print/ghostscript7-x11/files/patch-src-gp_unix.c
@@ -0,0 +1,83 @@
+--- src/gp_unix.c.orig 2003-01-17 09:49:02.000000000 +0900
++++ src/gp_unix.c 2015-08-22 01:54:32.507486000 +0900
+@@ -41,11 +41,60 @@
+
+ #endif
+
++#ifdef GS_DEVS_SHARED
++#ifndef GS_DEVS_SHARED_DIR
++# define GS_DEVS_SHARED_DIR "/usr/lib/ghostscript/7.07"
++#endif
++
++/*
++ * use shared library for drivers, always load them when starting, this
++ * avoid too many modifications, and since it is supported only under linux
++ * and applied as a patch (preferable).
++ */
++#include <sys/types.h>
++#include <limits.h>
++#include <dirent.h>
++#include <dlfcn.h>
++#include <string.h>
++
++void
++gp_init(void)
++{
++ DIR* dir = NULL;
++ struct dirent* dirent;
++ char buff[PATH_MAX];
++ char* pbuff;
++ void* handle;
++ void (*gs_shared_init)(void);
++
++ dir = opendir(GS_DEVS_SHARED_DIR);
++ if (dir == 0) return;
++
++ lprintf("DEBUG 2\n");
++
++ while ((dirent = readdir(dir)) != 0) {
++ snprintf(buff, sizeof(buff), "%s/%s", GS_DEVS_SHARED_DIR, dirent->d_name);
++ pbuff = buff + strlen(buff) - 3;
++ if (strcmp(pbuff, ".so") != 0)
++ continue;
++ handle = dlopen(buff, RTLD_NOW);
++ if (handle == NULL)
++ continue;
++ gs_shared_init = dlsym(handle, "gs_shared_init");
++ if (gs_shared_init != NULL)
++ (*gs_shared_init)();
++ }
++ lprintf("DEBUG 3\n");
++
++ closedir(dir);
++}
++#else
+ /* Do platform-dependent initialization. */
+ void
+ gp_init(void)
+ {
+ }
++#endif
+
+ /* Do platform-dependent cleanup. */
+ void
+@@ -57,6 +106,7 @@
+ void
+ gp_do_exit(int exit_status)
+ {
++ exit(exit_status);
+ }
+
+ /* ------ Miscellaneous ------ */
+@@ -67,7 +117,11 @@
+ const char *
+ gp_strerror(int errnum)
+ {
++#ifdef HAVE_STRERROR
++ return strerror(errnum);
++#else
+ return NULL;
++#endif
+ }
+
+ /* ------ Date and time ------ */
diff --git a/print/ghostscript7-x11/files/patch-src-gs.mak b/print/ghostscript7-x11/files/patch-src-gs.mak
new file mode 100644
index 000000000000..a9ee54700595
--- /dev/null
+++ b/print/ghostscript7-x11/files/patch-src-gs.mak
@@ -0,0 +1,19 @@
+--- src/gs.mak.orig 2015-08-21 22:03:26.487964000 +0900
++++ src/gs.mak 2015-08-21 22:04:09.624656000 +0900
+@@ -235,7 +235,7 @@
+ gconfig_h=$(GLGENDIR)$(D)gconfxx.h
+ gconfigf_h=$(GLGENDIR)$(D)gconfxc.h
+
+-all default : $(GS_XE)
++all default : $(GS_XE) $(GS_SHARED_OBJS)
+ $(NO_OP)
+
+ # the distclean and maintainer-clean targets (if any)
+@@ -248,6 +248,7 @@
+ clean : mostlyclean
+ $(RM_) $(GSGEN)arch.h
+ $(RM_) $(GS_XE)
++ $(RM_) $(GS_SHARED_OBJS)
+
+ #****** FOLLOWING IS WRONG, NEEDS TO BE PER-SUBSYSTEM ******
+ mostlyclean : config-clean
diff --git a/print/ghostscript7-x11/files/patch-src-gsalloc.c b/print/ghostscript7-x11/files/patch-src-gsalloc.c
new file mode 100644
index 000000000000..7c29a14eeada
--- /dev/null
+++ b/print/ghostscript7-x11/files/patch-src-gsalloc.c
@@ -0,0 +1,11 @@
+--- src/gsalloc.c.orig 2013-04-30 11:14:17.000000000 +0900
++++ src/gsalloc.c 2013-04-30 11:14:34.000000000 +0900
+@@ -195,7 +195,7 @@
+ iimem->large_size = ((chunk_size / 4) & -obj_align_mod) + 1;
+ iimem->is_controlled = false;
+ iimem->gc_status.vm_threshold = chunk_size * 3L;
+- iimem->gc_status.max_vm = max_long;
++ iimem->gc_status.max_vm = 0x7fffffff;
+ iimem->gc_status.psignal = NULL;
+ iimem->gc_status.signal_value = 0;
+ iimem->gc_status.enabled = false;
diff --git a/print/ghostscript7-x11/files/patch-src-gsmalloc.c b/print/ghostscript7-x11/files/patch-src-gsmalloc.c
new file mode 100644
index 000000000000..9b4d97da3844
--- /dev/null
+++ b/print/ghostscript7-x11/files/patch-src-gsmalloc.c
@@ -0,0 +1,11 @@
+--- src/gsmalloc.c.orig 2015-07-24 09:55:54.032137000 +0900
++++ src/gsmalloc.c 2015-07-24 09:57:15.070246000 +0900
+@@ -170,7 +170,7 @@
+ } else {
+ uint added = size + sizeof(gs_malloc_block_t);
+
+- if (mmem->limit - added < mmem->used)
++ if (added <= size || mmem->limit - added < mmem->used)
+ set_msg("exceeded limit");
+ else if ((ptr = (byte *) malloc(added)) == 0)
+ set_msg("failed");
diff --git a/print/ghostscript7-x11/files/patch-src-gxclrast.c b/print/ghostscript7-x11/files/patch-src-gxclrast.c
new file mode 100644
index 000000000000..59d5053ad305
--- /dev/null
+++ b/print/ghostscript7-x11/files/patch-src-gxclrast.c
@@ -0,0 +1,15 @@
+--- src/gxclrast.c.orig 2013-04-30 09:13:13.000000000 +0900
++++ src/gxclrast.c 2013-04-30 09:13:41.000000000 +0900
+@@ -87,10 +87,10 @@
+ private long
+ cmd_get_w(const byte * p, const byte ** rp)
+ {
+- long val = *p++ & 0x7f;
++ int val = *p++ & 0x7f;
+ int shift = 7;
+
+- for (; val += (long)(*p & 0x7f) << shift, *p++ > 0x7f; shift += 7);
++ for (; val += (int)(*p & 0x7f) << shift, *p++ > 0x7f; shift += 7);
+ *rp = p;
+ return val;
+ }
diff --git a/print/ghostscript7-x11/files/patch-src-gxfixed.h b/print/ghostscript7-x11/files/patch-src-gxfixed.h
new file mode 100644
index 000000000000..0988ca612c9b
--- /dev/null
+++ b/print/ghostscript7-x11/files/patch-src-gxfixed.h
@@ -0,0 +1,46 @@
+--- src/gxfixed.h.orig 2013-04-30 11:29:39.000000000 +0900
++++ src/gxfixed.h 2013-04-30 11:31:03.000000000 +0900
+@@ -27,12 +27,22 @@
+ * quantities: integers lose accuracy in crucial places,
+ * and floating point arithmetic is slow.
+ */
+-typedef long fixed;
+-typedef ulong ufixed; /* only used in a very few places */
+-#define ARCH_SIZEOF_FIXED ARCH_SIZEOF_LONG
++#if ARCH_SIZEOF_INT == 4
++typedef int fixed;
++typedef uint ufixed; /* only used in a very few places */
++# define ARCH_SIZEOF_FIXED ARCH_SIZEOF_INT
++# define max_fixed max_int
++# define min_fixed min_int
++#else
++# if ARCH_SIZEOF_LONG == 4
++ typedef long fixed;
++ typedef ulong ufixed; /* only used in a very few places */
++# define ARCH_SIZEOF_FIXED ARCH_SIZEOF_LONG
++# define max_fixed max_long
++# define min_fixed min_long
++# endif
++#endif
+
+-#define max_fixed max_long
+-#define min_fixed min_long
+ #define fixed_0 0L
+ #define fixed_epsilon 1L
+ /*
+@@ -120,13 +130,8 @@
+ #define fixed_truncated(x) ((x) < 0 ? fixed_ceiling(x) : fixed_floor(x))
+
+ /* Define the largest and smallest integer values that fit in a fixed. */
+-#if arch_sizeof_int == arch_sizeof_long
+-# define max_int_in_fixed fixed2int(max_fixed)
+-# define min_int_in_fixed fixed2int(min_fixed)
+-#else
+-# define max_int_in_fixed max_int
+-# define min_int_in_fixed min_int
+-#endif
++#define max_int_in_fixed fixed2int(max_fixed)
++#define min_int_in_fixed fixed2int(min_fixed)
+
+ #ifdef USE_FPU
+ # define USE_FPU_FIXED (USE_FPU < 0 && arch_floats_are_IEEE && arch_sizeof_long == 4)
diff --git a/print/ghostscript7-x11/files/patch-src-ibnum.c b/print/ghostscript7-x11/files/patch-src-ibnum.c
new file mode 100644
index 000000000000..2df0a7d138c7
--- /dev/null
+++ b/print/ghostscript7-x11/files/patch-src-ibnum.c
@@ -0,0 +1,49 @@
+--- src/ibnum.c.orig 2003-01-17 09:49:04.000000000 +0900
++++ src/ibnum.c 2013-04-30 11:18:27.000000000 +0900
+@@ -124,11 +124,11 @@
+ case num_int32:
+ case num_int32 + 16:
+ if ((format & 31) == 0) {
+- np->value.intval = sdecodelong(str, format);
++ np->value.intval = sdecodeint32(str, format);
+ return t_integer;
+ } else {
+ np->value.realval =
+- (double)sdecodelong(str, format) *
++ (double)sdecodeint32(str, format) *
+ binary_scale[format & 31];
+ return t_real;
+ }
+@@ -171,18 +171,14 @@
+ }
+
+ /* Decode a (32-bit, signed) long. */
+-long
+-sdecodelong(const byte * p, int format)
++int
++sdecodeint32(const byte * p, int format)
+ {
+ int a = p[0], b = p[1], c = p[2], d = p[3];
+- long v = (num_is_lsb(format) ?
+- ((long)d << 24) + ((long)c << 16) + (b << 8) + a :
+- ((long)a << 24) + ((long)b << 16) + (c << 8) + d);
++ int v = (num_is_lsb(format) ?
++ ((int)d << 24) + ((int)c << 16) + (b << 8) + a :
++ ((int)a << 24) + ((int)b << 16) + (c << 8) + d);
+
+-#if arch_sizeof_long > 4
+- /* Propagate bit 31 as the sign. */
+- v = (v ^ 0x80000000L) - 0x80000000L;
+-#endif
+ return v;
+ }
+
+@@ -190,7 +186,7 @@
+ float
+ sdecodefloat(const byte * p, int format)
+ {
+- bits32 lnum = (bits32) sdecodelong(p, format);
++ bits32 lnum = (bits32) sdecodeint32(p, format);
+ float fnum;
+
+ #if !arch_floats_are_IEEE
diff --git a/print/ghostscript7-x11/files/patch-src-ibnum.h b/print/ghostscript7-x11/files/patch-src-ibnum.h
new file mode 100644
index 000000000000..ffec70cac2ae
--- /dev/null
+++ b/print/ghostscript7-x11/files/patch-src-ibnum.h
@@ -0,0 +1,11 @@
+--- src/ibnum.h.orig 2013-04-30 10:50:12.000000000 +0900
++++ src/ibnum.h 2013-04-30 10:50:29.000000000 +0900
+@@ -60,7 +60,7 @@
+ int sdecode_number(P3(const byte *, int, ref *));
+ int sdecodeshort(P2(const byte *, int));
+ uint sdecodeushort(P2(const byte *, int));
+-long sdecodelong(P2(const byte *, int));
++int sdecodeint32(P2(const byte *, int));
+ float sdecodefloat(P2(const byte *, int));
+
+ #endif /* ibnum_INCLUDED */
diff --git a/print/ghostscript7-x11/files/patch-src-icclib.mak b/print/ghostscript7-x11/files/patch-src-icclib.mak
new file mode 100644
index 000000000000..a60ef670dfa2
--- /dev/null
+++ b/print/ghostscript7-x11/files/patch-src-icclib.mak
@@ -0,0 +1,11 @@
+--- src/icclib.mak.orig 2013-04-30 02:10:16.000000000 +0900
++++ src/icclib.mak 2013-04-30 02:10:26.000000000 +0900
+@@ -73,7 +73,7 @@
+
+ icc_h=$(ICCSRC)$(D)icc.h $(ICCSRC)$(D)icc$(ICCPROFVER).h
+
+-$(ICCOBJ)icc.$(OBJ) : $(ICCSRC)icc.c $(ICCDEP) $(icc_h)
++$(ICCOBJ)icc.$(OBJ) : ${ECHOGS_XE} $(ICCSRC)icc.c $(ICCDEP) $(icc_h)
+ # echo $(ICC_CCFLAGS)
+ $(EXP)$(ECHOGS_XE) $(ICC_CCFLAGS)
+ $(ICC_CC) $(ICCO_)icc.$(OBJ) $(C_) $(ICCSRC)icc.c
diff --git a/print/ghostscript7-x11/files/patch-src-idebug.c b/print/ghostscript7-x11/files/patch-src-idebug.c
new file mode 100644
index 000000000000..142926b4474b
--- /dev/null
+++ b/print/ghostscript7-x11/files/patch-src-idebug.c
@@ -0,0 +1,11 @@
+--- src/idebug.c.orig 2013-04-30 11:06:57.000000000 +0900
++++ src/idebug.c 2013-04-30 11:07:09.000000000 +0900
+@@ -90,7 +90,7 @@
+ case t_fontID:
+ goto strct;
+ case t_integer:
+- dprintf1("int %ld", pref->value.intval);
++ dprintf1("int %d", pref->value.intval);
+ break;
+ case t_mark:
+ dprintf("mark");
diff --git a/print/ghostscript7-x11/files/patch-src-idparam.c b/print/ghostscript7-x11/files/patch-src-idparam.c
new file mode 100644
index 000000000000..636d7c16b510
--- /dev/null
+++ b/print/ghostscript7-x11/files/patch-src-idparam.c
@@ -0,0 +1,21 @@
+--- src/idparam.c.orig 2013-04-30 10:54:55.000000000 +0900
++++ src/idparam.c 2013-04-30 10:55:23.000000000 +0900
+@@ -61,8 +61,7 @@
+ int maxval, int defaultval, int *pvalue)
+ {
+ ref *pdval;
+- int code;
+- long ival;
++ int code, ival;
+
+ if (pdict == 0 || dict_find_string(pdict, kstr, &pdval) <= 0) {
+ ival = defaultval;
+@@ -349,7 +348,7 @@
+ } else {
+ if (!r_has_type(puniqueid, t_integer) ||
+ puniqueid->value.intval < 0 ||
+- puniqueid->value.intval > 0xffffffL
++ puniqueid->value.intval > 0xffffff
+ )
+ return_error(e_rangecheck);
+ /* Apparently fonts created by Fontographer often have */
diff --git a/print/ghostscript7-x11/files/patch-src-ijs.mak b/print/ghostscript7-x11/files/patch-src-ijs.mak
new file mode 100644
index 000000000000..be8ee7807ac5
--- /dev/null
+++ b/print/ghostscript7-x11/files/patch-src-ijs.mak
@@ -0,0 +1,20 @@
+--- src/ijs.mak.orig 2003-01-17 09:49:04.000000000 +0900
++++ src/ijs.mak 2013-04-30 02:24:08.000000000 +0900
+@@ -66,7 +66,7 @@
+ ijs_client_h=$(IJSSRC)$(D)ijs_client.h
+ ijs_server_h=$(IJSSRC)$(D)ijs_server.h
+
+-$(IJSOBJ)ijs.$(OBJ) : $(IJSSRC)ijs.c $(IJSDEP) $(ijs_h)
++$(IJSOBJ)ijs.$(OBJ) : ${ECHOGS_XE} $(IJSSRC)ijs.c $(IJSDEP) $(ijs_h)
+ # echo $(IJS_CCFLAGS)
+ $(EXP)$(ECHOGS_XE) $(IJS_CCFLAGS)
+ $(IJS_CC) $(IJSO_)ijs.$(OBJ) $(C_) $(IJSSRC)ijs.c
+@@ -79,7 +79,7 @@
+ $(IJSDEP) $(ijs_h) $(ijs_server_h)
+ $(IJS_CC) $(IJSO_)ijs_server.$(OBJ) $(C_) $(IJSSRC)ijs_server.c
+
+-$(IJSOBJ)ijs_exec_unix.$(OBJ) : $(IJSSRC)ijs_exec_unix.c \
++$(IJSOBJ)ijs_exec_unix.$(OBJ) : $(arch_h) $(IJSSRC)ijs_exec_unix.c \
+ $(IJSDEP) $(ijs_h) $(ijs_client_h)
+ $(IJS_CC) $(IJSO_)ijs_exec_unix.$(OBJ) $(C_) $(IJSSRC)ijs_exec_unix.c
+
diff --git a/print/ghostscript7-x11/files/patch-src-int.mak b/print/ghostscript7-x11/files/patch-src-int.mak
new file mode 100644
index 000000000000..9e4c5a2c7663
--- /dev/null
+++ b/print/ghostscript7-x11/files/patch-src-int.mak
@@ -0,0 +1,24 @@
+--- src/int.mak.orig 2013-04-30 02:55:45.000000000 +0900
++++ src/int.mak 2013-04-30 02:56:06.000000000 +0900
+@@ -953,10 +953,10 @@
+
+ # We select either iccinit0 or iccinit1 depending on COMPILE_INITS.
+
+-$(PSOBJ)iccinit0.$(OBJ) : $(PSSRC)iccinit0.c $(stdpre_h)
++$(PSOBJ)iccinit0.$(OBJ) : $(arch_h) $(PSSRC)iccinit0.c $(stdpre_h)
+ $(PSCC) $(PSO_)iccinit0.$(OBJ) $(C_) $(PSSRC)iccinit0.c
+
+-$(PSOBJ)iccinit1.$(OBJ) : $(PSOBJ)gs_init.$(OBJ)
++$(PSOBJ)iccinit1.$(OBJ) : $(arch_h) $(PSOBJ)gs_init.$(OBJ)
+ $(CP_) $(PSOBJ)gs_init.$(OBJ) $(PSOBJ)iccinit1.$(OBJ)
+
+ # All the gs_*.ps files should be prerequisites of gs_init.c,
+@@ -964,7 +964,7 @@
+ $(PSGEN)gs_init.c : $(PSLIB)$(GS_INIT) $(GENINIT_XE) $(gconfig_h)
+ $(EXP)$(GENINIT_XE) -I $(PSLIB) $(GS_INIT) $(gconfig_h) -c $(PSGEN)gs_init.c
+
+-$(PSOBJ)gs_init.$(OBJ) : $(PSGEN)gs_init.c $(stdpre_h)
++$(PSOBJ)gs_init.$(OBJ) : $(arch_h) $(PSGEN)gs_init.c $(stdpre_h)
+ $(PSCC) $(PSO_)gs_init.$(OBJ) $(C_) $(PSGEN)gs_init.c
+
+ # ---------------- Stochastic halftone ---------------- #
diff --git a/print/ghostscript7-x11/files/patch-src-iparam.c b/print/ghostscript7-x11/files/patch-src-iparam.c
new file mode 100644
index 000000000000..b0bb91a4d3ef
--- /dev/null
+++ b/print/ghostscript7-x11/files/patch-src-iparam.c
@@ -0,0 +1,33 @@
+--- src/iparam.c.orig 2013-04-30 11:12:36.000000000 +0900
++++ src/iparam.c 2013-04-30 11:13:07.000000000 +0900
+@@ -67,7 +67,7 @@
+ int len;
+ byte *buf;
+
+- sprintf(istr, "%ld", pref->value.intval);
++ sprintf(istr, "%d", pref->value.intval);
+ len = strlen(istr);
+ /* GC will take care of freeing this: */
+ buf = gs_alloc_string(plist->memory, len, "ref_to_key");
+@@ -394,7 +394,7 @@
+ {
+ int code;
+ stack_param_list *const splist = (stack_param_list *) plist;
+- long index = penum->intval;
++ int index = penum->intval;
+ ref *stack_element;
+
+ do {
+@@ -563,12 +563,6 @@
+ code = gs_note_error(e_typecheck);
+ break;
+ }
+-#if arch_sizeof_int < arch_sizeof_long
+- if (elt.value.intval != (int)elt.value.intval) {
+- code = gs_note_error(e_rangecheck);
+- break;
+- }
+-#endif
+ piv[i] = (int)elt.value.intval;
+ }
+ if (code < 0) {
diff --git a/print/ghostscript7-x11/files/patch-src-iref.h b/print/ghostscript7-x11/files/patch-src-iref.h
new file mode 100644
index 000000000000..33313d38047b
--- /dev/null
+++ b/print/ghostscript7-x11/files/patch-src-iref.h
@@ -0,0 +1,11 @@
+--- src/iref.h.orig 2013-04-30 11:13:29.000000000 +0900
++++ src/iref.h 2013-04-30 11:13:41.000000000 +0900
+@@ -441,7 +441,7 @@
+ #define r_set_ptr(rp,ptr) ((rp)->value.pstruct = (obj_header_t *)(ptr))
+
+ union v { /* name the union to keep gdb happy */
+- long intval;
++ int intval;
+ ushort boolval;
+ float realval;
+ ulong saveid;
diff --git a/print/ghostscript7-x11/files/patch-src-iscan.c b/print/ghostscript7-x11/files/patch-src-iscan.c
new file mode 100644
index 000000000000..cd8b03f6ab56
--- /dev/null
+++ b/print/ghostscript7-x11/files/patch-src-iscan.c
@@ -0,0 +1,11 @@
+--- src/iscan.c.orig 2013-04-30 10:47:49.000000000 +0900
++++ src/iscan.c 2013-04-30 10:48:19.000000000 +0900
+@@ -635,7 +635,7 @@
+ uint size = ref_stack_count_inline(&o_stack) - pstack;
+ ref arr;
+
+- if_debug4('S', "[S}]d=%d, s=%d->%ld, c=%d\n",
++ if_debug4('S', "[S}]d=%d, s=%d->%d, c=%d\n",
+ pdepth, pstack,
+ (pstack == pdepth ? 0 :
+ ref_stack_index(&o_stack, size)->value.intval),
diff --git a/print/ghostscript7-x11/files/patch-src-iscanbin.c b/print/ghostscript7-x11/files/patch-src-iscanbin.c
new file mode 100644
index 000000000000..1f39c88b7209
--- /dev/null
+++ b/print/ghostscript7-x11/files/patch-src-iscanbin.c
@@ -0,0 +1,83 @@
+--- src/iscanbin.c.orig 2013-04-30 10:51:53.000000000 +0900
++++ src/iscanbin.c 2013-04-30 10:53:42.000000000 +0900
+@@ -173,7 +173,7 @@
+ pbs->num_format = num_format;
+ if (top_size == 0) {
+ /* Extended header (2-byte array size, 4-byte length) */
+- ulong lsize;
++ uint lsize;
+
+ if (rcnt < 7) {
+ s_end_inline(s, p - 1, rlimit);
+@@ -183,7 +183,7 @@
+ if (p[1] != 0) /* reserved, must be 0 */
+ return_error(e_syntaxerror);
+ top_size = sdecodeushort(p + 2, num_format);
+- lsize = sdecodelong(p + 4, num_format);
++ lsize = sdecodeint32(p + 4, num_format);
+ if ((size = lsize) != lsize)
+ return_error(e_limitcheck);
+ hsize = 8;
+@@ -445,8 +445,7 @@
+ for (; index < max_array_index; p += SIZEOF_BIN_SEQ_OBJ, index++) {
+ ref *op = abase + index;
+ uint osize;
+- long value;
+- uint atype, attrs;
++ int value, atype, attrs;
+
+ s_end_inline(s, p, rlimit); /* in case of error */
+ if (rlimit - p < SIZEOF_BIN_SEQ_OBJ) {
+@@ -464,14 +463,14 @@
+ make_null(op);
+ break;
+ case BS_TYPE_INTEGER:
+- make_int(op, sdecodelong(p + 5, num_format));
++ make_int(op, sdecodeint32(p + 5, num_format));
+ break;
+ case BS_TYPE_REAL:{
+ float vreal;
+
+ osize = sdecodeushort(p + 3, num_format);
+ if (osize != 0) { /* fixed-point number */
+- value = sdecodelong(p + 5, num_format);
++ value = sdecodeint32(p + 5, num_format);
+ vreal = (float)ldexp((double)value, -osize);
+ } else {
+ vreal = sdecodefloat(p + 5, num_format);
+@@ -480,7 +479,7 @@
+ break;
+ }
+ case BS_TYPE_BOOLEAN:
+- make_bool(op, sdecodelong(p + 5, num_format) != 0);
++ make_bool(op, sdecodeint32(p + 5, num_format) != 0);
+ break;
+ case BS_TYPE_STRING:
+ osize = sdecodeushort(p + 3, num_format);
+@@ -492,7 +491,7 @@
+ make_empty_string(op, attrs);
+ break;
+ }
+- value = sdecodelong(p + 5, num_format);
++ value = sdecodeint32(p + 5, num_format);
+ if (value < max_array_index * SIZEOF_BIN_SEQ_OBJ ||
+ value + osize > size
+ )
+@@ -524,7 +523,7 @@
+ /* falls through */
+ case BS_TYPE_NAME:
+ osize = sdecodeushort(p + 3, num_format);
+- value = sdecodelong(p + 5, num_format);
++ value = sdecodeint32(p + 5, num_format);
+ switch (osize) {
+ case 0:
+ code = array_get(user_names_p, value, op);
+@@ -546,7 +545,7 @@
+ osize = sdecodeushort(p + 3, num_format);
+ atype = t_array;
+ arr:
+- value = sdecodelong(p + 5, num_format);
++ value = sdecodeint32(p + 5, num_format);
+ if (value + osize > min_string_index ||
+ value & (SIZEOF_BIN_SEQ_OBJ - 1)
+ )
diff --git a/print/ghostscript7-x11/files/patch-src-iscannum.c b/print/ghostscript7-x11/files/patch-src-iscannum.c
new file mode 100644
index 000000000000..4a69664074a6
--- /dev/null
+++ b/print/ghostscript7-x11/files/patch-src-iscannum.c
@@ -0,0 +1,203 @@
+--- src/iscannum.c.orig 2003-01-17 09:49:04.000000000 +0900
++++ src/iscannum.c 2013-04-30 11:17:14.000000000 +0900
+@@ -57,7 +57,6 @@
+ };
+
+ int ival;
+- long lval;
+ double dval;
+ int exp10;
+ int code = 0;
+@@ -104,8 +103,26 @@
+ GET_NEXT(c, sp, goto iret);
+ if (!IS_DIGIT(d, c))
+ break;
+- if (WOULD_OVERFLOW(ival, d, max_int))
+- goto i2l;
++ if (WOULD_OVERFLOW((unsigned)ival, d, max_int)) {
++ /* goto i2l; */
++ if (ival == max_int / 10 && d == (max_int % 10) + 1 && sign < 0) {
++ GET_NEXT(c, sp, c= EOFC);
++ dval = -(double)min_int;
++ if (c == 'e' || c == 'E') {
++ exp10 = 0;
++ goto fs;
++ } else if (c == '.') {
++ GET_NEXT(c, sp, c = EOFC);
++ exp10 = 0;
++ goto fd;
++ } else if (!IS_DIGIT(d, c)) {
++ ival = min_int;
++ break;
++ }
++ } else
++ dval = ival;
++ goto l2d;
++ }
+ }
+ ind: /* We saw a non-digit while accumulating an integer in ival. */
+ switch (c) {
+@@ -116,6 +133,8 @@
+ *psp = sp;
+ code = 1;
+ break;
++ case EOFC:
++ break;
+ case 'e':
+ case 'E':
+ if (sign < 0)
+@@ -125,8 +144,8 @@
+ goto fe;
+ case '#':
+ {
+- const uint radix = (uint)ival;
+- ulong uval = 0, lmax;
++ const int radix = ival;
++ uint uval = 0, imax;
+
+ if (sign || radix < min_radix || radix > max_radix)
+ return_error(e_syntaxerror);
+@@ -136,19 +155,19 @@
+
+ switch (radix) {
+ case 2:
+- shift = 1, lmax = max_ulong >> 1;
++ shift = 1, imax = max_uint >> 1;
+ break;
+ case 4:
+- shift = 2, lmax = max_ulong >> 2;
++ shift = 2, imax = max_uint >> 2;
+ break;
+ case 8:
+- shift = 3, lmax = max_ulong >> 3;
++ shift = 3, imax = max_uint >> 3;
+ break;
+ case 16:
+- shift = 4, lmax = max_ulong >> 4;
++ shift = 4, imax = max_uint >> 4;
+ break;
+ case 32:
+- shift = 5, lmax = max_ulong >> 5;
++ shift = 5, imax = max_uint >> 5;
+ break;
+ default: /* can't happen */
+ return_error(e_rangecheck);
+@@ -161,13 +180,13 @@
+ code = 1;
+ break;
+ }
+- if (uval > lmax)
++ if (uval > imax)
+ return_error(e_limitcheck);
+ }
+ } else {
+- int lrem = max_ulong % radix;
++ int irem = max_uint % radix;
+
+- lmax = max_ulong / radix;
++ imax = max_uint / radix;
+ for (;; uval = uval * radix + d) {
+ GET_NEXT(c, sp, break);
+ d = decoder[c];
+@@ -176,8 +195,8 @@
+ code = 1;
+ break;
+ }
+- if (uval >= lmax &&
+- (uval > lmax || d > lrem)
++ if (uval >= imax &&
++ (uval > imax || d > irem)
+ )
+ return_error(e_limitcheck);
+ }
+@@ -190,55 +209,6 @@
+ make_int(pref, (sign < 0 ? -ival : ival));
+ return code;
+
+- /* Accumulate a long in lval. */
+-i2l:
+- for (lval = ival;;) {
+- if (WOULD_OVERFLOW(lval, d, max_long)) {
+- /* Make a special check for entering the smallest */
+- /* (most negative) integer. */
+- if (lval == max_long / 10 &&
+- d == (int)(max_long % 10) + 1 && sign < 0
+- ) {
+- GET_NEXT(c, sp, c = EOFC);
+- dval = -(double)min_long;
+- if (c == 'e' || c == 'E' || c == '.') {
+- exp10 = 0;
+- goto fs;
+- } else if (!IS_DIGIT(d, c)) {
+- lval = min_long;
+- break;
+- }
+- } else
+- dval = lval;
+- goto l2d;
+- }
+- lval = lval * 10 + d;
+- GET_NEXT(c, sp, goto lret);
+- if (!IS_DIGIT(d, c))
+- break;
+- }
+- switch (c) {
+- case '.':
+- GET_NEXT(c, sp, c = EOFC);
+- exp10 = 0;
+- goto l2r;
+- case EOFC:
+- break;
+- default:
+- *psp = sp;
+- code = 1;
+- break;
+- case 'e':
+- case 'E':
+- exp10 = 0;
+- goto le;
+- case '#':
+- return_error(e_syntaxerror);
+- }
+-lret:
+- make_int(pref, (sign < 0 ? -lval : lval));
+- return code;
+-
+ /* Accumulate a double in dval. */
+ l2d:
+ exp10 = 0;
+@@ -274,8 +244,8 @@
+ exp10 = 0;
+ while (IS_DIGIT(d, c)) {
+ if (WOULD_OVERFLOW(ival, d, max_int)) {
+- lval = ival;
+- goto l2r;
++ dval = ival;
++ goto fd;
+ }
+ ival = ival * 10 + d;
+ exp10--;
+@@ -293,23 +263,6 @@
+ dval = ival;
+ goto fe;
+
+- /* We saw a '.' while accumulating a long in lval. */
+-l2r:
+- while (IS_DIGIT(d, c)) {
+- if (WOULD_OVERFLOW(lval, d, max_long)) {
+- dval = lval;
+- goto fd;
+- }
+- lval = lval * 10 + d;
+- exp10--;
+- GET_NEXT(c, sp, c = EOFC);
+- }
+-le:
+- if (sign < 0)
+- lval = -lval;
+- dval = lval;
+- goto fe;
+-
+ /* Now we are accumulating a double in dval. */
+ fd:
+ while (IS_DIGIT(d, c)) {
diff --git a/print/ghostscript7-x11/files/patch-src-iutil.c b/print/ghostscript7-x11/files/patch-src-iutil.c
new file mode 100644
index 000000000000..c77cb19ddd84
--- /dev/null
+++ b/print/ghostscript7-x11/files/patch-src-iutil.c
@@ -0,0 +1,11 @@
+--- src/iutil.c.orig 2013-04-30 10:51:05.000000000 +0900
++++ src/iutil.c 2013-04-30 10:51:20.000000000 +0900
+@@ -428,7 +428,7 @@
+ data = (const byte *)(op->value.boolval ? "true" : "false");
+ break;
+ case t_integer:
+- sprintf(buf, "%ld", op->value.intval);
++ sprintf(buf, "%d", op->value.intval);
+ break;
+ case t_string:
+ check_read(*op);
diff --git a/print/ghostscript7-x11/files/patch-src-lib.mak b/print/ghostscript7-x11/files/patch-src-lib.mak
new file mode 100644
index 000000000000..6208eb8034a3
--- /dev/null
+++ b/print/ghostscript7-x11/files/patch-src-lib.mak
@@ -0,0 +1,46 @@
+--- src/lib.mak.orig 2003-01-17 09:49:05.000000000 +0900
++++ src/lib.mak 2015-08-22 02:23:05.682462000 +0900
+@@ -35,6 +35,7 @@
+ GLJCC=$(CC_) $(I_)$(GLI_) $(II)$(JI_)$(_I) $(JCF_) $(GLF_)
+ GLZCC=$(CC_) $(I_)$(GLI_) $(II)$(ZI_)$(_I) $(ZCF_) $(GLF_)
+ GLCCLEAF=$(CC_LEAF) $(I_)$(GLI_)$(_I) $(GLF_)
++GLCCSHARED=$(CC_SHARED) $(GLCCFLAGS)
+ # All top-level makefiles define GLD.
+ #GLD=$(GLGEN)
+
+@@ -187,22 +188,22 @@
+ $(GLD)gsnogc.dev : $(LIB_MAK) $(ECHOGS_XE) $(gsnogc_)
+ $(SETMOD) $(GLD)gsnogc $(gsnogc_)
+
+-$(GLOBJ)gsnogc.$(OBJ) : $(GLSRC)gsnogc.c $(GX)\
++$(GLOBJ)gsnogc.$(OBJ) : $(arch_h) $(GLSRC)gsnogc.c $(GX)\
+ $(gsmdebug_h) $(gsnogc_h) $(gsstruct_h) $(gxalloc_h)
+ $(GLCC) $(GLO_)gsnogc.$(OBJ) $(C_) $(GLSRC)gsnogc.c
+
+ ### Bitmap processing
+
+-$(GLOBJ)gsbitcom.$(OBJ) : $(GLSRC)gsbitcom.c $(AK) $(std_h)\
++$(GLOBJ)gsbitcom.$(OBJ) : $(arch_h) $(GLSRC)gsbitcom.c $(AK) $(std_h)\
+ $(gdebug_h) $(gsbitops_h) $(gstypes_h)
+ $(GLCC) $(GLO_)gsbitcom.$(OBJ) $(C_) $(GLSRC)gsbitcom.c
+
+-$(GLOBJ)gsbitops.$(OBJ) : $(GLSRC)gsbitops.c $(AK) $(memory__h) $(stdio__h)\
++$(GLOBJ)gsbitops.$(OBJ) : $(arch_h) $(GLSRC)gsbitops.c $(AK) $(memory__h) $(stdio__h)\
+ $(gdebug_h) $(gsbittab_h) $(gserror_h) $(gserrors_h) $(gstypes_h)\
+ $(gxbitops_h)
+ $(GLCC) $(GLO_)gsbitops.$(OBJ) $(C_) $(GLSRC)gsbitops.c
+
+-$(GLOBJ)gsbittab.$(OBJ) : $(GLSRC)gsbittab.c $(AK) $(stdpre_h) $(gsbittab_h)
++$(GLOBJ)gsbittab.$(OBJ) : $(arch_h) $(GLSRC)gsbittab.c $(AK) $(stdpre_h) $(gsbittab_h)
+ $(GLCC) $(GLO_)gsbittab.$(OBJ) $(C_) $(GLSRC)gsbittab.c
+
+ # gsflip is not part of the standard configuration: it's rather large,
+@@ -765,7 +766,7 @@
+ $(GLOBJ)gsparamx.$(OBJ) : $(GLSRC)gsparamx.c $(string__h)\
+ $(gserror_h) $(gserrors_h) $(gsmemory_h) $(gsparam_h) $(gsparamx_h)\
+ $(gstypes_h)
+- $(GLCC) $(GLO_)gsparamx.$(OBJ) $(C_) $(GLSRC)gsparamx.c
++ $(GLCCSHARED) $(GLO_)gsparamx.$(OBJ) $(C_) $(GLSRC)gsparamx.c
+
+ # Future replacement for gsparams.c
+ $(GLOBJ)gsparam2.$(OBJ) : $(GLSRC)gsparam2.c $(GXERR) $(memory__h)\
diff --git a/print/ghostscript7-x11/files/patch-src-unixinst.mak b/print/ghostscript7-x11/files/patch-src-unixinst.mak
new file mode 100644
index 000000000000..1a8041d74861
--- /dev/null
+++ b/print/ghostscript7-x11/files/patch-src-unixinst.mak
@@ -0,0 +1,122 @@
+--- src/unixinst.mak.orig 2003-01-17 09:49:05.000000000 +0900
++++ src/unixinst.mak 2015-08-22 00:31:09.540215000 +0900
+@@ -30,24 +30,24 @@
+ # rules, just in case bindir or scriptdir is a subdirectory of any of these.
+
+ install-exec: $(GS_XE)
+- -mkdir -p $(datadir)
+- -mkdir -p $(gsdir)
+- -mkdir -p $(gsdatadir)
+- -mkdir -p $(bindir)
+- $(INSTALL_PROGRAM) $(GS_XE) $(bindir)/$(GS)
++ -mkdir -p $(DESTDIR)$(datadir)
++ -mkdir -p $(DESTDIR)$(gsdir)
++ -mkdir -p $(DESTDIR)$(gsdatadir)
++ -mkdir -p $(DESTDIR)$(bindir)
++ $(INSTALL_PROGRAM) $(GS_XE) $(DESTDIR)$(bindir)/$(GS)
+
+ install-scripts: $(PSLIBDIR)/gsnd
+- -mkdir -p $(datadir)
+- -mkdir -p $(gsdir)
+- -mkdir -p $(gsdatadir)
+- -mkdir -p $(scriptdir)
++ -mkdir -p $(DESTDIR)$(datadir)
++ -mkdir -p $(DESTDIR)$(gsdir)
++ -mkdir -p $(DESTDIR)$(gsdatadir)
++ -mkdir -p $(DESTDIR)$(scriptdir)
+ $(SH) -c 'for f in \
+ gsbj gsdj gsdj500 gslj gslp gsnd \
+ bdftops dvipdf eps2eps font2c \
+ pdf2dsc pdf2ps pdfopt pf2afm pfbtopfa printafm \
+ ps2ascii ps2epsi ps2pdf ps2pdf12 ps2pdf13 ps2pdf14 ps2pdfwr ps2ps wftopfa \
+ fixmswrd.pl lprsetup.sh pj-gs.sh pv.sh sysvlp.sh unix-lpr.sh ;\
+- do if ( test -f $(PSLIBDIR)/$$f ); then $(INSTALL_PROGRAM) $(PSLIBDIR)/$$f $(scriptdir); fi;\
++ do if ( test -f $(PSLIBDIR)/$$f ); then $(INSTALL_SCRIPT) $(PSLIBDIR)/$$f $(DESTDIR)$(scriptdir); fi;\
+ done'
+
+ PSDOCDIR=$(PSLIBDIR)/../doc
+@@ -60,10 +60,10 @@
+ # one file from each subdirectory just as a sanity check.
+
+ install-libdata:
+- -mkdir -p $(datadir)
+- -mkdir -p $(gsdir)
+- -mkdir -p $(gsdatadir)
+- -mkdir -p $(gsdatadir)/lib
++ -mkdir -p $(DESTDIR)$(datadir)
++ -mkdir -p $(DESTDIR)$(gsdir)
++ -mkdir -p $(DESTDIR)$(gsdatadir)
++ -mkdir -p $(DESTDIR)$(gsdatadir)/lib
+ $(SH) -c 'for f in \
+ Fontmap Fontmap.GS \
+ CIDFnmap CIDFnmap.Ore CIDFnmap.ARP CIDFnmap.Bae CIDFnmap.Koc \
+@@ -83,13 +83,13 @@
+ viewpcx.ps viewpbm.ps viewps2a.ps \
+ winmaps.ps wftopfa.ps wrfont.ps zeroline.ps \
+ pdf2dsc.ps pdfopt.ps ;\
+- do if ( test -f $(PSLIBDIR)/$$f ); then $(INSTALL_DATA) $(PSLIBDIR)/$$f $(gsdatadir)/lib; fi;\
++ do if ( test -f $(PSLIBDIR)/$$f ); then $(INSTALL_DATA) $(PSLIBDIR)/$$f $(DESTDIR)$(gsdatadir)/lib; fi;\
+ done'
+ $(SH) -c 'for f in $(PSLIBDIR)/gs_*.ps $(PSLIBDIR)/pdf*.ps;\
+- do $(INSTALL_DATA) $$f $(gsdatadir)/lib ;\
++ do $(INSTALL_DATA) $$f $(DESTDIR)$(gsdatadir)/lib ;\
+ done'
+ $(SH) -c 'for f in $(PSLIBDIR)/*.ppd $(PSLIBDIR)/*.rpd $(PSLIBDIR)/*.upp $(PSLIBDIR)/*.xbm $(PSLIBDIR)/*.xpm;\
+- do $(INSTALL_DATA) $$f $(gsdatadir)/lib ;\
++ do $(INSTALL_DATA) $$f $(DESTDIR)$(gsdatadir)/lib ;\
+ done'
+
+ # install html documentation
+@@ -106,20 +106,20 @@
+ Psfiles.htm Public.htm Readme.htm Release.htm \
+ Source.htm Tester.htm Unix-lpr.htm Use.htm Xfonts.htm
+ install-doc: $(PSDOCDIR)/News.htm
+- -mkdir -p $(docdir)
++ -mkdir -p $(DESTDIR)$(docdir)
+ $(SH) -c 'for f in $(DOC_PAGES) ;\
+- do if ( test -f $(PSDOCDIR)/$$f ); then $(INSTALL_DATA) $(PSDOCDIR)/$$f $(docdir); fi;\
++ do if ( test -f $(PSDOCDIR)/$$f ); then $(INSTALL_DATA) $(PSDOCDIR)/$$f $(DESTDIR)$(docdir); fi;\
+ done'
+
+ # install the man pages for each locale
+-MAN_LCDIRS=. de
++MAN_LCDIRS=.
+ MAN1_LINKS_PS2PS=eps2eps
+ MAN1_LINKS_PS2PDF=ps2pdf12 ps2pdf13
+ MAN1_LINKS_GSLP=gsbj gsdj gsdj500 gslj
+ install-man: $(PSMANDIR)/gs.1
+- $(SH) -c 'test -d $(mandir) || mkdir -p $(mandir)'
++ $(SH) -c 'test -d $(DESTDIR)$(mandir) || mkdir -p $(DESTDIR)$(mandir)'
+ $(SH) -c 'for d in $(MAN_LCDIRS) ;\
+- do man1dir=$(mandir)/$$d/man$(man1ext) ;\
++ do man1dir=$(DESTDIR)$(mandir)/$$d/man$(man1ext) ;\
+ ( test -d $$man1dir || mkdir -p $$man1dir ) ;\
+ for f in $(PSMANDIR)/$$d/*.1 ;\
+ do $(INSTALL_DATA) $$f $$man1dir ;\
+@@ -146,17 +146,22 @@
+
+ # install the example files
+ install-examples:
+- -mkdir -p $(exdir)
++ -mkdir -p $(DESTDIR)$(exdir)
+ for f in \
+ alphabet.ps colorcir.ps doretree.ps escher.ps golfer.ps \
+ grayalph.ps snowflak.ps tiger.ps vasarely.ps waterfal.ps \
+ ridt91.eps ;\
+- do $(INSTALL_DATA) $(PSEXDIR)/$$f $(exdir) ;\
++ do $(INSTALL_DATA) $(PSEXDIR)/$$f $(DESTDIR)$(exdir) ;\
+ done
+- -mkdir -p $(exdir)/cjk
++ -mkdir -p $(DESTDIR)$(exdir)/cjk
+ for f in \
+ all_ac1.ps all_ag1.ps all_aj1.ps all_aj2.ps all_ak1.ps \
+ gscjk_ac.ps gscjk_ag.ps gscjk_aj.ps gscjk_ak.ps \
+ iso2022.ps;\
+- do $(INSTALL_DATA) $(PSEXDIR)/cjk/$$f $(exdir)/cjk ;\
++ do $(INSTALL_DATA) $(PSEXDIR)/cjk/$$f $(DESTDIR)$(exdir)/cjk ;\
+ done
++
++install-shared: $(GS_SHARED_OBJS)
++ -mkdir -p $(DESTDIR)$(gssharedir)
++ $(SH) -c 'for obj in $(GS_SHARED_OBJS); do \
++ $(INSTALL_PROGRAM) $$obj $(DESTDIR)$(gssharedir)/; done'
diff --git a/print/ghostscript7-x11/files/patch-src-zarith.c b/print/ghostscript7-x11/files/patch-src-zarith.c
new file mode 100644
index 000000000000..582f61e8f144
--- /dev/null
+++ b/print/ghostscript7-x11/files/patch-src-zarith.c
@@ -0,0 +1,48 @@
+--- src/zarith.c.orig 2013-04-30 11:07:41.000000000 +0900
++++ src/zarith.c 2013-04-30 11:08:43.000000000 +0900
+@@ -32,9 +32,9 @@
+ */
+
+ /* Define max and min values for what will fit in value.intval. */
+-#define MIN_INTVAL min_long
+-#define MAX_INTVAL max_long
+-#define MAX_HALF_INTVAL ((1L << (size_of(long) * 4 - 1)) - 1)
++#define MIN_INTVAL 0x80000000
++#define MAX_INTVAL 0x7fffffff
++#define MAX_HALF_INTVAL 0x7fff
+
+ /* <num1> <num2> add <sum> */
+ /* We make this into a separate procedure because */
+@@ -64,7 +64,7 @@
+ op[-1].value.realval += (double)op->value.intval;
+ break;
+ case t_integer: {
+- long int2 = op->value.intval;
++ int int2 = op->value.intval;
+
+ if (((op[-1].value.intval += int2) ^ int2) < 0 &&
+ ((op[-1].value.intval - int2) ^ int2) >= 0
+@@ -158,10 +158,10 @@
+ op[-1].value.realval *= (double)op->value.intval;
+ break;
+ case t_integer: {
+- long int1 = op[-1].value.intval;
+- long int2 = op->value.intval;
+- long abs1 = (int1 >= 0 ? int1 : -int1);
+- long abs2 = (int2 >= 0 ? int2 : -int2);
++ int int1 = op[-1].value.intval;
++ int int2 = op->value.intval;
++ uint abs1 = (uint)(int1 >= 0 ? int1 : -int1);
++ uint abs2 = (uint)(int2 >= 0 ? int2 : -int2);
+ float fprod;
+
+ if ((abs1 > MAX_HALF_INTVAL || abs2 > MAX_HALF_INTVAL) &&
+@@ -212,7 +212,7 @@
+ op[-1].value.realval -= (double)op->value.intval;
+ break;
+ case t_integer: {
+- long int1 = op[-1].value.intval;
++ int int1 = op[-1].value.intval;
+
+ if ((int1 ^ (op[-1].value.intval = int1 - op->value.intval)) < 0 &&
+ (int1 ^ op->value.intval) < 0
diff --git a/print/ghostscript7-x11/files/patch-src-zcontrol.c b/print/ghostscript7-x11/files/patch-src-zcontrol.c
new file mode 100644
index 000000000000..d00a600c19ec
--- /dev/null
+++ b/print/ghostscript7-x11/files/patch-src-zcontrol.c
@@ -0,0 +1,20 @@
+--- src/zcontrol.c.orig 2013-04-30 11:09:59.000000000 +0900
++++ src/zcontrol.c 2013-04-30 11:11:03.000000000 +0900
+@@ -356,7 +356,7 @@
+ {
+ os_ptr op = osp;
+ register es_ptr ep = esp;
+- long var = ep[-3].value.intval;
++ int var = ep[-3].value.intval;
+
+ if (var > ep[-1].value.intval) {
+ esp -= 5; /* pop everything */
+@@ -375,7 +375,7 @@
+ {
+ os_ptr op = osp;
+ register es_ptr ep = esp;
+- long var = ep[-3].value.intval;
++ int var = ep[-3].value.intval;
+
+ if (var < ep[-1].value.intval) {
+ esp -= 5; /* pop everything */
diff --git a/print/ghostscript7-x11/files/patch-src-zdict.c b/print/ghostscript7-x11/files/patch-src-zdict.c
new file mode 100644
index 000000000000..050ecc841717
--- /dev/null
+++ b/print/ghostscript7-x11/files/patch-src-zdict.c
@@ -0,0 +1,29 @@
+--- src/zdict.c.orig 2013-04-30 11:04:05.000000000 +0900
++++ src/zdict.c 2013-04-30 11:04:34.000000000 +0900
+@@ -35,12 +35,9 @@
+ os_ptr op = osp;
+
+ check_type(*op, t_integer);
+-#if arch_sizeof_int < arch_sizeof_long
+- check_int_leu(*op, max_uint);
+-#else
+ if (op->value.intval < 0)
+ return_error(e_rangecheck);
+-#endif
++
+ return dict_create((uint) op->value.intval, op);
+ }
+
+@@ -458,12 +455,8 @@
+ check_type(*op1, t_dictionary);
+ check_dict_write(*op1);
+ check_type(*op, t_integer);
+-#if arch_sizeof_int < arch_sizeof_long
+- check_int_leu(*op, max_uint);
+-#else
+ if (op->value.intval < 0)
+ return_error(e_rangecheck);
+-#endif
+ new_size = (uint) op->value.intval;
+ if (dict_length(op - 1) > new_size)
+ return_error(e_dictfull);
diff --git a/print/ghostscript7-x11/files/patch-src-zdps.c b/print/ghostscript7-x11/files/patch-src-zdps.c
new file mode 100644
index 000000000000..414a296cd4ea
--- /dev/null
+++ b/print/ghostscript7-x11/files/patch-src-zdps.c
@@ -0,0 +1,25 @@
+--- src/zdps.c.orig 2013-04-30 11:05:10.000000000 +0900
++++ src/zdps.c 2013-04-30 11:05:50.000000000 +0900
+@@ -46,19 +46,18 @@
+ {
+ os_ptr op = osp;
+ int code;
+- long x, y;
++ int x, y;
+
+ check_type(op[-2], t_integer);
+ check_type(op[-1], t_integer);
+ check_type(*op, t_integer);
+ x = op[-1].value.intval;
+ y = op->value.intval;
+- if (x != (int)x || y != (int)y ||
+- op[-2].value.intval < -1 ||
++ if (op[-2].value.intval < -1 ||
+ op[-2].value.intval >= gs_color_select_count
+ )
+ return_error(e_rangecheck);
+- code = gs_setscreenphase(igs, (int)x, (int)y,
++ code = gs_setscreenphase(igs, x, y,
+ (gs_color_select_t) op[-2].value.intval);
+ if (code >= 0)
+ pop(3);
diff --git a/print/ghostscript7-x11/files/patch-src-zfunc4.c b/print/ghostscript7-x11/files/patch-src-zfunc4.c
new file mode 100644
index 000000000000..0d8610978652
--- /dev/null
+++ b/print/ghostscript7-x11/files/patch-src-zfunc4.c
@@ -0,0 +1,13 @@
+--- src/zfunc4.c.orig 2013-04-30 10:45:00.000000000 +0900
++++ src/zfunc4.c 2013-04-30 10:45:23.000000000 +0900
+@@ -150,10 +150,6 @@
+ case t_integer: {
+ int i = elt.value.intval;
+
+-#if ARCH_SIZEOF_INT < ARCH_SIZEOF_LONG
+- if (i != elt.value.intval) /* check for truncation */
+- return_error(e_rangecheck);
+-#endif
+ if (i == (byte)i) {
+ *p = PtCr_byte;
+ p[1] = (byte)i;
diff --git a/print/ghostscript7-x11/files/patch-src-zgeneric.c b/print/ghostscript7-x11/files/patch-src-zgeneric.c
new file mode 100644
index 000000000000..d99189a5e16a
--- /dev/null
+++ b/print/ghostscript7-x11/files/patch-src-zgeneric.c
@@ -0,0 +1,20 @@
+--- src/zgeneric.c.orig 2013-04-30 10:55:48.000000000 +0900
++++ src/zgeneric.c 2013-04-30 10:56:40.000000000 +0900
+@@ -76,7 +76,7 @@
+ int count, i;
+ int code;
+
+- if ((ulong) op->value.intval > op - osbot) {
++ if ((uint)op->value.intval > (uint)(op - osbot)) {
+ /* There might be enough elements in other blocks. */
+ check_int_ltu(*op, ref_stack_count(&o_stack));
+ count = op->value.intval;
+@@ -471,7 +471,7 @@
+ {
+ os_ptr op = osp;
+ es_ptr obj = esp - 2;
+- int index = (int)esp->value.intval;
++ int index = esp->value.intval;
+
+ push(2); /* make room for key and value */
+ if ((index = dict_next(obj, index, op - 1)) >= 0) { /* continue */
diff --git a/print/ghostscript7-x11/files/patch-src-ziodev.c b/print/ghostscript7-x11/files/patch-src-ziodev.c
new file mode 100644
index 000000000000..2cd6f0add7a9
--- /dev/null
+++ b/print/ghostscript7-x11/files/patch-src-ziodev.c
@@ -0,0 +1,11 @@
+--- src/ziodev.c.orig 2013-04-30 11:06:19.000000000 +0900
++++ src/ziodev.c 2013-04-30 11:06:30.000000000 +0900
+@@ -79,8 +79,6 @@
+ const byte *dname;
+
+ check_type(*op, t_integer);
+- if (op->value.intval != (int)op->value.intval)
+- return_error(e_rangecheck);
+ iodev = gs_getiodevice((int)(op->value.intval));
+ if (iodev == 0) /* index out of range */
+ return_error(e_rangecheck);
diff --git a/print/ghostscript7-x11/files/patch-src-zmath.c b/print/ghostscript7-x11/files/patch-src-zmath.c
new file mode 100644
index 000000000000..94576da80fdf
--- /dev/null
+++ b/print/ghostscript7-x11/files/patch-src-zmath.c
@@ -0,0 +1,18 @@
+--- src/zmath.c.orig 2013-04-30 10:43:55.000000000 +0900
++++ src/zmath.c 2013-04-30 10:44:23.000000000 +0900
+@@ -229,14 +229,10 @@
+ zsrand(i_ctx_t *i_ctx_p)
+ {
+ os_ptr op = osp;
+- long state;
++ int state;
+
+ check_type(*op, t_integer);
+ state = op->value.intval;
+-#if arch_sizeof_long > 4
+- /* Trim the state back to 32 bits. */
+- state = (int)state;
+-#endif
+ /*
+ * The following somewhat bizarre adjustments are according to
+ * public information from Adobe describing their implementation.
diff --git a/print/ghostscript7-x11/files/patch-src-zstack.c b/print/ghostscript7-x11/files/patch-src-zstack.c
new file mode 100644
index 000000000000..f1359936e410
--- /dev/null
+++ b/print/ghostscript7-x11/files/patch-src-zstack.c
@@ -0,0 +1,11 @@
+--- src/zstack.c.orig 2013-04-30 10:54:14.000000000 +0900
++++ src/zstack.c 2013-04-30 10:54:26.000000000 +0900
+@@ -70,7 +70,7 @@
+ register os_ptr opn;
+
+ check_type(*op, t_integer);
+- if ((ulong)op->value.intval >= op - osbot) {
++ if ((uint)op->value.intval >= op - osbot) {
+ /* Might be in an older stack block. */
+ ref *elt;
+
diff --git a/print/ghostscript7-x11/files/patch-src-ztype.c b/print/ghostscript7-x11/files/patch-src-ztype.c
new file mode 100644
index 000000000000..98be203c6abe
--- /dev/null
+++ b/print/ghostscript7-x11/files/patch-src-ztype.c
@@ -0,0 +1,34 @@
+--- src/ztype.c.orig 2013-04-30 10:46:12.000000000 +0900
++++ src/ztype.c 2013-04-30 10:46:55.000000000 +0900
+@@ -53,10 +53,10 @@
+ * constant expressions, so we can't use min_long and max_long.
+ * What a nuisance!
+ */
+-#define ALT_MIN_LONG (-1L << (arch_sizeof_long * 8 - 1))
+-#define ALT_MAX_LONG (~(ALT_MIN_LONG))
+-private const double min_int_real = (ALT_MIN_LONG * 1.0 - 1);
+-private const double max_int_real = (ALT_MAX_LONG * 1.0 + 1);
++#define ALT_MIN_INT (-1 << 31)
++#define ALT_MAX_INT (~(ALT_MIN_INT))
++static const double min_int_real = (ALT_MIN_INT * 1.0 - 1);
++static const double max_int_real = (ALT_MAX_INT * 1.0 + 1);
+
+ #define REAL_CAN_BE_INT(v)\
+ ((v) > min_int_real && (v) < max_int_real)
+@@ -356,14 +356,14 @@
+ return_op_typecheck(op - 2);
+ }
+ } else {
+- ulong ival;
++ uint ival;
+ byte digits[sizeof(ulong) * 8];
+ byte *endp = &digits[countof(digits)];
+ byte *dp = endp;
+
+ switch (r_type(op - 2)) {
+ case t_integer:
+- ival = (ulong) op[-2].value.intval;
++ ival = (uint) op[-2].value.intval;
+ break;
+ case t_real:
+ {
diff --git a/print/ghostscript7-x11/files/patch-src:gdevlbp8.c b/print/ghostscript7-x11/files/patch-src:gdevlbp8.c
new file mode 100644
index 000000000000..052492c58f6a
--- /dev/null
+++ b/print/ghostscript7-x11/files/patch-src:gdevlbp8.c
@@ -0,0 +1,70 @@
+--- src/gdevlbp8.c.orig Wed Aug 1 09:48:23 2001
++++ src/gdevlbp8.c Thu Mar 14 20:56:05 2002
+@@ -22,6 +22,8 @@
+
+ /*
+ Modifications:
++ 3.10.00 Johnny Lam
++ Removed LIPS III code, as it's obsoleted by gdevlips driver.
+ 2.2.97 Lauri Paatero
+ Changed CSI command into ESC [. DCS commands may still need to be changed
+ (to ESC P).
+@@ -49,7 +51,6 @@
+
+ /* The device descriptors */
+ private dev_proc_print_page(lbp8_print_page);
+-private dev_proc_print_page(lips3_print_page);
+
+ const gx_device_printer far_data gs_lbp8_device =
+ prn_device(prn_std_procs, "lbp8",
+@@ -58,14 +59,6 @@
+ 0.16, 0.2, 0.32, 0.21, /* margins: left, bottom, right, top */
+ 1, lbp8_print_page);
+
+-const gx_device_printer far_data gs_lips3_device =
+- prn_device(prn_std_procs, "lips3",
+- 82, /* width_10ths, 8.3" */
+- 117, /* height_10ths, 11.7" */
+- X_DPI, Y_DPI,
+- 0.16, 0.27, 0.23, 0.27, /* margins */
+- 1, lips3_print_page);
+-
+ /* ------ Internal routines ------ */
+
+ #define ESC 0x1b
+@@ -84,23 +77,6 @@
+
+ static const char *lbp8_end = NULL;
+
+-static const char lips3_init[] = {
+- ESC, '<', /* soft reset */
+- DCS, '0', 'J', ST, /* JOB END */
+- DCS, '3', '1', ';', '3', '0', '0', ';', '2', 'J', ST, /* 300dpi, LIPS3 JOB START */
+- ESC, '<', /* soft reset */
+- DCS, '2', 'y', 'P', 'r', 'i', 'n', 't', 'i', 'n', 'g', '(', 'g', 's', ')', ST, /* Printing (gs) display */
+- ESC, '[', '?', '1', 'l', /* auto cr-lf disable */
+- ESC, '[', '?', '2', 'h', /* auto ff disable */
+- ESC, '[', '1', '1', 'h', /* set mode */
+- ESC, '[', '7', ' ', 'I', /* select unit size (300dpi)*/
+- ESC, '[', 'f' /* move to home position */
+-};
+-
+-static const char lips3_end[] = {
+- DCS, '0', 'J', ST /* JOB END */
+-};
+-
+ /* Send the page to the printer. */
+ private int
+ can_print_page(gx_device_printer *pdev, FILE *prn_stream,
+@@ -203,11 +179,4 @@
+ lbp8_print_page(gx_device_printer *pdev, FILE *prn_stream)
+ { return can_print_page(pdev, prn_stream, lbp8_init, sizeof(lbp8_init),
+ lbp8_end, sizeof(lbp8_end));
+-}
+-
+-/* Print a LIPS III page. */
+-private int
+-lips3_print_page(gx_device_printer *pdev, FILE *prn_stream)
+-{ return can_print_page(pdev, prn_stream, lips3_init, sizeof(lips3_init),
+- lips3_end, sizeof(lips3_end));
+ }
diff --git a/print/ghostscript7-x11/files/patch-src:gdevpdff.c b/print/ghostscript7-x11/files/patch-src:gdevpdff.c
new file mode 100644
index 000000000000..8a292bd4cdec
--- /dev/null
+++ b/print/ghostscript7-x11/files/patch-src:gdevpdff.c
@@ -0,0 +1,59 @@
+--- src/gdevpdff.c.org 2003-01-17 09:49:02.000000000 +0900
++++ src/gdevpdff.c 2003-09-21 05:08:36.000000000 +0900
+@@ -276,6 +276,11 @@
+ const byte *chars = font->font_name.chars;
+ uint size = font->font_name.size;
+
++ /* CIDFonts has null string in font_name, key_name is used */
++ if (0 == size) {
++ chars = font->key_name.chars;
++ size = font->key_name.size;
++ }
+ /*
+ * The behavior of Acrobat Distiller changed between 3.0 (PDF 1.2),
+ * which will never embed the base 14 fonts, and 4.0 (PDF 1.3), which
+@@ -720,19 +725,22 @@
+ same &= ~FONT_SAME_METRICS;
+ break;
+ case FONT_EMBED_NO:
+- /*
+- * Per the PDF 1.3 documentation, there are only 3 BaseEncoding
+- * values allowed for non-embedded fonts. Pick one here.
+- */
+- BaseEncoding =
+- ((const gs_font_base *)base_font)->nearest_encoding_index;
+- switch (BaseEncoding) {
+- default:
+- BaseEncoding = ENCODING_INDEX_WINANSI;
+- case ENCODING_INDEX_WINANSI:
+- case ENCODING_INDEX_MACROMAN:
+- case ENCODING_INDEX_MACEXPERT:
+- break;
++ if (!(font->FontType == ft_CID_encrypted ||
++ font->FontType == ft_CID_TrueType)) {
++ /*
++ * Per the PDF 1.3 documentation, there are only 3 BaseEncoding
++ * values allowed for non-embedded fonts. Pick one here.
++ */
++ BaseEncoding =
++ ((const gs_font_base *)base_font)->nearest_encoding_index;
++ switch (BaseEncoding) {
++ default:
++ BaseEncoding = ENCODING_INDEX_WINANSI;
++ case ENCODING_INDEX_WINANSI:
++ case ENCODING_INDEX_MACROMAN:
++ case ENCODING_INDEX_MACEXPERT:
++ break;
++ }
+ }
+ code = pdf_compute_font_descriptor(pdev, &fdesc, font, NULL);
+ if (code < 0)
+@@ -888,6 +896,7 @@
+ memcpy(ppf->widths_known, ftemp_widths_known,
+ sizeof(ftemp_widths_known));
+ }
++ ppf->embed = embed;
+ code = pdf_register_font(pdev, font, ppf);
+
+ *pppf = ppf;
+
diff --git a/print/ghostscript7-x11/files/patch-src:gdevpdff.h b/print/ghostscript7-x11/files/patch-src:gdevpdff.h
new file mode 100644
index 000000000000..f64a4e02f6b8
--- /dev/null
+++ b/print/ghostscript7-x11/files/patch-src:gdevpdff.h
@@ -0,0 +1,37 @@
+--- src/gdevpdff.h.org 2003-01-17 09:49:02.000000000 +0900
++++ src/gdevpdff.h 2003-09-18 23:42:38.000000000 +0900
+@@ -117,6 +117,12 @@
+ FONT_SUBSET_NO
+ } pdf_font_do_subset_t;
+
++typedef enum {
++ FONT_EMBED_STANDARD, /* 14 standard fonts */
++ FONT_EMBED_NO,
++ FONT_EMBED_YES
++} pdf_font_embed_t;
++
+ struct pdf_font_descriptor_s {
+ pdf_resource_common(pdf_font_descriptor_t);
+ pdf_font_name_t FontName;
+@@ -198,6 +204,7 @@
+ gs_font *font; /* non-0 iff font will notify us; */
+ /* should be a weak pointer */
+ int index; /* in pdf_standard_fonts, -1 if not base 14 */
++ pdf_font_embed_t embed; /* status of pdf_font_embed_status() */
+ gs_matrix orig_matrix; /* FontMatrix of unscaled font for embedding */
+ bool is_MM_instance; /* for Type 1/2 fonts, true iff the font */
+ /* is a Multiple Master instance */
+@@ -320,12 +327,6 @@
+
+ /* ---------------- Exported by gdevpdff.c ---------------- */
+
+-typedef enum {
+- FONT_EMBED_STANDARD, /* 14 standard fonts */
+- FONT_EMBED_NO,
+- FONT_EMBED_YES
+-} pdf_font_embed_t;
+-
+ typedef struct pdf_standard_font_s {
+ const char *fname;
+ gs_encoding_index_t base_encoding;
+
diff --git a/print/ghostscript7-x11/files/patch-src:gdevpdfs.c b/print/ghostscript7-x11/files/patch-src:gdevpdfs.c
new file mode 100644
index 000000000000..0378f15c88ab
--- /dev/null
+++ b/print/ghostscript7-x11/files/patch-src:gdevpdfs.c
@@ -0,0 +1,41 @@
+--- src/gdevpdfs.c.org 2003-09-20 00:11:16.000000000 +0900
++++ src/gdevpdfs.c 2003-09-25 17:44:10.000000000 +0900
+@@ -481,15 +481,21 @@
+
+ if (cid < pfd->chars_count) {
+ int index = cid >> 3, mask = 0x80 >> (cid & 7);
++ int gid;
++
++ if (!(pfd->chars_used.data[index] & mask) ||
++ !(psubf->widths_known[index] & mask)) {
+
+- if (!(pfd->chars_used.data[index] & mask)) {
+- pfd->chars_used.data[index] |= mask;
+ if (psubf->CIDToGIDMap) {
+ gs_font_cid2 *const subfont2 =
+ (gs_font_cid2 *)subfont;
+- int gid =
+- subfont2->cidata.CIDMap_proc(subfont2, glyph);
+
++ gid = subfont2->cidata.CIDMap_proc(subfont2, glyph);
++ }
++ }
++ if (!(pfd->chars_used.data[index] & mask)) {
++ pfd->chars_used.data[index] |= mask;
++ if (psubf->CIDToGIDMap) {
+ if (gid >= 0) {
+ psubf->CIDToGIDMap[cid] = gid;
+ mark_glyphs_used(subfont, gid + gs_min_cid_glyph,
+@@ -500,7 +506,11 @@
+ if (!(psubf->widths_known[index] & mask)) {
+ int width;
+
+- code = pdf_glyph_width(psubf, glyph, subfont, &width);
++ if (psubf->CIDToGIDMap)
++ code = pdf_glyph_width(psubf, gid + gs_min_cid_glyph,
++ subfont, &width);
++ else
++ code = pdf_glyph_width(psubf, glyph, subfont, &width);
+ if (code == 0) {
+ psubf->Widths[cid] = width;
+ psubf->widths_known[index] |= mask;
diff --git a/print/ghostscript7-x11/files/patch-src:gdevpdfw.c b/print/ghostscript7-x11/files/patch-src:gdevpdfw.c
new file mode 100644
index 000000000000..a08b87d42724
--- /dev/null
+++ b/print/ghostscript7-x11/files/patch-src:gdevpdfw.c
@@ -0,0 +1,60 @@
+--- src/gdevpdfw.c.org 2003-01-17 09:49:02.000000000 +0900
++++ src/gdevpdfw.c 2003-09-25 17:50:54.000000000 +0900
+@@ -348,18 +348,19 @@
+ /* Use the most common width as DW. */
+
+ {
+- ushort counts[1001];
++ ushort counts[1500*2]; /* histogram of (-1500..1500) */
+ int dw_count = 0, i;
+
+ memset(counts, 0, sizeof(counts));
+ while (!psf_enumerate_glyphs_next(&genum, &glyph)) {
+- int width = ppf->Widths[glyph - gs_min_cid_glyph];
++ int cid = glyph - gs_min_cid_glyph;
++ int width = ppf->Widths[cid];
+
+- counts[min(width, countof(counts) - 1)]++;
++ counts[max(0,min(width+countof(counts)/2,countof(counts)-1))]++;
+ }
+- for (i = 0; i < countof(counts); ++i)
++ for (i = 0; i < countof(counts); i++)
+ if (counts[i] > dw_count)
+- dw = i, dw_count = counts[i];
++ dw = i - countof(counts)/2, dw_count = counts[i];
+ if (dw != 0)
+ pprintd1(s, "/DW %d\n", dw);
+ }
+@@ -496,14 +497,16 @@
+ if (pdf_has_subset_prefix(chars, size))
+ chars += SUBSET_PREFIX_SIZE, size -= SUBSET_PREFIX_SIZE;
+ pdf_put_name(pdev, chars, size);
+- if (pef->sub_font_type == ft_CID_encrypted &&
++ if ((pef->sub_font_type == ft_CID_encrypted ||
++ pef->sub_font_type == ft_CID_TrueType) &&
+ pef->cmapname[0] == '/'
+ ) {
+ stream_putc(s, '-');
+ pdf_put_name_chars(pdev, (const byte*) (pef->cmapname + 1),
+ strlen(pef->cmapname + 1));
+ }
+- pprints1(s, "/Encoding %s", pef->cmapname);
++ pprints1(s, (pef->cmapname[0] == '/') ? "/Encoding%s" : "/Encoding %s",
++ pef->cmapname);
+ pprintld1(s, "/DescendantFonts[%ld 0 R]",
+ pdf_resource_id((const pdf_resource_t *)pef->DescendantFont));
+ write_Widths = 0;
+@@ -563,8 +566,10 @@
+ break;
+ case -1:
+ pdf_write_CIDFont_widths(pdev, pef);
+- if (pef->FontType == ft_CID_TrueType)
+- pdf_write_CIDToGIDMap(pdev, pef, &cidmap_id);
++ if (pef->FontType == ft_CID_TrueType) {
++ if (pef->embed != FONT_EMBED_NO)
++ pdf_write_CIDToGIDMap(pdev, pef, &cidmap_id);
++ }
+ break;
+ }
+ if (pef->Differences) {
+
diff --git a/print/ghostscript7-x11/files/patch-src:genarch.c b/print/ghostscript7-x11/files/patch-src:genarch.c
new file mode 100644
index 000000000000..a015e69e758a
--- /dev/null
+++ b/print/ghostscript7-x11/files/patch-src:genarch.c
@@ -0,0 +1,34 @@
+--- src/genarch.c.orig Tue Jun 5 15:38:57 2001
++++ src/genarch.c Wed Jun 20 04:17:42 2001
+@@ -41,6 +41,7 @@
+ fprintf(f, "\n\t /* ---------------- %s ---------------- */\n\n", str);
+ }
+
++#ifndef __FreeBSD__
+ private clock_t
+ time_clear(char *buf, int bsize, int nreps)
+ {
+@@ -51,6 +52,7 @@
+ memset(buf, 0, bsize);
+ return clock() - t;
+ }
++#endif /* __FreeBSD__ */
+
+ private void
+ define(FILE *f, const char *str)
+@@ -181,6 +183,7 @@
+ fprintf(f, "((unsigned long)~0L + (unsigned long)0)\n");
+ #undef PRINT_MAX
+
++#ifndef __FreeBSD__
+ section(f, "Cache sizes");
+
+ /*
+@@ -241,6 +244,7 @@
+ }
+ define_int(f, "ARCH_CACHE2_SIZE", bsize >> 1);
+ }
++#endif /* __FreeBSD__ */
+
+ section(f, "Miscellaneous");
+
diff --git a/print/ghostscript7-x11/files/patch-src:gxobj.h b/print/ghostscript7-x11/files/patch-src:gxobj.h
new file mode 100644
index 000000000000..f0df8565100c
--- /dev/null
+++ b/print/ghostscript7-x11/files/patch-src:gxobj.h
@@ -0,0 +1,17 @@
+--- src/gxobj.h.orig Fri Feb 22 19:45:59 2002
++++ src/gxobj.h Thu Dec 19 00:16:57 2002
+@@ -99,10 +99,14 @@
+ * The final | is because back pointer values are divided by obj_back_scale,
+ * so objects must be aligned at least 0 mod obj_back_scale.
+ */
++#if !defined(__ia64__) && !defined(__amd64__)
+ #define obj_align_mod\
+ (((arch_align_long_mod - 1) | (arch_align_ptr_mod - 1) |\
+ (arch_align_double_mod - 1) | (align_bitmap_mod - 1) |\
+ (obj_back_scale - 1)) + 1)
++#else
++#define obj_align_mod 16
++#endif
+ /* The only possible values for obj_align_mod are 4, 8, or 16.... */
+ #if obj_align_mod == 4
+ # define log2_obj_align_mod 2
diff --git a/print/ghostscript7-x11/files/patch-src:unix-dll.mak b/print/ghostscript7-x11/files/patch-src:unix-dll.mak
new file mode 100644
index 000000000000..f6032f9f08ac
--- /dev/null
+++ b/print/ghostscript7-x11/files/patch-src:unix-dll.mak
@@ -0,0 +1,87 @@
+--- src/unix-dll.mak.orig 2003-01-17 09:49:05.000000000 +0900
++++ src/unix-dll.mak 2015-08-22 01:13:03.452736000 +0900
+@@ -47,12 +47,17 @@
+ GSSOX=$(BINDIR)/$(SOBINRELDIR)/$(GSSOX_XENAME)
+
+ # shared library
+-GS_SONAME=lib$(GS).so
++GS_SONAME_BASE=lib$(GS)
++
++GS_SOEXT=so
++GS_SONAME=$(GS_SONAME_BASE).$(GS_SOEXT)
+ GS_SONAME_MAJOR=$(GS_SONAME).$(GS_VERSION_MAJOR)
+-GS_SONAME_MAJOR_MINOR= $(GS_SONAME).$(GS_VERSION_MAJOR).$(GS_VERSION_MINOR)
++GS_SONAME_MAJOR_MINOR=$(GS_SONAME).$(GS_VERSION_MAJOR).$(GS_VERSION_MINOR)
++LDFLAGS_SO=-shared -Wl,-soname=$(GS_SONAME_MAJOR)
++
+ GS_SO=$(BINDIR)/$(GS_SONAME)
+-GS_SO_MAJOR=$(GS_SO).$(GS_VERSION_MAJOR)
+-GS_SO_MAJOR_MINOR=$(GS_SO_MAJOR).$(GS_VERSION_MINOR)
++GS_SO_MAJOR=$(BINDIR)/$(GS_SONAME_MAJOR)
++GS_SO_MAJOR_MINOR=$(BINDIR)/$(GS_SONAME_MAJOR_MINOR)
+
+ # Shared object is built by redefining GS_XE in a recursive make.
+
+@@ -68,15 +73,16 @@
+
+ # Build the small Ghostscript loaders, with Gtk+ and without
+
+-$(GSSOX_XE): $(GS_SO) $(GLSRC)dxmain.c
+- $(GLCC) -g `gtk-config --cflags` -o $(GSSOX_XE) $(GLSRC)dxmain.c -L$(BINDIR) -l$(GS) `gtk-config --libs`
++$(GSSOX_XE): $(GS_SO) $(GLSRC)$(SOC_LOADER)
++ $(GLCC) -g -o $(GSSOX_XE) $(GLSRC)dxmainc.c -L$(BINDIR) -l$(GS)
+
+-$(GSSOC_XE): $(GS_SO) $(GLSRC)dxmainc.c
+- $(GLCC) -g -o $(GSSOC_XE) $(GLSRC)dxmainc.c -L$(BINDIR) -l$(GS)
++$(GSSOC_XE): $(GS_SO) $(GLSRC)$(SOC_LOADER)
++ $(GLCC) -g $(SOC_CFLAGS) -o $(GSSOC_XE) $(GLSRC)$(SOC_LOADER) \
++ -L$(BINDIR) -l$(GS) $(SOC_LIBS)
+
+ # ------------------------- Recursive make targets ------------------------- #
+
+-SODEFS=LDFLAGS='$(LDFLAGS) $(CFLAGS_SO) -shared -Wl,-soname,$(GS_SONAME_MAJOR)'\
++SODEFS=LDFLAGS='$(LDFLAGS) $(LDFLAGS_SO)'\
+ GS_XE=$(BINDIR)/$(SOBINRELDIR)/$(GS_SONAME_MAJOR_MINOR)\
+ STDIO_IMPLEMENTATION=c\
+ DISPLAY_DEV=$(DD)$(SOOBJRELDIR)/display.dev\
+@@ -98,21 +104,26 @@
+ $(MAKE) $(SODEFS) GENOPT='-DDEBUG' CFLAGS='$(CFLAGS_DEBUG) $(CFLAGS_SO) $(GCFLAGS) $(XCFLAGS)' $(GSSOC) $(GSSOX)
+
+ install-so: so
+- -mkdir -p $(prefix)
+- -mkdir -p $(datadir)
+- -mkdir -p $(gsdir)
+- -mkdir -p $(gsdatadir)
+- -mkdir -p $(bindir)
+- -mkdir -p $(libdir)
+- $(INSTALL_PROGRAM) $(GSSOC) $(bindir)/$(GSSOC_XENAME)
+- $(INSTALL_PROGRAM) $(GSSOX) $(bindir)/$(GSSOX_XENAME)
+- $(INSTALL_PROGRAM) $(BINDIR)/$(SOBINRELDIR)/$(GS_SONAME_MAJOR_MINOR) $(libdir)/$(GS_SONAME_MAJOR_MINOR)
+- $(RM_) $(libdir)/$(GS_SONAME)
+- ln -s $(GS_SONAME_MAJOR_MINOR) $(libdir)/$(GS_SONAME)
+- $(RM_) $(libdir)/$(GS_SONAME_MAJOR)
+- ln -s $(GS_SONAME_MAJOR_MINOR) $(libdir)/$(GS_SONAME_MAJOR)
++ -mkdir -p $(DESTDIR)$(prefix)
++ -mkdir -p $(DESTDIR)$(datadir)
++ -mkdir -p $(DESTDIR)$(gsdir)
++ -mkdir -p $(DESTDIR)$(gsdatadir)
++ -mkdir -p $(DESTDIR)$(bindir)
++ -mkdir -p $(DESTDIR)$(libdir)
++ -mkdir -p $(DESTDIR)$(gsincludedir)
++ $(INSTALL_PROGRAM) $(GSSOC) $(DESTDIR)$(bindir)/$(GSSOC_XENAME)
++ $(INSTALL_PROGRAM) $(GSSOX) $(DESTDIR)$(bindir)/$(GSSOX_XENAME)
++ $(INSTALL_PROGRAM) $(BINDIR)/$(SOBINRELDIR)/$(GS_SONAME_MAJOR_MINOR) $(DESTDIR)$(libdir)/$(GS_SONAME_MAJOR_MINOR)
++ $(RM_) $(DESTDIR)$(libdir)/$(GS_SONAME)
++ ln -s $(GS_SONAME_MAJOR_MINOR) $(DESTDIR)$(libdir)/$(GS_SONAME)
++ $(RM_) $(DESTDIR)$(libdir)/$(GS_SONAME_MAJOR)
++ ln -s $(GS_SONAME_MAJOR_MINOR) $(DESTDIR)$(libdir)/$(GS_SONAME_MAJOR)
++ $(INSTALL_DATA) $(GLSRC)iapi.h $(DESTDIR)$(gsincludedir)iapi.h
++ $(INSTALL_DATA) $(GLSRC)errors.h $(DESTDIR)$(gsincludedir)ierrors.h
++ $(INSTALL_DATA) $(GLSRC)gdevdsp.h $(DESTDIR)$(gsincludedir)gdevdsp.h
+
+-soinstall: install-so install-scripts install-data
++
++soinstall: install-so install-scripts install-data $(INSTALL_SHARED) $(INSTALL_CONTRIB)
+
+ # Make the build directories
+ SODIRS: STDDIRS
diff --git a/print/ghostscript7-x11/files/patch-src:zmedia2.c b/print/ghostscript7-x11/files/patch-src:zmedia2.c
new file mode 100644
index 000000000000..9033a4388085
--- /dev/null
+++ b/print/ghostscript7-x11/files/patch-src:zmedia2.c
@@ -0,0 +1,25 @@
+--- src/zmedia2.c.orig Fri Apr 27 02:57:41 2001
++++ src/zmedia2.c Fri Nov 2 04:08:16 2001
+@@ -429,11 +429,17 @@
+
+ rx = ry, ry = temp;
+ }
+- /* Adjust the medium size if flexible. */
+- if (medium->p.x < MIN_MEDIA_SIZE && mx > rx)
+- mx = rx;
+- if (medium->p.y < MIN_MEDIA_SIZE && my > ry)
+- my = ry;
++ /* If 'medium' is flexible, adjust 'mx' and 'my' towards 'rx' and 'ry',
++ respectively. Note that 'mx' and 'my' have just acquired the largest
++ permissible value, medium->q. */
++ if (medium->p.x < mx) /* non-empty width range */
++ if (rx < medium->p.x) mx = medium->p.x; /* minimum */
++ else if (mx > rx) mx = rx; /* fits */
++ /* else use medium->q.x, i.e., the maximum */
++ if (medium->p.y < my) /* non-empty height range */
++ if (ry < medium->p.y) my = medium->p.y; /* minimum */
++ else if (my > ry) my = ry; /* fits */
++ /* else use medium->q.y, i.e., the maximum */
+
+ /* Translate to align the centers. */
+ gs_make_translation(mx / 2, my / 2, pmat);
diff --git a/print/ghostscript7-x11/files/patch-src_gdevhl12.c b/print/ghostscript7-x11/files/patch-src_gdevhl12.c
new file mode 100644
index 000000000000..2976befa7cbe
--- /dev/null
+++ b/print/ghostscript7-x11/files/patch-src_gdevhl12.c
@@ -0,0 +1,11 @@
+--- src/gdevhl12.c.orig Sun Aug 1 13:39:19 2004
++++ src/gdevhl12.c Sun Aug 1 13:40:07 2004
+@@ -640,7 +640,7 @@
+ case TRAY_MANUAL:
+ tray_pcl = "\033&l2H";
+ break;
+- default:
++ default: ;
+ }
+ if (pdev->PageCount == 0) {
+ /* initialize printer */
diff --git a/print/ghostscript7-x11/pkg-descr b/print/ghostscript7-x11/pkg-descr
new file mode 100644
index 000000000000..3f3e1c25cef1
--- /dev/null
+++ b/print/ghostscript7-x11/pkg-descr
@@ -0,0 +1,8 @@
+This package installs X11 support library which adds the following
+devices to the installed Ghostscript:
+
+ x11, x11alpha, x11cmyk, x11cmyk2, x11cmyk4, x11cmyk8, x11gray2,
+ x11gray4, and x11mono.
+
+WWW: http://www.cs.wisc.edu/~ghost/doc/GPL/index.htm
+WWW: http://www.ghostscript.com/