How to build Ghostscript from source code

## Table of contents

> - General overview
> - How to acquire the source code
>   - Ghostscript source code
>   - Third-party library source code
> - How to unpack the source code
>   - How to unpack compressed tar files generally
>   - How to unpack zip files generally
>   - How to unpack Ghostscript itself
>   - How to unpack the third-party libraries
> - How to check for post-release bug fixes
> - How to prepare the makefiles
>   - Changes for your environment
>   - Selecting features and devices
>     - LZW compression
>   - Setting up "makefile"
>   - Invoking "make"
>   - Cross-compiling
> - How to build Ghostscript from source (PC version)
>   - Borland environment
>   - Microsoft environment
>   - Watcom environment
>   - Cygwin32 gcc
> - How to build Ghostscript from source (Mac version)
> - How to build Ghostscript from source (Unix version)
>   - Setting up "makefile"
>   - Unix build problems (and solutions)
>     - gcc 2.7.*
>     - GNU make
>     - 386 Unix
>     - Alpha with gcc
>     - H-P Apollo
>     - AT&T 7040 R3
>     - Convex
>     - DECStations with Ultrix
>     - Digital Unix (Alpha)
>     - H-P RISC workstations
>     - Intergraph Clipper
>     - Linux
>     - MIPS
>     - NCR 3550
>     - NeXTSTEP
>     - Pyramid MIServer-S
>     - IBM RS/6000
>     - SCO Unix/Xenix
>     - Silicon Graphics
>     - Sun
>       - SunOS
>       - Solaris
>     - SVR4 Unix
>     - System V Unix platforms
>     - Unixware
>     - VAX with Ultrix
> - How to build Ghostscript from source (OS/2 version)
> - How to build Ghostscript from source (VMS version)
>   - Building with GNU make on OpenVMS
> - Other environments
>   - Plan 9
>   - QNX

For other information, see the Ghostscript overview and the instructions on how to install Ghostscript.

# General overview

This document describes how to build a Ghostscript executable from source code. There are four major steps to building Ghostscript:

1. Acquire the compressed archive files of source code for Ghostscript and the required third-party libraries.
2. Unpack the archive files into the Ghostscript directory and correctly named subdirectories.
3. Prepare the makefiles, including specific changes for your operating environment and your choice of configuration options.
4. Invoke "`make`" to build the software.

The remainder of this document describes each of these steps in detail. Note that some of this process is platform-dependent. After building Ghostscript you must then install it; for that, see the installation instructions.

# How to acquire the source code

Building Ghostscript requires the Ghostscript source code itself, and also the source code for some third-party libraries that Ghostscript uses.

## Ghostscript source code

There are two kinds of Ghostscript distributions available, called "Aladdin Ghostscript" and "GNU Ghostscript"; the distinction between them is explained in the conditions for distributing Ghostscript. The authoritative distribution site for Aladdin Ghostscript is

> ftp://ftp.cs.wisc.edu/ghost/aladdin/gs###

where "###" is the unpunctuated version number. GNU Ghostscript should be available on all GNU sites, such as

> ftp://ftp.gnu.org/pub/gnu/

Ghostscript source code is packaged in two different formats: gzip-compressed tar files (*`.tar.gz`) and zip files (*`.zip`). For all versions there are gzip-compressed tar files:

> `ghostscript-`#.##`.tar.gz`
> `ghostscript-fonts-std-`#.##`.tar.gz`
> `ghostscript-fonts-other-`#.##`.tar.gz`

For recent versions of Aladdin Ghostscript -- not GNU Ghostscript -- there are also zip files (each zipped file fits onto a single 1.44MB diskette):

> `gs`###`fn`*`.zip`
> `gs`###`sr`*`.zip`

("#.##" and "###" are version numbers in punctuated and unpunctuated form.) Software to decompress and extract both formats is available for almost every platform for which Ghostscript is available -- including Unix, DOS, MS Windows, and VMS -- so you can choose the format most convenient for you; but it's up to you to locate that software. See the section on unpacking the source code.

## Third-party library source code

To build Ghostscript you need the source code for the Independent JPEG Group (IJG) library, the Portable Network Graphics (PNG) library, and the zlib compression and decompression library. Here are authoritative distribution points for these libraries, where as elsewhere, "#" is used for version numbers. The JPEG source code is quite stable, so the reference here includes the latest version number. The zlib references are version-independent and should always provide the latest version.

> Third-party libraries: authoritative sources
> JPEG |  | ftp://ftp.uu.net/graphics/jpeg/jpegsrc.v6b.tar.gz ftp://ftp.simtel.net/pub/simtelnet/msdos/graphics/jpegsr6b.zip
> PNG |  | ftp://swrinde.nde.swri.edu/pub/png/src/libpng-#.#.#.tar.gz ftp://swrinde.nde.swri.edu/pub/png/src/lpng###.zip http://www.cdrom.com/pub/png/src/libpng-#.#.#.tar.gz http://www.cdrom.com/pub/png/src/lpng###.zip
> zlib (latest) |  | ftp://ftp.cdrom.com/pub/infozip/zlib/zlib.tar.gz ftp://ftp.cdrom.com/pub/infozip/zlib/zlib.zip http://www.cdrom.com/pub/infozip/zlib/zlib.tar.gz http://www.cdrom.com/pub/infozip/zlib/zlib.zip

On DOS or MS Windows one ordinarily uses the zip file kits, in other environments the compressed tar files, but this is simply a matter of convenience, since for the same version of the software the compressed tar file has the same contents as the zip file. Note that each of these libraries has its own version number that has nothing to do with Ghostscript's version number; you should get the highest numbered version. (If you encounter difficulties in the build process you might have to use a lower-numbered version, but don't worry about this yet.) If you're running Linux, you might check whether these libraries are already available in source form on your system, since many Linux distributors include them; but we advise you to get the highest version from the Net if you can.

Although the zip archives of an old version of the PNG library may not be named `lpng`###`.zip`, we refer to it as `lpng`###`.zip`.

# How to unpack the source code

Unfortunately there are no generally accepted standards for how to package source code into archives, so the instructions for unpacking Ghostscript are longer than they should be. We begin with a brief explanation of how to extract the two kinds of archive files.

## How to unpack compressed tar files generally

Tar (`.tar`) files are the de facto standard for archiving files on Unix (every Unix system has the `tar` program), and programs to extract their contents are also widely available for DOS, MS Windows, and VMS. To economize on space and downloading time, Ghostscript's tar files are compressed with GNU `gzip`, which adds the suffix "`.gz`" to the file name, giving "`.tar.gz`".

To unpack a compressed tar file `MyArchive.tar.gz` you must both decompress it and extract the contents. You can do this in two steps, one to decompress the file and another to unpack it:

> `gzip -d MyArchive.tar.gz`
> `tar -xf MyArchive.tar`

or in a pipeline:

> `gzip -d -c MyArchive.tar.gz | tar -xf -`

or, if you have a program like GNU `tar` that can handle compressed tar files, with a single command:

> `tar -zxf MyArchive.tar.gz`

The `tar` program automatically preserves directory structure in extracting files. The Ghostscript source archive puts all files under a directory `gs`#.##, so using `tar` to unpack a compressed archive should always properly create that directory, which we will call the "gs directory". Make sure you're positioned in the parent of the gs directory before unpacking the files. If a subdirectory doesn't already exist, `tar` creates it.

