Index: gs2-extensions/xpdf-tools/trunk/src/GS-README.txt
===================================================================
--- gs2-extensions/xpdf-tools/trunk/src/GS-README.txt	(revision 32255)
+++ gs2-extensions/xpdf-tools/trunk/src/GS-README.txt	(revision 32256)
@@ -128,5 +128,5 @@
 
 
-2. To compile Xpdf-Tools dynamically and make it find *our* dynamically linked libraries for its helper packages zlib, libpng and freetype, edit packages/CASCADE-MAKE/XPDFTOOLS.sh to contain:
+2. To compile Xpdf-Tools dynamically and make it find *our* dynamically linked libraries for its helper packages zlib, libpng, libjpeg and freetype, edit packages/CASCADE-MAKE/XPDFTOOLS.sh to contain:
 
 	cmake -DCMAKE_BUILD_TYPE=Release \
@@ -134,4 +134,5 @@
 	    -DZLIB_LIBRARY=$prefix/lib/libz.so.1.2.7 \			# <========= THIS
 	    -DPNG_LIBRARY=$prefix/lib/libpng15.so.15.30.0 \		# <========= THIS
+	    -DJPEG_LIBRARY=$prefix/lib/libjpeg.so.PUT_THE_NUMBER_HERE \ # <========= THIS AND ENTER THE .SO VERSION NUMBER
 	    -DFREETYPE_LIBRARY=$prefix/lib/libfreetype.so.6.3.20 \	# <========= THIS
 	    -DCMAKE_DISABLE_FIND_PACKAGE_Qt4=1 \
@@ -207,12 +208,36 @@
 Since we're compiling up freetype, libpng and zlib packages as part of the Xpdf-Tools GS2-extension with CASCADE-MAKE, the next step was to compile xpdf-tools by dynamically linking against our .so files for these 3 libraries. To do so, XPDFTOOL.sh should have the following changes
 
