build: use VERSION_SHORT instead of VERSION_STRING
[netsniff-ng.git] / configure
blob15b2705fc2b77a10cdce18e94848dc7b50db0b62
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 <libcli.h>
468 void main(void)
470 struct cli_def *cli = cli_init();
474 $CC -o $TMPDIR/clitest $TMPDIR/clitest.c -lcli >> config.log 2>&1
475 if [ ! -x $TMPDIR/clitest ] ; then
476 echo "[NO]"
477 MISSING_DEFS=1
478 tools_remove "mausezahn"
479 else
480 echo "[YES]"
484 check_libnet()
486 echo -n "[*] Checking libnet ... "
488 cat > $TMPDIR/nettest.c << EOF
489 #include <libnet.h>
491 void main(void)
493 char err_buf[LIBNET_ERRBUF_SIZE];
494 libnet_t *l = libnet_init(LIBNET_LINK_ADV, "ethX", err_buf);
498 $CC -o $TMPDIR/nettest $TMPDIR/nettest.c -lnet >> config.log 2>&1
499 if [ ! -x $TMPDIR/nettest ] ; then
500 echo "[NO]"
501 MISSING_DEFS=1
502 tools_remove "mausezahn"
503 else
504 echo "[YES]"
508 gen_version_appendix()
510 local _appendix=""
512 git rev-parse > /dev/null 2>&1
513 if [ "$?" == "0" ] ; then
514 if [ ! "`git describe --always`" == \
515 "`git describe --abbrev=0 --tags`" ] ; then
516 _appendix="+"
520 echo "CONFIG_RC=\"$_appendix\"" >> Config
523 gen_config_hdr()
525 local _version=""
526 local _have_libpcap=""
527 local _have_libgeoip=""
528 local _have_libz=""
529 local _have_hwts=""
531 echo "[*] Generating config.h ... "
533 git rev-parse > /dev/null 2>&1
534 if [ "$?" == "0" ] ; then
535 _version="`git describe --always`"
536 else
537 _version="(none)"
540 if [ "$HAVE_LIBPCAP" == "1" ] ; then
541 _have_libpcap="#define HAVE_TCPDUMP_LIKE_FILTER 1"
544 if [ "$HAVE_HWTSTAMP" == "1" ] ; then
545 _have_hwts="#define HAVE_HARDWARE_TIMESTAMPING 1"
548 if [ "$HAVE_LIBGEOIP" == "1" ] ; then
549 _have_libgeoip="#define HAVE_GEOIP 1"
552 if [ "$HAVE_LIBZ" == "1" ] ; then
553 _have_libz="#define HAVE_LIBZ 1"
556 cat > config.h << EOF
557 #ifndef CONFIG_H
558 #define CONFIG_H
559 #define FILE_CLIENTS ".curvetun/clients"
560 #define FILE_SERVERS ".curvetun/servers"
561 #define FILE_PRIVKEY ".curvetun/priv.key"
562 #define FILE_PUBKEY ".curvetun/pub.key"
563 #define FILE_USERNAM ".curvetun/username"
564 #define GITVERSION "$_version"
565 $_have_libpcap
566 $_have_libgeoip
567 $_have_libz
568 $_have_hwts
569 #endif /* CONFIG_H */
573 rm -f config.log
575 echo "# This file is autogenerated by the configure script" > Config
576 check_pkg_config
578 if [ "$MISSING_PKG_CONFIG" == "1" ] ; then
579 echo "[!] pkg-config is not installed on your system or not in the PATH"
580 exit 1
583 check_ccache
584 check_flex
585 check_bison
586 check_nacl
587 check_libnl
588 check_tpacket_v2
589 check_tpacket_v3
590 check_libnf_ct
591 check_ncurses
592 check_libgeoip
593 check_zlib
594 check_urcu
595 check_libpcap
596 check_hwtstamp
597 check_libcli
598 check_libnet
600 gen_config_hdr
601 gen_version_appendix
603 if [ "$MISSING_DEFS" == "1" ] ; then
604 echo "[!] Some libraries or header definitions are missing or too old."
605 echo " Thus certain tools will not be built (see below). Please"
606 echo " refer to the INSTALL file for the libraries needed to build"
607 echo " the complete netsniff-ng toolkit."
610 if [ "$MISSING_NACL" == "1" ] ; then
611 echo "[!] The NaCl crypto library is currently not present on your"
612 echo " system or could not be found. Either install it from your"
613 echo " distro or build it manually using 'make nacl' and make sure"
614 echo " that the NACL_INC_DIR and NACL_LIB_DIR variables are set"
615 echo " appropriately."
618 if [ "x$TOOLS_NOBUILD" != "x" ] ; then
619 echo "[!] The following tools will *not* be built: $TOOLS_NOBUILD"
620 echo "[*] The following tools will be built: $TOOLS"
621 else
622 echo "[*] Looks good! All tools will be built!"
625 if [ -s config.log ] ; then
626 echo "[!] There were errors in the configure script. Please see"
627 echo " the file config.log for details."
630 if [ "$HAVE_LIBGEOIP" == "1" -a "$HAVE_LIBZ" == "1" ] ; then
631 echo "CONFIG_GEOIP=1" >> Config
632 else
633 echo "CONFIG_GEOIP=0" >> Config
636 echo "CONFIG_TOOLS=$TOOLS" >> Config
637 echo "CONFIG_OK=1" >> Config
639 exit 0