Code

Merged branch 'master' of git://git.tokkee.org/sysdb.
[sysdb.git] / configure.ac
1 dnl Process this file with autoconf to produce a configure script.
2 dnl
3 dnl This is the SysDB configure script.
4 dnl
5 dnl Copyright (C) 2012 Sebastian 'tokkee' Harl <sh@tokkee.org>
6 dnl All rights reserved.
7 dnl
8 dnl Redistribution and use in source and binary forms, with or without
9 dnl modification, are permitted provided that the following conditions
10 dnl are met:
11 dnl 1. Redistributions of source code must retain the above copyright
12 dnl    notice, this list of conditions and the following disclaimer.
13 dnl 2. Redistributions in binary form must reproduce the above copyright
14 dnl    notice, this list of conditions and the following disclaimer in the
15 dnl    documentation and/or other materials provided with the distribution.
16 dnl
17 dnl THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 dnl ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19 dnl TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20 dnl PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
21 dnl CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22 dnl EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23 dnl PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
24 dnl OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25 dnl WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
26 dnl OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
27 dnl ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 AC_INIT([System DataBase],[m4_esyscmd(./version-gen.sh)],
30                 [sysdb@sysdb.io],
31                 [sysdb],
32                 [http://sysdb.io/])
33 PACKAGE_MAINTAINER="Sebastian 'tokkee' Harl <tokkee@sysdb.io>"
34 AC_DEFINE_UNQUOTED([PACKAGE_MAINTAINER], ["$PACKAGE_MAINTAINER"],
35                 [Define to the name of the maintainer of this package.])
36 AC_CONFIG_SRCDIR([src/sysdb.c])
37 AC_CONFIG_HEADERS([src/config.h])
38 AC_PREFIX_DEFAULT([/opt/sysdb])
40 AM_INIT_AUTOMAKE([foreign subdir-objects -Wall])
42 AC_LANG(C)
44 AC_SYS_LARGEFILE
46 AC_PROG_CC
47 AC_PROG_CPP
48 AC_PROG_INSTALL
49 AC_PROG_LN_S
50 AC_PROG_MAKE_SET
51 m4_ifdef([AM_PROG_AR],[AM_PROG_AR],[])
53 AM_PROG_CC_C_O
54 AM_PROG_LEX
55 AC_PROG_YACC
57 m4_ifdef([LT_INIT],
58         [
59          LT_CONFIG_LTDL_DIR([libltdl])
60          LT_INIT([dlopen])
61          LTDL_INIT([convenience])
62         ],
63         # else
64         # (older libtools)
65         [
66          AC_CONFIG_SUBDIRS(libltdl)
67          AC_LIBLTDL_CONVENIENCE
68          AC_SUBST(LTDLINCL)
69          AC_SUBST(LIBLTDL)
70          AC_LIBTOOL_DLOPEN
71         ]
72 )
74 test_cc_flags() {
75         AC_LANG_CONFTEST([AC_LANG_PROGRAM([[ ]], [[ ]])])
76         $CC -c conftest.c $CFLAGS $@ > /dev/null 2> /dev/null
77         ret=$?
78         rm -f conftest.o
79         return $ret
80 }
82 STRICT_CFLAGS=""
84 m4_divert_once([HELP_ENABLE], [
85 Build options:])
87 dnl Optionally stick to standard C99 and POSIX:2001 as close as possible.
88 AC_ARG_ENABLE([standards],
89                 AS_HELP_STRING([--enable-standards],
90                                 [C99 / POSIX standards compliance mode @<:@default=no@:>@]),
91                 [enable_standards="$enableval"],
92                 [enable_standards="no"])
94 if test "x$enable_standards" = "xyes"; then
95         AC_DEFINE([_ISOC99_SOURCE], 1,
96                         [Define to enforce ISO/IEC 9899:1999 (C99) compliance.])
97         AC_DEFINE([_POSIX_C_SOURCE], 200112L,
98                         [Define to enforce IEEE 1003.1-2001 (POSIX:2001) compliance.])
99         AC_DEFINE([_XOPEN_SOURCE], 700,
100                         [Define to enforce X/Open 7 (XSI) compliance.])
101         AC_DEFINE([_REENTRANT], 1,
102                         [Define to enable reentrant interfaces.])
103         AC_DEFINE([_THREAD_SAFE], 1,
104                         [Define to enable reentrant interfaces.])
106         dnl GNU libc defines strcasecmp() only when using _BSD_SOURCE even though
107         dnl the function is conforming to POSIX.1-2001 as well. Let's weaken
108         dnl strict standards compliance a bit to work around this.
109         AC_DEFINE([_BSD_SOURCE], 1, [Define to enable 4.3BSD support.])
111         for flag in -std=c99; do
112                 AC_MSG_CHECKING([whether $CC accepts $flag])
114                 if test_cc_flags $flag; then
115                         STRICT_CFLAGS="$STRICT_CFLAGS $flag"
116                         AC_MSG_RESULT([yes])
117                 else
118                         AC_MSG_RESULT([no])
119                 fi
120         done
121 fi
123 dnl Hardening (see e.g. http://wiki.debian.org/Hardening for a motivation).
124 AC_DEFINE([_FORTIFY_SOURCE], 2,
125                 [Define to enable protection against static sized buffer overflows.])
126 AC_ARG_ENABLE([hardening],
127                 AS_HELP_STRING([--disable-hardening],
128                                 [hardening options @<:@default=yes@:>@]),
129                 [enable_hardening="$enableval"],
130                 [enable_hardening="yes"])
132 if test "x$enable_hardening" = "xyes"; then
133         hardening=0
134         hardening_tests=0
135         for flag in -Wformat -Wformat-security; do
136                 hardening_tests=$(($hardening_tests + 1))
137                 AC_MSG_CHECKING([whether $CC accepts $flag])
139                 if test_cc_flags $flag; then
140                         STRICT_CFLAGS="$STRICT_CFLAGS $flag"
141                         hardening=$(($hardening + 1))
142                         AC_MSG_RESULT([yes])
143                 else
144                         AC_MSG_RESULT([no])
145                 fi
146         done
147         if test $hardening -ne $hardening_tests; then
148                 AC_MSG_WARN(
149                                 [Some hardening options are not supported by your compiler!])
150         fi
151 fi
153 dnl Strict checking for potential problems.
154 AC_ARG_ENABLE([strict-checks],
155                 AS_HELP_STRING([--disable-strict-checks],
156                                 [strict compiler checks @<:@default=yes@:>@]),
157                 [enable_strict_checks="$enableval"],
158                 [enable_strict_checks="yes"])
160 for flag in -Wall -Werror; do
161         AC_MSG_CHECKING([whether $CC accepts $flag])
163         if test_cc_flags $flag; then
164                 STRICT_CFLAGS="$STRICT_CFLAGS $flag"
165                 AC_MSG_RESULT([yes])
166         else
167                 AC_MSG_RESULT([no])
168         fi
169 done
171 if test "x$enable_strict_checks" = "xyes"; then
172         dnl -Wsign-conversion may cause problems in expanded macros from libc
173         for flag in -Wextra \
174                         -Wbad-function-cast \
175                         -Wcast-align \
176                         -Wcast-qual \
177                         -Wconversion \
178                         -Wno-sign-conversion \
179                         -Wdeclaration-after-statement \
180                         -Wmissing-prototypes \
181                         -Wpointer-arith \
182                         -Wshadow \
183                         -Wstrict-prototypes; do
184                 AC_MSG_CHECKING([whether $CC accepts $flag])
186                 if test_cc_flags $flag; then
187                         STRICT_CFLAGS="$STRICT_CFLAGS $flag"
188                         AC_MSG_RESULT([yes])
189                 else
190                         AC_MSG_RESULT([no])
191                 fi
192         done
193 fi
194 AC_SUBST([STRICT_CFLAGS])
196 AC_ARG_ENABLE([gcov],
197                 AS_HELP_STRING([--enable-gcov],
198                                 [Gcov coverage statistics @<:@default=no@:>@]),
199                 [enable_gcov="$enableval"],
200                 [enable_gcov="no"])
202 dnl $GCC is based on some heuristics which might apply to clang as well.
203 dnl However, clang does not support gcov.
204 cc_is_gcc="no"
205 case "x$CC" in
206         xgcc)
207                 cc_is_gcc="yes"
208                 ;;
209         xgcc-*)
210                 cc_is_gcc="yes"
211                 ;;
212 esac
214 COVERAGE_CFLAGS=""
215 COVERAGE_LDFLAGS=""
216 if test "x$enable_gcov" = "xyes" && test "x$GCC$cc_is_gcc" == "xyesyes"; then
217         COVERAGE_CFLAGS="-O0"
218         cov_flag_have_problem="no"
220         AC_MSG_CHECKING([whether $CC accepts --coverage])
221         if test_cc_flags --coverage; then
222                 COVERAGE_CFLAGS="$COVERAGE_CFLAGS --coverage"
223                 COVERAGE_LDFLAGS="$COVERAGE_LDFLAGS --coverage"
224                 AC_MSG_RESULT([yes])
225         else
226                 AC_MSG_RESULT([no])
227                 cov_flag_have_problem="yes"
228         fi
230         for flag in -fno-inline; do
231                 AC_MSG_CHECKING([whether $CC accepts $flag])
232                 if test_cc_flags $flag; then
233                         COVERAGE_CFLAGS="$COVERAGE_CFLAGS $flag"
234                         AC_MSG_RESULT([yes])
235                 else
236                         AC_MSG_RESULT([no])
237                         cov_flag_have_problem="yes"
238                 fi
239         done
241         if test "x$cov_flag_have_problem" != "xno"; then
242                 AC_MSG_WARN([Some coverage flags are not supported by your compiler!])
243         fi
244 else if test "x$enable_gcov" = "xyes"; then
245         AC_MSG_WARN([Your compiler ($CC) is not known to support Gcov!])
246         enable_gcov="no (requires GCC)"
247 fi; fi
248 AC_SUBST([COVERAGE_CFLAGS])
249 AC_SUBST([COVERAGE_LDFLAGS])
251 AC_ARG_ENABLE([gprof],
252                 AS_HELP_STRING([--enable-gprof],
253                                 [Gprof profiling @<:@default=no@:>@]),
254                 [enable_gprof="$enableval"],
255                 [enable_gprof="no"])
257 PROFILING_CFLAGS=""
258 PROFILING_LDFLAGS=""
259 if test "x$enable_gprof" = "xyes"; then
260         PROFILING_CFLAGS="-O0"
261         profiling_flag_have_problem="no"
263         AC_MSG_CHECKING([whether $CC accepts -pg])
264         if test_cc_flags -pg; then
265                 PROFILING_CFLAGS="$PROFILING_CFLAGS -pg"
266                 PROFILING_LDFLAGS="$PROFILING_LDFLAGS -pg"
267                 AC_MSG_RESULT([yes])
268         else
269                 AC_MSG_RESULT([no])
270                 profiling_flag_have_problem="yes"
271         fi
273         for flag in -fprofile-arcs; do
274                 AC_MSG_CHECKING([whether $CC accepts $flag])
275                 if test_cc_flags $flag; then
276                         PROFILING_CFLAGS="$PROFILING_CFLAGS $flag"
277                         AC_MSG_RESULT([yes])
278                 fi
279                 # else: this is not a serious problem
280         done
282         if test "x$profiling_flag_have_problem" != "xno"; then
283                 AC_MSG_WARN([Some profiling flags are not supported by your compiler!])
284         fi
285 fi
286 AC_SUBST([PROFILING_CFLAGS])
287 AC_SUBST([PROFILING_LDFLAGS])
289 m4_divert_once([HELP_ENABLE], [
290 Build dependencies:])
292 dnl Testing.
293 PKG_CHECK_MODULES([CHECK], [check >= 0.9.4],
294                 [unit_tests="yes"], [unit_tests="no"])
296 AC_CHECK_HEADERS(libgen.h)
298 dnl Check for dependencies.
299 AC_ARG_WITH([libdbi],
300                 [AS_HELP_STRING([--with-libdbi], [libdbi support (default: auto)])],
301                 [with_libdbi="$withval"],
302                 [with_libdbi="yes"])
303 if test "x$with_libdbi" = "xyes" || test "x$with_libdbi" = "xauto"; then
304         AC_CHECK_HEADERS([dbi/dbi.h],
305                         [with_libdbi="yes"],
306                         [with_libdbi="no (dbi/dbi.h not found)"])
307 else if test "x$with_libdbi" = "xno"; then
308         with_libdbi="$with_libdbi (disabled on command-line)"
309 else
310         AC_MSG_ERROR([Invalid value for option --with-libdbi=$with_libdbi (expected "yes", "no", or "auto")])
311 fi; fi
312 if test "x$with_libdbi" = "xyes"; then
313         AC_CHECK_LIB([dbi], [dbi_initialize],
314                         [with_libdbi="yes"],
315                         [with_libdbi="no (libdbi or symbol 'dbi_initialize' not found)"])
316 fi
317 AM_CONDITIONAL([BUILD_WITH_LIBDBI], test "x$with_libdbi" = "xyes")
319 dnl Required for mocking FILE related functions.
320 orig_CFLAGS="$CFLAGS"
321 CFLAGS="$CFLAGS -D_GNU_SOURCE"
322 AC_CHECK_FUNCS([fopencookie],
323                 [have_fopencookie="yes"],
324                 [have_fopencookie="no (fopencookie not available)"])
325 CFLAGS="$orig_CFLAGS"
326 AM_CONDITIONAL([BUILD_WITH_FOPENCOOKIE], test "x$have_fopencookie" = "xyes")
327 if test "x$have_fopencookie" = "xyes"; then
328         AC_DEFINE([HAVE_FOPENCOOKIE], 1)
329 fi
331 dnl readline support
332 AC_ARG_WITH([readline],
333                 [AS_HELP_STRING([--with-readline],
334                         [readline support (libedit/libreadline) (default: auto, prefer libedit)])],
335                 [readline_support="$withval"],
336                 [readline_support="auto"])
338 if test "x$readline_support" = "xyes"; then
339         readline_support="auto"
340 else if test "x$readline_support" != "xauto" \
341                 && test "x$readline_support" != "xno" \
342                 && test "x$readline_support" != "xlibedit" \
343                 && test "x$readline_support" != "xlibreadline"; then
344         AC_MSG_ERROR([Invalid value for option --with-readline=$readline_support (expected "yes", "no", "auto", "libedit", or "libreadline")])
345 fi; fi
347 have_libedit="no"
348 if test "x$readline_support" = "xauto" \
349                 || test "x$readline_support" = "xlibedit"; then
350         PKG_CHECK_MODULES([LIBEDIT], [libedit],
351                         [have_libedit="yes"], [have_libedit="no"])
352         if test "x$have_libedit" = "xyes"; then
353                 AC_CHECK_HEADERS([editline/readline.h], [],
354                                 [AC_CHECK_HEADERS([readline.h], [],
355                                                 [have_libedit="no (readline header not found"])])
356         fi
357         if test "x$have_libedit" = "xyes"; then
358                 AC_CHECK_HEADERS([editline/history.h], [],
359                                 [AC_CHECK_HEADERS([history.h], [],
360                                                 [have_libedit="no (history header not found"])])
361         fi
362 else
363         have_libedit="disabled on command-line"
364 fi
366 have_libreadline="no"
367 if test "x$have_libedit" != "xyes"; then
368         if test "x$readline_support" = "xauto" \
369                         || test "x$readline_support" = "xlibreadline"; then
370                 AC_CHECK_LIB([readline], [readline],
371                                 [have_libreadline="yes"],
372                                 [have_libreadline="no (libreadline or symbol 'readline' not found)"])
373         fi
374         if test "x$have_libreadline" = "xyes"; then
375                 AC_CHECK_HEADERS([readline/readline.h], [],
376                                 [AC_CHECK_HEADERS([readline.h], [],
377                                                 [have_libreadline="no (readline header not found"])])
378         fi
379         if test "x$have_libreadline" = "xyes"; then
380                 AC_CHECK_HEADERS([readline/history.h], [],
381                                 [AC_CHECK_HEADERS([history.h], [],
382                                                 [have_libreadline="no (history header not found"])])
383         fi
384 else
385         have_libreadline="unchecked (prefer libedit)"
386 fi
388 if test "x$have_libedit" = "xyes"; then
389         READLINE_LIBS="$LIBEDIT_LIBS"
390         READLINE_CFLAGS="$LIBEDIT_CFLAGS"
391         readline_support="libedit"
392 else if test "x$have_libreadline" = "xyes"; then
393         READLINE_LIBS="-lreadline -lhistory"
394         READLINE_CFLAGS=""
395         readline_support="libreadline"
396 else
397         READLINE_LIBS=""
398         READLINE_CFLAGS=""
399         if test "x$readline_support" = "xno"; then
400                 AC_MSG_WARN([*** readline support disabled; disabling SysDB client])
401         else if test "x$readline_support" = "xauto"; then
402                 AC_MSG_WARN([*** readline not found; disabling SysDB client])
403         else
404                 AC_MSG_ERROR([readline not found])
405         fi; fi
406         readline_support="no"
407 fi; fi
408 AC_SUBST([READLINE_LIBS])
409 AC_SUBST([READLINE_CFLAGS])
410 AM_CONDITIONAL([BUILD_CLIENT], test "x$readline_support" != "no")
412 dnl Feature checks.
413 build_documentation="yes"
415 have_xmlto="yes"
416 AC_PATH_PROG([XMLTO], [xmlto])
417 if test "x$XMLTO" = "x"; then
418         have_xmlto="no"
419         build_documentation="no (missing xmlto)"
420 fi
421 AC_SUBST([XMLTO])
423 have_asciidoc="yes"
424 AC_PATH_PROG([ASCIIDOC], [asciidoc])
425 if test "x$ASCIIDOC" = "x"; then
426        have_asciidoc="no"
427        build_documentation="no (missing asciidoc)"
428 fi
429 AC_SUBST([ASCIIDOC])
431 AC_ARG_VAR([ADOCFLAGS], [AsciiDoc flags])
433 integration_tests="yes"
434 AC_PATH_PROG([VALGRIND], [valgrind])
435 if test "x$VALGRIND" = "x"; then
436         integration_tests="no (missing valgrind)"
437 fi
438 AM_CONDITIONAL([INTEGRATION_TESTING], test "x$integration_tests" = "xyes")
440 dnl Plugin checks.
441 puppet_storeconfigs_default=$with_libdbi
442 if test "x$puppet_storeconfigs_default" != "xyes"; then
443         puppet_storeconfigs_default="no (requires libdbi)"
444 fi
446 m4_divert_once([HELP_ENABLE], [
447 Backends:])
449 AC_SDB_PLUGIN_INIT
450 AC_SDB_PLUGIN([collectd], [yes],
451                 [backend accessing the system statistics collection daemon])
452 AC_SDB_PLUGIN([mk-livestatus], [yes],
453                 [backend accessing Nagios/Icinga/Shinken using MK Livestatus])
454 AC_SDB_PLUGIN([puppet-storeconfigs], [$puppet_storeconfigs_default],
455                 [backend accessing the Puppet stored configuration database])
457 m4_divert_once([HELP_ENABLE], [
458 Plugins:])
460 AC_SDB_PLUGIN([cname-dns], [yes],
461                 [canonicalize hostnames by querying DNS])
462 AC_SDB_PLUGIN([syslog], [yes],
463                 [plugin logging to syslog])
465 AM_CONDITIONAL([BUILD_DOCUMENTATION], test "x$build_documentation" = "xyes")
466 AM_CONDITIONAL([UNIT_TESTING], test "x$unit_tests" = "xyes")
468 AC_CONFIG_FILES([Makefile doc/Makefile src/Makefile
469                 src/liboconfig/Makefile t/Makefile])
470 AC_OUTPUT
472 BUILD_DATE="`date --utc '+%F %T'` (UTC)"
474 AC_MSG_RESULT()
475 AC_MSG_RESULT([$PACKAGE_NAME has been configured successfully.])
476 AC_MSG_RESULT()
477 AC_MSG_RESULT([Run 'make' to compile the software and use 'make install' to])
478 AC_MSG_RESULT([install the package into $prefix.])
479 AC_MSG_RESULT()
480 AC_MSG_RESULT([Configuration summary:])
481 AC_MSG_RESULT()
482 AC_MSG_RESULT([  package version: $PACKAGE_VERSION])
483 AC_MSG_RESULT([  build date: $BUILD_DATE])
484 AC_MSG_RESULT()
485 AC_MSG_RESULT([  Tools:])
486 AC_MSG_RESULT([    AsciiDoc: . . . . . . . . . $have_asciidoc])
487 AC_MSG_RESULT([    xmlto:  . . . . . . . . . . $have_xmlto])
488 AC_MSG_RESULT()
489 AC_MSG_RESULT([  Features:])
490 AC_MSG_RESULT([    documentation:  . . . . . . $build_documentation])
491 AC_MSG_RESULT([    unit testing: . . . . . . . $unit_tests])
492 AC_MSG_RESULT([      stdio mocking:  . . . . . $have_fopencookie])
493 AC_MSG_RESULT([    coverage testing: . . . . . $enable_gcov])
494 AC_MSG_RESULT([    integration testing:  . . . $integration_tests])
495 AC_MSG_RESULT([    profiling:  . . . . . . . . $enable_gprof])
496 AC_MSG_RESULT()
497 AC_MSG_RESULT([  Libraries:])
498 AC_MSG_RESULT([    libdbi: . . . . . . . . . . $with_libdbi])
499 AC_MSG_RESULT([    libedit:  . . . . . . . . . $have_libedit])
500 AC_MSG_RESULT([    libreadline:  . . . . . . . $have_libreadline])
501 AC_MSG_RESULT()
502 AC_MSG_RESULT([  Backends:])
503 AC_MSG_RESULT([    collectd: . . . . . . . . . $enable_collectd])
504 AC_MSG_RESULT([    mk-livestatus:  . . . . . . $enable_mk_livestatus])
505 AC_MSG_RESULT([    puppet-storeconfigs:  . . . $enable_puppet_storeconfigs])
506 AC_MSG_RESULT()
507 AC_MSG_RESULT([  Plugins:])
508 AC_MSG_RESULT([    cname::dns: . . . . . . . . $enable_cname_dns])
509 AC_MSG_RESULT([    syslog: . . . . . . . . . . $enable_syslog])
510 AC_MSG_RESULT()
511 AC_MSG_RESULT([This package is maintained by $PACKAGE_MAINTAINER.])
512 AC_MSG_RESULT([Please report bugs to $PACKAGE_BUGREPORT.])
513 AC_MSG_RESULT()
515 dnl vim: set tw=78 sw=4 ts=4 noexpandtab :