1# Require autoconf 2.13 -*- mode: fundamental; -*-
2AC_PREREQ(2.13)
3
4dnl Process this file with autoconf to produce a configure script.
5AC_INIT(nmap.cc)
6
7dnl Give us the --enable-nls option, to choose which translated man pages get
8dnl installed. This gets replaced with AM_GNU_GETTEXT for full gettext support.
9AM_NLS
10
11trace_use=""
12trace_no_use=""
13
14AC_ARG_WITH(localdirs,
15AC_HELP_STRING([--with-localdirs], [Explicitly ask compiler to use /usr/local/{include,libs} if they exist ]),
16  [ case "$with_localdirs" in
17      yes)
18        user_localdirs=1
19        ;;
20      no)
21        user_localdirs=0
22        ;;
23    esac
24    ],
25  [ user_localdirs=0 ] )
26
27if test "$user_localdirs" = 1; then
28  trace_use="$trace_use localdirs"
29   if test -d /usr/local/lib; then
30     LDFLAGS="$LDFLAGS -L/usr/local/lib"
31     fi
32   if test -d /usr/local/include; then
33     CPPFLAGS="$CPPFLAGS -I/usr/local/include"
34   fi
35else
36  trace_no_use="$trace_no_use localdirs"
37fi
38
39dnl Let subdirs configure scripts find the Nmap source dir
40if test "${top_nmap_srcdir+set}" != set; then
41  top_nmap_srcdir=`cd "$srcdir" && pwd`
42  export top_nmap_srcdir
43fi
44
45libpcapdir=libpcap
46AC_SUBST(libpcapdir)
47
48LIBSSH2DIR=libssh2
49AC_SUBST(LIBSSH2DIR)
50
51ZLIBDIR=libz
52AC_SUBST(ZLIBDIR)
53
54pcredir=libpcre
55AC_SUBST(pcredir)
56
57dnl use nmap_config.h instead of -D macros
58AC_CONFIG_HEADER(nmap_config.h)
59
60dnl Host specific hacks
61AC_CANONICAL_HOST
62AC_C_INLINE
63
64dnl Checks for programs.
65AC_PROG_CC
66AC_PROG_CXX
67AC_PROG_RANLIB
68AC_PROG_INSTALL
69AC_PROG_AWK
70
71dnl For nse_fs.cc
72dnl LARGE_FILES_IF_NOT_BROKEN
73
74if test -n "$GXX"; then
75  # -fno-strict-aliasing disables strict-aliasing optimizations that assume
76  # that pointers of different types never point to the same object.
77  CXXFLAGS="$CXXFLAGS -Wall -fno-strict-aliasing"
78fi
79
80CFLAGS="$CFLAGS -Wall"
81
82# Remember that all following tests will run with this CXXFLAGS by default
83AC_MSG_CHECKING(for __func__)
84AH_TEMPLATE(__func__, [C99-specified function identifier])
85AC_TRY_COMPILE([
86#include <stdio.h>
87],[printf ("%s", __func__);],
88have_func=yes, have_func=no)
89if test "x$have_func" = "xyes"; then
90   AC_MSG_RESULT(yes)
91else
92   AC_MSG_RESULT(no)
93   AC_MSG_CHECKING(for __FUNCTION__)
94   AC_TRY_COMPILE([
95#include <stdio.h>
96],[printf ("%s", __FUNCTION__);],
97have_function=yes, have_function=no)
98   if test "x$have_function" = "xyes"; then
99      AC_MSG_RESULT(yes)
100      AC_DEFINE(__func__, __FUNCTION__)
101   else
102      AC_MSG_RESULT(no)
103      AC_DEFINE(__func__, __FILE__)
104   fi
105fi
106
107AC_PATH_TOOL([STRIP], [strip], [/bin/true])
108
109needs_cpp_precomp=no
110
111LUA_CFLAGS="-DLUA_USE_POSIX -DLUA_USE_DLOPEN"
112
113AH_TEMPLATE(SOLARIS, [Sun/Oracle Solaris])
114AH_TEMPLATE(STUPID_SOLARIS_CHECKSUM_BUG, [],
115            [A bug in Solaris causing incorrect IP checksums])
116case "$host" in
117  *alpha-dec-osf*)
118    AC_DEFINE(DEC, 1, [DEC Alpha])
119    ;;
120  *-netbsd* | *-knetbsd*-gnu)
121    AC_DEFINE(NETBSD, 1, [NetBSD])
122    LDFLAGS="-Wl,-E $LDFLAGS" # needed for nse-C-module support
123    ;;
124  *-openbsd*)
125    AC_DEFINE(OPENBSD, 1, [OpenBSD])
126    LDFLAGS="-Wl,-E $LDFLAGS" # needed for nse-C-module support
127    ;;
128  *-freebsd* | *-kfreebsd*-gnu | *-dragonfly*)
129    AC_DEFINE(FREEBSD, 1, [FreeBSD])
130    LDFLAGS="-Wl,-E $LDFLAGS" # needed for nse-C-module support
131    ;;
132  *-bsdi*)
133    AC_DEFINE(BSDI, 1, [BSD/OS])
134    ;;
135  *-sgi-irix5* | *-sgi-irix6*)
136    AC_DEFINE(IRIX, 1, [IRIX])
137    ;;
138  *-hpux*)
139    AC_DEFINE(HPUX, 1, [HP-UX])
140    # To link with libnet and NM (/usr/lib/libnm.sl) library
141    # on HP-UX 11.11 (other versions?) Mikhail Zakharov (zmey20000@yahoo.com)
142    AC_CHECK_LIB(nm, open_mib)
143    ;;
144  *-aix*)
145    # use some AIX specific libraries
146    AC_CHECK_LIB(odm, odm_initialize)
147    AC_CHECK_LIB(cfg, _system_configuration)
148    AC_CHECK_LIB(crypt, crypt_r)
149    ;;
150  *-solaris2.1[[1-9]]*)
151    AC_DEFINE(SOLARIS)
152    # Solaris 11 and later use BPF packet capture rather than DLPI.
153    AC_DEFINE(SOLARIS_BPF_PCAP_CAPTURE, 1, [Solaris 11 and later use BPF packet capture rather than DLPI.])
154    ;;
155  *-solaris2.0*)
156    AC_DEFINE(STUPID_SOLARIS_CHECKSUM_BUG)
157    AC_DEFINE(SOLARIS)
158    ;;
159  *-solaris2.[[1-9]][[0-9]]*)
160    AC_DEFINE(SOLARIS)
161    ;;
162  *-solaris2.1*)
163    AC_DEFINE(STUPID_SOLARIS_CHECKSUM_BUG)
164    AC_DEFINE(SOLARIS)
165    ;;
166  *-solaris2.2*)
167    AC_DEFINE(STUPID_SOLARIS_CHECKSUM_BUG)
168    AC_DEFINE(SOLARIS)
169    ;;
170  *-solaris2.3*)
171    AC_DEFINE(STUPID_SOLARIS_CHECKSUM_BUG)
172    AC_DEFINE(SOLARIS)
173    ;;
174  *-solaris2.4*)
175    AC_DEFINE(STUPID_SOLARIS_CHECKSUM_BUG)
176    AC_DEFINE(SOLARIS)
177    ;;
178  *-solaris2.5.1)
179    AC_DEFINE(STUPID_SOLARIS_CHECKSUM_BUG)
180    AC_DEFINE(SOLARIS)
181    ;;
182  *-solaris*)
183    AC_DEFINE(SOLARIS)
184    ;;
185  *-sunos4*)
186    AC_DEFINE(SUNOS, 1, [SunOS 4])
187    AC_DEFINE(SPRINTF_RETURNS_STRING, 1,
188              [sprintf(9f) returns its first argument, not the number of characters printed])
189    ;;
190  *-linux*)
191    AC_DEFINE(LINUX, 1, [Linux])
192    LDFLAGS="-Wl,-E $LDFLAGS" # needed for nse-C-module support
193    ;;
194  *-apple-darwin*)
195    AC_DEFINE(MACOSX, 1, [Apple OS X])
196    dnl on Mac OSX the math library seems to contain unwanted getopt cruft
197    AC_CHECK_LIB(m, main)
198    LUA_CFLAGS="-DLUA_USE_MACOSX"
199    needs_cpp_precomp=yes
200    ;;
201esac
202
203AC_SUBST(LUA_CFLAGS)
204
205dnl Checks for header files.
206AC_CHECK_HEADERS(pwd.h termios.h sys/sockio.h stdint.h sys/stat.h fcntl.h)
207AC_CHECK_HEADERS(linux/rtnetlink.h,,,[#include <netinet/in.h>])
208dnl A special check required for <net/if.h> on Darwin. See
209dnl http://www.gnu.org/software/autoconf/manual/html_node/Header-Portability.html.
210AC_CHECK_HEADERS([sys/socket.h])
211AC_CHECK_HEADERS([net/if.h], [], [],
212[#include <stdio.h>
213#ifdef STDC_HEADERS
214# include <stdlib.h>
215# include <stddef.h>
216#else
217# ifdef HAVE_STDLIB_H
218#  include <stdlib.h>
219# endif
220#endif
221#ifdef HAVE_SYS_SOCKET_H
222# include <sys/socket.h>
223#endif
224])
225
226dnl If any socket libraries needed
227AC_SEARCH_LIBS(setsockopt, socket)
228AC_SEARCH_LIBS(gethostbyname, nsl)
229
230dnl Check IPv6 raw sending flavor.
231CHECK_IPV6_IPPROTO_RAW
232
233m4_define_default([_AM_PYTHON_INTERPRETER_LIST],[python2 python2.7 python2.6 python2.5 python2.4 python])
234AM_PATH_PYTHON([2.4], [HAVE_PYTHON=true], [HAVE_PYTHON=false])
235HAVE_PYTHON2=false
236if test $HAVE_PYTHON && test "x${PYTHON_VERSION%%.*}" = "x2"; then
237    HAVE_PYTHON2=true
238fi
239
240NDIFFDIR=ndiff
241
242# Do they want Ndiff?
243AC_ARG_WITH(ndiff, AC_HELP_STRING([--without-ndiff], [Skip installation of the Ndiff utility]), [], [with_ndiff=check])
244if $HAVE_PYTHON2 ; then : ;
245else
246  if test "$with_ndiff" = "check" ; then
247    AC_MSG_WARN([Not building Ndiff because Python 2.x with x>=4 was not found])
248  elif test "$with_ndiff" = "yes"; then
249    AC_MSG_FAILURE([--with-ndiff requires Python 2.x with x>=4])
250  fi
251  with_ndiff=no
252fi
253if test "$with_ndiff" = "no"; then
254  trace_no_use="$trace_no_use ndiff"
255  BUILDNDIFF=""
256  INSTALLNDIFF=""
257  UNINSTALLNDIFF=""
258  NDIFF_CHECK=""
259  NDIFF_CLEAN=""
260  NDIFF_DIST_CLEAN=""
261else
262  trace_use="$trace_use ndiff"
263  BUILDNDIFF=build-ndiff
264  INSTALLNDIFF=install-ndiff
265  UNINSTALLNDIFF=uninstall-ndiff
266  NDIFF_CHECK="check-ndiff"
267  NDIFF_CLEAN=clean-ndiff
268  NDIFF_DIST_CLEAN=distclean-ndiff
269fi
270AC_SUBST(NDIFFDIR)
271AC_SUBST(BUILDNDIFF)
272AC_SUBST(INSTALLNDIFF)
273AC_SUBST(UNINSTALLNDIFF)
274AC_SUBST(NDIFF_CHECK)
275AC_SUBST(NDIFF_CLEAN)
276AC_SUBST(NDIFF_DIST_CLEAN)
277
278ZENMAPDIR=zenmap
279
280# Do they want Zenmap?
281AC_ARG_WITH(zenmap, AC_HELP_STRING([--without-zenmap], [Skip installation of the Zenmap graphical frontend]), [], [with_zenmap=check])
282
283if $HAVE_PYTHON2 ; then : ;
284else
285  if test "$with_zenmap" = "check"; then
286    AC_MSG_WARN([Not building Zenmap because Python 2.x with x>=4 was not found])
287  elif test "$with_zenmap" = "yes"; then
288    AC_MSG_FAILURE([--with-zenmap requires Python 2.x with x>=4])
289  fi
290  with_zenmap=no
291fi
292if test "$with_zenmap" = "no"; then
293  trace_no_use="$trace_no_use zenmap"
294  BUILDZENMAP=""
295  INSTALLZENMAP=""
296  UNINSTALLZENMAP=""
297  ZENMAP_CHECK=""
298  ZENMAP_CLEAN=""
299  ZENMAP_DIST_CLEAN=""
300else
301  trace_use="$trace_use zenmap"
302  BUILDZENMAP=build-zenmap
303  INSTALLZENMAP=install-zenmap
304  UNINSTALLZENMAP=uninstall-zenmap
305  ZENMAP_CHECK=check-zenmap
306  ZENMAP_CLEAN=clean-zenmap
307  ZENMAP_DIST_CLEAN=distclean-zenmap
308fi
309AC_SUBST(ZENMAPDIR)
310AC_SUBST(BUILDZENMAP)
311AC_SUBST(INSTALLZENMAP)
312AC_SUBST(UNINSTALLZENMAP)
313AC_SUBST(ZENMAP_CHECK)
314AC_SUBST(ZENMAP_CLEAN)
315AC_SUBST(ZENMAP_DIST_CLEAN)
316
317NPINGDIR=nping
318
319# Do they want Nping?
320AC_ARG_WITH(nping, AC_HELP_STRING([--without-nping], [Skip installation of the Nping utility]), [], [with_nping=check])
321
322if test "$with_nping" = "no"; then
323  trace_no_use="$trace_no_use nping"
324  BUILDNPING=""
325  INSTALLNPING=""
326  UNINSTALLNPING=""
327  NPING_CLEAN=""
328  NPING_DIST_CLEAN=""
329else
330  trace_use="$trace_use nping"
331  BUILDNPING=build-nping
332  INSTALLNPING=install-nping
333  UNINSTALLNPING=uninstall-nping
334  NPING_CLEAN=clean-nping
335  NPING_DIST_CLEAN=distclean-nping
336  AC_CONFIG_SUBDIRS(nping)
337fi
338AC_SUBST(NPINGDIR)
339AC_SUBST(BUILDNPING)
340AC_SUBST(INSTALLNPING)
341AC_SUBST(UNINSTALLNPING)
342AC_SUBST(NPING_CLEAN)
343AC_SUBST(NPING_DIST_CLEAN)
344
345# We test whether they specified openssl desires explicitly
346use_openssl="yes"
347specialssldir=""
348AC_ARG_WITH(openssl,
349AC_HELP_STRING([--with-openssl=DIR],[Use optional openssl libs and includes from [DIR]/lib/ and [DIR]/include/openssl/)]),
350[  case "$with_openssl" in
351  yes)
352    ;;
353  no)
354    use_openssl="no"
355    ;;
356  *)
357    specialssldir="$with_openssl"
358    ac_configure_args="$ac_configure_args '--with-libssl-prefix=$with_openssl'"
359    CPPFLAGS="$CPPFLAGS -I$with_openssl/include"
360    LDFLAGS="$LDFLAGS -L$with_openssl/lib"
361    ;;
362  esac]
363)
364
365# If they didn't specify it, we try to find it
366if test "$use_openssl" = "yes" -a -z "$specialssldir"; then
367  AC_CHECK_HEADER(openssl/ssl.h,,
368  [ use_openssl="no"
369    if test "$with_openssl" = "yes"; then
370      AC_MSG_ERROR([OpenSSL was explicitly requested but openssl/ssl.h was not found. Try the --with-openssl=DIR argument to give the location of OpenSSL or run configure with --without-openssl.])
371    fi
372    AC_MSG_WARN([Failed to find openssl/ssl.h so OpenSSL will not be used. If it is installed you can try the --with-openssl=DIR argument])
373  ])
374
375# use_openssl="yes" given explicitly in next 2 rules to avoid adding lib to $LIBS
376 if test "$use_openssl" = "yes"; then
377   AC_CHECK_LIB(crypto, BIO_int_ctrl,
378    [ use_openssl="yes"],
379    [ use_openssl="no"
380    if test "$with_openssl" = "yes"; then
381      AC_MSG_ERROR([OpenSSL was explicitly requested but libcrypto was not found. Try the --with-openssl=DIR argument to give the location of OpenSSL or run configure with --without-openssl.])
382    fi
383    AC_MSG_WARN([Failed to find libcrypto so OpenSSL will not be used. If it is installed you can try the --with-openssl=DIR argument])
384   ])
385 fi
386
387 if test "$use_openssl" = "yes"; then
388   AC_CHECK_LIB(ssl, SSL_new,
389    [ use_openssl="yes" ],
390    [ use_openssl="no"
391    if test "$with_openssl" = "yes"; then
392      AC_MSG_ERROR([OpenSSL was explicitly requested but libssl was not found. Try the --with-openssl=DIR argument to give the location of OpenSSL or run configure with --without-openssl.])
393    fi
394    AC_MSG_WARN([Failed to find libssl so OpenSSL will not be used. If it is installed you can try the --with-openssl=DIR argument]) ],
395    [ -lcrypto ])
396 fi
397
398 if test "$use_openssl" = "yes"; then
399   AC_CHECK_LIB(crypto, EVP_PKEY_get1_EC_KEY,
400    [AC_DEFINE(HAVE_OPENSSL_EC, 1, [Have EVP_PKEY_get1_EC_KEY])],
401    [AC_MSG_WARN([Disabling support for EC crypto])])
402  fi
403fi
404
405OPENSSL_LIBS=
406if test "$use_openssl" = "yes"; then
407  trace_use="$trace_use openssl"
408  AC_DEFINE(HAVE_OPENSSL, 1, [Have OpenSSL library])
409  OPENSSL_LIBS="-lssl -lcrypto"
410else
411  trace_no_use="$trace_no_use openssl"
412fi
413
414AC_SUBST(OPENSSL_LIBS)
415
416dnl Check whether libpcap is already available
417have_libpcap=no
418
419# By default, search for pcap library
420test "${with_libpcap+set}" != "set" && with_libpcap=yes
421
422AC_ARG_WITH(libpcap,
423AC_HELP_STRING([--with-libpcap=DIR], [Look for pcap in DIR/include and DIR/libs.])
424AC_HELP_STRING([--with-libpcap=included], [Always use version included with Nmap]),
425[  case "$with_libpcap" in
426  yes)
427    AC_CHECK_HEADER(pcap.h,[
428      AC_CHECK_LIB(pcap, pcap_create,
429      [have_libpcap=yes ])])
430    ;;
431  included)
432    have_libpcap=no
433   ;;
434  *)
435    _cppflags=$CPPFLAGS
436    _ldflags=$LDFLAGS
437
438    CPPFLAGS="-I$with_libpcap/include $CPPFLAGS"
439    LDFLAGS="-L$with_libpcap/lib $LDFLAGS"
440
441    AC_CHECK_HEADER(pcap.h,[
442      AC_CHECK_LIB(pcap, pcap_create,
443        [have_libpcap=yes
444        LIBPCAP_INC=$with_libpcap/include
445        LIBPCAP_LIB=$with_libpcap/lib])])
446
447    LDFLAGS=$_ldflags
448    CPPFLAGS=$_cppflags
449    ;;
450  esac]
451)
452
453if test $needs_cpp_precomp = yes; then
454  CXXFLAGS="-no-cpp-precomp $CXXFLAGS"
455fi
456
457if test $have_libpcap = yes; then
458  if test "${LIBPCAP_INC+set}" = "set"; then
459    CPPFLAGS="-I$LIBPCAP_INC $CPPFLAGS"
460    LDFLAGS="-L$LIBPCAP_LIB $LDFLAGS"
461  fi
462
463  # link with -lpcap for the purposes of this test
464  LIBS_OLD="$LIBS"
465  LIBS="$LIBS -lpcap"
466  PCAP_IS_SUITABLE([have_libpcap=yes], [have_libpcap=no], [have_libpcap=yes])
467  LIBS="$LIBS_OLD"
468fi
469
470if test $have_libpcap != yes; then
471  AC_CONFIG_SUBDIRS(libpcap)
472  if test "${LIBPCAP_INC+set}" = "set"; then
473    CPPFLAGS="$CPPFLAGS -I$LIBPCAP_INC"
474  else
475    CPPFLAGS="$CPPFLAGS -I\$(top_srcdir)/$libpcapdir"
476  fi
477  LIBPCAP_LIBS='$(LIBPCAPDIR)/libpcap.a'
478  PCAP_BUILD="build-pcap"
479  PCAP_CLEAN="clean-pcap"
480  PCAP_DIST_CLEAN="distclean-pcap"
481  AC_DEFINE(PCAP_INCLUDED, 1, [Using included libpcap])
482  AC_DEFINE(HAVE_PCAP_SET_IMMEDIATE_MODE, 1, [Included libpcap has pcap_set_immediate_mode])
483else
484  # We assume our included libpcap doesn't need this check-and-define
485  # link with -lpcap for the purposes of this test
486  LIBS_OLD="$LIBS"
487  LIBS="$LIBS -lpcap"
488  AC_CHECK_FUNCS([pcap_set_immediate_mode])
489  # Restore libs
490  LIBS="$LIBS_OLD"
491
492  AC_DEFINE(HAVE_LIBPCAP, 1, [Have libpcap library])
493  LIBPCAP_LIBS="-lpcap"
494  PCAP_BUILD=""
495  PCAP_CLEAN=""
496  PCAP_DIST_CLEAN=""
497fi
498
499AC_SUBST(PCAP_BUILD)
500AC_SUBST(PCAP_CLEAN)
501AC_SUBST(PCAP_DIST_CLEAN)
502AC_SUBST(LIBPCAP_LIBS)
503
504have_pcre=no
505requested_included_pcre=no
506LIBPCREDIR=libpcre
507
508# First we test whether they specified libpcre explicitly
509AC_ARG_WITH(libpcre,
510AC_HELP_STRING([--with-libpcre=DIR], [Use an existing (compiled) pcre lib from DIR/include and DIR/lib.])
511AC_HELP_STRING([--with-libpcre=included], [Always use the version included with Nmap]),
512[  case "$with_libpcre" in
513  yes)
514    ;;
515  included)
516    requested_included_pcre=yes
517    ;;
518  *)
519    CPPFLAGS="-I$with_libpcre/include $CPPFLAGS"
520    LDFLAGS="-L$with_libpcre/lib $LDFLAGS"
521    have_pcre=yes
522    ;;
523  esac]
524)
525
526# If they didn't specify it, we try to find it
527if test $have_pcre != yes -a $requested_included_pcre != yes ; then
528  AC_CHECK_HEADER(pcre.h,
529    AC_CHECK_LIB(pcre, pcre_version, [have_pcre=yes ]),
530    [AC_CHECK_HEADER(pcre/pcre.h,
531      [AC_CHECK_LIB(pcre, pcre_version, [have_pcre=yes])]
532    )]
533  )
534fi
535
536# If we still don't have it, we use our own
537if test $have_pcre != yes ; then
538  AC_CONFIG_SUBDIRS( libpcre )
539  CPPFLAGS="-I\$(top_srcdir)/$LIBPCREDIR $CPPFLAGS"
540  LIBPCRE_LIBS="$LIBPCREDIR/libpcre.a"
541  PCRE_BUILD="build-pcre"
542  PCRE_CLEAN="clean-pcre"
543  PCRE_DIST_CLEAN="distclean-pcre"
544  AC_DEFINE(PCRE_INCLUDED, 1, [Using included libpcre])
545else
546# We only need to check for and use this if we are NOT using included pcre
547  AC_CHECK_HEADERS(pcre/pcre.h)
548  LIBPCRE_LIBS="-lpcre"
549  PCRE_BUILD=""
550  PCRE_CLEAN=""
551  PCRE_DIST_CLEAN=""
552fi
553
554AC_SUBST(LIBPCRE_LIBS)
555AC_SUBST(LIBPCREDIR)
556AC_SUBST(PCRE_BUILD)
557AC_SUBST(PCRE_CLEAN)
558AC_SUBST(PCRE_DIST_CLEAN)
559
560
561# We test whether desired libz is specified explicitly
562# Since this is a libssh2 dependency, we have to do it first.
563
564have_libz="no"
565requested_included_libz="no"
566test "${with_libz+set}" != "set" && with_libz="yes"
567
568AC_ARG_WITH(libz,
569AC_HELP_STRING([--with-libz=DIR], [Use specific copy of libz])
570AC_HELP_STRING([--with-libz=included], [Always use version included with Nmap]),
571[
572  case "$with_libz" in
573  yes)
574    ;;
575  no)
576    # Do nothing
577    ;;
578  included)
579    requested_included_libz="yes"
580    ;;
581  *)
582    _cppflags=$CPPFLAGS
583    _ldflags=$LDFLAGS
584
585    CPPFLAGS="-I$with_libz/include $CPPFLAGS"
586    LDFLAGS="-L$with_libz/lib $LDFLAGS"
587
588    ac_configure_args="$ac_configure_args '--with-libz-prefix=$with_libz'"
589    AC_CHECK_HEADER(zlib.h,[
590      AC_CHECK_LIB(z, gzread,
591        [have_libz=yes
592        ZLIB_INC=$with_libz/include
593        ZLIB_LIB=$with_libz/lib],,)
594      ])
595
596    LDFLAGS=$_ldflags
597    CPPFLAGS=$_cppflags
598  ;;
599  esac
600]
601)
602
603if test $with_libz != no; then
604  trace_use="$trace_use zlib"
605
606  # If they didn't specify it, we try to find it
607  if test $have_libz != yes -a $requested_included_libz != yes; then
608    AC_CHECK_HEADER(zlib.h,[
609      AC_CHECK_LIB(z, gzread,
610        [have_libz="yes"],,[-lm])
611      ])
612  fi
613
614  if test $have_libz != yes; then
615    AC_CONFIG_SUBDIRS(libz)
616    # TODO: This doesn't work because libssh2's configure script is looking for
617    # already-built libs.  Giving up for now: build libz first or install
618    # headers/libs on your own if you want compression support for SSH.
619    #ac_configure_args="$ac_configure_args '--with-libz-prefix=../../$ZLIBDIR'"
620    CPPFLAGS="-I\$(top_srcdir)/$ZLIBDIR $CPPFLAGS"
621    ZLIB_LIBS="$ZLIBDIR/libz.a"
622    ZLIB_BUILD="build-zlib"
623    ZLIB_CLEAN="clean-zlib"
624    ZLIB_DIST_CLEAN="distclean-zlib"
625    AC_DEFINE(ZLIB_INCLUDED, 1, [Using included zlib])
626  else
627    ZLIB_LIBS="-lz"
628    ZLIB_BUILD=""
629    ZLIB_CLEAN=""
630    ZLIB_DIST_CLEAN=""
631  fi
632  AC_DEFINE(HAVE_LIBZ, 1, [Have zlib library])
633else
634  trace_no_use="$trace_no_use zlib"
635  ZLIB_LIBS=""
636  ZLIB_BUILD=""
637  ZLIB_CLEAN=""
638  ZLIB_DIST_CLEAN=""
639fi
640
641AC_SUBST(ZLIB_BUILD)
642AC_SUBST(ZLIB_CLEAN)
643AC_SUBST(ZLIB_DIST_CLEAN)
644AC_SUBST(ZLIB_LIBS)
645
646# We test whether desired libssh2 is specified explicitly
647
648use_libssh2="yes"
649have_libssh2="no"
650requested_included_libssh2="no"
651test "${with_libssh2+set}" != "set" && with_libssh2="yes"
652
653AC_ARG_WITH(libssh2,
654AC_HELP_STRING([--with-libssh2=DIR], [Use specific copy of libssh2])
655AC_HELP_STRING([--with-libssh2=included], [Always use version included with Nmap])
656AC_HELP_STRING([--without-libssh2], [Compile without libssh2]),
657[ case "$with_libssh2" in
658  yes)
659    ;;
660  no)
661    use_libssh2="no"
662    ;;
663  included)
664    requested_included_libssh2="yes"
665    ;;
666  *)
667    _cppflags=$CPPFLAGS
668    _ldflags=$LDFLAGS
669
670    CPPFLAGS="-I$with_libssh2/include $CPPFLAGS"
671    LDFLAGS="-L$with_libssh2/lib $LDFLAGS"
672
673    AC_CHECK_HEADER(libssh2.h,[
674      AC_CHECK_LIB(ssh2, libssh2_version,
675        [have_libssh2=yes
676        LIBSSH2_INC=$with_libssh2/include
677        LIBSSH2_LIB=$with_libssh2/lib],
678        [LDFLAGS=$_ldflags
679        CPPFLAGS=$_cppflags],[-lm])
680      ])
681
682  ;;
683  esac]
684)
685
686
687if test $use_libssh2 = yes -a $use_openssl = yes; then
688  trace_use="$trace_use libssh2"
689
690  # If they didn't specify it, we try to find it
691  if test $have_libssh2 != yes -a $requested_included_libssh2 != yes; then
692    AC_CHECK_HEADER(libssh2.h,[
693      AC_CHECK_LIB(ssh2, libssh2_version,
694        [have_libssh2="yes"],,[-lm])
695      ])
696  fi
697
698  # If we still don't have it, we use our own
699  if test $have_libssh2 != yes; then
700    have_libssh2=yes
701    AC_CONFIG_SUBDIRS(libssh2)
702    CPPFLAGS="-I\$(top_srcdir)/$LIBSSH2DIR/include $CPPFLAGS"
703    LIBSSH2_LIBS="$LIBSSH2DIR/lib/libssh2.a"
704    LIBSSH2_BUILD="build-libssh2"
705    LIBSSH2_CLEAN="clean-libssh2"
706    LIBSSH2_DIST_CLEAN="distclean-libssh2"
707    AC_DEFINE(LIBSSH2_INCLUDED, 1, [Using included libssh2])
708  else
709    LIBSSH2_LIBS="-lssh2"
710    LIBSSH2_BUILD=""
711    LIBSSH2_CLEAN=""
712    LIBSSH2_DIST_CLEAN=""
713  fi
714  AC_DEFINE(HAVE_LIBSSH2, 1, [Have libssh2 library])
715else
716  use_libssh2="no"
717  trace_no_use="$trace_no_use libssh2"
718  LIBSSH2_LIBS=""
719  LIBSSH2_BUILD=""
720  LIBSSH2_CLEAN=""
721  LIBSSH2_DIST_CLEAN=""
722fi
723
724AC_SUBST(LIBSSH2_BUILD)
725AC_SUBST(LIBSSH2_CLEAN)
726AC_SUBST(LIBSSH2_DIST_CLEAN)
727AC_SUBST(LIBSSH2_LIBS)
728
729
730have_dnet=no
731requested_included_dnet=no
732LIBDNETDIR=libdnet-stripped
733
734# First we test whether they specified libdnet explicitly.
735# Unlike the other included libraries (pcap, pcre, lua), we prefer our local
736# copy of libdnet. That is, with the other libraries we check for a system
737# version by default, whereas with dnet we use the local version unless
738# specifically asked to use a system version.  This is because we have
739# made many improvements and fixes to our version of dnet.
740AC_ARG_WITH(libdnet,
741AC_HELP_STRING([--with-libdnet=DIR], [Use an existing (compiled) dnet lib from DIR/include and DIR/lib. This is NOT RECOMMENDED because we have made many important fixes to our included libdnet, as described at ./libdnet-stripped/NMAP_MODIFICATIONS])
742AC_HELP_STRING([--with-libdnet=included], [Use the libdnet version included with Nmap (default)]),
743[  case "$with_libdnet" in
744  yes)
745    ;;
746  included)
747    ;;
748  *)
749    CPPFLAGS="-I$with_libdnet/include $CPPFLAGS"
750    LDFLAGS="-L$with_libdnet/lib $LDFLAGS"
751    have_dnet=yes
752    ;;
753  esac]
754)
755
756# If they didn't provide location, we use the included one
757if test $have_dnet != yes ; then
758  AC_CONFIG_SUBDIRS( libdnet-stripped )
759  CPPFLAGS="-I\$(top_srcdir)/$LIBDNETDIR/include $CPPFLAGS"
760  LIBDNET_LIBS="\$(top_srcdir)/$LIBDNETDIR/src/.libs/libdnet.a"
761  DNET_BUILD="build-dnet"
762  DNET_CLEAN="clean-dnet"
763  DNET_DIST_CLEAN="distclean-dnet"
764  AC_DEFINE(DNET_INCLUDED, 1, [Use included libdnet])
765else
766  LIBDNET_LIBS="-ldnet"
767  DNET_BUILD=""
768  DNET_CLEAN=""
769  DNET_DIST_CLEAN=""
770fi
771
772AC_SUBST(LIBDNET_LIBS)
773AC_SUBST(LIBDNETDIR)
774AC_SUBST(DNET_BUILD)
775AC_SUBST(DNET_CLEAN)
776AC_SUBST(DNET_DIST_CLEAN)
777
778LIBLUADIR=liblua
779
780have_lua=no
781requested_included_lua=no
782no_lua=no
783
784# First we test whether they specified liblua explicitly
785AC_ARG_WITH(liblua,
786AC_HELP_STRING([--with-liblua=DIR], [Use an existing (compiled) lua lib from DIR/include and DIR/lib.])
787AC_HELP_STRING([--with-liblua=included], [Use the liblua version included with Nmap])
788AC_HELP_STRING([--without-liblua], [Compile without lua (this will exclude all of NSE from compilation)]),
789[  case "$with_liblua" in
790  yes)
791  ;;
792  included)
793    CPPFLAGS="-I\$(top_srcdir)/$LIBLUADIR $CPPFLAGS"
794    LIBLUA_LIBS="\$(top_srcdir)/$LIBLUADIR/liblua.a"
795    LUA_BUILD="build-lua"
796    LUA_CLEAN="clean-lua"
797    LUA_DIST_CLEAN="distclean-lua"
798      have_lua="yes"
799    AC_DEFINE(LUA_INCLUDED, 1, [Using included liblua])
800  ;;
801  no)
802    no_lua="yes"
803  ;;
804  *)
805    CPPFLAGS="-I$with_liblua/include $CPPFLAGS"
806    LDFLAGS="-L$with_liblua/lib $LDFLAGS"
807  ;;
808  esac]
809)
810
811# OpenSSL and NSE C modules can require dlopen
812AC_SEARCH_LIBS(dlopen, dl)
813
814# They don't want lua
815if test "$no_lua" = "yes"; then
816  trace_no_use="$trace_no_use lua"
817  CPPFLAGS="-DNOLUA $CPPFLAGS"
818  NOLUA="yes"
819  LUA_BUILD=""
820  LUA_CLEAN=""
821  LUA_DIST_CLEAN=""
822  INSTALLNSE=""
823
824else
825  trace_use="$trace_use lua"
826
827  # If they didn't specify it, we try to find it
828  if test $have_lua != yes; then
829    AC_CHECK_HEADERS([lua5.3/lua.h lua/5.3/lua.h lua.h lua/lua.h], [break])
830    AC_SEARCH_LIBS(lua_isyieldable, [lua5.3 lua53 lua], [have_lua=yes],, [-lm])
831    AC_LANG_PUSH(C)
832    # We need Lua 5.3 exactly
833    AC_MSG_CHECKING([for lua version == 503])
834    AC_PREPROC_IFELSE([ AC_LANG_PROGRAM( [[
835      #ifdef HAVE_LUA5_3_LUA_H
836          #include <lua5.3/lua.h>
837      #elif defined HAVE_LUA_5_3_LUA_H
838          #include <lua/5.3/lua.h>
839      #elif defined HAVE_LUA_H || defined LUA_INCLUDED
840          #include <lua.h>
841      #elif defined HAVE_LUA_LUA_H
842          #include <lua/lua.h>
843      #endif
844
845      #if (LUA_VERSION_NUM != 503)
846          #error Incorrect Lua version
847      #endif
848        ]],
849        [[if(LUA_VERSION_NUM != 503) return 1;]])
850    ],
851    [have_lua=yes], [have_lua=no])
852    AC_LANG_POP(C)
853
854    LUA_BUILD=""
855    LUA_CLEAN=""
856    LUA_DIST_CLEAN=""
857  fi
858
859  # if we didn't find we use our own
860  if test $have_lua != yes; then
861    AC_MSG_RESULT(no)
862    CPPFLAGS="-I\$(top_srcdir)/$LIBLUADIR $CPPFLAGS"
863    LIBLUA_LIBS="\$(top_srcdir)/$LIBLUADIR/liblua.a"
864    LUA_BUILD="build-lua"
865    LUA_CLEAN="clean-lua"
866    LUA_DIST_CLEAN="distclean-lua"
867    AC_DEFINE(LUA_INCLUDED, 1, [Using included liblua])
868  else
869    AC_MSG_RESULT(yes)
870  fi
871
872  INSTALLNSE="install-nse"
873  NSE_CHECK="check-nse"
874fi
875
876AC_SUBST(NOLUA)
877AC_SUBST(LIBLUA_LIBS)
878AC_SUBST(LIBLUADIR)
879AC_SUBST(LUA_BUILD)
880AC_SUBST(LUA_CLEAN)
881AC_SUBST(LUA_DIST_CLEAN)
882AC_SUBST(INSTALLNSE)
883AC_SUBST(NSE_CHECK)
884AC_SUBST(CXXFLAGS)
885AC_SUBST(CFLAGS)
886
887
888LIBLINEARDIR=liblinear
889have_liblinear=no
890
891# First we test whether they specified liblinear explicitly
892AC_ARG_WITH(liblinear,
893AC_HELP_STRING([--with-liblinear=DIR], [Use an existing (compiled) liblinear from DIR/include and DIR/lib.])
894AC_HELP_STRING([--with-liblinear=included], [Use the liblinear version included with Nmap]),
895[  case "$with_liblinear" in
896  yes)
897  ;;
898  included)
899    CPPFLAGS="-I\$(top_srcdir)/$LIBLINEARDIR $CPPFLAGS"
900    LIBLINEAR_LIBS="\$(top_srcdir)/$LIBLINEARDIR/liblinear.a"
901    LIBLINEAR_BUILD="build-liblinear"
902    LIBLINEAR_CLEAN="clean-liblinear"
903    LIBLINEAR_DIST_CLEAN="distclean-liblinear"
904    have_liblinear=yes
905  ;;
906  *)
907    CPPFLAGS="-I$with_liblinear/include $CPPFLAGS"
908    LDFLAGS="-L$with_liblinear/lib $LDFLAGS"
909    have_liblinear=yes
910  ;;
911  esac]
912)
913
914# If they didn't specify it, we try to find it
915if test $have_liblinear != yes; then
916  AC_CHECK_HEADERS([linear.h],
917    AC_CHECK_LIB(linear, predict, [have_liblinear=yes; LIBLINEAR_LIBS="-llinear"; break],, [-lm])
918  )
919
920  LIBLINEAR_BUILD=""
921  LIBLINEAR_CLEAN=""
922  LIBLINEAR_DIST_CLEAN=""
923fi
924
925# if we didn't find we use our own
926if test $have_liblinear != yes; then
927  AC_MSG_RESULT(no)
928  CPPFLAGS="-I\$(top_srcdir)/$LIBLINEARDIR $CPPFLAGS"
929  LIBLINEAR_LIBS="\$(top_srcdir)/$LIBLINEARDIR/liblinear.a"
930  LIBLINEAR_BUILD="build-liblinear"
931  LIBLINEAR_CLEAN="clean-liblinear"
932  LIBLINEAR_DIST_CLEAN="distclean-liblinear"
933  AC_DEFINE(LIBLINEAR_INCLUDED, 1, [Using included liblinear])
934else
935  AC_MSG_RESULT(yes)
936fi
937
938AC_SUBST(LIBLINEAR_LIBS)
939AC_SUBST(LIBLINEARDIR)
940AC_SUBST(LIBLINEAR_BUILD)
941AC_SUBST(LIBLINEAR_CLEAN)
942AC_SUBST(LIBLINEAR_DIST_CLEAN)
943
944
945#dnl check endedness
946AC_C_BIGENDIAN
947
948AC_MSG_CHECKING([if struct in_addr is a wacky huge structure (some Sun boxes)])
949AH_TEMPLATE(IN_ADDR_DEEPSTRUCT, [], [struct in_addr is a wacky huge structure (some Sun boxes)])
950
951AC_TRY_COMPILE([#include <netinet/in.h>], struct in_addr i; i._S_un._S_addr;, \
952             AC_DEFINE(IN_ADDR_DEEPSTRUCT) \
953             AC_MSG_RESULT(yes) , \
954             AC_TRY_COMPILE([#include <sys/types.h>
955#include <netinet/in.h>], struct in_addr i; i.S_un.S_addr;, \
956                             AC_DEFINE(IN_ADDR_DEEPSTRUCT) \
957                             AC_MSG_RESULT(yes) , \
958                             AC_MSG_RESULT(no);))
959
960AC_CACHE_CHECK(if struct icmp exists, ac_cv_struct_icmp_exists,
961        AC_TRY_COMPILE([
962               #include <sys/types.h>
963               #include <sys/param.h>
964               #include <netinet/in_systm.h>
965               #include <netinet/in.h>
966               #define __USE_BSD
967               #define __FAVOR_BSD
968               #define _BSD_SOURCE
969               #include <netinet/ip.h>
970               #include <netinet/ip_icmp.h>],
971                [unsigned int i = sizeof(struct icmp)],
972        ac_cv_struct_icmp_exists=yes,
973        ac_cv_struct_icmp_exists=no))
974if test $ac_cv_struct_icmp_exists = yes ; then
975        AC_DEFINE(HAVE_STRUCT_ICMP, 1, [struct icmp is declared])
976fi
977
978AC_CACHE_CHECK(if struct ip exists, ac_cv_struct_ip_exists,
979        AC_TRY_COMPILE([
980               #include <sys/types.h>
981               #include <sys/param.h>
982               #include <netinet/in_systm.h>
983               #include <netinet/in.h>
984               #define __USE_BSD
985               #define __FAVOR_BSD
986               #define _BSD_SOURCE
987               #include <netinet/ip.h>],
988                [unsigned int i = sizeof(struct ip)],
989        ac_cv_struct_ip_exists=yes,
990        ac_cv_struct_ip_exists=no))
991if test $ac_cv_struct_ip_exists = yes ; then
992        AC_DEFINE(HAVE_STRUCT_IP, 1, [struct ip is declared])
993fi
994
995AC_CACHE_CHECK(if struct ip has ip_sum member, ac_cv_ip_has_ip_sum,
996        AC_TRY_COMPILE([
997               #include <sys/types.h>
998               #include <sys/param.h>
999               #include <netinet/in_systm.h>
1000               #include <netinet/in.h>
1001               #define __USE_BSD
1002               #define __FAVOR_BSD
1003               #define _BSD_SOURCE
1004               #include <netinet/ip.h>
1005               #include <netinet/ip_icmp.h>],
1006                [unsigned int i = sizeof(((struct ip *)0)->ip_sum)],
1007        ac_cv_ip_has_ip_sum=yes,
1008        ac_cv_ip_has_ip_sum=no))
1009if test $ac_cv_ip_has_ip_sum = yes ; then
1010        AC_DEFINE(HAVE_IP_IP_SUM, 1, [struct ip has ip_sum member])
1011fi
1012
1013dnl Checks for library functions.
1014AC_CHECK_FUNCS(strerror)
1015RECVFROM_ARG6_TYPE
1016
1017AC_ARG_WITH(libnbase,
1018AC_HELP_STRING([--with-libnbase=DIR], [Look for nbase include/libs in DIR]),
1019[  case "$with_libnbase" in
1020  yes)
1021    ;;
1022  *)
1023    NBASEDIR="$with_libnbase"
1024    NBASE_BUILD=""
1025    ;;
1026  esac],
1027NBASE_BUILD="build-nbase"
1028NBASEDIR="nbase"
1029)
1030
1031LDFLAGS="$LDFLAGS -L$NBASEDIR"
1032CPPFLAGS="$CPPFLAGS -I\$(top_srcdir)/$NBASEDIR"
1033LIBNBASE_LIBS="-lnbase"
1034
1035AC_SUBST(NBASEDIR)
1036AC_SUBST(NBASE_BUILD)
1037AC_SUBST(LIBNBASE_LIBS)
1038
1039AC_CONFIG_SUBDIRS(nbase)
1040
1041NSOCKDIR="nsock"
1042NSOCK_BUILD="build-nsock"
1043NSOCK_CHECK="check-nsock"
1044AC_ARG_WITH(libnsock,
1045AC_HELP_STRING([--with-libnsock=DIR], [Compile and link to libnsock in DIR]),
1046[  case "$with_libnsock" in
1047  yes)
1048    ;;
1049  *)
1050    NSOCKDIR="$with_libnsock"
1051    NSOCK_BUILD=""
1052    NSOCK_CHECK=""
1053    ;;
1054  esac]
1055)
1056
1057LDFLAGS="$LDFLAGS -L$NSOCKDIR/src/"
1058CPPFLAGS="$CPPFLAGS -I\$(top_srcdir)/$NSOCKDIR/include"
1059LIBNSOCK_LIBS="-lnsock"
1060
1061AC_SUBST(NSOCKDIR)
1062AC_SUBST(NSOCK_BUILD)
1063AC_SUBST(NSOCK_CHECK)
1064AC_SUBST(LIBNSOCK_LIBS)
1065
1066AC_CONFIG_SUBDIRS(nsock/src)
1067
1068NCATDIR="ncat"
1069
1070AC_ARG_WITH(ncat,
1071  AC_HELP_STRING([--without-ncat], [Skip build and installation of Ncat]), [], [with_ncat=check])
1072
1073if test "$with_ncat" = "no"; then
1074  trace_no_use="$trace_no_use ncat"
1075  NCAT_BUILD=""
1076  NCAT_CHECK=""
1077  NCAT_INSTALL=""
1078  NCAT_UNINSTALL=""
1079  NCAT_CLEAN=""
1080  NCAT_DIST_CLEAN=""
1081else
1082  trace_use="$trace_use ncat"
1083  NCAT_BUILD="build-ncat"
1084  NCAT_CHECK="check-ncat"
1085  NCAT_INSTALL="install-ncat"
1086  NCAT_UNINSTALL="uninstall-ncat"
1087  NCAT_CLEAN="clean-ncat"
1088  NCAT_DIST_CLEAN="distclean-ncat"
1089  AC_CONFIG_SUBDIRS(ncat)
1090fi
1091
1092AC_SUBST(NCATDIR)
1093AC_SUBST(NCAT_BUILD)
1094AC_SUBST(NCAT_CHECK)
1095AC_SUBST(NCAT_INSTALL)
1096AC_SUBST(NCAT_UNINSTALL)
1097AC_SUBST(NCAT_CLEAN)
1098AC_SUBST(NCAT_DIST_CLEAN)
1099
1100AC_OUTPUT(Makefile libnetutil/Makefile)
1101
1102# Krad ASCII ART#!#@$!@#$
1103# Randomly store the name of one of the ASCII Art files in FILENAME
1104FILENAME=`ls $srcdir/docs/leet-nmap-ascii-art*.txt 2>/dev/null | $AWK '
1105    BEGIN {
1106        srand();
1107    }
1108
1109    {
1110        lines[[++d]] = $0
1111    }
1112
1113    END {
1114        # This makes AWKs random numbers more random
1115        print lines[[int(rand()*49139)%d+1]];
1116    }
1117    '`
1118# Print the file to screen, if any such file exists (i.e. $FILENAME is not empty)
1119if test "$FILENAME"; then
1120  cat "$FILENAME"
1121fi
1122echo "  NMAP IS A POWERFUL TOOL -- USE CAREFULLY AND RESPONSIBLY"
1123
1124echo "Configured with:$trace_use"
1125echo "Configured without:$trace_no_use"
1126echo "Type make (or gmake on some *BSD machines) to compile."
1127
1128if test "x$use_openssl" = "xno" && test "x$with_openssl" != "xno"; then
1129  echo "WARNING: You are compiling without OpenSSL"
1130fi
1131
1132if test "x$use_libssh2" != "xyes"; then
1133  echo "WARNING: You are compiling without LibSSH2"
1134fi
1135