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