1dnl
2dnl  Copyright 2020 Northern.tech AS
3dnl
4dnl  This file is part of CFEngine 3 - written and maintained by Northern.tech AS.
5dnl
6dnl  This program is free software; you can redistribute it and/or modify it
7dnl  under the terms of the GNU General Public License as published by the
8dnl  Free Software Foundation; version 3.
9dnl
10dnl  This program is distributed in the hope that it will be useful,
11dnl  but WITHOUT ANY WARRANTY; without even the implied warranty of
12dnl  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13dnl  GNU General Public License for more details.
14dnl
15dnl You should have received a copy of the GNU General Public License
16dnl along with this program; if not, write to the Free Software
17dnl Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA
18dnl
19dnl To the extent this program is licensed as part of the Enterprise
20dnl versions of CFEngine, the applicable Commercial Open Source License
21dnl (COSL) may apply to this file if you as a licensee so wish it. See
22dnl included file COSL.txt.
23dnl
24dnl ##########################################################################
25dnl #
26dnl # Build libntech
27dnl #
28dnl # Run ./autogen.sh to build configure script
29dnl #
30dnl ##########################################################################
31
32AC_PREREQ(2.63)
33
34AC_INIT(libntech, 0.1.0)
35AC_CANONICAL_TARGET
36
37dnl
38dnl This program needs to be checked early, as MAKEINFO variable is expanded in
39dnl AM_INIT_AUTOMAKE.
40dnl
41AC_CHECK_PROG(MAKEINFO, makeinfo, makeinfo)
42
43
44dnl Parallel unit tests are causing spurious failures across several systems,
45dnl particularly those doing process testing.
46dnl Unfortunately the option to disable parallel tests (serial-tests) doesn't
47dnl exist in automake 1.11 and earlier, so we need to do this complicated logic
48dnl to determine whether we can disable it or not. If it doesn't exist as an
49dnl option, then serial tests are already the default.
50AC_MSG_CHECKING([automake version])
51m4_define(AUTOMAKE_VERSION, m4_normalize(m4_esyscmd([automake --version 2>&1 | sed -ne '/^automake/{s/^automake.* \([^ ][^ ]*\)$/\1/; p;}'])))
52m4_define(SERIAL_TESTS, m4_bmatch(AUTOMAKE_VERSION, [^1\.\([0-9]\|1[0-1]\)\(\.\|$\)], [], [serial-tests]))
53AC_MSG_RESULT(AUTOMAKE_VERSION)
54
55
56AM_INIT_AUTOMAKE([tar-ustar] SERIAL_TESTS)
57AM_MAINTAINER_MODE([enable])
58
59m4_divert_text([DEFAULTS], [: "${AR_FLAGS=cr}"])
60
61AC_DEFINE(BUILD_YEAR, esyscmd([date +%Y | tr -d '\n']), "Software build year")
62
63AC_DEFINE_UNQUOTED(ABS_TOP_SRCDIR,
64"`cd -- "$srcdir"; pwd`",
65[Absolute path of source tree])
66
67m4_ifdef([AM_SILENT_RULES],[AM_SILENT_RULES([yes])])
68
69AC_CONFIG_HEADERS([config.h])
70
71dnl Libtool madness
72
73AC_CONFIG_MACRO_DIR([m4])
74
75dnl
76dnl hide [s]include macros, so old aclocal (automake < 1.10) won't find them and
77dnl won't complain about something/something.m4 not found
78dnl
79m4_define(incstart,sinc)
80m4_define(incend,lude)
81
82dnl
83dnl Save environment CFLAGS before autoconf starts messing with it.
84dnl It is restored later.
85dnl
86ENV_CFLAGS="$CFLAGS"
87
88dnl ######################################################################
89dnl Checks for programs.
90dnl ######################################################################
91
92AC_PROG_CC
93AC_PROG_MKDIR_P
94AC_EXEEXT
95
96dnl GCC specific flags
97m4_include([m4/cf3_gcc_flags.m4])
98
99# Use either new LT_INIT or old AC_DISABLE_STATIC/AC_PROG_LIBTOOL macros
100m4_ifdef([LT_INIT],
101  [LT_INIT([disable-static])],
102  [AC_DISABLE_STATIC
103   AC_PROG_LIBTOOL])
104
105AM_PROG_LEX
106AC_PROG_YACC
107AC_PROG_INSTALL
108AC_PATH_PROG([PERL], [perl])
109AC_CONFIG_LIBOBJ_DIR(libcompat)
110AC_PATH_PROG(GETCONF, getconf, false, $PATH:$prefix/bin:/usr/bin:/usr/local/bin:/sw/bin)
111AM_CONDITIONAL(CROSS_COMPILING, test "x$cross_compiling" = "xyes")
112
113
114dnl ######################################################################
115dnl Use pthreads if available
116dnl ######################################################################
117
118AC_ARG_WITH([pthreads],
119    [AS_HELP_STRING([--with-pthreads[[=PATH]]],
120                    [Specify path to pthreads, if not the part of operating system])])
121
122if test "x$with_pthreads" != x && test "x$with_pthreads" != "xyes" && test "x$with_pthreads" != "xno"; then
123   LIBS="$LIBS -L$with_pthreads/lib"
124   CPPFLAGS="-I$with_pthreads/include $CPPFLAGS"
125fi
126
127ACX_PTHREAD([],
128            [AC_MSG_ERROR(pthread-compatible library is required to build CFEngine)])
129
130CC="$PTHREAD_CC"
131CFLAGS="$PTHREAD_CFLAGS $CFLAGS"
132LIBS="$PTHREAD_LIBS $LIBS"
133
134dnl ######################################################################
135dnl Whether to build extensions as builtin extensions or a separate
136dnl plugin. The default is plugin.
137dnl --enable-builtin-extensions is the default on Windows, and can be
138dnl used on other platforms for debugging purposes, but isn't otherwise
139dnl supported.
140dnl ######################################################################
141
142AC_ARG_ENABLE([builtin-extensions], [AS_HELP_STRING([Build binaries with builtin extensions])],
143              [],
144              [
145                  AS_CASE([${target_os}], [mingw*], [enable_builtin_extensions=yes], [enable_builtin_extensions=no])
146              ])
147AM_CONDITIONAL([BUILTIN_EXTENSIONS], [test "x$enable_builtin_extensions" = "xyes"])
148AS_IF([test "x$enable_builtin_extensions" = "xyes"], [AC_DEFINE([BUILTIN_EXTENSIONS], [1], [Define if you want builtin Enterprise extensions])])
149AC_SUBST([enable_builtin_extensions])
150
151dnl ######################################################################
152dnl Configure files layout
153dnl ######################################################################
154
155AC_ARG_ENABLE([fhs],
156        [AS_HELP_STRING([--enable-fhs], [Enable FHS compliance. Defaults to custom CFEngine files layout])])
157
158#
159# pkglibdir/pkgdatadir are not overridable, so use our own invention instead.
160#
161
162AS_IF([test x"$enable_fhs" = xyes], [
163  projlibdir='${pkglibdir}'
164  WORKDIR='${localstatedir}/lib/${PACKAGE}'
165  MASTERDIR='default'
166  INPUTDIR='default'
167  LOGDIR='${localstatedir}/log/${PACKAGE}'
168  PIDDIR='${runstatedir:-${localstatedir}/run}/${PACKAGE}'
169  STATEDIR='default'
170], [
171  if test x"$prefix" = xNONE || test x"$prefix" = x/var/cfengine; then
172    prefix=/var/cfengine
173    case "$target_os" in
174      mingw*)
175        WORKDIR=$(cmd /c "echo %PROGRAMFILES%\\Cfengine" | sed 's/\\/\\\\/g')
176        MASTERDIR=default
177        INPUTDIR=default
178        LOGDIR=$(cmd /c "echo %PROGRAMFILES%\\Cfengine" | sed 's/\\/\\\\/g')
179        PIDDIR=$(cmd /c "echo %PROGRAMFILES%\\Cfengine" | sed 's/\\/\\\\/g')
180        STATEDIR=default
181      ;;
182      *)
183        WORKDIR=/var/cfengine
184        MASTERDIR=default
185        INPUTDIR=default
186        LOGDIR=/var/cfengine
187        PIDDIR=/var/cfengine
188        STATEDIR=default
189      ;;
190    esac
191  else
192    WORKDIR="${localstatedir}/${PACKAGE}"
193    MASTERDIR="default"
194    INPUTDIR="default"
195    LOGDIR="${localstatedir}/${PACKAGE}"
196    PIDDIR="${localstatedir}/${PACKAGE}"
197    STATEDIR="default"
198  fi
199  bindir="${bindir:-${exec_prefix}/bin}"
200  projlibdir='${libdir}'
201])
202
203AC_SUBST(projlibdir)
204
205dnl ######################################################################
206dnl Platform specific compiler flags.
207dnl ######################################################################
208
209AS_CASE([${target_os}],
210  [mingw*],
211    # Disable printf format warnings, because our wrapper supports more
212    # flags than vanilla Windows version, so they are false positives.
213    [CFLAGS="$CFLAGS -Wno-format"])
214
215dnl ######################################################################
216dnl Enable debugging
217dnl ######################################################################
218
219AC_ARG_ENABLE(debug,
220              AS_HELP_STRING([--enable-debug], [Enable debugging]),
221              [debug=$enableval],
222              [debug=no])
223AM_CONDITIONAL([NDEBUG], [test x"$debug" = x"no"])
224
225dnl Even though CFLAGS should contain the command-line CFLAGS
226dnl as last, some macro seem to messes the order up and insert
227dnl its own optimisation flags as well. So we append ENV_CFLAGS
228dnl at the end manually, causing a bit of flag duplication.
229
230if test x"$debug" = x"yes"
231then
232    CFLAGS="$CFLAGS -g3 -O0 $ENV_CFLAGS"
233else
234    CFLAGS="$CFLAGS -O2 -DNDEBUG $ENV_CFLAGS"
235fi
236
237dnl ######################################################################
238dnl Checks for libraries.
239dnl ######################################################################
240
241dnl Now check for database connectors
242
243# TODO remove
244AC_ARG_WITH([sql],
245    [AS_HELP_STRING([--with-sql[[=PATH]]],
246        [Enable SQL database connectors (deprecated, use \
247        --with[[out]]-postgresql and --with[[out]]-mysql instead)])
248    ],
249    [with_postgresql=$with_sql; with_mysql=$with_sql],
250    [])
251
252dnl PostgreSQL
253
254AC_ARG_WITH([postgresql],
255    [AS_HELP_STRING([--with-postgresql[[=PATH]]],
256        [Enable PostgreSQL connector])
257    ],
258    [],
259    [with_postgresql=check])
260
261if test "x$with_postgresql" != "xno"
262then
263    if test "x$with_postgresql" != xyes && test "x$with_postgresql" != xcheck
264    then
265        PG_CONFIG=$with_postgresql/bin/pg_config
266    else
267        PG_CONFIG=pg_config
268    fi
269
270    # pg_config is only for native builds
271    if test "x$cross_compiling" = "xno"
272    then
273        if test x`which $PG_CONFIG` != x
274        then
275            pg_include_dir=`$PG_CONFIG --includedir`
276            if test -n "$pg_include_dir"
277            then
278                POSTGRESQL_CPPFLAGS="-I$pg_include_dir"
279            fi
280        fi
281    fi
282
283    CF3_WITH_LIBRARY(postgresql,
284        [AC_CHECK_LIB(pq, PQconnectdb,
285            [],
286            [if test "x$with_postgresql" != xcheck; then
287                AC_MSG_ERROR(Cannot find PostgreSQL client library); fi]
288         )
289         AC_CHECK_HEADERS(libpq-fe.h,
290             [],
291             [if test "x$with_postgresql" != xcheck; then
292                 AC_MSG_ERROR(Cannot find PostgreSQL client library); fi]
293         )]
294    )
295fi
296
297dnl MySQL
298
299AC_ARG_WITH([mysql],
300    [AS_HELP_STRING([--with-mysql[[=PATH]]],
301        [Enable MySQL connector])
302    ],
303    [],
304    [with_mysql=check])
305
306if test "x$with_mysql" != "xno"
307then
308    if test "x$with_mysql" != xyes &&
309       test "x$with_mysql" != xcheck
310    then
311        MYSQL_CONFIG=$with_mysql/bin/mysql_config
312    else
313        MYSQL_CONFIG=mysql_config
314    fi
315
316    # mysql_config is only for native builds
317    if test "x$cross_compiling" = "xno"
318    then
319        if test x`which $MYSQL_CONFIG` != x
320        then
321            mysql_include_dir=`$MYSQL_CONFIG --include`
322            if test -n "$mysql_include_dir"
323            then
324                MYSQL_CPPFLAGS="$mysql_include_dir"
325            fi
326        fi
327    fi
328
329    CF3_WITH_LIBRARY(mysql,
330        [AC_CHECK_LIB(mysqlclient, mysql_real_connect,
331            [],
332            [if test "x$with_mysql" != xcheck; then
333                AC_MSG_ERROR(Cannot find MySQL client library); fi]
334        )
335        AC_CHECK_HEADERS(mysql.h,
336            [],
337            [if test "x$with_mysql" != xcheck; then
338                AC_MSG_ERROR(Cannot find MySQL clientlibrary); fi]
339        )
340        AC_CHECK_LIB(mysqlclient, EVP_CIPHER_CTX_init,
341            [AC_MSG_ERROR([MySQL client library exports symbols clashing \
342                with OpenSSL. Get the update from distribution provider, \
343                recompile MySQL library or disable MySQL connector. See \
344                http://bugs.mysql.com/bug.php?id=65055 for details.])
345            ]
346        )]
347    )
348fi
349
350dnl
351dnl In-process databases
352dnl
353
354dnl QDBM
355
356AC_ARG_WITH([qdbm],
357    [AS_HELP_STRING([--with-qdbm[[=PATH]]], [use QDBM to store runtime data])])
358AS_IF([test -n "$with_qdbm" && test "x$with_qdbm" != "xno"], [WITH_QDBM=1], [WITH_QDBM=0])
359
360if test $WITH_QDBM = 1; then
361  CF3_WITH_LIBRARY(qdbm, [
362    AC_CHECK_LIB(qdbm, dpopen, [], [AC_MSG_ERROR(Cannot find QDBM)])
363    AC_CHECK_HEADERS(depot.h, [], [AC_MSG_ERROR(Cannot find QDBM)])
364    AC_DEFINE(QDB, 1, [Define if QDBM is available])
365  ])
366fi
367
368dnl Tokyo Cabinet
369
370AC_ARG_WITH([tokyocabinet],
371    [AS_HELP_STRING([--with-tokyocabinet[[=PATH]]], [use Tokyo Cabinet to store runtime data])])
372
373AS_IF([test $WITH_QDBM -eq 0 && test -n "$with_tokyocabinet" && test "x$with_tokyocabinet" != "xno"], [WITH_TOKYO=1], [WITH_TOKYO=0])
374
375if test $WITH_TOKYO = 1; then
376  CF3_WITH_LIBRARY(tokyocabinet, [
377    AC_CHECK_LIB(tokyocabinet, tchdbnew, [], [AC_MSG_ERROR(Cannot find Tokyo Cabinet)])
378    AC_CHECK_HEADERS(tcutil.h, [], [AC_MSG_ERROR(Cannot find Tokyo Cabinet)])
379    AC_CHECK_HEADERS(tchdb.h, [], [AC_MSG_ERROR(Cannot find Tokyo Cabinet)])
380    AC_DEFINE(TCDB, 1, [Define if Tokyo Cabinet is available.])
381  ])
382fi
383
384dnl OpenLDAP Lightning MDB
385
386AC_ARG_WITH([lmdb],
387    [AS_HELP_STRING([--with-lmdb[[=PATH]]], [use Lightning MDB to store runtime data])])
388
389AS_IF([test $WITH_TOKYO -eq 0 && test $WITH_QDBM -eq 0 && (! test -n "$with_lmdb" || test "x$with_lmdb" != "xno")], [WITH_LMDB=1], [WITH_LMDB=0])
390
391if test $WITH_LMDB = 1; then
392  CF3_WITH_LIBRARY(lmdb, [
393    AC_CHECK_LIB(lmdb, mdb_dbi_open, [], [AC_MSG_ERROR(Cannot find Lightning MDB)])
394    AC_CHECK_HEADERS(lmdb.h, [], [AC_MSG_ERROR(Cannot find Lightning MDB)])
395    AC_DEFINE(LMDB, 1, [Define if Lightning MDB is available])
396  ])
397fi
398
399if test $WITH_QDBM -eq 0 && test $WITH_TOKYO -eq 0 && test $WITH_LMDB -eq 0; then
400   AC_MSG_ERROR(Either Tokyo Cabinet, LMDB, or QDBM must be selected to compile CFEngine)
401fi
402
403dnl
404dnl OpenSSL
405dnl
406
407AC_ARG_WITH(openssl,
408    [AS_HELP_STRING([--with-openssl[[=PATH]]],
409    [Specify OpenSSL path])], [], [with_openssl=yes])
410
411if  test -d /usr/local/Cellar/openssl/ && \
412    test -d /usr/local/opt/openssl/ && \
413    test "x$with_openssl" = "xyes" ; then
414    with_openssl="/usr/local/opt/openssl"
415    echo "OS X Homebrew detected"
416    echo "Defaulting to: --with-openssl=$with_openssl"
417fi
418
419if test "x$with_openssl" != "xno"; then
420  CF3_WITH_LIBRARY(openssl, [
421    AC_CHECK_LIB(crypto, RSA_generate_key_ex, [], [])
422    AC_CHECK_LIB(ssl, SSL_free, [], [])
423    AC_CHECK_DECLS([SSL_CTX_clear_options], [], [], [[#include <openssl/ssl.h>]])
424    AC_CHECK_HEADERS([openssl/opensslv.h], [], [AC_MSG_ERROR(Cannot find OpenSSL)])
425    AC_MSG_CHECKING(for OpenSSL version)
426    AC_PREPROC_IFELSE([AC_LANG_SOURCE([[
427    #include <openssl/opensslv.h>
428
429    #if OPENSSL_VERSION_NUMBER < 0x0090602fL
430    #This OpenSSL is too old
431    #endif
432    ]])],[AC_MSG_RESULT(OK)],[AC_MSG_ERROR(This release of CFEngine requires OpenSSL >= 0.9.7)])
433
434    if test "x$ac_cv_lib_crypto_RSA_generate_key_ex" = "xyes" ; then
435       AC_DEFINE(OPENSSL_NO_DEPRECATED, 1, [Define if non deprecated API is available.])
436    fi
437
438    if test "x$ac_cv_lib_crypto_RSA_generate_key_ex" = "xno" && \
439       test "x$ac_cv_lib_crypto_RSA_generate_key" = "xno" ; then
440       AC_MSG_ERROR(Cannot find OpenSSL)
441    fi
442
443    AC_CHECK_DECL([SSL_OP_NO_TLSv1_1],
444     [AC_DEFINE([HAVE_TLS_1_1], [1], [Define if TLS 1.1 is supported by OpenSSL])],
445     [], [[#include <openssl/ssl.h>]]
446     )
447    AC_CHECK_DECL([SSL_OP_NO_TLSv1_2],
448     [AC_DEFINE([HAVE_TLS_1_2], [1], [Define if TLS 1.2 is supported by OpenSSL])],
449     [], [[#include <openssl/ssl.h>]]
450     )
451    AC_CHECK_DECL([SSL_OP_NO_TLSv1_3],
452     [AC_DEFINE([HAVE_TLS_1_3], [1], [Define if TLS 1.3 is supported by OpenSSL])],
453     [], [[#include <openssl/ssl.h>]]
454     )
455  ])
456  AC_DEFINE(WITH_OPENSSL, 1, [Define if OpenSSL is being used])
457  AM_CONDITIONAL(WITH_OPENSSL, true)
458else
459  AM_CONDITIONAL(WITH_OPENSSL, false)
460fi
461
462dnl PCRE
463
464AC_ARG_WITH([pcre], [AS_HELP_STRING([--with-pcre[[=PATH]]], [Specify PCRE path])], [], [with_pcre=yes])
465
466if test "x$with_pcre" != "xno"; then
467  CF3_WITH_LIBRARY(pcre, [
468    AC_CHECK_LIB(pcre, pcre_exec, [], [AC_MSG_ERROR(Cannot find PCRE)])
469    AC_CHECK_HEADERS(
470      [pcre.h],
471      [],
472      [AC_CHECK_HEADERS(
473        [pcre/pcre.h],
474        [PCRE_CPPFLAGS="-Ipcre"],
475        AC_MSG_ERROR(Cannot find PCRE)
476      )]
477    )
478  ])
479  AC_DEFINE(WITH_PCRE, 1, [Define if PCRE is being used])
480  AM_CONDITIONAL(WITH_PCRE, true)
481else
482  AM_CONDITIONAL(WITH_PCRE, false)
483fi
484
485dnl libvirt
486
487AC_ARG_WITH([libvirt],
488    [AS_HELP_STRING([--with-libvirt[[=PATH]]], [support virtual machine management])],
489    [], [with_libvirt=check])
490
491if test "x$with_libvirt" != xno
492then
493   CF3_WITH_LIBRARY(libvirt, [
494      AC_CHECK_LIB(virt, virConnectOpen, [], [if test "x$with_libvirt" != xcheck; then AC_MSG_ERROR(Cannot find libvirt library); fi])
495      AC_CHECK_HEADERS(libvirt/libvirt.h, [], [if test "x$with_libvirt" != xcheck; then AC_MSG_ERROR(Cannot find libvirt library headers); fi])
496   ])
497fi
498
499dnl  BIG FAT WARNING FOR AC_CHECK_LIB: *always* leave the
500dnl  "action-if-yes" parameter empty else LIBS is not changed and C
501dnl  define is not generated!  Or use AC_SEARCH_LIBS for a better
502dnl  interface.
503
504dnl libacl
505dnl It is enough for any of the header files [acl.h sys/acl.h acl/libacl.h] to be present
506
507AC_ARG_WITH([libacl],
508    [AS_HELP_STRING([--with-libacl[[=PATH]]], [Specify libacl path])], [], [with_libacl=check])
509
510if test "x$with_libacl" != xno
511then
512  CF3_WITH_LIBRARY(libacl, [
513    AC_CHECK_LIB(acl, acl_init,
514      [],
515      [if test "x$with_libacl" != xcheck; then AC_MSG_ERROR(Cannot find libacl library); fi])
516    AC_CHECK_HEADERS([acl.h sys/acl.h acl/libacl.h],
517      [libacl_header_found=yes])
518    if test "x$libacl_header_found" != "xyes" && test "x$with_libacl" != xcheck;
519    then
520      AC_MSG_ERROR(Cannot find libacl library headers);
521    fi
522  ])
523fi
524
525dnl libcurl
526
527AC_ARG_WITH([libcurl],
528    [AS_HELP_STRING([--with-libcurl[[=PATH]]], [Specify libcurl path])], [], [with_libcurl=check])
529
530if test "x$with_libcurl" != xno
531then
532  CF3_WITH_LIBRARY(libcurl, [
533    AC_CHECK_LIB(curl, curl_global_init,
534      [],
535      [  libcurl_lib_found=no;
536         if test "x$with_libcurl" != xcheck;
537         then
538             AC_MSG_ERROR(Cannot find libcurl library);
539         fi
540      ])
541    AC_CHECK_HEADERS([curl/curl.h],
542      [libcurl_header_found=yes],
543      [if test "x$with_libcurl" != xcheck; then AC_MSG_ERROR(Cannot find libcurl header files); fi])
544  ])
545fi
546
547AM_CONDITIONAL(HAVE_LIBCURL,
548        [test "x$libcurl_lib_found" != xno && test "x$libcurl_header_found" = xyes])
549
550dnl libyaml
551
552AC_ARG_WITH([libyaml],
553    [AS_HELP_STRING([--with-libyaml[[=PATH]]], [Specify libyaml path])], [], [with_libyaml=check])
554
555if test "x$with_libyaml" != xno
556then
557  CF3_WITH_LIBRARY(libyaml, [
558    AC_CHECK_LIB(yaml, yaml_parser_initialize,
559      [],
560      [if test "x$with_libyaml" != xcheck; then AC_MSG_ERROR(Cannot find libyaml library); fi])
561    AC_CHECK_HEADERS(yaml.h,
562      [libyaml_header_found=yes],
563      [if test "x$with_libyaml" != xcheck; then AC_MSG_ERROR(Cannot find libyaml header files); fi])
564  ])
565fi
566
567dnl libxml2
568
569AC_ARG_WITH([libxml2],
570    [AS_HELP_STRING([--with-libxml2[[=PATH]]],
571        [Specify libxml2 path])
572    ],
573    [],
574    [with_libxml2=check])
575
576if test "x$with_libxml2" != xno
577then
578    if test "x$with_libxml2" != xyes &&
579       test "x$with_libxml2" != xcheck
580    then
581        XML2_CONFIG=$with_libxml2/bin/xml2-config
582    else
583        XML2_CONFIG=xml2-config
584    fi
585
586    # xml2-config is only for native builds
587    if test "x$cross_compiling" = "xno" && test x`which $XML2_CONFIG` != x
588    then
589        xml2_include_dir=`$XML2_CONFIG --cflags`
590        if test -n "$xml2_include_dir"
591        then
592            LIBXML2_CPPFLAGS="$xml2_include_dir"
593        fi
594    else                # xml2-config not found
595        # if a path, e.g. /var/cfengine was given, then we
596        # must take into account that libxml2 includes are in
597        # /var/cfengine/include/libxml2
598        LIBXML2_CPPFLAGS=-I$with_libxml2/include/libxml2
599    fi
600
601    CF3_WITH_LIBRARY(libxml2,
602        [AC_CHECK_LIB(xml2, xmlFirstElementChild,
603            [],
604            [if test "x$with_libxml2" != xcheck; then
605                AC_MSG_ERROR(Cannotfind libxml2); fi]
606        )
607        AC_CHECK_HEADERS([libxml/xmlwriter.h], [break],
608            [if test "x$with_libxml2" != xcheck; then
609                AC_MSG_ERROR(Cannot find libxml2); fi]
610        )]
611    )
612fi
613
614AM_CONDITIONAL([HAVE_LIBXML2],
615    [test "x$with_libxml2" != xno &&
616     test "x$ac_cv_lib_xml2_xmlFirstElementChild" = xyes])
617
618dnl avahi
619
620AC_CHECK_HEADERS(avahi-client/client.h,
621    AM_CONDITIONAL(HAVE_AVAHI_CLIENT, true),
622    AM_CONDITIONAL(HAVE_AVAHI_CLIENT, false),
623    [])
624AC_CHECK_HEADERS(avahi-common/address.h,
625    AM_CONDITIONAL(HAVE_AVAHI_COMMON, true),
626    AM_CONDITIONAL(HAVE_AVAHI_COMMON, false),
627    [])
628
629dnl
630
631dnl ######################################################################
632dnl Checks for header files.
633dnl ######################################################################
634
635AC_CHECK_HEADERS(unistd.h stdlib.h sys/loadavg.h)
636AC_CHECK_HEADERS(sys/param.h sys/resource.h)
637
638# sys/param.h is required for sys/mount.h on OpenBSD
639AC_CHECK_HEADERS(sys/mount.h, [], [], [AC_INCLUDES_DEFAULT
640#ifdef HAVE_SYS_PARAM_H
641# include <sys/param.h>
642#endif
643])
644
645# Required on BSD to get struct sockaddr_dl (for retrieving MAC addresses from getifaddrs())
646AC_CHECK_HEADERS(net/if_dl.h)
647
648# Required on Solaris to get struct arpreq (for retrieving MAC addresses)
649AC_CHECK_HEADERS(net/if_arp.h, , , [AC_INCLUDES_DEFAULT
650#include <sys/socket.h>
651])
652
653AC_CHECK_HEADERS(utime.h)
654AC_CHECK_HEADERS(time.h)
655AC_CHECK_HEADERS(sys/time.h)
656AC_CHECK_HEADERS(malloc.h sys/malloc.h)
657AC_CHECK_HEADERS(vfs.h)
658AC_CHECK_HEADERS(sys/vfs.h)
659AC_CHECK_HEADERS(sys/sockio.h)
660AC_CHECK_HEADERS(sys/statvfs.h)
661AC_CHECK_HEADERS(sys/statfs.h)
662AC_CHECK_HEADERS(fcntl.h)
663AC_CHECK_HEADERS(sys/filesys.h)
664AC_CHECK_HEADERS(dustat.h)
665AC_CHECK_HEADERS(sys/systeminfo.h)
666AC_CHECK_HEADERS(ieeefp.h)
667AC_CHECK_HEADERS(winsock2.h)
668AC_CHECK_HEADERS(ws2tcpip.h)
669AC_CHECK_HEADERS(zone.h)
670AC_CHECK_HEADERS(sys/uio.h)
671AC_CHECK_HEADERS_ONCE([sys/sysmacros.h]) dnl glibc deprecated inclusion in sys/type.h
672AC_CHECK_HEADERS(sys/types.h)
673AC_CHECK_HEADERS(sys/mpctl.h) dnl For HP-UX $(sys.cpus) - Mantis #1069
674AC_CHECK_HEADERS(shadow.h)
675AC_CHECK_HEADERS(sys/jail.h, [], [], [AC_INCLUDES_DEFAULT
676#ifdef HAVE_SYS_PARAM_H
677# include <sys/param.h>
678#endif
679])
680AC_CHECK_HEADERS(net/route.h netinet/in.h netinet/ip.h)
681
682
683AC_HEADER_STDC
684AC_HEADER_TIME
685AC_HEADER_SYS_WAIT
686AC_HEADER_DIRENT
687AC_HEADER_STDBOOL
688
689dnl ######################################################################
690dnl Checks for data types
691dnl ######################################################################
692
693AC_TYPE_MODE_T
694AC_TYPE_SIZE_T
695AC_TYPE_UID_T
696AC_TYPE_PID_T
697AC_CHECK_TYPES(clockid_t, [], [], [[
698#ifdef HAVE_TIME_H
699# include <time.h>
700#endif
701]])
702
703AC_CHECK_TYPES(socklen_t, [], [], [[
704#ifdef HAVE_SYS_TYPES_H
705# include <sys/types.h>
706#endif
707
708#include <sys/socket.h>
709]])
710
711dnl ######################################################################
712dnl Checks for typedefs, structures, and compiler characteristics.
713dnl ######################################################################
714
715AC_C_CONST
716
717AC_FUNC_FSEEKO
718AC_SYS_LARGEFILE
719AC_TYPE_OFF_T
720
721#
722# AC_SYS_LARGEFILE correctly figures out necessary macros for large files, but
723# on AIX there is a gotcha:
724#
725# Code generated by flex #includes <stdio.h> at the beginning of the file, which
726# picks up 32-bit wide off_t. Then it #includes <config.h> which provides LFS
727# macros, and finally it includes another system header, now with 64-bit wide
728# off_t, which causes a conflict.
729#
730if test "x$ac_cv_sys_large_files" = x1; then
731  CPPFLAGS="-D_LARGE_FILES=1 $CPPFLAGS"
732fi
733
734dnl ######################################################################
735dnl Check for libraries
736dnl ######################################################################
737
738AC_CHECK_LIB(m, sqrt)
739AC_CHECK_LIB(rt, clock_gettime)
740AC_CHECK_LIB(dl, dlopen)
741
742dnl ######################################################################
743dnl Check for special functions
744dnl ######################################################################
745
746AC_CHECK_DECLS(clock_gettime, [], [], [[#include <time.h>]])
747AC_REPLACE_FUNCS(clock_gettime)
748
749AC_CHECK_DECLS(unsetenv)
750AC_REPLACE_FUNCS(unsetenv)
751
752AC_CHECK_DECLS(strnlen)
753AC_REPLACE_FUNCS(strnlen)
754
755cf3_FUNC_STRNDUP
756
757AC_CHECK_DECLS(seteuid)
758AC_REPLACE_FUNCS(seteuid)
759
760AC_CHECK_DECLS(setlinebuf)
761AC_REPLACE_FUNCS(setlinebuf)
762
763AC_CHECK_DECLS(strlcat)
764AC_REPLACE_FUNCS(strlcat)
765
766AC_CHECK_DECLS(strlcpy)
767AC_REPLACE_FUNCS(strlcpy)
768
769AC_CHECK_DECLS(realpath)
770
771AC_CHECK_DECLS(strdup)
772AC_REPLACE_FUNCS(strdup)
773
774AC_CHECK_DECLS(memrchr)
775AC_REPLACE_FUNCS(memrchr)
776
777AC_CHECK_DECLS(round, [], [], [[#include <math.h>]])
778AC_REPLACE_FUNCS(round)
779
780AC_CHECK_DECLS(nanosleep)
781AC_REPLACE_FUNCS(nanosleep)
782
783AC_CHECK_DECLS(memdup)
784AC_REPLACE_FUNCS(memdup)
785
786AC_CHECK_DECLS(memmem)
787AC_REPLACE_FUNCS(memmem)
788
789AC_CHECK_DECLS(srand48)
790AC_REPLACE_FUNCS(srand48)
791
792AC_CHECK_DECLS(drand48)
793AC_REPLACE_FUNCS(drand48)
794
795AC_CHECK_DECLS(strerror)
796AC_REPLACE_FUNCS(strerror)
797
798AC_CHECK_DECLS(strstr)
799AC_REPLACE_FUNCS(strstr)
800
801AC_CHECK_DECLS(strcasestr)
802AC_REPLACE_FUNCS(strcasestr)
803
804AC_CHECK_DECLS(strcasecmp)
805AC_REPLACE_FUNCS(strcasecmp)
806
807AC_CHECK_DECLS(strncasecmp)
808AC_REPLACE_FUNCS(strncasecmp)
809
810AC_CHECK_DECLS(strsep)
811AC_REPLACE_FUNCS(strsep)
812
813AC_CHECK_DECLS(strsignal)
814AC_REPLACE_FUNCS(strsignal)
815
816AC_CHECK_DECLS(gmtime_r, [], [], [[#include <time.h>]])
817AC_REPLACE_FUNCS(gmtime_r)
818
819AC_CHECK_DECLS(getline, [], [], [#define _GNU_SOURCE 1
820AC_INCLUDES_DEFAULT])
821AC_REPLACE_FUNCS(getline)
822
823AC_CHECK_DECLS(strchrnul, [], [], [#define _GNU_SOURCE 1
824AC_INCLUDES_DEFAULT])
825AC_REPLACE_FUNCS(strchrnul)
826
827AC_CHECK_DECLS(localtime_r, [], [], [[#include <time.h>]])
828AC_REPLACE_FUNCS(localtime_r)
829
830AC_CHECK_DECLS(fgetgrent, [], [], [[#include <grp.h>]])
831
832AC_CHECK_DECLS(isfinite, [], [], [[#include <math.h>]])
833
834AC_CHECK_FUNCS(getpwent setpwent endpwent)
835
836AC_CHECK_FUNCS(fgetspent lckpwdf ulckpwdf)
837AC_CHECK_LIB([sec], [fgetspent], [
838    AC_DEFINE([HAVE_LIBSEC], 1, [Define if -lsec is available])
839    AC_DEFINE([HAVE_FGETSPENT], 1, [Define if fgetspent is available])
840    LIBS="-lsec $LIBS"
841])
842
843AC_CHECK_DECLS(getloadavg)
844AC_FUNC_GETLOADAVG
845
846AC_C_BIGENDIAN
847AC_CHECK_HEADERS([endian.h])
848AC_CHECK_DECLS(le32toh, [], [], [[#include <endian.h>]])
849
850AC_CHECK_DECLS(closefrom, [], [], [[#include <unistd.h>
851                                    #include <stdlib.h>]])
852AC_REPLACE_FUNCS(closefrom)
853
854AC_CHECK_HEADERS([sys/pstat.h])
855AC_CHECK_FUNCS(pstat_getfile2)
856
857CF3_PATH_ROOT_PROG([CHPASSWD], [chpasswd], [], [/sbin:/usr/sbin:/bin:/usr/bin:$PATH])
858AS_IF([test "x$CHPASSWD" != "x"],
859      [AC_DEFINE(HAVE_CHPASSWD, 1, [Define if chpasswd tool is present])]
860      [AC_DEFINE_UNQUOTED(CHPASSWD, ["$CHPASSWD"], [Path to chpasswd tool])]
861     )
862
863dnl AIX has this.
864CF3_PATH_ROOT_PROG([PWDADM], [pwdadm], [], [/sbin:/usr/sbin:/bin:/usr/bin:$PATH])
865AS_IF([test "x$PWDADM" != "x"],
866      [AC_DEFINE(HAVE_PWDADM, 1, [Define if pwdadm tool is present])]
867      [AC_DEFINE_UNQUOTED(PWDADM, ["$PWDADM"], [Path to pwdadm tool])]
868     )
869
870CF3_PATH_ROOT_PROG([USERADD], [useradd], [], [/sbin:/usr/sbin:/bin:/usr/bin:$PATH])
871AS_IF([test "x$USERADD" != "x"],
872      [AC_DEFINE(HAVE_USERADD, 1, [Define if useradd tool is present])]
873      [AC_DEFINE_UNQUOTED(USERADD, ["$USERADD"], [Path to useradd tool])]
874     )
875
876CF3_PATH_ROOT_PROG([USERMOD], [usermod], [], [/sbin:/usr/sbin:/bin:/usr/bin:$PATH])
877AS_IF([test "x$USERMOD" != "x"],
878      [AC_DEFINE(HAVE_USERMOD, 1, [Define if usermod tool is present])]
879      [AC_DEFINE_UNQUOTED(USERMOD, ["$USERMOD"], [Path to usermod tool])]
880     )
881
882CF3_PATH_ROOT_PROG([USERDEL], [userdel], [], [/sbin:/usr/sbin:/bin:/usr/bin:$PATH])
883AS_IF([test "x$USERDEL" != "x"],
884      [AC_DEFINE(HAVE_USERDEL, 1, [Define if userdel tool is present])]
885      [AC_DEFINE_UNQUOTED(USERDEL, ["$USERDEL"], [Path to userdel tool])]
886     )
887
888AS_IF([test "x$USERADD" != x && \
889       test "x$USERMOD" != x && test "x$USERDEL" != x],
890      [have_userprogs=yes],
891      [have_userprogs=no]
892)
893
894
895AC_ARG_WITH([pam], AS_HELP_STRING([--with-pam], [Compile with PAM support]))
896AS_IF([test x$with_pam != xno],
897[
898  CF3_WITH_LIBRARY(pam, [
899    AC_CHECK_LIB(pam, pam_start)
900    AC_CHECK_HEADERS([security/pam_appl.h])
901  ])
902  dnl These platforms must have pam, others can have it, but not required.
903  AS_CASE([$target_os],
904          [*gnu*|*solaris*|*aix*|*hpux*|*hp-ux*], [
905              AS_IF([test "x$ac_cv_lib_pam_pam_start" != "xyes"],
906                    [AC_MSG_ERROR(Cannot find PAM library)]
907              )
908              AS_IF([test "x$ac_cv_header_security_pam_appl_h" != "xyes"],
909                    [AC_MSG_ERROR(Cannot find PAM headers)]
910          )]
911  )
912  AS_IF([test "x$ac_cv_lib_pam_pam_start" = "xyes" && \
913         test "x$ac_cv_header_security_pam_appl_h" = "xyes"],
914        [have_pam=yes],
915        [have_pam=no]
916  )
917  AC_CHECK_FUNCS(fgetpwent fgetgrent)
918  AS_IF([test "x$have_pam" = "xyes" && \
919      test "x$have_userprogs" = "xyes" && \
920      test "x$ac_cv_func_fgetpwent" = "xyes" && \
921      test "x$ac_cv_func_fgetgrent" = "xyes"],
922  [
923      users_promises_ok=yes
924  ],[
925      users_promises_ok=no
926  ])
927], [
928  users_promises_ok=no
929])
930AM_CONDITIONAL(HAVE_USERS_PROMISE_DEPS, [test "x$users_promises_ok" = "xyes"])
931
932AC_CHECK_DECLS(getnetgrent, [], [], [[#include <netdb.h>]])
933AC_CHECK_FUNCS(getnetgrent)
934
935AC_CHECK_DECLS(setnetgrent, [], [], [[#include <netdb.h>]])
936AC_CHECK_FUNCS(setnetgrent)
937AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <netdb.h>]],
938                                   [[extern int setnetgrent(const char *)]])],
939  [AC_DEFINE([SETNETGRENT_RETURNS_INT], 1, [Whether setnetgrent returns int])],
940  [AC_DEFINE([SETNETGRENT_RETURNS_INT], 0, [Whether setnetgrent returns int])])
941
942
943AC_CHECK_DECLS(endnetgrent, [], [], [[#include <netdb.h>]])
944AC_CHECK_FUNCS(endnetgrent)
945AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <netdb.h>]],
946                                   [[extern int endnetgrent(const char *)]])],
947  [AC_DEFINE([ENDNETGRENT_RETURNS_INT], 1, [Whether endnetgrent returns int])],
948  [AC_DEFINE([ENDNETGRENT_RETURNS_INT], 0, [Whether endnetgrent returns int])])
949
950
951AC_CHECK_FUNCS(sendto)
952AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/types.h>
953                                     #include <sys/socket.h>]],
954                                   [[extern ssize_t sendto(int sockfd, const void *buf, size_t len, int flags, const struct sockaddr *dest_addr, socklen_t addrlen)]])],
955    [AC_DEFINE([SENDTO_RETURNS_SSIZE_T], 1, [Whether sendto returns ssize_t])],
956    [AC_DEFINE([SENDTO_RETURNS_SSIZE_T], 0, [Whether sendto does not returns ssize_t])])
957
958CF3_CHECK_PROPER_FUNC([ctime],
959  [],
960  [[#error ctime(3) may produce different results on different OSes. Let's have our POSIX-compliant implementation all the time]],
961  [#define ctime rpl_ctime])
962CF3_REPLACE_PROPER_FUNC([ctime])
963
964dnl Check whether mkdir accepts two parameters
965CF3_CHECK_PROPER_FUNC([mkdir],
966  [[#include <sys/stat.h>
967    #include <sys/types.h>]],
968  [[int mkdir(const char *pathname, mode_t mode);]],
969  [#define mkdir rpl_mkdir])
970
971dnl Check for Win32 stat. We don't know to detect improper stat during
972dnl compilation, so we resort to OS type detection.
973
974CF3_CHECK_PROPER_FUNC([stat],
975  [[#include <sys/types.h>
976    #include <sys/stat.h>]],
977  [[#if defined(__MINGW32__)
978    #error stat in Windows CRT ill-behaves
979    #endif]],
980  [])
981
982dnl Check for Win32 rename. We don't know how to detect improper rename (not
983dnl removing target file if it exists) during cross-compilation, so we resort to
984dnl OS type detection.
985
986CF3_CHECK_PROPER_FUNC([rename],
987  [],
988  [[#if defined(__MINGW32__)
989    #error rename in Windows CRT ill-behaves
990    #endif]],
991  [#define rename rpl_rename])
992
993AC_CHECK_DECLS(mkdtemp)
994AC_REPLACE_FUNCS(mkdtemp)
995
996AC_CHECK_DECLS(strrstr)
997AC_REPLACE_FUNCS(strrstr)
998
999AC_CHECK_DECLS(stpncpy)
1000AC_REPLACE_FUNCS(stpncpy)
1001
1002AC_CHECK_FUNCS(seteuid setegid setreuid setregid)
1003AC_CHECK_FUNCS(uname gethostname chflags)
1004AC_CHECK_FUNCS(mkfifo statfs statvfs door)
1005AC_CHECK_FUNCS(sysinfo setsid sysconf)
1006AC_CHECK_FUNCS(getzoneid getzonenamebyid)
1007AC_CHECK_FUNCS(fpathconf)
1008
1009AC_CHECK_MEMBERS([struct stat.st_mtim, struct stat.st_mtimespec])
1010AC_CHECK_MEMBERS([struct stat.st_blocks])
1011
1012AC_MSG_CHECKING([for PRIuMAX/PRIdMAX macros])
1013AC_EGREP_CPP([primacros_found],
1014  AC_INCLUDES_DEFAULT
1015  [#include <inttypes.h>
1016  #if defined(PRIuMAX) && defined(PRIdMAX)
1017    primacros_found
1018  #endif
1019  ],
1020  [AC_MSG_RESULT(yes)],
1021  [AC_MSG_RESULT(no)
1022   AC_MSG_RESULT(Unable to find out how to scan intmax_t/uintmax_t types)])
1023
1024HW_FUNC_VSNPRINTF
1025HW_FUNC_SNPRINTF
1026HW_FUNC_VASPRINTF
1027HW_FUNC_ASPRINTF
1028
1029dnl dirfd might be a function or a macro
1030
1031AC_CHECK_DECLS(dirfd, [], [], [AC_INCLUDES_DEFAULT
1032#ifdef HAVE_DIRENT_H
1033# include <dirent.h>
1034#endif
1035])
1036
1037AC_CHECK_FUNCS(dirfd, [], [
1038  AC_MSG_CHECKING([for dirfd macro])
1039  AC_EGREP_CPP([dirfd_found],
1040    AC_INCLUDES_DEFAULT
1041    [#ifdef HAVE_DIRENT_H
1042    # include <dirent.h>
1043    #endif
1044    #ifdef dirfd
1045      dirfd_found
1046    #endif
1047    ],
1048  [AC_MSG_RESULT(yes)
1049  DIRFD_MACRO_FOUND=1],
1050  [AC_MSG_RESULT(no)])
1051  if test x$DIRFD_MACRO_FOUND = x; then
1052    AC_LIBOBJ([dirfd])
1053  fi])
1054
1055AC_CHECK_FUNCS(jail_get)
1056
1057dnl
1058dnl Various functions
1059dnl
1060
1061AC_SEARCH_LIBS(setsockopt, socket)
1062AC_SEARCH_LIBS(gethostent, nsl)
1063
1064AC_CHECK_FUNCS(socket)
1065AC_CHECK_FUNCS(setsockopt)
1066AC_CHECK_FUNCS(gethostent)
1067
1068AC_CHECK_TYPES(struct sockaddr_storage, [], [], [[
1069#if HAVE_WINSOCK2_H
1070    #include <winsock2.h>
1071#endif
1072#if HAVE_WS2TCPIP_H
1073    #include <ws2tcpip.h>
1074#else
1075    #include <sys/socket.h>
1076    #include <netdb.h>
1077#endif]])
1078
1079AC_CHECK_DECLS(getaddrinfo, [], [AC_LIBOBJ(getaddrinfo)], [[
1080#if HAVE_WINSOCK2_H
1081    #include <winsock2.h>
1082#endif
1083#if HAVE_WS2TCPIP_H
1084    #include <ws2tcpip.h>
1085#else
1086    #include <sys/socket.h>
1087    #include <netdb.h>
1088#endif
1089]])
1090
1091AC_CHECK_DECLS([[inet_ntop], [inet_pton]], [], [], [[#include <arpa/inet.h>]])
1092AC_REPLACE_FUNCS(inet_ntop inet_pton)
1093
1094AC_CHECK_FUNCS(getifaddrs)
1095
1096AC_CHECK_FUNCS(getprocs64)
1097
1098AC_CHECK_FUNC(lchown, AC_DEFINE(HAVE_LCHOWN, 1, [Whether to use lchown(3) to change ownerships]))
1099
1100AC_CHECK_DECLS(pthread_attr_setstacksize, [], [], [[#include <pthread.h>]])
1101AC_REPLACE_FUNCS(pthread_attr_setstacksize)
1102
1103AC_CHECK_DECLS(pthread_sigmask, [], [], [[#include <signal.h>]])
1104AC_REPLACE_FUNCS(pthread_sigmask)
1105
1106AC_CHECK_DECLS(sched_yield, [], [], [[#include <sched.h>]])
1107AC_CHECK_FUNCS(sched_yield)
1108
1109AC_CHECK_DECLS([openat], [], [], [[#define _GNU_SOURCE 1
1110                                   #include <fcntl.h>]])
1111AC_CHECK_DECLS([fstatat], [], [], [[#define _GNU_SOURCE 1
1112                                    #include <sys/stat.h>]])
1113AC_CHECK_DECLS([fchownat], [], [], [[#define _GNU_SOURCE 1
1114                                     #include <unistd.h>]])
1115AC_CHECK_DECLS([fchmodat], [], [], [[#define _GNU_SOURCE 1
1116                                    #include <sys/stat.h>]])
1117AC_CHECK_DECLS([readlinkat], [], [], [[#define _GNU_SOURCE 1
1118                                       #include <unistd.h>]])
1119AC_REPLACE_FUNCS(openat fstatat fchownat fchmodat readlinkat)
1120
1121AC_CHECK_DECLS([log2], [], [], [[#include <math.h>]])
1122AC_REPLACE_FUNCS(log2)
1123
1124dnl ######################################################################
1125dnl Required by cf-upgrade. It cannot be implemented in libcompat because
1126dnl cf-upgrade does not link to any libraries except libutils and only
1127dnl statically.
1128dnl ######################################################################
1129AC_CHECK_FUNC(fexecve, AC_DEFINE(HAVE_FEXECVE, 1, [Whether to use fexecve(3) to execute a new process]))
1130
1131dnl ######################################################################
1132dnl These need declarations here, but will be defined in the
1133dnl Enterprise Windows code.
1134dnl ######################################################################
1135
1136AC_CHECK_DECLS(alarm)
1137AC_CHECK_DECLS(chmod)
1138AC_CHECK_DECLS(chown)
1139AC_CHECK_DECLS(fchmod)
1140AC_CHECK_FUNCS(fchmod)
1141AC_CHECK_DECLS(uname)
1142AC_CHECK_DECLS(getuid)
1143AC_CHECK_DECLS(getgid)
1144AC_CHECK_DECLS(lstat)
1145AC_CHECK_FUNCS(sleep)
1146AC_CHECK_DECLS(socketpair, [], [], [[#include <sys/socket.h>]])
1147AC_CHECK_DECLS(fsync)
1148AC_CHECK_DECLS(glob, [], [], [[#include <glob.h>]])
1149
1150dnl ######################################################################
1151dnl Check for sa_len in struct sockaddr
1152dnl ######################################################################
1153
1154AC_CHECK_MEMBERS([struct sockaddr.sa_len], , , [
1155#include <sys/types.h>
1156#include <sys/socket.h>])
1157
1158AC_CHECK_MEMBERS([struct ifreq.ifr_hwaddr],,, [
1159#include <sys/ioctl.h>
1160#include <net/if.h>])
1161
1162dnl BSD uses sys/sysctl.h for CPU counting
1163AC_CHECK_HEADERS(sys/sysctl.h, [], [], [AC_INCLUDES_DEFAULT
1164#ifdef HAVE_SYS_PARAM_H
1165# include <sys/param.h>
1166#endif
1167])
1168
1169dnl ######################################################################
1170dnl Requirements for GetUptimeMinutes() to set $(sys.uptime)
1171dnl ######################################################################
1172dnl Linux sysinfo() call
1173AC_CHECK_MEMBERS([struct sysinfo.uptime], , , [#include <sys/sysinfo.h>])
1174
1175dnl BSD uses sys/sysctl.h to get time-of-boot
1176AC_CHECK_HEADERS(sys/sysctl.h, [], [], [AC_INCLUDES_DEFAULT
1177#ifdef HAVE_SYS_PARAM_H
1178# include <sys/param.h>
1179#endif
1180])
1181
1182dnl Solaris uses kstat.h to get time-of-boot
1183AC_CHECK_HEADERS(kstat.h)
1184dnl SystemV way to get uptime, highly portable
1185AC_CHECK_HEADERS(utmp.h)
1186dnl POSIX way to get uptime
1187AC_CHECK_HEADERS(utmpx.h)
1188
1189dnl #######################################################################
1190dnl Newer BSD systems don't have a compatible rtentry - use ortentry
1191dnl #######################################################################
1192
1193rtry=none
1194AC_MSG_CHECKING(for either struct rtentry or struct ortentry)
1195AC_EGREP_HEADER(rtentry, net/route.h, rtry=rtentry)
1196if test "$rtry" = rtentry; then
1197 AC_DEFINE(HAVE_RTENTRY, 1, [Do we have any route entry structure?])
1198fi
1199AC_EGREP_HEADER(ortentry, net/route.h, rtry=ortentry)
1200if test "$rtry" = ortentry; then
1201 AC_DEFINE(HAVE_ORTENTRY, 1, [The old route entry structure in newer BSDs])
1202fi
1203AC_MSG_RESULT([$rtry])
1204
1205dnl #######################################################################
1206dnl Enable extended attributes. Used for SELinux and ACLs
1207dnl #######################################################################
1208
1209AC_CHECK_FUNCS(llistxattr, [AC_DEFINE(WITH_XATTR, 1, [Define if you have a libc that supports extended attributes])])
1210AC_CHECK_HEADERS([attr/xattr.h sys/xattr.h])
1211
1212AC_MSG_CHECKING([whether xattr functions have extra arguments])
1213AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include <sys/types.h>
1214                                    #include <sys/xattr.h>],
1215                                    [(void)llistxattr("", 0, 0, 0);
1216                                    (void)lgetxattr("", "", 0, 0, 0, 0);
1217                                    (void)lsetxattr("", "", "", 0, 0, 0);
1218                                    (void)lremovexattr("", "", 0);])],
1219                  [AC_DEFINE(WITH_XATTR_EXTRA_ARGS, 1, [Define if your xattr implementation has extra arguments])]
1220                  [AC_MSG_RESULT([yes])],
1221                  [AC_MSG_RESULT([no])])
1222
1223dnl #######################################################################
1224dnl Check for "fancy"(new) C compiler options
1225dnl #######################################################################
1226
1227saved_CFLAGS="$CFLAGS"
1228CFLAGS="-Werror -Wno-tautological-constant-out-of-range-compare"
1229AC_MSG_CHECKING([whether compiler supports -Wno-tautological-constant-out-of-range-compare])
1230AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])],
1231    [AC_MSG_RESULT([yes])]
1232    [NO_TAUTOLOGICAL_CC_OPTION="-Wno-tautological-constant-out-of-range-compare"],
1233    [AC_MSG_RESULT([no])]
1234    [NO_TAUTOLOGICAL_CC_OPTION=""]
1235)
1236CFLAGS="$saved_CFLAGS"
1237AC_SUBST([NO_TAUTOLOGICAL_CC_OPTION])
1238
1239dnl ######################################################################
1240dnl Give the chance to enable SELINUX
1241dnl ######################################################################
1242
1243AC_ARG_ENABLE([selinux], [AS_HELP_STRING([--enable-selinux], [Deprecated. SELinux support is always enabled])])
1244
1245dnl ######################################################################
1246dnl OS specific stuff
1247dnl ######################################################################
1248
1249case "$target_os" in
1250
1251   solaris2.8|solaris2.9)
1252        AC_DEFINE(_XOPEN_SOURCE, 500, [UNIX 98])
1253        AC_DEFINE(__EXTENSIONS__, 1, [Extended UNIX 98 interfaces])
1254        ;;
1255   solaris2.10|solaris2.11)
1256        AC_DEFINE(_XOPEN_SOURCE, 600, [SUSv3])
1257        AC_DEFINE(__EXTENSIONS__, 1, [Extended UNIX 98 interfaces])
1258        ;;
1259   hpux*|hp-ux*)
1260        dnl pstat* functions may fail with EOVERFLOW without this.
1261        AC_DEFINE(_PSTAT64, 1, [Enable wide data structures everywhere])
1262        ;;
1263   aix*)
1264        CPPFLAGS="$CPPFLAGS -w"
1265        ;;
1266   linux*|*bsd*|*gnu*)
1267        AC_CHECK_LIB(nss_nis, yp_get_default_domain)
1268        ;;
1269   freebsd*|dragonfly*)
1270        ;;
1271   netbsd*)
1272        ;;
1273   unicos*)
1274        ;;
1275   cray*)
1276        ;;
1277   qnx*)
1278        ;;
1279   openbsd*|obsd*)
1280        ;;
1281   sysv4.2MP|unix_sv*)
1282        ;;
1283   cygwin*)
1284        ;;
1285   mingw*)
1286        ;;
1287   sco*)
1288        ;;
1289   darwin*)
1290        ;;
1291   *)
1292        AC_MSG_ERROR(Unknown system type $target_os)
1293        ;;
1294esac
1295
1296m4_include([m4/cf3_platforms.m4])
1297
1298dnl #####################################################################
1299dnl Configure directories
1300dnl #####################################################################
1301
1302AC_ARG_WITH(workdir,
1303    [  --with-workdir=WORKDIR  default for internal (trusted) working directory ],
1304    [
1305        if test "x$withval" != x ; then
1306            WORKDIR="$withval"
1307            LOGDIR="$withval"
1308            PIDDIR="$withval"
1309        fi
1310    ],
1311)
1312
1313dnl Expand ${prefix} and whatnot in WORKDIR
1314
1315adl_RECURSIVE_EVAL("${WORKDIR}", WORKDIR)
1316
1317AC_DEFINE_UNQUOTED(WORKDIR, "${WORKDIR}", [Workdir location])
1318AC_SUBST(workdir, "${WORKDIR}")
1319
1320AC_ARG_WITH(masterdir,
1321    [  --with-masterdir=MASTERDIR  default for internal masterfiles directory ],
1322    [
1323        if test "x$withval" != x ; then
1324            MASTERDIR="$withval"
1325        fi
1326    ],
1327)
1328
1329dnl Expand ${prefix} and whatnot in MASTERDIR
1330
1331adl_RECURSIVE_EVAL("${MASTERDIR}", MASTERDIR)
1332
1333AC_DEFINE_UNQUOTED(MASTERDIR, "${MASTERDIR}", [Masterfiles directory location])
1334AC_SUBST(masterdir, "${MASTERDIR}")
1335
1336AC_ARG_WITH(inputdir,
1337    [  --with-inputdir=INPUTDIR  default for internal inputs directory ],
1338    [
1339        if test "x$withval" != x ; then
1340            INPUTDIR="$withval"
1341        fi
1342    ],
1343)
1344
1345dnl Expand ${prefix} and whatnot in INPUTDIR
1346
1347adl_RECURSIVE_EVAL("${INPUTDIR}", INPUTDIR)
1348
1349AC_DEFINE_UNQUOTED(INPUTDIR, "${INPUTDIR}", [Inputs directory location])
1350AC_SUBST(inputdir, "${INPUTDIR}")
1351
1352AC_ARG_WITH(logdir,
1353    [  --with-logdir=LOGDIR  default for internal log directory ],
1354    [
1355        if test "x$withval" != x ; then
1356            LOGDIR="$withval"
1357        fi
1358    ],
1359)
1360
1361dnl Expand ${prefix} and whatnot in LOGDIR
1362
1363adl_RECURSIVE_EVAL("${LOGDIR}", LOGDIR)
1364
1365AC_DEFINE_UNQUOTED(LOGDIR, "${LOGDIR}", [Logdir location])
1366AC_SUBST(logdir, "${LOGDIR}")
1367
1368AC_ARG_WITH(piddir,
1369    [  --with-piddir=LOGDIR  default for internal pid directory ],
1370    [
1371        if test "x$withval" != x ; then
1372            PIDDIR="$withval"
1373        fi
1374    ],
1375)
1376
1377dnl Expand ${prefix} and whatnot in PIDDIR
1378
1379adl_RECURSIVE_EVAL("${PIDDIR}", PIDDIR)
1380
1381AC_DEFINE_UNQUOTED(PIDDIR, "${PIDDIR}", [piddir location])
1382AC_SUBST(piddir, "${PIDDIR}")
1383
1384AC_ARG_WITH(statedir,
1385    [  --with-statedir=STATEDIR  default for internal state directory ],
1386    [
1387        if test "x$withval" != x ; then
1388            STATEDIR="$withval"
1389        fi
1390    ],
1391)
1392
1393dnl Expand ${prefix} and whatnot in STATEDIR
1394
1395adl_RECURSIVE_EVAL("${STATEDIR}", STATEDIR)
1396
1397AC_DEFINE_UNQUOTED(STATEDIR, "${STATEDIR}", [State directory location])
1398AC_SUBST(statedir, "${STATEDIR}")
1399
1400AC_ARG_WITH(shell, [AS_HELP_STRING([--with-shell=PATH],
1401                   [Specify path to POSIX-compatible shell (if not /bin/sh)])],
1402                   [],
1403                   [with_shell=/bin/sh])
1404
1405dnl Expand ${prefix} and whatnot in bindir
1406adl_RECURSIVE_EVAL("${bindir}", bindir)
1407
1408AC_DEFINE_UNQUOTED(BINDIR, "${bindir}", [binaries location])
1409AC_SUBST(bindir, "${bindir}")
1410
1411
1412if test "x$with_shell" = "xno"; then
1413   AC_MSG_ERROR([Please specify full path to POSIX-compatible shell])
1414fi
1415AC_DEFINE_UNQUOTED(SHELL_PATH, "$with_shell", [Path to the POSIX-compatible shell])
1416
1417
1418dnl #####################################################################
1419dnl Hostname and Version stuff
1420dnl #####################################################################
1421
1422AC_PATH_PROG(HOSTNAME, hostname, "", $PATH)
1423
1424AC_DEFINE_UNQUOTED(AUTOCONF_HOSTNAME, "`$HOSTNAME`", [Special CFEngine symbol])
1425AC_DEFINE_UNQUOTED(AUTOCONF_SYSNAME, "$target_os", [Speial CFEngine symbol])
1426
1427
1428dnl #####################################################################
1429dnl xen cpuid-based hvm detection
1430dnl #####################################################################
1431
1432AC_MSG_CHECKING(for Xen cpuid-based HVM detection)
1433if test x"$GCC" = "xyes"; then
1434    case $host_cpu in
1435        i[[3456]]86*|x86_64*|amd64)
1436            AC_DEFINE(XEN_CPUID_SUPPORT, 1, [Define if XEN cpuid-based HVM detection is available.])
1437            AC_MSG_RESULT(yes)
1438            ;;
1439        *)
1440            AC_MSG_RESULT(no)
1441            ;;
1442    esac
1443else
1444    AC_MSG_RESULT(no)
1445fi
1446
1447dnl
1448dnl Code coverage
1449dnl
1450
1451AC_ARG_ENABLE(coverage, AS_HELP_STRING([--enable-coverage], [Enable code coverage]),
1452              [use_coverage=$enableval], [use_coverage=no])
1453
1454if test "x$use_coverage" = "xyes"; then
1455  if test "$GCC" != "yes"; then
1456    AC_MSG_ERROR([GCC is required for --enable-coverage])
1457  fi
1458
1459  if test "$debug" != "yes"; then
1460    AC_MSG_ERROR([--enable-debug is required for --enable-coverage])
1461  fi
1462
1463  AC_CHECK_PROG(LCOV, lcov, lcov)
1464  AC_CHECK_PROG(LCOV_GENHTML, genhtml, genhtml)
1465
1466  if test -z "$LCOV"; then
1467    AC_MSG_ERROR([Cannot find lcov from the LTP package])
1468  fi
1469
1470  if test -z "$LCOV_GENHTML"; then
1471    AC_MSG_ERROR([Could not find genhtml from the LTP package])
1472  fi
1473
1474  dnl Remove all optimization flags from CFLAGS
1475  changequote({,})
1476  CFLAGS=`echo "$CFLAGS" | $SED -e 's/-O[0-9]*//g'`
1477  changequote([,])
1478
1479  dnl Add the special gcc flags
1480  CFLAGS="$CFLAGS -fprofile-arcs -ftest-coverage"
1481  LDFLAGS="$LDFLAGS -lgcov"
1482  # Need to set ENABLE_COVERAGE so that tests/unit/Makefile.am can adapt for one
1483  # test which needs gcov stubs if core not built with coverage.
1484  AM_CONDITIONAL([ENABLE_COVERAGE], true)
1485else
1486  AM_CONDITIONAL([ENABLE_COVERAGE], false)
1487fi
1488
1489dnl ######################################################################
1490dnl Collect all the options
1491dnl ######################################################################
1492
1493CORE_CPPFLAGS="$LMDB_CPPFLAGS $TOKYOCABINET_CPPFLAGS $QDBM_CPPFLAGS $PCRE_CPPFLAGS $OPENSSL_CPPFLAGS $SQLITE3_CPPFLAGS $LIBACL_CPPFLAGS $LIBCURL_CPPFLAGS $LIBYAML_CPPFLAGS $POSTGRESQL_CPPFLAGS $MYSQL_CPPFLAGS $LIBXML2_CPPFLAGS $CPPFLAGS"
1494CORE_CFLAGS="$LMDB_CFLAGS $TOKYOCABINET_CFLAGS $QDBM_CFLAGS $PCRE_CFLAGS $OPENSSL_CFLAGS $SQLITE3_CFLAGS $LIBACL_CFLAGS $LIBCURL_CFLAGS $LIBYAML_CFLAGS $POSTGRESQL_CFLAGS $MYSQL_CFLAGS $LIBXML2_CFLAGS $CFLAGS"
1495CORE_LDFLAGS="$LMDB_LDFLAGS $TOKYOCABINET_LDFLAGS $QDBM_LDFLAGS $PCRE_LDFLAGS $OPENSSL_LDFLAGS $SQLITE3_LDFLAGS $LIBACL_LDFLAGS $LIBCURL_LDFLAGS $LIBYAML_LDFLAGS $POSTGRESQL_LDFLAGS $MYSQL_LDFLAGS $LIBXML2_LDFLAGS $LDFLAGS"
1496CORE_LIBS="$LMDB_LIBS $TOKYOCABINET_LIBS $QDBM_LIBS $PCRE_LIBS $OPENSSL_LIBS $SQLITE3_LIBS $LIBACL_LIBS $LIBCURL_LIBS $LIBYAML_LIBS $POSTGRESQL_LIBS $MYSQL_LIBS $LIBXML2_LIBS $LIBS"
1497
1498dnl ######################################################################
1499dnl Make them available to subprojects.
1500dnl ######################################################################
1501
1502AC_SUBST([CORE_CPPFLAGS])
1503AC_SUBST([CORE_CFLAGS])
1504AC_SUBST([CORE_LDFLAGS])
1505AC_SUBST([CORE_LIBS])
1506AC_CONFIG_FILES([configure_flags.env])
1507
1508#
1509# Populate contents of config.post.h
1510#
1511AC_SUBST(post_macros)
1512AM_SUBST_NOTMAKE(post_macros)
1513
1514dnl ######################################################################
1515dnl Check how file descriptor transfers are supported between proceses.
1516dnl ######################################################################
1517AC_CHECK_MEMBER([struct msghdr.msg_control],
1518                [AC_DEFINE([HAVE_MSGHDR_MSG_CONTROL], [1], [Define to 1 if SCM_RIGHTS supported])],
1519                [AC_DEFINE([HAVE_NO_MSGHDR_MSG_CONTROL], [1], [Define to 1 if SCM_RIGHTS support])],
1520                [[#include <sys/types.h>
1521                  #include <sys/socket.h>]])
1522
1523AC_CHECK_MEMBER([struct msghdr.msg_accrights],
1524                [AC_DEFINE([HAVE_MSGHDR_ACCRIGHTS], [1], [Define to 1 if BSD .msg_accrights supported])],
1525                [AC_DEFINE([HAVE_NO_MSGHDR_ACCRIGHTS], [1], [Define to 1 if no BSD .msg_accrights support])],
1526                [[#include <sys/types.h>
1527                  #include <sys/socket.h>]])
1528
1529dnl ######################################################################
1530dnl Summarize
1531dnl ######################################################################
1532
1533AC_MSG_RESULT( )
1534
1535AC_MSG_RESULT(Summary:)
1536AC_MSG_RESULT(> Version: AC_PACKAGE_VERSION)
1537
1538AC_MSG_RESULT([> Required libraries])
1539
1540AC_MSG_RESULT([-> OpenSSL: $OPENSSL_PATH])
1541
1542AC_MSG_RESULT([-> PCRE: $PCRE_PATH])
1543
1544if test $WITH_TOKYO = 1; then
1545  AC_MSG_RESULT([-> DB: Tokyo Cabinet: $TOKYOCABINET_PATH])
1546elif test $WITH_QDBM = 1; then
1547  AC_MSG_RESULT([-> DB: QDBM: $QDBM_PATH])
1548fi
1549
1550AC_MSG_RESULT([> Optional libraries])
1551
1552if test "x$ac_cv_lib_mysqlclient_mysql_real_connect" = "xyes"; then
1553  AC_MSG_RESULT([-> MySQL connector: $MYSQL_PATH])
1554else
1555  AC_MSG_RESULT([-> MySQL connector: disabled])
1556fi
1557
1558if test "x$ac_cv_lib_pq_PQconnectdb" = "xyes"; then
1559  AC_MSG_RESULT([-> PostgreSQL connector: $POSTGRESQL_PATH])
1560else
1561  AC_MSG_RESULT([-> PostgreSQL connector: disabled])
1562fi
1563
1564if test $WITH_LMDB = 1; then
1565  AC_MSG_RESULT([-> DB: Lightning MDB: $LMDB_PATH])
1566elif test $WITH_TOKYO = 1; then
1567  AC_MSG_RESULT([-> DB: Tokyo Cabinet: $TOKYOCABINET_PATH])
1568elif test $WITH_QDBM = 1; then
1569  AC_MSG_RESULT([-> DB: QDBM: $QDBM_PATH])
1570fi
1571
1572if test "x$ac_cv_lib_virt_virConnectOpen" = xyes; then
1573  AC_MSG_RESULT([-> libvirt: $LIBVIRT_PATH])
1574else
1575  AC_MSG_RESULT([-> libvirt: disabled])
1576fi
1577
1578if test "x$ac_cv_lib_acl_acl_init" = xyes; then
1579  AC_MSG_RESULT([-> libacl: $LIBACL_PATH])
1580else
1581  AC_MSG_RESULT([-> libacl: disabled])
1582fi
1583
1584if test "x$ac_cv_lib_curl_curl_global_init" = xyes; then
1585  AC_MSG_RESULT([-> libcurl: $LIBCURL_PATH])
1586else
1587  AC_MSG_RESULT([-> libcurl: disabled])
1588fi
1589
1590if test "x$ac_cv_lib_yaml_yaml_parser_initialize" = xyes; then
1591  AC_MSG_RESULT([-> libyaml: $LIBYAML_PATH])
1592else
1593  AC_MSG_RESULT([-> libyaml: disabled])
1594fi
1595
1596if test "x$ac_cv_lib_xml2_xmlFirstElementChild" = xyes; then
1597  AC_MSG_RESULT([-> libxml2: $LIBXML2_PATH])
1598else
1599  AC_MSG_RESULT([-> libxml2: disabled])
1600fi
1601
1602if test "x$users_promises_ok" = "xyes"; then
1603  AC_MSG_RESULT([-> User promises: PAM/user* tools])
1604else
1605  AC_MSG_RESULT([-> User promises: disabled])
1606fi
1607
1608if test "x$enable_builtin_extensions" = "xyes"; then
1609  AC_MSG_RESULT([-> Enterprise extensions: Built in])
1610else
1611  AC_MSG_RESULT([-> Enterprise extensions: Plugin or not included])
1612fi
1613
1614m4_indir(incstart[]incend, [nova/config.m4])
1615
1616AC_MSG_RESULT([-> Workdir: $WORKDIR])
1617AC_MSG_RESULT([-> Masterdir: $MASTERDIR])
1618AC_MSG_RESULT([-> Inputdir: $INPUTDIR])
1619AC_MSG_RESULT([-> Logdir: $LOGDIR])
1620AC_MSG_RESULT([-> Piddir: $PIDDIR])
1621AC_MSG_RESULT([-> Statedir: $STATEDIR])
1622AC_MSG_RESULT([-> bindir: $bindir])
1623
1624AC_MSG_RESULT( )
1625
1626dnl ######################################################################
1627dnl Now make the Makefiles
1628dnl ######################################################################
1629
1630AC_CONFIG_FILES([Makefile
1631    libcompat/Makefile
1632    libutils/Makefile
1633    config.post.h
1634    tests/Makefile
1635    tests/unit/Makefile])
1636
1637AC_OUTPUT
1638
1639AC_MSG_RESULT(DONE: Configuration done. Run make/gmake to build libntech.)
1640