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.0.2-pre3])
15 m4_define(my_bug_email, [dstuart@dstuart.org])
17 AC_INIT(my_package, my_version, my_bug_email)
19 AC_CONFIG_MACRO_DIR([m4])
20 AC_CONFIG_AUX_DIR(config)
24 AM_INIT_AUTOMAKE([tar-ustar -Wall -Werror foreign])
26 dnl AM_MAINTAINER_MODE
28 AC_CONFIG_HEADERS([config.h])
30 dnl The top of our header
33 #ifndef FWKNOP_CONFIG_H
34 #define FWKNOP_CONFIG_H
37 dnl The bottom of our header file
40 #endif /* FWKNOP_CONFIG_H */
43 dnl FKO_CHECK_COMPILER_ARG([COMPILER FLAG])
45 dnl Macro to check compiler support for the given compiler option.
46 dnl Adds to CFLAGS and LDFLAGS if supported.
48 dnl The structure of this macro was adapted from OpenSSH.
50 AC_DEFUN([FKO_CHECK_COMPILER_ARG], [
51 saved_CFLAGS="$CFLAGS"
52 saved_LDFLAGS="$LDFLAGS"
53 CFLAGS="$CFLAGS $1 -Werror"
54 LDFLAGS="$LDFLAGS $1 -Werror"
55 AC_MSG_CHECKING([if $CC supports $1])
59 int main(void){char x[[256]]; snprintf(x, sizeof(x), "NNN"); return 0;}
62 CFLAGS="$saved_CFLAGS $1"
63 LDFLAGS="$saved_LDFLAGS $1"
67 int main(void){char x[[256]]; snprintf(x, sizeof(x), "NNN"); return 0;}
71 CFLAGS="$saved_CFLAGS"
72 LDFLAGS="$saved_LDFLAGS"],
73 [AC_MSG_WARN([cross compiling: cannot test])])
76 CFLAGS="$saved_CFLAGS"
77 LDFLAGS="$saved_LDFLAGS"]
80 dnl FKO_CHECK_COMPILER_ARG_LDFLAGS_ONLY([COMPILER FLAG])
82 dnl Macro to check compiler support for the given compiler option.
83 dnl Adds to LDFLAGS only if supported.
85 AC_DEFUN([FKO_CHECK_COMPILER_ARG_LDFLAGS_ONLY], [
86 saved_LDFLAGS="$LDFLAGS"
87 LDFLAGS="$LDFLAGS $1 -Werror"
88 AC_MSG_CHECKING([if $CC supports $1])
92 int main(void){char x[[256]]; snprintf(x, sizeof(x), "NNN"); return 0;}
95 LDFLAGS="$saved_LDFLAGS $1"
99 int main(void){char x[[256]]; snprintf(x, sizeof(x), "NNN"); return 0;}
101 [AC_MSG_RESULT(yes)],
103 LDFLAGS="$saved_LDFLAGS"],
104 [AC_MSG_WARN([cross compiling: cannot test])])
107 LDFLAGS="$saved_LDFLAGS"]
123 dnl Decide whether or not to enable all warnings with -Wall
126 AC_ARG_ENABLE([wall],
127 [AS_HELP_STRING([--disable-wall],
128 [Do not enable all warnings via -Wall @<:@default is on@:>@])],
129 [use_wall=$enableval],
132 if test "x$use_wall" = "xyes"; then
133 FKO_CHECK_COMPILER_ARG([-Wall])
136 dnl Check for security features offered by the compiler
138 dnl -fstack-protector-all doesn't always work for some GCC versions
139 dnl and/or platforms, so we test if we can. If it's not supported
140 dnl on a given platform gcc will emit a warning so we use -Werror.
142 dnl Decide whether or not to enable -fstack-protector
144 use_stack_protector=yes
145 AC_ARG_ENABLE([stack-protector],
146 [AS_HELP_STRING([--disable-stack-protector],
147 [Do not enable -fstack-protector @<:@default is on@:>@])],
148 [use_stack_protector=$enableval],
151 if test "x$use_stack_protector" = "xyes"; then
152 FKO_CHECK_COMPILER_ARG([-fstack-protector-all -fstack-protector])
155 dnl Decide whether or not to enable Position Independent Executable (PIE)
160 [AS_HELP_STRING([--disable-pie],
161 [Do not enable Position Independent Executable support @<:@default is on@:>@])],
162 [use_pie=$enableval],
165 if test "x$use_pie" = "xyes"; then
166 FKO_CHECK_COMPILER_ARG([-fPIE -pie])
169 dnl Decide whether or not to enable -D_FORTIFY_SOURCE support
171 use_fortify_source=yes
172 AC_ARG_ENABLE([fortify-source],
173 [AS_HELP_STRING([--disable-fortify-source],
174 [Do not enable -D_FORTIFY_SOURCE support @<:@default is on@:>@])],
175 [use_fortify_source=$enableval],
178 if test "x$use_fortify_source" = "xyes"; then
179 FKO_CHECK_COMPILER_ARG([-D_FORTIFY_SOURCE=2])
182 dnl Decide whether or not to use read-only relocations protection
184 use_ro_relocations=yes
185 AC_ARG_ENABLE([ro-relocations],
186 [AS_HELP_STRING([--disable-ro-relocations],
187 [Do not enable read-only relocations protection @<:@default is on@:>@])],
188 [use_ro_relocations=$enableval],
191 if test "x$use_ro_relocations" = "xyes"; then
192 FKO_CHECK_COMPILER_ARG_LDFLAGS_ONLY([-Wl,-z,relro])
195 dnl Decide whether or not to use immediate binding protection
197 use_immediate_binding=yes
198 AC_ARG_ENABLE([immediate-binding],
199 [AS_HELP_STRING([--disable-immediate-binding],
200 [Do not enable immediate binding protection @<:@default is on@:>@])],
201 [use_immediate_binding=$enableval],
204 if test "x$use_immediate_binding" = "xyes"; then
205 FKO_CHECK_COMPILER_ARG_LDFLAGS_ONLY([-Wl,-z,now])
208 # Checks for header files.
214 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])
232 AC_CHECK_SIZEOF(unsigned int)
233 dnl AC_CHECK_TYPES([uint8_t, uint32_t])
239 # Checks for library functions.
245 AC_CHECK_FUNCS([bzero gettimeofday memmove memset socket strchr strcspn strdup strncasecmp strndup strrchr strspn])
247 AC_SEARCH_LIBS([socket], [socket])
248 AC_SEARCH_LIBS([inet_addr], [nsl])
254 AC_DEFINE_UNQUOTED([PLATFORM_OPENBSD], [1], [Define if you are running on OpenBSD])
258 dnl Decide whether or not to build the client
261 AC_ARG_ENABLE([client],
262 [AS_HELP_STRING([--disable-client],
263 [Do not build the fwknop client @<:@default is to build@:>@])],
264 [want_client=$enableval],
266 AM_CONDITIONAL([WANT_CLIENT], [test "$want_client" = yes])
268 dnl Decide whether or not to build the server
271 AC_ARG_ENABLE([server],
272 [AS_HELP_STRING([--disable-server],
273 [Do not build the fwknop server @<:@default is to build@:>@])],
274 [want_server=$enableval],
276 AM_CONDITIONAL([WANT_SERVER], [test "$want_server" = yes])
278 dnl Decide whether or not to enable the digest-cache
280 want_digest_cache=yes
281 AC_ARG_ENABLE([digest-cache],
282 [AS_HELP_STRING([--disable-digest-cache],
283 [Do not enable the fwknopd digest-cache @<:@default is to build@:>@])],
284 [want_digest_cache=$enableval],
286 dnl AM_CONDITIONAL([WANT_DIGEST_CACHE], [test "$want_digest_cache" = yes])
288 dnl Decide whether or not to try to look for gdbm/ndbm (default to just
289 dnl use a file-based solution - reduces dependencies)
292 AC_ARG_ENABLE([file-cache],
293 [AS_HELP_STRING([--disable-file-cache],
294 [Replace file cache with gdbm/ndbm @<:@default on@:>@])],
295 [want_file_cache=$enableval],
297 AS_IF([test "$want_file_cache" = yes], [
298 AC_DEFINE([USE_FILE_CACHE], [1], [Define this to enable non-gdbm/ndbm digest storing (eliminates gdbm/ndbm dependency).])
301 # Check for 3rd-party libs
304 [AS_HELP_STRING([--with-gpgme],
305 [support for gpg encryption using libgpgme @<:@default=check@:>@])],
310 AS_IF([test "x$with_gpgme" != xno],
312 [AC_DEFINE([HAVE_LIBGPGME], [1], [Define if you have libgpgme])],
313 [if test "x$with_gpgme" != xcheck; then
315 [--with-gpgme was given, but test for gpgme failed])
319 ], [have_gpgme=no])], [have_gpgme=no])
321 dnl Add various common way to sbin dir to the path (just in case)
322 APP_PATH=$PATH$PATH_SEPARATOR/sbin$PATH_SEPARATOR/usr/sbin$PATH_SEPARATOR/usr/local/sbin
324 dnl Check for gpg (not gpg2)
327 [AS_HELP_STRING([--with-gpg=/path/to/gpg],
328 [Specify path to the gpg executable that gpgme will use @<:@default=check path@:>@])],
330 AS_IF([ test "x$withval" = x -o "x$withval" = xyes -o "x$withval" = xno ],
331 [AC_MSG_ERROR([--with-gpg requires an argument specifying a path to gpg])],
336 AC_PATH_PROG(GPG_EXE, [gpg], [], [$APP_PATH])
339 AS_IF([test "x$GPG_EXE" != x],
341 AC_DEFINE_UNQUOTED([GPG_EXE], ["$GPG_EXE"], [Path to gpg executable])
343 ], [ gpg_exe="(not found)"]
346 if [test "$have_gpgme" = "yes" ]; then
351 if [ test "x$CPPFLAGS" = "x" ] ; then
352 CPPFLAGS="-I/usr/local/include -I/usr/local/include/gpgme"
354 if [ test "x$LDFLAGS" = "x" ] ; then
355 LDFLAGS="-L/usr/local/lib"
361 dnl Check for libpcap, gdbm (or ndbm) if we are building the server component
363 AS_IF([test "$want_server" = yes], [
364 # Looking for libpcap
366 AC_CHECK_LIB([pcap],[pcap_open_live],
367 [ AC_DEFINE([HAVE_LIBPCAP], [1], [Define if you have libpcap]) ],
368 [ AC_MSG_ERROR([fwknopd needs libpcap])]
371 AS_IF([test "$want_digest_cache" = yes], [
373 have_digest_cache=yes
375 AS_IF([test "$want_file_cache" = no], [
377 # Looking for gdbm or fallback to ndbm or bail
379 AC_CHECK_LIB([gdbm],[gdbm_open],
381 AC_DEFINE([HAVE_LIBGDBM], [1], [Define if you have libgdbm])
383 [ AC_CHECK_LIB([ndbm],[dbm_open],
385 AC_DEFINE([HAVE_LIBNDBM], [1], [Define if you have libndbm])
388 [ AC_CHECK_HEADER([ndbm.h],
389 [ AC_CHECK_FUNC([dbm_open],
390 [ AC_DEFINE([HAVE_LIBNDBM], [1], [Define if you have libndbm])],
392 AC_DEFINE([NO_DIGEST_CACHE], [1], [Define this to disable the digest cache for replay detection - not recommended.])
393 AC_MSG_WARN([No DBM implementation found. Replay detection will be disabled.])
402 AC_DEFINE([NO_DIGEST_CACHE], [1], [Define this to disable the digest cache for replay detection - not recommended.])
407 AM_CONDITIONAL([USE_NDBM], [test x$use_ndbm = xyes])
408 AM_CONDITIONAL([CONFIG_FILE_CACHE], [test x$want_file_cache = xyes])
410 dnl Check for iptables
412 AC_ARG_WITH([iptables],
413 [AS_HELP_STRING([--with-iptables=/path/to/iptables],
414 [Specify path to the iptables executable @<:@default=check path@:>@])],
416 AS_IF([ test "x$withval" = xno ], [],
417 AS_IF([ test "x$withval" = x -o "x$withval" = xyes ],
418 [AC_MSG_ERROR([--with-iptables requires an argument specifying a path to iptables])],
419 [ IPTABLES_EXE=$withval ]
424 AC_PATH_PROG(IPTABLES_EXE, [iptables], [], [$APP_PATH])
431 [AS_HELP_STRING([--with-ipfw=/path/to/ipfw],
432 [Specify path to the ipfw executable @<:@default=check path@:>@])],
434 AS_IF([ test "x$withval" = xno ], [],
435 AS_IF([ test "x$withval" = x -o "x$withval" = xyes ],
436 [AC_MSG_ERROR([--with-ipfw requires an argument specifying a path to ipfw])],
437 [ IPFW_EXE=$withval ]
442 AC_PATH_PROG(IPFW_EXE, [ipfw], [], [$APP_PATH])
446 dnl Check for pf from OpenBSD
449 [AS_HELP_STRING([--with-pf=/path/to/pfctl],
450 [Specify path to the pf executable @<:@default=check path@:>@])],
452 AS_IF([ test "x$withval" = xno ], [],
453 AS_IF([ test "x$withval" = x -o "x$withval" = xyes ],
454 [AC_MSG_ERROR([--with-pf requires an argument specifying a path to pf])],
460 AC_PATH_PROG(PF_EXE, [pfctl], [], [$APP_PATH])
464 dnl Check for ipf (ipfilter)
467 [AS_HELP_STRING([--with-ipf=/path/to/ipf],
468 [Specify path to the ipf executable @<:@default=check path@:>@])],
470 AS_IF([ test "x$withval" = xno ], [],
471 AS_IF([ test "x$withval" = x -o "x$withval" = xyes ],
472 [AC_MSG_ERROR([--with-ipf requires an argument specifying a path to ipf])],
478 AC_PATH_PROG(IPF_EXE, [ipf], [], [$APP_PATH])
482 dnl Determine which firewall exe we use (if we have one).
483 dnl If iptables was found or specified, it wins, then we fallback to ipfw,
484 dnl then pf, and otherwise we try ipf.
486 AS_IF([test "x$IPTABLES_EXE" != x], [
488 FIREWALL_TYPE="iptables"
489 FIREWALL_EXE=$IPTABLES_EXE
490 AC_DEFINE_UNQUOTED([FIREWALL_IPTABLES], [1], [The firewall type: iptables.])
492 AS_IF([test "x$IPFW_EXE" != x], [
495 FIREWALL_EXE=$IPFW_EXE
496 AC_DEFINE_UNQUOTED([FIREWALL_IPFW], [1], [The firewall type: ipfw.])
498 AS_IF([test "x$PF_EXE" != x], [
502 AC_DEFINE_UNQUOTED([FIREWALL_PF], [1], [The firewall type: pf.])
504 AS_IF([test "x$IPF_EXE" != x], [
505 AC_MSG_ERROR([Sorry - ipf was specified or the only one found, however, it is not supported yet.])
507 FIREWALL_EXE=$IPF_EXE
508 AC_DEFINE_UNQUOTED([FIREWALL_IPF], [1], [The firewall type: ipf.])
509 ], [AC_MSG_ERROR([No firewall program was found or specified.]) ]
515 AC_DEFINE_UNQUOTED([FIREWALL_EXE], ["$FIREWALL_EXE"],
516 [Path to firewall command executable (it should match the firewall type).])
519 [test "$want_server" = no], [
521 AM_CONDITIONAL([USE_NDBM], [test x$use_ndbm = xno])
522 AM_CONDITIONAL([CONFIG_FILE_CACHE], [test x$use_ndbm = xno])
526 AC_CONFIG_FILES([Makefile
535 if [test "$have_gpgme" = "yes" ]; then
536 have_gpgme="$have_gpgme
537 Gpgme engine: $GPG_EXE"
541 $PACKAGE_NAME-$PACKAGE_VERSION configuration.
542 ==========================================================
543 Client build: $want_client
544 Server build: $want_server
545 GPG encryption support: $have_gpgme
547 Installation prefix: $prefix
549 if [test "$want_server" = "yes" ]; then
550 echo " Server support:
551 firewall type: $FIREWALL_TYPE
552 firewall program path: $FIREWALL_EXE
555 if [test "$want_digest_cache" = "no" ]; then
557 The digest-cache functionality is not enabled. This
558 could leave the fwknopd server open to replay attacks!