Some other programs -- under MS Windows, for instance -- can also unpack compressed tar files, but they may not automatically preserve directory structure nor even extract files into the current directory. If you use one of these, you must

- set the program's options to "Use folder names" or the equivalent, and
- check that it is extracting files into the right place.

## How to unpack zip files generally

Zip files are the de facto standard for archiving files on DOS and MS Windows, and programs to extract their contents are widely available for DOS, MS Windows, Unix, VMS, and other platforms. Zip files are at once an archive format and a compressed format, so an unzipping program decompresses and extracts archived files as a single step.

One common 16-bit DOS program is `pkunzip`, which comes in the `pkzip` package. If you use this, you should ensure that you have at least version 2.04g, because with its `-d` switch, that version of `pkunzip` preserves the directory structure of archived files when extracting them; see below. Another popular free program to unpack zip archives, available for DOS and MS Windows (16-bit and 32-bit), Unix, VMS, and other platforms, is InfoZIP `unzip`:

> http://www.cdrom.com/pub/infozip/UnZip.html

Unlike `pkunzip`, InfoZIP `unzip` automatically preserves the directory structure of extracted files. So if you have a zip archive `MyArchive.zip`:

> Extracting zipped files
> Command |  | Preserves directory structure
> `pkunzip MyArchive.zip` |  | Does NOT
> `pkunzip -d MyArchive.zip` |  | DOES (note the `-d` switch)
> `unzip MyArchive.zip` |  | DOES

As with the compressed tar files, make sure you're positioned in the parent of the gs directory before unpacking the files. If a subdirectory doesn't already exist, `zip` or `pkunzip -d` creates it.

## How to unpack Ghostscript itself

At this point you have acquired all the source code and are ready to unpack it according to the preceding guidelines for tar files or zip files. To unpack the Ghostscript source, make the parent of the (new) gs directory the current directory, then unpack the archive using one of these methods:

> 2-step: |  | `gzip -d ghostscript-`#.##`.tar.gz` `tar -xf ghostscript-`#.##`.tar`
> Pipe: |  | `gzip -d -c ghostscript-`#.##`.tar.gz | tar -xf -`
> GNU `tar`: |  | `tar -zxf ghostscript-`#.##`.tar.gz`
> `pkunzip`: |  | `pkunzip -d gs`###`sr1.zip` `pkunzip -d gs`###`sr2.zip` ...
> `unzip`: |  | `unzip gs`###`sr*.zip`

All the Ghostscript source files are now in the gs directory `./gs`#.##.

## How to unpack the third-party libraries

The Ghostscript makefiles expect to find the JPEG, PNG, and zlib source code in specific subdirectories of the gs directory, and this means you must pay careful attention to unpacking the source code for these packages. Use the same method for all of them, no matter how they're packaged:

1. Make the gs directory current
2. Unpack the archive file, creating a subdirectory (which will include a version number)
3. Whatever the subdirectory's original name, rename it to the versionless name show just below.

If you're uncertain how to unpack an archive, review the sections on compressed tar files and zip files.

> 3d-party software subdirectories
> Package |  | Possible original name |  | Rename to
> JPEG |  | `./jpeg-6b` |  | `./jpeg`
> PNG |  | `./libpng-`#.## |  | `./libpng`
> zlib |  | `./zlib-`#.#.# |  | `./zlib`

# How to check for post-release bug fixes

Before making any changes for your particular environment, check the post-release "known bugs" notice at

> http://www.cs.wisc.edu/~ghost/aladdin/relnotes/gs###/index.html

where "###" is the unpunctuated version number of Ghostscript's latest release. The page lists bugs known in the latest release, and also gives workarounds and patches where available. Apply the patches before building Ghostscript.

# How to prepare the makefiles

The Ghostscript makefiles are very large and complex in order to deal with the diverse requirements of all the different systems where they may be used. Fortunately, the only makefiles you're likely to want to change are relatively small ones containing platform-specific information.

> Platform-specific makefiles
> Makefile |  | Used for
> `bcwin32.mak` |  | MS Windows with Borland compilers
> `msvc32.mak` |  | MS Windows with Microsoft Visual C++ version 4.n or 5.n
> `openvms.mak` |  | OpenVMS
> `os2.mak` |  | OS/2 with the gcc/emx compiler
> `unix-cc.mak` |  | Unix with "traditional C" compilers
> `unix-gcc.mak` |  | Unix with gcc
> `unixansi.mak` |  | Unix with ANSI C compilers other than gcc
> `watc.mak` |  | DOS with Watcom compilers
> `watcw32.mak` |  | MS Windows with Watcom compilers
> Platform-independent makefiles
> `contrib.mak` |  | Contributed device drivers
> `devs.mak` |  | Aladdin's device drivers
> `gs.mak` |  | Documentation and miscellany
> `int.mak` |  | Main makefile for the PostScript & PDF interpreter
> `jpeg.mak` |  | JPEG library
> `lib.mak` |  | Graphics engine
> `libpng.mak` |  | PNG library
> `version.mak` |  | Version and release date
> `zlib.mak` |  | zlib library

Since these files change from one Ghostscript version to another, sometimes substantially, and since they all include documentation for the various options, here we don't duplicate most of that documentation: we recommend strongly that you review the entire makefile specific for your operating system and compiler before building Ghostscript.

## Changes for your environment

You must edit the platform-specific makefile to change any of these:

- The name of the makefile itself (`MAKEFILE` macro)
- The locations to install Ghostscript files (`prefix` etc.)
- The default search paths for the initialization and font files (`GS_LIB_DEFAULT` macro)
- The debugging options (`DEBUG` and `TDEBUG` macros)
- Which optional features to include (`FEATURE_DEVS`)
- Which device drivers to include (`DEVICE_DEVS` and `DEVICE_DEVS`{1--15} macros)
- Default resolution parameters for a dot-matrix printer driver (`devs.mak` or `contrib.mak`, whichever defines the driver)

The platform-specific makefiles include comments describing all these except the `DEVICE_DEVS` options. These are described in `devs.mak` and `contrib.mak`, even though the file that must be edited to select them is the platform-specific makefile. Check also the `JVERSION` and `PVERSION` macros in the platform-specific makefile, and adjust them if they don't match the JPEG and PNG library versions you're using: see `jpeg.mak` and `libpng.mak` for more information.

Some platform-specific options are described in the sections for individual platforms. See the "Options" section near the beginning of the relevant makefile for more information.

## Selecting features and devices

You may build Ghostscript with any of a variety of features and with any subset of the available device drivers. The complete list of features is in a comment at the beginning of `gs.mak`, and the complete list of drivers in comments at the beginning of `devs.mak` and `contrib.mak`. To find what devices a platform-specific makefile selects to include in the executable, look in it for all lines of the form

> `FEATURE_DEVS=`{list of features}
> `DEVICE_DEVS`*`=`{list of devices}

For example, if the makefile has

> `FEATURE_DEVS=level2.dev`

indicating that only the PostScript Level 2 facilities should be included, you might make it

> `FEATURE_DEVS=level2.dev pdf.dev`

