% !TEX TS-program = htlatex
\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-ImageMagick}
\author{Richard Koch}
\date{\today}                                           % Activate to display a given date or no date

\begin{document}
\maketitle

\section{Important Warnings}

This section contains lessons learned in 2013. The material here is important for all packages made with the new
PackageMaker.

Folders in which packages are built should live on the hard disk rather than an external
disk. Building constructs subfolders named ``root'' which contain copies of material to be installed. This root folder and its
contents are usually owned by root. But material on an external drive is owned by the user instead, so owners will be
incorrect after installing.

The final MacTeX template refers to  root folders of the various sub projects. In the template, each sub project
is listed in the left column; clicking on an arrow there reveals a panel in which the root folder is determined and configured.

Configuration of a root folder is governed by a panel with four tabs: Configuration, Contents, Components, and Scripts.
The material in the first and last tabs is important and should be entered carefully. The second Contents tab allows owners, groups, and
permissions of individual files in the folder to be set. This task is impossible for a huge root folder like TeXLive, but luckily
Apple provides a button "Apply Recommedations" which does it automatically following Apple's "best practices policy."
Always click this button.

For binary files like texlive/2013/bin/universal-darwin, the recommendations are unexpected. Actual binaries have owner root
and group wheel, but symbolic links have owner an individual user and group wheel. Permissions are -rwxr-xr-x. Experiments
and email conversations show that these choices work well.

For the GUI-package, the third tab, "Components", is very important. It lists actual apps and offers to relocate them. {\em Turn this off}.
Otherwise the installer won't upgrade programs in /Applications/TeX, but instead will search the disk for a copy to update.
Always check that these items are off. 


\section{ImageMagick}
This is the portion of the TUG documentation which deals with making the ImageMagick package.

{\bf Warning:} It is important that the folders in which packages are built live on the hard disk rather than an external
disk. Building constructs folders named ``root'' which are copies of material to be installed. This root folder and its
contents are often owned by root. But material on an external drive is owned by the user instead.


A clean package file will contain
\begin{itemize}
\item ``Building This Package'' folder with document explaining in detail how to build the package
\item File ``buildRoot.sh'' 
\item Files ``background.jpg'', ``License.rtf'', ``ReadMe.rtf'', and ``Welcome.rtf''
\item ``Code2013'' folder containing tar files with the sources for ImageMagick.
\item ``Universal'' folder with two files named liposcript and tarscript, and three empty folders. 
\item scripts folder containing files ``postinstall'', ``setloginpath'', and ``settexpath''
\item ConvertIMBuild project file for Packagemaker
\item ``TUG'' folder with this document
\end{itemize}


\section{OverView}

We do not ship ImageMagick, but only the ``convert'' utility inside it. This is necessary because convert is used by TeX4ht and yet is not part of TeX Live. Also TeX can be instructed to call convert automatically if tiff files are encountered. 

Normally ImageMagick ships as a series of libraries called by the main program. We don't want to install any libraries. So we
compile convert to use static libraries. This requires some tricky maneuvers  as the program is constructed.

\section{Adjusting for a New Year}

To switch to the new name:
\begin{itemize}
\item Edit the ``buildPackage.sh'' script, noting that the version number of the program is contained in the script.
\item The files which will be shown to the user during installation: License.rtf,
ReadMe.rtf, and Welcome.rtf. Edit these files to reflect the new package name and release date. Make other changes as appropriate.
\end{itemize}


\section{Compiling}

Compiling convert is tricky. Image Magick constructs shared libraries which its components all call, and it requires other libraries: libjpeg, png, freetype, tiff, zlib. We don't want to install the Image Magick shared libraries or these extra libraries. The trick is to compile Image Magick using static libraries and then pull out convert.

Start by renaming the old /usr/local in /usr, and rename X11 and/or X11R6 so X11 support won't be added.


We compile on OS X 10.5 for PPC and for Intel.  

First install the required libraries in /usr/local. We need the following libraries:
\begin{verbatim}
zlib     http://www.zlib.net/                         Ver 1.2.7: May 2, 2012
libjpeg  http://www.ijg.org                           Ver 8d: January 15, 2012     
freetype http://freetype.sourceforge.net/index2.html  Ver 2.4.11: December 20, 2012
libpng   http://www.libpng.org/pub/png/libpng.html    Ver 1.5.14: January 24, 2013
libtiff  http://www.remotesensing.org/libtiff/        Ver 4.0.3 September 22, 2012
bzip2    http://bzip.org/                             Ver 1.0.6; September 20, 2010

\end{verbatim}




The latest version of libjpeg is Ver 9, but that version has a bug which affects libtiff. So we downgrade to Ver 8d.
\newpage
Compile and install libjpeg first. Use the following instructions:
\begin{verbatim}
     make clean
     ./configure --enable-shared --enable-static
     
     rm libtool
     ln -s `which glibtool` ./libtool
     
     make

     sudo mkdir -p /usr/local/include

     sudo mkdir -p /usr/local/lib
     sudo mkdir -p /usr/local/man/man1
     sudo mkdir -p /usr/local/bin

     sudo make install
\end{verbatim}

Then change to /usr/local/lib and remove all files except libjpeg.a.

Compile zlib, libtiff, libpng,  freetype, and bzip2 in that order, using the standard commands (bzip2 doesn't have a .configure step):

\begin{verbatim}
          make clean
          ./configure
          make
          sudo make install
\end{verbatim}

After each step, remove all .dylib and .la files in /usr/local/lib.


 
Next go to /usr/local and remove everything in the bin directory. % except ``make''. 
Also remove the man, and share directories, leaving only the include and lib directories. 

Obtain the ImageMagick source code at 
\begin{verbatim}
   http://www.imagemagick.org/script/install-source.php#unix
\end{verbatim}
This contains version 6.8.3-3 released February 19, 2013.

Go to IM/ImageMagick-6.8.3-3 and compile Image Magick using the sequence
\begin{verbatim}
          make clean
          ./configure --disable-shared
          make
          sudo make install 
\end{verbatim}
It helps to look at the configure output and confirm that shared libraries are disabled. 

Now go to /usr/local and remove the include library. Also in /usr/local/lib, remove the ``old'' directory and all libraries, leaving only the folder named ``ImageMagick-6.8.3''.

Finally, move the entire remaining contents of /usr/local to Universal/local-i386 or Universal/local-ppc depending on whether you compiled on Intel  or on PPC. 

Make sure the Universal folder has a subfolder named ``local'' containing a subfolder named ``bin''. Change directory to Universal, strip the binaries, and lipo them together using the following commands:
\begin{verbatim}
          cd local-i386/bin
          strip *
          cd ../..
          cd local-ppc/bin
          strip *
          cd ../..
          sh liposcript
\end{verbatim}

Finally, execute the build instruction using the command
\begin{verbatim}
          sudo sh buildRoot.sh
\end{verbatim}

\section{Building the Final Install Package with Packagemaker}

The remaining tasks are not necessary unless you want to make a copy of Convert-IM for preliminary
testing.

Now edit ConvertIMBuild, the Packagemaker project file, using the GUI interface, 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: ImageMagick-Convert-6.8.3-3
\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 ImageMagick-Convert-6.7.6-9 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: ImageMagick-Convert-6.8.3-3
\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 ImageMagick-Convert-6.8.3-3 entry in the bottom left column. This item should show a ``/usr/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.imagemagick-convert-6.8.3-3
\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 ``ImageMagick-Convert-6.7.6-9-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 ImageMagick-Convert-6.8.3-3-Temp.pkg and ``new-name'' is ImageMagick-Convert-6.8.3-3.pkg








\end{document}  