Index: gs2-extensions/xpdf-tools/trunk/src/packages/GS-README.txt
===================================================================
--- gs2-extensions/xpdf-tools/trunk/src/packages/GS-README.txt	(revision 32248)
+++ gs2-extensions/xpdf-tools/trunk/src/packages/GS-README.txt	(revision 32249)
@@ -1,2 +1,18 @@
+__________________________________________________________
+CONTENTS
+__________________________________________________________
+
+Xpdf-Tools related
+A. XPDF
+B. Mojo::DOM perl package for parsing HTML
+C. Compiling Xpdf-Tools: statically or dynamically linked
+D. How we got Xpdf-Tools to compile using CASCADE-MAKE
+E. Getting more output when running CMake (verbosity)
+F. APPENDIX - Useful links
+
+LIBJPEG related
+G. LIBJPEG and LIBTIFF
+- Issues building LIBJPEG on 64 bit machines and the patch
+
 __________________________________________________________
 A. XPDF
@@ -84,5 +100,5 @@
 __________________________________________________________
 
-As explained in detail in section D below, gs-CMakeLists.txt allows us to compile xpdf-tools statically (as we've now set it up for by default) or dynamically (as its CMake makefiles were originally set up for).
+As explained in detail in section D below, we have a customised gs-CMakeLists.txt file which replaces the one in the xpf-4.00.tar.gz package's xpdf subfolder after this is untarred. This customised CMake configure/make file now allows us to compile xpdf-tools either statically (as we've now set it up for by default) or dynamically (as its CMake makefiles were originally set up for).
 
 1. To compile Xpdf-Tools statically, packages/CASCADE-MAKE/XPDFTOOLS.sh should contain:
@@ -356,5 +372,5 @@
 
 ----