to add the ability to interpret PDF files. (In fact, `FEATURE_DEVS` in the current Unix makefiles already includes `pdf.dev`.) The Unix makefile also defines

> `DEVICE_DEVS=x11.dev`

indicating that the X Windows driver should be included, but since platform-specific makefiles as distributed normally include many of the possible features and drivers, you will probably rather remove from the makefile the features and drivers you don't want. It does no harm to include unneeded features and devices, but the resulting executable will be larger than needed.

You may edit the `FEATURE`* lines to select or omit any of the features listed near the beginning of `gs.mak`, and the `DEVICE_DEVS`* lines to select or omit any of the device drivers listed near the beginning of `devs.mak` and `contrib.mak`. The first device listed in the definition of `DEVICE_DEVS` becomes the default device for this executable; see the usage documentation for how to select an output device at run time using the `-sDEVICE=` switch. If you can't fit all the devices on a single line, you may add lines defining

> `DEVICE_DEVS1=`{dev11}`.dev` ... {dev1n}`.dev`
> `DEVICE_DEVS2=`{dev21}`.dev` ... {dev2n}`.dev`

etc. up to `DEVICE_DEVS15`. Don't use continuation lines -- on some platforms they don't work.

### LZW compression

It is possible to substitute an LZW compressor for the LZW-compatible encoder provided with the standard fileset, by finding two lines in `lib.mak`

> `lzwe_=slzwce.$(OBJ) slzwc.$(OBJ)
> #lzwe_=slzwe.$(OBJ) slzwc.$(OBJ)`

and changing them to

> `#lzwe_=slzwce.$(OBJ) slzwc.$(OBJ)
> lzwe_=slzwe.$(OBJ) slzwc.$(OB)`

If you do this, you are responsible for constructing or obtaining a file `slzwe.c` that implements LZW compression; no such file is included in any current standard Ghostscript distribution, although you may be able to find one in distributions that predate Unisys's amnesty cutoff of January 1, 1995. You are also responsible for drawing your own conclusions about the applicability to LZW compression code of patents held by Unisys and IBM, and for obtaining any licenses you believe to be relevant.

## Setting up "makefile"

After you make all your changes, as the final step in preparing to build Ghostscript you must usually associate the name "`makefile`" with the correct makefile for your environment so the `make` command can find it. See the section on your particular platform for how to do that if necessary.

## Invoking "make"

`make`
  Builds Ghostscript without debugging options.

`make debug`
  Builds Ghostscript with debugging options and additional internal error checks. The program will be somewhat larger and slower, but it will behave no differently unless you actually turn on debugging options at execution time with the `-DDEBUG` or `-Z` command line switches described in the usage documentation.

`make begin`
  On PC platforms, attempts a quick and dirty compilation of all the `.c` files in the current directory. See the more detailed explanation.

`make install`
  After building, installs the Ghostscript executables, support files, and documentation, but does not install fonts. See the installation documentation.

`make clean`
  Deletes all the files created by the build process (relocatables, executables, and miscellaneous temporary files). If you've built an executable and want to save it, move it first to another place, because "`make clean`" deletes it.

Note: on most platforms some of these simple instructions don't quite work in one way or another. Read the section on your specific platform.

## Cross-compiling

If you are compiling Ghostscript on machine X with a cross-compiler that generates code for machine Y, an extra phase is needed:

> 1. `make arch.h`
> 2. Edit `arch.h` to reflect the architecture of machine Y.
> 3. Finally make the executable.

# How to build Ghostscript from source (PC version)

The relevant makefiles are

