summaryrefslogtreecommitdiff
path: root/configure
blob: 8d8f1b02e8a32b8cd6b94bf6d7ac60ea32fe3483 (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
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
#!/bin/bash
# This isn't a configure generated by autoconf!
# netsniff-ng build system
# Copyright 2013-2016 Tobias Klauser <tklauser@distanz.ch>
# Copyright 2013 Daniel Borkmann <borkmann@gnumaniacs.org>
# Subject to the GNU GPL, version 2.

MISSING_TOOLCHAIN=0
MISSING_DEFS=0
MISSING_NACL=0

TOOLS="netsniff-ng trafgen astraceroute flowtop ifpps bpfc curvetun mausezahn"
TOOLS_NOBUILD=""

HAVE_LIBNL=0
HAVE_LIBPCAP=0
HAVE_HWTSTAMP=0
HAVE_LIBGEOIP=0
HAVE_LIBZ=0
HAVE_TPACKET3=0

DISABLE_LIBNL=0
DISABLE_GEOIP=0
DISABLE_ZLIB=0
ENABLE_DEBUG=0

PREFIX="/usr/local"
SYSCONF_DIR="/etc"

usage()
{
	echo "Usage: ./configure [OPTION]... [VAR=VALUE]..."
	echo ""
	echo "  -h, --help       Display this help and exit"
	echo ""
	echo "Installation directories:"
	echo "  --prefix=PREFIX  install architecture-independent files in PREFIX"
	echo "                   [$PREFIX]"
	echo "  --sysconfdir=DIR read-only single-machine data [$SYSCONF_DIR]"
	echo ""
	echo "By default, \`make install' will install all the files in"
	echo "\`$PREFIX/bin', \`$PREFIX/lib' etc.  You can specify"
	echo "an installation prefix other than \`$PREFIX' using \`--prefix',"
	echo "for instance \`--prefix=\$HOME'."
	echo ""
	echo "Optional Features:"
	echo "  --disable-libnl  Disable libnl support"
	echo "  --disable-geoip  Disable geoip support"
	echo "  --disable-zlib   Disable zlib support"
	echo "  --enable-debug   Enable debug mode (default disabled)"
	echo ""
	echo "Some influential environment variables:"
	echo "  CC               C compiler command"
	echo "  CROSS_COMPILE    C cross-compiler prefix"

	exit 0
}

while [ $# -gt 0 ] ; do
	case "$1" in
	-h|--help)
		usage
		;;
	--prefix=*)
		PREFIX="${1#*=}"
		;;
	--sysconfdir=*)
		SYSCONF_DIR="${1#*=}"
		;;
	--disable-libnl)
		DISABLE_LIBNL=1
		;;
	--disable-geoip)
		DISABLE_GEOIP=1
		;;
	--disable-zlib)
		DISABLE_ZLIB=1
		;;
	--enable-debug)
		ENABLE_DEBUG=1
		;;
	*)
		echo "[!] Unrecognized option: '$1'. Try './configure --help' for more information"
		exit 1
		;;
	esac
	shift
done

[ -z "$CC" ] && CC="${CROSS_COMPILE}gcc"
[ -z "$LD" ] && LD="${CROSS_COMPILE}gcc"
if [ "x$SYSROOT" != "x" ] ; then
	PKG_CONFIG_PATH="$SYSROOT/usr/lib/pkgconfig:$PKG_CONFIG_PATH"
fi
[ -z $PKG_CONFIG ] && PKG_CONFIG="${CROSS_COMPILE}pkg-config"

TMPDIR=$(mktemp -d config.XXXXXX)
trap 'status=$?; rm -rf $TMPDIR; exit $status' EXIT HUP INT QUIT TERM

