changeset 6399:0140e01f745f

Merge pull request #10 from trueroad/pango-1.28 Fix Issue 2656: some LilyPond builds don't produce font ligatures
author PhilHolmes <PhilEHolmes@gmail.com>
date Mon, 06 Apr 2015 15:42:12 +0100
parents d02df78f9193 (current diff) 3622fffbaeb7 (diff)
children b8e03ad779c9 84fb766d47f0
files
diffstat 20 files changed, 1039 insertions(+), 39 deletions(-) [+]
line wrap: on
line diff
--- a/gub/installer.py	Mon Mar 02 14:34:54 2015 +0000
+++ b/gub/installer.py	Mon Apr 06 15:42:12 2015 +0100
@@ -181,8 +181,9 @@
             'share/guile/*/ice-9/debugger/',
             'share/gettext/intl',
             'share/ghostscript/*/{doc,examples}/',
-            'share/ghostscript/*/Resource/{CMap,ColorSpace,Decoding}/',
-# keep font, otherwise mingw users have problems.
+# keep Decoding, avoids utf8 warnings.
+            'share/ghostscript/*/Resource/{CMap,ColorSpace}/',
+# keep Font, otherwise mingw users have problems.
             'share/ghostscript/*/Resource/{Encoding,SubstCID}/',
             'share/gs/*/{doc,examples}/',
             'share/gtk-doc',
--- a/gub/misc.py	Mon Mar 02 14:34:54 2015 +0000
+++ b/gub/misc.py	Mon Apr 06 15:42:12 2015 +0100
@@ -144,7 +144,7 @@
     return default_version
 
 def version_to_string (t):
-    if t[-1]:
+    if t[-1] and t[-1] != '0':
         return '%s-%s' % ('.'.join (map (str, t[:-1])), t[-1])
     return '.'.join (map (str, t[:-1]))
 
@@ -158,11 +158,7 @@
     s = re.sub ('([^0-9][^0-9]*)', ' \\1 ', s)
     s = re.sub ('[ _.-][ _.-]*', ' ', s)
     s = s.strip ()
-    def atoi (x):
-        if re.match ('^[0-9]+$', x):
-            return int (x)
-        return x
-    return tuple (map (atoi, (s.split (' '))))
+    return tuple (s.split (' '))
 
 def is_ball (s):
     # FIXME: do this properly, by identifying different flavours:
--- a/gub/specs/freetype.py	Mon Mar 02 14:34:54 2015 +0000
+++ b/gub/specs/freetype.py	Mon Apr 06 15:42:12 2015 +0100
@@ -11,7 +11,7 @@
 libraries, display servers, font conversion tools, text image generation
 tools, and many other products as well.'''
 
-    source = 'http://download.savannah.nongnu.org/releases/freetype/freetype-old/freetype-2.3.11.tar.gz&name=freetype'
+    source = 'http://download.savannah.nongnu.org/releases/freetype/freetype-2.4.12.tar.gz&name=freetype'
     def __init__ (self, settings, source):
         target.AutoBuild.__init__ (self, settings, source)
         # Freetype stats /sbin, /usr/sbin and /hurd to determine if
--- a/gub/specs/ghostscript.py	Mon Mar 02 14:34:54 2015 +0000
+++ b/gub/specs/ghostscript.py	Mon Apr 06 15:42:12 2015 +0100
@@ -10,6 +10,7 @@
 shared = True
 
 class Ghostscript_static (target.AutoBuild):
+    parallel_build_broken = True
     '''The GPL Ghostscript PostScript interpreter
 Ghostscript is used for PostScript preview and printing.  It can
 display PostScript documents in an X11 environment.  It can render
@@ -22,10 +23,14 @@
     exe = ''
     revision = 'b35333cf3579e85725bd7d8d39eacc9640515eb8'
     #source = 'git://git.infradead.org/ghostscript.git?branch=refs/remotes/git-svn&revision=' + revision