> PC makefiles
> Makefile |  | Construction tools |  | For environment
> `bcwin32.mak` |  | Borland C++ 4.x |  | 32-bit MS Windows 3.1 + Win32s, 95, NT
> `msvc32.mak` |  | Microsoft Visual C++ 4.x or 5.x |  | MS Windows32-bit
> `watc.mak` |  | Watcom C/386 or C++ |  | MS-DOS 32-bit (extended)
> `watcw32.mak` |  | Watcom C/386 or C++ |  | MS Windows 32-bit (DOESN'T WORK YET)
> `unix-gcc.mak` |  | Cygnus gcc |  | Cygnus gnu-win32

To build Ghostscript you need MS-DOS version 3.3 or later and Borland C/C++ (4.0 or later); Microsoft Visual C++ (version 4.0 or later); Watcom C/386 (version 8.5 or later) or C++ (any version); or the free djgpp + go32 development system. The options in the makefiles were chosen to strike a balance between RAM consumption and likely usefulness. The default configuration generates an executable that assumes the directory where `make` was run as the final default directory for looking up the Ghostscript initialization and font files.

You must have `COMMAND.COM` in your path to build Ghostscript. After making the changes needed to choose features and devices to build into the executable, to build the Ghostscript executable all you need do is give the `make` command.

A special make target "`begin`" attempts to compile all the `.c` files in the current directory. Some of these compilations will fail, but the ones that succeed will go considerably faster because they don't individually pay the overhead of starting up the compiler. So a good strategy for building the executable for the first time, or after changing a widely used `.h` file, is to do the fast compilation of everything possible, then the controlled compilation of everything that failed in the first step:

> `make begin
> make`

Note: if you unpack the Ghostscript sources on a DOS or MS Windows system from a Unix tar file, the unpacked files have linefeed alone as the line terminator (the Unix convention) instead of carriage return + linefeed (the Microsoft convention), which may make the C compiler unhappy. One simple way to fix this, if you have the InfoZIP `zip` and `unzip` programs, is

> `zip -l CVTEMP.zip *.bat *.c *.h` |  | (Letter "l", not the digit "1")
> `unzip -o CVTEMP.zip` |  | (Rewrite all the same files correctly)
> `del CVTEMP.zip` |  | (Delete the temporary zip file)

## Borland environment

To compile Ghostscript with the Borland environment, you need Borland C++ (version 4.0 or later); specifically the compiler, `make` utility, and linker. You also need either the Borland assembler (version 1.0 or later) or the Microsoft assembler (version 4.0 or later).

To create "`makefile`", give the command

> `echo !include "bcwin32.mak" >makefile`

Besides the source files and the makefiles, you need:

> `turboc.cfg` |  | (the flags and switches for Turbo C)
> `gs.tr` |  | (the linker commands for the interpreter)
> *`.bat` |  | (a variety of batch files used in the build process)

Comments in the makefiles describe the configuration parameters. If your configuration is different from the following, you should definitely read those comments and see if you want or need to change any of this:

- The compiler files are in `C:\BC` and its subdirectories.
- You are using the Borland assembler `tasm`.
- You want an executable that will run on any 32-bit PC-compatible, regardless of processor type (80386, 80486, Pentium, or compatible) and regardless of whether a math coprocessor (80x87) is present -- an issue only with 80386 processors.

Notes

- A user reports that the Borland C++ 4.00 with patch 1-6 doesn't produce a working executable of Ghostscript 5.03. We can't test this, since we no longer have this compiler.
- Borland C++ 4.5 has a bug or bugs that cause(s) the 32-bit Windows executable to crash if you give any @-files on the command line. Among other things, this makes the uniprint driver unusable, because it references the .upp configuration files this way. This problem may possibly be fixed by one or more of the patch files on

  > ftp://ftp.borland.com/pub/borlandcpp/devsupport/patches/bc4_5/

- Borland C++ 4.52 has a bug that causes the 32-bit Windows executable to fail during startup. Borland (now Inprise) provides a patch for this bug in

  > ftp://ftp.borland.com/pub/borlandcpp/devsupport/patches/bc4_5/bc45xp1.zip

- Borland C++ 5.0 and 5.01 have a code generator bug that generates incorrect code for the construct `!file_is_valid()`. Do not attempt to compile Ghostscript with these compilers. If you want to report this bug to Borland, send them the result of compiling `ziodev.c` and tell them to look at the code generated for `file_is_valid()` and `!file_is_valid()`. We don't know whether Borland C++ 5.02 still has this problem.
- Building for the MS Windows Win32s environment, you need `bcc32.cfg` instead of `turboc.cfg`. The make process will stop after it has created `genarch.exe`. You should then run "`win genarch arch.h`", wait until `genarch` has finished and then exit MS Windows. Then type "`make`" again to restart the make process.
- Building for MS Windows NT, you also need `bcc32.cfg` instead of `turboc.cfg`, but the make process runs to completion automatically.

## Microsoft environment

To compile Ghostscript with the Microsoft environment, you need Microsoft Visual C++ 4.0 or later with its associated "`nmake`" utility and linker. If you're using version 4.x, before building, in `msvc32.mak` find the line "`MSVC_VERSION = 5`" and change it to "`MSVC_VERSION = 4`".

To create "`makefile`", give the command

> `echo !include msvc32.mak >makefile`

You may get error messages during compilation about `/QI0f` being an undefined switch, or the message "dwmain32.def: EXETYPE not supported for platform; ignored" during linking. Ignore them.

The Microsoft VC++ 5.0 compiler locks up when compiling `gxi12bit.c` with `/O2`. Compile this file without `/O2`.

The Microsoft VC++ 5.0 compiler produces a non-working executable if compiling without stack checking. Don't change the setting `TDEBUG=1` in `msvc32.mak`.

## Watcom environment

NOTE: The Watcom compiler is unusable, because Watcom's `wmake` and `wmakel` programs have severe size limitations that cause them to run out of memory when processing the Ghostscript makefiles. If enough people call Watcom (now PowerSoft) technical support, maybe they will do something about this. If you have suggestions for how to get around this limitation, please let us know.

On DOS or MS Windows with the Watcom compiler, add to `C:\AUTOEXEC.BAT` the line "`set DOS4G=quiet`". Then to create "`makefile`":

> Under |  | Give the command
> DOS |  | `echo !include watc.mak >makefile`
> MS Windows |  | `echo !include watcw32.mak >makefile`

Before compiling, change the definition of the `WCVERSION` macro in the makefile (`watc.mak` or `watcw32.mak`) to the version of the Watcom compiler you are using. This is necessary to handle some minor incompatibilities between versions.

To build Ghostscript, execute "`wmakebat`". This constructs a build script and then executes it. (This roundabout procedure is necessary because Watcom chose to implement `wmake` in a way that requires reading both the entire makefile and the entire current directory into the limited 640K DOS address space.)

Note that Watcom C/386 version 8.5 does not include `wmakel` (the 32-bit version of `wmake`). If this is the version that you have, use `wmake` instead, that is, edit `wmakebat.bat` to change "`wmakel`" to "`wmake`".

If you get an "Error(F01): Out of memory" with Watcom 8.5, you may wish to reduce the total size of the makefiles by editing `devs.mak` and `contrib.mak` to remove drivers you don't intend to use. If the error persists, contact Watcom technical support; they can send you the `wmakel` program, probably at no charge.

## Cygwin32 gcc

A user reports that it is possible to compile Ghostscript for MS Windows NT using the Cygwin32 gcc compiler, GNU `make`, and the `unix-gcc.mak` makefile, with only two small source code changes:

- Add "`b`" to the call to `fopen` in `gp_open_scratch`
- Mirror the `gp_ntfs` logic for `gp_file_name_is_absolute`

Information about this compiler and environment is at the Cygnus site:

> http://www.cygnus.com/misc/gnu-win32/

Please note that Cygnus's licensing terms aren't quite as liberal about redistribution as either the GNU General Public License or the Aladdin Free Public License, so read their license carefully if you want to redistribute the results of using their compiler.

# How to build Ghostscript from source (Mac version)

There are additional Mac-specific source files in a distribution separate from the rest of Ghostscript. In addition to the standard Ghostscript sources, you will need the following files:

> ftp://ftp.cs.wisc.edu/ghost/aladdin/mac/macgs-###-src.sit.bin
>   Source files as a StuffIt archive
> ftp://ftp.cs.wisc.edu/ghost/aladdin/mac/macgsmanual.html
>   How to use and build MacGS
> ftp://ftp.cs.wisc.edu/ghost/aladdin/mac/macgs-###-fonts*.sit.bin
>   Fonts (properly not to build MacGS but to install it)

If you don't have a program to expand and unpack these files, get the free StuffIt Expander program from your favorite Macintosh archive.

In the standard method of building Ghostscript, these files except the JPEG are unpacked into one big directory; the JPEG stuff is unpacked into a directory called `jpeg-6` under the main directory. The Macintosh stuff is also unpacked into its own directory, called "Mac Specific". However, if you like you can set up all these files in this hierarchy:

> Suggested Macintosh hierarchy
> `Ghost Dev`
> | `files` |  | (All *`.ps`, *`.htm`, and other non-build files)
> | `fonts` |  | (Fonts)
> | `src` |  | (*`.c`, *`.h`, *`.mak`)
> | `jpeg-6` |  | (JPEG files)
> | `Mac Specific` |  | (Mac files)
> | `MPW Build` |  | (Empty directory used for building under MPW)

Once everything is laid out, look at the file `Worksheet` in the "`Mac Specific`" folder for complete steps to build the system with either MPW or CodeWarrior.

# How to build Ghostscript from source (Unix version)

Before issuing the `make` command to build Ghostscript, you have to make some choices, for instance

- which compiler to use;
- what features and devices to include;
- whether to use system libraries for PNG and zlib;
- and how to handle problems and limitations for your particular platform.

Be sure to check the section on Unix build problems for notes on your particular platform and compiler. In fact, that is the first place to check if you build Ghostscript and it crashes or produces obviously incorrect results.

## Setting up "makefile"

The files `unix`*`.mak` are the makefiles for Unix platforms, and you choose one based on what compiler you use. To build Ghostscript, however, you must use the simple command "`make`", which must find the file "`makefile`" (or "`Makefile`"). If your system supports symbolic links, set up "`makefile`" like this.

> GNU gcc: |  | `ln -s unix-gcc.mak makefile`
> Non-gcc ANSI C compiler: |  | `ln -s unixansi.mak makefile`
> "Traditional" C compiler: |  | `ln -s unix-cc.mak makefile`

If your system doesn't support symbolic links, first finish all changes to the compiler-specific makefile, then make a hard link, omitting the `-s` switch.

The makefile distributed with Ghostscript selects the following devices to include in the build:

> Devices included as distributed
> Type |  | Devices
> Display |  | X Windows
> Printers |  | H-P DeskJets, LaserJets, and color DeskJets and PaintJets; Canon BubbleJets
> File formats |  | Group 3 & Group 4 fax; JPEG; PCX; PBM, PGM, PKM, & PPM; TIFF; PostScript images; PNG; distilled PDF, PostScript, and EPS; PCL XL ("PCL 6")

The `unix`*`.mak` files explicitly compile and link the JPEG, PNG, and zlib libraries into the executable. If your Unix system already includes the PNG and zlib libraries -- probably in `/usr/lib/libpng.`{`a`,`so`} and `/usr/lib/libz.`{`a`,`so`} -- and you would rather use those copies, change the definition of `SHARE_LIBPNG` and `SHARE_ZLIB` from 0 to 1 in the relevant `unix`*`.mak` file before compiling. Note that if you do this, you will get non-debug versions of these libraries even if you selected `DEBUG` in the makefile. At the insistence of some users, we have also provided the ability to do this with the JPEG library (`SHARE_JPEG`), but should not use it: in order to be compatible with Adobe interpreters (which do not follow the JPEG standard exactly), Ghostscript has to compile the IJG code with the non-standard definition

> `#define D_MAX_BLOCKS_IN_MCU 64`

and since shared versions of this library will not have been compiled this way, you awill get errors on some valid PostScript and PDF input files.

If the X11 client header files are located in some directory which your compiler does not automatically search, you must change the `XINCLUDE` macro in the makefile to include a specific `-I` switch. See the comment preceding `XINCLUDE` in the makefile.

Currently Ghostscript is set up to compile and link in a generic Unix environment. Some Unix environments may require changing the `LDFLAGS` macro in the makefile; be sure to check the section on build problems for your specific system.

Ghostscript uses ANSI syntax for function definitions. Because of this, when compiling with `cc` ("traditional" C), it must preprocess each `.c` file to convert it to the older syntax defined in Kernighan and Ritchie, which is what most current Unix compilers (other than gcc) support. This step is automatically performed by a utility called `ansi2knr`, which is included in the Ghostscript distribution. The makefile automatically builds `ansi2knr`. The `ansi2knr` preprocessing step is included in the makefile rule for compiling `.c` files. `ansi2knr` creates a file called `_temp_`$$`.c` to hold the converted code, where $$ is the process ID. If for some reason you want to change this name, it is defined in a script file `ccgs`.

## Unix build problems (and solutions)

### gcc 2.7.*

Some of the problems using gcc are very specific to the particular computer, the particular version of the operating system, and the particular version of gcc available to you. You can check the version of gcc with the `gcc --version` command.

An optimizer bug in gcc versions 2.7.0, 2.7.1, and 2.7.2 causes the compiler to generate incorrect code. The makefile works around this, but we recommend that if possible you use either an earlier or a later version of gcc; for instance, gcc 2.5.8, gcc 2.6.3, 2.7.2.1 or later which don't have this bug. Note, however, that gcc has other problems on some platforms, so please read the section for your specific platform.

### GNU make

Current versions of GNU `make` have no problems, but GNU `make` 3.59 can't handle the final linking step in some cases; if this happens, use the platform's standard `make`, typically `/bin/make`.

### 386 Unix

- gcc versions older than 1.38 on Intel 80386 systems do not compile Ghostscript correctly with the `-O` option.
- gcc 1.39 under `386BSD` has a bug that causes float-to-integer conversions to compile incorrectly, rendering the executable unusable.
- X11R5 may need "`#include <stddef.h>`" in `x_.h`.
- Also see regarding System V platforms.

### Alpha with gcc

- You don't have to use gcc on Alpha systems, because the bundled compiler works.
- The Alpha code generator in gcc 2.7.2.1 is broken. gcc 2.5.8 and 2.6.3 are probably usable. Versions before 2.5.0 are believed not to work. We suggest you use a recent version.
- If you really want to use gcc 2.7.x, here is a patch for that version from gcc maintainer Jim Wilson <wilson@cygnus.com>.

      *** reload.c.orig       Sun Mar  9 14:05:23 1997
      --- reload.c    Sun Mar  9 14:06:54 1997
      *************** push_secondary_reload (in_p, x, opnum, o
      *** 589,600 ****
               set it up now.  */

              if (in_p && icode == CODE_FOR_nothing
      !         && SECONDARY_MEMORY_NEEDED (class, reload_class, reload_mode))
      !       get_secondary_mem (x, reload_mode, opnum, type);

              if (! in_p && icode == CODE_FOR_nothing
      !         && SECONDARY_MEMORY_NEEDED (reload_class, class, reload_mode))
      !       get_secondary_mem (x, reload_mode, opnum, type);
        #endif
            }

      --- 589,600 ----
               set it up now.  */

              if (in_p && icode == CODE_FOR_nothing
      !         && SECONDARY_MEMORY_NEEDED (class, reload_class, mode))
      !       get_secondary_mem (x, mode, opnum, type);

              if (! in_p && icode == CODE_FOR_nothing
      !         && SECONDARY_MEMORY_NEEDED (reload_class, class, mode))
      !       get_secondary_mem (x, mode, opnum, type);
        #endif
            }

