summaryrefslogtreecommitdiff
path: root/configure.ac
blob: 4f544286c390e4e9fc02059c8154fe3ebcb2d52b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
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
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
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
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
#
# Libnet autoconfiguration information file
# Copyright (c) 1998 - 2002 Mike D. Schiffman <mike@infonexus.com>
# Modified by: Ali Abdulkadir <autostart.ini@gmail.com>,
#              Joachim Nilsson <troglobit@gmail.com>
# All rights reserved.
#
# Process this file with autoconf to produce a configure script.

AC_INIT([libnet], m4_esyscmd([sed -n '1p' VERSION | tr -d '\n']),
	[https://github.com/libnet/libnet/issues],[],
	[https://github.com/libnet/libnet])

# Visible in resulting configure script, e.g. with ./configure --version
AC_COPYRIGHT([Copyright (C) 1998 - 2022 The libnet Developer Community.])
AC_REVISION(${VERSION})

# the autotools and libtool should be at least these versions
AC_PREREQ([2.69])
LT_PREREQ([2.4.2])

AC_PROG_SHELL
AC_PROG_SED
AC_CHECK_PROGS([CHMOD],[chmod],[true])
AC_CANONICAL_TARGET
AC_CONFIG_SRCDIR([src/libnet_build_ip.c])
AC_CONFIG_MACRO_DIR([m4])
AM_INIT_AUTOMAKE([1.14 foreign subdir-objects no-dependencies dist-zip])
AM_SILENT_RULES([yes])
AC_CONFIG_HEADERS([include/config.h])

AC_CONFIG_FILES([Makefile \
		 Doxyfile \
		 libnet-config \
                 doc/Makefile \
                 doc/man/Makefile \
                 doc/man/man1/Makefile \
                 doc/man/man3/Makefile \
                 include/Makefile \
                 include/libnet.h \
		 libnet.pc \
                 src/Makefile \
                 sample/Makefile \
		 tests/Makefile \
		 win32/Makefile])
AC_CONFIG_FILES([doc/fixmanpages], [chmod a+x doc/fixmanpages])

# Check for the usual programs
AC_PROG_CC
AC_PROG_INSTALL
AC_USE_SYSTEM_EXTENSIONS
# The default is to use only PIC objects.
# This can still be overwritten with --without-pic
LT_INIT([pic-only])

#
# Check for headers
#
AC_CHECK_HEADERS([sys/sockio.h net/if.h sys/ioctl.h])
AC_CHECK_FUNCS([gethostbyname2])
AC_CHECK_FUNCS([getifaddrs])
AC_TYPE_UINT16_T
AC_TYPE_UINT32_T
AC_TYPE_UINT64_T

AC_MSG_CHECKING(for socklen_t)
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
        #include <sys/types.h>
        #include <sys/socket.h>
        ]], [[ socklen_t x; ]])],[have_socklen_t=yes],[have_socklen_t=no])
AS_IF([test "x$have_socklen_t" = "xyes"], [
        AC_DEFINE(HAVE_SOCKLEN_T, 1, [define if socklen_t is defined])])
AC_MSG_RESULT($have_socklen_t)

#
# And some custom things
#
AC_LIBNET_ENDIAN_CHECK
AC_SUBST(ENDIANESS)
AC_SUBST(ADDITIONAL_LIBS)
AC_SUBST(PKG_CONFIG_DEFINES)
AC_SUBST(PKG_CONFIG_LIBS)
AC_SUBST(PKG_CONFIG_CFLAGS)
AC_SUBST(LTLIBOBJS)

# Get link-layer interface type
AC_ARG_WITH(
	[link-layer],
	[AS_HELP_STRING([--with-link-layer],
	[when cross-compiling, one of * from libnet_link_*.c @<:@autodetect@:>@])])

AC_CHECK_HEADERS([net/pfilt.h sys/net/nit.h net/raw.h sys/dlpi.h linux/socket.h])

AC_MSG_CHECKING(link-layer packet interface type)

