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 m4_divert_once([HELP_ENABLE], [
83 Build options:])
85 dnl Optionally stick to standard C99 and POSIX:2001 as close as possible.
86 AC_ARG_ENABLE([standards],
87 AS_HELP_STRING([--enable-standards],
88 [C99 / POSIX standards compliance mode @<:@default=no@:>@]),
89 [enable_standards="$enableval"],
90 [enable_standards="no"])
92 if test "x$enable_standards" = "xyes"; then
93 AC_DEFINE([_ISOC99_SOURCE], 1,
94 [Define to enforce ISO/IEC 9899:1999 (C99) compliance.])
95 AC_DEFINE([_POSIX_C_SOURCE], 200112L,
96 [Define to enforce IEEE 1003.1-2001 (POSIX:2001) compliance.])
97 AC_DEFINE([_XOPEN_SOURCE], 600,
98 [Define to enforce X/Open 6 (XSI) compliance.])
99 AC_DEFINE([_REENTRANT], 1,
100 [Define to enable reentrant interfaces.])
101 AC_DEFINE([_THREAD_SAFE], 1,
102 [Define to enable reentrant interfaces.])
104 dnl GNU libc defines strcasecmp() only when using _BSD_SOURCE even though
105 dnl the function is conforming to POSIX.1-2001 as well. Let's weaken
106 dnl strict standards compliance a bit to work around this.
107 AC_DEFINE([_BSD_SOURCE], 1, [Define to enable 4.3BSD support.])
109 for flag in -std=c99 -pedantic; do
110 AC_MSG_CHECKING([whether $CC accepts $flag])
112 if test_cc_flags $flag; then
113 CFLAGS="$CFLAGS $flag"
114 AC_MSG_RESULT([yes])
115 else
116 AC_MSG_RESULT([no])
117 fi
118 done
119 fi
121 dnl Hardening (see e.g. http://wiki.debian.org/Hardening for a motivation).
122 AC_DEFINE([_FORTIFY_SOURCE], 2,
123 [Define to enable protection against static sized buffer overflows.])
124 AC_ARG_ENABLE([hardening],
125 AS_HELP_STRING([--disable-hardening],
126 [hardening options @<:@default=yes@:>@]),
127 [enable_hardening="$enableval"],
128 [enable_hardening="yes"])
130 if test "x$enable_hardening" = "xyes"; then
131 hardening=0
132 hardening_tests=0
133 for flag in -Wformat -Wformat-security; do
134 hardening_tests=$(($hardening_tests + 1))
135 AC_MSG_CHECKING([whether $CC accepts $flag])
137 if test_cc_flags $flag; then
138 CFLAGS="$CFLAGS $flag"
139 hardening=$(($hardening + 1))
140 AC_MSG_RESULT([yes])
141 else
142 AC_MSG_RESULT([no])
143 fi
144 done
145 if test $hardening -ne $hardening_tests; then
146 AC_MSG_WARN(
147 [Some hardening options are not supported by your compiler!])
148 fi
149 fi
151 dnl Strict checking for potential problems.
152 AC_ARG_ENABLE([strict-checks],
153 AS_HELP_STRING([--disable-strict-checks],
154 [strict compiler checks @<:@default=yes@:>@]),
155 [enable_strict_checks="$enableval"],
156 [enable_strict_checks="yes"])
158 STRICT_CFLAGS=""
159 for flag in -Wall -Werror; do
160 AC_MSG_CHECKING([whether $CC accepts $flag])
162 if test_cc_flags $flag; then
163 STRICT_CFLAGS="$STRICT_CFLAGS $flag"
164 AC_MSG_RESULT([yes])
165 else
166 AC_MSG_RESULT([no])
167 fi
168 done
170 if test "x$enable_strict_checks" = "xyes"; then
171 for flag in -Wextra \
172 -Wbad-function-cast \
173 -Wcast-align \
174 -Wcast-qual \
175 -Wconversion \
176 -Wdeclaration-after-statement \
177 -Wmissing-prototypes \
178 -Wpointer-arith \
179 -Wshadow \
180 -Wstrict-prototypes; do
181 AC_MSG_CHECKING([whether $CC accepts $flag])
183 if test_cc_flags $flag; then
184 STRICT_CFLAGS="$STRICT_CFLAGS $flag"
185 AC_MSG_RESULT([yes])
186 else
187 AC_MSG_RESULT([no])
188 fi
189 done
190 fi
191 AC_SUBST([STRICT_CFLAGS])
193 AC_ARG_ENABLE([gcov],
194 AS_HELP_STRING([--enable-gcov],
195 [Gcov coverage statistics @<:@default=no@:>@]),
196 [enable_gcov="$enableval"],
197 [enable_gcov="no"])
199 dnl $GCC is based on some heuristics which might apply to clang as well.
200 dnl However, clang does not support gcov.
201 cc_is_gcc="no"
202 case "x$CC" in
203 xgcc)
204 cc_is_gcc="yes"
205 ;;
206 xgcc-*)
207 cc_is_gcc="yes"
208 ;;
209 esac
211 COVERAGE_CFLAGS=""
212 COVERAGE_LDFLAGS=""
213 if test "x$enable_gcov" = "xyes" && test "x$GCC$cc_is_gcc" == "xyesyes"; then
214 COVERAGE_CFLAGS="-O0"
215 cov_flag_have_problem="no"
217 AC_MSG_CHECKING([whether $CC accepts --coverage])
218 if test_cc_flags --coverage; then
219 COVERAGE_CFLAGS="$COVERAGE_CFLAGS --coverage"
220 COVERAGE_LDFLAGS="$COVERAGE_LDFLAGS --coverage"
221 AC_MSG_RESULT([yes])
222 else
223 AC_MSG_RESULT([no])
224 cov_flag_have_problem="yes"
225 fi
227 for flag in -fno-inline; do
228 AC_MSG_CHECKING([whether $CC accepts $flag])
229 if test_cc_flags $flag; then
230 COVERAGE_CFLAGS="$COVERAGE_CFLAGS $flag"
231 AC_MSG_RESULT([yes])
232 else
233 AC_MSG_RESULT([no])
234 cov_flag_have_problem="yes"
235 fi
236 done
238 if test "x$cov_flag_have_problem" != "xno"; then
239 AC_MSG_WARN([Some coverage flags are not supported by your compiler!])
240 fi
241 else if test "x$enable_gcov" = "xyes"; then
242 AC_MSG_WARN([Your compiler ($CC) is not known to support Gcov!])
243 enable_gcov="no (requires GCC)"
244 fi; fi
245 AC_SUBST([COVERAGE_CFLAGS])
246 AC_SUBST([COVERAGE_LDFLAGS])
248 m4_divert_once([HELP_ENABLE], [
249 Build dependencies:])
251 dnl Testing.
252 PKG_CHECK_MODULES([CHECK], [check >= 0.9.4],
253 [build_testing="yes"], [build_testing="no"])
255 AC_CHECK_HEADERS(libgen.h)
257 dnl Check for dependencies.
258 AC_ARG_WITH([libdbi],
259 [AS_HELP_STRING([--with-libdbi], [libdbi support (default: auto)])],
260 [with_libdbi="$withval"],
261 [with_libdbi="yes"])
262 if test "x$with_libdbi" = "xyes" || test "x$with_libdbi" = "xauto"; then
263 AC_CHECK_HEADERS([dbi/dbi.h],
264 [with_libdbi="yes"],
265 [with_libdbi="no (dbi/dbi.h not found)"])
266 else if test "x$with_libdbi" = "xno"; then
267 with_libdbi="$with_libdbi (disabled on command-line)"
268 else
269 AC_MSG_ERROR([Invalid value for option --with-libdbi=$with_libdbi (expected "yes", "no", or "auto")])
270 fi; fi
271 if test "x$with_libdbi" = "xyes"; then
272 AC_CHECK_LIB([dbi], [dbi_initialize],
273 [with_libdbi="yes"],
274 [with_libdbi="no (libdbi or symbol 'dbi_initialize' not found)"])
275 fi
276 AM_CONDITIONAL([BUILD_WITH_LIBDBI], test "x$with_libdbi" = "xyes")
278 dnl Required for mocking FILE related functions.
279 orig_CFLAGS="$CFLAGS"
280 CFLAGS="$CFLAGS -D_GNU_SOURCE"
281 AC_CHECK_FUNCS([fopencookie],
282 [have_fopencookie="yes"],
283 [have_fopencookie="no (fopencookie not available)"])
284 CFLAGS="$orig_CFLAGS"
285 AM_CONDITIONAL([BUILD_WITH_FOPENCOOKIE], test "x$have_fopencookie" = "xyes")
286 if test "x$have_fopencookie" = "xyes"; then
287 AC_DEFINE([HAVE_FOPENCOOKIE], 1)
288 fi
290 dnl readline support
291 AC_ARG_WITH([readline],
292 [AS_HELP_STRING([--with-readline],
293 [readline support (libedit/libreadline) (default: auto, prefer libedit)])],
294 [readline_support="$withval"],
295 [readline_support="auto"])
297 if test "x$readline_support" = "xyes"; then
298 readline_support="auto"
299 else if test "x$readline_support" != "xauto" \
300 && test "x$readline_support" != "xno" \
301 && test "x$readline_support" != "xlibedit" \
302 && test "x$readline_support" != "xlibreadline"; then
303 AC_MSG_ERROR([Invalid value for option --with-readline=$readline_support (expected "yes", "no", "auto", "libedit", or "libreadline")])
304 fi; fi
306 have_libedit="no"
307 if test "x$readline_support" = "xauto" \
308 || test "x$readline_support" = "xlibedit"; then
309 PKG_CHECK_MODULES([LIBEDIT], [libedit],
310 [have_libedit="yes"], [have_libedit="no"])
311 if test "x$have_libedit" = "xyes"; then
312 AC_CHECK_HEADERS([editline/readline.h], [],
313 [AC_CHECK_HEADERS([readline.h], [],
314 [have_libedit="no (readline header not found"])])
315 fi
316 if test "x$have_libedit" = "xyes"; then
317 AC_CHECK_HEADERS([editline/history.h], [],
318 [AC_CHECK_HEADERS([history.h], [],
319 [have_libedit="no (history header not found"])])
320 fi
321 else
322 have_libedit="disabled on command-line"
323 fi
325 have_libreadline="no"
326 if test "x$have_libedit" != "xyes"; then
327 if test "x$readline_support" = "xauto" \
328 || test "x$readline_support" = "xlibreadline"; then
329 AC_CHECK_LIB([readline], [readline],
330 [have_libreadline="yes"],
331 [have_libreadline="no (libreadline or symbol 'readline' not found)"])
332 fi
333 if test "x$have_libreadline" = "xyes"; then
334 AC_CHECK_HEADERS([readline/readline.h], [],
335 [AC_CHECK_HEADERS([readline.h], [],
336 [have_libreadline="no (readline header not found"])])
337 fi
338 if test "x$have_libreadline" = "xyes"; then
339 AC_CHECK_HEADERS([readline/history.h], [],
340 [AC_CHECK_HEADERS([history.h], [],
341 [have_libreadline="no (history header not found"])])
342 fi
343 else
344 have_libreadline="unchecked (prefer libedit)"
345 fi
347 if test "x$have_libedit" = "xyes"; then
348 READLINE_LIBS="$LIBEDIT_LIBS"
349 READLINE_CFLAGS="$LIBEDIT_CFLAGS"
350 readline_support="libedit"
351 else if test "x$have_libreadline" = "xyes"; then
352 READLINE_LIBS="-lreadline -lhistory"
353 READLINE_CFLAGS=""
354 readline_support="libreadline"
355 else
356 READLINE_LIBS=""
357 READLINE_CFLAGS=""
358 if test "x$readline_support" = "xno"; then
359 AC_MSG_WARN([*** readline support disabled; disabling SysDB client])
360 else if test "x$readline_support" = "xauto"; then
361 AC_MSG_WARN([*** readline not found; disabling SysDB client])
362 else
363 AC_MSG_ERROR([readline not found])
364 fi; fi
365 readline_support="no"
366 fi; fi
367 AC_SUBST([READLINE_LIBS])
368 AC_SUBST([READLINE_CFLAGS])
369 AM_CONDITIONAL([BUILD_CLIENT], test "x$readline_support" != "no")
371 dnl Feature checks.
372 build_documentation="yes"
374 have_xmlto="yes"
375 AC_PATH_PROG([XMLTO], [xmlto])
376 if test "x$XMLTO" = "x"; then
377 have_xmlto="no"
378 build_documentation="no (missing xmlto)"
379 fi
381 have_xsltproc="yes"
382 AC_PATH_PROG([XSLTPROC], [xsltproc])
383 if test "x$XSLTPROC" = "x"; then
384 have_xsltproc="no"
385 build_documentation="no (missing xsltproc)"
386 fi
388 have_a2x="yes"
389 AC_PATH_PROG([A2X], [a2x])
390 if test "x$A2X" = "x"; then
391 have_a2x="no"
392 build_documentation="no (missing a2x)"
393 fi
394 AC_SUBST([A2X])
396 dnl Plugin checks.
397 puppet_storeconfigs_default=$with_libdbi
398 if test "x$puppet_storeconfigs_default" != "xyes"; then
399 puppet_storeconfigs_default="no (requires libdbi)"
400 fi
402 m4_divert_once([HELP_ENABLE], [
403 Backends:])
405 AC_SDB_PLUGIN_INIT
406 AC_SDB_PLUGIN([collectd], [yes],
407 [backend accessing the system statistics collection daemon])
408 AC_SDB_PLUGIN([mk-livestatus], [yes],
409 [backend accessing Nagios/Icinga/Shinken using MK Livestatus])
410 AC_SDB_PLUGIN([puppet-storeconfigs], [$puppet_storeconfigs_default],
411 [backend accessing the Puppet stored configuration database])
413 m4_divert_once([HELP_ENABLE], [
414 Plugins:])
416 AC_SDB_PLUGIN([cname-dns], [yes],
417 [canonicalize hostnames by querying DNS])
418 AC_SDB_PLUGIN([syslog], [yes],
419 [plugin logging to syslog])
421 AM_CONDITIONAL([BUILD_DOCUMENTATION], test "x$build_documentation" = "xyes")
422 AM_CONDITIONAL([BUILD_TESTING], test "x$build_testing" = "xyes")
424 AC_CONFIG_FILES([Makefile doc/Makefile src/Makefile
425 src/liboconfig/Makefile t/Makefile])
426 AC_OUTPUT
428 BUILD_DATE="`date --utc '+%F %T'` (UTC)"
430 AC_MSG_RESULT()
431 AC_MSG_RESULT([$PACKAGE_NAME has been configured successfully.])
432 AC_MSG_RESULT()
433 AC_MSG_RESULT([Run 'make' to compile the software and use 'make install' to])
434 AC_MSG_RESULT([install the package into $prefix.])
435 AC_MSG_RESULT()
436 AC_MSG_RESULT([Configuration summary:])
437 AC_MSG_RESULT()
438 AC_MSG_RESULT([ package version: $PACKAGE_VERSION])
439 AC_MSG_RESULT([ build date: $BUILD_DATE])
440 AC_MSG_RESULT()
441 AC_MSG_RESULT([ Tools:])
442 AC_MSG_RESULT([ AsciiDoc (a2x): . . . . . . $have_a2x])
443 AC_MSG_RESULT([ xmlto / xsltproc: . . . . . $have_xmlto / $have_xsltproc])
444 AC_MSG_RESULT()
445 AC_MSG_RESULT([ Features:])
446 AC_MSG_RESULT([ documentation: . . . . . . $build_documentation])
447 AC_MSG_RESULT([ unit testing: . . . . . . . $build_testing])
448 AC_MSG_RESULT([ stdio mocking: . . . . . $have_fopencookie])
449 AC_MSG_RESULT([ coverage testing: . . . . . $enable_gcov])
450 AC_MSG_RESULT()
451 AC_MSG_RESULT([ Libraries:])
452 AC_MSG_RESULT([ libdbi: . . . . . . . . . . $with_libdbi])
453 AC_MSG_RESULT([ libedit: . . . . . . . . . $have_libedit])
454 AC_MSG_RESULT([ libreadline: . . . . . . . $have_libreadline])
455 AC_MSG_RESULT()
456 AC_MSG_RESULT([ Backends:])
457 AC_MSG_RESULT([ collectd: . . . . . . . . . $enable_collectd])
458 AC_MSG_RESULT([ mk-livestatus: . . . . . . $enable_mk_livestatus])
459 AC_MSG_RESULT([ puppet-storeconfigs: . . . $enable_puppet_storeconfigs])
460 AC_MSG_RESULT()
461 AC_MSG_RESULT([ Plugins:])
462 AC_MSG_RESULT([ cname::dns: . . . . . . . . $enable_cname_dns])
463 AC_MSG_RESULT([ syslog: . . . . . . . . . . $enable_syslog])
464 AC_MSG_RESULT()
465 AC_MSG_RESULT([This package is maintained by $PACKAGE_MAINTAINER.])
466 AC_MSG_RESULT([Please report bugs to $PACKAGE_BUGREPORT.])
467 AC_MSG_RESULT()
469 dnl vim: set tw=78 sw=4 ts=4 noexpandtab :