Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 319 lines (297 sloc) 13.616 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318
import re
#
from gub.syntax import printf
from gub import context
from gub import misc
from gub import repository
from gub import target
from gub import tools

shared = True

class Ghostscript_static (target.AutoBuild):
    '''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
PostScript files as graphics to be printed on non-PostScript printers.
Supported printers include common dot-matrix, inkjet and laser
models.'''

    #source = 'svn:http://svn.ghostscript.com:8080/ghostscript&branch=trunk/gs&revision=7881'
    # HEAD - need to load TTF fonts on fedora without crashing.
    exe = ''
    revision = 'b35333cf3579e85725bd7d8d39eacc9640515eb8'
    #source = 'git://git.infradead.org/ghostscript.git?branch=refs/remotes/git-svn&revision=' + revision
    source = 'http://mirror2.cs.wisc.edu/pub/mirrors/ghost/GPL/gs870/ghostscript-8.70.tar.gz'
    patches = [
        'ghostscript-8.70-make.patch',
        ]
    parallel_build_broken = True
    # For --enable-compile-inits, see comment in compile()
    configure_flags = (target.AutoBuild.configure_flags
                       + misc.join_lines ('''
--enable-debug
--with-drivers=FILES
--without-pdftoraster
--disable-fontconfig
--disable-gtk
--disable-cairo
--without-x
--disable-cups
--without-ijs
--without-omni
--without-jasper
--disable-compile-inits
'''))
    compile_flags = (' INCLUDE=%(system_prefix)s/include'
                     + ' PSDOCDIR=%(prefix_dir)s/share/doc'
                     + ' PSMANDIR=%(prefix_dir)s/share/man'
                     + r''' XLDFLAGS='%(rpath)s' ''')
    install_command = (target.AutoBuild.install_command
                + ' install_prefix=%(install_root)s'
                + ' mandir=%(prefix_dir)s/share/man/ '
                + ' docdir=%(prefix_dir)s/share/doc/ghostscript/doc '
                + ' exdir=%(prefix_dir)s/share/doc/ghostscript/examples ')
    # Ghostscript's check for sys/time.h is buggy: it only looks in /usr/include.
    make_flags = target.AutoBuild.make_flags + ' TARGET=%(target_os)s CFLAGS+="-DHAVE_SYS_TIME_H=1"'
    obj = 'obj'
    @staticmethod
    def static_version ():
        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)
    @staticmethod
    def version_from_VERSION (self):
        try:
            s = self.read_file ('base/version.mak')
            if not 'GS_VERSION_MAJOR' in s:
                urg
            d = misc.grok_sh_variables_str (s)
            return '%(GS_VERSION_MAJOR)s.%(GS_VERSION_MINOR)s' % d
        except:
            pass
        return '0.0'
    dependencies = ['libjpeg-devel', 'libpng-devel']
    subpackage_names = ['doc', '']
    def srcdir (self):
        return re.sub ('-source', '',
                       target.AutoBuild.srcdir (self))
    def builddir (self):
        return re.sub ('-source', '',
                       target.AutoBuild.builddir (self))
    def name (self):
        return 'ghostscript'
    def autoupdate (self):
        # generate Makefile.in
        self.system ('cd %(srcdir)s && sh ./autogen.sh --help')
        disable_re = ('(DEVICE_DEVS[0-9]+)=([^\n]+(%s))'
                      % '|'.join (['tiff', 'pcx', 'uniprint',
                                   'deskjet', 'djet500', 'bmp', 'pbm',
                                   'bjc200', 'cdeskjet', 'faxg3', 'cljet5']))
        self.file_sub ([(disable_re, r'#\1= -DISABLED- \2 ')],
                       '%(srcdir)s/Makefile.in')
    def fixup_arch (self):
        # FIXME: wow, this is broken, cross-compile-wise. Use a compiled
        # c program to determine the size of basic types *after* an
        # autoconf run. Should see if afpl ghostscript also uses autoconf
        # and send a patch that generates arch.h from configure.

        cache_size = 1024*1024
        big_endian = 0
        can_shift = 1
        align_long_mod = 4
        align_ptr_mod = 4
        log2_sizeof_long = 2
        sizeof_ptr = 4
        
        if 'powerpc' in self.settings.target_architecture:
            big_endian = 1
            can_shift = 1
            cache_size = 2097152
        elif re.search ('i[0-9]86', self.settings.target_architecture):
            big_endian = 0
            can_shift = 0
            cache_size = 1048576

        if '64' in self.settings.target_architecture:
            align_long_mod = 8
            align_ptr_mod = 8
            log2_sizeof_long = 3
            sizeof_ptr = 8

        # obsolete
        self.file_sub (
            [('#define ARCH_CAN_SHIFT_FULL_LONG .',
              '#define ARCH_CAN_SHIFT_FULL_LONG %(can_shift)d' % locals ()),
             ('#define ARCH_CACHE1_SIZE [0-9]+',
              '#define ARCH_CACHE1_SIZE %(cache_size)d' % locals ()),
             ], '%(builddir)s/%(obj)s/arch.h')
        
        # cannot use: must_succeed=5, they may be okay..
        self.file_sub ([
             ('#define ARCH_IS_BIG_ENDIAN [0-9]',
              '#define ARCH_IS_BIG_ENDIAN %(big_endian)d' % locals ()),
             ('#define ARCH_ALIGN_LONG_MOD [0-9]',
              '#define ARCH_ALIGN_LONG_MOD %(align_long_mod)d' % locals ()),
             ('#define ARCH_ALIGN_PTR_MOD [0-9]',
              '#define ARCH_ALIGN_PTR_MOD %(align_ptr_mod)d' % locals ()),
             ('#define ARCH_LOG2_SIZEOF_LONG [0-9]',
              '#define ARCH_LOG2_SIZEOF_LONG %(log2_sizeof_long)d' % locals ()),
             ('#define ARCH_SIZEOF_PTR [0-9]',
              '#define ARCH_SIZEOF_PTR %(sizeof_ptr)d' % locals ()),
             ], '%(builddir)s/%(obj)s/arch.h')

    def configure (self):
        target.AutoBuild.configure (self)
        self.makefile_fixup ('%(builddir)s/Makefile')
    def makefile_fixup (self, file):
        self.file_sub ([
            ('-Dmalloc=rpl_malloc', ''),
            ('GLSRCDIR=./base', 'GLSRCDIR=%(srcdir)s/base'),
            ('PSSRCDIR=./psi', 'PSSRCDIR=%(srcdir)s/psi'),
            ('PSLIBDIR=./lib', 'PSLIBDIR=%(srcdir)s/lib'),
            ('PSRESDIR=./Resource', 'PSRESDIR=%(srcdir)s/Resource'),
            ('ICCSRCDIR=icclib', 'ICCSRCDIR=%(srcdir)s/icclib'),
            ('IJSSRCDIR=src', 'IJSSRCDIR=%(srcdir)s/src'),
            ('IMDISRCDIR=imdi', 'IMDISRCDIR=%(srcdir)s/imdi'),
            ('CONTRIBDIR=./contrib', 'CONTRIBDIR=%(srcdir)s/contrib'),
            ('include contrib/', 'include %(srcdir)s/contrib/'),
            # ESP-specific: addonsdir, omit zillion of
            # warnings (any important ones may be noticed
            # easier).
            ('ADDONSDIR=./addons', 'ADDONSDIR=%(srcdir)s/addons'),
            (' -Wmissing-prototypes ', ' '),
            (' -Wstrict-prototypes ', ' '),
            (' -Wmissing-declarations ', ' '),

            ## ugh: GS compile adds another layer of shell expansion. Yuck.
            (r'\$\${ORIGIN}', '\\$${ORIGIN}'),
            ],
               file)

    def compile (self):
        # 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