AS_IF([test -n "${with_link_layer}"], [
    AS_CASE([${with_link_layer}],
        [bpf],   [AC_LIBOBJ([libnet_link_bpf])],
        [pf],    [AC_LIBOBJ([libnet_link_pf])],
        [snit],  [AC_LIBOBJ([libnet_link_snit])],
        [nit],   [AC_LIBOBJ([libnet_link_nit])],
        [snoop], [AC_LIBOBJ([libnet_link_snoop])],
        [dlpi],  [AC_LIBOBJ([libnet_link_dlpi])],
        [win32], [AC_LIBOBJ([libnet_link_win32])],
        [none],  [AC_LIBOBJ([libnet_link_none])],
        [linux], [AC_LIBOBJ([libnet_link_linux])
                  AC_LIBNET_LINUX_PROCFS],
        [AC_MSG_ERROR([Invalid link type "${with_link_layer}"])])
     AC_MSG_RESULT(user selected link layer ${with_link_layer})],
[test "${cross_compiling}" != "yes" -a -r /dev/bpf0], [
    AC_LIBOBJ([libnet_link_bpf])
    AC_MSG_RESULT(found link layer bpf)],
[test "${ac_cv_header_net_pfilt_h}" = "yes"], [
    AC_LIBOBJ([libnet_link_pf])
    AC_MSG_RESULT(found link layer pf)],
[test "${cross_compiling}" != "yes" -a -r /dev/nit], [
    AC_LIBOBJ([libnet_link_snit])
    AC_MSG_RESULT(found link layer snit)],
[test "${ac_cv_header_sys_net_nit_h}" = "yes"], [
    AC_LIBOBJ([libnet_link_nit])
    AC_MSG_RESULT(found link layer nit)],
[test "${ac_cv_header_net_raw_h}" = "yes"], [
    AC_LIBOBJ([libnet_link_snoop])
    AC_MSG_RESULT(found link layer snoop)],
[test "${ac_cv_header_sys_dlpi_h}" = "yes"], [
    AC_LIBOBJ([libnet_link_dlpi])
    AC_MSG_RESULT(found link layer dlpi)
    AC_DEFINE(HAVE_DLPI, 1, [Define if the <sys/dlpi.h> header exists.])],
[test "${ac_cv_header_linux_socket_h}" = "yes"], [
    AC_LIBOBJ([libnet_link_linux])
    AC_MSG_RESULT(found link layer linux)
    AC_LIBNET_LINUX_PROCFS],
[test "${cross_compiling}" != "yes" -a -c /dev/bpf0], [
    # check again in case not readable
    AC_LIBOBJ([libnet_link_bpf])
    AC_MSG_RESULT(found link layer bpf)],
[test "${cross_compiling}" != "yes" -a -c /dev/nit], [
    # check again in case not readable
    AC_LIBOBJ([libnet_link_snit])
    AC_MSG_RESULT(found link layer snit)],
[test "$target_os" = "cygwin"], [
    AC_LIBOBJ([libnet_link_win32])
    AC_MSG_RESULT(found link layer win32 wpcap)],
[test "$host" = "i686-w64-mingw32" -o "x86_64-w64-mingw32" -o "x86_64-pc-mingw64"], [
    AC_LIBOBJ([libnet_link_win32])
    AC_MSG_RESULT(found link layer win32 @<:@WinPcap@:>@)],[
    AC_LIBOBJ([libnet_link_none])
    AC_MSG_WARN(could not find a link-layer packet interface)
    AC_MSG_WARN(link-layer packet injection will not be available)])

