ax_isc_rpath.m4 1.9 KB

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