build: Rename LD command variable to LDQ
[netsniff-ng.git] / configure
blob2e553cbcd8e299606dd5236968f62ac1943be215
1 #!/bin/bash
2 # This isn't a configure generated by autoconf!
3 # netsniff-ng build system
4 # Copyright 2013 Tobias Klauser <tklauser@distanz.ch>
5 # Copyright 2013 Daniel Borkmann <borkmann@gnumaniacs.org>
6 # Subject to the GNU GPL, version 2.
8 MISSING_PKG_CONFIG=0
9 MISSING_DEFS=0
10 MISSING_NACL=0
12 TOOLS="netsniff-ng trafgen astraceroute flowtop ifpps bpfc curvetun mausezahn"
13 TOOLS_NOBUILD=""
15 HAVE_LIBPCAP=0
16 HAVE_HWTSTAMP=0
17 HAVE_LIBGEOIP=0
18 HAVE_LIBZ=0
19 HAVE_TPACKET3=0
21 [ -z $CC ] && CC=cc
23 TMPDIR=$(mktemp -d config.XXXXXX)
24 trap 'status=$?; rm -rf $TMPDIR; exit $status' EXIT HUP INT QUIT TERM
26 tools_remove()
28 local _tools=$TOOLS
29 local _todel=$1
30 TOOLS=""
31 for tool in $_tools ; do
32 case "$tool" in
33 $_todel)
34 case $_todel in
35 $TOOLS_NOBUILD) ;;
36 *) TOOLS_NOBUILD="$TOOLS_NOBUILD $tool" ;;
37 esac ;;
38 *) TOOLS="$TOOLS $tool" ;;
39 esac
40 done
42 TOOLS=${TOOLS# }
43 TOOLS_NOBUILD=${TOOLS_NOBUILD# }
46 check_pkg_config()
48 echo -n "[*] Checking pkg-config ... "
50 if [ "x$(which pkg-config 2>> config.log)" == "x" ] ; then
51 echo "[NO]"
52 MISSING_PKG_CONFIG=1
53 else
54 echo "[YES]"
58 check_flex()
60 echo -n "[*] Checking flex ... "
62 if [ "x$(which flex 2>> config.log)" == "x" ] ; then
63 echo "[NO]"
64 MISSING_DEFS=1
65 tools_remove "trafgen"
66 tools_remove "bpfc"
67 else
68 echo "[YES]"
72 check_bison()
74 echo -n "[*] Checking bison ... "
76 if [ "x$(which bison 2>> config.log)" == "x" ] ; then
77 echo "[NO]"
78 MISSING_DEFS=1
79 tools_remove "trafgen"
80 tools_remove "bpfc"
81 else
82 echo "[YES]"
86 check_nacl()
88 echo -n "[*] Checking nacl ... "
90 cat > $TMPDIR/nacltest.c << EOF
91 #include "crypto_hash_sha512.h"
92 #include "crypto_verify_32.h"
93 #include "crypto_hash_sha512.h"
94 #include "crypto_box_curve25519xsalsa20poly1305.h"
95 #include "crypto_scalarmult_curve25519.h"
96 #include "crypto_auth_hmacsha512256.h"
98 int main(void) { }
99 EOF
101 if [ -z $NACL_INC_DIR ] ; then
102 NACL_INC_DIR="/usr/include/nacl"
105 if [ -z $NACL_LIB_DIR ] ; then
106 NACL_LIB_DIR="/usr/lib"
109 if [ -z $NACL_LIB ] ; then
110 NACL_LIB="nacl"
113 LDFLAGS="-L $NACL_LIB_DIR"
114 CFLAGS="-I $NACL_INC_DIR"
116 $CC $CFLAGS $LDFLAGS -o $TMPDIR/nacltest $TMPDIR/nacltest.c >> config.log 2>&1
117 if [ ! -x $TMPDIR/nacltest ] ; then
118 echo "[NO]"
119 MISSING_NACL=1
120 tools_remove "curvetun"
121 else
122 echo "[YES]"
123 echo "CONFIG_NACL_INC_DIR:=$NACL_INC_DIR" >> Config
124 echo "CONFIG_NACL_LIB_DIR:=$NACL_LIB_DIR" >> Config
125 echo "CONFIG_NACL_LIB:=$NACL_LIB" >> Config
129 check_libnl()
131 echo -n "[*] Checking libnl ... "
133 cat > $TMPDIR/libnltest.c << EOF
134 #include <libnl3/netlink/genl/genl.h>
135 #include <libnl3/netlink/genl/family.h>
136 #include <libnl3/netlink/genl/ctrl.h>
137 #include <libnl3/netlink/msg.h>
138 #include <libnl3/netlink/attr.h>
139 #include <libnl3/netlink/version.h>
141 #if LIBNL_VER_NUM < LIBNL_VER(3,0)
142 # error incompatible libnl version
143 #endif
145 int main(void)
147 struct nl_sock *sock = nl_socket_alloc();
148 struct nl_cache *nl_cache;
149 int ret = genl_connect(sock);
151 ret = genl_ctrl_alloc_cache(sock, &nl_cache);
155 $CC \
156 $(pkg-config --cflags libnl-3.0 2>> config.log) \
157 $(pkg-config --cflags libnl-genl-3.0 2>> config.log) \
158 -o $TMPDIR/libnltest \
159 $TMPDIR/libnltest.c \
160 $(pkg-config --libs libnl-3.0 2>> config.log) \
161 $(pkg-config --libs libnl-genl-3.0 2>> config.log) \
162 >> config.log 2>&1
163 if [ ! -x $TMPDIR/libnltest ] ; then
164 echo "[NO]"
165 MISSING_DEFS=1
166 tools_remove "trafgen"
167 tools_remove "netsniff-ng"
168 else
169 echo "[YES]"
173 check_tpacket_v3()
175 echo -n "[*] Checking tpacket_v3 ... "
177 cat > $TMPDIR/tpacketv3test.c << EOF
178 #include <stdio.h>
179 #include <linux/if_packet.h>
181 int main(void)
183 struct tpacket3_hdr *hdr;
184 int foo[] = {
185 TP_STATUS_BLK_TMO,
188 printf("%d\n", hdr->tp_status);
192 $CC -o $TMPDIR/tpacketv3test $TMPDIR/tpacketv3test.c >> config.log 2>&1
193 if [ ! -x $TMPDIR/tpacketv3test ] ; then
194 echo "[NO]"
195 MISSING_DEFS=1
196 else
197 echo "[YES]"
198 HAVE_TPACKET3=1
202 check_tpacket_v2()
204 echo -n "[*] Checking tpacket_v2 ... "
206 cat > $TMPDIR/tpacketv2test.c << EOF
207 #include <stdio.h>
208 #include <linux/if_packet.h>
210 int main(void)
212 struct tpacket2_hdr *hdr;
213 int foo[] = {
214 TP_STATUS_AVAILABLE,
215 TP_STATUS_SEND_REQUEST,
216 TP_STATUS_SENDING,
217 TP_STATUS_KERNEL,
218 TP_STATUS_USER,
221 printf("%d\n", hdr->tp_status);
225 $CC -o $TMPDIR/tpacketv2test $TMPDIR/tpacketv2test.c >> config.log 2>&1
226 if [ ! -x $TMPDIR/tpacketv2test ] ; then
227 echo "[NO]"
228 MISSING_DEFS=1
229 tools_remove "netsniff-ng"
230 tools_remove "trafgen"
231 else
232 echo "[YES]"
237 check_ncurses()
239 echo -n "[*] Checking ncurses ... "
241 cat > $TMPDIR/ncursestest.c << EOF
242 #include <curses.h>
244 int main(void)
246 WINDOW *screen = initscr();
250 $CC \
251 $(pkg-config --cflags ncurses 2>> config.log) \
252 -o $TMPDIR/ncursestest $TMPDIR/ncursestest.c \
253 $(pkg-config --libs ncurses 2>> config.log \
254 || echo '-lncurses' ) \
255 >> config.log 2>&1
256 if [ ! -x $TMPDIR/ncursestest ] ; then
257 echo "[NO]"
258 MISSING_DEFS=1
259 tools_remove "flowtop"
260 tools_remove "ifpps"
261 else
262 echo "[YES]"
266 check_libgeoip()
268 echo -n "[*] Checking libGeoIP ... "
270 cat > $TMPDIR/geoiptest.c << EOF
271 #include <GeoIP.h>
272 #include <GeoIPCity.h>
274 int main(void)
276 int dbs[] = {
277 GEOIP_CITY_EDITION_REV1,
278 GEOIP_CITY_EDITION_REV1_V6,
279 GEOIP_COUNTRY_EDITION,
280 GEOIP_COUNTRY_EDITION_V6,
281 GEOIP_ASNUM_EDITION,
282 GEOIP_ASNUM_EDITION_V6,
284 GeoIP *geoip = GeoIP_new(0);
288 $CC -o $TMPDIR/geoiptest $TMPDIR/geoiptest.c -lGeoIP >> config.log 2>&1
289 if [ ! -x $TMPDIR/geoiptest ] ; then
290 echo "[NO]"
291 MISSING_DEFS=1
292 else
293 echo "[YES]"
294 HAVE_LIBGEOIP=1
298 check_libnf_ct()
300 echo -n "[*] Checking libnetfilter-conntrack ... "
302 cat > $TMPDIR/nfcttest.c << EOF
303 #include <libnetfilter_conntrack/libnetfilter_conntrack.h>
304 #include <libnetfilter_conntrack/libnetfilter_conntrack_tcp.h>
305 #include <libnetfilter_conntrack/libnetfilter_conntrack_dccp.h>
306 #include <libnetfilter_conntrack/libnetfilter_conntrack_sctp.h>
308 int main(void)
310 struct nf_conntrack *ct;
311 const uint32_t id = nfct_get_attr_u32(ct, ATTR_ID);
315 $CC -o $TMPDIR/nfcttest $TMPDIR/nfcttest.c -lnetfilter_conntrack >> config.log 2>&1
316 if [ ! -x $TMPDIR/nfcttest ] ; then
317 echo "[NO]"
318 MISSING_DEFS=1
319 tools_remove "flowtop"
320 else
321 echo "[YES]"
325 check_zlib()
327 echo -n "[*] Checking libz ... "
329 cat > $TMPDIR/ztest.c << EOF
330 #include "zlib.h"
332 int main(void)
334 gzFile fp = gzopen("foo.gz", "rb");
338 $CC -o $TMPDIR/ztest $TMPDIR/ztest.c -lz >> config.log 2>&1
339 if [ ! -x $TMPDIR/ztest ] ; then
340 echo "[NO]"
341 echo "CONFIG_LIBZ=0" >> Config
342 MISSING_DEFS=1
343 tools_remove "astraceroute"
344 tools_remove "flowtop"
345 else
346 echo "[YES]"
347 echo "CONFIG_LIBZ=1" >> Config
348 HAVE_LIBZ=1
352 check_urcu()
354 echo -n "[*] Checking liburcu ... "
356 cat > $TMPDIR/urcutest.c << EOF
357 #include <urcu.h>
359 int main(void)
361 rcu_init();
362 synchronize_rcu();
366 $CC -o $TMPDIR/urcutest $TMPDIR/urcutest.c -lurcu >> config.log 2>&1
367 if [ ! -x $TMPDIR/urcutest ] ; then
368 echo "[NO]"
369 MISSING_DEFS=1
370 tools_remove "flowtop"
371 else
372 echo "[YES]"
376 check_libpcap()
378 echo -n "[*] Checking libpcap ... "
380 cat > $TMPDIR/pcaptest.c << EOF
381 #include <pcap.h>
383 int main(void)
385 struct bpf_program bpf;
386 int ret = pcap_compile_nopcap(65535, 1, &bpf, "foo.bpf", 1, 0xffffffff);
390 $CC -o $TMPDIR/pcaptest $TMPDIR/pcaptest.c -lpcap >> config.log 2>&1
391 if [ ! -x $TMPDIR/pcaptest ] ; then
392 echo "[NO]"
393 echo "CONFIG_LIBPCAP=0" >> Config
394 MISSING_DEFS=1
395 tools_remove "mausezahn"
396 else
397 echo "[YES]"
398 echo "CONFIG_LIBPCAP=1" >> Config
399 HAVE_LIBPCAP=1
403 check_hwtstamp()
405 echo -n "[*] Checking hw timestamping ... "
407 cat > $TMPDIR/hwtstest.c << EOF
408 #include <string.h>
409 #include <arpa/inet.h>
410 #include <sys/ioctl.h>
411 #include <sys/types.h>
412 #include <sys/socket.h>
413 #include <linux/sockios.h>
414 #include <linux/net_tstamp.h>
415 #include <linux/if_packet.h>
416 #include <linux/if_ether.h>
417 #include <linux/if.h>
419 int main(void)
421 int timesource = SOF_TIMESTAMPING_RAW_HARDWARE, ret;
422 int sock = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
423 struct hwtstamp_config hwconfig;
424 struct ifreq ifr;
426 memset(&hwconfig, 0, sizeof(hwconfig));
427 hwconfig.tx_type = HWTSTAMP_TX_OFF;
428 hwconfig.rx_filter = HWTSTAMP_FILTER_ALL;
430 memset(&ifr, 0, sizeof(ifr));
431 strncpy(ifr.ifr_name, "lo", sizeof(ifr.ifr_name));
432 ifr.ifr_data = &hwconfig;
434 ioctl(sock, SIOCSHWTSTAMP, &ifr);
435 setsockopt(sock, SOL_PACKET, PACKET_TIMESTAMP, &timesource,
436 sizeof(timesource));
440 $CC -o $TMPDIR/hwtstest $TMPDIR/hwtstest.c >> config.log 2>&1
441 if [ ! -x $TMPDIR/hwtstest ] ; then
442 echo "[NO]"
443 echo "CONFIG_HWTSTAMP=0" >> Config
444 else
445 echo "[YES]"
446 echo "CONFIG_HWTSTAMP=1" >> Config
447 HAVE_HWTSTAMP=1
451 check_libcli()
453 echo -n "[*] Checking libcli ... "
455 cat > $TMPDIR/clitest.c << EOF
456 #include <sys/time.h>
457 #include <libcli.h>
459 int main(void)
461 struct cli_def *cli = cli_init();
465 $CC -o $TMPDIR/clitest $TMPDIR/clitest.c -lcli >> config.log 2>&1
466 if [ ! -x $TMPDIR/clitest ] ; then
467 echo "[NO]"
468 MISSING_DEFS=1
469 tools_remove "mausezahn"
470 else
471 echo "[YES]"
475 check_libnet()
477 echo -n "[*] Checking libnet ... "
479 cat > $TMPDIR/nettest.c << EOF
480 #include <libnet.h>
482 int main(void)
484 char err_buf[LIBNET_ERRBUF_SIZE];
485 libnet_t *l = libnet_init(LIBNET_LINK_ADV, "ethX", err_buf);
489 $CC -o $TMPDIR/nettest $TMPDIR/nettest.c -lnet >> config.log 2>&1
490 if [ ! -x $TMPDIR/nettest ] ; then
491 echo "[NO]"
492 MISSING_DEFS=1
493 tools_remove "mausezahn"
494 else
495 echo "[YES]"
499 gen_version_appendix()
501 local _appendix=""
503 git rev-parse > /dev/null 2>&1
504 if [ "$?" == "0" ] ; then
505 if [ ! "`git describe --always`" == \
506 "`git describe --abbrev=0 --tags`" ] ; then
507 _appendix="+"
511 echo "CONFIG_RC=\"$_appendix\"" >> Config
514 gen_config_hdr()
516 local _version=""
517 local _have_libpcap=""
518 local _have_libgeoip=""
519 local _have_libz=""
520 local _have_hwts=""
521 local _have_tp3=""
523 echo "[*] Generating config.h ..."
525 git rev-parse > /dev/null 2>&1
526 if [ "$?" == "0" ] ; then
527 _version="`git describe --always`"
528 else
529 _version="(none)"
532 if [ "$HAVE_LIBPCAP" == "1" ] ; then
533 _have_libpcap="#define HAVE_TCPDUMP_LIKE_FILTER 1"
536 if [ "$HAVE_HWTSTAMP" == "1" ] ; then
537 _have_hwts="#define HAVE_HARDWARE_TIMESTAMPING 1"
540 if [ "$HAVE_LIBGEOIP" == "1" ] ; then
541 _have_libgeoip="#define HAVE_GEOIP 1"
544 if [ "$HAVE_LIBZ" == "1" ] ; then
545 _have_libz="#define HAVE_LIBZ 1"
548 if [ "$HAVE_TPACKET3" == "1" ] ; then
549 _have_tp3="#define HAVE_TPACKET3 1"
552 cat > config.h << EOF
553 #ifndef CONFIG_H
554 #define CONFIG_H
555 #define FILE_CLIENTS ".curvetun/clients"
556 #define FILE_SERVERS ".curvetun/servers"
557 #define FILE_PRIVKEY ".curvetun/priv.key"
558 #define FILE_PUBKEY ".curvetun/pub.key"
559 #define FILE_USERNAM ".curvetun/username"
560 #define GITVERSION "$_version"
561 $_have_libpcap
562 $_have_libgeoip
563 $_have_libz
564 $_have_hwts
565 $_have_tp3
566 #endif /* CONFIG_H */
570 rm -f config.log
572 echo "# This file is autogenerated by the configure script" > Config
573 check_pkg_config
575 if [ "$MISSING_PKG_CONFIG" == "1" ] ; then
576 echo "[!] pkg-config is not installed on your system or not in the PATH"
577 exit 1
580 check_flex
581 check_bison
582 check_nacl
583 check_libnl
584 check_tpacket_v2
585 check_tpacket_v3
586 check_libnf_ct
587 check_ncurses
588 check_libgeoip
589 check_zlib
590 check_urcu
591 check_libpcap
592 check_hwtstamp
593 check_libcli
594 check_libnet
596 gen_config_hdr
597 gen_version_appendix
599 if [ "$MISSING_DEFS" == "1" ] ; then
600 echo "[!] Some libraries or header definitions are missing or too old. Thus"
601 echo " certain tools will not be built (see below). Please refer to the"
602 echo " INSTALL file for the libraries needed to build the complete"
603 echo " netsniff-ng toolkit."
606 if [ "$MISSING_NACL" == "1" ] ; then
607 echo "[!] The NaCl crypto library is currently not present on your system or"
608 echo " could not be found. Either install it from your distro or build it"
609 echo " manually using 'make nacl' and make sure that the NACL_INC_DIR and"
610 echo " NACL_LIB_DIR environment variables are set appropriately."
613 if [ "x$TOOLS_NOBUILD" != "x" ] ; then
614 echo "[!] The following tools will *not* be built: $TOOLS_NOBUILD"
615 echo "[*] The following tools will be built: $TOOLS"
616 else
617 echo "[*] Looks good! All tools will be built!"
620 if [ -s config.log ] ; then
621 echo "[!] There were errors in the configure script. Please check the file"
622 echo " config.log for details."
625 if [ "$HAVE_LIBGEOIP" == "1" -a "$HAVE_LIBZ" == "1" ] ; then
626 echo "CONFIG_GEOIP=1" >> Config
627 else
628 echo "CONFIG_GEOIP=0" >> Config
631 echo "CONFIG_TOOLS=$TOOLS" >> Config
632 echo "CONFIG_OK=1" >> Config
634 exit 0