libpcap.m4 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. dnl libpcap.m4--PCAP libraries and includes
  2. dnl Derrick Brashear
  3. dnl from KTH krb and Arla
  4. dnl $Id: libpcap.m4,v 1.4 2006/01/20 20:21:09 snsimon Exp $
  5. dnl 2010/10/31 (stkn):
  6. dnl rename: PCAP_INC_FLAGS -> PCAP_CPPFLAGS
  7. dnl rename: PCAP_LIB_FLAGS -> PCAP_LDFLAGS (-L flags only)
  8. dnl add: PCAP_LIBS (libs only)
  9. AC_DEFUN([PCAP_INC_WHERE1], [
  10. ac_cv_found_pcap_inc=no
  11. if test -f "$1/pcap.h" ; then
  12. ac_cv_found_pcap_inc=yes
  13. fi
  14. ])
  15. AC_DEFUN([PCAP_INC_WHERE], [
  16. for i in $1; do
  17. AC_MSG_CHECKING(for pcap header in $i)
  18. PCAP_INC_WHERE1($i)
  19. if test "$ac_cv_found_pcap_inc" = "yes"; then
  20. ac_cv_pcap_where_inc=$i
  21. AC_MSG_RESULT(found)
  22. break
  23. else
  24. AC_MSG_RESULT(no found)
  25. fi
  26. done
  27. ])
  28. AC_DEFUN([PCAP_LIB_WHERE1], [
  29. saved_LIBS=$LIBS
  30. LIBS="$saved_LIBS -L$1 -lpcap"
  31. AC_TRY_LINK(,
  32. [pcap_lookupdev("");],
  33. [ac_cv_found_pcap_lib=yes],
  34. ac_cv_found_pcap_lib=no)
  35. LIBS=$saved_LIBS
  36. ])
  37. AC_DEFUN([TEST_LIBPATH], [
  38. changequote(<<, >>)
  39. define(<<AC_CV_FOUND>>, translit(ac_cv_found_$2_lib, <<- *>>, <<__p>>))
  40. changequote([, ])
  41. if test "$AC_CV_FOUND" = "yes"; then
  42. if test \! -r "$1/lib$2.a" -a \! -r "$1/lib$2.so" -a \! -r "$1/lib$2.sl" -a \! -r "$1/lib$2.dylib"; then
  43. AC_CV_FOUND=no
  44. fi
  45. fi
  46. ])
  47. AC_DEFUN([PCAP_LIB_WHERE], [
  48. for i in $1; do
  49. AC_MSG_CHECKING(for pcap library in $i)
  50. PCAP_LIB_WHERE1($i)
  51. TEST_LIBPATH($i, pcap)
  52. if test "$ac_cv_found_pcap_lib" = "yes" ; then
  53. ac_cv_pcap_where_lib=$i
  54. AC_MSG_RESULT(found)
  55. break
  56. else
  57. AC_MSG_RESULT(no found)
  58. fi
  59. done
  60. ])
  61. AC_DEFUN([FIND_LIB_SUBDIR],
  62. [dnl
  63. AC_ARG_WITH([lib-subdir], AC_HELP_STRING([--with-lib-subdir=DIR],[Find libraries in DIR instead of lib]))
  64. AC_CHECK_SIZEOF(long)
  65. AC_CACHE_CHECK([what directory libraries are found in], [ac_cv_cmu_lib_subdir],
  66. [test "X$with_lib_subdir" = "Xyes" && with_lib_subdir=
  67. test "X$with_lib_subdir" = "Xno" && with_lib_subdir=
  68. if test "X$with_lib_subdir" = "X" ; then
  69. ac_cv_cmu_lib_subdir=lib
  70. if test $ac_cv_sizeof_long -eq 4 ; then
  71. test -d /usr/lib32 && ac_cv_cmu_lib_subdir=lib32
  72. test -r /usr/lib/libpcap.so && ac_cv_cmu_lib_subdir=lib
  73. fi
  74. if test $ac_cv_sizeof_long -eq 8 ; then
  75. test -d /usr/lib64 && ac_cv_cmu_lib_subdir=lib64
  76. fi
  77. else
  78. ac_cv_cmu_lib_subdir=$with_lib_subdir
  79. fi])
  80. AC_SUBST(LIB_SUBDIR, $ac_cv_cmu_lib_subdir)
  81. ])
  82. AC_DEFUN([AX_LIB_PCAP], [
  83. AC_REQUIRE([FIND_LIB_SUBDIR])
  84. AC_ARG_WITH(pcap,
  85. [ --with-pcap=PREFIX Compile with PCAP support],
  86. [if test "X$with_pcap" = "X"; then
  87. with_pcap=yes
  88. fi])
  89. AC_ARG_WITH(pcap-lib,
  90. [ --with-pcap-lib=dir use pcap libraries in dir],
  91. [if test "$withval" = "yes" -o "$withval" = "no"; then
  92. AC_MSG_ERROR([No argument for --with-pcap-lib])
  93. fi])
  94. AC_ARG_WITH(pcap-include,
  95. [ --with-pcap-include=dir use pcap headers in dir],
  96. [if test "$withval" = "yes" -o "$withval" = "no"; then
  97. AC_MSG_ERROR([No argument for --with-pcap-include])
  98. fi])
  99. if test "X$with_pcap" != "X"; then
  100. if test "$with_pcap" != "yes"; then
  101. ac_cv_pcap_where_lib=$with_pcap
  102. ac_cv_pcap_where_inc=$with_pcap/include
  103. fi
  104. fi
  105. if test "X$with_pcap_lib" != "X"; then
  106. ac_cv_pcap_where_lib=$with_pcap_lib
  107. fi
  108. if test "X$ac_cv_pcap_where_lib" = "X"; then
  109. PCAP_LIB_WHERE(/usr/$LIB_SUBDIR /usr/local/$LIB_SUBDIR)
  110. fi
  111. if test "X$with_pcap_include" != "X"; then
  112. ac_cv_pcap_where_inc=$with_pcap_include
  113. fi
  114. if test "X$ac_cv_pcap_where_inc" = "X"; then
  115. PCAP_INC_WHERE(/usr/ng/include /usr/include /usr/local/include)
  116. fi
  117. AC_MSG_CHECKING(whether to include pcap)
  118. if test "X$ac_cv_pcap_where_lib" != "X" -a "X$ac_cv_pcap_where_inc" != "X"; then
  119. ac_cv_found_pcap=yes
  120. AC_MSG_RESULT(yes)
  121. PCAP_INC_DIR=$ac_cv_pcap_where_inc
  122. PCAP_LIB_DIR=$ac_cv_pcap_where_lib
  123. PCAP_CPPFLAGS="-I${PCAP_INC_DIR}"
  124. PCAP_LDFLAGS="-L${PCAP_LIB_DIR}"
  125. PCAP_LIBS="-lpcap"
  126. AC_SUBST(PCAP_INC_DIR)
  127. AC_SUBST(PCAP_LIB_DIR)
  128. AC_SUBST(PCAP_CPPFLAGS)
  129. AC_SUBST(PCAP_LDFLAGS)
  130. AC_SUBST(PCAP_LIBS)
  131. AC_DEFINE([HAVE_LIBPCAP],[1],[libpcap])
  132. else
  133. ac_cv_found_pcap=no
  134. AC_MSG_RESULT(no)
  135. fi
  136. ])