Use system memory clearing functions when available.
[pwmd.git] / configure.ac
blobec48332f3669ceb9fbf2dc798d5bb7879905990c
1 dnl Process this file with autoconf to produce a configure script.
2 AC_PREREQ(2.69)
3 AC_INIT([pwmd], [3.1.2-dev], [Ben Kibbey <bjk@luxsci.net>])
4 AC_CONFIG_MACRO_DIR([m4])
5 AC_CONFIG_AUX_DIR(build)
6 AC_CANONICAL_TARGET
7 AM_INIT_AUTOMAKE([foreign dist-bzip2 no-dist-gzip])
8 AC_PROG_MAKE_SET
9 AC_USE_SYSTEM_EXTENSIONS()
10 AC_CONFIG_SRCDIR([src/pwmd.c])
11 AM_CONFIG_HEADER([config.h])
12 AM_GNU_GETTEXT([external])
13 AM_GNU_GETTEXT_VERSION([0.19.8])
15 REQUIRE_LIBGCRYPT_VERSION="1.5.0"
16 REQUIRE_LIBASSUAN_VERSION="2.3.0"
17 REQUIRE_LIBGPGERROR_VERSION="1.18"
18 REQUIRE_LIBGPGME_VERSION="1.9.1"
19 REQUIRE_GNUPG_VERSION="2.1.15"
20 REQUIRE_LIBGNUTLS_VERSION="3.3.0"
22 AC_DEFINE_UNQUOTED(REQUIRE_LIBASSUAN_VERSION, "$REQUIRE_LIBASSUAN_VERSION",
23           [Minimum libassuan version.])
24 AC_DEFINE_UNQUOTED(REQUIRE_LIBGCRYPT_VERSION, "$REQUIRE_LIBGCRYPT_VERSION",
25           [Minimum libgcrypt version.])
26 AC_DEFINE_UNQUOTED(REQUIRE_LIBGPGERROR_VERSION, "$REQUIRE_LIBGPGERROR_VERSION",
27           [Minimum libgpg-error version.])
28 AC_DEFINE_UNQUOTED(REQUIRE_LIBGPGME_VERSION, "$REQUIRE_LIBGPGME_VERSION",
29           [Minimum libgpgme version.])
30 AC_DEFINE_UNQUOTED(REQUIRE_GNUPG_VERSION, "$REQUIRE_GNUPG_VERSION",
31           [Minimum gnupg version.])
32 AC_DEFINE_UNQUOTED(REQUIRE_LIBGNUTLS_VERSION, "$REQUIRE_LIBGNUTLS_VERSION",
33           [Minimum libgnutls version.])
35 dnl Checks for programs.
36 AC_C_BIGENDIAN
37 AC_PROG_CC_C99
38 AX_CC_FOR_BUILD
40 if test "$ac_cv_prog_cc_c99" = "no"; then
41     AC_MSG_WARN([Unable to find a C99 compatible compiler.])
44 AC_PROG_AWK
45 AC_PROG_LN_S
46 AC_PROG_INSTALL
47 AC_PROG_LN_S
48 AC_PROG_CPP
49 AC_PROG_MKDIR_P
51 dnl Checks for library functions.
52 AX_CHECK_COMPILE_FLAG([-D_FORTIFY_SOURCE=2],
53                       [CPPFLAGS="$CPPFLAGS -D_FORTIFY_SOURCE=2"])
54 AX_PTHREAD(, AC_MSG_ERROR([POSIX threads are required.]))
55 CC="$PTHREAD_CC"
56 CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
57 LIBS="$PTHREAD_LIBS $LIBS"
59 acx_pthread_testcancel_ok=no
60 AC_MSG_CHECKING([for pthread_testcancel()])
61 AC_TRY_LINK_FUNC(pthread_testcancel, acx_pthread_testcancel_ok=yes)
62 AC_MSG_RESULT($acx_pthread_testcancel_ok)
63 if test x"$acx_pthread_testcancel_ok" = "xyes"; then
64     AC_DEFINE(HAVE_PTHREAD_TESTCANCEL, 1, [Define if your OS has pthread_testcancel().])
67 acx_pthread_cancel_ok=no
68 AC_MSG_CHECKING([for pthread_cancel()])
69 AC_TRY_LINK_FUNC(pthread_cancel, acx_pthread_cancel_ok=yes)
70 AC_MSG_RESULT($acx_pthread_cancel_ok)
71 if test x"$acx_pthread_cancel_ok" = "xyes"; then
72     AC_DEFINE(HAVE_PTHREAD_CANCEL, 1, [Define if your OS has pthread_cancel().])
75 acx_pthread_atfork_ok=no
76 AC_MSG_CHECKING([for pthread_atfork()])
77 AC_TRY_LINK_FUNC(pthread_atfork, acx_pthread_atfork_ok=yes)
78 AC_MSG_RESULT($acx_pthread_atfork_ok)
79 if test x"$acx_pthread_atfork_ok" = "xyes"; then
80     AC_DEFINE(HAVE_PTHREAD_ATFORK, 1, [Define if your OS has pthread_atfork().])
83 dnl Checks for header files.
84 AC_HEADER_STDC
85 AC_HEADER_SYS_WAIT
87 AC_CHECK_HEADERS([fcntl.h stdlib.h string.h strings.h sys/time.h unistd.h \
88                   libintl.h locale.h syslog.h termios.h getopt.h limits.h \
89                   time.h sys/select.h sys/file.h arpa/inet.h inttypes.h \
90                   netdb.h netinet/in.h stddef.h sys/ioctl.h sys/socket.h \
91                   wchar.h wctype.h])
93 AC_CHECK_DECLS([SO_BINDTODEVICE],,, [[#include <sys/types.h>
94                                       #include <sys/socket.h>]])
96 case "${host}" in
97     *-linux-androideabi)
98         PTHREAD_CFLAGS="-pthread"
99         PTHREAD_LIBS="-pthread"
100         ;;
101     *)
102         ;;
103 esac
105 case "$target_os" in
106      linux*)
107         AC_CHECK_HEADERS([linux/sockios.h sys/prctl.h])
108         if test "x$ac_cv_header_linux_sockios_h" = xyes; then
109                 AC_CHECK_DECL([SIOCOUTQ],,, [[#include <linux/sockios.h>]])
110                 if test "x$ac_cv_have_decl_SIOCOUTQ" = xyes; then
111                         AC_DEFINE(HAVE_DECL_SIOCOUTQ, 1,
112                                 [Defined if SIOCOUTQ is available (Linux specific)])
113                 fi
114         fi
116         if test "x$ac_cv_header_sys_prctl_h" = xyes; then
117            AC_CHECK_DECL([PR_SET_NAME],,, [[#include <sys/prctl.h>]])
118               if test "x$ac_cv_have_decl_PR_SET_NAME" = xyes; then
119                     AC_DEFINE(HAVE_PR_SET_NAME, 1,
120                              [Defined if PR_SET_NAME is available (Linux specific)])
121               fi
123            AC_CHECK_DECL([PR_SET_DUMPABLE],,, [[#include <sys/prctl.h>]])
124               if test "x$ac_cv_have_decl_PR_SET_DUMPABLE" = xyes; then
125                     AC_DEFINE(HAVE_PR_SET_DUMPABLE, 1,
126                              [Defined if PR_SET_DUMPABLE is available (Linux specific)])
127               fi
128         fi
129         ;;
130      openbsd*)
131         ;;
132      *bsd*)
133         AC_CHECK_HEADERS([sys/filio.h])
134         if test "x$ac_cv_header_sys_filio_h" = xyes; then
135                 AC_CHECK_DECL([FIONWRITE],,, [[#include <sys/filio.h>]])
136                 if test "x$ac_cv_have_decl_FIONWRITE" = xyes; then
137                         AC_DEFINE(HAVE_DECL_FIONWRITE, 1,
138                                 [Defined if FIONWRITE is available (*BSD specific, not OpenBSD)])
139                 fi
140         fi
141         ;;
142       *cygwin*)
143         AC_DEFINE(HAVE_WINLIKE_SYSTEM, 1, [Define if this is a Windows-like system.])
144         ;;
145      *)
146 dnl     All others use SO_SNDLOWAT.
147         ;;
148 esac
150 dnl Checks for typedefs, structures, and compiler characteristics.
151 AC_TYPE_UID_T
152 AC_C_INLINE
153 AC_TYPE_MODE_T
154 AC_TYPE_OFF_T
155 AC_TYPE_PID_T
156 AC_TYPE_SIZE_T
157 AC_TYPE_SSIZE_T
158 AC_TYPE_UINT32_T
159 AC_TYPE_UINT64_T
160 AC_TYPE_UINT8_T
162 dnl Checks for library functions.
163 AM_GNU_GETTEXT
164 AC_FUNC_STAT
165 AC_FUNC_FORK
166 AC_FUNC_MEMCMP
167 AC_FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK
168 AC_FUNC_STRFTIME
169 AC_CHECK_FUNCS([memset mkdir munmap setlocale socket strchr strerror strrchr \
170                 strstr strtol setrlimit mlockall getopt_long backtrace \
171                 getpwnam_r getgrnam_r flock readdir_r clock_gettime getcwd \
172                 isascii memchr memmove pathconf putenv select strcasecmp \
173                 strncasecmp strrchr strtoul explicit_bzero memset_s])
174 AM_CONDITIONAL([NEED_GETOPT_LONG], [test "$ac_cv_func_getopt_long" != "yes"])
176 AM_PATH_GPG_ERROR($REQUIRE_LIBGPGERROR_VERSION,, AC_MSG_ERROR([libgpg-error >= $REQUIRE_LIBGPGERROR_VERSION not found]))
177 AM_PATH_LIBASSUAN($REQUIRE_LIBASSUAN_VERSION,, AC_MSG_ERROR([libassuan >= $REQUIRE_LIBASSUAN_VERSION not found]))
178 AM_PATH_LIBGCRYPT([1:$REQUIRE_LIBGCRYPT_VERSION],, AC_MSG_ERROR([libgcrypt >= $REQUIRE_LIBGCRYPT_VERSION not found]))
179 AM_PATH_GPGME_PTHREAD($REQUIRE_LIBGPGME_VERSION,, AC_MSG_ERROR([libgpgme >= $REQUIRE_LIBGPGME_VERSION not found]))
180 AM_PATH_XML2(,, AC_MSG_ERROR([libxml2 not found]))
181 AC_SEARCH_LIBS([clock_gettime], [rt])
183 dnl Remote TCP/TLS connections.
184 AC_ARG_ENABLE(gnutls, AC_HELP_STRING([--enable-gnutls],
185               [Enable TCP (GnuTLS) server support.]), USE_GNUTLS=$enableval,
186               USE_GNUTLS=no)
187 if test "x$USE_GNUTLS" = "xyes"; then
188     PKG_CHECK_MODULES([GNUTLS], [gnutls >= $REQUIRE_LIBGNUTLS_VERSION])
189     AC_DEFINE(WITH_GNUTLS, 1, [Define if you want TCP (GnuTLS) support.])
191 AM_CONDITIONAL(WITH_GNUTLS, [test "x$USE_GNUTLS" = "xyes"])
193 dnl Libacl support (for data files).
194 AC_ARG_ENABLE(acl, AC_HELP_STRING([--enable-acl],
195               [Enable Access Control List support for data files]),
196               [USE_LIBACL=yes], [USE_LIBACL=no])
197 if test "x$USE_LIBACL" = "xyes"; then
198     AC_SEARCH_LIBS([acl_get_file], [acl],,
199                    AC_MSG_ERROR([Missing or incomplete libacl installation.]))
200     AC_CHECK_HEADER([sys/acl.h],,
201                    AC_MSG_ERROR([Missing or incomplete libacl installation.]))
202     AC_DEFINE(WITH_LIBACL, 1, [Define if you want libacl support.])
204 AM_CONDITIONAL(WITH_LIBACL, [test "x$USE_LIBACL" = "xyes"])
206 AC_DEFUN([AC_DEBUG],
208     if test "$1"; then
209         ac_cv_sys_debug=$1
210     fi
212     AC_CACHE_CHECK([if debugging is wanted], [ac_cv_sys_debug],
213         [ac_cv_sys_debug=no])
214     AM_CONDITIONAL([WITH_DEBUG], [test "$ac_cv_sys_debug" = "yes"])
217 AC_ARG_ENABLE(debug, AC_HELP_STRING([--enable-debug], [Enable debugging (memory de/allocations output).]),
218     AC_DEBUG([$enableval]), AC_DEBUG)
220 AC_DEFUN([AC_MEM_DEBUG],
222     if test "$1"; then
223         ac_cv_sys_mem_debug=$1
224     fi
226     AC_CACHE_CHECK([if memory debugging is wanted], [ac_cv_sys_mem_debug],
227         [ac_cv_sys_mem_debug=no])
228     AM_CONDITIONAL([WITH_MEM_DEBUG], [test "$ac_cv_sys_mem_debug" = "yes"])
231 AC_DEFUN([AC_MUTEX_DEBUG],
233     if test "$1"; then
234         ac_cv_sys_mutex_debug=$1
235     fi
237     AC_CACHE_CHECK([if mutex debugging is wanted], [ac_cv_sys_mutex_debug],
238         [ac_cv_sys_mutex_debug=no])
239     AM_CONDITIONAL([WITH_MUTEX_DEBUG], [test "$ac_cv_sys_mutex_debug" = "yes"])
242 AC_ARG_ENABLE(mutex_debug, AC_HELP_STRING([--enable-mutex-debug], [Enable mutex debugging output.]),
243     AC_MUTEX_DEBUG([$enableval]), AC_MUTEX_DEBUG)
245 dnl Memory debugging.
246 AC_ARG_ENABLE(mem_debug, AC_HELP_STRING([--enable-mem-debug], [Disable internal memory manager.]),
247     AC_MEM_DEBUG([$enableval]), AC_MEM_DEBUG)
248 AM_CONDITIONAL(MEM_DEBUG, test x"${ac_cv_sys_mem_debug}" != xno)
250 # Default pwmd home directory.
251 AC_ARG_WITH(pwmd_homedir, AC_HELP_STRING([--with-pwmd-homedir=PATH],
252               [Default pwmd home directory (~/.pwmd)]),
253               pwmd_homedir="$withval", pwmd_homedir=)
254 if test x"$pwmd_homedir" != "x"; then
255    AC_DEFINE_UNQUOTED(PWMD_HOMEDIR, ["$pwmd_homedir"],
256                                     [Default pwmd home directory (~/.pwmd).])
259 VERSION_MAJOR="`echo "$VERSION" | sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*/\1/'`"
260 VERSION_MINOR="`echo "$VERSION" | sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*/\2/'`"
261 VERSION_PATCH="`echo "$VERSION" | sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*/\3/'`"
262 VERSION_NUM="`printf 0x%02x%02x%02X ${VERSION_MAJOR} ${VERSION_MINOR} ${VERSION_PATCH}`"
263 AC_DEFINE_UNQUOTED(VERSION_HEX, ${VERSION_NUM}, [For the file header.])
265 AC_CONFIG_FILES([Makefile src/Makefile doc/Makefile doc/pwmd-dump.1 \
266                  po/Makefile.in tests/Makefile])
267 AC_OUTPUT
268 echo
269 echo "Features:"
270 echo "    TCP (GnuTLS)....: $USE_GNUTLS"
271 echo "    Data file ACL's.: $USE_LIBACL"
273 if test x"$pwmd_homedir" != "x"; then
274 echo "    Home directory..: $pwmd_homedir"
275 else
276 echo "    Home directory..: ~/.pwmd"
279 echo "    Debug...........: ${ac_cv_sys_debug}"
280 echo "    Memory debug....: ${ac_cv_sys_mem_debug}"
281 echo "    Mutex debug.....: ${ac_cv_sys_mutex_debug}"