cpusched: Fix compiler warnings
[netsniff-ng.git] / configure
blob4d6b284d4b65218e62fa4e96af2fb094d70a8058
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
20 [ -z $CC ] && CC=cc
22 TMPDIR=$(mktemp -d config.XXXXXX)
23 trap 'status=$?; rm -rf $TMPDIR; exit $status' EXIT HUP INT QUIT TERM
25 tools_remove()
27 local _tools=$TOOLS
28 local _todel=$1
29 TOOLS=""
30 for tool in $_tools ; do
31 case "$tool" in
32 $_todel)
33 case $_todel in
34 $TOOLS_NOBUILD) ;;
35 *) TOOLS_NOBUILD="$TOOLS_NOBUILD $tool" ;;
36 esac ;;
37 *) TOOLS="$TOOLS $tool" ;;
38 esac
39 done
41 TOOLS=${TOOLS# }
42 TOOLS_NOBUILD=${TOOLS_NOBUILD# }
45 check_pkg_config()
47 echo -n "[*] Checking pkg-config ... "
49 if [ "x$(which pkg-config 2>> config.log)" == "x" ] ; then
50 echo "[NO]"
51 MISSING_PKG_CONFIG=1
52 else
53 echo "[YES]"
57 check_ccache()
59 echo -n "[*] Checking ccache ... "
61 if [ "x$(which ccache 2>> config.log)" == "x" ] ; then
62 echo "[NO]"
63 echo "CONFIG_CCACHE=" >> Config
64 else
65 echo "[YES]"
66 echo "CONFIG_CCACHE=ccache" >> Config
70 check_flex()
72 echo -n "[*] Checking flex ... "
74 if [ "x$(which flex 2>> config.log)" == "x" ] ; then
75 echo "[NO]"
76 MISSING_DEFS=1
77 tools_remove "trafgen"
78 tools_remove "bpfc"
79 else
80 echo "[YES]"
84 check_bison()
86 echo -n "[*] Checking bison ... "
88 if [ "x$(which bison 2>> config.log)" == "x" ] ; then
89 echo "[NO]"
90 MISSING_DEFS=1
91 tools_remove "trafgen"
92 tools_remove "bpfc"
93 else
94 echo "[YES]"
98 check_nacl()
100 echo -n "[*] Checking nacl ... "
102 cat > $TMPDIR/nacltest.c << EOF
103 #include "crypto_hash_sha512.h"
104 #include "crypto_verify_32.h"
105 #include "crypto_hash_sha512.h"
106 #include "crypto_box_curve25519xsalsa20poly1305.h"
107 #include "crypto_scalarmult_curve25519.h"
108 #include "crypto_auth_hmacsha512256.h"
110 int main(void) { }
113 if [ -z $NACL_INC_DIR ] ; then
114 NACL_INC_DIR="/usr/include/nacl"
117 if [ -z $NACL_LIB_DIR ] ; then
118 NACL_LIB_DIR="/usr/lib"
121 LDFLAGS="-L $NACL_LIB_DIR"
122 CFLAGS="-I $NACL_INC_DIR"
124 $CC $CFLAGS $LDFLAGS -o $TMPDIR/nacltest $TMPDIR/nacltest.c >> config.log 2>&1
125 if [ ! -x $TMPDIR/nacltest ] ; then
126 echo "[NO]"
127 MISSING_NACL=1
128 tools_remove "curvetun"
129 else
130 echo "[YES]"
131 echo "CONFIG_NACL_INC_DIR:=$NACL_INC_DIR" >> Config
132 echo "CONFIG_NACL_LIB_DIR:=$NACL_LIB_DIR" >> Config
136 check_libnl()
138 echo -n "[*] Checking libnl ... "
140 cat > $TMPDIR/libnltest.c << EOF
141 #include <libnl3/netlink/genl/genl.h>
142 #include <libnl3/netlink/genl/family.h>
143 #include <libnl3/netlink/genl/ctrl.h>
144 #include <libnl3/netlink/msg.h>
145 #include <libnl3/netlink/attr.h>
146 #include <libnl3/netlink/version.h>
148 #if LIBNL_VER_NUM < LIBNL_VER(3,0)
149 # error incompatible libnl version
150 #endif
152 void main(void)
154 struct nl_sock *sock = nl_socket_alloc();
155 struct nl_cache *nl_cache;
156 int ret = genl_connect(sock);
158 ret = genl_ctrl_alloc_cache(sock, &nl_cache);
162 $CC \
163 $(pkg-config --cflags libnl-3.0 2>> config.log) \
164 $(pkg-config --cflags libnl-genl-3.0 2>> config.log) \
165 -o $TMPDIR/libnltest \
166 $TMPDIR/libnltest.c \
167 $(pkg-config --libs libnl-3.0 2>> config.log) \
168 $(pkg-config --libs libnl-genl-3.0 2>> config.log) \
169 >> config.log 2>&1
170 if [ ! -x $TMPDIR/libnltest ] ; then
171 echo "[NO]"
172 MISSING_DEFS=1
173 tools_remove "trafgen"
174 tools_remove "netsniff-ng"
175 else
176 echo "[YES]"
180 check_tpacket_v3()
182 echo -n "[*] Checking tpacket_v3 ... "
184 cat > $TMPDIR/tpacketv3test.c << EOF
185 #include <stdio.h>
186 #include <linux/if_packet.h>
188 void main(void)
190 struct tpacket3_hdr *hdr;
191 int foo[] = {
192 TP_STATUS_BLK_TMO,
195 printf("%d\n", hdr->tp_status);
199 $CC -o $TMPDIR/tpacketv3test $TMPDIR/tpacketv3test.c >> config.log 2>&1
200 if [ ! -x $TMPDIR/tpacketv3test ] ; then
201 echo "[NO]"
202 MISSING_DEFS=1
203 tools_remove "netsniff-ng"
204 else
205 echo "[YES]"
209 check_tpacket_v2()
211 echo -n "[*] Checking tpacket_v2 ... "
213 cat > $TMPDIR/tpacketv2test.c << EOF
214 #include <stdio.h>
215 #include <linux/if_packet.h>
217 void main(void)
219 struct tpacket2_hdr *hdr;
220 int foo[] = {
221 TP_STATUS_AVAILABLE,
222 TP_STATUS_SEND_REQUEST,
223 TP_STATUS_SENDING,
224 TP_STATUS_KERNEL,
225 TP_STATUS_USER,
228 printf("%d\n", hdr->tp_status);
232 $CC -o $TMPDIR/tpacketv2test $TMPDIR/tpacketv2test.c >> config.log 2>&1
233 if [ ! -x $TMPDIR/tpacketv2test ] ; then
234 echo "[NO]"
235 MISSING_DEFS=1
236 tools_remove "netsniff-ng"
237 tools_remove "trafgen"
238 else
239 echo "[YES]"
244 check_ncurses()
246 echo -n "[*] Checking ncurses ... "
248 cat > $TMPDIR/ncursestest.c << EOF
249 #include <curses.h>
251 void main(void)
253 WINDOW *screen = initscr();
257 $CC \
258 $(pkg-config --cflags ncurses 2>> config.log) \
259 -o $TMPDIR/ncursestest $TMPDIR/ncursestest.c \
260 $(pkg-config --libs ncurses 2>> config.log) \
261 >> config.log 2>&1
262 if [ ! -x $TMPDIR/ncursestest ] ; then
263 echo "[NO]"
264 MISSING_DEFS=1
265 tools_remove "flowtop"
266 tools_remove "ifpps"
267 else
268 echo "[YES]"
272 check_libgeoip()
274 echo -n "[*] Checking libGeoIP ... "
276 cat > $TMPDIR/geoiptest.c << EOF
277 #include <GeoIP.h>
278 #include <GeoIPCity.h>
280 void main(void)
282 int dbs[] = {
283 GEOIP_CITY_EDITION_REV1,
284 GEOIP_CITY_EDITION_REV1_V6,
285 GEOIP_COUNTRY_EDITION,
286 GEOIP_COUNTRY_EDITION_V6,
287 GEOIP_ASNUM_EDITION,
288 GEOIP_ASNUM_EDITION_V6,
290 GeoIP *geoip = GeoIP_new(0);
294 $CC -o $TMPDIR/geoiptest $TMPDIR/geoiptest.c -lGeoIP >> config.log 2>&1
295 if [ ! -x $TMPDIR/geoiptest ] ; then
296 echo "[NO]"
297 echo "CONFIG_LIBGEOIP=0" >> Config
298 MISSING_DEFS=1
299 tools_remove "astraceroute"
300 tools_remove "flowtop"
301 else
302 echo "[YES]"
303 echo "CONFIG_LIBGEOIP=1" >> Config
304 HAVE_LIBGEOIP=1
308 check_libnf_ct()
310 echo -n "[*] Checking libnetfilter-conntrack ... "
312 cat > $TMPDIR/nfcttest.c << EOF
313 #include <libnetfilter_conntrack/libnetfilter_conntrack.h>
314 #include <libnetfilter_conntrack/libnetfilter_conntrack_tcp.h>
315 #include <libnetfilter_conntrack/libnetfilter_conntrack_dccp.h>
316 #include <libnetfilter_conntrack/libnetfilter_conntrack_sctp.h>
318 void main(void)
320 struct nf_conntrack *ct;
321 const uint32_t id = nfct_get_attr_u32(ct, ATTR_ID);
325 $CC -o $TMPDIR/nfcttest $TMPDIR/nfcttest.c -lnetfilter_conntrack >> config.log 2>&1
326 if [ ! -x $TMPDIR/nfcttest ] ; then
327 echo "[NO]"
328 MISSING_DEFS=1
329 tools_remove "flowtop"
330 else
331 echo "[YES]"
335 check_zlib()
337 echo -n "[*] Checking libz ... "
339 cat > $TMPDIR/ztest.c << EOF
340 #include "zlib.h"
342 void main(void)
344 gzFile fp = gzopen("foo.gz", "rb");
348 $CC -o $TMPDIR/ztest $TMPDIR/ztest.c -lz >> config.log 2>&1
349 if [ ! -x $TMPDIR/ztest ] ; then
350 echo "[NO]"
351 echo "CONFIG_LIBZ=0" >> Config
352 MISSING_DEFS=1
353 tools_remove "astraceroute"
354 tools_remove "flowtop"
355 else
356 echo "[YES]"
357 echo "CONFIG_LIBZ=1" >> Config
358 HAVE_LIBZ=1
362 check_urcu()
364 echo -n "[*] Checking liburcu ... "
366 cat > $TMPDIR/urcutest.c << EOF
367 #include <urcu.h>
369 void main(void)
371 rcu_init();
372 synchronize_rcu();
376 $CC -o $TMPDIR/urcutest $TMPDIR/urcutest.c -lurcu >> config.log 2>&1
377 if [ ! -x $TMPDIR/urcutest ] ; then
378 echo "[NO]"
379 MISSING_DEFS=1
380 tools_remove "flowtop"
381 else
382 echo "[YES]"
386 check_libpcap()
388 echo -n "[*] Checking libpcap ... "
390 cat > $TMPDIR/pcaptest.c << EOF
391 #include <pcap.h>
393 void main(void)
395 struct bpf_program bpf;
396 int ret = pcap_compile_nopcap(65535, 1, &bpf, "foo.bpf", 1, 0xffffffff);
400 $CC -o $TMPDIR/pcaptest $TMPDIR/pcaptest.c -lpcap >> config.log 2>&1
401 if [ ! -x $TMPDIR/pcaptest ] ; then
402 echo "[NO]"
403 echo "CONFIG_LIBPCAP=0" >> Config
404 MISSING_DEFS=1
405 tools_remove "mausezahn"
406 else
407 echo "[YES]"
408 echo "CONFIG_LIBPCAP=1" >> Config
409 HAVE_LIBPCAP=1
413 check_hwtstamp()
415 echo -n "[*] Checking hw timestamping ... "
417 cat > $TMPDIR/hwtstest.c << EOF
418 #include <string.h>
419 #include <arpa/inet.h>
420 #include <sys/ioctl.h>
421 #include <sys/types.h>
422 #include <sys/socket.h>
423 #include <linux/sockios.h>
424 #include <linux/net_tstamp.h>
425 #include <linux/if_packet.h>
426 #include <linux/if_ether.h>
427 #include <linux/if.h>
429 void main(void)
431 int timesource = SOF_TIMESTAMPING_RAW_HARDWARE, ret;
432 int sock = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
433 struct hwtstamp_config hwconfig;
434 struct ifreq ifr;
436 memset(&hwconfig, 0, sizeof(hwconfig));
437 hwconfig.tx_type = HWTSTAMP_TX_OFF;
438 hwconfig.rx_filter = HWTSTAMP_FILTER_ALL;
440 memset(&ifr, 0, sizeof(ifr));
441 strncpy(ifr.ifr_name, "lo", sizeof(ifr.ifr_name));
442 ifr.ifr_data = &hwconfig;
444 ioctl(sock, SIOCSHWTSTAMP, &ifr);
445 setsockopt(sock, SOL_PACKET, PACKET_TIMESTAMP, &timesource,
446 sizeof(timesource));
450 $CC -o $TMPDIR/hwtstest $TMPDIR/hwtstest.c >> config.log 2>&1
451 if [ ! -x $TMPDIR/hwtstest ] ; then
452 echo "[NO]"
453 echo "CONFIG_HWTSTAMP=0" >> Config
454 else
455 echo "[YES]"
456 echo "CONFIG_HWTSTAMP=1" >> Config
457 HAVE_HWTSTAMP=1
461 check_libcli()
463 echo -n "[*] Checking libcli ... "
465 cat > $TMPDIR/clitest.c << EOF
466 #include <sys/time.h>
467 #include <libcli.h>
469 void main(void)
471 struct cli_def *cli = cli_init();
475 $CC -o $TMPDIR/clitest $TMPDIR/clitest.c -lcli >> config.log 2>&1
476 if [ ! -x $TMPDIR/clitest ] ; then
477 echo "[NO]"
478 MISSING_DEFS=1
479 tools_remove "mausezahn"
480 else
481 echo "[YES]"
485 check_libnet()
487 echo -n "[*] Checking libnet ... "
489 cat > $TMPDIR/nettest.c << EOF
490 #include <libnet.h>
492 void main(void)
494 char err_buf[LIBNET_ERRBUF_SIZE];
495 libnet_t *l = libnet_init(LIBNET_LINK_ADV, "ethX", err_buf);
499 $CC -o $TMPDIR/nettest $TMPDIR/nettest.c -lnet >> config.log 2>&1
500 if [ ! -x $TMPDIR/nettest ] ; then
501 echo "[NO]"
502 MISSING_DEFS=1
503 tools_remove "mausezahn"
504 else
505 echo "[YES]"
509 gen_version_appendix()
511 local _appendix=""
513 git rev-parse > /dev/null 2>&1
514 if [ "$?" == "0" ] ; then
515 if [ ! "`git describe --always`" == \
516 "`git describe --abbrev=0 --tags`" ] ; then
517 _appendix="+"
521 echo "CONFIG_RC=\"$_appendix\"" >> Config
524 gen_config_hdr()
526 local _version=""
527 local _have_libpcap=""
528 local _have_libgeoip=""
529 local _have_libz=""
530 local _have_hwts=""
532 echo "[*] Generating config.h ... "
534 git rev-parse > /dev/null 2>&1
535 if [ "$?" == "0" ] ; then
536 _version="`git describe --always`"
537 else
538 _version="(none)"
541 if [ "$HAVE_LIBPCAP" == "1" ] ; then
542 _have_libpcap="#define HAVE_TCPDUMP_LIKE_FILTER 1"
545 if [ "$HAVE_HWTSTAMP" == "1" ] ; then
546 _have_hwts="#define HAVE_HARDWARE_TIMESTAMPING 1"
549 if [ "$HAVE_LIBGEOIP" == "1" ] ; then
550 _have_libgeoip="#define HAVE_GEOIP 1"
553 if [ "$HAVE_LIBZ" == "1" ] ; then
554 _have_libz="#define HAVE_LIBZ 1"
557 cat > config.h << EOF
558 #ifndef CONFIG_H
559 #define CONFIG_H
560 #define FILE_CLIENTS ".curvetun/clients"
561 #define FILE_SERVERS ".curvetun/servers"
562 #define FILE_PRIVKEY ".curvetun/priv.key"
563 #define FILE_PUBKEY ".curvetun/pub.key"
564 #define FILE_USERNAM ".curvetun/username"
565 #define GITVERSION "$_version"
566 $_have_libpcap
567 $_have_libgeoip
568 $_have_libz
569 $_have_hwts
570 #endif /* CONFIG_H */
574 rm -f config.log
576 echo "# This file is autogenerated by the configure script" > Config
577 check_pkg_config
579 if [ "$MISSING_PKG_CONFIG" == "1" ] ; then
580 echo "[!] pkg-config is not installed on your system or not in the PATH"
581 exit 1
584 check_ccache
585 check_flex
586 check_bison
587 check_nacl
588 check_libnl
589 check_tpacket_v2
590 check_tpacket_v3
591 check_libnf_ct
592 check_ncurses
593 check_libgeoip
594 check_zlib
595 check_urcu
596 check_libpcap
597 check_hwtstamp
598 check_libcli
599 check_libnet
601 gen_config_hdr
602 gen_version_appendix
604 if [ "$MISSING_DEFS" == "1" ] ; then
605 echo "[!] Some libraries or header definitions are missing or too old."
606 echo " Thus certain tools will not be built (see below). Please"
607 echo " refer to the INSTALL file for the libraries needed to build"
608 echo " the complete netsniff-ng toolkit."
611 if [ "$MISSING_NACL" == "1" ] ; then
612 echo "[!] The NaCl crypto library is currently not present on your"
613 echo " system or could not be found. Either install it from your"
614 echo " distro or build it manually using 'make nacl' and make sure"
615 echo " that the NACL_INC_DIR and NACL_LIB_DIR variables are set"
616 echo " appropriately."
619 if [ "x$TOOLS_NOBUILD" != "x" ] ; then
620 echo "[!] The following tools will *not* be built: $TOOLS_NOBUILD"
621 echo "[*] The following tools will be built: $TOOLS"
622 else
623 echo "[*] Looks good! All tools will be built!"
626 if [ -s config.log ] ; then
627 echo "[!] There were errors in the configure script. Please see"
628 echo " the file config.log for details."
631 if [ "$HAVE_LIBGEOIP" == "1" -a "$HAVE_LIBZ" == "1" ] ; then
632 echo "CONFIG_GEOIP=1" >> Config
633 else
634 echo "CONFIG_GEOIP=0" >> Config
637 echo "CONFIG_TOOLS=$TOOLS" >> Config
638 echo "CONFIG_OK=1" >> Config
640 exit 0