### H-P Apollo

- You must run the compiler in ANSI-compatible mode (that is, set `AK=`{null string} in the makefile); otherwise it gives incorrect error messages for any function declared as returning a float value.
- The H-P Apollo compiler may not compile Ghostscript correctly. If you get unexpected crashes at run time, use gcc.

### AT&T 7040 R3

- If Ghostscript crashes on startup, recompile with `-O0` to work around compiler bugs.

### Convex

- Use `unixansi.mak`. Do not invoke optimization (`-O1`) because the compiler will produce incorrect code.
- Set `CFLAGS` to "`-no -fn -tm c1`".

### DECStations with Ultrix

- If you get the compiler message "cfe: Fatal: _temp_19086.c: Segmentation violation" or a similar one, try compiling with the `-oldc` switch.
- You may wish to set

  `GS_LIB_DEFAULT=$(gsdatadir):/usr/lib/DPS/outline/decwin:$(gsdatadir)/fonts`

  in the makefile to add the Display PostScript font directory to the font search path.

- Set

  `CFLAGS="-Olimit 2500"`

  to make the optimizer allocate enough table space.

- The Ultrix 4.4 C compiler compiles `gdevm1.c` incorrectly. Insert the following line in the makefile rule for "`gdevm1.$(OBJ)`" (the body of the rule is empty in the standard distribution):

  `$(CCC) -oldc gdevm1.c`

### Digital Unix (Alpha)

- Use `unixansi.mak` for all Digital Unix compilers.
- For versions of Digital Unix before 4.0, set

  `CFLAGS=-std -migrate -Olimit 1000 -g3 -O2 $(XCFLAGS)
  LDFLAGS=-lots $(XLDFLAGS)`

  You may be able to omit `-g3`. For later versions of Digital Unix, users have reported that the proper flags are

  `CFLAGS=-std1 -Olimit 1000 -g3 -O2 $(XCFLAGS)`

  again, optionally omitting the `-g3`.

### H-P RISC workstations