''')
        self.fixup_arch ()
        target.AutoBuild.compile (self)

    def install (self):
        target.AutoBuild.install (self)
        self.system ('mkdir -p %(install_prefix)s/etc/relocate')
        self.dump ('''
prependdir GS_FONTPATH=$INSTALLER_PREFIX/share/ghostscript/%(version)s/fonts
prependdir GS_FONTPATH=$INSTALLER_PREFIX/share/gs/fonts
prependdir GS_LIB=$INSTALLER_PREFIX/share/ghostscript/%(version)s/Resource
prependdir GS_LIB=$INSTALLER_PREFIX/share/ghostscript/%(version)s/Resource/Init
''', '%(install_prefix)s/etc/relocate/gs.reloc')

class Ghostscript_shared (Ghostscript_static):
    configure_flags = (Ghostscript_static.configure_flags
                       .replace ('--disable-static', '--enable-dynamic'))
    obj = 'soobj'
    compile_flags = Ghostscript_static.compile_flags + ' so'
    install_flags = (Ghostscript_static.install_flags
                     .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')

if shared:
    Ghostscript = Ghostscript_shared
else:
    Ghostscript = Ghostscript_static
    
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',
        ]
    def __init__ (self, settings, source):
        Ghostscript.__init__ (self, settings, source)
        # Configure (compile) without -mwindows for console
        # FIXME: should add to CPPFLAGS...
        #self.target_gcc_flags = '-mms-bitfields -D_Windows -D__WINDOWS__'
        # We certainly do not want gs.exe to open a dos box
        # We can also compile an gs-console.exe some day
        self.target_gcc_flags = '-mwindows -mms-bitfields -D_Windows -D__WINDOWS__'
    config_cache_overrides = Ghostscript.config_cache_overrides + '''
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 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'),
                            ('^(EXTRALIBS *=.*)(-rdynamic )', r'\1')],
                           '%(builddir)s/Makefile')
        self.file_sub ([('^(EXTRALIBS *=.*)', r'\1 -lwinspool -lcomdlg32 -lz')],
                       '%(builddir)s/Makefile')
        self.file_sub ([('^unix__=.*', misc.join_lines ('''unix__=
$(GLOBJ)gp_mswin.$(OBJ)
$(GLOBJ)gp_wgetv.$(OBJ)
$(GLOBJ)gp_stdia.$(OBJ)
$(GLOBJ)gp_ntfs.$(OBJ)
$(GLOBJ)gp_win32.$(OBJ)
$(GLOBJ)gp_upapr.$(OBJ)
'''))],
               '%(srcdir)s/base/unix-aux.mak')
        self.dump ('''
GLCCWIN=$(CC) $(CFLAGS) -I$(GLOBJDIR)
PSCCWIN=$(CC) $(CFLAGS) -I$(GLOBJDIR)

include $(GLSRCDIR)/w32.mak
include $(GLSRCDIR)/gsdll.mak
include $(GLSRCDIR)/winplat.mak
include $(GLSRCDIR)/pcwin.mak
''',
             '%(builddir)s/Makefile',
             mode='a')
    def install (self):
        Ghostscript.install (self)
        if shared:
            self.system ('mv %(install_prefix)s/lib/*dll %(install_prefix)s/bin')