# Check for Doxygen and enable its features.
# For details, see m4/ax_prog_doxygen.m4 and
# http://www.bioinf.uni-freiburg.de/~mmann/HowTo/automake.html#doxygenSupport
DX_DOXYGEN_FEATURE(ON)
DX_DOT_FEATURE(ON)
DX_CHI_FEATURE(OFF)
DX_RTF_FEATURE(OFF)
DX_XML_FEATURE(OFF)
DX_PDF_FEATURE(OFF)
DX_PS_FEATURE(OFF)
DX_CHM_FEATURE(OFF)
DX_HTML_FEATURE(ON)
DX_MAN_FEATURE(ON)
DX_INIT_DOXYGEN(${PACKAGE_NAME}, [${top_builddir}/Doxyfile], [doc])
AM_CONDITIONAL(ENABLE_DOXYGEN,[test "x${DX_FLAG_doc}" = x1])
AM_CONDITIONAL(ENABLE_HTML,[test "x${DX_FLAG_html}" = x1])
AM_CONDITIONAL(ENABLE_MAN,[test "x${DX_FLAG_man}" = x1])

# Check for sample building
AC_MSG_CHECKING([whether to build sample programs])
AC_ARG_ENABLE([samples],
    [AS_HELP_STRING([--enable-samples],[do not build sample programs @<:@default=no@:>@])],
    [enable_samples=$enableval],
    [enable_samples=no]
)
AC_MSG_RESULT([$enable_samples])
AM_CONDITIONAL([ENABLE_SAMPLES], [test "$enable_samples" = "yes"])

# Check for tests enabling
AC_MSG_CHECKING([enable tests])
AC_ARG_ENABLE([tests],
    [AS_HELP_STRING([--enable-tests],[do not enable tests @<:@default=no@:>@])],
    [enable_tests=$enableval],
    [enable_tests=no]
)
AC_MSG_RESULT([$enable_tests])
AM_CONDITIONAL([ENABLE_TESTS], [test "$enable_tests" = "yes"])
AS_IF([test "$enable_tests" = "yes"], [
    AC_DEFINE(LIBNET_ENABLE_TESTS, 1, [Useful define for testing purposes.])
])

# what (not) to do if the user disables shared libraries
AM_CONDITIONAL([COND_SHARED], [test "x$enable_shared" != xno])

# Enable some extra features.
CFLAGS="$CFLAGS -D_DEFAULT_SOURCE=1"

# Check and set OS specific parameters
AS_CASE([$target_os],
[*linux*], [
    AC_DEFINE(_BSD_SOURCE, 1,
        [Define as necessary to "unhide" header symbols.])
    AC_DEFINE(_DEFAULT_SOURCE, 1,
        [Define as necessary to "unhide" header symbols.])

    PKG_CONFIG_DEFINES="-D_BSD_SOURCE -D_DEFAULT_SOURCE"
    AC_CHECK_HEADERS(net/ethernet.h, \
        PKG_CONFIG_DEFINES="$PKG_CONFIG_DEFINES -DHAVE_NET_ETHERNET_H")
    ],

[*freebsd*], [
    PKG_CONFIG_DEFINES="-DHAVE_SOCKADDR_SA_LEN"
    AC_DEFINE(HAVE_SOCKADDR_SA_LEN, 1, [FreeBSD has sa_len in struct sockaddr.])

    AC_MSG_CHECKING([FreeBSD version, is SOCK_RAW really raw?])
    AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/param.h>]], [[
#if (__FreeBSD_version >= 1100030)
    return 0;
#else
#error FreeBSD pre-11, SOCK_RAW isn't really raw, see https://www.freebsd.org/cgi/man.cgi?ip(4)#end
#endif]])],[AC_MSG_RESULT(yes)],[AC_MSG_RESULT(no)
    AC_DEFINE(LIBNET_BSD_BYTE_SWAP, 1, FreeBSD pre-11, libnet must byteswap raw ip_len, ip_off)
    PKG_CONFIG_DEFINES="${PKG_CONFIG_DEFINES} -DLIBNET_BSD_BYTE_SWAP"])],

[*netbsd*], [
    AC_DEFINE(LIBNET_BSD_BYTE_SWAP, 1,
        [Define if libnet should byteswap data.])

    PKG_CONFIG_DEFINES="-DLIBNET_BSD_BYTE_SWAP"
    ],

[*openbsd*], [
    AC_DEFINE(HAVE_SOCKADDR_SA_LEN, 1,
        [Define if the sockaddr structure includes a sa_len member.])
    ],