- Ghostscript builds on H-P machines with either GNU gcc or H-P's ANSI-capable `cc`. The minimal, non-ANSI-capable `cc` that ships with a basic HPUX system does not work. If `cc` on your system doesn't accept the `-Aa` switch, then you need to get the full `cc` or gcc.
- If you use H-P's compiler, be sure you have upgraded to a recent release. Many bizarre symptoms have been reported trying to build Ghostscript with older, buggier compilers, for example:
  - The link step fails with a message about "`max`" not being defined.
  - The build succeeds, but the resulting executable fails to start up, with an error message like "Initializing... Unrecoverable error: typecheck in .registerencoding".
  - The build succeeds, but the resulting executable produces a black background on the first page of output.
- It is reported that On HPUX 9.* you need at least compiler patch PHSS_5723 and dld.sl patch PHSS_5734 to build Ghostscript. (As of late 1997, those patches are long obsolete; the current patches are compiler PHSS_10357 and dld.sl PHSS_11246. It is unknown whether current Ghostscript releases work with compiler/dld.sl versions older than these.)
- On HPUX 10.*, we don't know what combinations of compiler version and switches work. It is reported that On HPUX 10.20, setting "`CC=c89`" and "`CFLAGS=+O3 $(XCFLAGS)`" works, contradicting the information in the next paragraph, but this may be dependent on the specific compiler version.
- In either HPUX version, you need to set "`CC=cc -Aa`" (or use `-Ae` if you prefer), and set "`CFLAGS=-D_HPUX_SOURCE -O $(XCFLAGS)`". Higher levels of optimization than `-O` may work depending on your compiler revision; some users have reported success with `+O3`, some have not.
- Some users have reported needing `-DNOSYSTIME` and `-D_POSIX_SOURCE` in `CFLAGS`, but recent tests do not show these to be necessary.
- If you use gcc, it's a good idea to have a recent release -- 2.7.2.1 or later -- but gcc 2.6.3 has been known to work with past releases of Ghostscript. gcc versions earlier than 2.6.3, and 2.7.* earlier than 2.7.2.1, are known not to work. You may be able to get a working executable with an older gcc by removing `-O` from `CFLAGS`.

### Intergraph Clipper

- Recommended settings are:

  `XCFLAGS=-w -Q -DSYSV -D__SVR3
  EXTRALIBS=-lbsd -lc_s
  CC=acc -knr
  PLATFORM=sysv_`

- You will probably need to change the value of `XLIBS` from "`XLIBS=Xt X11 Xext`" to "`XLIBS=Xt_s X11_s Xext`".

### Linux

To create RPM (Red Hat Package Manager) files for Ghostscript N.NN:

- Change to your source directory (`/usr/src/redhat` for Red Hat Linux 5.1).
- Copy `ghostscript-N.NN*.tar.gz` (4 source files) to the `SOURCES` subdirectory.
- Copy `ghostscript-fonts-5.10a.tar.gz` to the `SOURCES` subdirectory.
- From `SOURCES/ghostscript-N.NN.tar.gz`,
  - extract `rpm-conf.dif` and copy to `SOURCES/ghostscript-N.NN-config.patch`
  - extract `gs.rps` and copy to `SPECS/ghostscript-N.NN.spec`
  - extract `gs-fonts.rps` and copy to `SPECS/ghostscript-fonts-N.NN.spec`
  If the contents of these files have become out of date, you will need to update the version number N.NN in the spec files, and update the patch file.
- Change to the SPECS subdirectory and then execute the commands

  > `rpm -ba ghostscript-N.NN.spec
  > rpm -ba ghostscript-fonts-N.NN.spec`

  This will create the RPM files

  > `RPMS/i386/ghostscript-N.NN-1.i386.rpm
  > RPMS/noarch/ghostscript-fonts-N.NN-1.noarch.rpm
  > SRPMS/ghostscript-N.NN-1.src.rpm
  > SRPMS/ghostscript-fonts-N.NN-1.src.rpm
  > `

- See instructions on how to install Ghostscript under Unix.

Bruce Babcock <babcock@math.psu.edu> has made available everything needed to build Ghostscript under Linux Slackware 3.*, Red Hat 4.* and 5.*, and Debian 1.* and 2.0; the files include instructions and shell scripts to build and install Ghostscript, as well as all the source and font kits and patches needed:

> ftp://ykbsb2.yk.psu.edu/pub/ghost/GS-5.10/
> ftp://ykbsb2.yk.psu.edu/pub/ghost/GS-5.10-Extra/

The other notes in this section do not originate with Bruce.

- If you build on Linux with X11 R6 or later, you may get link-time error messages about undefined references to various functions beginning with "SMC" and "ICE". If this happens, make sure that `XLIBS` in the makefile is set to "`Xt SM ICE Xext X11`" rather than "`Xt Xext X11`".
- With gcc version 2.6.3 or later, you may encounter an incompatibility in object formats (`a.out` vs. ELF) with the XFree86 library. Typically, `ld` complains that some X library is not found, or that many `Xlib` or `Xt` functions are not found in the library (similar to the messages for omitting `SM` and `ICE` from `XLIBS`). Or you get a message when you start Ghostscript that the program or the shared library is an unrecognized format.

  If this happens, edit `unix-gcc.mak` to add the switches "`-b i486-linuxaout`" to both `CFLAGS` and `LDFLAGS`, then "`make clean`" followed by "`make`"). If this doesn't help, or if other strange things happen, contact your Linux supplier or support resource.

### MIPS

- There is apparently a bug in older versions of the MIPS C compiler which causes `gxdither.c` to compile incorrectly if optimization is enabled (`-O`). However, this bug is definitely fixed in MipsPRO C version 6.00; with this version, compiling with "`-O2 -mips2`" produces good output.

### NCR 3550

- With the NCR C Development Toolkit you must use `-O0`.

### NeXTSTEP

- For all NeXTSTEP systems, use `unix-gcc.mak`.
- For current versions of NeXTSTEP, in `unixtail.mak` (and `ugcclib.mak`, if you are using only the library) change the definition of `INCLUDE` to "`INCLUDE=/usr/include/bsd`"
- For NeXTSTEP versions before 3.2
  - edit `unix-gcc.mak` to change `CC=gcc` to `CC=cc` and add `-D_NEXT_SOURCE` to `CFLAGS`;
  - change occurrences of `sys/time.h` to `ansi/time.h`; and
  - in `gp_unifs.c` change `<dirent.h>` to `<sys/dirent.h>`.
- For NeXTSTEP 3.2 and later
  - edit `unix-gcc.mak` to change `CC=gcc` to `CC=cc`, add `-D_POSIX_SOURCE` to `CFLAGS` and remove `-g`, and remove `-Wstrict-prototypes` from `GCFLAGS`; and
  - to the end of Fontmap add the line "`/Ohlfs /Courier ;`".
- If you are running the Pencom co-Xist X server (development version), the X headers and libraries are in the default places, so change the makefile definitions of `XINCLUDE` and `XLIBDIRS` to empty strings.

### Pyramid MIServer-S

See "AT&T 7040 R3".

### IBM RS/6000

