ax_isc_rpath.m4 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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
  7. dnl gcc's -rpath 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 whichever
  20. # language is used in the main script. Note also that it's not LDFLAGS;
  21. # technically this is a linker flag, but we've noticed $LDFLAGS can be placed
  22. # where the compiler could interpret it as a compiler option, leading to
  23. # subtle failure mode. So, in the check below using the compiler flag is
  24. # safer (in the actual Makefiles the flag should be set in LDFLAGS).
  25. CXXFLAGS_SAVED="$CXXFLAGS"
  26. CXXFLAGS="$CXXFLAGS -Wl,-R/usr/lib"
  27. CCFLAGS_SAVED="$CCFLAGS"
  28. CCFLAGS="$CCFLAGS -Wl,-R/usr/lib"
  29. # check -Wl,-R and -R rather than gcc specific -rpath to be as portable
  30. # as possible. -Wl,-R seems to be safer, so we try it first. In some cases
  31. # -R is not actually recognized but AC_TRY_LINK doesn't fail due to that.
  32. AC_MSG_CHECKING([whether -Wl,-R flag is available in linker])
  33. AC_TRY_LINK([],[],
  34. [ AC_MSG_RESULT(yes)
  35. ISC_RPATH_FLAG=-Wl,-R
  36. ],[ AC_MSG_RESULT(no)
  37. AC_MSG_CHECKING([whether -R flag is available in linker])
  38. CXXFLAGS="$CXXFLAGS_SAVED -R"
  39. CCFLAGS="$CCFLAGS_SAVED -R"
  40. AC_TRY_LINK([], [],
  41. [ AC_MSG_RESULT([yes; note that -R is more sensitive about the position in option arguments])
  42. ISC_RPATH_FLAG=-R
  43. ],[ AC_MSG_RESULT(no) ])
  44. ])
  45. CXXFLAGS=$CXXFLAGS_SAVED
  46. CCFLAGS=$CCFLAGS_SAVED
  47. fi
  48. ])dnl AX_ISC_RPATH