Index: /gs2-extensions/imagemagick/branches/macos-dev/README
===================================================================
--- /gs2-extensions/imagemagick/branches/macos-dev/README	(revision 34337)
+++ /gs2-extensions/imagemagick/branches/macos-dev/README	(revision 34337)
@@ -0,0 +1,196 @@
+31 Oct 2016, last updated 1 Feb 2017
+ak19
+
+If making an imagemagick binary tarball, here are the steps to go through and the things to check
+
+WINDOWS IMAGEMAGICK BINARY
+This was merely a zip up of the bin\windows\imagemagick folder checked out from http://trac.greenstone.org/browser/main/trunk/binaries/windows/bin/imagemagick
+I then removed the .svn subfolder, zipped it up and put it here. The purpose is for people working with GS2 source distributions to grab a quick copy, as the compilation process doesn't compile up imagemagick.
+For GS2's unix systems, if "imagemagick" is passed in as parameter to the makegs2.sh script, it will now download the appropriate imagemagick binary tarball for the unix flavour from http://trac.greenstone.org/browser/gs2-extensions/imagemagick after compilation has succeeded.
+
+
+TO CREATE THE IMAGEMAGICK TARBALL FOR DARWIN EL CAPITAN
+
+0. Need to be on an El Capitan that should not have xwindows (like Dr Bainbridge's El Capitan laptop), so that we don't produce imagemagick binaries dependent on these libs, see trac changeset 31012.
+
+For general information: An important change involved setting the mmacosx-version-min=10.8, in order to get the generated imagemagick binary to work on more Mac El Capitan machines, as explained in the commit message for http://trac.greenstone.org/changeset/31145:
+"Redoing El Capitan imgmagick binary for release after testing on an uncooperative El Cap Mac machine. The key change involved recompiling with mmacosx-version-min=10.8 (Mountain Lion) to make the binary more backwards compatible."
+
+1. svn co http://svn.greenstone.org/gs2-extensions/imagemagick/trunk
+
+2. Then:
+   cd src
+   ./CASCADE-MAKE.sh
+
+3. See section THINGS TO CHECK below and perform the tests there to check the compiled up imagemagick works.
+
+4. Create an imagemagick folder containing only setup.bash, setup.bat and the darwin folder (or the "linux" folder on linux machines).
+
+4a. (This seems to be a Darwin-only step, as we don't cut-down the products in the linux folder the same way.)
+The darwin folder from step 4 should only contain the following 4 folders, so remove the rest:
+- script
+- etc
+- lib
+- bin: cut down to just the following 
+  convert
+  identify
+  Magick-config
+  Magick++-config
+  MagickCore-config
+  MagickWand-config
+  Wand-config
+
+Note: As per the El Capitan release-kit (kits/rk3/ant-scripts/compile.xml), only the darwin folder within the tarball (and not the setup scripts) will get copied over as the "imagemagick" folder into gs2build/bin/darwin. (So the "darwin" folder will be named "imagemagick" in the final binary.)
+
+5. Create a tarball of the imagemagick folder created in step 4 above (containing the darwin subfolder and the 2 setup scripts) and name the tarball imagemagick-darwin-10.11.tar.gz
+
+   tar -cvzf imagemagick-darwin-10.11.tar.gz imagemagick
+
+6. Commit the tarball into the trunk folder checked out in step 1 above. 
+
+
+THINGS TO CHECK
+
+To test imagemagick works
+
+0. cd into src/<OS>/bin
+
+1. ./identify -list format
+
+It should print out the list of image conversion formats supported. Check the read/write status of the listed file formats: we want r,w  (read and write abilities) for GIF, JPG, PNG, TIFF.
+
+2. Next run
+   ./convert logo: logo.png
+
+This will (should) generate a file called logo.png in the same location.
+Check that it is indeed PNG by running:
+
+   file logo.png
+
+The file info printed should say whether it's PNG. If things went wrong, the actual file produced might be listed as GIF still. In that case, the conversion was unsuccessful, which means something could be wrong with the delegate/imgmagick library for that image file format. Check for any errors when configuring and compiling up that delegate library.
+
+
+
+RESOURCES ON COMPILING UP AN IMAGEMAGICK BINARY STATICALLY
+
+- http://www.imagemagick.org/script/download.php
+
+- http://stackoverflow.com/questions/25634129/compile-static-version-of-imagemagick-convert-util
+
+- http://imagemagick.sourceforge.net/docs/GuideToBuildingIMForMacOSX.pdf
+
+- http://www.imagemagick.org/discourse-server/viewtopic.php?t=13145
+
+Words to look out for:
+delegates
+
+./convert
+different listing of formats supported?
+
+
+depends on:
+- version of imgmagick (src code)
+- whether it uses xwindows libraries or not
+-> macs used to come with xwindows libraries, and imgmagick used to make use of that. But now Macs aren't guaranteed to come with xwindows libs, so for El Capitan binaries, compile up ImageMagick tarball on Gilda El Capitan (which produces bins not dependent on xwindows libs), rather than generating the tarball on the ElCap laptop where xwin libs are available and dynamically linked to (but these libs are then found missing on other El Capitan machines like Gilda, and the convert command will fail).
+
+
+FILE LISTING:
+
+gilda:GS3bin_28Oct2016 anupama$ cd gs2build/bin/darwin/imagemagick/
+
+gilda:imagemagick anupama$ ls
+bin		  etc	   lib	script
+
+gilda:imagemagick anupama$ ls script/
+aspectpad.sh
+
+gilda:imagemagick anupama$ ls -la lib/
+total 38672
+drwxr-xr-x  41 anupama  wheel     1394 28 Oct 15:37 .
+drwxr-xr-x   6 anupama  wheel      204 28 Oct 15:37 ..
+drwxr-xr-x   3 anupama  wheel      102 28 Oct 15:37 ImageMagick-6.9.5
+-rw-r--r--   1 anupama  wheel      642 24 Aug 13:54 charset.alias
+drwxr-xr-x   6 anupama  wheel      204 28 Oct 15:37 gettext
+-rw-r--r--   1 anupama  wheel  1108152 24 Aug 14:03 libMagick++-6.Q16.a
+-rw-r--r--   1 anupama  wheel     1691 24 Aug 14:03 libMagick++-6.Q16.la
+-rw-r--r--   1 anupama  wheel  7242008 24 Aug 14:03 libMagickCore-6.Q16.a
+-rw-r--r--   1 anupama  wheel     1491 24 Aug 14:03 libMagickCore-6.Q16.la
+-rw-r--r--   1 anupama  wheel  2624976 24 Aug 14:03 libMagickWand-6.Q16.a
+-rw-r--r--   1 anupama  wheel     1594 24 Aug 14:03 libMagickWand-6.Q16.la
+-rw-r--r--   1 anupama  wheel    53392 24 Aug 13:52 libasprintf.a
+-rw-r--r--   1 anupama  wheel      943 24 Aug 13:52 libasprintf.la
+-rw-r--r--   1 anupama  wheel   104624 24 Aug 13:54 libbz2.a
+-rw-r--r--   1 anupama  wheel     9400 24 Aug 13:48 libcharset.a
+-rw-r--r--   1 anupama  wheel      938 24 Aug 13:48 libcharset.la
+-rw-r--r--   1 anupama  wheel     1228 24 Aug 13:53 libgettextlib.la
+-rw-r--r--   1 anupama  wheel  1352208 24 Aug 13:53 libgettextpo.a
+-rw-r--r--   1 anupama  wheel     1215 24 Aug 13:53 libgettextpo.la
+-rw-r--r--   1 anupama  wheel     1325 24 Aug 13:53 libgettextsrc.la
+-rw-r--r--   1 anupama  wheel  1292104 24 Aug 13:48 libiconv.a
+-rw-r--r--   1 anupama  wheel      932 24 Aug 13:48 libiconv.la
+-rw-r--r--   1 anupama  wheel   211720 24 Aug 13:53 libintl.a
+-rw-r--r--   1 anupama  wheel     1109 24 Aug 13:53 libintl.la
+-rw-r--r--   1 anupama  wheel   595296 24 Aug 13:57 libjasper.a
+-rw-r--r--   1 anupama  wheel      988 24 Aug 13:57 libjasper.la
+-rw-r--r--   1 anupama  wheel   421824 24 Aug 13:55 libjpeg.a
+-rw-r--r--   1 anupama  wheel     1016 24 Aug 13:55 libjpeg.la
+-rw-r--r--   1 anupama  wheel   281688 24 Aug 13:57 libpng.a
+-rw-r--r--   1 anupama  wheel     1022 24 Aug 13:57 libpng.la
+-rw-r--r--   1 anupama  wheel   281688 24 Aug 13:57 libpng14.a
+-rw-r--r--   1 anupama  wheel     1022 24 Aug 13:57 libpng14.la
+-rw-r--r--   1 anupama  wheel  1376688 24 Aug 13:56 libtiff.a
+-rw-r--r--   1 anupama  wheel     1114 24 Aug 13:56 libtiff.la
+-rw-r--r--   1 anupama  wheel   125408 24 Aug 13:56 libtiffxx.a
+-rw-r--r--   1 anupama  wheel     1211 24 Aug 13:56 libtiffxx.la
+-rw-r--r--   1 anupama  wheel  2495888 24 Aug 13:55 libxml2.a
+-rw-r--r--   1 anupama  wheel     1124 24 Aug 13:55 libxml2.la
+-rw-r--r--   1 anupama  wheel   108264 24 Aug 13:54 libz.a
+drwxr-xr-x  18 anupama  wheel      612 28 Oct 15:37 pkgconfig
+-rw-r--r--   1 anupama  wheel      357 24 Aug 13:55 xml2Conf.sh
+
+gilda:imagemagick anupama$ ls etc/
+ImageMagick-6
+
+gilda:imagemagick anupama$ ls -la bin/
+total 38240
+drwxr-xr-x  9 anupama  wheel      306 28 Oct 15:37 .
+drwxr-xr-x  6 anupama  wheel      204 28 Oct 15:37 ..
+-rwxrwxr-x  1 anupama  wheel     1328 24 Aug 14:03 Magick++-config
+-rwxrwxr-x  1 anupama  wheel     1294 24 Aug 14:03 Magick-config
+-rwxrwxr-x  1 anupama  wheel     1302 24 Aug 14:03 MagickCore-config
+-rwxrwxr-x  1 anupama  wheel     1542 24 Aug 14:03 MagickWand-config
+-rwxrwxr-x  1 anupama  wheel     1289 24 Aug 14:03 Wand-config
+-rwxrwxr-x  1 anupama  wheel  9903736 24 Aug 14:03 convert
+-rwxrwxr-x  1 anupama  wheel  9653688 24 Aug 14:03 identify
+
+------------------------------------------------------------------------
+15 Mar 2019
+ak19
+
+On an Ubuntu 18.04 VM, we found that GLI launched and said imagemagick wasn't installed (despite being bundled) and it would have to find a system version.
+
+The included imagemagick was from a tarball, and when you ran "gs-magick.pl identify", the problem was that it was finding a system libpng, which resulted in the secondary problem that this system libpng then required a different zlib from the bundled zlib:
+
+~/GS309_21Feb2019$ gs-magick.pl identify
+identify: /home/anupama/GS309_21Feb2019/gs2build/bin/linux/imagemagick/lib/libz.so.1: version `ZLIB_1.2.9' not found (required by /usr/lib/x86_64-linux-gnu/libpng16.so.16)
+
+
+Since the linux 64 tarball of imagemagick had been built 6 years ago, while the El Capitan imagemagick tarball was built 2 years ago, we hoped that rebuilding imagemagick again would produce a more static binary that would then bypass the above issue.
+
+Although imagemagick compiled successfully,
+* the command "identify -list format" under section THINGS TO CHECK above, did not include TIFF as one of the supported formats. We require support for gif, jp(e)g, png and tiff.
+* and the command "convert -list configure" did not list "tiff" among the delegates in the DELEGATES line, see https://imagemagick.org/discourse-server/viewtopic.php?t=20635
+
+The imagemagick config.log showed that there were errors with tiff when configuring imagemagick.
+Searching through ImageMagick's config.log for occurrences of --with-tiff showed that despite --with-tiff being switched on, it got switched off because of failed configure tests. (See https://imagemagick.org/discourse-server/viewtopic.php?t=18039)
+
+PROBLEM AND SOLUTION:
+That was with tiff-3.9.4.tar.gz and ImageMagick-6.9.5-4.tar.gz, which was fine on El Capitan but not on Linux where TIFF was not supported with these versions (not just Ubuntu v18.04 but also v16.04).
+* The suggestion at http://lists.endsoftwarepatents.org/archive/html/discuss-gnustep/2001-07/msg00025.html was not helpful: we already appended -lz to our LDFLAGS for ImageMagick to help tiff along on Macs. The same line was already active for Linux too. And preceding the -lz with the insertion of -ltiff made no meaningful difference.
+* Just hiking up the tiff version gradually to tiff-4.0.10 (downloadable along with intermediate versions from https://download.osgeo.org/libtiff/ with tiff 4.0.10 being the latest) made no difference.
+* But in conjunction with ImageMagick-6.9.10-33.tar.gz, the most conservative version available at https://imagemagick.org/download/, imagemagick now compiled successfully with the new tiff-4.0.10, so that TIFF was now finally among the listed supported formats and had "rw" support when `identify -list format` is run. And doing "./convert logo: logo.tiff" followed by "file logo.tiff" shows the logo.tiff file resulting from the conversion to indeed be a TIFF file. (I also converted between png and tiff, and back again, to be doubly sure of the TIFF support.)
+
+
+It is possible that versions of ImageMagick and Tiff intermediate to those above would succeed as well, but that will be a rather long experiment with too many combinations of ImageMagick and Tiff. Since the GS3 tutorials still need to be tested on Mac and Linux machines, I'll see if the tarball can be successfully created on the linux-64bit lsb machine and works on Ubuntu 18.04.
+
+------------------------------------------------------------------------
Index: /gs2-extensions/imagemagick/branches/macos-dev/src/CASCADE-MAKE.sh
===================================================================
--- /gs2-extensions/imagemagick/branches/macos-dev/src/CASCADE-MAKE.sh	(revision 34337)
+++ /gs2-extensions/imagemagick/branches/macos-dev/src/CASCADE-MAKE.sh	(revision 34337)
@@ -0,0 +1,42 @@
+#!/bin/bash
+
+source devel.bash
+
+for d in packages ; do
+    echo "Running $d/CASCADE-MAKE.sh"
+
+    (cd $d ; ./CASCADE-MAKE.sh $*)
+
+    if [ $? != 0 ] ; then
+	echo "Error encountered running $d/CASCADE-MAKE.sh"
+	exit 1
+    fi
+done
+
+if [ ! -d $GEXTIMAGEMAGICK_INSTALLED/script ] ; then
+  echo "Creating 'script' folder in installed area"
+  mkdir $GEXTIMAGEMAGICK_INSTALLED/script
+fi
+
+/bin/cp bin/script/*.sh $GEXTIMAGEMAGICK_INSTALLED/script/.
+
+
+if [ $makedist = "1"  ] ; then
+
+    # fix up symbolic links that use absolute paths to use rel paths instead
+	if [ -d "linux" ] ; then
+	    cd linux/bin
+	else 
+		cd darwin/bin
+	fi
+    /bin/rm -f bzcmp
+    /bin/rm -f bzegrep
+    /bin/rm -f bzfgrep
+    /bin/rm -f bzless
+    ln -s bzdiff bzcmp
+    ln -s bzgrep bzegrep
+    ln -s bzgrep bzfgrep
+    ln -s bzmore bzless    
+    cd ../..
+  default_toplevel_make_dist $GSDLOS
+fi
Index: /gs2-extensions/imagemagick/branches/macos-dev/src/bin/script/aspectpad.sh
===================================================================
--- /gs2-extensions/imagemagick/branches/macos-dev/src/bin/script/aspectpad.sh	(revision 34337)
+++ /gs2-extensions/imagemagick/branches/macos-dev/src/bin/script/aspectpad.sh	(revision 34337)
@@ -0,0 +1,279 @@
+#!/bin/bash
+#
+# Developed by Fred Weinhaus 12/1/2009 .......... revised 12/4/2009
+#
+# USAGE: aspectpad [-a aspect] [-m mode] [-p pcolor] [-t toler] infile outfile
+# USAGE: aspectpad [-help]
+#
+# OPTIONS:
+#
+# -a      aspect	       	aspect ratio value desired; float>=1; default=2
+# -m      mode              mode for aspect; al, ap, l or p; default=al
+#                           l=force landscape pad; p=force portrait pad;
+#                           al=automatic pad (landscape for square images);
+#                           ap=automatic pad (portrait for square images)
+# -p      pcolor            pad color; any valid IM color; default=black
+# -t      toler             aspect tolerance; float>=0; if absolute difference 
+#                           between desired aspect and image aspect is less 
+#                           than or equal to tolerance, then no padding; 
+#                           default=0
+#
+###
+#
+# NAME: ASPECTPAD 
+# 
+# PURPOSE: To pad an image with a color to a specified aspect ratio 
+# and orientation.
+# 
+# DESCRIPTION: ASPECTPAD pads an image with a color to a specified aspect
+# ratio and orientation. The user can choose to force the pad to either 
+# landscape or portrait orientation or preserve the orientation in automatic 
+# mode. All padding will result in the image being centered.
+# 
+# OPTIONS: 
+# 
+# -a aspect ... ASPECT is the desired aspect ratio. Values are floats>=1. 
+# The default=2
+# 
+# -m mode ... MODE is the padding mode. Choices are: l, p, al or ap. When 
+# mode=l, the padding will force the result to be landscape at the desired 
+# aspect value. When mode=p, the padding will force the result to be portrait.
+# When mode=al, the padding will preserve the aspect of the original image, but 
+# will pad a square image into landscape format. When mode=ap, the padding will 
+# preserve the aspect of the original image, but will pad a square image into 
+# portrait format. The default=al.
+# 
+# -p pcolor ... PCOLOR is the desired padding color. Any valid IM color 
+# specification may be used. The default=black
+# 
+# -t toler ... TOLER is the aspect tolerance. If the absolute difference 
+# between desired aspect and image aspect is less than or equal to toler, 
+# then no padding will be applied. Values are floats>=0. The default=0
+# 
+# CAVEAT: No guarantee that this script will work on all platforms, 
+# nor that trapping of inconsistent parameters is complete and 
+# foolproof. Use At Your Own Risk. 
+# 
+######
+#
+
+# set default values
+aspect="2"				# aspect>=1
+mode="al"				# al, ap, l, p; a=auto
+pcolor="black"			# pad color
+toler=0					# toler>=0
+
+# set directory for temporary files
+dir="."    # suggestions are dir="." or dir="/tmp"
+
+# set up functions to report Usage and Usage with Description
+PROGNAME=`type $0 | awk '{print $3}'`  # search for executable on path
+PROGDIR=`dirname $PROGNAME`            # extract directory of program
+PROGNAME=`basename $PROGNAME`          # base name of program
+usage1() 
+	{
+	echo >&2 ""
+	echo >&2 "$PROGNAME:" "$@"
+	sed >&2 -n '/^###/q;  /^#/!q;  s/^#//;  s/^ //;  4,$p' "$PROGDIR/$PROGNAME"
+	}
+usage2() 
+	{
+	echo >&2 ""
+	echo >&2 "$PROGNAME:" "$@"
+	sed >&2 -n '/^######/q;  /^#/!q;  s/^#*//;  s/^ //;  4,$p' "$PROGDIR/$PROGNAME"
+	}
+
+
+# function to report error messages
+errMsg()
+	{
+	echo ""
+	echo $1
+	echo ""
+	usage1
+	exit 1
+	}
+
+
+# function to test for minus at start of value of second part of option 1 or 2
+checkMinus()
+	{
+	test=`echo "$1" | grep -c '^-.*$'`   # returns 1 if match; 0 otherwise
+    [ $test -eq 1 ] && errMsg "$errorMsg"
+	}
+
+# test for correct number of arguments and get values
+if [ $# -eq 0 ]
+	then
+	# help information
+   echo ""
+   usage2
+   exit 0
+elif [ $# -gt 10 ]
+	then
+	errMsg "--- TOO MANY ARGUMENTS WERE PROVIDED ---"
+else
+	while [ $# -gt 0 ]
+		do
+			# get parameter values
+			case "$1" in
+		     -help)    # help information
+					   echo ""
+					   usage2
+					   exit 0
+					   ;;
+				-m)    # get mode
+					   shift  # to get the next parameter
+					   # test if parameter starts with minus sign 
+					   errorMsg="--- INVALID MODE SPECIFICATION ---"
+					   checkMinus "$1"
+					   mode=`echo "$1" | tr '[A-Z]' '[a-z]'`
+					   case "$mode" in 
+					   		l) ;;
+					   		p) ;;
+					   		al) ;;
+					   		ap) ;;
+					   		*) errMsg "--- MODE=$mode IS AN INVALID VALUE ---" 
+					   	esac
+					   ;;
+				-a)    # get aspect
+					   shift  # to get the next parameter
+					   # test if parameter starts with minus sign 
+					   errorMsg="--- INVALID ASPECT SPECIFICATION ---"
+					   checkMinus "$1"
+					   aspect=`expr "$1" : '\([.0-9]*\)'`
+					   aspecttest=`echo "$aspect < 1" | bc`
+					   [ $aspecttest -eq 1 ] && errMsg "--- ASPECT=$aspect MUST BE A FLOAT GREATER THAN OR EQUAL TO 1 ---"
+					   ;;
+				-p)    # get pcolor
+					   shift  # to get the next parameter
+					   # test if parameter starts with minus sign 
+					   errorMsg="--- INVALID PCOLOR SPECIFICATION ---"
+					   checkMinus "$1"
+					   pcolor="$1"
+					   ;;
+				-t)    # get toler
+					   shift  # to get the next parameter
+					   # test if parameter starts with minus sign 
+					   errorMsg="--- INVALID TOLER SPECIFICATION ---"
+					   checkMinus "$1"
+					   toler=`expr "$1" : '\([.0-9]*\)'`
+					   tolertest=`echo "$toler < 0" | bc`
+					   [ $tolertest -eq 1 ] && errMsg "--- TOLER=$toler MUST BE A NON-NEGATIVE FLOAT ---"
+					   ;;
+				 -)    # STDIN and end of arguments
+					   break
+					   ;;
+				-*)    # any other - argument
+					   errMsg "--- UNKNOWN OPTION ---"
+					   ;;
+		     	 *)    # end of arguments
+					   break
+					   ;;
+			esac
+			shift   # next option
+	done
+	#
+	# get infile and outfile
+	infile=$1
+	outfile=$2
+fi
+
+# test that infile provided
+[ "$infile" = "" ] && errMsg "NO INPUT FILE SPECIFIED"
+
+# test that outfile provided
+[ "$outfile" = "" ] && errMsg "NO OUTPUT FILE SPECIFIED"
+
+# setup temporary images
+tmpA1="$dir/aspectpad_1_$$.mpc"
+tmpA2="$dir/aspectpad_1_$$.cache"
+trap "rm -f $tmpA1 $tmpA2; exit 0" 0
+trap "rm -f $tmpA1 $tmpA2; exit 1" 1 2 3 15
+
+
+# read the input image and test validity.
+convert -quiet -regard-warnings "$infile" +repage "$tmpA1" ||
+	errMsg "--- FILE $infile DOES NOT EXIST OR IS NOT AN ORDINARY FILE, NOT READABLE OR HAS ZERO SIZE  ---"
+
+# get size and aspect ratio of input
+ww=`convert $tmpA1 -ping -format "%w" info:`
+hh=`convert $tmpA1 -ping -format "%h" info:`
+wratio=`convert xc: -format "%[fx:$ww/$hh]" info:`
+hratio=`convert xc: -format "%[fx:$hh/$ww]" info:`
+#echo "ww=$ww; hh=$hh wratio=$wratio; hratio=$hratio"
+
+# test if aspect >= ratio
+wtest=`convert xc: -format "%[fx:$aspect>=$wratio?1:0]" info:`
+htest=`convert xc: -format "%[fx:$aspect>=$hratio?1:0]" info:`
+#echo "wtest=$wtest; htest=$htest"
+
+# test if within toler of desired aspect
+tratio=`convert xc: -format "%[fx:$wratio>=1?$wratio:$hratio]" info:`
+ttest=`convert xc: -format "%[fx:abs($tratio-$aspect)<=$toler?1:0]" info:`
+#echo "tratio=$tratio; ttest=$ttest"
+
+# copy input to output if image aspect is within toler
+if [ $ttest -eq 1 ]; then
+	convert $tmpA1 $outfile
+	exit
+fi
+
+# force landscape mode
+if [ "$mode" = "l" -a $wtest -eq 1 ]; then
+	ww=`convert xc: -format "%[fx:$hh*$aspect]" info:`
+	convert $tmpA1 -gravity center -background "$pcolor" -extent ${ww}x${hh} $outfile
+	exit
+elif [ "$mode" = "l" -a $wtest -eq 0 ]; then
+	hh=`convert xc: -format "%[fx:$hh*$wratio/$aspect]" info:`
+	convert $tmpA1 -gravity center -background "$pcolor" -extent ${ww}x${hh} $outfile
+	exit
+fi
+
+# force portrait mode
+if [ "$mode" = "p" -a $htest -eq 1 ]; then
+	hh=`convert xc: -format "%[fx:$ww*$aspect]" info:`
+	convert $tmpA1 -gravity center -background "$pcolor" -extent ${ww}x${hh} $outfile
+	exit
+elif [ "$mode" = "p" -a $htest -eq 0 ]; then
+	ww=`convert xc: -format "%[fx:$ww*$hratio/$aspect]" info:`
+	convert $tmpA1 -gravity center -background "$pcolor" -extent ${ww}x${hh} $outfile
+	exit
+fi
+
+
+# auto square image
+if [ "$mode" = "al" -a $ww -eq $hh ]; then
+	ww=`convert xc: -format "%[fx:$hh*$aspect]" info:`
+	convert $tmpA1 -gravity center -background "$pcolor" -extent ${ww}x${hh} $outfile
+	exit
+elif [ "$mode" = "ap" -a $ww -eq $hh ]; then
+	hh=`convert xc: -format "%[fx:$ww*$aspect]" info:`
+	convert $tmpA1 -gravity center -background "$pcolor" -extent ${ww}x${hh} $outfile
+	exit
+fi
+
+
+# auto landscape image 
+if [ $ww -gt $hh -a $wtest -eq 1 ]; then
+	ww=`convert xc: -format "%[fx:$hh*$aspect]" info:`
+	convert $tmpA1 -gravity center -background "$pcolor" -extent ${ww}x${hh} $outfile
+	exit
+elif [ $ww -gt $hh -a $wtest -eq 0 ]; then
+	hh=`convert xc: -format "%[fx:$hh*$wratio/$aspect]" info:`
+	convert $tmpA1 -gravity center -background "$pcolor" -extent ${ww}x${hh} $outfile
+	exit
+fi
+
+
+# auto portrait image
+if [ $hh -gt $ww -a $htest -eq 1 ]; then
+	hh=`convert xc: -format "%[fx:$ww*$aspect]" info:`
+	convert $tmpA1 -gravity center -background "$pcolor" -extent ${ww}x${hh} $outfile
+	exit
+elif [ $hh -gt $ww -a $htest -eq 0 ]; then
+	ww=`convert xc: -format "%[fx:$ww*$hratio/$aspect]" info:`
+	convert $tmpA1 -gravity center -background "$pcolor" -extent ${ww}x${hh} $outfile
+	exit
+fi
+
Index: /gs2-extensions/imagemagick/branches/macos-dev/src/devel.bash
===================================================================
--- /gs2-extensions/imagemagick/branches/macos-dev/src/devel.bash	(revision 34337)
+++ /gs2-extensions/imagemagick/branches/macos-dev/src/devel.bash	(revision 34337)
@@ -0,0 +1,18 @@
+#!/bin/bash
+
+if [ -d cascade-make ] ; then
+  source cascade-make/lib/cascade-lib.bash GEXTIMAGEMAGICK . $*
+fi
+
+if [ -z $GEXTIMAGEMAGICK ] ; then
+  source setup.bash
+fi
+
+# for darwin, want to be backwards compatible upto and incl Mountain Lion
+# to avoid "Illegal Instruction 4" errors when running imgmagick convert
+# on older Mac
+if [ "x$GSDLOS" = "xdarwin" ] ; then
+    export CFLAGS="-mmacosx-version-min=10.8 $CFLAGS"
+    export CXXFLAGS="-mmacosx-version-min=10.8 $CXXFLAGS"
+    export LDFLAGS="-mmacosx-version-min=10.8 $LDFLAGS"
+fi
Index: /gs2-extensions/imagemagick/branches/macos-dev/src/packages/CASCADE-MAKE.sh
===================================================================
--- /gs2-extensions/imagemagick/branches/macos-dev/src/packages/CASCADE-MAKE.sh	(revision 34337)
+++ /gs2-extensions/imagemagick/branches/macos-dev/src/packages/CASCADE-MAKE.sh	(revision 34337)
@@ -0,0 +1,18 @@
+#!/bin/bash
+
+source ../cascade-make/lib/cascade-lib.bash GEXTIMAGEMAGICK .. $*
+
+# Need to compile up JPEG before TIFF, since TIFF is dependent on libjpeg.so
+# (else it will find a system libjpeg.so, which will be libjpeg.so.62 and not the included libjpeg.so.8)
+
+#for d in LIBZ LIBBZ2 JPEG TIFF GS LIBPNG JPEG2000 IMAGEMAGICK ; do
+for d in LIBICONV GETTEXT PKG-CONFIG   LIBZ LIBBZ2  LIBXML JPEG TIFF LIBPNG JPEG2000 GS IMAGEMAGICK ; do
+    echo "    Running CASCADE-MAKE/$d.sh"
+
+    ./CASCADE-MAKE/$d.sh $*
+
+    if [ $? != 0 ] ; then
+	echo "Error encountered running CASCADE-MAKE/$d.sh"
+	exit 1
+    fi
+done
Index: /gs2-extensions/imagemagick/branches/macos-dev/src/packages/CASCADE-MAKE/GETTEXT.sh
===================================================================
--- /gs2-extensions/imagemagick/branches/macos-dev/src/packages/CASCADE-MAKE/GETTEXT.sh	(revision 34337)
+++ /gs2-extensions/imagemagick/branches/macos-dev/src/packages/CASCADE-MAKE/GETTEXT.sh	(revision 34337)
@@ -0,0 +1,36 @@
+#!/bin/bash
+
+package=gettext
+#version=-0.18.1.1
+version=-0.18.2
+#version=-0.19.6
+
+progname=$0
+
+source ../cascade-make/lib/cascade-lib.bash GEXTIMAGEMAGICK ../.. $*
+
+prefix=$GEXTIMAGEMAGICK_INSTALLED
+
+if [ "x$CROSSCONFIGURE_ARGS" != "x" ] ; then
+
+  if [ $crossOS = "android" ] ; then
+    export CROSSCONFIGURE_VARS="$CROSSCONFIGURE_VARS \
+          gl_cv_header_working_stdint_h=yes"
+  fi
+
+  if [ $crossOS = "windows" ] ; then
+    export CROSSCONFIGURE_VARS="$CROSSCONFIGURE_VARS \
+          gl_cv_func_memchr_works=yes
+          ac_cv_func_strnlen_working=yes"
+  fi
+fi
+
+opt_run_untar $force_untar $auto_untar $package $version
+opt_run_configure $force_config $auto_config $package $version $prefix --without-emacs --without-git --disable-shared
+
+opt_run_make $compile $package $version
+opt_run_make $install $package $version "install"
+opt_run_make $clean $package $version "clean"
+opt_run_make $distclean $package $version "distclean"
+
+opt_run_tarclean $tarclean $package $version
Index: /gs2-extensions/imagemagick/branches/macos-dev/src/packages/CASCADE-MAKE/GS.sh
===================================================================
--- /gs2-extensions/imagemagick/branches/macos-dev/src/packages/CASCADE-MAKE/GS.sh	(revision 34337)
+++ /gs2-extensions/imagemagick/branches/macos-dev/src/packages/CASCADE-MAKE/GS.sh	(revision 34337)
@@ -0,0 +1,20 @@
+#!/bin/bash
+
+package=ghostscript
+version=-9.15
+
+progname=$0
+
+source ../cascade-make/lib/cascade-lib.bash GEXTIMAGEMAGICK ../.. $*
+
+prefix=$GEXTIMAGEMAGICK_INSTALLED
+
+opt_run_untar $force_untar $auto_untar $package $version
+opt_run_configure $force_config $auto_config $package $version $prefix --without-x
+
+opt_run_make $compile $package $version
+opt_run_make $install $package $version "install"
+opt_run_make $clean $package $version "clean"
+opt_run_make $distclean $package $version "distclean"
+
+opt_run_tarclean $tarclean $package $version
Index: /gs2-extensions/imagemagick/branches/macos-dev/src/packages/CASCADE-MAKE/IMAGEMAGICK.sh
===================================================================
--- /gs2-extensions/imagemagick/branches/macos-dev/src/packages/CASCADE-MAKE/IMAGEMAGICK.sh	(revision 34337)
+++ /gs2-extensions/imagemagick/branches/macos-dev/src/packages/CASCADE-MAKE/IMAGEMAGICK.sh	(revision 34337)
@@ -0,0 +1,41 @@
+#!/bin/bash
+
+package=ImageMagick
+#version=-6.9.5-4
+version=-6.9.10-33
+
+progname=$0
+
+source ../cascade-make/lib/cascade-lib.bash GEXTIMAGEMAGICK ../.. $*
+
+prefix=$GEXTIMAGEMAGICK_INSTALLED
+
+export CFLAGS="$CFLAGS -I$GEXTIMAGEMAGICK_INSTALLED/include"
+export CPPFLAGS="$CPPFLAGS -I$GEXTIMAGEMAGICK_INSTALLED/include"
+export CXXFLAGS="$CXXFLAGS -I$GEXTIMAGEMAGICK_INSTALLED/include"
+# We need to add libz to LDFLAGS to get the configure test for libtiff to succeed
+# (only found to be necessary on an uncooperative mac)
+export LDFLAGS="$LDFLAGS -L$GEXTIMAGEMAGICK_INSTALLED/lib -lz"
+export LD_LIBRARY_PATH="$GEXTIMAGEMAGICK_INSTALLED/lib"
+
+# If on darwin, check if clang exists. If so, use that as CC, in place of gcc
+# use command -v instead of which to check if a program exists. 
+# http://stackoverflow.com/questions/592620/check-if-a-program-exists-from-a-bash-script
+if [ "x$GSDLOS" = "xdarwin" ] ; then
+    if command -v clang > /dev/null 2>&1; then
+	echo "Found clang compiler. Switching CC to clang"
+	CROSSCONFIGURE_VARS="CC=clang"
+    fi
+fi
+
+# it's going to generate the ghostscript binary not ghostscript library
+# so --without-gslib
+opt_run_untar $force_untar $auto_untar $package $version
+opt_run_configure $force_config $auto_config $package $version $prefix --without-gslib --disable-shared 
+
+opt_run_make $compile $package $version
+opt_run_make $install $package $version "install"
+opt_run_make $clean $package $version "clean"
+opt_run_make $distclean $package $version "distclean"
+
+opt_run_tarclean $tarclean $package $version
Index: /gs2-extensions/imagemagick/branches/macos-dev/src/packages/CASCADE-MAKE/JPEG.sh
===================================================================
--- /gs2-extensions/imagemagick/branches/macos-dev/src/packages/CASCADE-MAKE/JPEG.sh	(revision 34337)
+++ /gs2-extensions/imagemagick/branches/macos-dev/src/packages/CASCADE-MAKE/JPEG.sh	(revision 34337)
@@ -0,0 +1,27 @@
+#!/bin/bash
+
+package=jpeg
+version=-8b
+
+progname=$0
+
+source ../cascade-make/lib/cascade-lib.bash GEXTIMAGEMAGICK ../.. $*
+
+prefix=$GEXTIMAGEMAGICK_INSTALLED
+
+
+export CFLAGS="$CFLAGS -I$GEXTIMAGEMAGICK_INSTALLED/include"
+export CPPFLAGS="$CPPFLAGS -I$GEXTIMAGEMAGICK_INSTALLED/include"
+export CXXFLAGS="$CXXFLAGS -I$GEXTIMAGEMAGICK_INSTALLED/include"
+export LDFLAGS="$LDFLAGS -L$GEXTIMAGEMAGICK_INSTALLED/lib"
+
+opt_run_untar $force_untar $auto_untar $package $version
+opt_run_configure $force_config $auto_config $package $version $prefix \
+  --disable-shared
+
+opt_run_make $compile $package $version
+opt_run_make $install $package $version "install"
+opt_run_make $clean $package $version "clean"
+opt_run_make $distclean $package $version "distclean"
+
+opt_run_tarclean $tarclean $package $version
Index: /gs2-extensions/imagemagick/branches/macos-dev/src/packages/CASCADE-MAKE/JPEG2000.sh
===================================================================
--- /gs2-extensions/imagemagick/branches/macos-dev/src/packages/CASCADE-MAKE/JPEG2000.sh	(revision 34337)
+++ /gs2-extensions/imagemagick/branches/macos-dev/src/packages/CASCADE-MAKE/JPEG2000.sh	(revision 34337)
@@ -0,0 +1,25 @@
+#!/bin/bash
+
+package=jasper
+version=-1.900.1
+
+progname=$0
+
+source ../cascade-make/lib/cascade-lib.bash GEXTIMAGEMAGICK ../.. $*
+
+prefix=$GEXTIMAGEMAGICK_INSTALLED
+
+export CFLAGS="$CFLAGS -I$GEXTIMAGEMAGICK_INSTALLED/include -fPIC"
+export CPPFLAGS="$CPPFLAGS -I$GEXTIMAGEMAGICK_INSTALLED/include -fPIC"
+export CXXFLAGS="$CXXFLAGS -I$GEXTIMAGEMAGICK_INSTALLED/include -fPIC"
+export LDFLAGS="$LDFLAGS -L$GEXTIMAGEMAGICK_INSTALLED/lib"
+
+opt_run_untar $force_untar $auto_untar $package $version
+opt_run_configure $force_config $auto_config $package $version $prefix
+
+opt_run_make $compile $package $version
+opt_run_make $install $package $version "install"
+opt_run_make $clean $package $version "clean"
+opt_run_make $distclean $package $version "distclean"
+
+opt_run_tarclean $tarclean $package $version
Index: /gs2-extensions/imagemagick/branches/macos-dev/src/packages/CASCADE-MAKE/LIBBZ2.sh
===================================================================
--- /gs2-extensions/imagemagick/branches/macos-dev/src/packages/CASCADE-MAKE/LIBBZ2.sh	(revision 34337)
+++ /gs2-extensions/imagemagick/branches/macos-dev/src/packages/CASCADE-MAKE/LIBBZ2.sh	(revision 34337)
@@ -0,0 +1,60 @@
+#!/bin/bash
+
+package=bzip2
+version=-1.0.6
+
+progname=$0
+
+source ../cascade-make/lib/cascade-lib.bash GEXTIMAGEMAGICK ../.. $*
+
+prefix=$GEXTIMAGEMAGICK_INSTALLED
+
+if [ "x$CROSSCONFIGURE_ARGS" != "x" ] ; then
+  export CPP="$crossHost-cpp"
+  export CC="$crossHost-gcc"
+  export CXX="$crossHost-g++"
+  export LD="$crossHost-ld"
+  export AR="$crossHost-ar"
+  export RANLIB="$crossHost-ranlib"
+fi
+
+
+fixmake=0
+
+if [ "x$CROSSCONFIGURE_ARGS" != "x" ] ; then
+
+  if [ $force_untar = "1" ] ; then
+    fixmake=1
+  elif [ $auto_config = "1" ] && [ ! -d $package$version ] ; then
+    fixmake=1
+  fi
+fi
+
+
+opt_run_untar $force_untar $auto_untar $package $version
+
+if [ $fixmake = "1" ] ; then
+
+  cat $package$version/Makefile \
+   | sed "s/^CC=gcc/CC=$crossHost-gcc/" \
+   | sed "s/^AR=ar/AR=$crossHost-ar/" \
+   | sed "s/^RANLIB=ranlib/RANLIB=$crossHost-ranlib/" \
+   > $package$version/Makefile.cross
+  /bin/mv $package$version/Makefile.cross $package$version/Makefile
+fi
+
+
+#custom opt_run_make 'compile'
+if [ $compile = 1 ] ; then
+    (cd $package$version ; make CFLAGS="$CFLAGS -fPIC")
+fi
+
+#custom opt_run_make 'install'
+if [ $install = 1 ] ; then
+    (cd $package$version ; make install PREFIX=$prefix) 
+fi
+
+opt_run_make $clean $package $version "clean"
+opt_run_make $distclean $package $version "distclean"
+
+opt_run_tarclean $tarclean $package $version
Index: /gs2-extensions/imagemagick/branches/macos-dev/src/packages/CASCADE-MAKE/LIBICONV.sh
===================================================================
--- /gs2-extensions/imagemagick/branches/macos-dev/src/packages/CASCADE-MAKE/LIBICONV.sh	(revision 34337)
+++ /gs2-extensions/imagemagick/branches/macos-dev/src/packages/CASCADE-MAKE/LIBICONV.sh	(revision 34337)
@@ -0,0 +1,38 @@
+#!/bin/bash
+
+package=gs-libiconv
+version=-1.14
+
+progname=$0
+
+source ../cascade-make/lib/cascade-lib.bash GEXTIMAGEMAGICK ../.. $*
+
+prefix=$GEXTIMAGEMAGICK_INSTALLED
+
+if [ "x$crossOS" = "xandroid" ] ; then
+  # Stops configure generating a local 'stdint.h' in 'srclib' folder
+  # (when this file was generated, caused no end of issues with chaining
+  #  standard header files, errors with time_t, pid_t etc)
+  # Fix came from:
+  #  http://stackoverflow.com/questions/9053702/building-libiconv-fails-with-the-android-standalone-toolchain
+
+  extra_config_args="gl_cv_header_working_stdint_h=yes"
+else
+  extra_config_args=
+fi
+
+
+opt_run_untar $force_untar $auto_untar $package $version
+opt_run_configure $force_config $auto_config $package $version $prefix \
+  $extra_config_args \
+  --enable-static \
+  --disable-shared \
+
+#export DYLIB_COMPATIBILITY_VERSION=7.0.0
+
+opt_run_make $compile $package $version
+opt_run_make $install $package $version "install"
+opt_run_make $clean $package $version "clean"
+opt_run_make $distclean $package $version "distclean"
+
+opt_run_tarclean $tarclean $package $version
Index: /gs2-extensions/imagemagick/branches/macos-dev/src/packages/CASCADE-MAKE/LIBPNG.sh
===================================================================
--- /gs2-extensions/imagemagick/branches/macos-dev/src/packages/CASCADE-MAKE/LIBPNG.sh	(revision 34337)
+++ /gs2-extensions/imagemagick/branches/macos-dev/src/packages/CASCADE-MAKE/LIBPNG.sh	(revision 34337)
@@ -0,0 +1,27 @@
+#!/bin/bash
+
+package=libpng
+version=-1.4.4
+
+progname=$0
+
+source ../cascade-make/lib/cascade-lib.bash GEXTIMAGEMAGICK ../.. $*
+
+prefix=$GEXTIMAGEMAGICK_INSTALLED
+
+export CFLAGS="$CFLAGS -I$GEXTIMAGEMAGICK_INSTALLED/include"
+export CPPFLAGS="$CPPFLAGS -I$GEXTIMAGEMAGICK_INSTALLED/include"
+export CXXFLAGS="$CXXFLAGS -I$GEXTIMAGEMAGICK_INSTALLED/include"
+export LDFLAGS="$LDFLAGS -L$GEXTIMAGEMAGICK_INSTALLED/lib"
+export LD_LIBRARY_PATH="$GEXTIMAGEMAGICK_INSTALLED/lib"
+
+opt_run_untar $force_untar $auto_untar $package $version
+opt_run_configure $force_config $auto_config $package $version $prefix \
+  --disable-shared
+
+opt_run_make $compile $package $version
+opt_run_make $install $package $version "install"
+opt_run_make $clean $package $version "clean"
+opt_run_make $distclean $package $version "distclean"
+
+opt_run_tarclean $tarclean $package $version
Index: /gs2-extensions/imagemagick/branches/macos-dev/src/packages/CASCADE-MAKE/LIBXML.sh
===================================================================
--- /gs2-extensions/imagemagick/branches/macos-dev/src/packages/CASCADE-MAKE/LIBXML.sh	(revision 34337)
+++ /gs2-extensions/imagemagick/branches/macos-dev/src/packages/CASCADE-MAKE/LIBXML.sh	(revision 34337)
@@ -0,0 +1,27 @@
+#!/bin/bash
+
+# libxml2.2.9.0 was modified for Greenstone to allow compilation to succeed on a Mac, so it has acquired a 'gs-' prefix
+package=gs-libxml2
+version=-2.9.0
+
+progname=$0
+
+source ../cascade-make/lib/cascade-lib.bash GEXTIMAGEMAGICK ../.. $*
+
+prefix=$GEXTIMAGEMAGICK_INSTALLED
+
+export CFLAGS="$CFLAGS -I$GEXTIMAGEMAGICK_INSTALLED/include -DLIBXML_STATIC"
+export CPPFLAGS="$CPPFLAGS -I$GEXTIMAGEMAGICK_INSTALLED/include"
+export CXXFLAGS="$CXXFLAGS -I$GEXTIMAGEMAGICK_INSTALLED/include"
+export LDFLAGS="$LDFLAGS -L$GEXTIMAGEMAGICK_INSTALLED/lib"
+
+opt_run_untar $force_untar $auto_untar $package $version
+opt_run_configure $force_config $auto_config $package $version $prefix \
+  --without-python --disable-shared
+
+opt_run_make $compile $package $version
+opt_run_make $install $package $version "install"
+opt_run_make $clean $package $version "clean"
+opt_run_make $distclean $package $version "distclean"
+
+opt_run_tarclean $tarclean $package $version
Index: /gs2-extensions/imagemagick/branches/macos-dev/src/packages/CASCADE-MAKE/LIBZ.sh
===================================================================
--- /gs2-extensions/imagemagick/branches/macos-dev/src/packages/CASCADE-MAKE/LIBZ.sh	(revision 34337)
+++ /gs2-extensions/imagemagick/branches/macos-dev/src/packages/CASCADE-MAKE/LIBZ.sh	(revision 34337)
@@ -0,0 +1,55 @@
+#!/bin/bash
+
+package=zlib
+version=-1.2.7
+
+progname=$0
+
+source ../cascade-make/lib/cascade-lib.bash GEXTIMAGEMAGICK ../.. $*
+
+prefix=$GEXTIMAGEMAGICK_INSTALLED
+
+if [ "x$CROSSCONFIGURE_ARGS" != "x" ] ; then
+  if [ "x$crossOS" = "xwindows" ] ; then
+      export LDSHAREDLIBC=-lcrtdll
+  fi
+    # zlib configure does not support '--host'
+    export CROSSCONFIGURE_ARGS=
+fi
+
+
+opt_run_untar $force_untar $auto_untar $package $version
+
+#opt_run_configure $force_config $auto_config $package $version $prefix
+
+if [ $auto_config = "1" ] ; then
+  if [ ! -f $package$version/configure.log ] ; then
+    force_config=1
+  fi
+
+fi
+
+if [ $force_config = "1" ] ; then
+    echo "[pushd $package$version]"
+    ( cd $package$version ; \
+      echo $CROSSCONFIGURE_VARS ./configure --static --prefix="$prefix" $CROSSCONFIGURE_ARGS $@ ; \
+      eval $CROSSCONFIGURE_VARS ./configure --static --prefix="$prefix" $CROSSCONFIGURE_ARGS $@ )
+    if [ $? != 0 ] ; then
+        echo "      Error encountered running *configure* stage of $progname"
+        exit 1
+    fi
+    echo "[popd]"
+  else
+    if [ $auto_config = "1" ] ; then
+      echo "Found top-level for ${progname%.*} => no need to run ./configure"
+    fi
+fi
+
+
+
+opt_run_make $compile $package $version
+opt_run_make $install $package $version "install"
+opt_run_make $clean $package $version "clean"
+opt_run_make $distclean $package $version "distclean"
+
+opt_run_tarclean $tarclean $package $version
Index: /gs2-extensions/imagemagick/branches/macos-dev/src/packages/CASCADE-MAKE/PKG-CONFIG.sh
===================================================================
--- /gs2-extensions/imagemagick/branches/macos-dev/src/packages/CASCADE-MAKE/PKG-CONFIG.sh	(revision 34337)
+++ /gs2-extensions/imagemagick/branches/macos-dev/src/packages/CASCADE-MAKE/PKG-CONFIG.sh	(revision 34337)
@@ -0,0 +1,48 @@
+#!/bin/bash
+
+package=pkg-config
+#version=-0.25
+version=-0.27
+
+progname=$0
+
+source ../cascade-make/lib/cascade-lib.bash GEXTIMAGEMAGICK ../.. $*
+
+prefix=$GEXTIMAGEMAGICK_INSTALLED
+
+export CFLAGS="$CFLAGS -I$GEXTIMAGEMAGICK_INSTALLED/include"
+export CXXFLAGS="$CXXFLAGS -I$GEXTIMAGEMAGICK_INSTALLED/include"
+export LDFLAGS="$LDFLAGS -L$GEXTIMAGEMAGICK_INSTALLED/lib"
+export DYLD_LIBRARY_PATH=
+
+opt_run_untar $force_untar $auto_untar $package $version
+
+# On Mac: if there's an error about
+# "#error GNU libiconv not in use but included iconv.h is from libiconv"
+# then prepend --with-libiconv before --with-internal-glib for darwin too
+
+# On a CentOS build encountered an error related to dtrace 
+# (potentially related to static/dynamic libraries and whether the '-dev' header
+#  files are included)
+# Solution is to disable dtrace with 
+#    --disable-dtrace
+# In 'glib' in gnomelib-ext  a similar error occurred relating to 'systemtap'.  If this was
+# to occur here, then presumably the related fix of '--disable-systemtap'
+# would suffice.
+# Potentially related link to all this (from the glib:CASCADE-MAKE comment)
+#    https://gitlab.gnome.org/GNOME/glib/issues/653
+
+if [ "x$GSDLOS" = "xdarwin" ] ; then
+    LIBS=-lintl opt_run_configure $force_config $auto_config $package $version $prefix \
+	--with-internal-glib --disable-shared
+else
+    opt_run_configure $force_config $auto_config $package $version $prefix \
+		      --with-libiconv --with-internal-glib --disable-shared --disable-dtrace
+fi
+
+opt_run_make $compile $package $version
+opt_run_make $install $package $version "install"
+opt_run_make $clean $package $version "clean"
+opt_run_make $distclean $package $version "distclean"
+
+opt_run_tarclean $tarclean $package $version
Index: /gs2-extensions/imagemagick/branches/macos-dev/src/packages/CASCADE-MAKE/TIFF.sh
===================================================================
--- /gs2-extensions/imagemagick/branches/macos-dev/src/packages/CASCADE-MAKE/TIFF.sh	(revision 34337)
+++ /gs2-extensions/imagemagick/branches/macos-dev/src/packages/CASCADE-MAKE/TIFF.sh	(revision 34337)
@@ -0,0 +1,24 @@
+#!/bin/bash
+
+package=tiff
+#version=-3.9.4
+version=-4.0.10
+
+progname=$0
+
+source ../cascade-make/lib/cascade-lib.bash GEXTIMAGEMAGICK ../.. $*
+
+prefix=$GEXTIMAGEMAGICK_INSTALLED
+
+# Need to configure with jpeg-8 library and include directories,
+# else configure of tiff will look for libjpeg.so.62 and end up compiling against that
+# http://www.imagemagick.org/discourse-server/viewtopic.php?f=2&t=18566
+opt_run_untar $force_untar $auto_untar $package $version
+opt_run_configure $force_config $auto_config $package $version $prefix --with-jpeg-lib-dir=$GEXTIMAGEMAGICK_INSTALLED/lib --with-jpeg-include-dir=$GEXTIMAGEMAGICK_INSTALLED/include --disable-shared
+
+opt_run_make $compile $package $version
+opt_run_make $install $package $version "install"
+opt_run_make $clean $package $version "clean"
+opt_run_make $distclean $package $version "distclean"
+
+opt_run_tarclean $tarclean $package $version
Index: /gs2-extensions/imagemagick/branches/macos-dev/src/packages/README.txt
===================================================================
--- /gs2-extensions/imagemagick/branches/macos-dev/src/packages/README.txt	(revision 34337)
+++ /gs2-extensions/imagemagick/branches/macos-dev/src/packages/README.txt	(revision 34337)
@@ -0,0 +1,38 @@
+README
+
+This file tracks changes made to imagemagick/packages for Greenstone.
+
+1. libxml2-2.9.0 seems to contain changes for Greenstone, resulting in a gs-libxml2-2.9.0 that we use instead.
+
+Not sure what the changes are. It was first committed with revision 30675 by Dr Bainbridge, not as the libxml version but directly as the gs-libxml version:
+http://trac.greenstone.org/browser/gs2-extensions/imagemagick/trunk/src/packages/gs-libxml2-2.9.0.tar.gz
+
+And CASCADE-MAKE/LIBXML.SH only states
+
+    libxml2.2.9.0 was modified for Greenstone to allow compilation to succeed on a Mac, so it has acquired a 'gs-' prefix
+
+
+2. 13 July 2017
+ak19
+
+To get imagemagick's libiconv to compile up on Ubuntu 16.04 (a machine that contains perl 5.22.1, but where I was also trying with perl 5.24.x), I found that imagemagick failed to compile with an error about gets vs fgets. The error message was:
+
+   
+> stdio.h:1010:1: error: âgetsâ undeclared here (not in a function)
+>  _GL_WARN_ON_USE (gets, "gets is a security hole - use fgets
+> instead");
+
+The following was the solution, found at https://lists.gnu.org/archive/html/bug-gnu-libiconv/2016-04/msg00001.html
+
+******************************
+698c698,703
+< _GL_WARN_ON_USE (gets, "gets is a security hole - use fgets instead");
+---
+> // Needs a patch to compile imagemagick (testing on Ubuntu v 16.04 LTS)
+> // https://gist.github.com/paulczar/5493708
+> // https://lists.gnu.org/archive/html/bug-gnu-libiconv/2016-04/msg00001.html
+> # if defined(__GLIBC__) && !defined(__UCLIBC__) && !__GLIBC_PREREQ(2, 16)
+>   _GL_WARN_ON_USE (gets, "gets is a security hole - use fgets instead");
+> # endif
+******************************
+
Index: /gs2-extensions/imagemagick/branches/macos-dev/src/setup.bash
===================================================================
--- /gs2-extensions/imagemagick/branches/macos-dev/src/setup.bash	(revision 34337)
+++ /gs2-extensions/imagemagick/branches/macos-dev/src/setup.bash	(revision 34337)
@@ -0,0 +1,62 @@
+extdesc="the ImageMagick extension"
+
+full_setup=`pwd`/${BASH_SOURCE}
+fulldir=${full_setup%/*}
+fulldir=${fulldir%/.}
+
+if [ "x$GSDLHOME" = "x" ] ; then
+  if [ -e ../../setup.bash ] ; then
+    export gsopt_noexts=1 && pushd ../.. && source setup.bash && popd 
+    export gsopt_noexts=
+  else
+    # backstop
+    GSDLOS=`uname -s | tr '[A-Z]' '[a-z]'`
+    # check for running bash under cygwin
+    if test "`echo $GSDLOS | sed 's/cygwin//'`" != "$GSDLOS" ; then
+      GSDLOS=windows
+    fi 
+
+  fi
+fi
+
+if [ "x$GEXTIMAGEMAGICK" = "x" ] ; then
+  export GEXTIMAGEMAGICK=$fulldir
+  export GEXTIMAGEMAGICK_INSTALLED=$GEXTIMAGEMAGICK/$GSDLOS
+
+  # Developer setting (for compilation: configure in ImageMagick)
+  # better in devel.bash?
+  export PKG_CONFIG_PATH="$GEXTIMAGEMAGICK_INSTALLED/lib/pkgconfig:$PKG_CONFIG_PATH"
+
+  export MAGICK_HOME=$GEXTIMAGEMAGICK_INSTALLED
+  export PATH=$GEXTIMAGEMAGICK_INSTALLED/bin:$GEXTIMAGEMAGICK_INSTALLED/script:$PATH
+
+  if [ "x$LD_LIBRARY_PATH" = "x" ] ; then
+    export LD_LIBRARY_PATH=$GEXTIMAGEMAGICK_INSTALLED/lib
+  else
+    export LD_LIBRARY_PATH=$GEXTIMAGEMAGICK_INSTALLED/lib:$LD_LIBRARY_PATH
+  fi
+  if [ "x$DYLD_FALLBACK_LIBRARY_PATH" = "x" ] ; then
+    export DYLD_FALLBACK_LIBRARY_PATH=$GEXTIMAGEMAGICK_INSTALLED/lib
+  else
+    export DYLD_FALLBACK_LIBRARY_PATH=$GEXTIMAGEMAGICK_INSTALLED/lib:$DYLD_FALLBACK_LIBRARY_PATH
+  fi
+
+  if [ -e "devel-srcpack" ] ; then
+    export LD_LIBRARY_PATH=$GEXTIMAGEMAGICK_INSTALLED/devel/lib:$LD_LIBRARY_PATH
+    export DYLD_FALLBACK_LIBRARY_PATH=$GEXTIMAGEMAGICK_INSTALLED/devel/lib:$DYLD_FALLBACK_LIBRARY_PATH
+  fi
+
+  
+  extdir=${GEXTIMAGEMAGICK##*/}
+
+  if [ "x$GSDLEXTS" = "x" ] ; then
+    export GSDLEXTS=$extdir
+  else 
+    export GSDLEXTS=$GSDLEXTS:$extdir
+  fi
+
+
+  echo "+Your environment is now setup for $extdesc"
+else
+  echo "+Your environment is already setup for $extdesc"
+fi
Index: /gs2-extensions/imagemagick/branches/macos-dev/src/setup.bat
===================================================================
--- /gs2-extensions/imagemagick/branches/macos-dev/src/setup.bat	(revision 34337)
+++ /gs2-extensions/imagemagick/branches/macos-dev/src/setup.bat	(revision 34337)
@@ -0,0 +1,58 @@
+@echo off
+pushd "%CD%"
+CD /D "%~dp0"
+set GSDLLANG=en
+set extdesc="the ImageMagick extension"
+
+if "%OS%" == "Windows_NT" goto WinNT
+if "%OS%" == "" goto Win95
+if "%GSDLLANG%" == "en" echo Setup failed - your PATH has not been set
+if "%GSDLLANG%" == "es" echo No se pudo realizar la configuraci¢n - no se ha establecido la RUTA.
+if "%GSDLLANG%" == "fr" echo Echc de l'installation - votre variable PATH n'a pas t ajuste
+if "%GSDLLANG%" == "ru" echo áâ ­®¢ª  ­¥ ã€ « áì -  ­¥ ¡ë« ãáâ ­®¢«¥­
+goto End
+
+:WinNT
+set GEXTIMAGEMAGICK=%CD%
+set GEXTIMAGEMAGICK_INSTALLED=%GEXTIMAGEMAGICK%\windows
+
+set MAGICK_HOME=%GEXTIMAGEMAGICK_INSTALLED%
+set PATH=%GEXTIMAGEMAGICK_INSTALLED%\bin;%PATH%
+set GS_CP_SET=yes
+goto Success
+
+:Win95
+if "%1" == "SetEnv" goto Win95Env
+REM We'll invoke a second copy of the command processor to make
+REM sure there's enough environment space
+COMMAND /E:2048 /K %0 SetEnv
+goto End
+
+:Win95Env
+set GEXTIMAGEMAGICK=%CD%
+set PATH="%GEXTIMAGEMAGICK_INSTALLED%\bin";"%PATH%"
+set GS_CP_SET=yes
+goto Success
+
+:Success
+
+set fulldir=%~dp0
+
+:: strip off everything up to (and including) ext dir
+set extdir=%fulldir:*ext\=%
+
+:: remove trailing slash
+set extdir=%extdir:\=%
+
+
+if "x%GSDLEXTS%" == "x" (
+  set GSDLEXTS=%extdir%
+) else (
+  set GSDLEXTS=%GSDLEXTS%:%extdir%
+)
+
+echo +Your environment is now setup for %extdesc%
+
+:End
+
+popd