-/usr/bin/c++  -I/home/greenstone/gs3-svn-26Mar2018/gs2build/ext/xpdf-tools/trunk/src/linux/include  -I/home/greenstone/gs3-svn-26Mar2018/gs2build/ext/xpdf-tools/trunk/src/linux/include -I/home/greenstone/gs3-svn-26Mar2018/gs2build/ext/xpdf-tools/trunk/src/linux/include/libpng15 -O3 -Wall -fPIC  -L/home/greenstone/gs3-svn-26Mar2018/gs2build/ext/xpdf-tools/trunk/src/linux/lib  -L/home/greenstone/gs3-svn-26Mar2018/gs2build/ext/xpdf-tools/trunk/src/linux/lib -static ***** <- HERE ****** -O2 -Wall -fPIC -rdynamic CMakeFiles/pdftohtml.dir/HTMLGen.cc.o CMakeFiles/pdftohtml.dir/SplashOutputDev.cc.o CMakeFiles/pdftohtml.dir/TextOutputDev.cc.o CMakeFiles/pdftohtml.dir/pdftohtml.cc.o CMakeFiles/xpdf_objs.dir/AcroForm.cc.o CMakeFiles/xpdf_objs.dir/Annot.cc.o CMakeFiles/xpdf_objs.dir/Array.cc.o CMakeFiles/xpdf_objs.dir/BuiltinFont.cc.o CMakeFiles/xpdf_objs.dir/BuiltinFontTables.cc.o CMakeFiles/xpdf_objs.dir/Catalog.cc.o CMakeFiles/xpdf_objs.dir/CharCodeToUnicode.cc.o CMakeFiles/xpdf_objs.dir/CMap.cc.o CMakeFiles/xpdf_objs.dir/Decrypt.cc.o CMakeFiles/xpdf_objs.dir/Dict.cc.o CMakeFiles/xpdf_objs.dir/Error.cc.o CMakeFiles/xpdf_objs.dir/FontEncodingTables.cc.o CMakeFiles/xpdf_objs.dir/Form.cc.o CMakeFiles/xpdf_objs.dir/Function.cc.o CMakeFiles/xpdf_objs.dir/Gfx.cc.o CMakeFiles/xpdf_objs.dir/GfxFont.cc.o CMakeFiles/xpdf_objs.dir/GfxState.cc.o CMakeFiles/xpdf_objs.dir/GlobalParams.cc.o CMakeFiles/xpdf_objs.dir/JArithmeticDecoder.cc.o CMakeFiles/xpdf_objs.dir/JBIG2Stream.cc.o CMakeFiles/xpdf_objs.dir/JPXStream.cc.o CMakeFiles/xpdf_objs.dir/Lexer.cc.o CMakeFiles/xpdf_objs.dir/Link.cc.o CMakeFiles/xpdf_objs.dir/NameToCharCode.cc.o CMakeFiles/xpdf_objs.dir/Object.cc.o CMakeFiles/xpdf_objs.dir/OptionalContent.cc.o CMakeFiles/xpdf_objs.dir/Outline.cc.o CMakeFiles/xpdf_objs.dir/OutputDev.cc.o CMakeFiles/xpdf_objs.dir/Page.cc.o CMakeFiles/xpdf_objs.dir/Parser.cc.o CMakeFiles/xpdf_objs.dir/PDFDoc.cc.o CMakeFiles/xpdf_objs.dir/PDFDocEncoding.cc.o CMakeFiles/xpdf_objs.dir/PSTokenizer.cc.o CMakeFiles/xpdf_objs.dir/SecurityHandler.cc.o CMakeFiles/xpdf_objs.dir/Stream.cc.o CMakeFiles/xpdf_objs.dir/TextString.cc.o CMakeFiles/xpdf_objs.dir/UnicodeMap.cc.o CMakeFiles/xpdf_objs.dir/UnicodeTypeTable.cc.o CMakeFiles/xpdf_objs.dir/UTF8.cc.o CMakeFiles/xpdf_objs.dir/XFAForm.cc.o CMakeFiles/xpdf_objs.dir/XRef.cc.o CMakeFiles/xpdf_objs.dir/Zoox.cc.o  -o pdftohtml ../goo/libgoo.a ../fofi/libfofi.a ../splash/libsplash.a -static -lfreetype -lpng -lz -lm -lc -lpthread 
+/usr/bin/c++  -I/home/greenstone/gs3-svn-26Mar2018/gs2build/ext/xpdf-tools/linux/include  -I/home/greenstone/gs3-svn-26Mar2018/gs2build/ext/xpdf-tools/linux/include -I/home/greenstone/gs3-svn-26Mar2018/gs2build/ext/xpdf-tools/linux/include/libpng15 -O3 -Wall -fPIC  -L/home/greenstone/gs3-svn-26Mar2018/gs2build/ext/xpdf-tools/linux/lib  -L/home/greenstone/gs3-svn-26Mar2018/gs2build/ext/xpdf-tools/linux/lib -static ***** <- HERE ****** -O2 -Wall -fPIC -rdynamic CMakeFiles/pdftohtml.dir/HTMLGen.cc.o CMakeFiles/pdftohtml.dir/SplashOutputDev.cc.o CMakeFiles/pdftohtml.dir/TextOutputDev.cc.o CMakeFiles/pdftohtml.dir/pdftohtml.cc.o CMakeFiles/xpdf_objs.dir/AcroForm.cc.o CMakeFiles/xpdf_objs.dir/Annot.cc.o CMakeFiles/xpdf_objs.dir/Array.cc.o CMakeFiles/xpdf_objs.dir/BuiltinFont.cc.o CMakeFiles/xpdf_objs.dir/BuiltinFontTables.cc.o CMakeFiles/xpdf_objs.dir/Catalog.cc.o CMakeFiles/xpdf_objs.dir/CharCodeToUnicode.cc.o CMakeFiles/xpdf_objs.dir/CMap.cc.o CMakeFiles/xpdf_objs.dir/Decrypt.cc.o CMakeFiles/xpdf_objs.dir/Dict.cc.o CMakeFiles/xpdf_objs.dir/Error.cc.o CMakeFiles/xpdf_objs.dir/FontEncodingTables.cc.o CMakeFiles/xpdf_objs.dir/Form.cc.o CMakeFiles/xpdf_objs.dir/Function.cc.o CMakeFiles/xpdf_objs.dir/Gfx.cc.o CMakeFiles/xpdf_objs.dir/GfxFont.cc.o CMakeFiles/xpdf_objs.dir/GfxState.cc.o CMakeFiles/xpdf_objs.dir/GlobalParams.cc.o CMakeFiles/xpdf_objs.dir/JArithmeticDecoder.cc.o CMakeFiles/xpdf_objs.dir/JBIG2Stream.cc.o CMakeFiles/xpdf_objs.dir/JPXStream.cc.o CMakeFiles/xpdf_objs.dir/Lexer.cc.o CMakeFiles/xpdf_objs.dir/Link.cc.o CMakeFiles/xpdf_objs.dir/NameToCharCode.cc.o CMakeFiles/xpdf_objs.dir/Object.cc.o CMakeFiles/xpdf_objs.dir/OptionalContent.cc.o CMakeFiles/xpdf_objs.dir/Outline.cc.o CMakeFiles/xpdf_objs.dir/OutputDev.cc.o CMakeFiles/xpdf_objs.dir/Page.cc.o CMakeFiles/xpdf_objs.dir/Parser.cc.o CMakeFiles/xpdf_objs.dir/PDFDoc.cc.o CMakeFiles/xpdf_objs.dir/PDFDocEncoding.cc.o CMakeFiles/xpdf_objs.dir/PSTokenizer.cc.o CMakeFiles/xpdf_objs.dir/SecurityHandler.cc.o CMakeFiles/xpdf_objs.dir/Stream.cc.o CMakeFiles/xpdf_objs.dir/TextString.cc.o CMakeFiles/xpdf_objs.dir/UnicodeMap.cc.o CMakeFiles/xpdf_objs.dir/UnicodeTypeTable.cc.o CMakeFiles/xpdf_objs.dir/UTF8.cc.o CMakeFiles/xpdf_objs.dir/XFAForm.cc.o CMakeFiles/xpdf_objs.dir/XRef.cc.o CMakeFiles/xpdf_objs.dir/Zoox.cc.o  -o pdftohtml ../goo/libgoo.a ../fofi/libfofi.a ../splash/libsplash.a -static -lfreetype -lpng -lz -lm -lc -lpthread 
 ----
 
