libarchive_autodetect-st_lib_archive.m4 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. dnl
  2. dnl @synopsis ST_LIB_ARCHIVE([ENABLED-DEFAULT])
  3. dnl
  4. dnl This macro figures out what's necessary to link a program against an
  5. dnl instance of the BSD libarchive package by Tim Kientzle.
  6. dnl
  7. dnl See http://people.freebsd.org/~kientzle/libarchive/ for more info.
  8. dnl
  9. dnl It exports and substitutes the variables LIBARCHIVE_LIBS, LIBARCHIVE_LDFLAGS,
  10. dnl and LIBARCHIVE_CPPFLAGS to appropriate values for the identified instance of
  11. dnl libarchive. The values are AC_SUBST'd, so a user could, for example, simply
  12. dnl include @LIBARCHIVE_CPPFLAGS@ in the definition of AM_CPPFLAGS in a Makefile.am.
  13. dnl
  14. dnl ENABLED-DEFAULT is either "yes" or "no" and determines whether the default value
  15. dnl is --with-libarchive or --without-libarchive. It is not possible to specify a
  16. dnl default directory. More simply, any reasonable choice for a default should just
  17. dnl go into the auto-detect list.
  18. dnl
  19. dnl The macro defines the symbol HAVE_LIBARCHIVE if the library is found. You
  20. dnl should use autoheader to include a definition for this symbol in a config.h
  21. dnl file. Sample usage in a C/C++ source is as follows:
  22. dnl
  23. dnl #ifdef HAVE_LIBARCHIVE
  24. dnl #include <archive.h>
  25. dnl #endif /* HAVE_LIBARCHIVE */
  26. dnl
  27. dnl @category InstalledPackages
  28. dnl @author Andre Stechert <[email protected]>
  29. dnl @version 2006-04-20
  30. dnl @license GPLWithACException
  31. AC_DEFUN([ST_LIB_ARCHIVE],
  32. [
  33. #
  34. # Handle input from the configurer and blend with the requirements from the maintainer.
  35. # We go through the trouble of creating a second set of variables other than the with_foo
  36. # variables in order to be sure that error/corner cases have been cleaned up.
  37. #
  38. # After this statement, three trusted variable are defined.
  39. #
  40. # st_lib_archive_ENABLED will be either "yes" or "no". its value determines whether
  41. # or not we bother with the rest of the checks and whether or not we export a
  42. # bunch of variables.
  43. #
  44. # st_lib_archive_LOCATION will be either "auto" or "defined". if it is "auto", then
  45. # we try a bunch of standard locations. if it is "defined", then we just try the value
  46. # provided in st_lib_archive_DIR.
  47. #
  48. # st_lib_archive_DIR will contain the string provided by the user, provided that it's
  49. # actually a directory.
  50. #
  51. AC_MSG_CHECKING([if libarchive is wanted])
  52. AC_ARG_WITH([libarchive],
  53. AS_HELP_STRING([--with-libarchive=DIR], [libarchive installation directory]),
  54. [if test "x$with_libarchive" = "xno" ; then
  55. st_lib_archive_ENABLED=no
  56. elif test "x$with_libarchive" = "xyes" ; then
  57. st_lib_archive_ENABLED=yes
  58. st_lib_archive_LOCATION=auto
  59. else
  60. st_lib_archive_ENABLED=yes
  61. st_lib_archive_LOCATION=defined
  62. if test -d "$with_libarchive" ; then
  63. st_lib_archive_DIR="$with_libarchive"
  64. else
  65. AC_MSG_ERROR([$with_libarchive is not a directory])
  66. fi
  67. fi],
  68. [if test "x$1" = "xno" ; then
  69. st_lib_archive_ENABLED=no
  70. elif test "x$1" = "xyes" ; then
  71. st_lib_archive_ENABLED=yes
  72. else
  73. st_lib_archive_ENABLED=yes
  74. fi])
  75. if test "$st_lib_archive_ENABLED" = "yes" ; then
  76. AC_MSG_RESULT([yes])
  77. #
  78. # After this statement, one trusted variable is defined.
  79. #
  80. # st_lib_archive_LIB will be either "lib" or "lib64", depending on whether the configurer
  81. # specified 32, 64. The default is "lib".
  82. #
  83. AC_MSG_CHECKING([whether to use lib or lib64])
  84. AC_ARG_WITH([libarchive-bits],
  85. AS_HELP_STRING([--with-libarchive-bits=32/64], [if 64, look in /lib64 on hybrid systems]),
  86. [if test "x$with_libarchive_bits" = "x32" ; then
  87. st_lib_archive_LIB=lib
  88. elif test "x$with_libarchive_bits" = "x64" ; then
  89. st_lib_archive_LIB=lib64
  90. else
  91. AC_MSG_ERROR([the argument must be either 32 or 64])
  92. fi],
  93. [st_lib_archive_LIB=lib])
  94. AC_MSG_RESULT($st_lib_archive_LIB)
  95. #
  96. # Save the environment before verifying libarchive availability
  97. #
  98. st_lib_archive_SAVECPPFLAGS="$CPPFLAGS"
  99. st_lib_archive_SAVELDFLAGS="$LDFLAGS"
  100. AC_LANG_SAVE
  101. AC_LANG_C
  102. if test "x$st_lib_archive_LOCATION" = "xdefined" ; then
  103. CPPFLAGS="-I$st_lib_archive_DIR/include $st_lib_archive_SAVECPPFLAGS"
  104. LDFLAGS="-L$st_lib_archive_DIR/$st_lib_archive_LIB $st_lib_archive_SAVELDFLAGS"
  105. AC_CHECK_LIB(archive, archive_read_new, [st_lib_archive_found_lib=yes], [st_lib_archive_found_lib=no])
  106. AC_CHECK_HEADER(archive.h, [st_lib_archive_found_hdr=yes], [st_lib_archive_found_hdr=no])
  107. if test "x$st_lib_archive_found_lib" = "xyes" && test "x$st_lib_archive_found_hdr" = "xyes"; then
  108. LIBARCHIVE_CPPFLAGS="-I$dir/include"
  109. LIBARCHIVE_LDFLAGS="-L$dir/$st_lib_archive_LIB"
  110. else
  111. AC_MSG_ERROR([could not find libarchive in the requested location])
  112. fi
  113. else
  114. #
  115. # These are the common install directories for Linux, FreeBSD, Solaris, and Mac.
  116. #
  117. for dir in /usr /usr/local /usr/sfw /opt/csw /opt/local /sw
  118. do
  119. if test -d "$dir" ; then
  120. CPPFLAGS="-I$dir/include $st_lib_archive_SAVECPPFLAGS"
  121. LDFLAGS="-L$dir/$st_lib_archive_LIB $st_lib_archive_SAVELDFLAGS"
  122. AC_CHECK_LIB(archive, archive_read_new, [st_lib_archive_found_lib=yes], [st_lib_archive_found_lib=no])
  123. AC_CHECK_HEADER(archive.h, [st_lib_archive_found_hdr=yes], [st_lib_archive_found_hdr=no])
  124. if test "x$st_lib_archive_found_lib" = "xyes" && test "x$st_lib_archive_found_hdr" = "xyes"; then
  125. LIBARCHIVE_CPPFLAGS="-I$dir/include"
  126. LIBARCHIVE_LDFLAGS="-L$dir/$st_lib_archive_LIB"
  127. break
  128. fi
  129. fi
  130. done
  131. fi
  132. if test "x$st_lib_archive_found_hdr" = "xyes" && test "x$st_lib_archive_found_lib" = "xyes" ; then
  133. LIBARCHIVE_LIBS="-larchive"
  134. AC_DEFINE([HAVE_LIBARCHIVE], [1], [Defined to 1 if libarchive is available for use.])
  135. AC_SUBST(LIBARCHIVE_LIBS)
  136. AC_SUBST(LIBARCHIVE_CPPFLAGS)
  137. AC_SUBST(LIBARCHIVE_LDFLAGS)
  138. fi
  139. #
  140. # Restore the environment now that we're done.
  141. #
  142. AC_LANG_RESTORE
  143. CPPFLAGS="$st_lib_archive_SAVECPPFLAGS"
  144. LDFLAGS="$st_lib_archive_SAVELDFLAGS"
  145. else
  146. AC_MSG_RESULT([no])
  147. fi
  148. AM_CONDITIONAL(LIBARCHIVE, test "x$st_lib_archive_found_lib" = "xyes" && test "x$st_lib_archive_found_hdr" = "xyes")
  149. ])