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