Index: gs2-extensions/xpdf-tools/trunk/src/packages/CASCADE-MAKE/XPDFTOOLS.sh
===================================================================
--- gs2-extensions/xpdf-tools/trunk/src/packages/CASCADE-MAKE/XPDFTOOLS.sh	(revision 32245)
+++ gs2-extensions/xpdf-tools/trunk/src/packages/CASCADE-MAKE/XPDFTOOLS.sh	(revision 32246)
@@ -19,4 +19,16 @@
 export LDFLAGS="$LDFLAGS -L$GEXTXPDFTOOLS_INSTALLED/lib"
 
+# For Mac OSX, when -static is passed in for linking, we end up with the error "ld: library not found for -lcrt0.o"
+# See https://stackoverflow.com/questions/3801011/ld-library-not-found-for-lcrt0-o-on-osx-10-6-with-gcc-clang-static-flag
+# On Mac OSX, compile it with -Bstatic instead, as per https://stackoverflow.com/questions/844819/how-to-static-link-on-os-x
+# We will pass in the correct static variant as the custom GSDLFLAG_STATIC, so it will be set to either "-static" (for linux)
+# or "-Bstatic" for darwin when CMake starts compiling up xpdf-tools. When the GSDLFLAG_STATIC is set, it will also trigger
+# the branch of the gs-CMakeLists.txt code that does static compiling. If not set, xpdf-tools are compiled against dynamically
+# linked libraries.
+if [ "x$GSDLOS" == "xdarwin" ] ; then
+    static_flag=-Bstatic
+else
+    static_flag=-static
+fi
 
 opt_run_untar $force_untar $auto_untar $package $version
@@ -72,5 +84,5 @@
 	    -DCMAKE_CXX_FLAGS="$CXXFLAGS" \
 	    -DCMAKE_EXE_LINKER_FLAGS="$LDFLAGS" \
-	    -DGSDLFLAG_STATIC_BUILD="true" \
+ 	    -DGSDLFLAG_STATIC="$static_flag" \
 	    $GEXT_XPDFTOOLS/packages/$package$version
     fi ; \
@@ -95,5 +107,5 @@
 #	    -DPNG_LIBRARY=$prefix/lib/libpng15.a \
 #	    -DFREETYPE_LIBRARY=$prefix/lib/libfreetype.a \
-# And throw in -DGSDLFLAG_STATIC_BUILD="true"
+# And throw in -DGSDLFLAG_STATIC_BUILD="-static" for linux or with "-Bstatic" for Macs
 # In place of FREETYPE_LIBRARY, could also try the following (then check built bins
 # by running ldd and file over them):
@@ -118,6 +130,6 @@
 #	    -DFREETYPE_LIBRARY=$prefix/lib/libfreetype.so.6.3.20 \
 # The above is for building dynamic xpdf-tools executables. For which, also don't
-# pass in -DGSDLFLAG_STATIC_BUILD="true" (remove the line, don't comment it out, nor
-# set the value to false)
+# pass in -DGSDLFLAG_STATIC_BUILD="..." (remove the line, don't comment it out, nor
+# set the value to "")
 
 # If compilation was successful, then we don't need cmake binaries anymore when
Index: gs2-extensions/xpdf-tools/trunk/src/packages/gs-CMakeLists.txt
===================================================================
--- gs2-extensions/xpdf-tools/trunk/src/packages/gs-CMakeLists.txt	(revision 32245)
+++ gs2-extensions/xpdf-tools/trunk/src/packages/gs-CMakeLists.txt	(revision 32246)
@@ -20,8 +20,14 @@
 include_directories("${PROJECT_SOURCE_DIR}/splash")
 
-if(GSDLFLAG_STATIC_BUILD)
-  message(STATUS "@@@@ GSDLFLAG_STATIC_BUILD SET. Building xpdf-tools statically.")
-else ()
-  message(STATUS "@@@@ GSDLFLAG_STATIC_BUILD not SET. Building dynamically using xpdf-tools' (mostly) original, unmodified linker flags.")
+
+# For Mac OSX, when -static is passed in for linking, we end up with the error "ld: library not found for -lcrt0.o"
+# See https://stackoverflow.com/questions/3801011/ld-library-not-found-for-lcrt0-o-on-osx-10-6-with-gcc-clang-static-flag
+# On Mac OSX, compile it with -Bstatic, as per https://stackoverflow.com/questions/844819/how-to-static-link-on-os-x
+# XPDFTOOLS.sh will have set the GSDLFLAG_STATIC to either "-static" (for linux) or "-Bstatic" for darwin
+
+if(GSDLFLAG_STATIC)
+  message(STATUS "@@@@ GSDLFLAG_STATIC SET. Building xpdf-tools statically.")
+else ()
+  message(STATUS "@@@@ GSDLFLAG_STATIC not SET. Building dynamically using xpdf-tools' (mostly) original, unmodified linker flags.")
 endif ()
 if (PNG_FOUND)
