ax_isc_rpath.m4 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. dnl @synopsis AX_ISC_RPATH
  2. dnl
  3. dnl @summary figure out whether and which "rpath" linker option is available
  4. dnl
  5. dnl This macro checks if the linker supports an option to embed a path
  6. dnl to a runtime library (often installed in an uncommon place), such as the
  7. dnl commonly used -R option. If found, it sets the ISC_RPATH_FLAG variable to
  8. dnl the found option flag. The main configure.ac can use it as follows:
  9. dnl if test "x$ISC_RPATH_FLAG" != "x"; then
  10. dnl LDFLAGS="$LDFLAGS ${ISC_RPATH_FLAG}/usr/local/lib/some_library"
  11. dnl fi
  12. dnl
  13. dnl If you pass --disable-rpath to configure, ISC_RPATH_FLAG is not set
  14. AC_DEFUN([AX_ISC_RPATH], [
  15. AC_ARG_ENABLE(rpath,
  16. [AC_HELP_STRING([--disable-rpath], [don't hardcode library path into binaries])],
  17. rpath=$enableval, rpath=yes)
  18. if test x$rpath != xno; then
  19. # We'll tweak both CXXFLAGS and CCFLAGS so this function will work
  20. # whichever language is used in the main script. Note also that it's not
  21. #LDFLAGS; technically this is a linker flag, but we've noticed $LDFLAGS
  22. # can be placed where the compiler could interpret it as a compiler
  23. # option, leading to subtle failure mode. So, in the check below using
  24. # the compiler flag is safer (in the actual Makefiles the flag should be
  25. # set in LDFLAGS).
  26. CXXFLAGS_SAVED="$CXXFLAGS"
  27. CXXFLAGS="$CXXFLAGS -Wl,-R/usr/lib"
  28. CCFLAGS_SAVED="$CCFLAGS"
  29. CCFLAGS="$CCFLAGS -Wl,-R/usr/lib"
  30. # check -Wl,-R and -R rather than gcc specific -rpath to be as portable
  31. # as possible. -Wl,-R seems to be safer, so we try it first. In some
  32. # cases -R is not actually recognized but AC_TRY_LINK doesn't fail due to
  33. # that.
  34. AC_MSG_CHECKING([whether -Wl,-R flag is available in linker])
  35. AC_TRY_LINK([],[],
  36. [ AC_MSG_RESULT(yes)
  37. ISC_RPATH_FLAG=-Wl,-R
  38. ],[ AC_MSG_RESULT(no)
  39. AC_MSG_CHECKING([whether -R flag is available in linker])
  40. CXXFLAGS="$CXXFLAGS_SAVED -R"
  41. CCFLAGS="$CCFLAGS_SAVED -R"
  42. AC_TRY_LINK([], [],
  43. [ AC_MSG_RESULT([yes; note that -R is more sensitive about the position in option arguments])
  44. ISC_RPATH_FLAG=-R
  45. ],[ AC_MSG_RESULT(no) ])
  46. ])
  47. CXXFLAGS=$CXXFLAGS_SAVED
  48. CCFLAGS=$CCFLAGS_SAVED
  49. fi
  50. ])dnl AX_ISC_RPATH