Code

420021f628ab81d61a4e898fe1acdc6c3d173f2a
[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                 [sh@tokkee.org],
31                 [sysdb],
32                 [http://git.tokkee.org/?p=sysdb.git])
33 PACKAGE_MAINTAINER="Sebastian 'tokkee' Harl <sh@tokkee.org>"
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 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 m4_divert_once([HELP_ENABLE], [
252 Build dependencies:])
254 dnl Testing.
255 PKG_CHECK_MODULES([CHECK], [check >= 0.9.4],
256                 [build_testing="yes"], [build_testing="no"])
258 AC_CHECK_HEADERS(libgen.h)
260 dnl Check for dependencies.
261 AC_ARG_WITH([libdbi],
262                 [AS_HELP_STRING([--with-libdbi], [libdbi support (default: auto)])],
263                 [with_libdbi="$withval"],
264                 [with_libdbi="yes"])
265 if test "x$with_libdbi" = "xyes" || test "x$with_libdbi" = "xauto"; then
266         AC_CHECK_HEADERS([dbi/dbi.h],
267                         [with_libdbi="yes"],
268                         [with_libdbi="no (dbi/dbi.h not found)"])
269 else if test "x$with_libdbi" = "xno"; then
270         with_libdbi="$with_libdbi (disabled on command-line)"
271 else
272         AC_MSG_ERROR([Invalid value for option --with-libdbi=$with_libdbi (expected "yes", "no", or "auto")])
273 fi; fi
274 if test "x$with_libdbi" = "xyes"; then
275         AC_CHECK_LIB([dbi], [dbi_initialize],
276                         [with_libdbi="yes"],
277                         [with_libdbi="no (libdbi or symbol 'dbi_initialize' not found)"])
278 fi
279 AM_CONDITIONAL([BUILD_WITH_LIBDBI], test "x$with_libdbi" = "xyes")
281 dnl Required for mocking FILE related functions.
282 orig_CFLAGS="$CFLAGS"
283 CFLAGS="$CFLAGS -D_GNU_SOURCE"
284 AC_CHECK_FUNCS([fopencookie],
285                 [have_fopencookie="yes"],
286                 [have_fopencookie="no (fopencookie not available)"])
287 CFLAGS="$orig_CFLAGS"
288 AM_CONDITIONAL([BUILD_WITH_FOPENCOOKIE], test "x$have_fopencookie" = "xyes")
289 if test "x$have_fopencookie" = "xyes"; then
290         AC_DEFINE([HAVE_FOPENCOOKIE], 1)
291 fi
293 dnl readline support
294 AC_ARG_WITH([readline],
295                 [AS_HELP_STRING([--with-readline],
296                         [readline support (libedit/libreadline) (default: auto, prefer libedit)])],
297                 [readline_support="$withval"],
298                 [readline_support="auto"])
300 if test "x$readline_support" = "xyes"; then
301         readline_support="auto"
302 else if test "x$readline_support" != "xauto" \
303                 && test "x$readline_support" != "xno" \
304                 && test "x$readline_support" != "xlibedit" \
305                 && test "x$readline_support" != "xlibreadline"; then
306         AC_MSG_ERROR([Invalid value for option --with-readline=$readline_support (expected "yes", "no", "auto", "libedit", or "libreadline")])
307 fi; fi
309 have_libedit="no"
310 if test "x$readline_support" = "xauto" \
311                 || test "x$readline_support" = "xlibedit"; then
312         PKG_CHECK_MODULES([LIBEDIT], [libedit],
313                         [have_libedit="yes"], [have_libedit="no"])
314         if test "x$have_libedit" = "xyes"; then
315                 AC_CHECK_HEADERS([editline/readline.h], [],
316                                 [AC_CHECK_HEADERS([readline.h], [],
317                                                 [have_libedit="no (readline header not found"])])
318         fi
319         if test "x$have_libedit" = "xyes"; then
320                 AC_CHECK_HEADERS([editline/history.h], [],
321                                 [AC_CHECK_HEADERS([history.h], [],
322                                                 [have_libedit="no (history header not found"])])
323         fi
324 else
325         have_libedit="disabled on command-line"
326 fi
328 have_libreadline="no"
329 if test "x$have_libedit" != "xyes"; then
330         if test "x$readline_support" = "xauto" \
331                         || test "x$readline_support" = "xlibreadline"; then
332                 AC_CHECK_LIB([readline], [readline],
333                                 [have_libreadline="yes"],
334                                 [have_libreadline="no (libreadline or symbol 'readline' not found)"])
335         fi
336         if test "x$have_libreadline" = "xyes"; then
337                 AC_CHECK_HEADERS([readline/readline.h], [],
338                                 [AC_CHECK_HEADERS([readline.h], [],
339                                                 [have_libreadline="no (readline header not found"])])
340         fi
341         if test "x$have_libreadline" = "xyes"; then
342                 AC_CHECK_HEADERS([readline/history.h], [],
343                                 [AC_CHECK_HEADERS([history.h], [],
344                                                 [have_libreadline="no (history header not found"])])
345         fi
346 else
347         have_libreadline="unchecked (prefer libedit)"
348 fi
350 if test "x$have_libedit" = "xyes"; then
351         READLINE_LIBS="$LIBEDIT_LIBS"
352         READLINE_CFLAGS="$LIBEDIT_CFLAGS"
353         readline_support="libedit"
354 else if test "x$have_libreadline" = "xyes"; then
355         READLINE_LIBS="-lreadline -lhistory"
356         READLINE_CFLAGS=""
357         readline_support="libreadline"
358 else
359         READLINE_LIBS=""
360         READLINE_CFLAGS=""
361         if test "x$readline_support" = "xno"; then
362                 AC_MSG_WARN([*** readline support disabled; disabling SysDB client])
363         else if test "x$readline_support" = "xauto"; then
364                 AC_MSG_WARN([*** readline not found; disabling SysDB client])
365         else
366                 AC_MSG_ERROR([readline not found])
367         fi; fi
368         readline_support="no"
369 fi; fi
370 AC_SUBST([READLINE_LIBS])
371 AC_SUBST([READLINE_CFLAGS])
372 AM_CONDITIONAL([BUILD_CLIENT], test "x$readline_support" != "no")
374 dnl Feature checks.
375 build_documentation="yes"
377 have_xmlto="yes"
378 AC_PATH_PROG([XMLTO], [xmlto])
379 if test "x$XMLTO" = "x"; then
380         have_xmlto="no"
381         build_documentation="no (missing xmlto)"
382 fi
384 have_xsltproc="yes"
385 AC_PATH_PROG([XSLTPROC], [xsltproc])
386 if test "x$XSLTPROC" = "x"; then
387        have_xsltproc="no"
388        build_documentation="no (missing xsltproc)"
389 fi
391 have_a2x="yes"
392 AC_PATH_PROG([A2X], [a2x])
393 if test "x$A2X" = "x"; then
394        have_a2x="no"
395        build_documentation="no (missing a2x)"
396 fi
397 AC_SUBST([A2X])
399 dnl Plugin checks.
400 puppet_storeconfigs_default=$with_libdbi
401 if test "x$puppet_storeconfigs_default" != "xyes"; then
402         puppet_storeconfigs_default="no (requires libdbi)"
403 fi
405 m4_divert_once([HELP_ENABLE], [
406 Backends:])
408 AC_SDB_PLUGIN_INIT
409 AC_SDB_PLUGIN([collectd], [yes],
410                 [backend accessing the system statistics collection daemon])
411 AC_SDB_PLUGIN([mk-livestatus], [yes],
412                 [backend accessing Nagios/Icinga/Shinken using MK Livestatus])
413 AC_SDB_PLUGIN([puppet-storeconfigs], [$puppet_storeconfigs_default],
414                 [backend accessing the Puppet stored configuration database])
416 m4_divert_once([HELP_ENABLE], [
417 Plugins:])
419 AC_SDB_PLUGIN([cname-dns], [yes],
420                 [canonicalize hostnames by querying DNS])
421 AC_SDB_PLUGIN([syslog], [yes],
422                 [plugin logging to syslog])
424 AM_CONDITIONAL([BUILD_DOCUMENTATION], test "x$build_documentation" = "xyes")
425 AM_CONDITIONAL([BUILD_TESTING], test "x$build_testing" = "xyes")
427 AC_CONFIG_FILES([Makefile doc/Makefile src/Makefile
428                 src/liboconfig/Makefile t/Makefile])
429 AC_OUTPUT
431 BUILD_DATE="`date --utc '+%F %T'` (UTC)"
433 AC_MSG_RESULT()
434 AC_MSG_RESULT([$PACKAGE_NAME has been configured successfully.])
435 AC_MSG_RESULT()
436 AC_MSG_RESULT([Run 'make' to compile the software and use 'make install' to])
437 AC_MSG_RESULT([install the package into $prefix.])
438 AC_MSG_RESULT()
439 AC_MSG_RESULT([Configuration summary:])
440 AC_MSG_RESULT()
441 AC_MSG_RESULT([  package version: $PACKAGE_VERSION])
442 AC_MSG_RESULT([  build date: $BUILD_DATE])
443 AC_MSG_RESULT()
444 AC_MSG_RESULT([  Tools:])
445 AC_MSG_RESULT([    AsciiDoc (a2x): . . . . . . $have_a2x])
446 AC_MSG_RESULT([    xmlto / xsltproc: . . . . . $have_xmlto / $have_xsltproc])
447 AC_MSG_RESULT()
448 AC_MSG_RESULT([  Features:])
449 AC_MSG_RESULT([    documentation:  . . . . . . $build_documentation])
450 AC_MSG_RESULT([    unit testing: . . . . . . . $build_testing])
451 AC_MSG_RESULT([      stdio mocking:  . . . . . $have_fopencookie])
452 AC_MSG_RESULT([    coverage testing: . . . . . $enable_gcov])
453 AC_MSG_RESULT()
454 AC_MSG_RESULT([  Libraries:])
455 AC_MSG_RESULT([    libdbi: . . . . . . . . . . $with_libdbi])
456 AC_MSG_RESULT([    libedit:  . . . . . . . . . $have_libedit])
457 AC_MSG_RESULT([    libreadline:  . . . . . . . $have_libreadline])
458 AC_MSG_RESULT()
459 AC_MSG_RESULT([  Backends:])
460 AC_MSG_RESULT([    collectd: . . . . . . . . . $enable_collectd])
461 AC_MSG_RESULT([    mk-livestatus:  . . . . . . $enable_mk_livestatus])
462 AC_MSG_RESULT([    puppet-storeconfigs:  . . . $enable_puppet_storeconfigs])
463 AC_MSG_RESULT()
464 AC_MSG_RESULT([  Plugins:])
465 AC_MSG_RESULT([    cname::dns: . . . . . . . . $enable_cname_dns])
466 AC_MSG_RESULT([    syslog: . . . . . . . . . . $enable_syslog])
467 AC_MSG_RESULT()
468 AC_MSG_RESULT([This package is maintained by $PACKAGE_MAINTAINER.])
469 AC_MSG_RESULT([Please report bugs to $PACKAGE_BUGREPORT.])
470 AC_MSG_RESULT()
472 dnl vim: set tw=78 sw=4 ts=4 noexpandtab :