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 OpenSSL
352dnl
353
354AC_ARG_WITH(openssl,
355    [AS_HELP_STRING([--with-openssl[[=PATH]]],
356    [Specify OpenSSL path])], [], [with_openssl=yes])
357
358if  test -d /usr/local/Cellar/openssl/ && \
359    test -d /usr/local/opt/openssl/ && \
360    test "x$with_openssl" = "xyes" ; then
361    with_openssl="/usr/local/opt/openssl"
362    echo "OS X Homebrew detected"
363    echo "Defaulting to: --with-openssl=$with_openssl"
364fi
365
366if test "x$with_openssl" != "xno"; then
367  CF3_WITH_LIBRARY(openssl, [
368    AC_CHECK_LIB(crypto, RSA_generate_key_ex, [], [])
369    AC_CHECK_LIB(ssl, SSL_free, [], [])
370    AC_CHECK_DECLS([SSL_CTX_clear_options], [], [], [[#include <openssl/ssl.h>]])
371    AC_CHECK_HEADERS([openssl/opensslv.h], [], [AC_MSG_ERROR(Cannot find OpenSSL)])
372    AC_MSG_CHECKING(for OpenSSL version)
373    AC_PREPROC_IFELSE([AC_LANG_SOURCE([[
374    #include <openssl/opensslv.h>
375
376    #if OPENSSL_VERSION_NUMBER < 0x0090602fL
377    #This OpenSSL is too old
378    #endif
379    ]])],[AC_MSG_RESULT(OK)],[AC_MSG_ERROR(This release of CFEngine requires OpenSSL >= 0.9.7)])
380
381    if test "x$ac_cv_lib_crypto_RSA_generate_key_ex" = "xyes" ; then
382       AC_DEFINE(OPENSSL_NO_DEPRECATED, 1, [Define if non deprecated API is available.])
383    fi
384
385    if test "x$ac_cv_lib_crypto_RSA_generate_key_ex" = "xno" && \
386       test "x$ac_cv_lib_crypto_RSA_generate_key" = "xno" ; then
387       AC_MSG_ERROR(Cannot find OpenSSL)
388    fi
389
390    AC_CHECK_DECL([SSL_OP_NO_TLSv1_1],
391     [AC_DEFINE([HAVE_TLS_1_1], [1], [Define if TLS 1.1 is supported by OpenSSL])],
392     [], [[#include <openssl/ssl.h>]]
393     )
394    AC_CHECK_DECL([SSL_OP_NO_TLSv1_2],
395     [AC_DEFINE([HAVE_TLS_1_2], [1], [Define if TLS 1.2 is supported by OpenSSL])],
396     [], [[#include <openssl/ssl.h>]]
397     )
398    AC_CHECK_DECL([SSL_OP_NO_TLSv1_3],
399     [AC_DEFINE([HAVE_TLS_1_3], [1], [Define if TLS 1.3 is supported by OpenSSL])],
400     [], [[#include <openssl/ssl.h>]]
401     )
402  ])
403  AC_DEFINE(WITH_OPENSSL, 1, [Define if OpenSSL is being used])
404  AM_CONDITIONAL(WITH_OPENSSL, true)
405else
406  AM_CONDITIONAL(WITH_OPENSSL, false)
407fi
408
409dnl PCRE
410
411AC_ARG_WITH([pcre], [AS_HELP_STRING([--with-pcre[[=PATH]]], [Specify PCRE path])], [], [with_pcre=yes])
412
413if test "x$with_pcre" != "xno"; then
414  CF3_WITH_LIBRARY(pcre, [
415    AC_CHECK_LIB(pcre, pcre_exec, [], [AC_MSG_ERROR(Cannot find PCRE)])
416    AC_CHECK_HEADERS(
417      [pcre.h],
418      [],
419      [AC_CHECK_HEADERS(
420        [pcre/pcre.h],
421        [PCRE_CPPFLAGS="-Ipcre"],
422        AC_MSG_ERROR(Cannot find PCRE)
423      )]
424    )
425  ])
426  AC_DEFINE(WITH_PCRE, 1, [Define if PCRE is being used])
427  AM_CONDITIONAL(WITH_PCRE, true)
428else
429  AM_CONDITIONAL(WITH_PCRE, false)
430fi
431
432dnl libvirt
433
434AC_ARG_WITH([libvirt],
435    [AS_HELP_STRING([--with-libvirt[[=PATH]]], [support virtual machine management])],
436    [], [with_libvirt=check])
437
438if test "x$with_libvirt" != xno
439then
440   CF3_WITH_LIBRARY(libvirt, [
441      AC_CHECK_LIB(virt, virConnectOpen, [], [if test "x$with_libvirt" != xcheck; then AC_MSG_ERROR(Cannot find libvirt library); fi])
442      AC_CHECK_HEADERS(libvirt/libvirt.h, [], [if test "x$with_libvirt" != xcheck; then AC_MSG_ERROR(Cannot find libvirt library headers); fi])
443   ])
444fi
445
446dnl  BIG FAT WARNING FOR AC_CHECK_LIB: *always* leave the
447dnl  "action-if-yes" parameter empty else LIBS is not changed and C
448dnl  define is not generated!  Or use AC_SEARCH_LIBS for a better
449dnl  interface.
450
451dnl libacl
452dnl It is enough for any of the header files [acl.h sys/acl.h acl/libacl.h] to be present
453
454AC_ARG_WITH([libacl],
455    [AS_HELP_STRING([--with-libacl[[=PATH]]], [Specify libacl path])], [], [with_libacl=check])
456
457if test "x$with_libacl" != xno
458then
459  CF3_WITH_LIBRARY(libacl, [
460    AC_CHECK_LIB(acl, acl_init,
461      [],
462      [if test "x$with_libacl" != xcheck; then AC_MSG_ERROR(Cannot find libacl library); fi])
463    AC_CHECK_HEADERS([acl.h sys/acl.h acl/libacl.h],
464      [libacl_header_found=yes])
465    if test "x$libacl_header_found" != "xyes" && test "x$with_libacl" != xcheck;
466    then
467      AC_MSG_ERROR(Cannot find libacl library headers);
468    fi
469  ])
470fi
471
472dnl libcurl
473
474AC_ARG_WITH([libcurl],
475    [AS_HELP_STRING([--with-libcurl[[=PATH]]], [Specify libcurl path])], [], [with_libcurl=check])
476
477if test "x$with_libcurl" != xno
478then
479  CF3_WITH_LIBRARY(libcurl, [
480    AC_CHECK_LIB(curl, curl_global_init,
481      [],
482      [  libcurl_lib_found=no;
483         if test "x$with_libcurl" != xcheck;
484         then
485             AC_MSG_ERROR(Cannot find libcurl library);
486         fi
487      ])
488    AC_CHECK_HEADERS([curl/curl.h],
489      [libcurl_header_found=yes],
490      [if test "x$with_libcurl" != xcheck; then AC_MSG_ERROR(Cannot find libcurl header files); fi])
491  ])
492fi
493
494AM_CONDITIONAL(HAVE_LIBCURL,
495        [test "x$libcurl_lib_found" != xno && test "x$libcurl_header_found" = xyes])
496
497dnl libyaml
498
499AC_ARG_WITH([libyaml],
500    [AS_HELP_STRING([--with-libyaml[[=PATH]]], [Specify libyaml path])], [], [with_libyaml=check])
501
502if test "x$with_libyaml" != xno
503then
504  CF3_WITH_LIBRARY(libyaml, [
505    AC_CHECK_LIB(yaml, yaml_parser_initialize,
506      [],
507      [if test "x$with_libyaml" != xcheck; then AC_MSG_ERROR(Cannot find libyaml library); fi])
508    AC_CHECK_HEADERS(yaml.h,
509      [libyaml_header_found=yes],
510      [if test "x$with_libyaml" != xcheck; then AC_MSG_ERROR(Cannot find libyaml header files); fi])
511  ])
512fi
513
514dnl libxml2
515
516AC_ARG_WITH([libxml2],
517    [AS_HELP_STRING([--with-libxml2[[=PATH]]],
518        [Specify libxml2 path])
519    ],
520    [],
521    [with_libxml2=check])
522
523if test "x$with_libxml2" != xno
524then
525    if test "x$with_libxml2" != xyes &&
526       test "x$with_libxml2" != xcheck
527    then
528        XML2_CONFIG=$with_libxml2/bin/xml2-config
529    else
530        XML2_CONFIG=xml2-config
531    fi
532
533    # xml2-config is only for native builds
534    if test "x$cross_compiling" = "xno" && test x`which $XML2_CONFIG` != x
535    then
536        xml2_include_dir=`$XML2_CONFIG --cflags`
537        if test -n "$xml2_include_dir"
538        then
539            LIBXML2_CPPFLAGS="$xml2_include_dir"
540        fi
541    else                # xml2-config not found
542        # if a path, e.g. /var/cfengine was given, then we
543        # must take into account that libxml2 includes are in
544        # /var/cfengine/include/libxml2
545        LIBXML2_CPPFLAGS=-I$with_libxml2/include/libxml2
546    fi
547
548    CF3_WITH_LIBRARY(libxml2,
549        [AC_CHECK_LIB(xml2, xmlFirstElementChild,
550            [],
551            [if test "x$with_libxml2" != xcheck; then
552                AC_MSG_ERROR(Cannotfind libxml2); fi]
553        )
554        AC_CHECK_HEADERS([libxml/xmlwriter.h], [break],
555            [if test "x$with_libxml2" != xcheck; then
556                AC_MSG_ERROR(Cannot find libxml2); fi]
557        )]
558    )
559fi
560
561AM_CONDITIONAL([HAVE_LIBXML2],
562    [test "x$with_libxml2" != xno &&
563     test "x$ac_cv_lib_xml2_xmlFirstElementChild" = xyes])
564
565dnl avahi
566
567AC_CHECK_HEADERS(avahi-client/client.h,
568    AM_CONDITIONAL(HAVE_AVAHI_CLIENT, true),
569    AM_CONDITIONAL(HAVE_AVAHI_CLIENT, false),
570    [])
571AC_CHECK_HEADERS(avahi-common/address.h,
572    AM_CONDITIONAL(HAVE_AVAHI_COMMON, true),
573    AM_CONDITIONAL(HAVE_AVAHI_COMMON, false),
574    [])
575
576dnl
577
578dnl ######################################################################
579dnl Checks for header files.
580dnl ######################################################################
581
582AC_CHECK_HEADERS(unistd.h stdlib.h sys/loadavg.h)
583AC_CHECK_HEADERS(sys/param.h sys/resource.h)
584
585# sys/param.h is required for sys/mount.h on OpenBSD
586AC_CHECK_HEADERS(sys/mount.h, [], [], [AC_INCLUDES_DEFAULT
587#ifdef HAVE_SYS_PARAM_H
588# include <sys/param.h>
589#endif
590])
591
592# Required on BSD to get struct sockaddr_dl (for retrieving MAC addresses from getifaddrs())
593AC_CHECK_HEADERS(net/if_dl.h)
594
595# Required on Solaris to get struct arpreq (for retrieving MAC addresses)
596AC_CHECK_HEADERS(net/if_arp.h, , , [AC_INCLUDES_DEFAULT
597#include <sys/socket.h>
598])
599
600AC_CHECK_HEADERS(utime.h)
601AC_CHECK_HEADERS(time.h)
602AC_CHECK_HEADERS(sys/time.h)
603AC_CHECK_HEADERS(malloc.h sys/malloc.h)
604AC_CHECK_HEADERS(vfs.h)
605AC_CHECK_HEADERS(sys/vfs.h)
606AC_CHECK_HEADERS(sys/sockio.h)
607AC_CHECK_HEADERS(sys/statvfs.h)
608AC_CHECK_HEADERS(sys/statfs.h)
609AC_CHECK_HEADERS(fcntl.h)
610AC_CHECK_HEADERS(sys/filesys.h)
611AC_CHECK_HEADERS(dustat.h)
612AC_CHECK_HEADERS(sys/systeminfo.h)
613AC_CHECK_HEADERS(ieeefp.h)
614AC_CHECK_HEADERS(winsock2.h)
615AC_CHECK_HEADERS(ws2tcpip.h)
616AC_CHECK_HEADERS(zone.h)
617AC_CHECK_HEADERS(sys/uio.h)
618AC_CHECK_HEADERS_ONCE([sys/sysmacros.h]) dnl glibc deprecated inclusion in sys/type.h
619AC_CHECK_HEADERS(sys/types.h)
620AC_CHECK_HEADERS(sys/mpctl.h) dnl For HP-UX $(sys.cpus) - Mantis #1069
621AC_CHECK_HEADERS(shadow.h)
622AC_CHECK_HEADERS(sys/jail.h, [], [], [AC_INCLUDES_DEFAULT
623#ifdef HAVE_SYS_PARAM_H
624# include <sys/param.h>
625#endif
626])
627AC_CHECK_HEADERS(net/route.h netinet/in.h netinet/ip.h)
628
629
630AC_HEADER_STDC
631AC_HEADER_TIME
632AC_HEADER_SYS_WAIT
633AC_HEADER_DIRENT
634AC_HEADER_STDBOOL
635
636dnl ######################################################################
637dnl Checks for data types
638dnl ######################################################################
639
640AC_TYPE_MODE_T
641AC_TYPE_SIZE_T
642AC_TYPE_UID_T
643AC_TYPE_PID_T
644AC_CHECK_TYPES(clockid_t, [], [], [[
645#ifdef HAVE_TIME_H
646# include <time.h>
647#endif
648]])
649
650AC_CHECK_TYPES(socklen_t, [], [], [[
651#ifdef HAVE_SYS_TYPES_H
652# include <sys/types.h>
653#endif
654
655#include <sys/socket.h>
656]])
657
658dnl ######################################################################
659dnl Checks for typedefs, structures, and compiler characteristics.
660dnl ######################################################################
661
662AC_C_CONST
663
664AC_FUNC_FSEEKO
665AC_SYS_LARGEFILE
666AC_TYPE_OFF_T
667
668#
669# AC_SYS_LARGEFILE correctly figures out necessary macros for large files, but
670# on AIX there is a gotcha:
671#
672# Code generated by flex #includes <stdio.h> at the beginning of the file, which
673# picks up 32-bit wide off_t. Then it #includes <config.h> which provides LFS
674# macros, and finally it includes another system header, now with 64-bit wide
675# off_t, which causes a conflict.
676#
677if test "x$ac_cv_sys_large_files" = x1; then
678  CPPFLAGS="-D_LARGE_FILES=1 $CPPFLAGS"
679fi
680
681dnl ######################################################################
682dnl Check for libraries
683dnl ######################################################################
684
685AC_CHECK_LIB(m, sqrt)
686AC_CHECK_LIB(rt, clock_gettime)
687AC_CHECK_LIB(dl, dlopen)
688
689dnl ######################################################################
690dnl Check for special functions
691dnl ######################################################################
692
693AC_CHECK_DECLS(clock_gettime, [], [], [[#include <time.h>]])
694AC_REPLACE_FUNCS(clock_gettime)
695
696AC_CHECK_DECLS(unsetenv)
697AC_REPLACE_FUNCS(unsetenv)
698
699AC_CHECK_DECLS(strnlen)
700AC_REPLACE_FUNCS(strnlen)
701
702cf3_FUNC_STRNDUP
703
704AC_CHECK_DECLS(seteuid)
705AC_REPLACE_FUNCS(seteuid)
706
707AC_CHECK_DECLS(setlinebuf)
708AC_REPLACE_FUNCS(setlinebuf)
709
710AC_CHECK_DECLS(strlcat)
711AC_REPLACE_FUNCS(strlcat)
712
713AC_CHECK_DECLS(strlcpy)
714AC_REPLACE_FUNCS(strlcpy)
715
716AC_CHECK_DECLS(realpath)
717
718AC_CHECK_DECLS(strdup)
719AC_REPLACE_FUNCS(strdup)
720
721AC_CHECK_DECLS(memrchr)
722AC_REPLACE_FUNCS(memrchr)
723
724AC_CHECK_DECLS(round, [], [], [[#include <math.h>]])
725AC_REPLACE_FUNCS(round)
726
727AC_CHECK_DECLS(nanosleep)
728AC_REPLACE_FUNCS(nanosleep)
729
730AC_CHECK_DECLS(memdup)
731AC_REPLACE_FUNCS(memdup)
732
733AC_CHECK_DECLS(memmem)
734AC_REPLACE_FUNCS(memmem)
735
736AC_CHECK_DECLS(srand48)
737AC_REPLACE_FUNCS(srand48)
738
739AC_CHECK_DECLS(drand48)
740AC_REPLACE_FUNCS(drand48)
741
742AC_CHECK_DECLS(strerror)
743AC_REPLACE_FUNCS(strerror)
744
745AC_CHECK_DECLS(strstr)
746AC_REPLACE_FUNCS(strstr)
747
748AC_CHECK_DECLS(strcasestr)
749AC_REPLACE_FUNCS(strcasestr)
750
751AC_CHECK_DECLS(strcasecmp)
752AC_REPLACE_FUNCS(strcasecmp)
753
754AC_CHECK_DECLS(strncasecmp)
755AC_REPLACE_FUNCS(strncasecmp)
756
757AC_CHECK_DECLS(strsep)
758AC_REPLACE_FUNCS(strsep)
759
760AC_CHECK_DECLS(strsignal)
761AC_REPLACE_FUNCS(strsignal)
762
763AC_CHECK_DECLS(gmtime_r, [], [], [[#include <time.h>]])
764AC_REPLACE_FUNCS(gmtime_r)
765
766AC_CHECK_DECLS(getline, [], [], [#define _GNU_SOURCE 1
767AC_INCLUDES_DEFAULT])
768AC_REPLACE_FUNCS(getline)
769
770AC_CHECK_DECLS(strchrnul, [], [], [#define _GNU_SOURCE 1
771AC_INCLUDES_DEFAULT])
772AC_REPLACE_FUNCS(strchrnul)
773
774AC_CHECK_DECLS(localtime_r, [], [], [[#include <time.h>]])
775AC_REPLACE_FUNCS(localtime_r)
776
777AC_CHECK_DECLS(fgetgrent, [], [], [[#include <grp.h>]])
778
779AC_CHECK_DECLS(isfinite, [], [], [[#include <math.h>]])
780
781AC_CHECK_FUNCS(getpwent setpwent endpwent)
782
783AC_CHECK_FUNCS(fgetspent lckpwdf ulckpwdf)
784AC_CHECK_LIB([sec], [fgetspent], [
785    AC_DEFINE([HAVE_LIBSEC], 1, [Define if -lsec is available])
786    AC_DEFINE([HAVE_FGETSPENT], 1, [Define if fgetspent is available])
787    LIBS="-lsec $LIBS"
788])
789
790AC_CHECK_DECLS(getloadavg)
791AC_FUNC_GETLOADAVG
792
793AC_C_BIGENDIAN
794AC_CHECK_HEADERS([endian.h])
795AC_CHECK_DECLS(le32toh, [], [], [[#include <endian.h>]])
796
797AC_CHECK_DECLS(closefrom, [], [], [[#include <unistd.h>
798                                    #include <stdlib.h>]])
799AC_REPLACE_FUNCS(closefrom)
800
801AC_CHECK_HEADERS([sys/pstat.h])
802AC_CHECK_FUNCS(pstat_getfile2)
803
804CF3_PATH_ROOT_PROG([CHPASSWD], [chpasswd], [], [/sbin:/usr/sbin:/bin:/usr/bin:$PATH])
805AS_IF([test "x$CHPASSWD" != "x"],
806      [AC_DEFINE(HAVE_CHPASSWD, 1, [Define if chpasswd tool is present])]
807      [AC_DEFINE_UNQUOTED(CHPASSWD, ["$CHPASSWD"], [Path to chpasswd tool])]
808     )
809
810dnl AIX has this.
811CF3_PATH_ROOT_PROG([PWDADM], [pwdadm], [], [/sbin:/usr/sbin:/bin:/usr/bin:$PATH])
812AS_IF([test "x$PWDADM" != "x"],
813      [AC_DEFINE(HAVE_PWDADM, 1, [Define if pwdadm tool is present])]
814      [AC_DEFINE_UNQUOTED(PWDADM, ["$PWDADM"], [Path to pwdadm tool])]
815     )
816
817CF3_PATH_ROOT_PROG([USERADD], [useradd], [], [/sbin:/usr/sbin:/bin:/usr/bin:$PATH])
818AS_IF([test "x$USERADD" != "x"],
819      [AC_DEFINE(HAVE_USERADD, 1, [Define if useradd tool is present])]
820      [AC_DEFINE_UNQUOTED(USERADD, ["$USERADD"], [Path to useradd tool])]
821     )
822
823CF3_PATH_ROOT_PROG([USERMOD], [usermod], [], [/sbin:/usr/sbin:/bin:/usr/bin:$PATH])
824AS_IF([test "x$USERMOD" != "x"],
825      [AC_DEFINE(HAVE_USERMOD, 1, [Define if usermod tool is present])]
826      [AC_DEFINE_UNQUOTED(USERMOD, ["$USERMOD"], [Path to usermod tool])]
827     )
828
829CF3_PATH_ROOT_PROG([USERDEL], [userdel], [], [/sbin:/usr/sbin:/bin:/usr/bin:$PATH])
830AS_IF([test "x$USERDEL" != "x"],
831      [AC_DEFINE(HAVE_USERDEL, 1, [Define if userdel tool is present])]
832      [AC_DEFINE_UNQUOTED(USERDEL, ["$USERDEL"], [Path to userdel tool])]
833     )
834
835AS_IF([test "x$USERADD" != x && \
836       test "x$USERMOD" != x && test "x$USERDEL" != x],
837      [have_userprogs=yes],
838      [have_userprogs=no]
839)
840
841
842AC_ARG_WITH([pam], AS_HELP_STRING([--with-pam], [Compile with PAM support]))
843AS_IF([test x$with_pam != xno],
844[
845  CF3_WITH_LIBRARY(pam, [
846    AC_CHECK_LIB(pam, pam_start)
847    AC_CHECK_HEADERS([security/pam_appl.h])
848  ])
849  dnl These platforms must have pam, others can have it, but not required.
850  AS_CASE([$target_os],
851          [*gnu*|*solaris*|*aix*|*hpux*|*hp-ux*], [
852              AS_IF([test "x$ac_cv_lib_pam_pam_start" != "xyes"],
853                    [AC_MSG_ERROR(Cannot find PAM library)]
854              )
855              AS_IF([test "x$ac_cv_header_security_pam_appl_h" != "xyes"],
856                    [AC_MSG_ERROR(Cannot find PAM headers)]
857          )]
858  )
859  AS_IF([test "x$ac_cv_lib_pam_pam_start" = "xyes" && \
860         test "x$ac_cv_header_security_pam_appl_h" = "xyes"],
861        [have_pam=yes],
862        [have_pam=no]
863  )
864  AC_CHECK_FUNCS(fgetpwent fgetgrent)
865  AS_IF([test "x$have_pam" = "xyes" && \
866      test "x$have_userprogs" = "xyes" && \
867      test "x$ac_cv_func_fgetpwent" = "xyes" && \
868      test "x$ac_cv_func_fgetgrent" = "xyes"],
869  [
870      users_promises_ok=yes
871  ],[
872      users_promises_ok=no
873  ])
874], [
875  users_promises_ok=no
876])
877AM_CONDITIONAL(HAVE_USERS_PROMISE_DEPS, [test "x$users_promises_ok" = "xyes"])
878
879AC_CHECK_DECLS(getnetgrent, [], [], [[#include <netdb.h>]])
880AC_CHECK_FUNCS(getnetgrent)
881
882AC_CHECK_DECLS(setnetgrent, [], [], [[#include <netdb.h>]])
883AC_CHECK_FUNCS(setnetgrent)
884AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <netdb.h>]],
885                                   [[extern int setnetgrent(const char *)]])],
886  [AC_DEFINE([SETNETGRENT_RETURNS_INT], 1, [Whether setnetgrent returns int])],
887  [AC_DEFINE([SETNETGRENT_RETURNS_INT], 0, [Whether setnetgrent returns int])])
888
889
890AC_CHECK_DECLS(endnetgrent, [], [], [[#include <netdb.h>]])
891AC_CHECK_FUNCS(endnetgrent)
892AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <netdb.h>]],
893                                   [[extern int endnetgrent(const char *)]])],
894  [AC_DEFINE([ENDNETGRENT_RETURNS_INT], 1, [Whether endnetgrent returns int])],
895  [AC_DEFINE([ENDNETGRENT_RETURNS_INT], 0, [Whether endnetgrent returns int])])
896
897
898AC_CHECK_FUNCS(sendto)
899AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/types.h>
900                                     #include <sys/socket.h>]],
901                                   [[extern ssize_t sendto(int sockfd, const void *buf, size_t len, int flags, const struct sockaddr *dest_addr, socklen_t addrlen)]])],
902    [AC_DEFINE([SENDTO_RETURNS_SSIZE_T], 1, [Whether sendto returns ssize_t])],
903    [AC_DEFINE([SENDTO_RETURNS_SSIZE_T], 0, [Whether sendto does not returns ssize_t])])
904
905CF3_CHECK_PROPER_FUNC([ctime],
906  [],
907  [[#error ctime(3) may produce different results on different OSes. Let's have our POSIX-compliant implementation all the time]],
908  [#define ctime rpl_ctime])
909CF3_REPLACE_PROPER_FUNC([ctime])
910
911dnl Check whether mkdir accepts two parameters
912CF3_CHECK_PROPER_FUNC([mkdir],
913  [[#include <sys/stat.h>
914    #include <sys/types.h>]],
915  [[int mkdir(const char *pathname, mode_t mode);]],
916  [#define mkdir rpl_mkdir])
917
918dnl Check for Win32 stat. We don't know to detect improper stat during
919dnl compilation, so we resort to OS type detection.
920
921CF3_CHECK_PROPER_FUNC([stat],
922  [[#include <sys/types.h>
923    #include <sys/stat.h>]],
924  [[#if defined(__MINGW32__)
925    #error stat in Windows CRT ill-behaves
926    #endif]],
927  [])
928
929dnl Check for Win32 rename. We don't know how to detect improper rename (not
930dnl removing target file if it exists) during cross-compilation, so we resort to
931dnl OS type detection.
932
933CF3_CHECK_PROPER_FUNC([rename],
934  [],
935  [[#if defined(__MINGW32__)
936    #error rename in Windows CRT ill-behaves
937    #endif]],
938  [#define rename rpl_rename])
939
940AC_CHECK_DECLS(mkdtemp)
941AC_REPLACE_FUNCS(mkdtemp)
942
943AC_CHECK_DECLS(strrstr)
944AC_REPLACE_FUNCS(strrstr)
945
946AC_CHECK_DECLS(stpncpy)
947AC_REPLACE_FUNCS(stpncpy)
948
949AC_CHECK_FUNCS(seteuid setegid setreuid setregid)
950AC_CHECK_FUNCS(uname gethostname chflags)
951AC_CHECK_FUNCS(mkfifo statfs statvfs door)
952AC_CHECK_FUNCS(sysinfo setsid sysconf)
953AC_CHECK_FUNCS(getzoneid getzonenamebyid)
954AC_CHECK_FUNCS(fpathconf)
955
956AC_CHECK_MEMBERS([struct stat.st_mtim, struct stat.st_mtimespec])
957AC_CHECK_MEMBERS([struct stat.st_blocks])
958
959AC_MSG_CHECKING([for PRIuMAX/PRIdMAX macros])
960AC_EGREP_CPP([primacros_found],
961  AC_INCLUDES_DEFAULT
962  [#include <inttypes.h>
963  #if defined(PRIuMAX) && defined(PRIdMAX)
964    primacros_found
965  #endif
966  ],
967  [AC_MSG_RESULT(yes)],
968  [AC_MSG_RESULT(no)
969   AC_MSG_RESULT(Unable to find out how to scan intmax_t/uintmax_t types)])
970
971HW_FUNC_VSNPRINTF
972HW_FUNC_SNPRINTF
973HW_FUNC_VASPRINTF
974HW_FUNC_ASPRINTF
975
976dnl dirfd might be a function or a macro
977
978AC_CHECK_DECLS(dirfd, [], [], [AC_INCLUDES_DEFAULT
979#ifdef HAVE_DIRENT_H
980# include <dirent.h>
981#endif
982])
983
984AC_CHECK_FUNCS(dirfd, [], [
985  AC_MSG_CHECKING([for dirfd macro])
986  AC_EGREP_CPP([dirfd_found],
987    AC_INCLUDES_DEFAULT
988    [#ifdef HAVE_DIRENT_H
989    # include <dirent.h>
990    #endif
991    #ifdef dirfd
992      dirfd_found
993    #endif
994    ],
995  [AC_MSG_RESULT(yes)
996  DIRFD_MACRO_FOUND=1],
997  [AC_MSG_RESULT(no)])
998  if test x$DIRFD_MACRO_FOUND = x; then
999    AC_LIBOBJ([dirfd])
1000  fi])
1001
1002AC_CHECK_FUNCS(jail_get)
1003
1004dnl
1005dnl Various functions
1006dnl
1007
1008AC_SEARCH_LIBS(setsockopt, socket)
1009AC_SEARCH_LIBS(gethostent, nsl)
1010
1011AC_CHECK_FUNCS(socket)
1012AC_CHECK_FUNCS(setsockopt)
1013AC_CHECK_FUNCS(gethostent)
1014
1015AC_CHECK_TYPES(struct sockaddr_storage, [], [], [[
1016#if HAVE_WINSOCK2_H
1017    #include <winsock2.h>
1018#endif
1019#if HAVE_WS2TCPIP_H
1020    #include <ws2tcpip.h>
1021#else
1022    #include <sys/socket.h>
1023    #include <netdb.h>
1024#endif]])
1025
1026AC_CHECK_DECLS(getaddrinfo, [], [AC_LIBOBJ(getaddrinfo)], [[
1027#if HAVE_WINSOCK2_H
1028    #include <winsock2.h>
1029#endif
1030#if HAVE_WS2TCPIP_H
1031    #include <ws2tcpip.h>
1032#else
1033    #include <sys/socket.h>
1034    #include <netdb.h>
1035#endif
1036]])
1037
1038AC_CHECK_DECLS([[inet_ntop], [inet_pton]], [], [], [[#include <arpa/inet.h>]])
1039AC_REPLACE_FUNCS(inet_ntop inet_pton)
1040
1041AC_CHECK_FUNCS(getifaddrs)
1042
1043AC_CHECK_FUNCS(getprocs64)
1044
1045AC_CHECK_FUNC(lchown, AC_DEFINE(HAVE_LCHOWN, 1, [Whether to use lchown(3) to change ownerships]))
1046
1047AC_CHECK_DECLS(pthread_attr_setstacksize, [], [], [[#include <pthread.h>]])
1048AC_REPLACE_FUNCS(pthread_attr_setstacksize)
1049
1050AC_CHECK_DECLS(pthread_sigmask, [], [], [[#include <signal.h>]])
1051AC_REPLACE_FUNCS(pthread_sigmask)
1052
1053AC_CHECK_DECLS(sched_yield, [], [], [[#include <sched.h>]])
1054AC_CHECK_FUNCS(sched_yield)
1055
1056AC_CHECK_DECLS([openat], [], [], [[#define _GNU_SOURCE 1
1057                                   #include <fcntl.h>]])
1058AC_CHECK_DECLS([fstatat], [], [], [[#define _GNU_SOURCE 1
1059                                    #include <sys/stat.h>]])
1060AC_CHECK_DECLS([fchownat], [], [], [[#define _GNU_SOURCE 1
1061                                     #include <unistd.h>]])
1062AC_CHECK_DECLS([fchmodat], [], [], [[#define _GNU_SOURCE 1
1063                                    #include <sys/stat.h>]])
1064AC_CHECK_DECLS([readlinkat], [], [], [[#define _GNU_SOURCE 1
1065                                       #include <unistd.h>]])
1066AC_REPLACE_FUNCS(openat fstatat fchownat fchmodat readlinkat)
1067
1068AC_CHECK_DECLS([log2], [], [], [[#include <math.h>]])
1069AC_REPLACE_FUNCS(log2)
1070
1071dnl ######################################################################
1072dnl Required by cf-upgrade. It cannot be implemented in libcompat because
1073dnl cf-upgrade does not link to any libraries except libutils and only
1074dnl statically.
1075dnl ######################################################################
1076AC_CHECK_FUNC(fexecve, AC_DEFINE(HAVE_FEXECVE, 1, [Whether to use fexecve(3) to execute a new process]))
1077
1078dnl ######################################################################
1079dnl These need declarations here, but will be defined in the
1080dnl Enterprise Windows code.
1081dnl ######################################################################
1082
1083AC_CHECK_DECLS(alarm)
1084AC_CHECK_DECLS(chmod)
1085AC_CHECK_DECLS(chown)
1086AC_CHECK_DECLS(fchmod)
1087AC_CHECK_FUNCS(fchmod)
1088AC_CHECK_DECLS(uname)
1089AC_CHECK_DECLS(getuid)
1090AC_CHECK_DECLS(getgid)
1091AC_CHECK_DECLS(lstat)
1092AC_CHECK_FUNCS(sleep)
1093AC_CHECK_DECLS(socketpair, [], [], [[#include <sys/socket.h>]])
1094AC_CHECK_DECLS(fsync)
1095AC_CHECK_DECLS(glob, [], [], [[#include <glob.h>]])
1096
1097dnl ######################################################################
1098dnl Check for sa_len in struct sockaddr
1099dnl ######################################################################
1100
1101AC_CHECK_MEMBERS([struct sockaddr.sa_len], , , [
1102#include <sys/types.h>
1103#include <sys/socket.h>])
1104
1105AC_CHECK_MEMBERS([struct ifreq.ifr_hwaddr],,, [
1106#include <sys/ioctl.h>
1107#include <net/if.h>])
1108
1109dnl BSD uses sys/sysctl.h for CPU counting
1110AC_CHECK_HEADERS(sys/sysctl.h, [], [], [AC_INCLUDES_DEFAULT
1111#ifdef HAVE_SYS_PARAM_H
1112# include <sys/param.h>
1113#endif
1114])
1115
1116dnl ######################################################################
1117dnl Requirements for GetUptimeMinutes() to set $(sys.uptime)
1118dnl ######################################################################
1119dnl Linux sysinfo() call
1120AC_CHECK_MEMBERS([struct sysinfo.uptime], , , [#include <sys/sysinfo.h>])
1121
1122dnl BSD uses sys/sysctl.h to get time-of-boot
1123AC_CHECK_HEADERS(sys/sysctl.h, [], [], [AC_INCLUDES_DEFAULT
1124#ifdef HAVE_SYS_PARAM_H
1125# include <sys/param.h>
1126#endif
1127])
1128
1129dnl Solaris uses kstat.h to get time-of-boot
1130AC_CHECK_HEADERS(kstat.h)
1131dnl SystemV way to get uptime, highly portable
1132AC_CHECK_HEADERS(utmp.h)
1133dnl POSIX way to get uptime
1134AC_CHECK_HEADERS(utmpx.h)
1135
1136dnl #######################################################################
1137dnl Newer BSD systems don't have a compatible rtentry - use ortentry
1138dnl #######################################################################
1139
1140rtry=none
1141AC_MSG_CHECKING(for either struct rtentry or struct ortentry)
1142AC_EGREP_HEADER(rtentry, net/route.h, rtry=rtentry)
1143if test "$rtry" = rtentry; then
1144 AC_DEFINE(HAVE_RTENTRY, 1, [Do we have any route entry structure?])
1145fi
1146AC_EGREP_HEADER(ortentry, net/route.h, rtry=ortentry)
1147if test "$rtry" = ortentry; then
1148 AC_DEFINE(HAVE_ORTENTRY, 1, [The old route entry structure in newer BSDs])
1149fi
1150AC_MSG_RESULT([$rtry])
1151
1152dnl #######################################################################
1153dnl Enable extended attributes. Used for SELinux and ACLs
1154dnl #######################################################################
1155
1156AC_CHECK_FUNCS(llistxattr, [AC_DEFINE(WITH_XATTR, 1, [Define if you have a libc that supports extended attributes])])
1157AC_CHECK_HEADERS([attr/xattr.h sys/xattr.h])
1158
1159AC_MSG_CHECKING([whether xattr functions have extra arguments])
1160AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include <sys/types.h>
1161                                    #include <sys/xattr.h>],
1162                                    [(void)llistxattr("", 0, 0, 0);
1163                                    (void)lgetxattr("", "", 0, 0, 0, 0);
1164                                    (void)lsetxattr("", "", "", 0, 0, 0);
1165                                    (void)lremovexattr("", "", 0);])],
1166                  [AC_DEFINE(WITH_XATTR_EXTRA_ARGS, 1, [Define if your xattr implementation has extra arguments])]
1167                  [AC_MSG_RESULT([yes])],
1168                  [AC_MSG_RESULT([no])])
1169
1170dnl #######################################################################
1171dnl Check for "fancy"(new) C compiler options
1172dnl #######################################################################
1173
1174saved_CFLAGS="$CFLAGS"
1175CFLAGS="-Werror -Wno-tautological-constant-out-of-range-compare"
1176AC_MSG_CHECKING([whether compiler supports -Wno-tautological-constant-out-of-range-compare])
1177AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])],
1178    [AC_MSG_RESULT([yes])]
1179    [NO_TAUTOLOGICAL_CC_OPTION="-Wno-tautological-constant-out-of-range-compare"],
1180    [AC_MSG_RESULT([no])]
1181    [NO_TAUTOLOGICAL_CC_OPTION=""]
1182)
1183CFLAGS="$saved_CFLAGS"
1184AC_SUBST([NO_TAUTOLOGICAL_CC_OPTION])
1185
1186dnl ######################################################################
1187dnl Give the chance to enable SELINUX
1188dnl ######################################################################
1189
1190AC_ARG_ENABLE([selinux], [AS_HELP_STRING([--enable-selinux], [Deprecated. SELinux support is always enabled])])
1191
1192dnl ######################################################################
1193dnl OS specific stuff
1194dnl ######################################################################
1195
1196case "$target_os" in
1197
1198   solaris2.8|solaris2.9)
1199        AC_DEFINE(_XOPEN_SOURCE, 500, [UNIX 98])
1200        AC_DEFINE(__EXTENSIONS__, 1, [Extended UNIX 98 interfaces])
1201        ;;
1202   solaris2.10|solaris2.11)
1203        AC_DEFINE(_XOPEN_SOURCE, 600, [SUSv3])
1204        AC_DEFINE(__EXTENSIONS__, 1, [Extended UNIX 98 interfaces])
1205        ;;
1206   hpux*|hp-ux*)
1207        dnl pstat* functions may fail with EOVERFLOW without this.
1208        AC_DEFINE(_PSTAT64, 1, [Enable wide data structures everywhere])
1209        ;;
1210   aix*)
1211        CPPFLAGS="$CPPFLAGS -w"
1212        ;;
1213   linux*|*bsd*|*gnu*)
1214        AC_CHECK_LIB(nss_nis, yp_get_default_domain)
1215        ;;
1216   freebsd*|dragonfly*)
1217        ;;
1218   netbsd*)
1219        ;;
1220   unicos*)
1221        ;;
1222   cray*)
1223        ;;
1224   qnx*)
1225        ;;
1226   openbsd*|obsd*)
1227        ;;
1228   sysv4.2MP|unix_sv*)
1229        ;;
1230   cygwin*)
1231        ;;
1232   mingw*)
1233        ;;
1234   sco*)
1235        ;;
1236   darwin*)
1237        ;;
1238   *)
1239        AC_MSG_ERROR(Unknown system type $target_os)
1240        ;;
1241esac
1242
1243m4_include([m4/cf3_platforms.m4])
1244
1245dnl #####################################################################
1246dnl Configure directories
1247dnl #####################################################################
1248
1249AC_ARG_WITH(workdir,
1250    [  --with-workdir=WORKDIR  default for internal (trusted) working directory ],
1251    [
1252        if test "x$withval" != x ; then
1253            WORKDIR="$withval"
1254            LOGDIR="$withval"
1255            PIDDIR="$withval"
1256        fi
1257    ],
1258)
1259
1260dnl Expand ${prefix} and whatnot in WORKDIR
1261
1262adl_RECURSIVE_EVAL("${WORKDIR}", WORKDIR)
1263
1264AC_DEFINE_UNQUOTED(WORKDIR, "${WORKDIR}", [Workdir location])
1265AC_SUBST(workdir, "${WORKDIR}")
1266
1267AC_ARG_WITH(masterdir,
1268    [  --with-masterdir=MASTERDIR  default for internal masterfiles directory ],
1269    [
1270        if test "x$withval" != x ; then
1271            MASTERDIR="$withval"
1272        fi
1273    ],
1274)
1275
1276dnl Expand ${prefix} and whatnot in MASTERDIR
1277
1278adl_RECURSIVE_EVAL("${MASTERDIR}", MASTERDIR)
1279
1280AC_DEFINE_UNQUOTED(MASTERDIR, "${MASTERDIR}", [Masterfiles directory location])
1281AC_SUBST(masterdir, "${MASTERDIR}")
1282
1283AC_ARG_WITH(inputdir,
1284    [  --with-inputdir=INPUTDIR  default for internal inputs directory ],
1285    [
1286        if test "x$withval" != x ; then
1287            INPUTDIR="$withval"
1288        fi
1289    ],
1290)
1291
1292dnl Expand ${prefix} and whatnot in INPUTDIR
1293
1294adl_RECURSIVE_EVAL("${INPUTDIR}", INPUTDIR)
1295
1296AC_DEFINE_UNQUOTED(INPUTDIR, "${INPUTDIR}", [Inputs directory location])
1297AC_SUBST(inputdir, "${INPUTDIR}")
1298
1299AC_ARG_WITH(logdir,
1300    [  --with-logdir=LOGDIR  default for internal log directory ],
1301    [
1302        if test "x$withval" != x ; then
1303            LOGDIR="$withval"
1304        fi
1305    ],
1306)
1307
1308dnl Expand ${prefix} and whatnot in LOGDIR
1309
1310adl_RECURSIVE_EVAL("${LOGDIR}", LOGDIR)
1311
1312AC_DEFINE_UNQUOTED(LOGDIR, "${LOGDIR}", [Logdir location])
1313AC_SUBST(logdir, "${LOGDIR}")
1314
1315AC_ARG_WITH(piddir,
1316    [  --with-piddir=LOGDIR  default for internal pid directory ],
1317    [
1318        if test "x$withval" != x ; then
1319            PIDDIR="$withval"
1320        fi
1321    ],
1322)
1323
1324dnl Expand ${prefix} and whatnot in PIDDIR
1325
1326adl_RECURSIVE_EVAL("${PIDDIR}", PIDDIR)
1327
1328AC_DEFINE_UNQUOTED(PIDDIR, "${PIDDIR}", [piddir location])
1329AC_SUBST(piddir, "${PIDDIR}")
1330
1331AC_ARG_WITH(statedir,
1332    [  --with-statedir=STATEDIR  default for internal state directory ],
1333    [
1334        if test "x$withval" != x ; then
1335            STATEDIR="$withval"
1336        fi
1337    ],
1338)
1339
1340dnl Expand ${prefix} and whatnot in STATEDIR
1341
1342adl_RECURSIVE_EVAL("${STATEDIR}", STATEDIR)
1343
1344AC_DEFINE_UNQUOTED(STATEDIR, "${STATEDIR}", [State directory location])
1345AC_SUBST(statedir, "${STATEDIR}")
1346
1347AC_ARG_WITH(shell, [AS_HELP_STRING([--with-shell=PATH],
1348                   [Specify path to POSIX-compatible shell (if not /bin/sh)])],
1349                   [],
1350                   [with_shell=/bin/sh])
1351
1352dnl Expand ${prefix} and whatnot in bindir
1353adl_RECURSIVE_EVAL("${bindir}", bindir)
1354
1355AC_DEFINE_UNQUOTED(BINDIR, "${bindir}", [binaries location])
1356AC_SUBST(bindir, "${bindir}")
1357
1358
1359if test "x$with_shell" = "xno"; then
1360   AC_MSG_ERROR([Please specify full path to POSIX-compatible shell])
1361fi
1362AC_DEFINE_UNQUOTED(SHELL_PATH, "$with_shell", [Path to the POSIX-compatible shell])
1363
1364
1365dnl #####################################################################
1366dnl Hostname and Version stuff
1367dnl #####################################################################
1368
1369AC_PATH_PROG(HOSTNAME, hostname, "", $PATH)
1370
1371AC_DEFINE_UNQUOTED(AUTOCONF_HOSTNAME, "`$HOSTNAME`", [Special CFEngine symbol])
1372AC_DEFINE_UNQUOTED(AUTOCONF_SYSNAME, "$target_os", [Speial CFEngine symbol])
1373
1374
1375dnl #####################################################################
1376dnl xen cpuid-based hvm detection
1377dnl #####################################################################
1378
1379AC_MSG_CHECKING(for Xen cpuid-based HVM detection)
1380if test x"$GCC" = "xyes"; then
1381    case $host_cpu in
1382        i[[3456]]86*|x86_64*|amd64)
1383            AC_DEFINE(XEN_CPUID_SUPPORT, 1, [Define if XEN cpuid-based HVM detection is available.])
1384            AC_MSG_RESULT(yes)
1385            ;;
1386        *)
1387            AC_MSG_RESULT(no)
1388            ;;
1389    esac
1390else
1391    AC_MSG_RESULT(no)
1392fi
1393
1394dnl
1395dnl Code coverage
1396dnl
1397
1398AC_ARG_ENABLE(coverage, AS_HELP_STRING([--enable-coverage], [Enable code coverage]),
1399              [use_coverage=$enableval], [use_coverage=no])
1400
1401if test "x$use_coverage" = "xyes"; then
1402  if test "$GCC" != "yes"; then
1403    AC_MSG_ERROR([GCC is required for --enable-coverage])
1404  fi
1405
1406  AC_CHECK_PROG(LCOV, lcov, lcov)
1407  AC_CHECK_PROG(LCOV_GENHTML, genhtml, genhtml)
1408
1409  if test -z "$LCOV"; then
1410    AC_MSG_ERROR([Cannot find lcov from the LTP package])
1411  fi
1412
1413  if test -z "$LCOV_GENHTML"; then
1414    AC_MSG_ERROR([Could not find genhtml from the LTP package])
1415  fi
1416
1417  dnl Remove all optimization flags from CFLAGS
1418  changequote({,})
1419  CFLAGS=`echo "$CFLAGS" | $SED -e 's/-O[0-9]*//g'`
1420  changequote([,])
1421
1422  dnl Add the special gcc flags
1423  CFLAGS="$CFLAGS -fprofile-arcs -ftest-coverage"
1424  LDFLAGS="$LDFLAGS -lgcov"
1425  # Need to set ENABLE_COVERAGE so that tests/unit/Makefile.am can adapt for one
1426  # test which needs gcov stubs if core not built with coverage.
1427  AM_CONDITIONAL([ENABLE_COVERAGE], true)
1428else
1429  AM_CONDITIONAL([ENABLE_COVERAGE], false)
1430fi
1431
1432dnl ######################################################################
1433dnl Collect all the options
1434dnl ######################################################################
1435
1436CORE_CPPFLAGS="$PCRE_CPPFLAGS $OPENSSL_CPPFLAGS $SQLITE3_CPPFLAGS $LIBACL_CPPFLAGS $LIBCURL_CPPFLAGS $LIBYAML_CPPFLAGS $POSTGRESQL_CPPFLAGS $MYSQL_CPPFLAGS $LIBXML2_CPPFLAGS $CPPFLAGS"
1437CORE_CFLAGS="$PCRE_CFLAGS $OPENSSL_CFLAGS $SQLITE3_CFLAGS $LIBACL_CFLAGS $LIBCURL_CFLAGS $LIBYAML_CFLAGS $POSTGRESQL_CFLAGS $MYSQL_CFLAGS $LIBXML2_CFLAGS $CFLAGS"
1438CORE_LDFLAGS="$PCRE_LDFLAGS $OPENSSL_LDFLAGS $SQLITE3_LDFLAGS $LIBACL_LDFLAGS $LIBCURL_LDFLAGS $LIBYAML_LDFLAGS $POSTGRESQL_LDFLAGS $MYSQL_LDFLAGS $LIBXML2_LDFLAGS $LDFLAGS"
1439CORE_LIBS="$PCRE_LIBS $OPENSSL_LIBS $SQLITE3_LIBS $LIBACL_LIBS $LIBCURL_LIBS $LIBYAML_LIBS $POSTGRESQL_LIBS $MYSQL_LIBS $LIBXML2_LIBS $LIBS"
1440
1441dnl ######################################################################
1442dnl Make them available to subprojects.
1443dnl ######################################################################
1444
1445AC_SUBST([CORE_CPPFLAGS])
1446AC_SUBST([CORE_CFLAGS])
1447AC_SUBST([CORE_LDFLAGS])
1448AC_SUBST([CORE_LIBS])
1449AC_CONFIG_FILES([configure_flags.env])
1450
1451#
1452# Populate contents of config.post.h
1453#
1454AC_SUBST(post_macros)
1455AM_SUBST_NOTMAKE(post_macros)
1456
1457dnl ######################################################################
1458dnl Check how file descriptor transfers are supported between proceses.
1459dnl ######################################################################
1460AC_CHECK_MEMBER([struct msghdr.msg_control],
1461                [AC_DEFINE([HAVE_MSGHDR_MSG_CONTROL], [1], [Define to 1 if SCM_RIGHTS supported])],
1462                [AC_DEFINE([HAVE_NO_MSGHDR_MSG_CONTROL], [1], [Define to 1 if SCM_RIGHTS support])],
1463                [[#include <sys/types.h>
1464                  #include <sys/socket.h>]])
1465
1466AC_CHECK_MEMBER([struct msghdr.msg_accrights],
1467                [AC_DEFINE([HAVE_MSGHDR_ACCRIGHTS], [1], [Define to 1 if BSD .msg_accrights supported])],
1468                [AC_DEFINE([HAVE_NO_MSGHDR_ACCRIGHTS], [1], [Define to 1 if no BSD .msg_accrights support])],
1469                [[#include <sys/types.h>
1470                  #include <sys/socket.h>]])
1471
1472dnl ######################################################################
1473dnl Summarize
1474dnl ######################################################################
1475
1476AC_MSG_RESULT( )
1477
1478AC_MSG_RESULT(Summary:)
1479AC_MSG_RESULT(> Version: AC_PACKAGE_VERSION)
1480
1481AC_MSG_RESULT([> Optional libraries])
1482
1483AC_MSG_RESULT([-> OpenSSL: $OPENSSL_PATH])
1484
1485AC_MSG_RESULT([-> PCRE: $PCRE_PATH])
1486
1487if test "x$ac_cv_lib_mysqlclient_mysql_real_connect" = "xyes"; then
1488  AC_MSG_RESULT([-> MySQL connector: $MYSQL_PATH])
1489else
1490  AC_MSG_RESULT([-> MySQL connector: disabled])
1491fi
1492
1493if test "x$ac_cv_lib_pq_PQconnectdb" = "xyes"; then
1494  AC_MSG_RESULT([-> PostgreSQL connector: $POSTGRESQL_PATH])
1495else
1496  AC_MSG_RESULT([-> PostgreSQL connector: disabled])
1497fi
1498
1499
1500if test "x$ac_cv_lib_virt_virConnectOpen" = xyes; then
1501  AC_MSG_RESULT([-> libvirt: $LIBVIRT_PATH])
1502else
1503  AC_MSG_RESULT([-> libvirt: disabled])
1504fi
1505
1506if test "x$ac_cv_lib_acl_acl_init" = xyes; then
1507  AC_MSG_RESULT([-> libacl: $LIBACL_PATH])
1508else
1509  AC_MSG_RESULT([-> libacl: disabled])
1510fi
1511
1512if test "x$ac_cv_lib_curl_curl_global_init" = xyes; then
1513  AC_MSG_RESULT([-> libcurl: $LIBCURL_PATH])
1514else
1515  AC_MSG_RESULT([-> libcurl: disabled])
1516fi
1517
1518if test "x$ac_cv_lib_yaml_yaml_parser_initialize" = xyes; then
1519  AC_MSG_RESULT([-> libyaml: $LIBYAML_PATH])
1520else
1521  AC_MSG_RESULT([-> libyaml: disabled])
1522fi
1523
1524if test "x$ac_cv_lib_xml2_xmlFirstElementChild" = xyes; then
1525  AC_MSG_RESULT([-> libxml2: $LIBXML2_PATH])
1526else
1527  AC_MSG_RESULT([-> libxml2: disabled])
1528fi
1529
1530if test "x$users_promises_ok" = "xyes"; then
1531  AC_MSG_RESULT([-> User promises: PAM/user* tools])
1532else
1533  AC_MSG_RESULT([-> User promises: disabled])
1534fi
1535
1536if test "x$enable_builtin_extensions" = "xyes"; then
1537  AC_MSG_RESULT([-> Enterprise extensions: Built in])
1538else
1539  AC_MSG_RESULT([-> Enterprise extensions: Plugin or not included])
1540fi
1541
1542m4_indir(incstart[]incend, [nova/config.m4])
1543
1544AC_MSG_RESULT([-> Workdir: $WORKDIR])
1545AC_MSG_RESULT([-> Masterdir: $MASTERDIR])
1546AC_MSG_RESULT([-> Inputdir: $INPUTDIR])
1547AC_MSG_RESULT([-> Logdir: $LOGDIR])
1548AC_MSG_RESULT([-> Piddir: $PIDDIR])
1549AC_MSG_RESULT([-> Statedir: $STATEDIR])
1550AC_MSG_RESULT([-> bindir: $bindir])
1551
1552AC_MSG_RESULT( )
1553
1554dnl ######################################################################
1555dnl Now make the Makefiles
1556dnl ######################################################################
1557
1558AC_CONFIG_FILES([Makefile
1559    libcompat/Makefile
1560    libutils/Makefile
1561    config.post.h
1562    tests/Makefile
1563    tests/unit/Makefile])
1564
1565AC_OUTPUT
1566
1567AC_MSG_RESULT(DONE: Configuration done. Run make/gmake to build libntech.)
1568