- Many versions of the AIX C compiler have bugs that have prevented Ghostscript from compiling and linking properly. We believe that the current Ghostscript release works around these bugs, and that `unix-cc.mak` with `CC=cc` should work.
- You must also edit the makefile (`unixansi.mak` or `unix-cc.mak`) to change `INSTALL` to `/usr/ucb/install`.
- If `-DSYSV` produces a complaint about the functions `index` and `rindex` not being defined, try removing it.
- If the xlc 1.2.1 optimizer runs out of memory, you may need to add `-qmaxmem=4000` to `CFLAGS`.
- A user reports that the AIX C compiler shipped with AIX 3.2.5 compiles Ghostscript only if invoked with "`c89 -D_POSIX_SOURCE`" and without `-O`. On the other hand, another user reports successful compilation using `unix-ansi.mak` and the command line

  `make CC=c89 XCFLAGS="-DOSY_AIX -D_ALL_SOURCE -qnoro -qmaxmem=3000 -bfl" $*`

- Apparently some (but not all) releases of the C library declare the `hypot` function: if the declaration in `math_.h` produces an error message, try removing it.
- The IBM X11R3 server is known to be buggy: use the MIT X server if possible.
- The xlc 1.3.0.x compiler provided in AIX 3.2.5+ definitely will not compile Ghostscript correctly if `-O` is used on all files. A user reports that compiling `z`*`.c`, `gsmatrix.c`, `gxstroke.c` without `-O` is sufficient to produce a working executable:.
- Some installations of AIX 3.2.5 have what appears to be an incorrect or inconsistent version of `libXt.a` in `/usr/lpp/X11/lib`. If linking shows `XtShellStrings` and `XtStrings` as unresolved externals, set "`XLIBDIRS=-L/usr/lpp/X11/lib/R5 -L/usr/lpp/X11/lib`" rather than just "`XLIBDIRS=-L/usr/lpp/X11/lib`".

### SCO Unix/Xenix

- See also "386 Unix" and "System V Unix platforms".
- The standard cc compiler on SCO OpenServer v5 has optimizer bugs. Compile without -O.
- The SCO Unix C compiler apparently can't handle the `P` n macros in `std.h`. If you get strange compilation errors on SCO Unix, ask SCO for a compiler fix.
- Meanwhile, to use gcc with SCO ODT, see `unix-gcc.mak` for the appropriate switch settings.
- Because of a bug in SCO's floating point emulator, gcc 2.3.3 produces code that causes crashes on machines without hardware floating point. Use a different compiler on these machines.
- If you aren't using the X11 driver, you must add `-lsocket` to the linker command (near the end of `unix-`*`.mak`) to link the date and time functions.
- If you want to use direct frame buffer addressing instead of X Windows, include the relevant frame buffer devices (`ega.dev`, `vga.dev`, etc.) and change `gdevevga.c` to `gdevsco.c` as indicated in `contrib.mak`. Note: this works with SuperVGA displays only for 800x600x16 mode.
- If the display looks "smeared", try recompiling `gdevpcfb.c` with `-O0`.
- If Ghostscript crashes, use the `-q` switch or redirect console output to a file.
- If your compiler accepts both the `-Xt` and `-Xa` switches, use `-Xt`. Even though this causes the compiler to use incorrect rules for computing the result types of "`<<`" and "`>>`", `-Xa` enables optimizations that produce incorrect code.
- For SCO ODT 2.0, in addition to `-D__SVR3` and `-DSYSV`, you need to specify `-Dsco`, `-DUSG`, and `-DMALLOC_0_RETURNS_NULL`. For SCO ODT, you need "`EXTRALIBS=-lX11 -lsocket -lmalloc`", or maybe only `-lsocket` depending on the version), and for SCO ODT 2.0, you must also specify `-lc_s`. For SCO Xenix, you need "`EXTRALIBS=-lmalloc`".
- For all SCO systems, set "`XINCLUDE=`" and "`XLIBDIRS=`".

### Silicon Graphics

- Set

  `CFLAGS="-Olimit 2500"`

  to make the optimizer allocate enough table space.

- With the compiler shipped with Irix 5.2, use the `-ansi` option.
- The SGI C compiler may produce warnings about "Undefined the ANSI standard library defined macro stdin/stdout/stderr". To suppress these warnings, add "`-woff 608`" to the definition of `CFLAGS`.
- The SGI C compiler shipped with Irix 6.1 and 6.2 will not compile `zlib/deflate.c` properly with optimization. Compile this file separately without `-O`.
- The MIPSpro 7.1 compiler produces incorrect output with `-O3` or "`-Ofast=ip32 -show`. Use only `-O2`.

### Sun

- The Sun unbundled C compiler (SC1.0) doesn't compile Ghostscript properly with the `-fast` option: Ghostscript core-dumps in `build_gs_font`. With that compiler use `-g`, or use gcc instead.
- The Sun version of `dbx` often gives up with an error message when trying to load Ghostscript. If this happens, use GNU `gdb` instead. (`gdb` is more reliable than `dbx` in other ways as well.)
- A bug in some versions of `zlib` results in an undefined symbol `zmemcmp` when compiling with Sun cc. Use gcc instead.

#### SunOS

- In SunOS 4.1.[23], you may get undefined symbols `_get_wmShellWidgetClass` and `_get_applicationShellWidgetClass` when linking. Compiling "`-Bstatic -lXmu -Bdynamic`" appears to work for SC1.0. For gcc, try adding `-static` to `CFLAGS`. To solve the problem if you are using OpenWindows 3.0 (X11R4-based Xt), ask Sun for patches 100512-02 and 100573-03.

#### Solaris

- Solaris 2.2 may require setting "`EXTRALIBS=-lsocket`". Solaris 2.3 and 2.4 seem to require "`EXTRALIBS=-lnsl -lsocket`".
- For Solaris 2.6 (and possibly some other versions), if you set `SHARE_LIBPNG=1`, `SHARE_ZLIB=1`, or `SHARE_JPEG=1`, you may need to set

  `XLDFLAGS=-R /usr/local/`xxx`/lib:/usr/local/lib`

  using the full path names of the relevant directories.

- Solaris 2.n uses `/usr/openwin/share/include` for the X11 libraries rather than `/usr/local/X/include`.
- Solaris 2.n typically has Type 1 fonts in `/usr/openwin/lib/X11/fonts/Type1/outline`.
- For Solaris 2.`n` `in the makefile you must change the definition of `INSTALL` from "install -c`" to "`/usr/ucb/install -c`".
- You may need to set `XLIBDIR` to the directory that holds the X11 libraries, as for other SVR4 systems. Set `-DSVR4` in `CFLAGS`.
- If you are using the SunPRO C compiler, don't use optimization level `-xO3`. On SPARC platforms the compiler hangs; on Intel platforms the generated code is incorrect. With this compiler on Intel, do not use the `-native` flag: floating point computations become unacceptably inaccurate. You can use `-xcg92` (SPARC V8) and `-dalign` for better performance.

### SVR4 Unix

- You may need to set `EXTRALIBS=-lnsl`.
- Do not change `PLATFORM=unix_` to `PLATFORM=sysv_`.
- On SVR4 Unix platforms with dynamic linking, you may need to define `XLIBDIR` as the name of the directory that holds the X Windows libraries. Do not prefix the name with "`-L`".
- For SVR4.0 systems, set `-DSVR4` and `-DSVR4_0` in the makefile; do not set `-DSYSV`. For SVR4.2 (or later) and Solaris 2.n systems, set only `-DSVR4` (not `-DSVR4_0` nor `-DSYSV`).

### System V Unix platforms