-	(1) set up CFLAGS, CXXFLAGS, CPPFLAGS and LDFLAGS to help linkage of xpdf-tools find our .so versions of the necessary libs:
+      (1) For linux, we need to build on the LSB environment.
+      We're moreover hoping that 32 bit binaries generated this way will work on both 32 and 64 bit machines.
+
+      However, on the 32 bit LSB environment, we additionally need to pass in "-march=i486|i586|i686" to gcc
+      Without it, things end up with the error
+          undefined reference to `__sync_add_and_fetch_4'
+      See https://stackoverflow.com/questions/130740/link-error-when-compiling-gcc-atomic-operation-in-32-bit-mode
+      which further explains that
+	      "-march=" means "generate code for a particular CPU (and don't run on older CPUs)".
+      So, although uname -m returns i686 on the 32 bit linux VM that generates the nightly bins, we
+      still want to support i586 and i486 systems, so passing that in as the architecture
+      Don't do this for 64 bit systems.
+      And it seems it only needs to be set on CXXFLAGS in this case.
+
+      	  arch=`uname -m`
+	  if [[ $arch = *"64"* ]]; then
+    	     arch=
+	  else
+	      echo "@@@ 32 bit machine, need to pass in -march=i486 to avoid certain linking errors"
+	      arch="-march=i486"
+	  fi
+	  ...
+	  export CXXFLAGS="$CXXFLAGS -I$GEXTXPDFTOOLS_INSTALLED/include -I$GEXTXPDFTOOLS_INSTALLED/include/libpng15 $arch"
+
+	(2) set up CFLAGS, CXXFLAGS, CPPFLAGS and LDFLAGS to help linkage of xpdf-tools find our .so versions of the necessary libs:
 
 	export CFLAGS="$CFLAGS -I$GEXTXPDFTOOLS_INSTALLED/include -I$GEXTXPDFTOOLS_INSTALLED/include/libpng15"
 	export CPPFLAGS="$CPPFLAGS -I$GEXTXPDFTOOLS_INSTALLED/include -I$GEXTXPDFTOOLS_INSTALLED/include/libpng15"
-	export CXXFLAGS="$CXXFLAGS -I$GEXTXPDFTOOLS_INSTALLED/include -I$GEXTXPDFTOOLS_INSTALLED/include/libpng15"
+	export CXXFLAGS="$CXXFLAGS -I$GEXTXPDFTOOLS_INSTALLED/include -I$GEXTXPDFTOOLS_INSTALLED/include/libpng15 $arch"
 	export LDFLAGS="$LDFLAGS -L$GEXTXPDFTOOLS_INSTALLED/lib"
 
-	(2) The CMAKE command we run must pass the full paths to the actual .so library files (the ones with specific
+	(3) The CMAKE command we run must pass the full paths to the actual .so library files (the ones with specific
 	versions in their files names) rather than the symbolically linked generally-named .so files (the latter won't
 	be found when building xpdf-tools and CMake will try to look for the .so library files elsewhere on the system):
@@ -239,5 +264,5 @@
 
 
-	(3) Since CMakeLists.txt has been modified, we initially renamed the xpdf src tarball to gs-xpdf-4.00.tar.gz.
+	(4) Since CMakeLists.txt has been modified, we initially renamed the xpdf src tarball to gs-xpdf-4.00.tar.gz.
 	However, the current version works with the regular downloaded xpdf-4.00.tar.gz tarball. But after extraction,
 	XPDFTOOLS.sh copies across the custom packages/gs-CMakeLists.txt into the extracted tarball's xpdf subdirectory,
@@ -362,5 +387,5 @@
 Initial attempts at modifying gs-CMakeLists.txt for static compiling that proved to be unnecessary:
 
-	(1) Setting -static globally doesn't have a useful effect.
+	(i) Setting -static globally doesn't have a useful effect.
 
 	# We want to build static xpdf-tools binaries. See
@@ -381,5 +406,5 @@
 ----
 
-	(2) Threads::Threads instead of -lpthread results in a partially dynamic executable.
+	(ii) Threads::Threads instead of -lpthread results in a partially dynamic executable.
 
 	# The original, unmodified CMakeLists.txt was not set up sufficiently
@@ -404,9 +429,9 @@
 
 
-(5) To view the unmodified CMakeLists.txt included in the xpdf-4.00 source code tarball, untar it and look for its "xpdf/CMakeLists.txt" (not the toplevel file of the same name).
+5. To view the unmodified CMakeLists.txt included in the xpdf-4.00 source code tarball, untar it and look for its "xpdf/CMakeLists.txt" (not the toplevel file of the same name).
 Run a 'diff' against gs-CMakeLists.txt to see further differences, such as debug statements and comments. Most comments have been removed and placed into this readme file instead.
 
 
-(6) When CASCADE-MAKE is run on the xpdf-tools GS2-extension, it first compiles up CMake, needed to compile up xpdf-tools.
+6. When CASCADE-MAKE is run on the xpdf-tools GS2-extension, it first compiles up CMake, needed to compile up xpdf-tools.
 Unlike the library packages like freetype, libpng and zlib that we also build for xpdf-tools as part of this gs2-extension, CMake's build products don't need to be included in the distribution tarball of our built xpdf-tools executables.
 
Index: gs2-extensions/xpdf-tools/trunk/src/packages/CASCADE-MAKE/XPDFTOOLS.sh
===================================================================
--- gs2-extensions/xpdf-tools/trunk/src/packages/CASCADE-MAKE/XPDFTOOLS.sh	(revision 32255)
+++ gs2-extensions/xpdf-tools/trunk/src/packages/CASCADE-MAKE/XPDFTOOLS.sh	(revision 32256)
@@ -12,9 +12,22 @@
 prefix=$GEXTXPDFTOOLS_INSTALLED
 
+# When trying to compile xpdf-tools on a 32 bit linux LSB, we get the error
+# "undefined reference to `__sync_add_and_fetch_4'" unless we follow the instructions at
+# https://stackoverflow.com/questions/130740/link-error-when-compiling-gcc-atomic-operation-in-32-bit-mode
+# and append to CXXFLAGS "-march=i486", which is the earliest architecture for which compilation
+# succeeds and the xpdftool binaries produced work (even though our 32 bit LSB is i686).
+arch=`uname -m`
+if [[ $arch = *"64"* ]]; then
+    arch=
+else
+    echo "@@@ 32 bit unix, passing in -march=i486 to avoid certain linking errors"
+    arch="-march=i486"
+fi
+
 # Use C/CPP/CXX FLAGS and LDFLAGS for further setting up
 # libpng and libz for compiling xpdftools
 export CFLAGS="$CFLAGS -I$GEXTXPDFTOOLS_INSTALLED/include -I$GEXTXPDFTOOLS_INSTALLED/include/libpng15"
 export CPPFLAGS="$CPPFLAGS -I$GEXTXPDFTOOLS_INSTALLED/include -I$GEXTXPDFTOOLS_INSTALLED/include/libpng15"
-export CXXFLAGS="$CXXFLAGS -I$GEXTXPDFTOOLS_INSTALLED/include -I$GEXTXPDFTOOLS_INSTALLED/include/libpng15"
+export CXXFLAGS="$CXXFLAGS -I$GEXTXPDFTOOLS_INSTALLED/include -I$GEXTXPDFTOOLS_INSTALLED/include/libpng15 $arch"
 export LDFLAGS="$LDFLAGS -L$GEXTXPDFTOOLS_INSTALLED/lib"
 
@@ -114,8 +127,9 @@
 
 ## For building dynamic xpdf-tools executables, change the above to have the following instead
-## (still unable get the .so for LIBJPEG generated, so could try JPEG_LIBRARY set same as above)
+## The .so for LIBJPEG gets generated for libjpeg version 9c (but not 6b). Correct the .so version number below.
 #	    -DZLIB_LIBRARY=$prefix/lib/libz.so.1.2.7 \
 #	    -DTIFF_LIBRARY=$prefix/lib/libtiff.so.5.2.2 \
 #	    -DPNG_LIBRARY=$prefix/lib/libpng15.so.15.30.0 \
+#	    -DJPEG_LIBRARY=$prefix/lib/libjpeg.so.PUT_THE_NUMBER_HERE \
 #	    -DFREETYPE_LIBRARY=$prefix/lib/libfreetype.so.6.3.20 \
 # (The 3rd line can alternatively be "-DFREETYPE_DIR=$prefix")