-    source = 'http://sourceforge.net/projects/ghostscript/files/GPL%%20Ghostscript/8.70/ghostscript-8.70.tar.gz'
+    source = 'http://downloads.ghostscript.com/public/ghostscript-9.15.tar.gz'
     patches = [
-        'ghostscript-8.70-make.patch',
-        ]
+        'ghostscript-9.15-make.patch',
+        'ghostscript-9.15-cygwin.patch',
+        'ghostscript-9.15-windows-popen.patch',
+        'ghostscript-9.15-windows-snprintf.patch',
+        'ghostscript-9.15-windows-make.patch',
+       ]
     parallel_build_broken = True
     # For --enable-compile-inits, see comment in compile()
     configure_flags = (target.AutoBuild.configure_flags
@@ -42,6 +47,8 @@
 --without-omni
 --without-jasper
 --disable-compile-inits
+--with-system-libtiff
+--enable-little-endian
 '''))
     compile_flags = (' INCLUDE=%(system_prefix)s/include'
                      + ' PSDOCDIR=%(prefix_dir)s/share/doc'
@@ -56,13 +63,17 @@
     make_flags = target.AutoBuild.make_flags + ' TARGET=%(target_os)s CFLAGS+="-DHAVE_SYS_TIME_H=1"'
     obj = 'obj'
     @staticmethod
-    def static_version ():
+    def static_version (self=False):
         return misc.version_from_url (Ghostscript.source)
     def __init__ (self, settings, source):
         target.AutoBuild.__init__ (self, settings, source)
         if (isinstance (source, repository.Repository)
             and not isinstance (source, repository.TarBall)):
             source.version = misc.bind_method (Ghostscript.version_from_VERSION, source)
+        else:
+            source.version = misc.bind_method (Ghostscript.static_version, source)
+        if 'powerpc' in self.settings.target_architecture:
+            self.configure_flags = self.configure_flags.replace('--enable-little-endian', '--enable-big-endian')
     @staticmethod
     def version_from_VERSION (self):
         try:
@@ -74,7 +85,15 @@
         except:
             pass
         return '0.0'
-    dependencies = ['libjpeg-devel', 'libpng-devel']
+    dependencies = [
+        'freetype-devel',
+        'libjpeg-devel',
+        'libpng-devel',
+        'libtiff-runtime',
+        'tools::pkg-config',
+        ]
+    def get_build_dependencies (self):
+        return ['libtiff-devel']
     subpackage_names = ['doc', '']
     def srcdir (self):
         return re.sub ('-source', '',
@@ -84,6 +103,12 @@
                        target.AutoBuild.builddir (self))
     def name (self):
         return 'ghostscript'
+    def patch (self):
+        self.symlink('base', self.expand('%(srcdir)s/src'))
+        target.AutoBuild.patch (self)
+        self.file_sub ([('[([]PKGCONFIG', '(XPKGCONFIG'),
+                        ('PKGCONFIG', 'PKG_CONFIG')],
+                       '%(srcdir)s/configure.ac', must_succeed=True)
     def autoupdate (self):
         # generate Makefile.in
         self.system ('cd %(srcdir)s && sh ./autogen.sh --help')
@@ -142,11 +167,17 @@
               '#define ARCH_LOG2_SIZEOF_LONG %(log2_sizeof_long)d' % locals ()),
              ('#define ARCH_SIZEOF_PTR [0-9]',
               '#define ARCH_SIZEOF_PTR %(sizeof_ptr)d' % locals ()),
+             ('#define ARCH_SIZEOF_GX_COLOR_INDEX [0-9]',
+              '#define ARCH_SIZEOF_GX_COLOR_INDEX 8'),
              ], '%(builddir)s/%(obj)s/arch.h')
 
     def configure (self):
         target.AutoBuild.configure (self)
         self.makefile_fixup ('%(builddir)s/Makefile')
+        self.file_sub ([('^(EXTRALIBS *=)', r'\1 -lfreetype '),
+                        ('^(AUXEXTRALIBS *=.*)(-ltiff )', r'\1'),
+                        ('^(AUXEXTRALIBS *=.*)(-L%(system_prefix)s/lib )', r'\1')],
+                       '%(builddir)s/Makefile')
     def makefile_fixup (self, file):
         self.file_sub ([
             ('-Dmalloc=rpl_malloc', ''),
@@ -176,7 +207,7 @@
         # obj/mkromfs is needed for --enable-compile-inits but depends on native -liconv.
         self.system ('''
 cd %(builddir)s && mkdir -p %(obj)s
-cd %(builddir)s && make PATH=/usr/bin:$PATH CC=cc CCAUX=cc C_INCLUDE_PATH= CFLAGS= CPPFLAGS= GCFLAGS= LIBRARY_PATH= OBJ=build-o GLGENDIR=%(obj)s %(obj)s/genconf %(obj)s/echogs %(obj)s/genarch %(obj)s/arch.h 
+cd %(builddir)s && make PATH=/usr/bin:$PATH CC=cc CCAUX=cc C_INCLUDE_PATH= CFLAGS= CPPFLAGS= GCFLAGS= LIBRARY_PATH= OBJ=build-o GLGENDIR=%(obj)s %(obj)s/aux/genconf%(exe)s %(obj)s/aux/echogs%(exe)s %(obj)s/aux/genarch%(exe)s %(obj)s/arch.h 
 ''')
         self.fixup_arch ()
         target.AutoBuild.compile (self)
@@ -200,8 +231,7 @@
                      .replace (' install', ' soinstall'))
     def install (self):
         Ghostscript_static.install (self)
-        self.system ('mv %(install_prefix)s/bin/gs%(exe)sc %(install_prefix)s/bin/gs%(exe)s')
-        self.system ('rm -f %(install_prefix)s/bin/gs%(exe)sx')
+        self.system ('mv %(install_prefix)s/bin/gsc%(exe)s %(install_prefix)s/bin/gs%(exe)s')
 
 if shared:
     Ghostscript = Ghostscript_shared
@@ -211,12 +241,8 @@
 class Ghostscript__mingw (Ghostscript):
     exe = '.exe'
     patches = Ghostscript.patches + [
-        'ghostscript-8.70-cygwin.patch',
-        'ghostscript-8.70-windows-wb.patch',
-        'ghostscript-8.70-windows-make.patch',
-        'ghostscript-8.70-gs_dll.patch',
-        'ghostscript-8.70-mingw-w64-snprintf.patch',
-        ]
+        'ghostscript-9.15-windows-dxmain.patch'
+    ]
     def __init__ (self, settings, source):
         Ghostscript.__init__ (self, settings, source)
         # Configure (compile) without -mwindows for console
@@ -229,11 +255,11 @@
 ac_cv_lib_pthread_pthread_create=no
 '''
     compile_flags = Ghostscript.compile_flags.replace ("XLDFLAGS='", "XLDFLAGS='-mwindows ")
-    def patch (self):
-        self.symlink('base', self.expand('%(srcdir)s/src'))
-        Ghostscript.patch (self)
     def configure (self):
         Ghostscript.configure (self)
+        if 'linux' in self.settings.build_architecture:
+            self.file_sub ([('^(AUXEXTRALIBS *=.*)(-liconv )', r'\1')],
+                           '%(builddir)s/Makefile')
         if shared: # Shared is a configure cross-compile disaster area,
             # it uses BUILD's uname to determine HOST libraries.
             self.file_sub ([('^(EXTRALIBS *=.*)(-ldl )', r'\1'),
@@ -248,6 +274,7 @@
 $(GLOBJ)gp_ntfs.$(OBJ)
 $(GLOBJ)gp_win32.$(OBJ)
 $(GLOBJ)gp_upapr.$(OBJ) 
+$(GLOBJ)gp_wutf8.$(OBJ)
 '''))],
                '%(srcdir)s/base/unix-aux.mak')        
         self.dump ('''
@@ -268,16 +295,26 @@
 
 class Ghostscript__freebsd (Ghostscript):
     dependencies = Ghostscript.dependencies + ['libiconv-devel']
+    patches = Ghostscript.patches + ['ghostscript-9.15-freebsd6.patch']
     def configure (self):
         Ghostscript.configure (self)
+        if 'linux' in self.settings.build_architecture:
+            self.file_sub ([('^(AUXEXTRALIBS *=.*)(-liconv )', r'\1')],
+                           '%(builddir)s/Makefile')
         if shared: # Shared is a configure cross-compile disaster area,
             # it uses BUILD's uname to determine HOST libraries.
             self.file_sub ([('^(EXTRALIBS *=.*)(-ldl )', r'\1')],
                            '%(builddir)s/Makefile')
 
 class Ghostscript__darwin (Ghostscript):
+    patches = Ghostscript.patches + [
+        'ghostscript-9.15-Resource-directory.patch'
+    ]
     def configure (self):
         Ghostscript.configure (self)
+        if 'linux' in self.settings.build_architecture:
+            self.file_sub ([('^(AUXEXTRALIBS *=.*)(-liconv )', r'\1')],
+                           '%(builddir)s/Makefile')
         if shared: # Shared is a configure cross-compile disaster area,
             # it uses BUILD's uname to determine HOST libraries.
             self.file_sub ([('^(EXTRALIBS *=.*)(-ldl )', r'\1'),
@@ -289,26 +326,35 @@
         Ghostscript.install (self)
         if shared:
             self.system ('''
-%(cross_prefix)s/bin/%(target_architecture)s-install_name_tool -id /usr/lib/libgs.8.70.dylib %(install_prefix)s/lib/libgs.8.70.dylib
-%(cross_prefix)s/bin/%(target_architecture)s-install_name_tool -change ./bin/../sobin/libgs.8.70.dylib /usr/lib/libgs.8.70.dylib %(install_prefix)s/bin/gs
+%(cross_prefix)s/bin/%(target_architecture)s-install_name_tool -id /usr/lib/libgs.%(version)s.dylib %(install_prefix)s/lib/libgs.%(version)s.dylib
+%(cross_prefix)s/bin/%(target_architecture)s-install_name_tool -change ./sobin/libgs.%(version)s.dylib @executable_path/../lib/libgs.%(version)s.dylib %(install_prefix)s/bin/gs
 ''')
 
 class Ghostscript__tools (tools.AutoBuild, Ghostscript_static):
     parallel_build_broken = True
-    dependencies = ['libjpeg', 'libpng']
+    dependencies = [
+        'freetype-devel',
+        'libjpeg-devel',
+        'libpng-devel',
+        'libtiff-devel',
+        ]
     configure_flags = (tools.AutoBuild.configure_flags
                        + Ghostscript_static.configure_flags)
     make_flags = Ghostscript_static.make_flags
     def configure (self):
         tools.AutoBuild.configure (self)
         self.makefile_fixup ('%(builddir)s/Makefile')
+        self.file_sub ([('^(EXTRALIBS *=)', r'\1 -lfreetype ')],
+                       '%(builddir)s/Makefile')
+    def autoupdate (self):
+        self.system ('cd %(srcdir)s && sh ./autogen.sh --help')
     def compile (self):
         self.system ('''
 cd %(builddir)s && mkdir -p obj
-cd %(builddir)s && make CC=cc CCAUX=cc C_INCLUDE_PATH= CFLAGS= CPPFLAGS= GCFLAGS= LIBRARY_PATH= obj/genconf obj/echogs obj/genarch obj/arch.h
+cd %(builddir)s && make CC=cc CCAUX=cc C_INCLUDE_PATH= CFLAGS= CPPFLAGS= GCFLAGS= LIBRARY_PATH= obj/aux/genconf obj/aux/echogs obj/aux/genarch obj/arch.h
 cd %(builddir)s && make INCLUDE=/usr/include gconfig__h=gconfig_-native.h gconfig_-native.h
 cd %(builddir)s && make INCLUDE=%(system_prefix)s/include gconfig__h=gconfig_-tools.h gconfig_-tools.h
-cd %(builddir)s && sort -u gconfig_-native.h gconfig_-tools.h > obj/gconfig_.h
+cd %(builddir)s && sort -u gconfig_-native.h gconfig_-tools.h | grep "^#define" | grep -v "HAVE_SYS_TIME_H" > obj/gconfig_.h
 ''')
 #        self.fixup_arch ()
         tools.AutoBuild.compile (self)
--- a/gub/specs/lcms.py	Mon Mar 02 14:34:54 2015 +0000
+++ b/gub/specs/lcms.py	Mon Apr 06 15:42:12 2015 +0100
@@ -1,8 +1,14 @@
 from gub import target
+from gub import tools
 
 class Lcms (target.AutoBuild):
-    source = 'http://www.littlecms.com/lcms-1.17.tar.gz'
+    source = 'http://sourceforge.net/projects/lcms/files/lcms/1.18/lcms-1.18a.tar.gz'
     dependencies = ['tools::libtool']
     def configure (self):
         target.AutoBuild.configure (self)
         self.system ('rm -f %(srcdir)s/include/icc34.h')
+
+class Lcms__tools (tools.AutoBuild, Lcms):
+    def configure (self):
+        tools.AutoBuild.configure (self)
+        self.system ('rm -f %(srcdir)s/include/icc34.h')
--- a/gub/specs/libpng.py	Mon Mar 02 14:34:54 2015 +0000
+++ b/gub/specs/libpng.py	Mon Apr 06 15:42:12 2015 +0100
@@ -2,8 +2,7 @@
 from gub import tools 
 
 class Libpng (target.AutoBuild):
-    source = 'http://sourceforge.net/projects/libpng/files/libpng12/older-releases/1.2.8/libpng-1.2.8-config.tar.gz'
-    patches = ['libpng-pngconf.h-setjmp.patch']
+    source = 'http://sourceforge.net/projects/libpng/files/libpng12/1.2.53/libpng-1.2.53.tar.gz'
     dependencies = ['zlib-devel', 'tools::autoconf', 'tools::automake', 'tools::libtool']
     def name (self):
         return 'libpng'
--- a/gub/specs/libtiff.py	Mon Mar 02 14:34:54 2015 +0000
+++ b/gub/specs/libtiff.py	Mon Apr 06 15:42:12 2015 +0100
@@ -2,13 +2,40 @@
 from gub import tools
 
 class Libtiff (target.AutoBuild):
-    source = 'http://dl.maptools.org/dl/libtiff/tiff-3.8.2.tar.gz'
-    dependencies = ['tools::libtool', 'libjpeg-devel']
+    source = 'http://download.osgeo.org/libtiff/tiff-4.0.3.tar.gz'
+    dependencies = ['tools::libtool', 'libjpeg-devel', 'zlib-devel']
+    subpackage_names = ['doc', 'devel', 'runtime', '']
+    def get_subpackage_definitions (self):
+        d = target.AutoBuild.get_subpackage_definitions (self)
+        prefix_dir = self.settings.prefix_dir
+        d['runtime'] = [
+            prefix_dir + '/lib/libtiff*.so*',
+        ]
+        return d
+
+class Libtiff__mingw (Libtiff):
+    def get_subpackage_definitions (self):
+        d = target.AutoBuild.get_subpackage_definitions (self)
+        prefix_dir = self.settings.prefix_dir
+        d['runtime'] = [
+            prefix_dir + '/bin/libtiff*.dll',
+        ]
+        return d
+
+class Libtiff__darwin (Libtiff):
+    def get_subpackage_definitions (self):
+        d = target.AutoBuild.get_subpackage_definitions (self)
+        prefix_dir = self.settings.prefix_dir
+        d['runtime'] = [
+            prefix_dir + '/lib/libtiff*.dylib',
+        ]
+        return d
 
 class Libtiff__tools (tools.AutoBuild, Libtiff):
     dependencies = [
             'libtool',
             'libjpeg-devel',
+            'zlib-devel',
 #            'system::g++',
             ]
     configure_flags = (tools.AutoBuild.configure_flags
--- a/gub/specs/lilypondcairo.py	Mon Mar 02 14:34:54 2015 +0000
+++ b/gub/specs/lilypondcairo.py	Mon Apr 06 15:42:12 2015 +0100
@@ -6,11 +6,12 @@
 # in.  Hmm.
 
 class Lilypondcairo (lilypond.Lilypond):
-    source = 'http://lilypond.org/download/source/v2.13/lilypond-2.13.54.tar.gz'
+    source = 'http://lilypond.org/download/source/v2.13/lilypond-2.13.62.tar.gz'
     dependencies = [x.replace ('pango', 'pangocairo')
                     for x in lilypond.Lilypond.dependencies]
     patches = [
         '0003-Start-OTF-font-from-E800-avoids-hardcoded-linux-unic.patch',
+        '0001-Allow-for-spaces-in-ttf-font-glyph-names.-Fixes-1562.patch',
         ]
     def get_conflict_dict (self):
         return {'': ['lilypond']}
@@ -21,6 +22,7 @@
                 for x in lilypond.Lilypond__mingw.dependencies]
     patches = [
         '0003-Start-OTF-font-from-E800-avoids-hardcoded-linux-unic.patch',
+        '0001-Allow-for-spaces-in-ttf-font-glyph-names.-Fixes-1562.patch',
         ]
     def get_conflict_dict (self):
         return {'': ['lilypond']}
--- a/gub/specs/netpbm.py	Mon Mar 02 14:34:54 2015 +0000
+++ b/gub/specs/netpbm.py	Mon Apr 06 15:42:12 2015 +0100
@@ -19,7 +19,7 @@
 CC=gcc
 CFLAGS='-O2 -fPIC -flax-vector-conversions'
 LDFLAGS='%(rpath)s -L%(builddir)s/pbm -L%(builddir)s/pgm -L%(builddir)s/pnm -L%(builddir)s/ppm'
-LADD=-lm
+LADD='-lm -lz'
 LINUXSVGALIB=NONE
 XML2LD=NONE
 XML2_LIBS=NONE
--- a/gub/specs/pango.py	Mon Mar 02 14:34:54 2015 +0000
+++ b/gub/specs/pango.py	Mon Apr 06 15:42:12 2015 +0100
@@ -12,10 +12,11 @@
     (r'^1\.24', '1.6.0'),
     (r'^1\.26', '1.6.0'),
     (r'^1\.27', '1.6.0'),
+    (r'^1\.28', '1.6.0'),
     ]
 
 class Pango (target.AutoBuild):
-    source = 'http://ftp.gnome.org/pub/GNOME/platform/2.28/2.28.1/sources/pango-1.26.0.tar.gz'
+    source = 'http://ftp.gnome.org/pub/GNOME/sources/pango/1.28/pango-1.28.3.tar.gz'
     patches = ['pango-1.20-substitute-env.patch']
     dependencies = [
             'tools::glib', 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/patches/ghostscript-9.00-share-libtiff-init.patch	Mon Apr 06 15:42:12 2015 +0100
@@ -0,0 +1,40 @@
+>From 0f34cb36f7812efcfb3bb27256a37ba349c83776 Mon Sep 17 00:00:00 2001
+From: Hin-Tak Leung <hintak@ghostscript.com>
+Date: Thu, 12 Aug 2010 00:27:14 +0100
+Subject: [PATCH 07/10] SHARE_LIBTIFF not initialised
+
+---
+ base/configure.ac |    3 +--
+ 1 files changed, 1 insertions(+), 2 deletions(-)
+
+diff --git a/base/configure.ac b/base/configure.ac
+index 0f7cb78..deea3cf 100644
+--- a/base/configure.ac
++++ b/base/configure.ac
+@@ -540,6 +540,7 @@ dnl png for the png output device; it also requires zlib
+ AC_ARG_WITH([system-libtiff], AC_HELP_STRING([--with-system-libtiff],
+ 					     [Force using the systems libtiff]),
+ 	    [], [with_system_libtiff=check])
++SHARE_LIBTIFF=1
+ TIFFDEVS=''
+ TIFFDEVS_ALL='$(DD)tiffs $(DD)tiff12nc $(DD)tiff24nc $(DD)tiff48nc $(DD)tiff32nc $(DD)tiff64nc $(DD)tiffcrle $(DD)tifflzw $(DD)tiffpack $(DD)tiffgray $(DD)tiffsep'
+ case "x$with_system_libtiff" in
+@@ -547,7 +548,6 @@ case "x$with_system_libtiff" in
+ 	if test -d tiff; then
+ 	    LIBTIFFDIR=tiff
+ 	    HAVE_LOCAL_LIBTIFF=1
+-	    SHARE_LIBTIFF=0
+ 	else
+ 	    AC_CHECK_LIB(tiff, TIFFOpen,
+ 		     [AC_CHECK_HEADERS(tiff.h, [HAVE_SYSTEM_LIBTIFF=1;SHARE_LIBTIFF=1])],
+@@ -577,7 +577,6 @@ Disabling tiff output devices.])
+         if test -d tiff; then
+ 	    AC_MSG_RESULT([yes])
+ 	    LIBTIFFDIR=tiff
+-	    SHARE_LIBTIFF=0
+ 	    TIFFDEVS="$TIFFDEVS_ALL"
+ 	else
+ 	    AC_MSG_RESULT([no])
+-- 
+1.7.2.2
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/patches/ghostscript-9.00-windows-snprintf.patch	Mon Apr 06 15:42:12 2015 +0100
@@ -0,0 +1,30 @@
+>From 62de1fd86c1172903641c12a90122f7c00266ee3 Mon Sep 17 00:00:00 2001
+From: Hin-Tak Leung <hintak@ghostscript.com>
+Date: Thu, 12 Aug 2010 02:09:48 +0100
+Subject: [PATCH 09/10] mingw32/cygwin provides snprintf() - no need to have private
+ version, unlike msvc
+
+---
+ base/gp_mswin.c |    2 ++
+ 1 files changed, 2 insertions(+), 0 deletions(-)
+
+diff --git a/base/gp_mswin.c b/base/gp_mswin.c
+index a9c3d3a..096c5f8 100644
+--- a/base/gp_mswin.c
++++ b/base/gp_mswin.c
+@@ -729,6 +729,7 @@ int gp_fseek_64(FILE *strm, int64_t offset, int origin)
+ /* Microsoft Visual C++ 2005  doesn't properly define snprintf,
+    which is defined in the C standard ISO/IEC 9899:1999 (E) */
+ 
++#if !defined(__CYGWIN__) && !defined(__MINGW32__)
+ int snprintf(char *buffer, size_t count, const char *format, ...)
+ {
+     if (count > 0) {
+@@ -743,3 +744,4 @@ int snprintf(char *buffer, size_t count, const char *format, ...)
+     } else
+ 	return 0;
+ }
++#endif
+-- 
+1.7.2.2
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/patches/ghostscript-9.15-Resource-directory.patch	Mon Apr 06 15:42:12 2015 +0100
@@ -0,0 +1,22 @@
+--- ghostscript-9.15/Resource/Init/gs_lev2.ps.org	2014-09-22 19:17:33.000000000 +0900
++++ ghostscript-9.15/Resource/Init/gs_lev2.ps	2015-03-18 19:43:48.202037700 +0900
+@@ -653,7 +653,7 @@
+     % Search for valid (iccprofiles) directory as a sibling to (Resource)
+     % and set it as a default if found.
+     LIBPATH {
+-      (Resource) search {
++      (Resource/) search {
+         exch pop exch pop (iccprofiles) concatstrings
+         .file_name_separator concatstrings
+         dup (default_gray.icc) concatstrings status {
+--- ghostscript-9.15/Resource/Init/gs_res.ps.org	2014-09-22 19:17:33.000000000 +0900
++++ ghostscript-9.15/Resource/Init/gs_res.ps	2015-03-18 19:44:06.280211600 +0900
+@@ -284,7 +284,7 @@
+     dup .file_name_current eq {
+       pop
+     } {
+-      (Resource) search {
++      (Resource/) search {
+         exch concatstrings
+         exch pop
+         .file_name_separator concatstrings exit
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/patches/ghostscript-9.15-cygwin.patch	Mon Apr 06 15:42:12 2015 +0100
@@ -0,0 +1,87 @@
+--- a/base/unix-gcc.mak	2014-09-22 19:17:33.000000000 +0900
++++ b/base/unix-gcc.mak	2015-03-11 20:58:56.434601000 +0900
+@@ -57,13 +57,13 @@
+ INSTALL_PROGRAM = $(INSTALL) -m 755
+ INSTALL_DATA = $(INSTALL) -m 644
+ 
+-prefix = /usr/local
++prefix = /usr
+ exec_prefix = $(prefix)
+ bindir = $(exec_prefix)/bin
+ scriptdir = $(bindir)
+ includedir = $(prefix)/include
+ libdir = $(exec_prefix)/lib
+-mandir = $(prefix)/man
++mandir = $(prefix)/share/man
+ man1ext = 1
+ datadir = $(prefix)/share
+ gsdir = $(datadir)/ghostscript
+@@ -71,7 +71,7 @@
+ gssharedir = $(libdir)/ghostscript/$(GS_DOT_VERSION)
+ gsincludedir = $(includedir)/ghostscript/
+ 
+-docdir=$(gsdatadir)/doc
++docdir=$(gsdatadir)/doc/ghostscript-$(GS_DOT_VERSION)
+ exdir=$(gsdatadir)/examples
+ GS_DOCDIR=$(docdir)
+ 
+@@ -156,7 +156,7 @@
+ # what its name is.
+ # See gs.mak and Make.htm for more information.
+ 
+-SHARE_LIBPNG=0
++SHARE_LIBPNG=1
+ LIBPNG_NAME=png
+ 
+ # Define whether to use a shared version of libtiff and where
+@@ -180,7 +180,7 @@
+ # what its name is (usually libz, but sometimes libgz).
+ # See gs.mak and Make.htm for more information.
+ 
+-SHARE_ZLIB=0
++SHARE_ZLIB=1
+ #ZLIB_NAME=gz
+ ZLIB_NAME=z
+ 
+@@ -245,7 +245,7 @@
+ CFLAGS_STANDARD=-O2
+ CFLAGS_DEBUG=-g -O0
+ CFLAGS_PROFILE=-pg -O2
+-CFLAGS_SO=-fPIC
++#CFLAGS_SO=-fPIC
+ 
+ # Define the other compilation flags.  Add at most one of the following:
+ #	-DBSD4_2 for 4.2bsd systems.
+@@ -302,7 +302,7 @@
+ # Note that x_.h expects to find the header files in $(XINCLUDE)/X11,
+ # not in $(XINCLUDE).
+ 
+-XINCLUDE=-I/usr/X11R6/include
++#XINCLUDE=-I/usr/X11R6/include
+ 
+ # Define the directory/ies and library names for the X11 library files.
+ # XLIBDIRS is for ld and should include -L; XLIBDIR is for LD_RUN_PATH
+@@ -317,9 +317,11 @@
+ #XLIBS=Xt SM ICE Xext X11
+ 
+ #XLIBDIRS=-L/usr/local/X/lib
+-XLIBDIRS=-L/usr/X11R6/lib
++#XLIBDIRS=-L/usr/X11R6/lib
++XLIBDIRS=
+ XLIBDIR=
+-XLIBS=Xt Xext X11
++#XLIBS=Xt Xext X11
++XLIBS=
+ 
+ # Define the .dev module that implements thread and synchronization
+ # primitives for this platform.
+@@ -377,7 +379,8 @@
+ # Choose the device(s) to include.  See devs.mak for details,
+ # devs.mak and contrib.mak for the list of available devices.
+ 
+-DEVICE_DEVS=$(DISPLAY_DEV) $(DD)x11.dev $(DD)x11alpha.dev $(DD)x11cmyk.dev $(DD)x11gray2.dev $(DD)x11gray4.dev $(DD)x11mono.dev
++#DEVICE_DEVS=$(DISPLAY_DEV) $(DD)x11.dev $(DD)x11alpha.dev $(DD)x11cmyk.dev $(DD)x11gray2.dev $(DD)x11gray4.dev $(DD)x11mono.dev
++DEVICE_DEVS=
+ 
+ #DEVICE_DEVS1=
+ #DEVICE_DEVS2=
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/patches/ghostscript-9.15-freebsd6.patch	Mon Apr 06 15:42:12 2015 +0100
@@ -0,0 +1,14 @@
+FreeBSD 6 doesn't have posix_memalign().
+FreeBSD 7 has posix_memalign().
+
+--- a/openjpeg/src/lib/openjp2/opj_malloc.h	2014-09-22 19:17:33.000000000 +0900
++++ b/openjpeg/src/lib/openjp2/opj_malloc.h	2015-03-13 23:38:30.196095100 +0900
+@@ -99,7 +99,7 @@
+ 	#if defined(__sun)
+ 		#define HAVE_MEMALIGN
+   #elif defined(__FreeBSD__)
+-    #define HAVE_POSIX_MEMALIGN
++    /*#define HAVE_POSIX_MEMALIGN*/
+ 	/* Linux x86_64 and OSX always align allocations to 16 bytes */
+ 	#elif !defined(__amd64__) && !defined(__APPLE__) && !defined(_AIX)
+ 		#define HAVE_MEMALIGN
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/patches/ghostscript-9.15-make.patch	Mon Apr 06 15:42:12 2015 +0100
@@ -0,0 +1,105 @@
+--- a/base/unix-dll.mak	2014-09-22 19:17:33.000000000 +0900
++++ b/base/unix-dll.mak	2015-03-11 20:06:35.095445000 +0900
+@@ -28,6 +28,11 @@
+ SODIRPREFIX=so
+ SODEBUGDIRPREFIX=sodebug
+ 
++ifeq ($(TARGET),mingw)
++GS=gs
++XE=.exe
++endif
++
+ # ------------------- Ghostscript shared object --------------------------- #
+ 
+ # Shared object names
+@@ -63,14 +68,27 @@
+ # LDFLAGS_SO=-shared -Wl,$(LD_SET_DT_SONAME)$(LDFLAGS_SO_PREFIX)$(GS_SONAME_MAJOR)
+ 
+ 
++ifeq ($(TARGET),darwin)
+ # MacOS X
+-#GS_SOEXT=dylib
+-#GS_SONAME=$(GS_SONAME_BASE).$(GS_SOEXT)
+-#GS_SONAME_MAJOR=$(GS_SONAME_BASE).$(GS_VERSION_MAJOR).$(GS_SOEXT)
+-#GS_SONAME_MAJOR_MINOR=$(GS_SONAME_BASE).$(GS_VERSION_MAJOR).$(GS_VERSION_MINOR).$(GS_SOEXT)
++GS_SOEXT=dylib
++GS_SONAME=$(GS_SONAME_BASE).$(GS_SOEXT)
++GS_SONAME_MAJOR=$(GS_SONAME_BASE).$(GS_VERSION_MAJOR).$(GS_SOEXT)
++GS_SONAME_MAJOR_MINOR=$(GS_SONAME_BASE).$(GS_VERSION_MAJOR).$(GS_VERSION_MINOR).$(GS_SOEXT)
+ #LDFLAGS_SO=-dynamiclib -flat_namespace
+ #LDFLAGS_SO_MAC=-dynamiclib -install_name $(GS_SONAME_MAJOR_MINOR)
+ #LDFLAGS_SO=-dynamiclib -install_name $(FRAMEWORK_NAME)
++LDFLAGS_SO=-dynamiclib
++endif
++
++ifeq ($(TARGET),mingw)
++# Mingw
++GS_SONAME_BASE=gs
++GS_SOEXT=dll
++GS_SONAME=$(GS_SONAME_BASE).$(GS_SOEXT)
++GS_SONAME_MAJOR=$(GS_SONAME_BASE)-$(GS_VERSION_MAJOR).$(GS_SOEXT)
++GS_SONAME_MAJOR_MINOR=$(GS_SONAME_BASE)-$(GS_VERSION_MAJOR).$(GS_VERSION_MINOR).$(GS_SOEXT)
++LDFLAGS_SO=-shared -Wl,-soname=$(GS_SONAME_MAJOR_MINOR)
++endif
+ 
+ GS_SO=$(BINDIR)/$(GS_SONAME)
+ GS_SO_MAJOR=$(BINDIR)/$(GS_SONAME_MAJOR) 
+@@ -99,6 +117,8 @@
+ 
+ # ------------------------- Recursive make targets ------------------------- #
+ 
++# Help -rpath $ORIGIN survive the $(MAKE) command line expansion
++MAKE_LDFLAGS=$(subst $$,\$$$$,$(LDFLAGS))
+ SODEFS=\
+  GS_XE=$(BINDIR)/$(GS_SONAME_MAJOR_MINOR)\
+  DISPLAY_DEV=$(DD)display.dev\
+@@ -129,16 +149,16 @@
+ 	$(MAKE) so-subtarget GENOPT='-DDEBUG' BUILDDIRPREFIX=$(SODEBUGDIRPREFIX)
+ 
+ so-subtarget:
+-	$(MAKE) $(SODEFS) GENOPT='$(GENOPT)' LDFLAGS='$(LDFLAGS)'\
++	$(MAKE) $(SODEFS) GENOPT='$(GENOPT)' LDFLAGS='$(MAKE_LDFLAGS)'\
+ 	 CFLAGS='$(CFLAGS_STANDARD) $(GCFLAGS) $(AC_CFLAGS) $(XCFLAGS)' prefix=$(prefix)\
+ 	 directories
+-	$(MAKE) $(SODEFS) GENOPT='$(GENOPT)' LDFLAGS='$(LDFLAGS)'\
++	$(MAKE) $(SODEFS) GENOPT='$(GENOPT)' LDFLAGS='$(MAKE_LDFLAGS)'\
+ 	 CFLAGS='$(CFLAGS_STANDARD) $(GCFLAGS) $(AC_CFLAGS) $(XCFLAGS)' prefix=$(prefix)\
+ 	 $(AUXDIR)/echogs$(XEAUX) $(AUXDIR)/genarch$(XEAUX)
+-	$(MAKE) $(SODEFS) GENOPT='$(GENOPT)' LDFLAGS='$(LDFLAGS) $(LDFLAGS_SO)'\
++	$(MAKE) $(SODEFS) GENOPT='$(GENOPT)' LDFLAGS='$(MAKE_LDFLAGS) $(LDFLAGS_SO)'\
+ 	 CFLAGS='$(CFLAGS_STANDARD) $(CFLAGS_SO) $(GCFLAGS) $(AC_CFLAGS) $(XCFLAGS)'\
+ 	 prefix=$(prefix)
+-	$(MAKE) $(SODEFS_FINAL) GENOPT='$(GENOPT)' LDFLAGS='$(LDFLAGS)'\
++	$(MAKE) $(SODEFS_FINAL) GENOPT='$(GENOPT)' LDFLAGS='$(MAKE_LDFLAGS)'\
+ 	 CFLAGS='$(CFLAGS_STANDARD) $(GCFLAGS) $(AC_CFLAGS) $(XCFLAGS)' prefix=$(prefix)\
+ 	 $(GSSOC_XE) $(GSSOX_XE)
+ 
+--- a/base/unixlink.mak	2014-09-22 19:17:33.000000000 +0900
++++ b/base/unixlink.mak	2015-03-11 20:53:01.152652900 +0900
+@@ -45,13 +45,16 @@
+ 	$(SH) <$(liar_tr)
+ 	$(RANLIB) $(GS_A)
+ 
++# Help -rpath $ORIGIN survive the ECHOGS_XE sh command line expansion
++SHELL_LDFLAGS=$(subst $$,\$$,$(LDFLAGS))
++
+ # Here is the final link step.  The stuff with LD_RUN_PATH is for SVR4
+ # systems with dynamic library loading; I believe it's harmless elsewhere.
+ # The resetting of the environment variables to empty strings is for SCO Unix,
+ # which has limited environment space.
+ ldt_tr=$(PSOBJ)ldt.tr
+ $(GS_XE): $(ld_tr) $(ECHOGS_XE) $(XE_ALL) $(PSOBJ)gsromfs$(COMPILE_INITS).$(OBJ)
+-	$(ECHOGS_XE) -w $(ldt_tr) -n - $(CCLD) $(LDFLAGS) -o $(GS_XE)
++	$(ECHOGS_XE) -w $(ldt_tr) -n - $(CCLD) $(SHELL_LDFLAGS) -o $(GS_XE)
+ 	$(ECHOGS_XE) -a $(ldt_tr) -n -s $(PSOBJ)gsromfs$(COMPILE_INITS).$(OBJ) $(PSOBJ)gs.$(OBJ) -s
+ 	cat $(ld_tr) >>$(ldt_tr)
+ 	$(ECHOGS_XE) -a $(ldt_tr) -s - $(EXTRALIBS) $(STDLIBS)
+@@ -70,7 +73,7 @@
+ apitest: $(APITEST_XE)
+ 
+ $(APITEST_XE): $(ld_tr) $(ECHOGS_XE) $(XE_ALL) $(PSOBJ)gsromfs$(COMPILE_INITS).$(OBJ) $(PSOBJ)apitest.$(OBJ)
+-	$(ECHOGS_XE) -w $(ldt_tr) -n - $(CCLD) $(LDFLAGS) -o $(APITEST_XE)
++	$(ECHOGS_XE) -w $(ldt_tr) -n - $(CCLD) $(SHELL_LDFLAGS) -o $(APITEST_XE)
+ 	$(ECHOGS_XE) -a $(ldt_tr) -n -s $(PSOBJ)gsromfs$(COMPILE_INITS).$(OBJ) $(PSOBJ)apitest.$(OBJ) -s
+ 	cat $(ld_tr) >>$(ldt_tr)
+ 	$(ECHOGS_XE) -a $(ldt_tr) -s - $(EXTRALIBS) $(STDLIBS)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/patches/ghostscript-9.15-windows-dxmain.patch	Mon Apr 06 15:42:12 2015 +0100
@@ -0,0 +1,303 @@
+--- a/psi/dxmainc.c	2014-09-22 19:17:33.000000000 +0900
++++ b/psi/dxmainc.c	2015-03-19 22:41:31.286769200 +0900
+@@ -28,10 +28,12 @@
+  *  gcc -shared -Wl,-soname,libgs.so.7 -o libgs.so.7.00 file.o -lc
+  */
+ 
++#include "windows_.h"
+ #include <stdio.h>
+ #include <stdlib.h>
+ #include <string.h>
+ #include <unistd.h>
++#include <io.h>
+ #include <fcntl.h>
+ #include <errno.h>
+ #define __PROTOTYPES__
+@@ -40,22 +42,22 @@
+ 
+ const char start_string[] = "systemdict /start get exec\n";
+ 
+-static int gsdll_stdin(void *instance, char *buf, int len);
+-static int gsdll_stdout(void *instance, const char *str, int len);
+-static int gsdll_stdout(void *instance, const char *str, int len);
++static int GSDLLCALL gsdll_stdin(void *instance, char *buf, int len);
++static int GSDLLCALL gsdll_stdout(void *instance, const char *str, int len);
++static int GSDLLCALL gsdll_stdout(void *instance, const char *str, int len);
+ 
+ /*********************************************************************/
+ /* stdio functions */
+ 
+ /* callback for reading stdin */
+ /* Use async input */
+-static int
++static int GSDLLCALL
+ gsdll_stdin(void *instance, char *buf, int len)
+ {
+-    return read(fileno(stdin), buf, len);
++    return _read(fileno(stdin), buf, len);
+ }
+ 
+-static int
++static int GSDLLCALL
+ gsdll_stdout(void *instance, const char *str, int len)
+ {
+     fwrite(str, 1, len, stdout);
+@@ -63,7 +65,7 @@
+     return len;
+ }
+ 
+-static int
++static int GSDLLCALL
+ gsdll_stderr(void *instance, const char *str, int len)
+ {
+     fwrite(str, 1, len, stderr);
+@@ -71,18 +73,196 @@
+     return len;
+ }
+ 
++/* porting from dwmainc.c */
++#ifndef GS_NO_UTF8
++/* stdio functions - versions that translate to/from utf-8 */
++static int GSDLLCALL
++gsdll_stdin_utf8(void *instance, char *buf, int len)
++{
++    static WCHAR thiswchar = 0; /* wide character to convert to multiple bytes */
++    static int nmore = 0;       /* number of additional encoding bytes to generate */
++    UINT consolecp = 0;
++    int nret = 0;               /* number of bytes returned to caller */
++    int i;
++
++    while (len) {
++        while (len && nmore) {
++            nmore--;
++            *buf++ = 0x80 | ((thiswchar >> (6 * nmore)) & 0x3F), nret++;
++            len--;
++        }
++        while (len) {
++            if (0 >= _read(fileno(stdin), buf, 1))
++                return nret;
++            nret++, buf++, len--;
++            if (buf[-1] == '\n')
++                /* return at end of line (note: no traslation needed) */
++                return nret;
++            else if ((unsigned char)buf[-1] <= 0x7F)
++                /* no translation needed for 7-bit ASCII codes */
++                continue;
++            else {
++                /* extended character, may be double */
++                BYTE dbcsstr[2];
++
++                dbcsstr[0] = buf[-1];
++                if (!consolecp)
++                    consolecp = GetConsoleCP();
++                thiswchar = L'?'; /* initialize in case the conversion below fails */
++                if (IsDBCSLeadByteEx(consolecp, dbcsstr[0])) {
++                    /* double-byte character code, fetch the trail byte */
++                    _read(fileno(stdin), &dbcsstr[1], 1);
++                    MultiByteToWideChar(consolecp, 0, dbcsstr, 2, &thiswchar, 1);
++                }
++                else {
++                    MultiByteToWideChar(consolecp, 0, dbcsstr, 1, &thiswchar, 1);
++                }
++                /* convert thiswchar to utf-8 */
++                if (thiswchar <= 0x007F) {          /* encoded as single byte */
++                    buf[-1] = (char)thiswchar;
++                } else if (thiswchar <= 0x07FF) {   /* encoded as 2 bytes */
++                    buf[-1] = 0xC0 | ((thiswchar >> 6) & 0x1F);
++                    nmore = 1;
++                    break;
++                } else if (thiswchar <= 0xFFFF) {   /* encoded as 3 bytes */
++                    buf[-1] = 0xE0 | ((thiswchar >> 12) & 0xF);
++                    nmore = 2;
++                    break;
++                } else
++                    /* note: codes outside the BMP not handled */
++                    buf[-1] = '?';
++            }
++        }
++    }
++    return nret;
++}
++
++static void
++gsdll_utf8write(FILE *stdwr, const char *str, int len, WCHAR *thiswchar, int *nmore)
++{
++    UINT consolecp = 0;
++
++    while (len) {
++        const char *str0;
++
++        /* write ASCII chars without translation */
++        for (str0 = str; len && !(*str & 0x80); str++, len--);
++        if (str > str0) {
++            if (*nmore) {
++                /* output previous, incomplete utf-8 sequence as ASCII "?" */
++                fwrite("?", 1, 1, stdwr);
++                *nmore = 0, *thiswchar = 0;
++            }
++            fwrite(str0, 1, str - str0, stdwr);
++        }
++        /* accumulate lead/trail bytes into *thiswchar */
++        for (; len; str++, len--) {
++            switch (*str & 0xC0) {
++                case 0x80:      /* trail byte */
++                    if (*nmore) {
++                        (*nmore)--;
++                        *thiswchar |= (WCHAR)(unsigned char)(*str & 0x3F) << (6 * *nmore);
++                        }
++                    else {
++                        /* lead byte missing; output unexpected trail byte as ASCII "?" */
++                        *nmore = 0;
++                        *thiswchar = L'?';
++                    }
++                    break;
++                case 0xC0:      /* lead byte */
++                    if (*nmore)
++                        /* output previous, incomplete utf-8 sequence as ASCII "?" */
++                        fwrite("?", 1, 1, stdwr);
++                    if (!(*str & 0x20))
++                        *nmore = 1;     /* 2-byte encoding */
++                    else if (!(*str & 0x10))
++                        *nmore = 2;     /* 3-byte encoding */
++                    else if (!(*str & 0x08))
++                        *nmore = 3;     /* 4-byte encoding */
++                    else
++                        *nmore = 0;     /* restricted (> 4) or invalid encodings */
++                    if (*nmore)
++                        *thiswchar = (WCHAR)(unsigned char)(*str & (0x3F >> *nmore)) << (6 * *nmore);
++                    else {
++                        /* output invalid encoding as ASCII "?" */
++                        *thiswchar = L'?';
++                    }
++                    break;
++                default:        /* cannot happen because *str has MSB set */
++                    break;
++            }
++            /* output wide character if finished */
++            if (!*nmore) {
++                char mbstr[8];
++                int n_mbstr;
++
++                if (!consolecp)
++                    consolecp = GetConsoleOutputCP();
++                n_mbstr = WideCharToMultiByte(consolecp, 0, thiswchar, 1, mbstr, sizeof mbstr, NULL, NULL);
++                if (n_mbstr <= 0)
++                    fwrite("?", 1, 1, stdwr);
++                else
++                    fwrite(mbstr, 1, n_mbstr, stdwr);
++                *thiswchar = 0; /* cleanup */
++                str++, len--;
++                break;
++            }
++        }
++    }
++    fflush(stdwr);
++}
++
++static int GSDLLCALL
++gsdll_stdout_utf8(void *instance, const char *utf8str, int bytelen)
++{
++    static WCHAR thiswchar = 0; /* accumulates the bits from multiple encoding bytes */
++    static int nmore = 0;       /* expected number of additional encoding bytes */
++
++    gsdll_utf8write(stdout, utf8str, bytelen, &thiswchar, &nmore);
++    return bytelen;
++}
++
++static int GSDLLCALL
++gsdll_stderr_utf8(void *instance, const char *utf8str, int bytelen)
++{
++    static WCHAR thiswchar = 0; /* accumulates the bits from multiple encoding bytes */
++    static int nmore = 0;       /* expected number of additional encoding bytes */
++
++    gsdll_utf8write(stderr, utf8str, bytelen, &thiswchar, &nmore);
++    return bytelen;
++}
++#endif
++
+ /*********************************************************************/
+ 
++#ifdef GS_NO_UTF8
+ int main(int argc, char *argv[])
++#else
++/* porting from dwmainc.c */
++static int main_utf8(int argc, char *argv[])
++#endif
+ {
+     int exit_status;
+     int code = 1, code1;
+     void *instance;
+     int exit_code;
+ 
++    if (!_isatty(fileno(stdin)))
++        _setmode(fileno(stdin), _O_BINARY);
++    _setmode(fileno(stdout), _O_BINARY);
++    _setmode(fileno(stderr), _O_BINARY);
++
+     /* run Ghostscript */
+     if ((code = gsapi_new_instance(&instance, NULL)) == 0) {
++#ifdef GS_NO_UTF8
+         gsapi_set_stdio(instance, gsdll_stdin, gsdll_stdout, gsdll_stderr);
++#else
++        /* porting from dwmainc.c */
++        gsapi_set_stdio(instance,
++            _isatty(fileno(stdin)) ?  gsdll_stdin_utf8 : gsdll_stdin,
++            _isatty(fileno(stdout)) ?  gsdll_stdout_utf8 : gsdll_stdout,
++            _isatty(fileno(stderr)) ?  gsdll_stderr_utf8 : gsdll_stderr);
++#endif
+         code = gsapi_init_with_args(instance, argc, argv);
+ 
+         if (code == 0)
+@@ -111,3 +291,52 @@
+ 
+     return exit_status;
+ }
++
++/* porting from dwmainc.c */
++#ifndef GS_NO_UTF8
++int wmain(int argc, wchar_t *argv[], wchar_t *envp[]) {
++    /* Duplicate args as utf8 */
++    char **nargv;
++    int i, code;
++
++    nargv = calloc(argc, sizeof(nargv[0]));
++    if (nargv == NULL)
++        goto err;
++    for (i=0; i < argc; i++) {
++        nargv[i] = malloc(wchar_to_utf8(NULL, argv[i]));
++        if (nargv[i] == NULL)
++            goto err;
++        (void)wchar_to_utf8(nargv[i], argv[i]);
++    }
++    code = main_utf8(argc, nargv);
++
++    if (0) {
++err:
++        fprintf(stderr,
++                "Ghostscript failed to initialise due to malloc failure\n");
++        code = -1;
++    }
++
++    if (nargv) {
++        for (i=0; i<argc; i++) {
++            free(nargv[i]);
++        }
++        free(nargv);
++    }
++
++    return code;
++}
++#endif
++
++/* for mingw non-unicode runtime */
++#ifndef GS_NO_UTF8
++int __wgetmainargs (int *c, wchar_t ***v, wchar_t ***e, int w, int *s);
++
++int main(int argc, wchar_t *argv[], wchar_t *envp[]) {
++    int wargc=0, si=0;
++    wchar_t **wargv, **wenvp;
++
++    __wgetmainargs (&wargc, &wargv, &wenvp, 1, &si);
++    return wmain(wargc, wargv, wenvp);
++}
++#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/patches/ghostscript-9.15-windows-make.patch	Mon Apr 06 15:42:12 2015 +0100
@@ -0,0 +1,295 @@
+--- /dev/null	2015-03-14 01:29:23.000000000 +0900
++++ b/base/gsdll.mak	2015-03-14 01:27:42.445482800 +0900
+@@ -0,0 +1,28 @@
++#    Copyright (C) 1997-2004 Aladdin Enterprises.  All rights reserved.
++# 
++# This software is provided AS-IS with no warranty, either express or
++# implied.
++# 
++# This software is distributed under license and may not be copied,
++# modified or distributed except as expressly authorized under the terms
++# of the license contained in the file LICENSE in this distribution.
++# 
++# For more information about licensing, please refer to
++# http://www.ghostscript.com/licensing/. For information on
++# commercial licensing, go to http://www.artifex.com/licensing/ or
++# contact Artifex Software, Inc., 101 Lucas Valley Road #110,
++# San Rafael, CA  94903, U.S.A., +1(415)492-9861.
++
++# This makefile must be acceptable to Microsoft Visual C++, Watcom C++,
++# and Borland C++.  For this reason, the only conditional directives
++# allowed are !if[n]def, !else, and !endif.
++
++# Compile gsdll.c, the main program of the DLL.
++
++$(PSOBJ)gsdll.obj: $(PSSRC)gsdll.c $(AK) $(iapi_h) $(ghost_h)
++	$(PSCCWIN) $(COMPILE_FOR_DLL) $(PSO_)gsdll.$(OBJ) $(C_) $(PSSRC)gsdll.c
++
++$(GLOBJ)gp_msdll.obj: $(GLSRC)gp_msdll.c $(AK) $(iapi_h)
++	$(PSCCWIN) $(COMPILE_FOR_DLL) $(GLO_)gp_msdll.$(OBJ) $(C_) $(GLSRC)gp_msdll.c
++
++# end of gsdll.mak
+--- a/psi/winint.mak	2014-09-22 19:17:33.000000000 +0900
++++ b/psi/winint.mak	2015-03-14 01:28:28.351796400 +0900
+@@ -111,13 +111,7 @@
+  $(dwdll_h) $(iapi_h)
+ 	$(PSCCWIN) $(COMPILE_FOR_EXE) $(PSO_)dwnodll.obj $(C_) $(PSSRC)dwnodll.c
+ 
+-# Compile gsdll.c, the main program of the DLL.
+-
+-$(PSOBJ)gsdll.obj: $(PSSRC)gsdll.c $(AK) $(iapi_h) $(ghost_h)
+-	$(PSCCWIN) $(COMPILE_FOR_DLL) $(PSO_)gsdll.$(OBJ) $(C_) $(PSSRC)gsdll.c
+-
+-$(GLOBJ)gp_msdll.obj: $(GLSRC)gp_msdll.c $(AK) $(iapi_h)
+-	$(PSCCWIN) $(COMPILE_FOR_DLL) $(GLO_)gp_msdll.$(OBJ) $(C_) $(GLSRC)gp_msdll.c
++!include $(GLSRCDIR)\gsdll.mak
+ 
+ # Modules for console mode EXEs
+ 
+--- a/base/winlib.mak	2014-09-22 19:17:33.000000000 +0900
++++ b/base/winlib.mak	2015-03-14 01:40:33.017615400 +0900
+@@ -164,6 +164,7 @@
+ 
+ !include $(GLSRCDIR)\winplat.mak
+ !include $(GLSRCDIR)\pcwin.mak
++!include $(GLSRCDIR)\w32.mak
+ 
+ # Define abbreviations for the executable and DLL files.
+ GS_OBJ=$(GLOBJ)$(GS)
+@@ -176,108 +177,4 @@
+ $(gconfig__h): $(TOP_MAKEFILES)
+ 	$(ECHOGS_XE) -w $(gconfig__h) -x 2f2a20 This file deliberately left blank. -x 2a2f
+ 
+-# -------------------------------- Library -------------------------------- #
+-
+-# The Windows Win32 platform
+-
+-mswin32__=$(GLOBJ)gp_mswin.$(OBJ) $(GLOBJ)gp_wgetv.$(OBJ) $(GLOBJ)gp_wpapr.$(OBJ) \
+- $(GLOBJ)gp_stdia.$(OBJ) $(GLOBJ)gp_wutf8.$(OBJ)
+-mswin32_inc=$(GLD)nosync.dev $(GLD)winplat.dev
+-
+-$(GLGEN)mswin32_.dev:  $(mswin32__) $(ECHOGS_XE) $(mswin32_inc)
+-	$(SETMOD) $(GLGEN)mswin32_ $(mswin32__)
+-	$(ADDMOD) $(GLGEN)mswin32_ -include $(mswin32_inc)
+-
+-$(GLOBJ)gp_mswin.$(OBJ): $(GLSRC)gp_mswin.c $(AK) $(gp_mswin_h) \
+- $(ctype__h) $(dos__h) $(malloc__h) $(memory__h) $(pipe__h) \
+- $(stdio__h) $(string__h) $(windows__h) \
+- $(gx_h) $(gp_h) $(gpcheck_h) $(gpmisc_h) $(gserrors_h) $(gsexit_h)
+-	$(GLCCWIN) $(GLO_)gp_mswin.$(OBJ) $(C_) $(GLSRC)gp_mswin.c
+-
+-$(GLOBJ)gp_wutf8.$(OBJ): $(GLSRC)gp_wutf8.c $(windows__h)
+-	$(GLCCWIN) $(GLO_)gp_wutf8.$(OBJ) $(C_) $(GLSRC)gp_wutf8.c
+-
+-$(AUX)gp_wutf8.$(OBJ): $(GLSRC)gp_wutf8.c $(windows__h)
+-	$(GLCCAUX) $(AUXO_)gp_wutf8.$(OBJ) $(C_) $(GLSRC)gp_wutf8.c
+-
+-$(GLOBJ)gp_wgetv.$(OBJ): $(GLSRC)gp_wgetv.c $(AK) $(gscdefs_h)
+-	$(GLCCWIN) $(GLO_)gp_wgetv.$(OBJ) $(C_) $(GLSRC)gp_wgetv.c
+-
+-$(GLOBJ)gp_wpapr.$(OBJ): $(GLSRC)gp_wpapr.c $(AK) $(gp_h)
+-	$(GLCCWIN) $(GLO_)gp_wpapr.$(OBJ) $(C_) $(GLSRC)gp_wpapr.c
+-
+-$(GLOBJ)gp_stdia.$(OBJ): $(GLSRC)gp_stdia.c $(AK)\
+-  $(stdio__h) $(time__h) $(unistd__h) $(gx_h) $(gp_h)
+-	$(GLCCWIN) $(GLO_)gp_stdia.$(OBJ) $(C_) $(GLSRC)gp_stdia.c
+-
+-# The Metro platform
+-!ifdef METRO
+-METRO_OBJS=$(GLOBJ)winrtsup.$(OBJ) $(GLOBJ)gp_wutf8.$(OBJ)
+-
+-$(GLOBJ)winrtsup.$(OBJ): $(GLSRCDIR)/winrtsup.cpp
+-	$(GLCCWIN) /EHsc $(GLO_)winrtsup.$(OBJ) $(C_) $(GLSRCDIR)/winrtsup.cpp
+-!else
+-METRO_OBJS=
+-!endif
+-
+-
+-metro__=$(GLOBJ)gp_mswin.$(OBJ) $(GLOBJ)gp_wgetv.$(OBJ) $(GLOBJ)gp_wpapr.$(OBJ)\
+-  $(GLOBJ)gp_stdia.$(OBJ) $(METRO_OBJS)
+-#$(GLOBJ)gp_wutf8.$(OBJ)
+-metro_inc=$(GLD)nosync.dev $(GLD)winplat.dev
+-
+-$(GLGEN)metro_.dev:  $(metro__) $(ECHOGS_XE) $(metro_inc)
+-	$(SETMOD) $(GLGEN)metro_ $(metro__)
+-	$(ADDMOD) $(GLGEN)metro_ -include $(metro_inc)
+-
+-
+-# Define MS-Windows handles (file system) as a separable feature.
+-
+-mshandle_=$(GLOBJ)gp_mshdl.$(OBJ)
+-$(GLD)mshandle.dev: $(ECHOGS_XE) $(mshandle_)
+-	$(SETMOD) $(GLD)mshandle $(mshandle_)
+-	$(ADDMOD) $(GLD)mshandle -iodev handle
+-
+-$(GLOBJ)gp_mshdl.$(OBJ): $(GLSRC)gp_mshdl.c $(AK)\
+- $(ctype__h) $(errno__h) $(stdio__h) $(string__h)\
+- $(gsmemory_h) $(gstypes_h) $(gxiodev_h) $(gserrors_h)
+-	$(GLCC) $(GLO_)gp_mshdl.$(OBJ) $(C_) $(GLSRC)gp_mshdl.c
+-
+-# Define MS-Windows printer (file system) as a separable feature.
+-
+-msprinter_=$(GLOBJ)gp_msprn.$(OBJ)
+-msxpsprinter_=$(GLOBJ)xpsprint.$(OBJ)
+-
+-$(GLD)msprinter_0.dev: $(ECHOGS_XE) $(msprinter_)
+-	$(SETMOD) $(GLD)msprinter_0 $(msprinter_)
+-	$(ADDMOD) $(GLD)msprinter_0 -iodev printer
+-
+-$(GLD)msprinter_1.dev: $(ECHOGS_XE) $(msprinter_) $(msxpsprinter_) \
+- $(DD)xpswrite.dev
+-	$(SETMOD) $(GLD)msprinter_1 $(msprinter_) $(msxpsprinter_)
+-	$(ADDMOD) $(GLD)msprinter_1 -iodev printer
+-
+-$(GLD)msprinter.dev: $(GLD)msprinter_$(XPSPRINT).dev
+-	$(CP_) $(GLD)msprinter_$(XPSPRINT).dev $(GLD)msprinter.dev
+-
+-$(GLOBJ)gp_msprn.$(OBJ): $(GLSRC)gp_msprn.c $(AK)\
+- $(ctype__h) $(errno__h) $(stdio__h) $(string__h)\
+- $(gsmemory_h) $(gstypes_h) $(gxiodev_h)
+-	$(GLCCWIN) $(GLO_)gp_msprn.$(OBJ) $(C_) $(GLSRC)gp_msprn.c
+-
+-# The XPS printer
+-$(GLOBJ)xpsprint.$(OBJ): $(GLSRC)xpsprint.cpp $(windows__h) $(string__h) \
+- $(gx_h) $(gserrors_h)
+-	$(GLCCWINXPSPRINT) $(GLO_)xpsprint.$(OBJ) $(C_) $(GLSRC)xpsprint.cpp
+-
+-# Define MS-Windows polling as a separable feature
+-# because it is not needed by the gslib.
+-mspoll_=$(GLOBJ)gp_mspol.$(OBJ)
+-$(GLD)mspoll.dev: $(ECHOGS_XE) $(mspoll_)
+-	$(SETMOD) $(GLD)mspoll $(mspoll_)
+-
+-$(GLOBJ)gp_mspol.$(OBJ): $(GLSRC)gp_mspol.c $(AK)\
+- $(gx_h) $(gp_h) $(gpcheck_h)
+-	$(GLCCWIN) $(GLO_)gp_mspol.$(OBJ) $(C_) $(GLSRC)gp_mspol.c
+-
+ # end of winlib.mak
+--- /dev/null	2015-03-14 01:43:27.000000000 +0900
++++ b/base/w32.mak	2015-03-14 01:42:38.595935600 +0900
+@@ -0,0 +1,125 @@
++# Copyright (C) 2001-2012 Artifex Software, Inc.
++# All Rights Reserved.
++#
++# This software is provided AS-IS with no warranty, either express or
++# implied.
++#
++# This software is distributed under license and may not be copied,
++# modified or distributed except as expressly authorized under the terms
++# of the license contained in the file LICENSE in this distribution.
++#
++# Refer to licensing information at http://www.artifex.com or contact
++# Artifex Software, Inc.,  7 Mt. Lassen Drive - Suite A-134, San Rafael,
++# CA  94903, U.S.A., +1(415)492-9861, for further information.
++#
++# Common makefile section for 32-bit MS Windows.
++
++# This makefile must be acceptable to Microsoft Visual C++, Watcom C++,
++# and Borland C++.  For this reason, the only conditional directives
++# allowed are !if[n]def, !else, and !endif.
++
++# -------------------------------- Library -------------------------------- #
++
++# The Windows Win32 platform
++
++mswin32__=$(GLOBJ)gp_mswin.$(OBJ) $(GLOBJ)gp_wgetv.$(OBJ) $(GLOBJ)gp_wpapr.$(OBJ) \
++ $(GLOBJ)gp_stdia.$(OBJ) $(GLOBJ)gp_wutf8.$(OBJ)
++mswin32_inc=$(GLD)nosync.dev $(GLD)winplat.dev
++
++$(GLGEN)mswin32_.dev:  $(mswin32__) $(ECHOGS_XE) $(mswin32_inc)
++	$(SETMOD) $(GLGEN)mswin32_ $(mswin32__)
++	$(ADDMOD) $(GLGEN)mswin32_ -include $(mswin32_inc)
++
++$(GLOBJ)gp_mswin.$(OBJ): $(GLSRC)gp_mswin.c $(AK) $(gp_mswin_h) \
++ $(ctype__h) $(dos__h) $(malloc__h) $(memory__h) $(pipe__h) \
++ $(stdio__h) $(string__h) $(windows__h) \
++ $(gx_h) $(gp_h) $(gpcheck_h) $(gpmisc_h) $(gserrors_h) $(gsexit_h)
++	$(GLCCWIN) $(GLO_)gp_mswin.$(OBJ) $(C_) $(GLSRC)gp_mswin.c
++
++$(GLOBJ)gp_wutf8.$(OBJ): $(GLSRC)gp_wutf8.c $(windows__h)
++	$(GLCCWIN) $(GLO_)gp_wutf8.$(OBJ) $(C_) $(GLSRC)gp_wutf8.c
++
++$(AUX)gp_wutf8.$(OBJ): $(GLSRC)gp_wutf8.c $(windows__h)
++	$(GLCCAUX) $(AUXO_)gp_wutf8.$(OBJ) $(C_) $(GLSRC)gp_wutf8.c
++
++$(GLOBJ)gp_wgetv.$(OBJ): $(GLSRC)gp_wgetv.c $(AK) $(gscdefs_h)
++	$(GLCCWIN) $(GLO_)gp_wgetv.$(OBJ) $(C_) $(GLSRC)gp_wgetv.c
++
++$(GLOBJ)gp_wpapr.$(OBJ): $(GLSRC)gp_wpapr.c $(AK) $(gp_h)
++	$(GLCCWIN) $(GLO_)gp_wpapr.$(OBJ) $(C_) $(GLSRC)gp_wpapr.c
++
++$(GLOBJ)gp_stdia.$(OBJ): $(GLSRC)gp_stdia.c $(AK)\
++  $(stdio__h) $(time__h) $(unistd__h) $(gx_h) $(gp_h)
++	$(GLCCWIN) $(GLO_)gp_stdia.$(OBJ) $(C_) $(GLSRC)gp_stdia.c
++
++# The Metro platform
++#!ifdef METRO
++#METRO_OBJS=$(GLOBJ)winrtsup.$(OBJ) $(GLOBJ)gp_wutf8.$(OBJ)
++#
++#$(GLOBJ)winrtsup.$(OBJ): $(GLSRCDIR)/winrtsup.cpp
++#	$(GLCCWIN) /EHsc $(GLO_)winrtsup.$(OBJ) $(C_) $(GLSRCDIR)/winrtsup.cpp
++#!else
++METRO_OBJS=
++#!endif
++
++
++metro__=$(GLOBJ)gp_mswin.$(OBJ) $(GLOBJ)gp_wgetv.$(OBJ) $(GLOBJ)gp_wpapr.$(OBJ)\
++  $(GLOBJ)gp_stdia.$(OBJ) $(METRO_OBJS)
++#$(GLOBJ)gp_wutf8.$(OBJ)
++metro_inc=$(GLD)nosync.dev $(GLD)winplat.dev
++
++$(GLGEN)metro_.dev:  $(metro__) $(ECHOGS_XE) $(metro_inc)
++	$(SETMOD) $(GLGEN)metro_ $(metro__)
++	$(ADDMOD) $(GLGEN)metro_ -include $(metro_inc)
++
++
++# Define MS-Windows handles (file system) as a separable feature.
++
++mshandle_=$(GLOBJ)gp_mshdl.$(OBJ)
++$(GLD)mshandle.dev: $(ECHOGS_XE) $(mshandle_)
++	$(SETMOD) $(GLD)mshandle $(mshandle_)
++	$(ADDMOD) $(GLD)mshandle -iodev handle
++
++$(GLOBJ)gp_mshdl.$(OBJ): $(GLSRC)gp_mshdl.c $(AK)\
++ $(ctype__h) $(errno__h) $(stdio__h) $(string__h)\
++ $(gsmemory_h) $(gstypes_h) $(gxiodev_h) $(gserrors_h)
++	$(GLCC) $(GLO_)gp_mshdl.$(OBJ) $(C_) $(GLSRC)gp_mshdl.c
++
++# Define MS-Windows printer (file system) as a separable feature.
++
++msprinter_=$(GLOBJ)gp_msprn.$(OBJ)
++msxpsprinter_=$(GLOBJ)xpsprint.$(OBJ)
++
++$(GLD)msprinter_0.dev: $(ECHOGS_XE) $(msprinter_)
++	$(SETMOD) $(GLD)msprinter_0 $(msprinter_)
++	$(ADDMOD) $(GLD)msprinter_0 -iodev printer
++
++$(GLD)msprinter_1.dev: $(ECHOGS_XE) $(msprinter_) $(msxpsprinter_) \
++ $(DD)xpswrite.dev
++	$(SETMOD) $(GLD)msprinter_1 $(msprinter_) $(msxpsprinter_)
++	$(ADDMOD) $(GLD)msprinter_1 -iodev printer
++
++$(GLD)msprinter.dev: $(GLD)msprinter_$(XPSPRINT).dev
++	$(CP_) $(GLD)msprinter_$(XPSPRINT).dev $(GLD)msprinter.dev
++
++$(GLOBJ)gp_msprn.$(OBJ): $(GLSRC)gp_msprn.c $(AK)\
++ $(ctype__h) $(errno__h) $(stdio__h) $(string__h)\
++ $(gsmemory_h) $(gstypes_h) $(gxiodev_h)
++	$(GLCCWIN) $(GLO_)gp_msprn.$(OBJ) $(C_) $(GLSRC)gp_msprn.c
++
++# The XPS printer
++$(GLOBJ)xpsprint.$(OBJ): $(GLSRC)xpsprint.cpp $(windows__h) $(string__h) \
++ $(gx_h) $(gserrors_h)
++	$(GLCCWINXPSPRINT) $(GLO_)xpsprint.$(OBJ) $(C_) $(GLSRC)xpsprint.cpp
++
++# Define MS-Windows polling as a separable feature
++# because it is not needed by the gslib.
++mspoll_=$(GLOBJ)gp_mspol.$(OBJ)
++$(GLD)mspoll.dev: $(ECHOGS_XE) $(mspoll_)
++	$(SETMOD) $(GLD)mspoll $(mspoll_)
++
++$(GLOBJ)gp_mspol.$(OBJ): $(GLSRC)gp_mspol.c $(AK)\
++ $(gx_h) $(gp_h) $(gpcheck_h)
++	$(GLCCWIN) $(GLO_)gp_mspol.$(OBJ) $(C_) $(GLSRC)gp_mspol.c
++
++# end of w32.mak
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/patches/ghostscript-9.15-windows-popen.patch	Mon Apr 06 15:42:12 2015 +0100
@@ -0,0 +1,11 @@
+--- a/base/gp_mswin.c	2015-03-11 21:10:32.833047100 +0900
++++ b/base/gp_mswin.c	2015-03-14 10:38:12.873730900 +0900
+@@ -145,7 +145,7 @@
+                                      win_prntmp, "wb");
+         return pfile;
+     } else if (fname[0] == '|') 	/* pipe */
+-        return mswin_popen(fname + 1, (binary_mode ? "wb" : "w"));
++        return popen(fname + 1, (binary_mode ? "wb" : "w"));
+     else if (strcmp(fname, "LPT1:") == 0)
+         return NULL;	/* not supported, use %printer%name instead  */
+     else
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/patches/ghostscript-9.15-windows-snprintf.patch	Mon Apr 06 15:42:12 2015 +0100
@@ -0,0 +1,15 @@
+--- a/base/gp_mswin.c	2014-09-22 19:17:33.000000000 +0900
++++ b/base/gp_mswin.c	2015-03-11 21:10:32.833047100 +0900
+@@ -900,6 +900,7 @@
+ /* Microsoft Visual C++ 2005  doesn't properly define snprintf,
+    which is defined in the C standard ISO/IEC 9899:1999 (E) */
+ 
++#if !defined(__CYGWIN__) && !defined(__MINGW32__)
+ int snprintf(char *buffer, size_t count, const char *format, ...)
+ {
+     if (count > 0) {
+@@ -914,3 +915,4 @@
+     } else
+         return 0;
+ }
++#endif