class Ghostscript__freebsd (Ghostscript):
    dependencies = Ghostscript.dependencies + ['libiconv-devel']
    def configure (self):
        Ghostscript.configure (self)
        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):
    def configure (self):
        Ghostscript.configure (self)
        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'),
                            ('^(EXTRALIBS *=.*)(-rdynamic )', r'\1 -dynamic'),
                            ('^(EXTRALIBS *=.*)(-shared )', r'\1 -dynamic'),
                            ('^(CC_SHARED *=.*)( -shared)', r'\1 -dynamic')],
                           '%(builddir)s/Makefile')

class Ghostscript__tools (tools.AutoBuild, Ghostscript_static):
    parallel_build_broken = True
    dependencies = ['libjpeg', 'libpng']
    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')
    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 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
''')
# self.fixup_arch ()
        tools.AutoBuild.compile (self)
    install_command = (tools.AutoBuild.install_command
                + ' install_prefix=%(install_root)s'
                + ' mandir=%(prefix_dir)s/share/man/ '
                + ' docdir=%(prefix_dir)s/share/doc/ghostscript/doc '
                + ' exdir=%(prefix_dir)s/share/doc/ghostscript/examples '
                )

def test ():
    printf ('Ghostscript.static_version:', Ghostscript.static_version ())

if __name__ =='__main__':
    test ()
Something went wrong with that request. Please try again.