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.1-pre2])
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 build binaries with profiling coverage support
125 want_profile_coverage=no
126 AC_ARG_ENABLE([profile-coverage],
127 [AS_HELP_STRING([--enable-profile-coverage],
128 [Build fwknop binaries with profile coverage support @<:@default is to disable@:>@])],
129 [want_profile_coverage=$enableval],
132 if test "x$want_profile_coverage" = "xyes"; then
134 FKO_CHECK_COMPILER_ARG([-fprofile-arcs -ftest-coverage -fno-inline])
137 dnl Decide whether or not to enable all warnings with -Wall
140 AC_ARG_ENABLE([wall],
141 [AS_HELP_STRING([--disable-wall],
142 [Do not enable all warnings via -Wall @<:@default is on@:>@])],
143 [use_wall=$enableval],
146 if test "x$use_wall" = "xyes"; then
147 FKO_CHECK_COMPILER_ARG([-Wall])
150 dnl Check for security features offered by the compiler
152 dnl -fstack-protector-all doesn't always work for some GCC versions
153 dnl and/or platforms, so we test if we can. If it's not supported
154 dnl on a given platform gcc will emit a warning so we use -Werror.
156 dnl Decide whether or not to enable -fstack-protector
158 use_stack_protector=yes
159 AC_ARG_ENABLE([stack-protector],
160 [AS_HELP_STRING([--disable-stack-protector],
161 [Do not enable -fstack-protector @<:@default is on@:>@])],
162 [use_stack_protector=$enableval],
165 if test "x$use_stack_protector" = "xyes"; then
166 FKO_CHECK_COMPILER_ARG([-fstack-protector-all -fstack-protector])
169 dnl Decide whether or not to enable Position Independent Executable (PIE)
174 [AS_HELP_STRING([--disable-pie],
175 [Do not enable Position Independent Executable support @<:@default is on@:>@])],
176 [use_pie=$enableval],
179 if test "x$use_pie" = "xyes"; then
180 FKO_CHECK_COMPILER_ARG([-fPIE -pie])
183 dnl Decide whether or not to enable -D_FORTIFY_SOURCE support
185 use_fortify_source=yes
186 AC_ARG_ENABLE([fortify-source],
187 [AS_HELP_STRING([--disable-fortify-source],
188 [Do not enable -D_FORTIFY_SOURCE support @<:@default is on@:>@])],
189 [use_fortify_source=$enableval],
192 if test "x$use_fortify_source" = "xyes"; then
193 FKO_CHECK_COMPILER_ARG([-D_FORTIFY_SOURCE=2])
196 dnl Decide whether or not to use read-only relocations protection
198 use_ro_relocations=yes
199 AC_ARG_ENABLE([ro-relocations],
200 [AS_HELP_STRING([--disable-ro-relocations],
201 [Do not enable read-only relocations protection @<:@default is on@:>@])],
202 [use_ro_relocations=$enableval],
205 if test "x$use_ro_relocations" = "xyes"; then
206 FKO_CHECK_COMPILER_ARG_LDFLAGS_ONLY([-Wl,-z,relro])
209 dnl Decide whether or not to use immediate binding protection
211 use_immediate_binding=yes
212 AC_ARG_ENABLE([immediate-binding],
213 [AS_HELP_STRING([--disable-immediate-binding],
214 [Do not enable immediate binding protection @<:@default is on@:>@])],
215 [use_immediate_binding=$enableval],
218 if test "x$use_immediate_binding" = "xyes"; then
219 FKO_CHECK_COMPILER_ARG_LDFLAGS_ONLY([-Wl,-z,now])
222 # Checks for header files.
228 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])
246 AC_CHECK_SIZEOF(unsigned int)
247 dnl AC_CHECK_TYPES([uint8_t, uint32_t])
253 # Checks for library functions.
259 AC_CHECK_FUNCS([bzero gettimeofday memmove memset socket strchr strcspn strdup strncasecmp strndup strrchr strspn])
261 AC_SEARCH_LIBS([socket], [socket])
262 AC_SEARCH_LIBS([inet_addr], [nsl])
268 AC_DEFINE_UNQUOTED([PLATFORM_OPENBSD], [1], [Define if you are running on OpenBSD])
272 dnl Decide whether or not to build the client
275 AC_ARG_ENABLE([client],
276 [AS_HELP_STRING([--disable-client],
277 [Do not build the fwknop client @<:@default is to build@:>@])],
278 [want_client=$enableval],
280 AM_CONDITIONAL([WANT_CLIENT], [test "$want_client" = yes])
282 dnl Decide whether or not to build the server
285 AC_ARG_ENABLE([server],
286 [AS_HELP_STRING([--disable-server],
287 [Do not build the fwknop server @<:@default is to build@:>@])],
288 [want_server=$enableval],
290 AM_CONDITIONAL([WANT_SERVER], [test "$want_server" = yes])
292 dnl Decide whether or not to enable the digest-cache
294 want_digest_cache=yes
295 AC_ARG_ENABLE([digest-cache],
296 [AS_HELP_STRING([--disable-digest-cache],
297 [Do not enable the fwknopd digest-cache @<:@default is to build@:>@])],
298 [want_digest_cache=$enableval],
300 dnl AM_CONDITIONAL([WANT_DIGEST_CACHE], [test "$want_digest_cache" = yes])
302 dnl Decide whether or not to try to look for gdbm/ndbm (default to just
303 dnl use a file-based solution - reduces dependencies)
306 AC_ARG_ENABLE([file-cache],
307 [AS_HELP_STRING([--disable-file-cache],
308 [Replace file cache with gdbm/ndbm @<:@default on@:>@])],
309 [want_file_cache=$enableval],
311 AS_IF([test "$want_file_cache" = yes], [
312 AC_DEFINE([USE_FILE_CACHE], [1], [Define this to enable non-gdbm/ndbm digest storing (eliminates gdbm/ndbm dependency).])
315 # Check for 3rd-party libs
318 [AS_HELP_STRING([--with-gpgme],
319 [support for gpg encryption using libgpgme @<:@default=check@:>@])],
324 AS_IF([test "x$with_gpgme" != xno],
326 [AC_DEFINE([HAVE_LIBGPGME], [1], [Define if you have libgpgme])],
327 [if test "x$with_gpgme" != xcheck; then
329 [--with-gpgme was given, but test for gpgme failed])
333 ], [have_gpgme=no])], [have_gpgme=no])
335 dnl Add various common way to sbin dir to the path (just in case)
336 APP_PATH=$PATH$PATH_SEPARATOR/sbin$PATH_SEPARATOR/usr/sbin$PATH_SEPARATOR/usr/local/sbin
338 dnl Check for gpg (not gpg2)
341 [AS_HELP_STRING([--with-gpg=/path/to/gpg],
342 [Specify path to the gpg executable that gpgme will use @<:@default=check path@:>@])],
344 AS_IF([ test "x$withval" = x -o "x$withval" = xyes -o "x$withval" = xno ],
345 [AC_MSG_ERROR([--with-gpg requires an argument specifying a path to gpg])],
350 AC_PATH_PROG(GPG_EXE, [gpg], [], [$APP_PATH])
353 AS_IF([test "x$GPG_EXE" != x],
355 AC_DEFINE_UNQUOTED([GPG_EXE], ["$GPG_EXE"], [Path to gpg executable])
357 ], [ gpg_exe="(not found)"]
360 if [test "$have_gpgme" = "yes" ]; then
365 if [ test "x$CPPFLAGS" = "x" ] ; then
366 CPPFLAGS="-I/usr/local/include -I/usr/local/include/gpgme"
368 if [ test "x$LDFLAGS" = "x" ] ; then
369 LDFLAGS="-L/usr/local/lib"
375 dnl Check for libpcap, gdbm (or ndbm) if we are building the server component
377 AS_IF([test "$want_server" = yes], [
378 # Looking for libpcap
380 AC_CHECK_LIB([pcap],[pcap_open_live],
381 [ AC_DEFINE([HAVE_LIBPCAP], [1], [Define if you have libpcap]) ],
382 [ AC_MSG_ERROR([fwknopd needs libpcap])]
385 AS_IF([test "$want_digest_cache" = yes], [
387 have_digest_cache=yes
389 AS_IF([test "$want_file_cache" = no], [
391 # Looking for gdbm or fallback to ndbm or bail
393 AC_CHECK_LIB([gdbm],[gdbm_open],
395 AC_DEFINE([HAVE_LIBGDBM], [1], [Define if you have libgdbm])
397 [ AC_CHECK_LIB([ndbm],[dbm_open],
399 AC_DEFINE([HAVE_LIBNDBM], [1], [Define if you have libndbm])
402 [ AC_CHECK_HEADER([ndbm.h],
403 [ AC_CHECK_FUNC([dbm_open],
404 [ AC_DEFINE([HAVE_LIBNDBM], [1], [Define if you have libndbm])],
406 AC_DEFINE([NO_DIGEST_CACHE], [1], [Define this to disable the digest cache for replay detection - not recommended.])
407 AC_MSG_WARN([No DBM implementation found. Replay detection will be disabled.])
416 AC_DEFINE([NO_DIGEST_CACHE], [1], [Define this to disable the digest cache for replay detection - not recommended.])
421 AM_CONDITIONAL([USE_NDBM], [test x$use_ndbm = xyes])
422 AM_CONDITIONAL([CONFIG_FILE_CACHE], [test x$want_file_cache = xyes])
424 dnl Check for iptables
426 AC_ARG_WITH([iptables],
427 [AS_HELP_STRING([--with-iptables=/path/to/iptables],
428 [Specify path to the iptables executable @<:@default=check path@:>@])],
430 AS_IF([ test "x$withval" = xno ], [],
431 AS_IF([ test "x$withval" = x -o "x$withval" = xyes ],
432 [AC_MSG_ERROR([--with-iptables requires an argument specifying a path to iptables])],
433 [ IPTABLES_EXE=$withval ]
438 AC_PATH_PROG(IPTABLES_EXE, [iptables], [], [$APP_PATH])
445 [AS_HELP_STRING([--with-ipfw=/path/to/ipfw],
446 [Specify path to the ipfw executable @<:@default=check path@:>@])],
448 AS_IF([ test "x$withval" = xno ], [],
449 AS_IF([ test "x$withval" = x -o "x$withval" = xyes ],
450 [AC_MSG_ERROR([--with-ipfw requires an argument specifying a path to ipfw])],
451 [ IPFW_EXE=$withval ]
456 AC_PATH_PROG(IPFW_EXE, [ipfw], [], [$APP_PATH])
460 dnl Check for pf from OpenBSD
463 [AS_HELP_STRING([--with-pf=/path/to/pfctl],
464 [Specify path to the pf executable @<:@default=check path@:>@])],
466 AS_IF([ test "x$withval" = xno ], [],
467 AS_IF([ test "x$withval" = x -o "x$withval" = xyes ],
468 [AC_MSG_ERROR([--with-pf requires an argument specifying a path to pf])],
474 AC_PATH_PROG(PF_EXE, [pfctl], [], [$APP_PATH])
478 dnl Check for ipf (ipfilter)
481 [AS_HELP_STRING([--with-ipf=/path/to/ipf],
482 [Specify path to the ipf executable @<:@default=check path@:>@])],
484 AS_IF([ test "x$withval" = xno ], [],
485 AS_IF([ test "x$withval" = x -o "x$withval" = xyes ],
486 [AC_MSG_ERROR([--with-ipf requires an argument specifying a path to ipf])],
492 AC_PATH_PROG(IPF_EXE, [ipf], [], [$APP_PATH])
496 dnl Determine which firewall exe we use (if we have one).
497 dnl If iptables was found or specified, it wins, then we fallback to ipfw,
498 dnl then pf, and otherwise we try ipf.
500 AS_IF([test "x$IPTABLES_EXE" != x], [
502 FIREWALL_TYPE="iptables"
503 FIREWALL_EXE=$IPTABLES_EXE
504 AC_DEFINE_UNQUOTED([FIREWALL_IPTABLES], [1], [The firewall type: iptables.])
506 AS_IF([test "x$IPFW_EXE" != x], [
509 FIREWALL_EXE=$IPFW_EXE
510 AC_DEFINE_UNQUOTED([FIREWALL_IPFW], [1], [The firewall type: ipfw.])
512 AS_IF([test "x$PF_EXE" != x], [
516 AC_DEFINE_UNQUOTED([FIREWALL_PF], [1], [The firewall type: pf.])
518 AS_IF([test "x$IPF_EXE" != x], [
519 AC_MSG_ERROR([Sorry - ipf was specified or the only one found, however, it is not supported yet.])
521 FIREWALL_EXE=$IPF_EXE
522 AC_DEFINE_UNQUOTED([FIREWALL_IPF], [1], [The firewall type: ipf.])
523 ], [AC_MSG_ERROR([No firewall program was found or specified.]) ]
529 AC_DEFINE_UNQUOTED([FIREWALL_EXE], ["$FIREWALL_EXE"],
530 [Path to firewall command executable (it should match the firewall type).])
533 [test "$want_server" = no], [
535 AM_CONDITIONAL([USE_NDBM], [test x$use_ndbm = xno])
536 AM_CONDITIONAL([CONFIG_FILE_CACHE], [test x$use_ndbm = xno])
540 AC_CONFIG_FILES([Makefile
549 if [test "$have_gpgme" = "yes" ]; then
550 have_gpgme="$have_gpgme
551 Gpgme engine: $GPG_EXE"
555 $PACKAGE_NAME-$PACKAGE_VERSION configuration.
556 ==========================================================
557 Client build: $want_client
558 Server build: $want_server
559 GPG encryption support: $have_gpgme
561 Installation prefix: $prefix
563 if [test "$want_server" = "yes" ]; then
564 echo " Server support:
565 firewall type: $FIREWALL_TYPE
566 firewall program path: $FIREWALL_EXE
569 if [test "$want_digest_cache" = "no" ]; then
571 The digest-cache functionality is not enabled. This
572 could leave the fwknopd server open to replay attacks!