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