configure.ac 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464
  1. dnl
  2. dnl configure.ac:
  3. dnl Autoconf input for iftop.
  4. dnl
  5. dnl I hate autoconf with a passion. It's an utter pain to write these bloody
  6. dnl things and even once you have you find yourself testing for more and more
  7. dnl special cases. But that's OK. Paul is going to maintain it :)
  8. dnl -- Chris Lightfoot
  9. dnl
  10. dnl $Id: configure.ac,v 1.2 2014/01/19 20:28:31 pdw Exp $
  11. dnl
  12. dnl To regenerate everything from source, do:
  13. dnl autoheader
  14. dnl aclocal
  15. dnl automake
  16. dnl autoconf
  17. dnl Now you should have good sources to make into a tarball and distribute.
  18. dnl ./configure (perhaps with some arguments)
  19. dnl make
  20. dnl Tested with automake 1.9.6-1.14 and autoconf 2.59-2.69.
  21. dnl
  22. dnl Boilerplate configuration
  23. dnl
  24. AC_INIT([iftop], [1.0pre4], [pdw@ex-parrot.com], [iftop], [http://www.ex-parrot.com/pdw/iftop/])
  25. AC_CONFIG_AUX_DIR(config)
  26. AC_CANONICAL_SYSTEM
  27. AC_CONFIG_HEADERS([config.h])
  28. AM_INIT_AUTOMAKE
  29. dnl Make sure we have a C compiler....
  30. AC_PROG_CC
  31. AC_HEADER_STDC
  32. dnl
  33. dnl Options to configure.
  34. dnl
  35. AC_ARG_WITH(resolver,
  36. [ --with-resolver=TYPE Technique iftop should use for name resolution.
  37. Valid options are:
  38. netdb use gethostbyaddr_r in multiple
  39. threads.
  40. netdb_1thread use gethostbyaddr_r and
  41. assume it is not reentrant.
  42. ares use the MIT ARES asynchronous
  43. resolver library.
  44. forking use the REALLY SUCKY forking resolver.
  45. guess run experiments to guess a
  46. reasonable value. Only works if you
  47. aren't cross-compiling. This
  48. is the default. guess will
  49. either select netdb or netdb_1thread.
  50. none don't do name resolution.],
  51. [resolver=$withval],
  52. [resolver=guess])
  53. AC_ARG_WITH(libpcap,
  54. [ --with-libpcap=WHERE Where the libpcap packet-capture library is found.
  55. The pcap library should be installed in WHERE/lib,
  56. and the header file in either WHERE/include or
  57. WHERE/include/pcap.
  58. [default=look in standard locations]],
  59. [libpcap_prefix=$withval],
  60. [libpcap_prefix=""])
  61. dnl
  62. dnl Fairly generic checks.
  63. dnl
  64. dnl Checks for system headers.
  65. AC_CHECK_HEADERS([sgtty.h sys/ioctl.h sys/time.h sys/sockio.h termio.h termios.h unistd.h])
  66. dnl Checks for typedefs, structures, and compiler characteristics.
  67. AC_C_CONST
  68. AC_TYPE_SIZE_T
  69. AC_HEADER_TIME
  70. dnl
  71. dnl Are we on a system that uses the STREAMS low-level DLPI interface?
  72. dnl
  73. AC_CHECK_HEADER([sys/dlpi.h],[AC_DEFINE([HAVE_DLPI],1,[Are we running on a STREAMS system with DLPI?])])
  74. dnl Checks for library functions.
  75. AC_CHECK_FUNCS(regcomp select strdup strerror strspn)
  76. AC_SEARCH_LIBS(socket, socket)
  77. AC_SEARCH_LIBS(log, m)
  78. AC_CHECK_FUNC(gethostbyname, ,
  79. [AC_CHECK_LIB(nsl, gethostbyname)] )
  80. AC_SEARCH_LIBS(inet_aton, [socket nsl])
  81. AC_SEARCH_LIBS(inet_pton, [socket nsl])
  82. AC_CHECK_FUNCS(inet_aton inet_pton)
  83. dnl
  84. dnl Find integers of known physical size. This is a pain in the arse because
  85. dnl we can't use AC_CHECK_SIZEOF to find the original variables, since that
  86. dnl function doesn't permit us to include a header file. Sigh.
  87. dnl
  88. for type in u_int8_t u_int16_t u_int32_t ; do
  89. AC_MSG_CHECKING([size of $type])
  90. AC_RUN_IFELSE([AC_LANG_SOURCE([
  91. #include <sys/types.h>
  92. #include <stdio.h>
  93. int main() {
  94. $type dummy;
  95. FILE *f=fopen("conftestval", "w");
  96. if (!f) exit(1);
  97. fprintf(f, "%d\n", sizeof($1));
  98. exit(0);
  99. }
  100. ])], [
  101. x=`cat conftestval`
  102. eval "size_$type=$x"
  103. AC_MSG_RESULT([$x])
  104. ], [
  105. eval "size_$type=0"
  106. AC_MSG_RESULT([unknown type])
  107. ], [
  108. eval "size_$type=0"
  109. AC_MSG_RESULT([can't determine when cross-compiling])
  110. ])
  111. done
  112. dnl Groan. Have to do things this way so that autoheader can do its thing....
  113. AC_DEFINE_UNQUOTED(SIZEOF_U_INT8_T, [$size_u_int8_t], [size of u_int8_t])
  114. AC_DEFINE_UNQUOTED(SIZEOF_U_INT16_T, [$size_u_int16_t], [size of u_int16_t])
  115. AC_DEFINE_UNQUOTED(SIZEOF_U_INT32_T, [$size_u_int32_t], [size of u_int32_t])
  116. dnl If we already have these types, don't piss about any more....
  117. if test $size_u_int8_t != 1 || test $size_u_int16_t != 2 || test $size_u_int32_t != 4 ; then
  118. dnl XXXif test $size_u_int8_t != 1 -o $size_u_int16_t != 2 -o $size_u_int32_t != 4 ; then
  119. do_int_types=1
  120. AC_CHECK_HEADERS(
  121. stdint.h dnl C99
  122. sys/inttypes.h, dnl Solaris
  123. [do_int_types=0; break])
  124. if test $do_int_types = 1 ; then
  125. dnl No C99 int types, so figure them out from basic types.
  126. AC_CHECK_SIZEOF(unsigned short int)
  127. AC_CHECK_SIZEOF(unsigned int)
  128. AC_CHECK_SIZEOF(unsigned long int)
  129. else
  130. dnl Just use the C99 ones.
  131. AC_DEFINE(HAVE_C99_INTS, 1, [C99 fixed-width int types available])
  132. fi
  133. fi
  134. dnl
  135. dnl Name resolution.
  136. dnl
  137. dnl This is complicated because we need some sort of reentrant mechanism for
  138. dnl name resolution. Naturally, UNIX vendors have come up with a variety of
  139. dnl incompatible schemes for this, many of which don't work at all.
  140. dnl
  141. dnl First, the default resolver, which uses getnameinfo or gethostbyaddr_r. If
  142. dnl not available, we fall back to gethostbyaddr. We could fall back to ARES,
  143. dnl but that's probably not available on typical machines.
  144. dnl If we've been asked to guess, remember that fact in specified_resolver.
  145. dnl From this point on, resolver is our preferred resolver given the
  146. dnl experiments we've done so far, or "guess" if we have no idea.
  147. specified_resolver=$resolver
  148. if test x$specified_resolver = xguess ; then
  149. dnl Best possibility is getnameinfo.
  150. use_getnameinfo=0
  151. AC_SEARCH_LIBS(getnameinfo, [nsl], [use_getnameinfo=1])
  152. dnl XXX For the moment, don't use getnameinfo, since it isn't actually
  153. dnl thread safe on, e.g., NetBSD.
  154. use_getnameinfo=0
  155. if test $use_getnameinfo = 1 ; then
  156. dnl Done.
  157. AC_DEFINE(USE_GETNAMEINFO, 1, [use getnameinfo for name resolution])
  158. else
  159. dnl Best hope is netdb, which presently means gethostbyaddr_r.
  160. resolver=netdb
  161. fi
  162. fi
  163. if test x$resolver = xnetdb ; then
  164. dnl Can use gethostbyaddr_r?
  165. AC_SEARCH_LIBS(gethostbyaddr_r, [nsl], , [resolver=guess])
  166. if test x$resolver = xguess && test x$specified_resolver != xguess ; then
  167. dnl They wanted gethostbyaddr_r, but they can't have it, so stop.
  168. AC_MSG_ERROR([no library defines gethostbyaddr_r])
  169. fi
  170. fi
  171. dnl We still might do gethostbyaddr_r. Figure out whether we have
  172. dnl glibc-style or Solaris-style gethostbyaddr_r (or neither...).
  173. dnl Separate determining how to call gethostbyaddr_r from testing
  174. dnl whether it works so we can support cross-compilation.
  175. if test x$resolver = xnetdb ; then
  176. AC_MSG_CHECKING([how to call gethostbyaddr_r])
  177. dnl Try 7 arguments returning a struct hostent*.
  178. AC_LINK_IFELSE([AC_LANG_SOURCE([`cat config/hostentp_ghba_r.c`])],
  179. [AC_MSG_RESULT([7 args])
  180. ghba_args=8
  181. AC_DEFINE(GETHOSTBYADDR_R_RETURNS_HOSTENT_P, 1,
  182. [7-argument gethostbyaddr_r returns struct hostent*])], [
  183. dnl Try 8 arguments returning an int.
  184. AC_LINK_IFELSE([AC_LANG_SOURCE([`cat config/int_ghba_r.c`])],
  185. [AC_MSG_RESULT([8 args, int return])
  186. ghba_args=8
  187. AC_DEFINE(GETHOSTBYADDR_R_RETURNS_INT, 1,
  188. [8-argument gethostbyaddr_r returns int])], [
  189. dnl Neither.
  190. AC_MSG_RESULT([don't know how])
  191. resolver=guess])])
  192. if test x$resolver = xguess && test x$specified_resolver != xguess ; then
  193. dnl They wanted gethostbyaddr_r, but they can't have it, so stop.
  194. AC_MSG_ERROR([gethostbyaddr_r has no known calling convention])
  195. fi
  196. fi
  197. dnl If we still want to do gethostbyaddr_r, and we aren't
  198. dnl cross-compiling, test it.
  199. if test x$resolver = xnetdb ; then
  200. if test x$ghba_args = x8 ; then
  201. testfile=int_ghba_r
  202. else
  203. testfile=hostentp_ghba_r
  204. fi
  205. AC_MSG_CHECKING(gethostbyaddr_r usability)
  206. AC_RUN_IFELSE([AC_LANG_SOURCE([`cat config/$testfile.c`])],
  207. [AC_MSG_RESULT([yes])],
  208. [AC_MSG_RESULT([no])
  209. resolver=guess],
  210. [AC_MSG_RESULT([can't test because we are cross-compiling])])
  211. if test x$resolver = xguess ; then
  212. if test x$specified_resolver = xguess ; then
  213. AC_MSG_RESULT([gethostbyaddr_r doesn't work, so we'll try something else])
  214. else
  215. dnl They wanted gethostbyaddr_r, but it doesn't work, so stop.
  216. AC_MSG_ERROR([gethostbyaddr_r doesn't work])
  217. fi
  218. fi
  219. fi
  220. dnl We found a gethostbyaddr_r we know how to use and which seems to
  221. dnl work.
  222. if test x$resolver = xnetdb ; then
  223. AC_DEFINE(USE_GETHOSTBYADDR_R, 1, [use gethostbyaddr_r for name resolution])
  224. fi
  225. dnl They may have asked for ares.
  226. if test x$resolver = xares ; then
  227. dnl See if ares is to hand....
  228. AC_SEARCH_LIBS(ares_init, [ares], [
  229. AC_DEFINE(USE_ARES, 1, [use ARES for name resolution])
  230. ], [
  231. dnl They asked for ares, but we can't give it to them, so stop.
  232. AC_MSG_ERROR([can't find ARES. Re-run configure and ask for a different resolver.])])
  233. fi
  234. dnl Last thing to try if we haven't decided yet is netdb_1thread.
  235. if test x$resolver = xguess ; then
  236. resolver=netdb_1thread
  237. fi
  238. dnl Ugh. Both the single-threaded and the forking resolvers use gethostbyaddr.
  239. if test x$resolver = xnetdb_1thread || test x$resolver = xforking ; then
  240. AC_SEARCH_LIBS(gethostbyaddr, [nsl], , [
  241. AC_MSG_ERROR([gethostbyaddr is not available. You will have to
  242. recompile with no name resolution at all.])])
  243. if test x$resolver = xnetdb_1thread ; then
  244. AC_MSG_WARN([using single-threaded resolver with gethostbyaddr
  245. Consider obtaining ARES or a machine with a working gethostbyaddr_r.])
  246. AC_DEFINE(USE_GETHOSTBYADDR, 1, [use gethostbyaddr for name resolution])
  247. else
  248. AC_DEFINE(USE_FORKING_RESOLVER, 1, [use a REALLY SUCKY forking resolver for name resolution])
  249. fi
  250. fi
  251. dnl Otherwise, no resolver at all. Boo hoo.
  252. dnl
  253. dnl Find libpcap.
  254. dnl
  255. if test x$libpcap_prefix = x ; then
  256. libpcap_prefix="/usr /usr/local /opt /software"
  257. fi
  258. AC_MSG_CHECKING([where to find pcap.h])
  259. foundpcaph=0
  260. oldCPPFLAGS=$CPPFLAGS
  261. for test_prefix in "" $libpcap_prefix ; do
  262. for x in "" /pcap ; do
  263. if test x$test_prefix != x ; then
  264. CPPFLAGS="$oldCPPFLAGS -I$test_prefix/include$x"
  265. fi
  266. AC_TRY_CPP([
  267. #include <pcap.h>
  268. ], [
  269. AC_MSG_RESULT([$test_prefix/include$x])
  270. foundpcaph=1
  271. break
  272. ])
  273. done
  274. if test $foundpcaph = 1 ; then
  275. break
  276. fi
  277. done
  278. if test $foundpcaph = 0 ; then
  279. AC_MSG_RESULT([no idea])
  280. AC_MSG_ERROR([can't find pcap.h
  281. You're not going to get very far without libpcap.])
  282. else
  283. dnl assume that -lpcap is under $test_prefix/lib
  284. if test x$test_prefix != x ; then
  285. LDFLAGS="$LDFLAGS -L$test_prefix/lib"
  286. fi
  287. AC_CHECK_LIB(pcap, pcap_open_live, , [
  288. AC_MSG_ERROR([can't find libpcap
  289. You're not going to get very far without libpcap.])
  290. ])
  291. fi
  292. foundpcap=0
  293. AC_CHECK_HEADERS([pcap.h pcap/pcap.h], [
  294. foundpcap=1
  295. break
  296. ])
  297. if test $foundpcap = 0 ; then
  298. AC_MSG_ERROR([can't find pcap.h
  299. You're not going to get very far without libpcap.])
  300. fi
  301. dnl
  302. dnl Curses. Really, we need ncurses or something similarly advanced, since
  303. dnl we use the (apparently obscure) mvchgat function. Unfortunately, there's
  304. dnl a solid chance that mvchgat is a macro, so we can't just use
  305. dnl AC_SEARCH_LIBS....
  306. dnl
  307. AC_MSG_CHECKING([for a curses library containing mvchgat])
  308. oldLIBS=$LIBS
  309. for curseslib in ncursesw curses ncurses ; do
  310. LIBS="$oldLIBS -l$curseslib"
  311. AC_TRY_LINK([
  312. #include <$curseslib.h>
  313. ], [
  314. mvchgat(0, 0, 1, A_REVERSE, 0, NULL)
  315. ], [
  316. foundcurseslib=$curseslib
  317. break
  318. ])
  319. done
  320. if test x$foundcurseslib = x ; then
  321. AC_MSG_RESULT([none found])
  322. AC_MSG_ERROR([Curses! Foiled again!
  323. (Can't find a curses library supporting mvchgat.)
  324. Consider installing ncurses.])
  325. else
  326. AC_MSG_RESULT([-l$foundcurseslib])
  327. fi
  328. dnl
  329. dnl POSIX threads. Different systems like different combinations of flags,
  330. dnl libraries, etc. We use a test program to figure this stuff out.
  331. dnl
  332. AC_MSG_CHECKING([POSIX threads compilation])
  333. thrfail=1
  334. oldCFLAGS=$CFLAGS
  335. oldLIBS=$LIBS
  336. for flag in "" -mt -pthread -thread ; do
  337. CFLAGS="$oldCFLAGS $flag"
  338. for lib in "" -lpthread "-lpthread -lposix4" ; do
  339. LIBS="$oldLIBS $lib"
  340. AC_LINK_IFELSE([AC_LANG_SOURCE([`cat config/pthread.c`])], [
  341. foundthrlib=$lib
  342. foundthrflag=$flag
  343. thrfail=0
  344. break
  345. ])
  346. done
  347. if test $thrfail = 0 ; then
  348. break
  349. fi
  350. done
  351. if test $thrfail = 1 ; then
  352. AC_MSG_RESULT([no idea])
  353. AC_MSG_ERROR([can't figure out how to compile with POSIX threads
  354. If your system actually supports POSIX threads, this means we've messed up.])
  355. fi
  356. AC_MSG_RESULT([CFLAGS=$foundthrflag and LIBS=$foundthrlib])
  357. AC_MSG_CHECKING([POSIX threads usability])
  358. AC_RUN_IFELSE([AC_LANG_SOURCE([`cat config/pthread.c`])],
  359. [AC_MSG_RESULT([yes])],
  360. [AC_MSG_ERROR(
  361. [it fails. We probably guessed the wrong CFLAGS.])],
  362. [AC_MSG_RESULT([can't test because we are cross-compiling])])
  363. dnl
  364. dnl Are we on a system (like Solaris) that requires promiscuous mode in order to
  365. dnl see any outgoing packets?
  366. dnl
  367. AC_MSG_CHECKING([if we need to enable promiscuous mode by default])
  368. enable_default_promiscuous="no"
  369. case "$host_os" in
  370. solaris*) enable_default_promiscuous="yes" ;;
  371. esac
  372. AC_ARG_ENABLE(default-promiscuous,
  373. [ --enable-default-promiscuous If enabled, iftop will operate in promiscuous mode
  374. to capture outgoing packets])
  375. AC_MSG_RESULT([$enable_default_promiscuous])
  376. if test x"$enable_default_promiscuous" = x"yes"; then
  377. AC_DEFINE([NEED_PROMISCUOUS_FOR_OUTGOING],1,[Enable default promiscuous mode to capture outgoing packets])
  378. fi
  379. dnl
  380. dnl Wahey! This might even work.
  381. dnl
  382. AC_SUBST(ac_aux_dir)
  383. AC_OUTPUT(Makefile config/Makefile)
  384. if echo $PACKAGE_VERSION | grep 'pre' > /dev/null ; then
  385. AC_MSG_WARN([
  386. ******************************************************************************
  387. This is a pre-release version. Pre-releases are subject to limited
  388. announcements, and therefore limited circulation, as a means of testing
  389. the more widely circulated final releases.
  390. Please do not be surprised if this release is broken, and if it is broken, do
  391. not assume that someone else has spotted it. Instead, please drop a note on
  392. the mailing list, or a brief email to me on pdw@ex-parrot.com
  393. Thank you for taking the time to be the testing phase of this development
  394. process.
  395. Paul Warren
  396. ******************************************************************************
  397. ])
  398. fi