Changeset 32246


Ignore:
Timestamp:
2018-07-06T19:19:28+12:00 (6 years ago)
Author:
ak19
Message:

I'm unable so far to get xpdf-tools to build statically on the mac. These are the changes to get it to build on the Mac in an attempt to make static xpdf-tools binaries. Running otool minus L on the binaries however shows that they're linking to dylib dlls, albeit our ones for freetype, libpng and zlib.

Location:
gs2-extensions/xpdf-tools/trunk/src/packages
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • gs2-extensions/xpdf-tools/trunk/src/packages/CASCADE-MAKE/XPDFTOOLS.sh

    r32240 r32246  
    1919export LDFLAGS="$LDFLAGS -L$GEXTXPDFTOOLS_INSTALLED/lib"
    2020
     21# For Mac OSX, when -static is passed in for linking, we end up with the error "ld: library not found for -lcrt0.o"
     22# See https://stackoverflow.com/questions/3801011/ld-library-not-found-for-lcrt0-o-on-osx-10-6-with-gcc-clang-static-flag
     23# On Mac OSX, compile it with -Bstatic instead, as per https://stackoverflow.com/questions/844819/how-to-static-link-on-os-x
     24# We will pass in the correct static variant as the custom GSDLFLAG_STATIC, so it will be set to either "-static" (for linux)
     25# or "-Bstatic" for darwin when CMake starts compiling up xpdf-tools. When the GSDLFLAG_STATIC is set, it will also trigger
     26# the branch of the gs-CMakeLists.txt code that does static compiling. If not set, xpdf-tools are compiled against dynamically
     27# linked libraries.
     28if [ "x$GSDLOS" == "xdarwin" ] ; then
     29    static_flag=-Bstatic
     30else
     31    static_flag=-static
     32fi
    2133
    2234opt_run_untar $force_untar $auto_untar $package $version
     
    7284        -DCMAKE_CXX_FLAGS="$CXXFLAGS" \
    7385        -DCMAKE_EXE_LINKER_FLAGS="$LDFLAGS" \
    74         -DGSDLFLAG_STATIC_BUILD="true" \
     86        -DGSDLFLAG_STATIC="$static_flag" \
    7587        $GEXT_XPDFTOOLS/packages/$package$version
    7688    fi ; \
     
    95107#       -DPNG_LIBRARY=$prefix/lib/libpng15.a \
    96108#       -DFREETYPE_LIBRARY=$prefix/lib/libfreetype.a \
    97 # And throw in -DGSDLFLAG_STATIC_BUILD="true"
     109# And throw in -DGSDLFLAG_STATIC_BUILD="-static" for linux or with "-Bstatic" for Macs
    98110# In place of FREETYPE_LIBRARY, could also try the following (then check built bins
    99111# by running ldd and file over them):
     
    118130#       -DFREETYPE_LIBRARY=$prefix/lib/libfreetype.so.6.3.20 \
    119131# The above is for building dynamic xpdf-tools executables. For which, also don't
    120 # pass in -DGSDLFLAG_STATIC_BUILD="true" (remove the line, don't comment it out, nor
    121 # set the value to false)
     132# pass in -DGSDLFLAG_STATIC_BUILD="..." (remove the line, don't comment it out, nor
     133# set the value to "")
    122134
    123135# If compilation was successful, then we don't need cmake binaries anymore when
  • gs2-extensions/xpdf-tools/trunk/src/packages/gs-CMakeLists.txt

    r32244 r32246  
    2020include_directories("${PROJECT_SOURCE_DIR}/splash")
    2121
    22 if(GSDLFLAG_STATIC_BUILD)
    23   message(STATUS "@@@@ GSDLFLAG_STATIC_BUILD SET. Building xpdf-tools statically.")
    24 else ()
    25   message(STATUS "@@@@ GSDLFLAG_STATIC_BUILD not SET. Building dynamically using xpdf-tools' (mostly) original, unmodified linker flags.")
     22
     23# For Mac OSX, when -static is passed in for linking, we end up with the error "ld: library not found for -lcrt0.o"
     24# See https://stackoverflow.com/questions/3801011/ld-library-not-found-for-lcrt0-o-on-osx-10-6-with-gcc-clang-static-flag
     25# On Mac OSX, compile it with -Bstatic, as per https://stackoverflow.com/questions/844819/how-to-static-link-on-os-x
     26# XPDFTOOLS.sh will have set the GSDLFLAG_STATIC to either "-static" (for linux) or "-Bstatic" for darwin
     27
     28if(GSDLFLAG_STATIC)
     29  message(STATUS "@@@@ GSDLFLAG_STATIC SET. Building xpdf-tools statically.")
     30else ()
     31  message(STATUS "@@@@ GSDLFLAG_STATIC not SET. Building dynamically using xpdf-tools' (mostly) original, unmodified linker flags.")
    2632endif ()
    2733if (PNG_FOUND)
     
    4147  include_directories("${LCMS_INCLUDE_DIR}")
    4248  set(COLOR_MANAGER_SOURCE "ColorManager.cc")
    43   if(GSDLFLAG_STATIC_BUILD)
     49  if(GSDLFLAG_STATIC)
    4450    # Untested combination, warn https://cmake.org/cmake/help/v3.0/command/message.html
    45     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. @@@@@@@@@@@@@@@")
     51    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. @@@@@@@@@@@@@@@")
    4652  endif ()
    4753else ()
     
    4955endif ()
    5056if (DTYPE_LIBRARY)
    51   if(GSDLFLAG_STATIC_BUILD)
     57  if(GSDLFLAG_STATIC)
    5258    # Untested combination, warn
    53     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. @@@@@@@@@@@@@@@")
     59    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. @@@@@@@@@@@@@@@")
    5460  endif ()
    5561endif ()
     
    154160    pdftops.cc
    155161  ) 
    156   if(GSDLFLAG_STATIC_BUILD)
     162  if(GSDLFLAG_STATIC)
    157163    target_link_libraries(pdftops goo fofi splash
    158       -static -lfreetype ${DTYPE_LIBRARY} ${LCMS_LIBRARY} -lz -lm -lc -lpthread)
     164      ${GSDLFLAG_STATIC} -lfreetype ${DTYPE_LIBRARY} ${LCMS_LIBRARY} -lz -lm -lc -lpthread)
    159165    # Threads::Threads instead of -lpthread results in a partially dynamic executable
    160166  else ()
     
    172178    pdftops.cc
    173179  )
    174   if(GSDLFLAG_STATIC_BUILD)
    175     target_link_libraries(pdftops goo fofi -static ${LCMS_LIBRARY} -lm -lc -lpthread)
     180  if(GSDLFLAG_STATIC)
     181    target_link_libraries(pdftops goo fofi ${GSDLFLAG_STATIC} ${LCMS_LIBRARY} -lm -lc -lpthread)
    176182  else ()
    177183    target_link_libraries(pdftops goo fofi ${LCMS_LIBRARY})
     
    188194  pdftotext.cc
    189195)
    190 if(GSDLFLAG_STATIC_BUILD)
    191   target_link_libraries(pdftotext goo fofi -static ${LCMS_LIBRARY} -lpthread)
     196if(GSDLFLAG_STATIC)
     197  target_link_libraries(pdftotext goo fofi ${GSDLFLAG_STATIC} ${LCMS_LIBRARY} -lpthread)
    192198  # Threads::Threads instead of -lpthread results in a partially dynamic executable
    193199else ()
     
    207213    pdftohtml.cc
    208214  )
    209   if(GSDLFLAG_STATIC_BUILD)
     215  if(GSDLFLAG_STATIC)
    210216    target_link_libraries(pdftohtml goo fofi splash
    211       -static -lfreetype ${DTYPE_LIBRARY} ${LCMS_LIBRARY} -lpng -lz -lm -lc -lpthread)
     217      ${GSDLFLAG_STATIC} -lfreetype ${DTYPE_LIBRARY} ${LCMS_LIBRARY} -lpng -lz -lm -lc -lpthread)
    212218  else ()
    213219    target_link_libraries(pdftohtml goo fofi splash
     
    227233# The order of dynamic .so files listed by ldd in the broken binary differs from
    228234# a manually linked working version of pdftohtml, and seems to be the only difference
    229 # between the two in ldd output. Not using "-Wl,-Bstatic" and using -static in its
    230 # place creates a partially static dynamic executable that isn't broken, whereas
     235# between the two in ldd output. Not using "-Wl,-Bstatic" and using -static (-Bstatic on Mac)
     236# in its place creates a partially static dynamic executable that isn't broken, whereas
    231237# additionally removing "-Wl,-Bdynamic -lpthread" and replacing it with -lpthread
    232238# moreover produces a working pdftohtml that is a fully static linked executable.
     
    247253  pdfinfo.cc
    248254)
    249 if(GSDLFLAG_STATIC_BUILD)
    250   target_link_libraries(pdfinfo goo fofi -static ${LCMS_LIBRARY} -lpthread)
     255if(GSDLFLAG_STATIC)
     256  target_link_libraries(pdfinfo goo fofi ${GSDLFLAG_STATIC} ${LCMS_LIBRARY} -lpthread)
    251257else ()
    252258  target_link_libraries(pdfinfo goo fofi ${LCMS_LIBRARY})
     
    261267  pdffonts.cc
    262268)
    263 if(GSDLFLAG_STATIC_BUILD)
    264   target_link_libraries(pdffonts goo fofi -static ${LCMS_LIBRARY} -lpthread)
     269if(GSDLFLAG_STATIC)
     270  target_link_libraries(pdffonts goo fofi ${GSDLFLAG_STATIC} ${LCMS_LIBRARY} -lpthread)
    265271else ()
    266272  target_link_libraries(pdffonts goo fofi ${LCMS_LIBRARY})
     
    275281  pdfdetach.cc
    276282)
    277 if(GSDLFLAG_STATIC_BUILD)
    278   target_link_libraries(pdfdetach goo fofi -static ${LCMS_LIBRARY} -lpthread)
     283if(GSDLFLAG_STATIC)
     284  target_link_libraries(pdfdetach goo fofi ${GSDLFLAG_STATIC} ${LCMS_LIBRARY} -lpthread)
    279285else ()
    280286  target_link_libraries(pdfdetach goo fofi ${LCMS_LIBRARY})
     
    291297    pdftoppm.cc
    292298  )
    293   if(GSDLFLAG_STATIC_BUILD)
     299  if(GSDLFLAG_STATIC)
    294300    target_link_libraries(pdftoppm goo fofi splash
    295       -static -lfreetype ${DTYPE_LIBRARY} ${LCMS_LIBRARY} -lz -lm -lc -lpthread)
     301      ${GSDLFLAG_STATIC} -lfreetype ${DTYPE_LIBRARY} ${LCMS_LIBRARY} -lz -lm -lc -lpthread)
    296302  else ()
    297303    target_link_libraries(pdftoppm goo fofi splash
     
    313319    pdftopng.cc
    314320  )
    315   if(GSDLFLAG_STATIC_BUILD)
     321  if(GSDLFLAG_STATIC)
    316322    target_link_libraries(pdftopng goo fofi splash
    317       -static -lfreetype ${DTYPE_LIBRARY} ${LCMS_LIBRARY} -lpng -lz -lm -lc -lpthread)
     323      ${GSDLFLAG_STATIC} -lfreetype ${DTYPE_LIBRARY} ${LCMS_LIBRARY} -lpng -lz -lm -lc -lpthread)
    318324  else ()
    319325    target_link_libraries(pdftopng goo fofi splash
     
    333339  pdfimages.cc
    334340)
    335 if(GSDLFLAG_STATIC_BUILD)
    336   target_link_libraries(pdfimages goo fofi -static ${LCMS_LIBRARY} -lpthread)
     341if(GSDLFLAG_STATIC)
     342  target_link_libraries(pdfimages goo fofi ${GSDLFLAG_STATIC} ${LCMS_LIBRARY} -lpthread)
    337343else ()
    338344  target_link_libraries(pdfimages goo fofi ${LCMS_LIBRARY})
Note: See TracChangeset for help on using the changeset viewer.