configure.in 14.4 KB
Newer Older
chris's avatar
chris committed
1 2 3 4 5 6 7 8 9 10 11
dnl
dnl configure.in:
dnl Autoconf input for iftop.
dnl
dnl I hate autoconf with a passion. It's an utter pain to write these bloody
dnl things and even once you have you find yourself testing for more and more
dnl special cases. But that's OK. Paul is going to maintain it :)
dnl     -- Chris Lightfoot
dnl
dnl $Id$
dnl
12 13 14 15 16 17 18 19 20
dnl To regenerate everything from source, do:
dnl    autoheader
dnl    aclocal
dnl    automake
dnl    autoconf
dnl Now you should have good sources to make into a tarball and distribute.
dnl    ./configure     (perhaps with some arguments)
dnl    make
dnl Tested with Automake 1.4 and autoconf 2.59.
chris's avatar
chris committed
21 22 23 24 25
dnl
dnl Boilerplate configuration
dnl

AC_INIT(iftop.c)
26

chris's avatar
chris committed
27
AC_CONFIG_AUX_DIR(config)
28 29 30

AC_CANONICAL_SYSTEM

chris's avatar
chris committed
31
AM_CONFIG_HEADER(config.h)
pdw's avatar
pdw committed
32
AM_INIT_AUTOMAKE(iftop, "1.0pre2")
chris's avatar
chris committed
33 34 35 36 37 38 39 40 41 42 43 44

AC_DEFINE_UNQUOTED(IFTOP_VERSION, "$VERSION", [The iftop version number])

dnl Make sure we have a C compiler....
AC_PROG_CC
AC_HEADER_STDC

dnl
dnl Options to configure.
dnl

