build: configure: Add option to enable debug symbols
[netsniff-ng.git] / configure
blob4a5b7e314086e0a66a50383e2cc67550eba0cce5
1 #!/bin/bash
2 # This isn't a configure generated by autoconf!
3 # netsniff-ng build system
4 # Copyright 2013-2016 Tobias Klauser <tklauser@distanz.ch>
5 # Copyright 2013 Daniel Borkmann <borkmann@gnumaniacs.org>
6 # Subject to the GNU GPL, version 2.
8 MISSING_TOOLCHAIN=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_LIBNL=0
16 HAVE_LIBPCAP=0
17 HAVE_HWTSTAMP=0
18 HAVE_LIBGEOIP=0
19 HAVE_LIBZ=0
20 HAVE_TPACKET3=0
22 DISABLE_LIBNL=0
23 DISABLE_GEOIP=0
24 DISABLE_ZLIB=0
25 ENABLE_DEBUG=0
27 usage()
29 echo "Usage: ./configure [OPTION]... [VAR=VALUE]..."
30 echo ""
31 echo " -h, --help Display this help and exit"
32 echo ""
33 echo "Optional Features:"
34 echo " --disable-libnl Disable libnl support"
35 echo " --disable-geoip Disable geoip support"
36 echo " --disable-zlib Disable zlib support"
37 echo " --enable-debug Enable debug mode (default disabled)"
38 echo ""
39 echo "Some influential environment variables:"
40 echo " CC C compiler command"
41 echo " CROSS_COMPILE C cross-compiler prefix"
43 exit 0
46 while [ $# -gt 0 ] ; do
47 case "$1" in
48 -h|--help)
49 usage
51 --disable-libnl)
52 DISABLE_LIBNL=1
54 --disable-geoip)
55 DISABLE_GEOIP=1
57 --disable-zlib)
58 DISABLE_ZLIB=1
60 --enable-debug)
61 ENABLE_DEBUG=1
64 echo "[!] Unrecognized option: '$1'. Try './configure --help' for more information"
65 exit 1
67 esac
68 shift
69 done
71 [ -z "$CC" ] && CC="${CROSS_COMPILE}gcc"
72 [ -z "$LD" ] && LD="${CROSS_COMPILE}gcc"
73 if [ "x$SYSROOT" != "x" ] ; then
74 PKG_CONFIG_PATH="$SYSROOT/usr/lib/pkgconfig:$PKG_CONFIG_PATH"
76 [ -z $PKG_CONFIG ] && PKG_CONFIG="${CROSS_COMPILE}pkg-config"
78 TMPDIR=$(mktemp -d config.XXXXXX)
79 trap 'status=$?; rm -rf $TMPDIR; exit $status' EXIT HUP INT QUIT TERM
81 tools_remove()
83 local _tools=$TOOLS
84 local _todel=$1
85 TOOLS=""
86 for tool in $_tools ; do
87 case "$tool" in
88 $_todel)
89 case $_todel in
90 $TOOLS_NOBUILD) ;;
91 *) TOOLS_NOBUILD="$TOOLS_NOBUILD $tool" ;;
92 esac ;;
93 *) TOOLS="$TOOLS $tool" ;;
94 esac
95 done
97 TOOLS=${TOOLS# }
98 TOOLS_NOBUILD=${TOOLS_NOBUILD# }
101 check_toolchain()
103 if [ "x$CROSS_COMPILE" != "x" ] ; then
104 echo "[*] Cross-compiling for $($CC -print-multiarch)"
105 echo "CROSS_COMPILE=$CROSS_COMPILE" >> Config
108 echo -n "[*] Checking compiler $CC ... "
109 if [ "x$(which $CC 2>> config.log)" == "x" ] ; then
110 echo "[NO]"
111 MISSING_TOOLCHAIN=1
112 else
113 echo "[YES]"
114 echo "CC=$CC" >> Config
117 echo -n "[*] Checking linker $LD ... "
118 if [ "x$(which $LD 2>> config.log)" == "x" ] ; then
119 echo "[NO]"
120 MISSING_TOOLCHAIN=1
121 else
122 echo "[YES]"
123 echo "LD=$LD" >> Config
126 echo -n "[*] Checking $PKG_CONFIG ... "
127 if [ "x$(which $PKG_CONFIG 2>> config.log)" == "x" ] ; then
128 echo "[NO]"
129 MISSING_TOOLCHAIN=1
130 else
131 echo "[YES]"
132 echo "PKG_CONFIG=$PKG_CONFIG" >> Config
133 echo "PKG_CONFIG_PATH=$PKG_CONFIG_PATH" >> Config
137 check_flex()
139 echo -n "[*] Checking flex ... "
141 if [ "x$(which flex 2>> config.log)" == "x" ] ; then
142 echo "[NO]"
143 MISSING_DEFS=1
144 tools_remove "trafgen"
145 tools_remove "bpfc"
146 else
147 echo "[YES]"
151 check_bison()
153 echo -n "[*] Checking bison ... "
155 if [ "x$(which bison 2>> config.log)" == "x" ] ; then
156 echo "[NO]"
157 MISSING_DEFS=1
158 tools_remove "trafgen"
159 tools_remove "bpfc"
160 else
161 echo "[YES]"
165 check_nacl()
167 echo -n "[*] Checking nacl ... "
169 cat > $TMPDIR/nacltest.c << EOF
170 #include "crypto_hash_sha512.h"
171 #include "crypto_verify_32.h"
172 #include "crypto_hash_sha512.h"
173 #include "crypto_box_curve25519xsalsa20poly1305.h"
174 #include "crypto_scalarmult_curve25519.h"
175 #include "crypto_auth_hmacsha512256.h"
177 int main(void) { }
180 if [ -z $NACL_INC_DIR ] ; then
181 NACL_INC_DIR="$SYSROOT/usr/include/nacl"
184 if [ -z $NACL_LIB_DIR ] ; then
185 NACL_LIB_DIR="$SYSROOT/usr/lib"
188 if [ -z $NACL_LIB ] ; then
189 NACL_LIB="nacl"
192 LDFLAGS="-L $NACL_LIB_DIR"
193 CFLAGS="-I $NACL_INC_DIR"
195 $CC $CFLAGS $LDFLAGS -o $TMPDIR/nacltest $TMPDIR/nacltest.c >> config.log 2>&1
196 if [ ! -x $TMPDIR/nacltest ] ; then
197 echo "[NO]"
198 MISSING_NACL=1
199 tools_remove "curvetun"
200 else
201 echo "[YES]"
202 echo "CONFIG_NACL_INC_DIR:=$NACL_INC_DIR" >> Config
203 echo "CONFIG_NACL_LIB_DIR:=$NACL_LIB_DIR" >> Config
204 echo "CONFIG_NACL_LIB:=$NACL_LIB" >> Config
208 check_libnl()
210 echo -n "[*] Checking libnl ... "
212 if [ "$DISABLE_LIBNL" == "1" ] ; then
213 echo "[DISABLED]"
214 return
217 cat > $TMPDIR/libnltest.c << EOF
218 #include <netlink/genl/genl.h>
219 #include <netlink/genl/family.h>
220 #include <netlink/genl/ctrl.h>
221 #include <netlink/msg.h>
222 #include <netlink/attr.h>
223 #include <netlink/version.h>
225 #if LIBNL_VER_NUM < LIBNL_VER(3,0)
226 # error incompatible libnl version
227 #endif
229 int main(void)
231 struct nl_sock *sock = nl_socket_alloc();
232 struct nl_cache *nl_cache;
233 int ret = genl_connect(sock);
235 ret = genl_ctrl_alloc_cache(sock, &nl_cache);
239 $CC \
240 $($PKG_CONFIG --cflags libnl-3.0 2>> config.log) \
241 $($PKG_CONFIG --cflags libnl-genl-3.0 2>> config.log) \
242 -o $TMPDIR/libnltest \
243 $TMPDIR/libnltest.c \
244 $($PKG_CONFIG --libs libnl-3.0 2>> config.log) \
245 $($PKG_CONFIG --libs libnl-genl-3.0 2>> config.log) \
246 >> config.log 2>&1
247 if [ ! -x $TMPDIR/libnltest ] ; then
248 echo "[NO]"
249 MISSING_DEFS=1
250 else
251 echo "[YES]"
252 HAVE_LIBNL=1
256 check_libnl_route()
258 echo -n "[*] Checking libnl-route ... "
260 if [ "$DISABLE_LIBNL" == "1" ] ; then
261 echo "[DISABLED]"
262 return
265 if [ "$HAVE_LIBNL" == "0" ] ; then
266 echo "[SKIPPED]"
267 return
270 cat > $TMPDIR/libnlroutetest.c << EOF
271 #include <netlink/route/link.h>
272 #include <netlink/route/addr.h>
274 int main(void)
276 char str[100];
278 rtnl_addr_flags2str(1, str, sizeof(str));
279 rtnl_link_flags2str(1, str, sizeof(str));
280 rtnl_link_operstate2str(1, str, sizeof(str));
282 return 0;
286 $CC \
287 $($PKG_CONFIG --cflags libnl-route-3.0 2>> config.log) \
288 -o $TMPDIR/libnlroutetest \
289 $TMPDIR/libnlroutetest.c \
290 $($PKG_CONFIG --libs libnl-route-3.0 2>> config.log) \
291 >> config.log 2>&1
292 if [ ! -x $TMPDIR/libnlroutetest ] ; then
293 echo "[NO]"
294 MISSING_DEFS=1
295 HAVE_LIBNL=0
296 else
297 echo "[YES]"
298 # HAVE_LIBNL already set by check_libnl()
302 check_tpacket_v3()
304 echo -n "[*] Checking tpacket_v3 ... "
306 cat > $TMPDIR/tpacketv3test.c << EOF
307 #include <stdio.h>
308 #include <linux/if_packet.h>
310 int main(void)
312 struct tpacket3_hdr *hdr;
313 int foo[] = {
314 TP_STATUS_BLK_TMO,
317 printf("%d\n", hdr->tp_status);
321 $CC -o $TMPDIR/tpacketv3test $TMPDIR/tpacketv3test.c >> config.log 2>&1
322 if [ ! -x $TMPDIR/tpacketv3test ] ; then
323 echo "[NO]"
324 MISSING_DEFS=1
325 else
326 echo "[YES]"
327 HAVE_TPACKET3=1
331 check_tpacket_v2()
333 echo -n "[*] Checking tpacket_v2 ... "
335 cat > $TMPDIR/tpacketv2test.c << EOF
336 #include <stdio.h>
337 #include <linux/if_packet.h>
339 int main(void)
341 struct tpacket2_hdr *hdr;
342 int foo[] = {
343 TP_STATUS_AVAILABLE,
344 TP_STATUS_SEND_REQUEST,
345 TP_STATUS_SENDING,
346 TP_STATUS_KERNEL,
347 TP_STATUS_USER,
350 printf("%d\n", hdr->tp_status);
354 $CC -o $TMPDIR/tpacketv2test $TMPDIR/tpacketv2test.c >> config.log 2>&1
355 if [ ! -x $TMPDIR/tpacketv2test ] ; then
356 echo "[NO]"
357 MISSING_DEFS=1
358 tools_remove "netsniff-ng"
359 tools_remove "trafgen"
360 else
361 echo "[YES]"
366 check_ncurses()
368 echo -n "[*] Checking ncurses ... "
370 cat > $TMPDIR/ncursestest.c << EOF
371 #include <curses.h>
373 int main(void)
375 WINDOW *screen = initscr();
379 $CC \
380 $($PKG_CONFIG --cflags ncurses 2>> config.log) \
381 -o $TMPDIR/ncursestest $TMPDIR/ncursestest.c \
382 $($PKG_CONFIG --libs ncurses 2>> config.log \
383 || echo '-lncurses' ) \
384 >> config.log 2>&1
385 if [ ! -x $TMPDIR/ncursestest ] ; then
386 echo "[NO]"
387 MISSING_DEFS=1
388 tools_remove "flowtop"
389 tools_remove "ifpps"
390 else
391 echo "[YES]"
395 check_libgeoip()
397 echo -n "[*] Checking libGeoIP ... "
399 if [ "$DISABLE_GEOIP" == "1" ] ; then
400 echo "[DISABLED]"
401 return
404 cat > $TMPDIR/geoiptest.c << EOF
405 #include <GeoIP.h>
406 #include <GeoIPCity.h>
408 int main(void)
410 int dbs[] = {
411 GEOIP_CITY_EDITION_REV1,
412 GEOIP_CITY_EDITION_REV1_V6,
413 GEOIP_COUNTRY_EDITION,
414 GEOIP_COUNTRY_EDITION_V6,
415 GEOIP_ASNUM_EDITION,
416 GEOIP_ASNUM_EDITION_V6,
418 GeoIP *geoip = GeoIP_new(0);
422 $CC -o $TMPDIR/geoiptest $TMPDIR/geoiptest.c -lGeoIP >> config.log 2>&1
423 if [ ! -x $TMPDIR/geoiptest ] ; then
424 echo "[NO]"
425 MISSING_DEFS=1
426 else
427 echo "[YES]"
428 HAVE_LIBGEOIP=1
432 check_libnf_ct()
434 echo -n "[*] Checking libnetfilter-conntrack ... "
436 cat > $TMPDIR/nfcttest.c << EOF
437 #include <libnetfilter_conntrack/libnetfilter_conntrack.h>
438 #include <libnetfilter_conntrack/libnetfilter_conntrack_tcp.h>
439 #include <libnetfilter_conntrack/libnetfilter_conntrack_dccp.h>
440 #include <libnetfilter_conntrack/libnetfilter_conntrack_sctp.h>
442 int main(void)
444 struct nf_conntrack *ct;
445 const uint32_t id = nfct_get_attr_u32(ct, ATTR_ID);
449 $CC \
450 $($PKG_CONFIG --cflags libnetfilter_conntrack 2>> config.log) \
451 -o $TMPDIR/nfcttest \
452 $TMPDIR/nfcttest.c \
453 $($PKG_CONFIG --libs libnetfilter_conntrack 2>> config.log) \
454 >> config.log 2>&1
455 if [ ! -x $TMPDIR/nfcttest ] ; then
456 echo "[NO]"
457 MISSING_DEFS=1
458 tools_remove "flowtop"
459 else
460 echo "[YES]"
464 check_zlib()
466 echo -n "[*] Checking libz ... "
468 if [ "$DISABLE_ZLIB" == "1" ] ; then
469 echo "[DISABLED]"
470 return
473 cat > $TMPDIR/ztest.c << EOF
474 #include "zlib.h"
476 int main(void)
478 gzFile fp = gzopen("foo.gz", "rb");
482 $CC -o $TMPDIR/ztest $TMPDIR/ztest.c -lz >> config.log 2>&1
483 if [ ! -x $TMPDIR/ztest ] ; then
484 echo "[NO]"
485 echo "CONFIG_LIBZ=0" >> Config
486 MISSING_DEFS=1
487 tools_remove "astraceroute"
488 tools_remove "flowtop"
489 else
490 echo "[YES]"
491 echo "CONFIG_LIBZ=1" >> Config
492 HAVE_LIBZ=1
496 check_urcu()
498 echo -n "[*] Checking liburcu ... "
500 cat > $TMPDIR/urcutest.c << EOF
501 #include <urcu.h>
503 int main(void)
505 rcu_init();
506 synchronize_rcu();
510 $CC -o $TMPDIR/urcutest $TMPDIR/urcutest.c -lurcu >> config.log 2>&1
511 if [ ! -x $TMPDIR/urcutest ] ; then
512 echo "[NO]"
513 MISSING_DEFS=1
514 tools_remove "flowtop"
515 else
516 echo "[YES]"
520 check_libpcap()
522 echo -n "[*] Checking libpcap ... "
524 cat > $TMPDIR/pcaptest.c << EOF
525 #include <pcap.h>
527 int main(void)
529 struct bpf_program bpf;
530 int ret = pcap_compile_nopcap(65535, 1, &bpf, "foo.bpf", 1, 0xffffffff);
534 $CC -o $TMPDIR/pcaptest $TMPDIR/pcaptest.c -lpcap >> config.log 2>&1
535 if [ ! -x $TMPDIR/pcaptest ] ; then
536 echo "[NO]"
537 echo "CONFIG_LIBPCAP=0" >> Config
538 MISSING_DEFS=1
539 tools_remove "mausezahn"
540 else
541 echo "[YES]"
542 echo "CONFIG_LIBPCAP=1" >> Config
543 HAVE_LIBPCAP=1
547 check_hwtstamp()
549 echo -n "[*] Checking hw timestamping ... "
551 cat > $TMPDIR/hwtstest.c << EOF
552 #include <string.h>
553 #include <arpa/inet.h>
554 #include <sys/ioctl.h>
555 #include <sys/types.h>
556 #include <sys/socket.h>
557 #include <linux/sockios.h>
558 #include <linux/net_tstamp.h>
559 #include <linux/if_packet.h>
560 #include <linux/if_ether.h>
561 #include <linux/if.h>
563 int main(void)
565 int timesource = SOF_TIMESTAMPING_RAW_HARDWARE, ret;
566 int sock = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
567 struct hwtstamp_config hwconfig;
568 struct ifreq ifr;
570 memset(&hwconfig, 0, sizeof(hwconfig));
571 hwconfig.tx_type = HWTSTAMP_TX_OFF;
572 hwconfig.rx_filter = HWTSTAMP_FILTER_ALL;
574 memset(&ifr, 0, sizeof(ifr));
575 strncpy(ifr.ifr_name, "lo", sizeof(ifr.ifr_name));
576 ifr.ifr_data = &hwconfig;
578 ioctl(sock, SIOCSHWTSTAMP, &ifr);
579 setsockopt(sock, SOL_PACKET, PACKET_TIMESTAMP, &timesource,
580 sizeof(timesource));
584 $CC -o $TMPDIR/hwtstest $TMPDIR/hwtstest.c >> config.log 2>&1
585 if [ ! -x $TMPDIR/hwtstest ] ; then
586 echo "[NO]"
587 echo "CONFIG_HWTSTAMP=0" >> Config
588 else
589 echo "[YES]"
590 echo "CONFIG_HWTSTAMP=1" >> Config
591 HAVE_HWTSTAMP=1
595 check_libcli()
597 echo -n "[*] Checking libcli ... "
599 cat > $TMPDIR/clitest.c << EOF
600 #include <sys/time.h>
601 #include <libcli.h>
603 int main(void)
605 struct cli_def *cli = cli_init();
609 $CC -o $TMPDIR/clitest $TMPDIR/clitest.c -lcli >> config.log 2>&1
610 if [ ! -x $TMPDIR/clitest ] ; then
611 echo "[NO]"
612 MISSING_DEFS=1
613 tools_remove "mausezahn"
614 else
615 echo "[YES]"
619 check_libnet()
621 echo -n "[*] Checking libnet ... "
623 cat > $TMPDIR/nettest.c << EOF
624 #include <libnet.h>
626 int main(void)
628 char err_buf[LIBNET_ERRBUF_SIZE];
629 libnet_t *l = libnet_init(LIBNET_LINK_ADV, "ethX", err_buf);
633 $CC -o $TMPDIR/nettest $TMPDIR/nettest.c -lnet >> config.log 2>&1
634 if [ ! -x $TMPDIR/nettest ] ; then
635 echo "[NO]"
636 MISSING_DEFS=1
637 tools_remove "mausezahn"
638 else
639 echo "[YES]"
643 gen_version_appendix()
645 local _appendix=""
647 git rev-parse > /dev/null 2>&1
648 if [ "$?" == "0" ] ; then
649 if [ ! "`git describe --always`" == \
650 "`git describe --abbrev=0 --tags`" ] ; then
651 _appendix="+"
655 echo "CONFIG_RC=\"$_appendix\"" >> Config
658 gen_config_hdr()
660 local _version=""
661 local _have_libpcap=""
662 local _have_libgeoip=""
663 local _have_libnl=""
664 local _have_libz=""
665 local _have_hwts=""
666 local _have_tp3=""
668 echo "[*] Generating config.h ..."
670 git rev-parse > /dev/null 2>&1
671 if [ "$?" == "0" ] ; then
672 _version="`git describe --always`"
673 else
674 _version="(none)"
677 if [ "$HAVE_LIBNL" == "1" ] ; then
678 _have_libnl="#define HAVE_LIBNL 1"
679 else
680 _have_libnl="/* HAVE_LIBNL is not defined */"
683 if [ "$HAVE_LIBPCAP" == "1" ] ; then
684 _have_libpcap="#define HAVE_TCPDUMP_LIKE_FILTER 1"
685 else
686 _have_libpcap="/* HAVE_TCPDUMP_LIKE_FILTER is not defined */"
689 if [ "$HAVE_HWTSTAMP" == "1" ] ; then
690 _have_hwts="#define HAVE_HARDWARE_TIMESTAMPING 1"
691 else
692 _have_hwts="/* HAVE_HARDWARE_TIMESTAMPING is not defined */"
695 if [ "$HAVE_LIBGEOIP" == "1" ] ; then
696 _have_libgeoip="#define HAVE_GEOIP 1"
697 else
698 _have_libgeoip="/* HAVE_GEOIP is not defined */"
701 if [ "$HAVE_LIBZ" == "1" ] ; then
702 _have_libz="#define HAVE_LIBZ 1"
703 else
704 _have_libz="/* HAVE_LIBZ is not defined */"
707 if [ "$HAVE_TPACKET3" == "1" ] ; then
708 _have_tp3="#define HAVE_TPACKET3 1"
709 else
710 _have_tp3="/* HAVE_TPACKET3 is not defined */"
713 cat > config.h << EOF
714 #ifndef CONFIG_H
715 #define CONFIG_H
716 #define FILE_CLIENTS ".curvetun/clients"
717 #define FILE_SERVERS ".curvetun/servers"
718 #define FILE_PRIVKEY ".curvetun/priv.key"
719 #define FILE_PUBKEY ".curvetun/pub.key"
720 #define FILE_USERNAM ".curvetun/username"
721 #define GITVERSION "$_version"
722 $_have_libnl
723 $_have_libpcap
724 $_have_libgeoip
725 $_have_libz
726 $_have_hwts
727 $_have_tp3
728 #endif /* CONFIG_H */
732 rm -f config.log
734 echo "# This file is autogenerated by the configure script" > Config
735 check_toolchain
737 if [ "$MISSING_TOOLCHAIN" == "1" ] ; then
738 echo "[!] One or more of the toolchain tools couldn't be found in your"
739 echo " \$PATH. Please check the file config.log for details."
740 exit 1
743 check_flex
744 check_bison
745 check_nacl
746 check_libnl
747 check_libnl_route
748 check_tpacket_v2
749 check_tpacket_v3
750 check_libnf_ct
751 check_ncurses
752 check_libgeoip
753 check_zlib
754 check_urcu
755 check_libpcap
756 check_hwtstamp
757 check_libcli
758 check_libnet
760 gen_config_hdr
761 gen_version_appendix
763 if [ "$MISSING_DEFS" == "1" ] ; then
764 echo "[!] Some libraries or header definitions are missing or too old. Thus"
765 echo " certain tools will not be built (see below). Please refer to the"
766 echo " INSTALL file for the libraries needed to build the complete"
767 echo " netsniff-ng toolkit."
770 if [ "$MISSING_NACL" == "1" ] ; then
771 echo "[!] The NaCl crypto library is currently not present on your system or"
772 echo " could not be found. Either install it from your distro or build it"
773 echo " manually using 'make nacl' and make sure that the NACL_INC_DIR and"
774 echo " NACL_LIB_DIR environment variables are set appropriately."
777 if [ "x$TOOLS_NOBUILD" != "x" ] ; then
778 echo "[!] The following tools will *not* be built: $TOOLS_NOBUILD"
779 echo "[*] The following tools will be built: $TOOLS"
780 else
781 echo "[*] Looks good! All tools will be built!"
784 if [ -s config.log ] ; then
785 echo "[!] There were errors in the configure script. Please check the file"
786 echo " config.log for details."
789 echo "CONFIG_LIBNL=$HAVE_LIBNL" >> Config
791 if [ "$HAVE_LIBGEOIP" == "1" -a "$HAVE_LIBZ" == "1" ] ; then
792 echo "CONFIG_GEOIP=1" >> Config
793 else
794 echo "CONFIG_GEOIP=0" >> Config
797 echo "CONFIG_DEBUG=$ENABLE_DEBUG" >> Config
798 echo "CONFIG_TOOLS=$TOOLS" >> Config
799 echo "CONFIG_OK=1" >> Config
801 exit 0