@@ -41,7 +47,7 @@
   include_directories("${LCMS_INCLUDE_DIR}")
   set(COLOR_MANAGER_SOURCE "ColorManager.cc")
-  if(GSDLFLAG_STATIC_BUILD)
+  if(GSDLFLAG_STATIC)
     # Untested combination, warn https://cmake.org/cmake/help/v3.0/command/message.html
-    message(AUTHOR_WARNING "@@@@@@@@@@@@@@@ GSDL Warning: static building with HAVE_LCMS on. If running ldd/file on generated binaries shows any binary to be partially a dynamic executable, then Export VERBOSE=1 and re-run the CMake build. Then check the verbose build output's linker flags (for static building) for that binary: they should not be -Wl,-Bstatic LIBS -Wl,-Bdynamic -lpthread but -static LIBS. Fix it by removing all references to LCMS_LIBRARY in the static linking flags of target_link_libraries statements (i.e. when GSDLFLAG_STATIC_BUILD is set) in file gs-CMakeLists.txt and replacing them with the -l equivalent for the color manager library, (l)cms. @@@@@@@@@@@@@@@")
+    message(AUTHOR_WARNING "@@@@@@@@@@@@@@@ GSDL Warning: static building with HAVE_LCMS on. If running ldd/file on generated binaries shows any binary to be partially a dynamic executable, then Export VERBOSE=1 and re-run the CMake build. Then check the verbose build output's linker flags (for static building) for that binary: they should not be -Wl,-Bstatic LIBS -Wl,-Bdynamic -lpthread but -static LIBS. Fix it by removing all references to LCMS_LIBRARY in the static linking flags of target_link_libraries statements (i.e. when GSDLFLAG_STATIC is set) in file gs-CMakeLists.txt and replacing them with the -l equivalent for the color manager library, (l)cms. @@@@@@@@@@@@@@@")
   endif ()
 else ()
@@ -49,7 +55,7 @@
 endif ()
 if (DTYPE_LIBRARY)
-  if(GSDLFLAG_STATIC_BUILD)
+  if(GSDLFLAG_STATIC)
     # Untested combination, warn
-    message(AUTHOR_WARNING "@@@@@@@@@@@@@@@ GSDL Warning: static building with TYPE_LIBRARY. If running ldd/file on generated binaries shows any binary to be partially a dynamic executable, then export VERBOSE=1 and re-run the CMake build. Then check the verbose build output's linker flags (for static building) for that binary: they should not be -Wl,-Bstatic LIBS -Wl,-Bdynamic -lpthread but -static LIBS. Fix it by removing all references to DTYPE_LIBRARY in the static linking flags of target_link_libraries statements (i.e. when GSDLFLAG_STATIC_BUILD is set) in file gs-CMakeLists.txt and replacing them with the -l equivalent for typelib. @@@@@@@@@@@@@@@")
+    message(AUTHOR_WARNING "@@@@@@@@@@@@@@@ GSDL Warning: static building with TYPE_LIBRARY. If running ldd/file on generated binaries shows any binary to be partially a dynamic executable, then export VERBOSE=1 and re-run the CMake build. Then check the verbose build output's linker flags (for static building) for that binary: they should not be -Wl,-Bstatic LIBS -Wl,-Bdynamic -lpthread but -static LIBS. Fix it by removing all references to DTYPE_LIBRARY in the static linking flags of target_link_libraries statements (i.e. when GSDLFLAG_STATIC is set) in file gs-CMakeLists.txt and replacing them with the -l equivalent for typelib. @@@@@@@@@@@@@@@")
   endif ()
 endif ()
@@ -154,7 +160,7 @@
     pdftops.cc
   )  
-  if(GSDLFLAG_STATIC_BUILD)
+  if(GSDLFLAG_STATIC)
     target_link_libraries(pdftops goo fofi splash
-      -static -lfreetype ${DTYPE_LIBRARY} ${LCMS_LIBRARY} -lz -lm -lc -lpthread)
+      ${GSDLFLAG_STATIC} -lfreetype ${DTYPE_LIBRARY} ${LCMS_LIBRARY} -lz -lm -lc -lpthread)
     # Threads::Threads instead of -lpthread results in a partially dynamic executable
   else ()
@@ -172,6 +178,6 @@
     pdftops.cc
   )
-  if(GSDLFLAG_STATIC_BUILD)
-    target_link_libraries(pdftops goo fofi -static ${LCMS_LIBRARY} -lm -lc -lpthread)
+  if(GSDLFLAG_STATIC)
+    target_link_libraries(pdftops goo fofi ${GSDLFLAG_STATIC} ${LCMS_LIBRARY} -lm -lc -lpthread)
   else ()
     target_link_libraries(pdftops goo fofi ${LCMS_LIBRARY})
@@ -188,6 +194,6 @@
   pdftotext.cc
 )