@@ -396,2 +412,164 @@
 
 
+__________________________________________________________
+E. Getting more output when running CMake (verbosity)
+__________________________________________________________
+See https://www.linuxquestions.org/questions/programming-9/cmake-or-make-debug-output-show-command-624800/
+To turn on debugging:
+	export VERBOSE=1
+	./CASCADE-MAKE.sh
+
+To turn off debugging, need to actually make VERBOSE undefined again (don't set it to 0):
+	export VERBOSE=
+	./CASCADE-MAKE.sh
+
+
+__________________________________________________________
+F. APPENDIX - Useful links
+__________________________________________________________
+A. Helping CMake along. (Not all of this was necessary for compiling xpdftools statically, but they're generally useful links)
+
+https://github.com/SynoCommunity/spksrc/issues/1779
+https://stackoverflow.com/questions/1620918/cmake-and-libpthread
+https://cmake.org/cmake/help/v3.0/prop_tgt/LINK_FLAGS.html
+https://cmake.org/cmake/help/v3.11/command/target_link_libraries.html?highlight=target_link_libraries
+https://stackoverflow.com/questions/24648357/compiling-a-static-executable-with-cmake
+https://stackoverflow.com/questions/42815420/cmake-cant-find-my-static-libs
+https://cmake.org/cmake/help/v3.0/command/message.html
+https://stackoverflow.com/questions/30980383/cmake-compile-options-for-libpng
+	https://stackoverflow.com/questions/36220123/undefined-reference-to-png-set-longjmp-fn-when-compiling-pcl-source-file
+
+
+B. About the error "bash: no such file or directory" when run on a statically generated binary:
+
+https://askubuntu.com/questions/351827/unable-to-run-a-32-bit-program-on-64-bit-vm/353497#353497
+https://unix.stackexchange.com/questions/13391/getting-not-found-message-when-running-a-32-bit-binary-on-a-64-bit-system/13409#13409
+https://arstechnica.com/civis/viewtopic.php?f=16&t=1173118
+https://superuser.com/questions/344533/no-such-file-or-directory-error-in-bash-but-the-file-exists
+https://unix.stackexchange.com/questions/45277/executing-binary-file-file-not-found
+
+C. Other links
+
+https://unix.stackexchange.com/questions/279397/ldd-dont-find-path-how-to-add
+
+
+__________________________________________________________
+G. LIBJPEG and LIBTIFF
+__________________________________________________________
+
+1. Issues building LIBJPEG on 64 bit machines and the patch
+
+I copied the LIBJPEG package from http://trac.greenstone.org/browser/other-projects/realistic-books/trunk/packages (also at http://trac.greenstone.org/browser/gs2-extensions/ocr/trunk/packages/cmdline).
+
+	* Configuring out of the box produced the following error:
+	   checking host system type... Invalid configuration `x86_64-unknown-linux-gnu': machine `x86_64-unknown' not recognized
+
+	* So that, as a consequence, when running make on the libjpeg package, make failed with the error:
+	   ./libtool --mode=compile gcc -I/home/greenstone/gs3-svn-26Mar2018/gs2build/ext/xpdf-tools/linux/include -fPIC  -I/home/greenstone/gs3-svn-26Mar2018/gs2build/ext/xpdf-tools/linux/include  -I. -c ./jcapimin.c
+	   make: ./libtool: Command not found
+	   make: *** [jcapimin.lo] Error 127
+		Error encountered running *make * stage of ./CASCADE-MAKE/LIBJPEG.sh
+
+The same was true when I grabbed the libjpeg from sourceforge (https://sourceforge.net/projects/libjpeg/files/), which was also still version jpeg 6b from 2008.
+
+I found the following webpages discussing the above error messages:
+- https://unix.stackexchange.com/questions/80479/how-to-work-with-libtool
+- https://github.com/rwestlund/freesweep/issues/1
+- https://ubuntuforums.org/showthread.php?t=1232714
+- https://stackoverflow.com/questions/12828687/configure-fails-to-detect-proper-ld-on-a-64-bit-system-with-32-bit-userland
+- SOLUTION: https://sourceforge.net/p/libjpeg/bugs/12/
+
+However, the error only strikes when configure is run with --enable-static.
+
+Note also that contrary to the above pages, running configure with the additional options
+	--host=x86_64-linux-gnu --build=x86_64-linux-gnu --target=x86_64-linux-gnu --disable-shared --enable-static
+did not help. Nor did adding the above flags get rid of configure attempting to work with host=x86_64-unknown(-unknown)-linux-gnu
+
+The SOLUTION, found when searching for the error message along with "enable-static", as it's the combination that is relevant, is described
+at https://sourceforge.net/p/libjpeg/bugs/12/
+
+which was to patch up the config.sub filed included in the jpeg-6b tarball, to also cover x86_64-* machines:
+		tahoe | i860 | x86_64-* | m32r | m68k | m68000 | m88k | ns32k | arc | arm \
+
+The above change is necessary because this libjpeg is outdated and has been superceded by other JPEG libraries, also discussed at https://sourceforge.net/p/libjpeg/bugs/12/
+I'm not sure if those libraries are compatible with XpdfTools however, so I'm sticking with libjpeg as long as I can get it to build and be recognised by XpdfTools.
+
+The solution is once more to have a patch file: CASCADE-MAKE/LIBJPEG.sh replaces the config.sub with in the jpeg-6b package after this is untarred with packages/gs-libjpeg-config.sub, which contains the patch.
+
+
+2. I followed the instructions at http://www.linuxfromscratch.org/blfs/view/6.3/general/libjpeg.html
+to try to build libjpeg with --enable-static and --enable-shared to produce both libjpeg.a and libjpeg.so.
+
+However, nothing I try gets it to generate a libjpeg.so. It seems to always produce a libjpeg.a in xpdf-tools/linux/lib
+regardless of whether CASCADE-MAKE/LIBJPEG.sh passes the --enable-static flag to the configure command or not, and regardless of whether --enable-shared is additionally or individually passed in.
+
+As a consequence, there's no  libjpeg.so file to set the -DJPEG_LIBRARY flag in XPDFTOOLS.sh to for when building xpdf-tools against dynamically linked libraries.
+
+I tried the various combinations with the lib jpeg-6b source tarballs from 
+- sourceforge, https://sourceforge.net/projects/libjpeg/files/, the latest tarball of this was from 2008
+- http://www.linuxfromscratch.org/blfs/view/6.3/general/libjpeg.html, which was last updated in 2007
+- http://trac.greenstone.org/browser/other-projects/realistic-books/trunk/packages/jpeg-6b.tar.gz, which was added to trac in 2009 but is probably the 2008 or 2007 version too.
+
+
+3. Modifications for using TIFF and JPEG libraries when building Xpdf-Tools:
+	
+* CASCADE-MAKE.sh, replaced
+	PACKAGES="CMAKE LIBZ LIBPNG FREETYPE XPDFTOOLS"
+with
+	PACKAGES="CMAKE LIBZ LIBTIFF LIBPNG LIBJPEG FREETYPE XPDFTOOLS"
+
+
+* XPDFTOOLS.sh
+If compiling statically make sure the CMake command contains the following changes:
+	    -DTIFF_INCLUDE_DIR=$prefix/include \		# <========== new
+	    -DJPEG_INCLUDE_DIR=$prefix/include \		# <========== new
+	    -DZLIB_LIBRARY=$prefix/lib/libz.a \
+	    -DTIFF_LIBRARY=$prefix/lib/libtiff.a \		# <========== new
+	    -DPNG_LIBRARY=$prefix/lib/libpng15.a \
+	    -DJPEG_LIBRARY=$prefix/lib/libjpeg.a \		# <========== new
+	    -DFREETYPE_LIBRARY=$prefix/lib/libfreetype.a \
+	    -DGSDLFLAG_STATIC="$static_flag" \
+
+
+
+The above flag names were discovered by deleting the untarred xpdf-4.00 folder.
+Then in a fresh terminal, source devel.bash from xpdf-tools and re-run CASCADE-MAKE.sh without the above modifications:
+
+	-- Found FreeType (new-style includes): /home/greenstone/gs3-svn-26Mar2018/gs2build/ext/xpdf-tools/linux/lib/libfreetype.a
+	-- Found ZLIB: /home/greenstone/gs3-svn-26Mar2018/gs2build/ext/xpdf-tools/linux/lib/libz.a (found version "1.2.8") 
+	-- Found PNG: /home/greenstone/gs3-svn-26Mar2018/gs2build/ext/xpdf-tools/linux/lib/libpng15.a (found version "1.2.50") 
+	-- Could NOT find JPEG (missing: JPEG_LIBRARY JPEG_INCLUDE_DIR) 
+	-- Could NOT find TIFF (missing: TIFF_LIBRARY TIFF_INCLUDE_DIR) 
+	-- lcms2 not found
+	-- No Qt library found
+
+
+* packages/gs-CMakeLists.txt was modified again, 
+
+	- this time to also pass:
+		-ltiff and -ljpeg to all target_link_libraries() commands that run when GSDLFLAG_STATIC is set
+	and
+		${TIFF_LIBRARY} and ${JPEG_LIBRARY} to all target_link_libraries() commands that run when GSDLFLAG_STATIC is not set
+
+	- And to add in the include directories and defitions if JPEG/TIFF libraries were provided:
+		if (JPEG_FOUND)
+		  include_directories("${JPEG_INCLUDE_DIR}")
+		  add_definitions("${JPEG_DEFINITIONS}")
+		  message(STATUS "@@@@@@@@@@@@@@@ JPEG_FOUND (include_dir ; include_dirs): ${JPEG_INCLUDE_DIR} ; ${JPEG_INCLUDE_DIRS}")
+		else ()
+		  message(STATUS "@@@@@@@@@@@@@@@ NO JPEG_FOUND")
+		endif ()
+		if (TIFF_FOUND)
+		  include_directories("${TIFF_INCLUDE_DIRS}")
+		  add_definitions("${TIFF_DEFINITIONS}")
+		  message(STATUS "@@@@@@@@@@@@@@@ TIFF_FOUND ${TIFF_INCLUDE_DIRS}")
+		else ()
+		  message(STATUS "@@@@@@@@@@@@@@@ NO TIFF_FOUND")
+		endif ()
+
+	Note however that although gs-CMakeLists.txt now knows what the pluralised TIFF_INCLUDE_DIRS is (and TIFF_INCLUDE_DIR)
+	as for PNG and ZLIB, gs-CMakeLists.txt does not have a value for the pluralised JPEG_INCLUDE_DIRS, only the
+	JPEG_INCLUDE_DIRS set above. And both the CMAKE flags in XPDFTOOLS.sh for tiff and jpeg libs seem to have been setup
+	in the same way now. Not sure where these automatically assigned variables come from in order to check up on them.
+
+