[*bsdi*], [
    AC_DEFINE(LIBNET_BSD_BYTE_SWAP, 1,
        [Define if libnet should byteswap data.])
    PKG_CONFIG_DEFINES="-DLIBNET_BSD_BYTE_SWAP"
    ],

[*darwin*], [
    AC_DEFINE(HAVE_SOCKADDR_SA_LEN, 1,
        [Define if the sockaddr structure includes a sa_len member.])
    AC_DEFINE(LIBNET_BSD_BYTE_SWAP, 1, [Define if libnet should byteswap data.])
    PKG_CONFIG_DEFINES="-DHAVE_SOCKADDR_SA_LEN -DLIBNET_BSD_BYTE_SWAP"
    ],

[*solaris*], [
    AC_DEFINE(HAVE_SOLARIS, 1, [Define if we are running on Solaris.])
    AC_CHECK_HEADERS(sys/bufmod.h sys/dlpi_ext.h)
    AC_MSG_CHECKING(for /dev/dlpi device)
    AS_IF([test -c /dev/dlpi], [
        AC_MSG_RESULT(yes)
        AC_DEFINE(HAVE_DEV_DLPI, 1, [Define if /dev/dlpi is available.])
    ], [
        AC_MSG_RESULT(no)
        dir="/dev/dlpi"
        AC_MSG_CHECKING(for $dir directory)
        AS_IF([test -d $dir], [
            AC_MSG_RESULT(yes)
            AC_DEFINE_UNQUOTED(DLPI_DEV_PREFIX, "$dir",
                [Define if /dev/dlpi is a directory.])
        ], [
            AC_MSG_RESULT(no)
        ])
    ])
    AC_CHECK_LIB(socket, socket, ,AC_MSG_ERROR(libsocket not found.))
    AC_CHECK_LIB(nsl, gethostbyname, ,AC_MSG_ERROR(libnsl not found.))
    AC_CHECK_LIB(resolv, hstrerror, ,AC_MSG_ERROR(libresolv not found.))

    #
    # Broken checksums?
    #
    AS_CASE([`uname -r`],
    [5.4], [
        AC_DEFINE(STUPID_SOLARIS_CHECKSUM_BUG, 1,
            [Define if our version of Solaris has broken checksums.])
        ],
    [5.5*], [
        AC_DEFINE(STUPID_SOLARIS_CHECKSUM_BUG, 1,
            [Define if our version of Solaris has broken checksums.])
        ],
    [5.8], [
        AC_DEFINE(STUPID_SOLARIS_CHECKSUM_BUG, 1,
            [Define if our version of Solaris has broken checksums.])
        AC_DEFINE(HAVE_SOLARIS_IPV6, 1,
            [Define if our version of Solaris supports IPv6.])

        ],
    [5.9], [
        AC_DEFINE(STUPID_SOLARIS_CHECKSUM_BUG, 1,
            [Define if our version of Solaris has broken checksums.])
        AC_DEFINE(HAVE_SOLARIS_IPV6, 1,
            [Define if our version of Solaris supports IPv6.])
        ],
    [5.10 | 5.11 | 5.12], [
        AC_DEFINE(HAVE_SOLARIS_IPV6, 1,
            [Define if our version of Solaris supports IPv6.])
        ])

    ADDITIONAL_LIBS="-lresolv -lsocket -lnsl"
    PKG_CONFIG_LIBS="$PKG_CONFIG_LIBS -lresolv -lsocket -lnsl"
    ],

[*hpux11*], [
    AC_DEFINE(HAVE_HPUX11, 1, [Define if we are building on HP/UX.])
    AC_CHECK_HEADERS(sys/dlpi_ext.h)
    ],

[*cygwin* | *msys*], [
    WIN32="yes"
    AC_SUBST(WIN32)
    CFLAGS="$CFLAGS -mwin32"
    AC_CHECK_LIB(packet, PacketSetMode, ,AC_MSG_ERROR(packet lib not found.))
    AC_CHECK_LIB(wpcap, pcap_setmode, ,AC_MSG_ERROR(pcap lib not found.))
    LIBS="$LIBS -lws2_32"
    ],