-if(GSDLFLAG_STATIC_BUILD)
-  target_link_libraries(pdftotext goo fofi -static ${LCMS_LIBRARY} -lpthread)
+if(GSDLFLAG_STATIC)
+  target_link_libraries(pdftotext goo fofi ${GSDLFLAG_STATIC} ${LCMS_LIBRARY} -lpthread)
   # Threads::Threads instead of -lpthread results in a partially dynamic executable
 else ()
@@ -207,7 +213,7 @@
     pdftohtml.cc
   )
-  if(GSDLFLAG_STATIC_BUILD)
+  if(GSDLFLAG_STATIC)
     target_link_libraries(pdftohtml goo fofi splash
-      -static -lfreetype ${DTYPE_LIBRARY} ${LCMS_LIBRARY} -lpng -lz -lm -lc -lpthread)
+      ${GSDLFLAG_STATIC} -lfreetype ${DTYPE_LIBRARY} ${LCMS_LIBRARY} -lpng -lz -lm -lc -lpthread)
   else ()
     target_link_libraries(pdftohtml goo fofi splash
@@ -227,6 +233,6 @@
 # The order of dynamic .so files listed by ldd in the broken binary differs from
 # a manually linked working version of pdftohtml, and seems to be the only difference
-# between the two in ldd output. Not using "-Wl,-Bstatic" and using -static in its
-# place creates a partially static dynamic executable that isn't broken, whereas
+# between the two in ldd output. Not using "-Wl,-Bstatic" and using -static (-Bstatic on Mac)
+# in its place creates a partially static dynamic executable that isn't broken, whereas
 # additionally removing "-Wl,-Bdynamic -lpthread" and replacing it with -lpthread
 # moreover produces a working pdftohtml that is a fully static linked executable.
@@ -247,6 +253,6 @@
   pdfinfo.cc
 )
-if(GSDLFLAG_STATIC_BUILD)
-  target_link_libraries(pdfinfo goo fofi -static ${LCMS_LIBRARY} -lpthread)
+if(GSDLFLAG_STATIC)
+  target_link_libraries(pdfinfo goo fofi ${GSDLFLAG_STATIC} ${LCMS_LIBRARY} -lpthread)
 else ()
   target_link_libraries(pdfinfo goo fofi ${LCMS_LIBRARY})
@@ -261,6 +267,6 @@
   pdffonts.cc
 )
-if(GSDLFLAG_STATIC_BUILD)
-  target_link_libraries(pdffonts goo fofi -static ${LCMS_LIBRARY} -lpthread)
+if(GSDLFLAG_STATIC)
+  target_link_libraries(pdffonts goo fofi ${GSDLFLAG_STATIC} ${LCMS_LIBRARY} -lpthread)
 else ()
   target_link_libraries(pdffonts goo fofi ${LCMS_LIBRARY})
@@ -275,6 +281,6 @@
   pdfdetach.cc
 )
-if(GSDLFLAG_STATIC_BUILD)
-  target_link_libraries(pdfdetach goo fofi -static ${LCMS_LIBRARY} -lpthread)
+if(GSDLFLAG_STATIC)
+  target_link_libraries(pdfdetach goo fofi ${GSDLFLAG_STATIC} ${LCMS_LIBRARY} -lpthread)
 else ()
   target_link_libraries(pdfdetach goo fofi ${LCMS_LIBRARY})
@@ -291,7 +297,7 @@
     pdftoppm.cc
   )
-  if(GSDLFLAG_STATIC_BUILD)
+  if(GSDLFLAG_STATIC)
     target_link_libraries(pdftoppm goo fofi splash
-      -static -lfreetype ${DTYPE_LIBRARY} ${LCMS_LIBRARY} -lz -lm -lc -lpthread)
+      ${GSDLFLAG_STATIC} -lfreetype ${DTYPE_LIBRARY} ${LCMS_LIBRARY} -lz -lm -lc -lpthread)
   else ()
     target_link_libraries(pdftoppm goo fofi splash
@@ -313,7 +319,7 @@
     pdftopng.cc
   )
-  if(GSDLFLAG_STATIC_BUILD)
+  if(GSDLFLAG_STATIC)
     target_link_libraries(pdftopng goo fofi splash
-      -static -lfreetype ${DTYPE_LIBRARY} ${LCMS_LIBRARY} -lpng -lz -lm -lc -lpthread)
+      ${GSDLFLAG_STATIC} -lfreetype ${DTYPE_LIBRARY} ${LCMS_LIBRARY} -lpng -lz -lm -lc -lpthread)
   else ()
     target_link_libraries(pdftopng goo fofi splash
@@ -333,6 +339,6 @@
   pdfimages.cc
 )
-if(GSDLFLAG_STATIC_BUILD)
-  target_link_libraries(pdfimages goo fofi -static ${LCMS_LIBRARY} -lpthread)
+if(GSDLFLAG_STATIC)
+  target_link_libraries(pdfimages goo fofi ${GSDLFLAG_STATIC} ${LCMS_LIBRARY} -lpthread)
 else ()
   target_link_libraries(pdfimages goo fofi ${LCMS_LIBRARY})