tools_remove()
{
	local _tools=$TOOLS
	local _todel=$1
	TOOLS=""
	for tool in $_tools ; do
		case "$tool" in
		$_todel)
			case $_todel in
			$TOOLS_NOBUILD) ;;
			*) TOOLS_NOBUILD="$TOOLS_NOBUILD $tool" ;;
			esac ;;
		*) TOOLS="$TOOLS $tool" ;;
		esac
	done

	TOOLS=${TOOLS# }
	TOOLS_NOBUILD=${TOOLS_NOBUILD# }
}

check_command()
{
	local cmd="$1"

	[ "x$(which "$cmd" 2>> config.log)" == "x" ]
}

check_toolchain()
{
	if [ "x$CROSS_COMPILE" != "x" ] ; then
		echo "[*] Cross-compiling for $($CC -print-multiarch)"
		echo "CROSS_COMPILE=$CROSS_COMPILE" >> Config
	fi

	echo -n "[*] Checking compiler $CC ... "
	if check_command $CC ; then
		echo "[NO]"
		MISSING_TOOLCHAIN=1
	else
		echo "[YES]"
		echo "CC=$CC" >> Config
	fi

	echo -n "[*] Checking linker $LD ... "
	if check_command $LD ; then
		echo "[NO]"
		MISSING_TOOLCHAIN=1
	else
		echo "[YES]"
		echo "LD=$LD" >> Config
	fi

	echo -n "[*] Checking $PKG_CONFIG ... "
	if check_command $PKG_CONFIG ; then
		echo "[NO]"
		MISSING_TOOLCHAIN=1
	else
		echo "[YES]"
		echo "PKG_CONFIG=$PKG_CONFIG" >> Config
		echo "PKG_CONFIG_PATH=$PKG_CONFIG_PATH" >> Config
	fi
}

check_flex()
{
	echo -n "[*] Checking flex ... "

	if check_command flex ; then
		echo "[NO]"
		MISSING_DEFS=1
		tools_remove "trafgen"
		tools_remove "bpfc"
	else
		echo "[YES]"
	fi
}

check_bison()
{
	echo -n "[*] Checking bison ... "

	if check_command bison ; then
		echo "[NO]"
		MISSING_DEFS=1
		tools_remove "trafgen"
		tools_remove "bpfc"
	else
		echo "[YES]"
	fi
}

check_nacl()
{
	echo -n "[*] Checking nacl ... "

	cat > $TMPDIR/nacltest.c << EOF
#include "crypto_hash_sha512.h"
#include "crypto_verify_32.h"
#include "crypto_hash_sha512.h"
#include "crypto_box_curve25519xsalsa20poly1305.h"
#include "crypto_scalarmult_curve25519.h"
#include "crypto_auth_hmacsha512256.h"

int main(void) { }
EOF

	if [ -z $NACL_INC_DIR ] ; then
		NACL_INC_DIR="$SYSROOT/usr/include/nacl"
	fi

	if [ -z $NACL_LIB_DIR ] ; then
		NACL_LIB_DIR="$SYSROOT/usr/lib"
	fi

	if [ -z $NACL_LIB ] ; then
		NACL_LIB="nacl"
	fi

	LDFLAGS="-L $NACL_LIB_DIR"
	CFLAGS="-I $NACL_INC_DIR"

	$CC $CFLAGS $LDFLAGS -o $TMPDIR/nacltest $TMPDIR/nacltest.c >> config.log 2>&1
	if [ ! -x $TMPDIR/nacltest ] ; then
		echo "[NO]"
		MISSING_NACL=1
		tools_remove "curvetun"
	else
		echo "[YES]"
		echo "CONFIG_NACL_INC_DIR:=$NACL_INC_DIR" >> Config
		echo "CONFIG_NACL_LIB_DIR:=$NACL_LIB_DIR" >> Config
		echo "CONFIG_NACL_LIB:=$NACL_LIB" >> Config
	fi
}

check_libnl()
{
	echo -n "[*] Checking libnl ... "

	if [ "$DISABLE_LIBNL" == "1" ] ; then
		echo "[DISABLED]"
		return
	fi

	cat > $TMPDIR/libnltest.c << EOF
#include <netlink/genl/genl.h>
#include <netlink/genl/family.h>
#include <netlink/genl/ctrl.h>
#include <netlink/msg.h>
#include <netlink/attr.h>
#include <netlink/version.h>

#if LIBNL_VER_NUM < LIBNL_VER(3,0)
# error incompatible libnl version
#endif

int main(void)
{
	struct nl_sock *sock = nl_socket_alloc();
	struct nl_cache *nl_cache;
	int ret = genl_connect(sock);

	ret = genl_ctrl_alloc_cache(sock, &nl_cache);
}
EOF

	$CC \
		$($PKG_CONFIG --cflags libnl-3.0 2>> config.log) \
		$($PKG_CONFIG --cflags libnl-genl-3.0 2>> config.log) \
		-o $TMPDIR/libnltest \
		$TMPDIR/libnltest.c \
		$($PKG_CONFIG --libs libnl-3.0 2>> config.log) \
		$($PKG_CONFIG --libs libnl-genl-3.0 2>> config.log) \
			>> config.log 2>&1
	if [ ! -x $TMPDIR/libnltest ] ; then
		echo "[NO]"
		MISSING_DEFS=1
	else
		echo "[YES]"
		HAVE_LIBNL=1
	fi
}

check_libnl_route()
{
	echo -n "[*] Checking libnl-route ... "

	if [ "$DISABLE_LIBNL" == "1" ] ; then
		echo "[DISABLED]"
		return
	fi

	if [ "$HAVE_LIBNL" == "0" ] ; then
		echo "[SKIPPED]"
		return
	fi

	cat > $TMPDIR/libnlroutetest.c << EOF
#include <netlink/route/link.h>
#include <netlink/route/addr.h>

int main(void)
{
	char str[100];

	rtnl_addr_flags2str(1, str, sizeof(str));
	rtnl_link_flags2str(1, str, sizeof(str));
	rtnl_link_operstate2str(1, str, sizeof(str));

	return 0;
}
EOF

	$CC \
		$($PKG_CONFIG --cflags libnl-route-3.0 2>> config.log) \
		-o $TMPDIR/libnlroutetest \
		$TMPDIR/libnlroutetest.c \
		$($PKG_CONFIG --libs libnl-route-3.0 2>> config.log) \
			>> config.log 2>&1
	if [ ! -x $TMPDIR/libnlroutetest ] ; then
		echo "[NO]"
		MISSING_DEFS=1
		HAVE_LIBNL=0
	else
		echo "[YES]"
		# HAVE_LIBNL already set by check_libnl()
	fi
}

check_tpacket_v3()
{
	echo -n "[*] Checking tpacket_v3 ... "

	cat > $TMPDIR/tpacketv3test.c << EOF
#include <stdio.h>
#include <linux/if_packet.h>

int main(void)
{
	struct tpacket3_hdr *hdr;
	int foo[] = {
		TP_STATUS_BLK_TMO,
	};

	printf("%d\n", hdr->tp_status);
}
EOF

	$CC -o $TMPDIR/tpacketv3test $TMPDIR/tpacketv3test.c >> config.log 2>&1
	if [ ! -x $TMPDIR/tpacketv3test ] ; then
		echo "[NO]"
		MISSING_DEFS=1
	else
		echo "[YES]"
		HAVE_TPACKET3=1
	fi
}

check_tpacket_v2()
{
	echo -n "[*] Checking tpacket_v2 ... "

	cat > $TMPDIR/tpacketv2test.c << EOF
#include <stdio.h>
#include <linux/if_packet.h>

int main(void)
{
	struct tpacket2_hdr *hdr;
	int foo[] = {
		TP_STATUS_AVAILABLE,
		TP_STATUS_SEND_REQUEST,
		TP_STATUS_SENDING,
		TP_STATUS_KERNEL,
		TP_STATUS_USER,
	};

	printf("%d\n", hdr->tp_status);
}
EOF

	$CC -o $TMPDIR/tpacketv2test $TMPDIR/tpacketv2test.c >> config.log 2>&1
	if [ ! -x $TMPDIR/tpacketv2test ] ; then
		echo "[NO]"
		MISSING_DEFS=1
		tools_remove "netsniff-ng"
		tools_remove "trafgen"
	else
		echo "[YES]"
	fi
}


check_ncurses()
{
	echo -n "[*] Checking ncurses ... "

	cat > $TMPDIR/ncursestest.c << EOF
#include <curses.h>

int main(void)
{
	WINDOW *screen = initscr();
}
EOF

	$CC \
		$($PKG_CONFIG --cflags ncurses 2>> config.log) \
		-o $TMPDIR/ncursestest $TMPDIR/ncursestest.c \
		$($PKG_CONFIG --libs ncurses 2>> config.log \
	          || echo '-lncurses' ) \
			>> config.log 2>&1
	if [ ! -x $TMPDIR/ncursestest ] ; then
		echo "[NO]"
		MISSING_DEFS=1
		tools_remove "flowtop"
		tools_remove "ifpps"
	else
		echo "[YES]"
	fi
}

check_libgeoip()
{
	echo -n "[*] Checking libGeoIP ... "

	if [ "$DISABLE_GEOIP" == "1" ] ; then
		echo "[DISABLED]"
		return
	fi

	cat > $TMPDIR/geoiptest.c << EOF
#include <GeoIP.h>
#include <GeoIPCity.h>

int main(void)
{
	int dbs[] = {
		GEOIP_CITY_EDITION_REV1,
		GEOIP_CITY_EDITION_REV1_V6,
		GEOIP_COUNTRY_EDITION,
		GEOIP_COUNTRY_EDITION_V6,
		GEOIP_ASNUM_EDITION,
		GEOIP_ASNUM_EDITION_V6,
	};
	GeoIP *geoip = GeoIP_new(0);
}
EOF

	$CC -o $TMPDIR/geoiptest $TMPDIR/geoiptest.c -lGeoIP >> config.log 2>&1
	if [ ! -x $TMPDIR/geoiptest ] ; then
		echo "[NO]"
		MISSING_DEFS=1
	else
		echo "[YES]"
		HAVE_LIBGEOIP=1
	fi
}

check_libnf_ct()
{
	echo -n "[*] Checking libnetfilter-conntrack ... "

	cat > $TMPDIR/nfcttest.c << EOF
#include <libnetfilter_conntrack/libnetfilter_conntrack.h>
#include <libnetfilter_conntrack/libnetfilter_conntrack_tcp.h>
#include <libnetfilter_conntrack/libnetfilter_conntrack_dccp.h>
#include <libnetfilter_conntrack/libnetfilter_conntrack_sctp.h>

int main(void)
{
	struct nf_conntrack *ct;
	const uint32_t id = nfct_get_attr_u32(ct, ATTR_ID);
}
EOF

	$CC \
		$($PKG_CONFIG --cflags libnetfilter_conntrack 2>> config.log) \
		-o $TMPDIR/nfcttest \
		$TMPDIR/nfcttest.c \
		$($PKG_CONFIG --libs libnetfilter_conntrack 2>> config.log) \
			>> config.log 2>&1
	if [ ! -x $TMPDIR/nfcttest ] ; then
		echo "[NO]"
		MISSING_DEFS=1
		tools_remove "flowtop"
	else
		echo "[YES]"
	fi
}

check_zlib()
{
	echo -n "[*] Checking libz ... "

	if [ "$DISABLE_ZLIB" == "1" ] ; then
		echo "[DISABLED]"
		return
	fi

	cat > $TMPDIR/ztest.c << EOF
#include "zlib.h"

int main(void)
{
	gzFile fp = gzopen("foo.gz", "rb");
}
EOF

	$CC -o $TMPDIR/ztest $TMPDIR/ztest.c -lz >> config.log 2>&1
	if [ ! -x $TMPDIR/ztest ] ; then
		echo "[NO]"
		echo "CONFIG_LIBZ=0" >> Config
		MISSING_DEFS=1
		tools_remove "astraceroute"
		tools_remove "flowtop"
	else
		echo "[YES]"
		echo "CONFIG_LIBZ=1" >> Config
		HAVE_LIBZ=1
	fi
}

check_urcu()
{
	echo -n "[*] Checking liburcu ... "

	cat > $TMPDIR/urcutest.c << EOF
#include <urcu.h>

int main(void)
{
	rcu_init();
	synchronize_rcu();
}
EOF

	$CC -o $TMPDIR/urcutest $TMPDIR/urcutest.c -lurcu >> config.log 2>&1
	if [ ! -x $TMPDIR/urcutest ] ; then
		echo "[NO]"
		MISSING_DEFS=1
		tools_remove "flowtop"
	else
		echo "[YES]"
	fi
}

check_libpcap()
{
	echo -n "[*] Checking libpcap ... "

	cat > $TMPDIR/pcaptest.c << EOF
#include <pcap.h>

int main(void)
{
	struct bpf_program bpf;
	int ret = pcap_compile_nopcap(65535, 1, &bpf, "foo.bpf", 1, 0xffffffff);
}
EOF

	$CC -o $TMPDIR/pcaptest $TMPDIR/pcaptest.c -lpcap >> config.log 2>&1
	if [ ! -x $TMPDIR/pcaptest ] ; then
		echo "[NO]"
		echo "CONFIG_LIBPCAP=0" >> Config
		MISSING_DEFS=1
		tools_remove "mausezahn"
	else
		echo "[YES]"
		echo "CONFIG_LIBPCAP=1" >> Config
		HAVE_LIBPCAP=1
	fi
}

check_hwtstamp()
{
	echo -n "[*] Checking hw timestamping ... "

	cat > $TMPDIR/hwtstest.c << EOF
#include <string.h>
#include <arpa/inet.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <linux/sockios.h>
#include <linux/net_tstamp.h>
#include <linux/if_packet.h>
#include <linux/if_ether.h>
#include <linux/if.h>

int main(void)
{
	int timesource = SOF_TIMESTAMPING_RAW_HARDWARE, ret;
	int sock = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
	struct hwtstamp_config hwconfig;
	struct ifreq ifr;

	memset(&hwconfig, 0, sizeof(hwconfig));
	hwconfig.tx_type = HWTSTAMP_TX_OFF;
	hwconfig.rx_filter = HWTSTAMP_FILTER_ALL;

	memset(&ifr, 0, sizeof(ifr));
	strncpy(ifr.ifr_name, "lo", sizeof(ifr.ifr_name));
	ifr.ifr_data = &hwconfig;

	ioctl(sock, SIOCSHWTSTAMP, &ifr);
	setsockopt(sock, SOL_PACKET, PACKET_TIMESTAMP, &timesource,
		   sizeof(timesource));
}
EOF

	$CC -o $TMPDIR/hwtstest $TMPDIR/hwtstest.c >> config.log 2>&1
	if [ ! -x $TMPDIR/hwtstest ] ; then
		echo "[NO]"
		echo "CONFIG_HWTSTAMP=0" >> Config
	else
		echo "[YES]"
		echo "CONFIG_HWTSTAMP=1" >> Config
		HAVE_HWTSTAMP=1
	fi
}

check_libcli()
{
	echo -n "[*] Checking libcli ... "

	cat > $TMPDIR/clitest.c << EOF
#include <sys/time.h>
#include <libcli.h>

int main(void)
{
	struct cli_def *cli = cli_init();
}
EOF

	$CC -o $TMPDIR/clitest $TMPDIR/clitest.c -lcli >> config.log 2>&1
	if [ ! -x $TMPDIR/clitest ] ; then
		echo "[NO]"
		MISSING_DEFS=1
		tools_remove "mausezahn"
	else
		echo "[YES]"
	fi
}

check_libnet()
{
	echo -n "[*] Checking libnet ... "

	cat > $TMPDIR/nettest.c << EOF
#include <libnet.h>

int main(void)
{
	char err_buf[LIBNET_ERRBUF_SIZE];
	libnet_t *l = libnet_init(LIBNET_LINK_ADV, "ethX", err_buf);
}
EOF

	$CC -o $TMPDIR/nettest $TMPDIR/nettest.c -lnet >> config.log 2>&1
	if [ ! -x $TMPDIR/nettest ] ; then
		echo "[NO]"
		MISSING_DEFS=1
		tools_remove "mausezahn"
	else
		echo "[YES]"
	fi
}

gen_version_appendix()
{
	local _appendix=""

	git rev-parse > /dev/null 2>&1
	if [ "$?" == "0" ] ; then
		if [ ! "`git describe --always`" == \
		       "`git describe --abbrev=0 --tags`" ] ; then
			_appendix="+"
		fi
	fi

	echo "CONFIG_RC=\"$_appendix\"" >> Config
}

gen_config_hdr()
{
	local _version=""
	local _have_libpcap=""
	local _have_libgeoip=""
	local _have_libnl=""
	local _have_libz=""
	local _have_hwts=""
	local _have_tp3=""

	echo "[*] Generating config.h ..."

	git rev-parse > /dev/null 2>&1
	if [ "$?" == "0" ] ; then
		_version="`git describe --always`"
	else
		_version="(none)"
	fi

	if [ "$HAVE_LIBNL" == "1" ] ; then
		_have_libnl="#define HAVE_LIBNL 1"
	else
		_have_libnl="/* HAVE_LIBNL is not defined */"
	fi

	if [ "$HAVE_LIBPCAP" == "1" ] ; then
		_have_libpcap="#define HAVE_TCPDUMP_LIKE_FILTER 1"
	else
		_have_libpcap="/* HAVE_TCPDUMP_LIKE_FILTER is not defined */"
	fi

	if [ "$HAVE_HWTSTAMP" == "1" ] ; then
		_have_hwts="#define HAVE_HARDWARE_TIMESTAMPING 1"
	else
		_have_hwts="/* HAVE_HARDWARE_TIMESTAMPING is not defined */"
	fi

	if [ "$HAVE_LIBGEOIP" == "1" ] ; then
		_have_libgeoip="#define HAVE_GEOIP 1"
	else
		_have_libgeoip="/* HAVE_GEOIP is not defined */"
	fi

	if [ "$HAVE_LIBZ" == "1" ] ; then
		_have_libz="#define HAVE_LIBZ 1"
	else
		_have_libz="/* HAVE_LIBZ is not defined */"
	fi

	if [ "$HAVE_TPACKET3" == "1" ] ; then
		_have_tp3="#define HAVE_TPACKET3 1"
	else
		_have_tp3="/* HAVE_TPACKET3 is not defined */"
	fi

	cat > config.h << EOF
#ifndef CONFIG_H
#define CONFIG_H
#define FILE_CLIENTS ".curvetun/clients"
#define FILE_SERVERS ".curvetun/servers"
#define FILE_PRIVKEY ".curvetun/priv.key"
#define FILE_PUBKEY ".curvetun/pub.key"
#define FILE_USERNAM ".curvetun/username"
#define GITVERSION "$_version"
$_have_libnl
$_have_libpcap
$_have_libgeoip
$_have_libz
$_have_hwts
$_have_tp3
#endif /* CONFIG_H */
EOF
}

rm -f config.log

echo "# This file is autogenerated by the configure script" > Config
check_toolchain

if [ "$MISSING_TOOLCHAIN" == "1" ] ; then
	echo "[!] One or more of the toolchain tools couldn't be found in your"
	echo "    \$PATH. Please check the file config.log for details."
	exit 1
fi

check_flex
check_bison
check_nacl
check_libnl
check_libnl_route
check_tpacket_v2
check_tpacket_v3
check_libnf_ct
check_ncurses
check_libgeoip
check_zlib
check_urcu
check_libpcap
check_hwtstamp
check_libcli
check_libnet

gen_config_hdr
gen_version_appendix

if [ "$MISSING_DEFS" == "1" ] ; then
	echo "[!] Some libraries or header definitions are missing or too old. Thus"
	echo "    certain tools will not be built (see below) or they will be built"
	echo "    with reduced functionality. Please refer to the INSTALL file"
	echo "    for the libraries needed to build the complete netsniff-ng toolkit"
fi

if [ "$MISSING_NACL" == "1" ] ; then
	echo "[!] The NaCl crypto library is currently not present on your system or"
	echo "    could not be found. Either install it from your distro or build it"
	echo "    manually using 'make nacl' and make sure that the NACL_INC_DIR and"
	echo "    NACL_LIB_DIR environment variables are set appropriately."
fi

if [ "x$TOOLS_NOBUILD" != "x" ] ; then
	echo "[!] The following tools will *not* be built: $TOOLS_NOBUILD"
	echo "[*] The following tools will be built: $TOOLS"
else
	echo "[*] Looks good! All tools will be built!"
fi

if [ -s config.log ] ; then
	echo "[!] There were errors in the configure script. Please check the file"
	echo "    config.log for details."
fi

echo "CONFIG_LIBNL=$HAVE_LIBNL" >> Config

if [ "$HAVE_LIBGEOIP" == "1" -a "$HAVE_LIBZ" == "1"  ] ; then
	echo "CONFIG_GEOIP=1" >> Config
else
	echo "CONFIG_GEOIP=0" >> Config
fi

echo "CONFIG_PREFIX=$PREFIX" >> Config
echo "CONFIG_ETCDIR=$SYSCONF_DIR" >> Config

echo "CONFIG_DEBUG=$ENABLE_DEBUG" >> Config
echo "CONFIG_TOOLS=$TOOLS" >> Config
echo "CONFIG_OK=1" >> Config

exit 0