- If you are using a stock System V platform that lacks `rename` and `gettimeofday`, in the makefile change "`PLATFORM=unix_`" to "`PLATFORM=sysv_`".
- You will probably need to change the definition of `INSTALL` from "`install`" to "`/usr/ucb/install`".

### Unixware

- The standard cc compiler has optimizer bugs. Compile without `-O`.

### VAX with Ultrix

- You may wish to set

  `GS_LIB_DEFAULT=$(gsdatadir):/usr/lib/DPS/outline/decwin:$(gsdatadir)/fonts`

  in the makefile to add the Display PostScript font directory to the font search path.

# How to build Ghostscript from source (OS/2 version)

- The relevant makefile is `os2.mak` The gcc/emx 0.9b (or later) compiler and IBM `NMAKE.EXE` are required.
- For gcc/emx versions 0.9c and later, the `LINK386` command must include "`$(COMPBASE)\lib\end.lib`"; version 0.9b requires omitting it. The current `os2.mak` file does include this file in the `LINK386` command, so if you are using 0.9b, delete this file reference before building.
- Be sure you are using the standard OS/2 shell, `CMD.EXE`. Some other shells have bugs or differences that cause the makefile not to work.
- Before compiling or linking, you should execute "`copy os2.mak makefile`". Then to start the make process type "`nmake`". One DLL and two EXEs will be produced: `gsdll2.dll` (the Ghostscript DLL), `gsos2.exe` (the Ghostscript executable) and `gspmdrv.exe` (the Presentation Manager display driver).

# How to build Ghostscript from source (VMS version)

Some versions of DEC's X server have bugs that produce broad bands of color where dither patterns should appear, or characters displayed white on top of black rectangles or not displayed at all. If this happens, consult the usage documentation for how to work around X server bugs using X resources; also report the problem to DEC, or whomever supplied your X server.

You may also wish to turn off the use of a backing pixmap with Ghostscript, either to work around X server memory limitations or bugs, or to obtain faster displaying at the expense of no redrawing when a Ghostscript window is restored from an icon or exposed after being occluded by another window. Again, the usage documentation tells how to do this.

You can precompile any Type 1 font into C, then compile and build it into Ghostscript, as described in the fonts documentation. If you do this, then add "`ccfonts.dev`" to `FEATURE_DEVS` in `VMS-CC.MAK`, `VMS-GCC.MAK`, `VMS-DECC.MAK`, or `OPENVMS.MAK`:

> `$ FEATURE_DEVS = "level2.dev ccfonts.dev"`

Specify the font names with `ccfonts1`:

> `$ ccfonts1 = "Courier Courier_Oblique Courier_Bold Courier_BoldOblique"`

If this makes the line too long, add another line of the same form, such as

> `$ ccfonts1 = "Courier Courier_Oblique Courier_Bold Courier_BoldOblique" $ ccfonts2 = "Times_Roman Times_Italic Times_Bold Times_BoldItalic"`

## Building with GNU make on OpenVMS

As of Ghostscript version 5.0 you can use GNU make -- with the file `OPENVMS.MAK` and some auxiliary `.COM` files -- to build Ghostscript on OpenVMS. Use the command:

> `make -fopenvms.mak "OPENVMS=`{`VAX`,`ALPHA`}`" "DECWINDOWS=`[`1.2`]`"`

That is, specify either `VAX` or `ALPHA` as the value of the `OPENVMS` parameter, and either "`1.2`" or nothing (blank) as the value of `DECWINDOWS`. (The value "`VAX`" just means that you want to use the VAX C compiler: it doesn't imply that you are running on VAX hardware.) In Europe and other parts of the world where ISO standard paper sizes are used, append "`A4_PAPER=1`" to that line to make A4 the default paper size at run time.

If you haven't a prebuilt copy of GNU make, you'll have to build it yourself; as of Version 3.76 (but not earlier) it is said to build properly under OpenVMS on both VAX and Alpha. The kit is available at the Free Software Foundation's ftp site and its mirrors. See

> ftp://ftp.gnu.org/pub/gnu/

# Other environments

## Plan 9

Use `unix-gcc.mak`, editing it to define

> `CC=cc GCFLAGS=-D_BSD_EXTENSION -DPlan9`

You will also probably have to edit many path names.

## QNX

David J. Hawkey Jr. writes that he built Ghostscript 4.03 and 5.0 under QNX 4.22, 4.23, and 4.24 using Watcom C 10.6 and that "it works quite well, after figuring out the `/etc/config/lpsrvr` directives, except for color printing to my HP DeskJet some-number-or-another". Here is a concise presentation of changes based on the ones he made for Ghostscript 4.03.

`unixansi.mak`

  Original lines |  | Change to
  `INSTALL = install -c INSTALL_PROGRAM = $(INSTALL) -m 755 INSTALL_DATA = $(INSTALL) -m 644` |  | `INSTALL = cp INSTALL_PROGRAM = $(INSTALL) INSTALL_DATA = $(INSTALL)`
  `datadir = $(prefix)/share` |  | `datadir = $(prefix)/lib`
  `CFLAGS_STANDARD=-O` |  | `CFLAGS_STANDARD=-Otx -zp1 -mf`
  `LDFLAGS=$(XLDFLAGS)` |  | `LDFLAGS=-mf -N32k $(XLDFLAGS)`
  `EXTRALIBS=` |  | `EXTRALIBS=-lXqnx_s -lsocket`
  `XINCLUDE=-I/usr/local/X/include` |  | `#XINCLUDE=-I/usr/local/X/include`
  `XLIBDIRS=-L/usr/local/X/lib XLIBDIR= XLIBS=Xt Xext X11` |  | `#XLIBDIRS=-L/usr/local/X/lib #XLIBDIR= XLIBS=Xt_s Xext X11_s`

`gp_unifs.c`
  After the line

  > `#include <sys/param.h>`

  add these lines:

  > `#if defined(__QNX__)
  > #include <unix.h>
  > #endif`

`gp_unix.c`
  After the line

  > `#include "time.h"`

  add these lines:

  > `#if defined(__QNX__)
  > #include <sys/time.h>
  > #endif`

`time_.h`
  Modify the line beginning

  > `# if defined(Plan9) ||`

  to begin

  > `# if defined(__QNX__) || defined(Plan9) ||`

`/etc/config/lpsrvr`
  Here is Hawkey's `lpsrvr` as an example.

  >     # lpsrvr
  >     #
  >     # Defines the print queues and their devices
  >     #
  >     # Queues

  >     # ink-jet: Ghostscript interpreter for mono DeskJet - LaserJet works
  >     #          better than DeskJet!

  >     [ij-monops]
  >             ta=lpt1
  >             co=/usr/local/bin/gs -q -sDEVICE=laserjet -sOutputFile=- -dNOPAUSE $(spfile) quit.ps | cat > $(device)

  >     # Devices

  >     [-lpt1]
  >             dv=/dev/par1

  >     [-lpt2]
  >             dv=/dev/par2

Copyright © 1996, 1997, 1998 Aladdin Enterprises. All rights reserved.

This file is part of Aladdin Ghostscript. See the Aladdin Free Public License (the "License") for full details of the terms of using, copying, modifying, and redistributing Aladdin Ghostscript.

Ghostscript version 5.50, 16 September 1998