AC_ARG_WITH(resolver,
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
    [  --with-resolver=TYPE    Technique iftop should use for name resolution.  
                          Valid options are:
			  netdb          use gethostbyaddr_r in multiple
			                 threads.
			  netdb_1thread  use gethostbyaddr_r and
					 assume it is not reentrant.
			  ares           use the MIT ARES asynchronous
					 resolver library.
			  forking        use the REALLY SUCKY forking resolver.
			  guess          run experiments to guess a
					 reasonable value.  Only works if you
					 aren't cross-compiling.  This
					 is the default.  guess will
					 either select netdb or netdb_1thread.
			  none           don't do name resolution.],
chris's avatar
chris committed
60
    [resolver=$withval],
61
    [resolver=guess])
chris's avatar
chris committed
62

chris's avatar
chris committed
63 64 65 66 67 68 69 70 71
AC_ARG_WITH(libpcap,
    [  --with-libpcap=WHERE    Where the libpcap packet-capture library is found.
                          The pcap library should be installed  in WHERE/lib,
                          and the header file in either WHERE/include or
                          WHERE/include/pcap.
                          [default=look in standard locations]],
    [libpcap_prefix=$withval],
    [libpcap_prefix=""])

chris's avatar
chris committed
72 73 74 75 76 77 78 79 80 81 82 83
dnl
dnl Fairly generic checks.
dnl

dnl Checks for system headers.
AC_CHECK_HEADERS(sys/ioctl.h sys/time.h sys/sockio.h unistd.h)

dnl Checks for typedefs, structures, and compiler characteristics.
AC_C_CONST
AC_TYPE_SIZE_T
AC_HEADER_TIME

84 85 86 87 88 89
dnl
dnl Are we on a system that uses the STREAMS low-level DLPI interface?
dnl

AC_CHECK_HEADER([sys/dlpi.h],[AC_DEFINE([HAVE_DLPI],1,[Are we running on a STREAMS system with DLPI?])])

chris's avatar
chris committed
90 91 92 93 94 95 96 97
dnl Checks for library functions.
AC_CHECK_FUNCS(regcomp select strdup strerror strspn)

AC_SEARCH_LIBS(socket, socket)
AC_SEARCH_LIBS(log, m)
AC_CHECK_FUNC(gethostbyname, ,
	[AC_CHECK_LIB(nsl, gethostbyname)] )

98 99
AC_SEARCH_LIBS(inet_aton, [socket nsl])
AC_SEARCH_LIBS(inet_pton, [socket nsl])
chris's avatar
chris committed
100 101 102 103 104 105 106 107 108 109
AC_CHECK_FUNCS(inet_aton inet_pton)

dnl
dnl Find integers of known physical size. This is a pain in the arse because
dnl we can't use AC_CHECK_SIZEOF to find the original variables, since that
dnl function doesn't permit us to include a header file. Sigh.
dnl

for type in u_int8_t u_int16_t u_int32_t ; do
    AC_MSG_CHECKING([size of $type])
chris's avatar
chris committed
110
    AC_RUN_IFELSE([
chris's avatar
chris committed
111 112 113 114 115 116 117 118 119
#include <sys/types.h>
#include <stdio.h>
int main() {
    $type dummy;
    FILE *f=fopen("conftestval", "w");
    if (!f) exit(1);
    fprintf(f, "%d\n", sizeof($1));
    exit(0);
}
chris's avatar
chris committed
120
    ], [
chris's avatar
chris committed
121 122 123
        x=`cat conftestval`
        eval "size_$type=$x"
        AC_MSG_RESULT([$x])
chris's avatar
chris committed
124
    ], [
chris's avatar
chris committed
125 126
        eval "size_$type=0"
        AC_MSG_RESULT([unknown type])
chris's avatar
chris committed
127 128 129 130
    ], [
        eval "size_$type=0"
        AC_MSG_RESULT([can't determine when cross-compiling])
    ])
chris's avatar
chris committed
131 132 133 134 135 136 137 138
done

dnl Groan. Have to do things this way so that autoheader can do its thing....
AC_DEFINE_UNQUOTED(SIZEOF_U_INT8_T,  [$size_u_int8_t],  [size of u_int8_t])
AC_DEFINE_UNQUOTED(SIZEOF_U_INT16_T, [$size_u_int16_t], [size of u_int16_t])
AC_DEFINE_UNQUOTED(SIZEOF_U_INT32_T, [$size_u_int32_t], [size of u_int32_t])

dnl If we already have these types, don't piss about any more....
chris's avatar
chris committed
139 140 141

if test $size_u_int8_t != 1 || test $size_u_int16_t != 2 || test $size_u_int32_t != 4 ; then
dnl XXXif test $size_u_int8_t != 1 -o $size_u_int16_t != 2 -o $size_u_int32_t != 4 ; then
chris's avatar
chris committed
142 143
    do_int_types=1
    AC_CHECK_HEADERS(
chris's avatar
chris committed
144 145
        stdint.h             dnl C99
        sys/inttypes.h,      dnl Solaris
chris's avatar
chris committed
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169
        [do_int_types=0; break])

    if test $do_int_types = 1 ; then
        dnl No C99 int types, so figure them out from basic types.
        AC_CHECK_SIZEOF(unsigned short int)
        AC_CHECK_SIZEOF(unsigned int)
        AC_CHECK_SIZEOF(unsigned long int)
    else
        dnl Just use the C99 ones.
        AC_DEFINE(HAVE_C99_INTS, 1, [C99 fixed-width int types available])
    fi
fi

dnl
dnl Name resolution.
dnl
dnl This is complicated because we need some sort of reentrant mechanism for
dnl name resolution. Naturally, UNIX vendors have come up with a variety of
dnl incompatible schemes for this, many of which don't work at all.
dnl

dnl First, the default resolver, which uses getnameinfo or gethostbyaddr_r. If
dnl not available, we fall back to gethostbyaddr. We could fall back to ARES,
dnl but that's probably not available on typical machines.
170 171 172 173 174 175

dnl If we've been asked to guess, remember that fact in specified_resolver.
dnl From this point on, resolver is our preferred resolver given the
dnl experiments we've done so far, or "guess" if we have no idea.
specified_resolver=$resolver
if test x$specified_resolver = xguess ; then
chris's avatar
chris committed
176 177
    dnl Best possibility is getnameinfo.
    use_getnameinfo=0
178
    AC_SEARCH_LIBS(getnameinfo, [nsl], [use_getnameinfo=1])
chris's avatar
chris committed
179 180 181 182 183 184 185 186 187

    dnl XXX For the moment, don't use getnameinfo, since it isn't actually
    dnl thread safe on, e.g., NetBSD.
    use_getnameinfo=0

    if test $use_getnameinfo = 1 ; then
        dnl Done.
        AC_DEFINE(USE_GETNAMEINFO, 1, [use getnameinfo for name resolution])
    else
188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248
	dnl Best hope is netdb, which presently means gethostbyaddr_r.
	resolver=netdb
    fi
fi

if test x$resolver = xnetdb ; then
    dnl Can use gethostbyaddr_r?
    AC_SEARCH_LIBS(gethostbyaddr_r, [nsl], , [resolver=guess])
    if test x$resolver = xguess && test x$specified_resolver != xguess ; then
       dnl They wanted gethostbyaddr_r, but they can't have it, so stop.
       AC_MSG_ERROR([no library defines gethostbyaddr_r])
    fi
fi

dnl We still might do gethostbyaddr_r.  Figure out whether we have
dnl glibc-style or Solaris-style gethostbyaddr_r (or neither...).
dnl Separate determining how to call gethostbyaddr_r from testing
dnl whether it works so we can support cross-compilation.            
if test x$resolver = xnetdb ; then
    AC_MSG_CHECKING([how to call gethostbyaddr_r])
    dnl Try 7 arguments returning a struct hostent*.
    AC_LINK_IFELSE(AC_LANG_SOURCE([`cat config/hostentp_ghba_r.c`]),
                   [AC_MSG_RESULT([7 args])
		    ghba_args=8
	            AC_DEFINE(GETHOSTBYADDR_R_RETURNS_HOSTENT_P, 1,
                    [7-argument gethostbyaddr_r returns struct hostent*])], [
    dnl Try 8 arguments returning an int.
    AC_LINK_IFELSE(AC_LANG_SOURCE([`cat config/int_ghba_r.c`]),
                   [AC_MSG_RESULT([8 args, int return])
		    ghba_args=8
	            AC_DEFINE(GETHOSTBYADDR_R_RETURNS_INT, 1,
                    [8-argument gethostbyaddr_r returns int])], [
    dnl Neither.
    AC_MSG_RESULT([don't know how])
    resolver=guess])])
    if test x$resolver = xguess && test x$specified_resolver != xguess ; then
       dnl They wanted gethostbyaddr_r, but they can't have it, so stop.
       AC_MSG_ERROR([gethostbyaddr_r has no known calling convention])
    fi
fi

dnl If we still want to do gethostbyaddr_r, and we aren't
dnl cross-compiling, test it.
if test x$resolver = xnetdb ; then
    if test x$ghba_args = x8 ; then
       testfile=int_ghba_r
    else
       testfile=hostentp_ghba_r
    fi
    AC_MSG_CHECKING(gethostbyaddr_r usability)
    AC_RUN_IFELSE([`cat config/$testfile.c`],
                  [AC_MSG_RESULT([yes])],
		  [AC_MSG_RESULT([no])
		   resolver=guess],
		  [AC_MSG_RESULT([can't test because we are cross-compiling])])
    if test x$resolver = xguess ; then
        if test x$specified_resolver = xguess ; then
           AC_MSG_RESULT([gethostbyaddr_r doesn't work, so we'll try something else])
        else
           dnl They wanted gethostbyaddr_r, but it doesn't work, so stop.
           AC_MSG_ERROR([gethostbyaddr_r doesn't work])
chris's avatar
chris committed
249 250 251 252
        fi
    fi
fi

253 254 255 256 257 258 259
dnl We found a gethostbyaddr_r we know how to use and which seems to
dnl work.
if test x$resolver = xnetdb ; then
    AC_DEFINE(USE_GETHOSTBYADDR_R, 1, [use gethostbyaddr_r for name resolution])
fi

dnl They may have asked for ares.
chris's avatar
chris committed
260 261
if test x$resolver = xares ; then
    dnl See if ares is to hand....
262
    AC_SEARCH_LIBS(ares_init, [ares], [
chris's avatar
chris committed
263 264
        AC_DEFINE(USE_ARES, 1, [use ARES for name resolution])
        ], [
265 266
        dnl They asked for ares, but we can't give it to them, so stop.
        AC_MSG_ERROR([can't find ARES.  Re-run configure and ask for a different resolver.])])
chris's avatar
chris committed
267 268
fi

269 270 271 272
dnl Last thing to try if we haven't decided yet is netdb_1thread.
if test x$resolver = xguess ; then
   resolver=netdb_1thread
fi
chris's avatar
chris committed
273

pdw's avatar
pdw committed
274 275
dnl Ugh. Both the single-threaded and the forking resolvers use gethostbyaddr.
if test x$resolver = xnetdb_1thread || test x$resolver = xforking ; then
276
    AC_SEARCH_LIBS(gethostbyaddr, [nsl], , [
277 278
        AC_MSG_ERROR([gethostbyaddr is not available.  You will have to 
  recompile with no name resolution at all.])])
chris's avatar
chris committed
279

pdw's avatar
pdw committed
280 281
    if test x$resolver = xnetdb_1thread ; then
        AC_MSG_WARN([using single-threaded resolver with gethostbyaddr
chris's avatar
chris committed
282
  Consider obtaining ARES or a machine with a working gethostbyaddr_r.])
pdw's avatar
pdw committed
283 284 285 286
        AC_DEFINE(USE_GETHOSTBYADDR, 1, [use gethostbyaddr for name resolution])
    else
        AC_DEFINE(USE_FORKING_RESOLVER, 1, [use a REALLY SUCKY forking resolver for name resolution])
    fi
chris's avatar
chris committed
287 288 289 290 291
fi

dnl Otherwise, no resolver at all. Boo hoo.

dnl
chris's avatar
chris committed
292
dnl Find libpcap.
chris's avatar
chris committed
293 294
dnl

chris's avatar
chris committed
295 296 297 298 299 300 301
if test x$libpcap_prefix = x ; then
    libpcap_prefix="/usr /usr/local /opt /software"
fi

AC_MSG_CHECKING([where to find pcap.h])
foundpcaph=0
oldCPPFLAGS=$CPPFLAGS
302
for test_prefix in "" $libpcap_prefix ; do
chris's avatar
chris committed
303
    for x in "" /pcap ; do
304 305
        if test x$test_prefix != x ; then
            CPPFLAGS="$oldCPPFLAGS -I$test_prefix/include$x"
chris's avatar
chris committed
306 307 308 309
        fi
        AC_TRY_CPP([
#include <pcap.h>
        ], [
310
        AC_MSG_RESULT([$test_prefix/include$x])
chris's avatar
chris committed
311 312 313 314 315 316 317 318 319 320 321 322
        foundpcaph=1
        break
        ])
    done
    if test $foundpcaph = 1 ; then
        break
    fi
done

if test $foundpcaph = 0 ; then
    AC_MSG_RESULT([no idea])
    AC_MSG_ERROR([can't find pcap.h
chris's avatar
chris committed
323
  You're not going to get very far without libpcap.])
chris's avatar
chris committed
324
else
325 326
    dnl assume that -lpcap is under $test_prefix/lib
    if test x$test_prefix != x ; then
chris's avatar
chris committed
327
        LDFLAGS="$LDFLAGS -L$test_prefix/lib"
chris's avatar
chris committed
328 329 330 331 332 333
    fi
    AC_CHECK_LIB(pcap, pcap_open_live, , [
            AC_MSG_ERROR([can't find libpcap
  You're not going to get very far without libpcap.])
        ])
fi
chris's avatar
chris committed
334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354

foundpcap=0
AC_CHECK_HEADERS([pcap.h pcap/pcap.h], [
    foundpcap=1
    break
    ])

if test $foundpcap = 0 ; then
    AC_MSG_ERROR([can't find pcap.h
  You're not going to get very far without libpcap.])
fi

dnl
dnl Curses. Really, we need ncurses or something similarly advanced, since
dnl we use the (apparently obscure) mvchgat function. Unfortunately, there's
dnl a solid chance that mvchgat is a macro, so we can't just use
dnl AC_SEARCH_LIBS....
dnl

AC_MSG_CHECKING([for a curses library containing mvchgat])
oldLIBS=$LIBS
355
for curseslib in ncursesw curses ncurses ; do
chris's avatar
chris committed
356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381
    LIBS="$oldLIBS -l$curseslib"
    AC_TRY_LINK([
#include <curses.h>
        ], [
        mvchgat(0, 0, 1, A_REVERSE, 0, NULL)
        ], [
        foundcurseslib=$curseslib
        break
        ])
done

if test x$foundcurseslib = x ; then
    AC_MSG_RESULT([none found])
    AC_MSG_ERROR([Curses! Foiled again!
  (Can't find a curses library supporting mvchgat.)
  Consider installing ncurses.])
else
    AC_MSG_RESULT([-l$foundcurseslib])
fi


dnl
dnl POSIX threads. Different systems like different combinations of flags,
dnl libraries, etc. We use a test program to figure this stuff out.
dnl

382
AC_MSG_CHECKING([POSIX threads compilation])
chris's avatar
chris committed
383 384 385 386 387 388 389
thrfail=1
oldCFLAGS=$CFLAGS
oldLIBS=$LIBS
for flag in "" -mt -pthread -thread ; do
    CFLAGS="$oldCFLAGS $flag"
    for lib in "" -lpthread "-lpthread -lposix4" ; do
        LIBS="$oldLIBS $lib"
390
        AC_LINK_IFELSE(AC_LANG_SOURCE([`cat config/pthread.c`]), [
chris's avatar
chris committed
391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407
            foundthrlib=$lib
            foundthrflag=$flag
            thrfail=0
            break
            ])
    done
    if test $thrfail = 0 ; then
        break
    fi
done

if test $thrfail = 1 ; then
    AC_MSG_RESULT([no idea])
    AC_MSG_ERROR([can't figure out how to compile with POSIX threads
  If your system actually supports POSIX threads, this means we've messed up.])
fi

408 409 410 411 412 413 414 415
AC_MSG_RESULT([CFLAGS=$foundthrflag and LIBS=$foundthrlib])
AC_MSG_CHECKING([POSIX threads usability])
AC_RUN_IFELSE([`cat config/pthread.c`],
	      [AC_MSG_RESULT([yes])],
              [AC_MSG_ERROR(
	       [it fails.  We probably guessed the wrong CFLAGS.])],
	      [AC_MSG_RESULT([can't test because we are cross-compiling])])

chris's avatar
chris committed
416
dnl
417 418
dnl Are we on a system (like Solaris) that requires promiscuous mode in order to
dnl see any outgoing packets?
chris's avatar
chris committed
419 420
dnl

421 422 423 424 425 426 427 428 429
AC_MSG_CHECKING([if we need to enable promiscuous mode by default])

enable_default_promiscuous="no"

case "$host_os" in
solaris*) enable_default_promiscuous="yes" ;;
esac

AC_ARG_ENABLE(default-promiscuous,
430 431
	[  --enable-default-promiscuous If enabled, iftop will operate in promiscuous mode 
                          to capture outgoing packets])
432 433 434 435 436 437 438 439 440 441

AC_MSG_RESULT([$enable_default_promiscuous])

if test x"$enable_default_promiscuous" = x"yes"; then
	AC_DEFINE([NEED_PROMISCUOUS_FOR_OUTGOING],1,[Enable default promiscuous mode to capture outgoing packets])
fi

dnl
dnl Wahey! This might even work.
dnl
chris's avatar
chris committed
442 443 444 445 446

AC_SUBST(ac_aux_dir)

AC_OUTPUT(Makefile config/Makefile)

pdw's avatar
pdw committed
447 448 449 450 451 452 453 454
if echo $VERSION | grep 'pre' ; then 
	AC_MSG_WARN([
******************************************************************************

This is a pre-release version.  Pre-releases are subject to limited 
announcements, and therefore limited circulation, as a means of testing
the more widely circulated final releases.  

455 456 457
Please do not be surprised if this release is broken, and if it is broken, do
not assume that someone else has spotted it.  Instead, please drop a note on
the mailing list, or a brief email to me on pdw@ex-parrot.com
pdw's avatar
pdw committed
458 459 460 461 462 463 464 465 466

Thank you for taking the time to be the testing phase of this development
process.

Paul Warren

******************************************************************************
])
fi