\documentclass[11pt, oneside]{amsart}
\usepackage{geometry}                % See geometry.pdf to learn the layout options. There are lots.
\geometry{letterpaper}                   % ... or a4paper or a5paper or ... 
%\geometry{landscape}                % Activate for for rotated page geometry
\usepackage[parfill]{parskip}    % Activate to begin paragraphs with an empty line rather than an indent
\usepackage{graphicx}
\usepackage{amssymb}
\usepackage{epstopdf}
\usepackage{url}
\DeclareGraphicsRule{.tif}{png}{.png}{`convert #1 `dirname #1`/`basename #1 .tif`.png}

\title{TUG-Ghostscript}
\author{Richard Koch}
\date{\today}                                           % Activate to display a given date or no date

\begin{document}
\maketitle
\section{Ghostscript}
This is the portion of the TUG documentation which deals with making the Ghostscript package.

\section{Overview}

From 2017 on, MacTeX will support the platforms for which Apple provides security updates, and thus the three most recent versions of macOS.
MacTeX is built on these oldest of these versions. In 2018, MacTeX is built on El Capitan and supports El Capitan,  Sierra, and High Sierra.

Building Ghostscript is done in three steps. The first builds the binaries, which are placed
in the folder ``Binaries.'' Two binaries are built El Capitan, one with X11
support and one without this support.

In the second stage, Ghostscript is built and installed in /usr/local. Then a buildPackage
script copies the resulting installation to the ``root'' folder in the Build Directory.
This script replaces the binaries in this root folder with the carefully constructed combined
build binaries in Binaries.

The script makes modifications for TeX Fonts by Arnold-Voisin and for Japanese fonts by Kuroki-Yusuke, Bruno Voisin, and Norbert Preining. The Arnold-Voisin additions were constructed in 2012. The Japanese additions were constructed in 2015 with very difficult testing by Bruno and Norbert. 

In the third stage, this root folder is used to construct an install package using the
GhostscriptBuild template.

\section{Contents} 
A clean package file will contain
\newpage
\begin{itemize}
\item ``Binaries'' folder 
\item Folders containing documentation by Bruno and various font lists
\item Files ``buildPackage.sh''  and ``buildTeXfonts.sh''
\item Packagemaker template files GhostscriptBuild and GhostscriptBuild copy.
\item Files ``background.jpg'', ``License.rtf'', ``ReadMe.rtf'', and ``Welcome.rtf''
\item ``scripts'' folder containing file ``postinstall'' 
\item signPackage.sh file
\item ``TUG'' folder with this document
\end{itemize}

To construct the package, download the latest Ghostscript tar file from \url{http://www.ghostscript.com/} and put the file
in the ``source'' folder. Then unzip this file; the resulting folder is the source code for Ghostscript.

In 2015, very extensive word was done to improve support for CJK fonts by Bruno Voisin,
Norbert Preining, and others. Various documents created during that work are preserved
in the folder Bruno-Documentation, in case it is necessary to refer back to it.

\section{Building Binaries}

Build binaries on El Capitan. 
Build a version with X11 support and a version without this support.

Before building, move /usr/local/bin to /usr/local/bin-temp and /usr/local/share to /usr/local/share-temp. Leave /opt alone for X11 build, but change it to /opt-temp for non-X11 build.

To build:

\begin{verbatim}
     make clean
     ./configure --disable-compile-inits
     make
\end{verbatim}

Move all of these binaries to the ``Binaries'' folder on the machine used to
build the actual install package.


\section{Preparing the Root Folder}

Next edit the file ``buildPackage.sh'' to reflect the current version of Ghostscript. Currently this file contains ``9.22'', referring to
folders installed by Ghostscript. Change this number appropriately.

Next make sure the latest TeX Live is installed on this machine and type
\begin{verbatim}
     sh buildTeXfonts.sh
\end{verbatim} 
This step will create a folder named ``fonts'' in ``source/TeXfonts/ containing symbolic links to the pfb font files in this latest
TeX Live distribution. 


Next change directory to /usr and rename /usr/local to /usr/local-temp. Copy the Ghostscript source folder to your machine and
install Ghostscript using
\begin{verbatim}
     make clean
     ./configure --disable-compile-inits
     make
     sudo make install
\end{verbatim}

In this step we are not interested in the binaries, but instead in the support files for Ghostscript. 

Then change to the main Ghostscript directory of the MacTeX build system and type
\begin{verbatim}
     sudo sh buildPackage.sh
\end{verbatim}

This step will copy Ghostscript support files from /usr/local to the root directory of  MacTeX's  Ghostscript build folder.
It will add the binaries constructed earlier. Then it will make modifications from Arnold-Voisin so Ghostscript will understand TeX file. It will also make modifications from
Kuroki-Yusuku, Bruno Voisin, and Norbert Preining so Ghostscript will understand Japanese files.


\section{Adjusting Files in the Ghostscript Install Package}

This package contains some files which are shown to the user during installation. One of these files
is a brief Welcome document, a second is a longer ReadMe file, and a third shows the License for the code. After the
Ghostscript install package is constructed, you may need to revise these documents. For example, the Welcome document
contains the release date. Usually TeX Live authors are overly ambitious and predict a release several months earlier
than it actually occurs, and you'll need to change the release date from time to time.

None of these files appear in MacTeX, but they appear if you make an optional Ghostscript Install Package.

\section{Making a Standalone Install Package}

This step is optional. If you want an install package containing only Ghostscript, construct it as follows. 

This section of the MacTeX package contains a Packagemaker project file named ``GhostscriptBuild''. Edit this project file using the
GUI interface of PackageBuilder as follows:

\begin{enumerate}
\item Click the top item on the left. The right side will change to a view with three tabs. First select
the Configuration tab. Edit so
\begin{enumerate}
\item Title: ``Ghostscript-9.22'
\item User Sees: Easy Install Only
\item Install Destination: System volume
\item Certificate: Leave this blank. You might think that putting a certificate name here would correctly sign
the package, but experiments show that it does not. The package needs to be signed after it is constructed.
\item Description: Empty
\end{enumerate}
\item The Requirements and Actions tab entries for the top item can be left blank

\item Click the entry in the Contents section on the left. The right side will change to a view with two tabs.
Select the Configuration tab. Edit so
\begin{enumerate}
\item Choice Name: Ghostscript-9.22
\item Identifier: choice1
\item Initial State: Selected and Enabled
\item Destiination: Leave Blank
\item Tooltip: Leave Blank
\item Description: Leave Blank
\end{enumerate}
\item The Requirements tab entries for this contents item can be left blank
\item Open the Ghostscript-9.22 entry in the bottom left column. This item should show a ``local'' directory,
obtained by dragging root/user/local to the left column. The right side will change to a view with four tabs.
The item under the Components tab can be left blank. It is not necessary to edit the
items under the Contents tab. The items under the
Configuration tab should be edited as follows:
\begin{enumerate}
\item Install: root/usr/local (The item on the right should have selected ``Relative To Project'')
\item Destination: /usr/local (The item on the right should have selected ``Relative To Project'')
\item Do not check ``Allow custom location''
\item Patch: No patch root selected
\item Package Identifier: org.tug.mactex.ghostscript9.22
\item Package Version: 1.0
\item Restart Action: None
\item Check ``Require admin authentication''
\item PackageLocation: Self-Contained
\end{enumerate}
The items under the Scripts tab should be edited to read
\begin{enumerate}
\item Scripts directory: scripts (The item on the right should have selected ``Relative To Project'')
\item Preinstall: Leave Blank
\item Postinstall: scripts/postinstall (The item on the right should have selected ``Relative To Project'')
\end{enumerate}

\end{enumerate}

After verifying all these items, build the install package by clicking the ``Build'' icon. When asked to select
a name, choose ``Ghostscript-9.19-Temp''. 
After the package has been made, sign it by executing the following line in Terminal:
\begin{verbatim}
     sh signPackage.sh
\end{verbatim}
This script simply calls
\begin{verbatim}
     productsign --sign "Developer ID Installer: Richard Koch" old-name new-name
\end{verbatim}
where ``old-name'' is Ghostscript-9.22-Temp.pkg and ``new-name'' is Ghostscript-9.22.pkg









\end{document}  



The following warnings will be posted from the previous step. These can be ignored.
\begin{verbatim}
Warning: Mode lrwxr-xr-x  does not match -rw-r--r--  of root volume 
     for "/usr/local/share/man/man1/eps2eps.1". 
Warning: Mode lrwxr-xr-x  does not match -rw-r--r--  of root volume 
     for "/usr/local/share/man/man1/gsbj.1".     
Warning: Mode lrwxr-xr-x  does not match -rw-r--r--  of root volume 
     for "/usr/local/share/man/man1/gsdj.1". 
Warning: Mode lrwxr-xr-x  does not match -rw-r--r--  of root volume 
     for "/usr/local/share/man/man1/gsdj500.1". 
Warning: Mode lrwxr-xr-x  does not match -rw-r--r--  of root volume 
     for "/usr/local/share/man/man1/gslj.1". 
Warning: Mode lrwxr-xr-x  does not match -rw-r--r--  of root volume 
     for "/usr/local/share/man/man1/ps2pdf12.1". 
Warning: Mode lrwxr-xr-x  does not match -rw-r--r--  of root volume 
     for "/usr/local/share/man/man1/ps2pdf13.1". 
Warning: Mode lrwxr-xr-x  does not match -rw-r--r--  of root volume 
     for "/usr/local/share/man/man1/ps2pdf14.1". 
Warning: Mode lrwxr-xr-x  does not match -rw-r--r--  of root volume 
     for "/usr/local/share/man/de/man1/eps2eps.1". 
Warning: Mode lrwxr-xr-x  does not match -rw-r--r--  of root volume 
     for "/usr/local/share/man/de/man1/ps2pdf12.1". 
Warning: Mode lrwxr-xr-x  does not match -rw-r--r--  of root volume 
     for "/usr/local/share/man/de/man1/ps2pdf13.1". 
Warning: Mode lrwxr-xr-x  does not match -rw-r--r--  of root volume 
     for "/usr/local/share/man/de/man1/ps2pdf14.1". 
\end{verbatim}
