1 dnl Fwknop AutoConf script...
2 dnl =========================
4 dnl Created by Damien Stuart
6 dnl Inspiration from RRDtool configure.ac, the AutoConf Archive
7 dnl (http://www.nongnu.org/autoconf-archive/), and other examples.
9 dnl Minimum Autoconf version required.
12 dnl Define our name, version and email.
13 m4_define(my_package, [fwknop])
14 m4_define(my_version, [2.0rc5])
15 m4_define(my_bug_email, [dstuart@dstuart.org])
17 AC_INIT(my_package, my_version, my_bug_email)
19 AC_CONFIG_AUX_DIR(config)
23 AM_INIT_AUTOMAKE([tar-ustar -Wall -Werror foreign])
25 dnl AM_MAINTAINER_MODE
27 AC_CONFIG_HEADERS([config.h])
29 dnl The top of our header
32 #ifndef FWKNOP_CONFIG_H
33 #define FWKNOP_CONFIG_H
36 dnl The bottom of our header file
39 #endif /* FWKNOP_CONFIG_H */
42 dnl Decide whether or not to build the client
45 AC_ARG_ENABLE([client],
46 [AS_HELP_STRING([--disable-client],
47 [Do not build the fwknop client @<:@default is to build@:>@])],
48 [want_client=$enableval],
50 AM_CONDITIONAL([WANT_CLIENT], [test "$want_client" = yes])
52 dnl Decide whether or not to build the server
55 AC_ARG_ENABLE([server],
56 [AS_HELP_STRING([--disable-server],
57 [Do not build the fwknop server @<:@default is to build@:>@])],
58 [want_server=$enableval],
60 AM_CONDITIONAL([WANT_SERVER], [test "$want_server" = yes])
62 dnl Decide whether or not to enable the digest-cache
65 AC_ARG_ENABLE([digest-cache],
66 [AS_HELP_STRING([--disable-digest-cache],
67 [Do not enable the fwknopd digest-cache @<:@default is to build@:>@])],
68 [want_digest_cache=$enableval],
70 dnl AM_CONDITIONAL([WANT_DIGEST_CACHE], [test "$want_digest_cache" = yes])
72 dnl Decide whether or not to try to look for gdbm/ndbm (default to just
73 dnl use a file-based solution - reduces dependencies)
76 AC_ARG_ENABLE([file-cache],
77 [AS_HELP_STRING([--disable-file-cache],
78 [Replace file cache with gdbm/ndbm @<:@default on@:>@])],
79 [want_file_cache=$enableval],
81 AS_IF([test "$want_file_cache" = yes], [
82 AC_DEFINE([USE_FILE_CACHE], [1], [Define this to enable non-gdbm/ndbm digest storing (eliminates gdbm/ndbm dependency).])
85 dnl Decide whether or not to enable all warnings with -Wall
89 [AS_HELP_STRING([--disable-wall],
90 [Do not enable all warnings via -Wall @<:@default is on@:>@])],
91 [use_wall=$enableval],
95 dnl Decide whether or not to enable -fstack-protector
97 use_stack_protector=yes
98 AC_ARG_ENABLE([stack-protector],
99 [AS_HELP_STRING([--disable-stack-protector],
100 [Do not enable -fstack-protector @<:@default is on@:>@])],
101 [use_stack_protector=$enableval],
104 dnl Decide whether or not to enable Position Independent Executable (PIE)
109 [AS_HELP_STRING([--disable-pie],
110 [Do not enable Position Independent Executable support @<:@default is on@:>@])],
111 [use_pie=$enableval],
114 dnl Decide whether or not to enable -D_FORTIFY_SOURCE support
116 use_fortify_source=yes
117 AC_ARG_ENABLE([fortify-source],
118 [AS_HELP_STRING([--disable-fortify-source],
119 [Do not enable -D_FORTIFY_SOURCE support @<:@default is on@:>@])],
120 [use_fortify_source=$enableval],
123 dnl Decide whether or not to use read-only relocations protection
125 use_ro_relocations=yes
126 AC_ARG_ENABLE([ro-relocations],
127 [AS_HELP_STRING([--disable-ro-relocations],
128 [Do not enable read-only relocations protection @<:@default is on@:>@])],
129 [use_ro_relocations=$enableval],
132 dnl Decide whether or not to use immediate binding protection
134 use_immediate_binding=yes
135 AC_ARG_ENABLE([immediate-binding],
136 [AS_HELP_STRING([--disable-immediate-binding],
137 [Do not enable immediate binding protection @<:@default is on@:>@])],
138 [use_immediate_binding=$enableval],
159 AC_DEFINE_UNQUOTED([PLATFORM_OPENBSD], [1], [Define if you are running on OpenBSD])
163 # Checks for header files.
169 AC_CHECK_HEADERS([arpa/inet.h ctype.h endian.h errno.h locale.h netdb.h net/ethernet.h netinet/in.h stdint.h stdlib.h string.h strings.h sys/byteorder.h sys/endian.h sys/ethernet.h sys/socket.h sys/stat.h sys/time.h sys/wait.h termios.h time.h unistd.h])
187 AC_CHECK_SIZEOF(unsigned int)
188 dnl AC_CHECK_TYPES([uint8_t, uint32_t])
194 # Checks for library functions.
200 AC_CHECK_FUNCS([bzero gettimeofday memmove memset socket strchr strcspn strdup strncasecmp strndup strrchr strspn])
202 AC_SEARCH_LIBS([socket], [socket])
203 AC_SEARCH_LIBS([inet_addr], [nsl])
207 if test "x$use_wall" = "xyes"; then
209 AC_MSG_CHECKING(if $CC supports $t)
210 saved_CFLAGS="$CFLAGS"
211 saved_LDFLAGS="$LDFLAGS"
212 CFLAGS="$CFLAGS $t -Werror"
213 LDFLAGS="$LDFLAGS $t -Werror"
217 int main(void){char x[[256]]; snprintf(x, sizeof(x), "NNN"); return 0;}
220 CFLAGS="$saved_CFLAGS $t"
221 LDFLAGS="$saved_LDFLAGS $t"
222 AC_MSG_CHECKING(if $t works)
226 int main(void){char x[[256]]; snprintf(x, sizeof(x), "NNN"); return 0;}
230 [ AC_MSG_RESULT(no) ],
231 [ AC_MSG_WARN([cross compiling: cannot test])
235 [ AC_MSG_RESULT(no) ]
237 CFLAGS="$saved_CFLAGS"
238 LDFLAGS="$saved_LDFLAGS"
242 # Check for security features offered by the compiler
245 # Adapted from OpenSSH:
246 # -fstack-protector-all doesn't always work for some GCC versions
247 # and/or platforms, so we test if we can. If it's not supported
248 # on a given platform gcc will emit a warning so we use -Werror.
249 if test "x$use_stack_protector" = "xyes"; then
250 for t in -fstack-protector-all -fstack-protector; do
251 AC_MSG_CHECKING(if $CC supports $t)
252 saved_CFLAGS="$CFLAGS"
253 saved_LDFLAGS="$LDFLAGS"
254 CFLAGS="$CFLAGS $t -Werror"
255 LDFLAGS="$LDFLAGS $t -Werror"
259 int main(void){char x[[256]]; snprintf(x, sizeof(x), "NNN"); return 0;}
262 CFLAGS="$saved_CFLAGS $t"
263 LDFLAGS="$saved_LDFLAGS $t"
264 AC_MSG_CHECKING(if $t works)
268 int main(void){char x[[256]]; snprintf(x, sizeof(x), "NNN"); return 0;}
272 [ AC_MSG_RESULT(no) ],
273 [ AC_MSG_WARN([cross compiling: cannot test])
277 [ AC_MSG_RESULT(no) ]
279 CFLAGS="$saved_CFLAGS"
280 LDFLAGS="$saved_LDFLAGS"
284 if test "x$use_pie" = "xyes"; then
285 for t in "-fPIE -pie"; do
286 AC_MSG_CHECKING(if $CC supports $t)
287 saved_CFLAGS="$CFLAGS"
288 saved_LDFLAGS="$LDFLAGS"
289 CFLAGS="$CFLAGS $t -Werror"
290 LDFLAGS="$LDFLAGS $t -Werror"
294 int main(void){char x[[256]]; snprintf(x, sizeof(x), "NNN"); return 0;}
297 CFLAGS="$saved_CFLAGS $t"
298 LDFLAGS="$saved_LDFLAGS $t"
299 AC_MSG_CHECKING(if $t works)
303 int main(void){char x[[256]]; snprintf(x, sizeof(x), "NNN"); return 0;}
307 [ AC_MSG_RESULT(no) ],
308 [ AC_MSG_WARN([cross compiling: cannot test])
312 [ AC_MSG_RESULT(no) ]
314 CFLAGS="$saved_CFLAGS"
315 LDFLAGS="$saved_LDFLAGS"
319 if test "x$use_fortify_source" = "xyes"; then
320 for t in "-D_FORTIFY_SOURCE=2"; do
321 AC_MSG_CHECKING(if $CC supports $t)
322 saved_CFLAGS="$CFLAGS"
323 saved_LDFLAGS="$LDFLAGS"
324 CFLAGS="$CFLAGS $t -Werror"
325 LDFLAGS="$LDFLAGS $t -Werror"
329 int main(void){char x[[256]]; snprintf(x, sizeof(x), "NNN"); return 0;}
332 CFLAGS="$saved_CFLAGS $t"
333 LDFLAGS="$saved_LDFLAGS $t"
334 AC_MSG_CHECKING(if $t works)
338 int main(void){char x[[256]]; snprintf(x, sizeof(x), "NNN"); return 0;}
342 [ AC_MSG_RESULT(no) ],
343 [ AC_MSG_WARN([cross compiling: cannot test])
347 [ AC_MSG_RESULT(no) ]
349 CFLAGS="$saved_CFLAGS"
350 LDFLAGS="$saved_LDFLAGS"
354 if test "x$use_ro_relocations" = "xyes"; then
355 for t in "-Wl,-z,relro"; do
356 AC_MSG_CHECKING(if $CC supports $t)
357 saved_LDFLAGS="$LDFLAGS"
358 LDFLAGS="$LDFLAGS $t -Werror"
362 int main(void){char x[[256]]; snprintf(x, sizeof(x), "NNN"); return 0;}
365 LDFLAGS="$saved_LDFLAGS $t"
366 AC_MSG_CHECKING(if $t works)
370 int main(void){char x[[256]]; snprintf(x, sizeof(x), "NNN"); return 0;}
374 [ AC_MSG_RESULT(no) ],
375 [ AC_MSG_WARN([cross compiling: cannot test])
379 [ AC_MSG_RESULT(no) ]
381 LDFLAGS="$saved_LDFLAGS"
385 if test "x$use_immediate_binding" = "xyes"; then
386 for t in "-Wl,-z,now"; do
387 AC_MSG_CHECKING(if $CC supports $t)
388 saved_LDFLAGS="$LDFLAGS"
389 LDFLAGS="$LDFLAGS $t -Werror"
393 int main(void){char x[[256]]; snprintf(x, sizeof(x), "NNN"); return 0;}
396 LDFLAGS="$saved_LDFLAGS $t"
397 AC_MSG_CHECKING(if $t works)
401 int main(void){char x[[256]]; snprintf(x, sizeof(x), "NNN"); return 0;}
405 [ AC_MSG_RESULT(no) ],
406 [ AC_MSG_WARN([cross compiling: cannot test])
410 [ AC_MSG_RESULT(no) ]
412 LDFLAGS="$saved_LDFLAGS"
416 # Check for 3rd-party libs
419 [AS_HELP_STRING([--with-gpgme],
420 [support for gpg encryption using libgpgme @<:@default=check@:>@])],
425 AS_IF([test "x$with_gpgme" != xno],
427 [AC_DEFINE([HAVE_LIBGPGME], [1], [Define if you have libgpgme])],
428 [if test "x$with_gpgme" != xcheck; then
430 [--with-gpgme was given, but test for gpgme failed])
434 ], [have_gpgme=no])], [have_gpgme=no])
436 dnl Add various common way to sbin dir to the path (just in case)
437 APP_PATH=$PATH$PATH_SEPARATOR/sbin$PATH_SEPARATOR/usr/sbin$PATH_SEPARATOR/usr/local/sbin
439 dnl Check for gpg (not gpg2)
442 [AS_HELP_STRING([--with-gpg=/path/to/gpg],
443 [Specify path to the gpg executable that gpgme will use @<:@default=check path@:>@])],
445 AS_IF([ test "x$withval" = x -o "x$withval" = xyes -o "x$withval" = xno ],
446 [AC_MSG_ERROR([--with-gpg requires an argument specifying a path to gpg])],
451 AC_PATH_PROG(GPG_EXE, [gpg], [], [$APP_PATH])
454 AS_IF([test "x$GPG_EXE" != x],
456 AC_DEFINE_UNQUOTED([GPG_EXE], ["$GPG_EXE"], [Path to gpg executable])
458 ], [ gpg_exe="(not found)"]
461 if [test "$have_gpgme" = "yes" ]; then
466 if [ test "x$CPPFLAGS" = "x" ] ; then
467 CPPFLAGS="-I/usr/local/include -I/usr/local/include/gpgme"
469 if [ test "x$LDFLAGS" = "x" ] ; then
470 LDFLAGS="-L/usr/local/lib"
476 dnl Check for libpcap, gdbm (or ndbm) if we are building the server component
478 AS_IF([test "$want_server" = yes], [
479 # Looking for libpcap
481 AC_CHECK_LIB([pcap],[pcap_open_live],
482 [ AC_DEFINE([HAVE_LIBPCAP], [1], [Define if you have libpcap]) ],
483 [ AC_MSG_ERROR([fwknopd needs libpcap])]
486 AS_IF([test "$want_digest_cache" = yes], [
488 have_digest_cache=yes
490 AS_IF([test "$want_file_cache" = no], [
492 # Looking for gdbm or fallback to ndbm or bail
494 AC_CHECK_LIB([gdbm],[gdbm_open],
496 AC_DEFINE([HAVE_LIBGDBM], [1], [Define if you have libgdbm])
498 [ AC_CHECK_LIB([ndbm],[dbm_open],
500 AC_DEFINE([HAVE_LIBNDBM], [1], [Define if you have libndbm])
503 [ AC_CHECK_HEADER([ndbm.h],
504 [ AC_CHECK_FUNC([dbm_open],
505 [ AC_DEFINE([HAVE_LIBNDBM], [1], [Define if you have libndbm])],
507 AC_DEFINE([NO_DIGEST_CACHE], [1], [Define this to disable the digest cache for replay detection - not recommended.])
508 AC_MSG_WARN([No DBM implementation found. Replay detection will be disabled.])
517 AC_DEFINE([NO_DIGEST_CACHE], [1], [Define this to disable the digest cache for replay detection - not recommended.])
522 AM_CONDITIONAL([USE_NDBM], [test x$use_ndbm = xyes])
523 AM_CONDITIONAL([CONFIG_FILE_CACHE], [test x$want_file_cache = xyes])
525 dnl Check for iptables
527 AC_ARG_WITH([iptables],
528 [AS_HELP_STRING([--with-iptables=/path/to/iptables],
529 [Specify path to the iptables executable @<:@default=check path@:>@])],
531 AS_IF([ test "x$withval" = xno ], [],
532 AS_IF([ test "x$withval" = x -o "x$withval" = xyes ],
533 [AC_MSG_ERROR([--with-iptables requires an argument specifying a path to iptables])],
534 [ IPTABLES_EXE=$withval ]
539 AC_PATH_PROG(IPTABLES_EXE, [iptables], [], [$APP_PATH])
546 [AS_HELP_STRING([--with-ipfw=/path/to/ipfw],
547 [Specify path to the ipfw executable @<:@default=check path@:>@])],
549 AS_IF([ test "x$withval" = xno ], [],
550 AS_IF([ test "x$withval" = x -o "x$withval" = xyes ],
551 [AC_MSG_ERROR([--with-ipfw requires an argument specifying a path to ipfw])],
552 [ IPFW_EXE=$withval ]
557 AC_PATH_PROG(IPFW_EXE, [ipfw], [], [$APP_PATH])
561 dnl Check for pf from OpenBSD
564 [AS_HELP_STRING([--with-pf=/path/to/pfctl],
565 [Specify path to the pf executable @<:@default=check path@:>@])],
567 AS_IF([ test "x$withval" = xno ], [],
568 AS_IF([ test "x$withval" = x -o "x$withval" = xyes ],
569 [AC_MSG_ERROR([--with-pf requires an argument specifying a path to pf])],
575 AC_PATH_PROG(PF_EXE, [pfctl], [], [$APP_PATH])
579 dnl Check for ipf (ipfilter)
582 [AS_HELP_STRING([--with-ipf=/path/to/ipf],
583 [Specify path to the ipf executable @<:@default=check path@:>@])],
585 AS_IF([ test "x$withval" = xno ], [],
586 AS_IF([ test "x$withval" = x -o "x$withval" = xyes ],
587 [AC_MSG_ERROR([--with-ipf requires an argument specifying a path to ipf])],
593 AC_PATH_PROG(IPF_EXE, [ipf], [], [$APP_PATH])
597 dnl Determine which firewall exe we use (if we have one).
598 dnl If iptables was found or specified, it wins, then we fallback to ipfw,
599 dnl then pf, and otherwise we try ipf.
601 AS_IF([test "x$IPTABLES_EXE" != x], [
603 FIREWALL_TYPE="iptables"
604 FIREWALL_EXE=$IPTABLES_EXE
605 AC_DEFINE_UNQUOTED([FIREWALL_IPTABLES], [1], [The firewall type: iptables.])
607 AS_IF([test "x$IPFW_EXE" != x], [
610 FIREWALL_EXE=$IPFW_EXE
611 AC_DEFINE_UNQUOTED([FIREWALL_IPFW], [1], [The firewall type: ipfw.])
613 AS_IF([test "x$PF_EXE" != x], [
617 AC_DEFINE_UNQUOTED([FIREWALL_PF], [1], [The firewall type: pf.])
619 AS_IF([test "x$IPF_EXE" != x], [
620 AC_MSG_ERROR([Sorry - ipf was specified or the only one found, however, it is not supported yet.])
622 FIREWALL_EXE=$IPF_EXE
623 AC_DEFINE_UNQUOTED([FIREWALL_IPF], [1], [The firewall type: ipf.])
624 ], [AC_MSG_ERROR([No firewall program was found or specified.]) ]
630 AC_DEFINE_UNQUOTED([FIREWALL_EXE], ["$FIREWALL_EXE"],
631 [Path to firewall command executable (it should match the firewall type).])
634 [test "$want_server" = no], [
636 AM_CONDITIONAL([USE_NDBM], [test x$use_ndbm = xno])
637 AM_CONDITIONAL([CONFIG_FILE_CACHE], [test x$use_ndbm = xno])
641 AC_CONFIG_FILES([Makefile
650 if [test "$have_gpgme" = "yes" ]; then
651 have_gpgme="$have_gpgme
652 Gpgme engine: $GPG_EXE"
656 $PACKAGE_NAME-$PACKAGE_VERSION configuration.
657 ==========================================================
658 Client build: $want_client
659 Server build: $want_server
660 GPG encryption support: $have_gpgme
662 Installation prefix: $prefix
664 if [test "$want_server" = "yes" ]; then
665 echo " Server support:
666 firewall type: $FIREWALL_TYPE
667 firewall program path: $FIREWALL_EXE
670 if [test "$want_digest_cache" = "no" ]; then
672 The digest-cache functionality is not enabled. This
673 could leave the fwknopd server open to replay attacks!