[*mingw*], [
    WIN32="yes"
    AC_SUBST(WIN32)

    AS_IF([test "$enable_shared" = "yes"], [AC_CHECK_TOOL(WINDRES, windres, :)])

    AC_DEFINE(WIN32_LEAN_AND_MEAN, 1, [Define to limit the scope of <windows.h>])

    AC_CHECK_LIB(packet, PacketSetMode, ,AC_MSG_ERROR(libpacket.a not found. See README.win32 for more information))
    AC_CHECK_LIB(wpcap, pcap_setmode, ,AC_MSG_ERROR(libwpcap.a not found. See README.win32 for more information))
    LIBS="$LIBS -lws2_32 -liphlpapi"

    AS_IF([test "$host" = "i686-w64-mingw32"], [
        CFLAGS="$CFLAGS -march=i686 -mwin32"], [
	CFLAGS="$CFLAGS -mwin32"

	AX_CHECK_LINK_FLAG([-Wl,--high-entropy-va],
            [LDFLAGS="$LDFLAGS -Wl,--high-entropy-va"],
            [AC_MSG_NOTICE([Consider updating your toolchain.])])
    ])

    AS_IF([test "${cross_compiling}" = "yes"], [
        CFLAGS="$CFLAGS -static-libgcc"])
    ],

[*irix*], [
    CFLAGS="$CFLAGS -DINET6=1"
    ], [
    AC_MSG_WARN(${target_os} is not officially supported yet.)
    AC_MSG_RESULT(Please report this to ${PACKAGE_BUGREPORT})])

# this only matters if we are building for Windows...
AM_CONDITIONAL([WIN32], [test "${WIN32}" = "yes"])

# Create all files from AC_CONFIG_FILES()
AC_OUTPUT

# Helper variables for summary, below
AS_IF([test ${DX_FLAG_doc} -eq 1], [rebuild_docs=yes], [rebuild_docs=no])
link_layer=`"echo"${LTLIBOBJS}"" | sed 's/.*libnet_link_\(.*\)\$.*/\1/'`

AC_MSG_RESULT([
-=-=-=-=-=-=-=-=-=-= $PACKAGE Configuration Complete =-=-=-=-=-=-=-=-=-=-

    Version ....................... ${VERSION}

    Host .......................... ${host}
    Operating System .............. ${host_os}
    Host CPU ...................... ${host_cpu}
    Host Vendor ................... ${host_vendor}
    Host OS ....................... ${host_os}
    Prefix ........................ ${prefix}

    Cross-compiling ............... ${cross_compiling}
    Compiler is GNU (compatible) .. ${ac_cv_c_compiler_gnu}
    CC ............................ ${CC}
    CFLAGS ........................ ${CFLAGS}
    LD ............................ ${LD}
    LDFLAGS ....................... ${LDFLAGS}
    LIBS .......................... ${LIBS}

    Link Layer .................... ${link_layer}
    Shared Libraries .............. ${enable_shared}
    Static Libraries .............. ${enable_static}
    PIC ........................... ${pic_mode}
    Build Sample Programs ......... ${enable_samples}
    Rebuild docs .................. ${rebuild_docs}
    Tests.......................... ${enable_tests}

To override options

	$0 --help

Report bugs to ${PACKAGE_BUGREPORT}

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
To disable silent build and print the full command line of every stage

	make V=1
])
AS_IF([test "$WIN32" = "yes"], [AC_MSG_RESULT(
[To compile shared libraries on MinGW use the bundled WinPcap libraries
in ./win32/.  GCC can NOT produce x64 compatible images with official
WinPcap Developer Pack.  See README.win32 for more info.
])])
AS_IF([test "$rebuild_docs" = "yes"], [AC_MSG_RESULT(
[To build/update the documentation

	make doc
])])