1# configure.ac - for DirMngr
2#       Copyright (C) 2002 Klarälvdalens Datakonsult AB
3#       Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008,
4#                     2009 g10 Code GmbH
5#
6# This file is part of DirMngr.
7#
8# DirMngr is free software; you can redistribute it and/or modify
9# it under the terms of the GNU General Public License as published by
10# the Free Software Foundation; either version 2 of the License, or
11# (at your option) any later version.
12#
13# DirMngr is distributed in the hope that it will be useful,
14# but WITHOUT ANY WARRANTY; without even the implied warranty of
15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16# GNU General Public License for more details.
17#
18# You should have received a copy of the GNU General Public License
19# along with this program; if not, write to the Free Software
20# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
21# USA.
22
23# Process this file with autoconf to produce a configure script.
24AC_PREREQ(2.59)
25min_automake_version="1.9.3"
26
27# Remember to change the version number immediately *after* a release.
28# Set my_issvn to "yes" for non-released code.  Remember to run an
29# "svn up" and "autogen.sh" right before creating a distribution.
30m4_define([my_version], [1.1.0])
31m4_define([my_issvn], [no])
32
33m4_define([svn_revision], m4_esyscmd([printf "%d" $( (svn info 2>/dev/null \
34            || echo 'Revision: 0')|sed -n '/^Revision:/ {s/[^0-9]//gp;q;}')]))
35AC_INIT([dirmngr],
36        [my_version[]m4_if(my_issvn,[yes],[-svn[]svn_revision])],
37        [bug-dirmngr@gnupg.org])
38
39NEED_GPG_ERROR_VERSION=1.4
40
41NEED_LIBGCRYPT_API=1
42NEED_LIBGCRYPT_VERSION=1.4.0
43
44NEED_LIBASSUAN_API=2
45NEED_LIBASSUAN_VERSION=2.0.0
46
47NEED_KSBA_API=1
48NEED_KSBA_VERSION=1.0.2
49
50COPYRIGHT_YEAR_NAME="2010 g10 Code GmbH"
51
52PACKAGE=$PACKAGE_NAME
53VERSION=$PACKAGE_VERSION
54
55
56AC_CONFIG_SRCDIR(src/dirmngr.c)
57AM_CONFIG_HEADER(config.h)
58AM_INIT_AUTOMAKE($PACKAGE, $VERSION)
59AB_INIT
60
61AC_GNU_SOURCE
62
63# Some status variables to give feedback at the end of a configure run
64have_gpg_error=no
65have_libgcrypt=no
66have_libassuan=no
67have_ksba=no
68have_ldap=no
69have_pth=no
70
71AM_MAINTAINER_MODE
72
73AC_SUBST(PACKAGE)
74AC_SUBST(VERSION)
75AC_DEFINE_UNQUOTED(PACKAGE, "$PACKAGE", [Name of this package])
76AC_DEFINE_UNQUOTED(VERSION, "$VERSION", [Version of this package])
77AC_DEFINE_UNQUOTED(PACKAGE_BUGREPORT, "$PACKAGE_BUGREPORT",
78                                        [Bug report address])
79AC_DEFINE_UNQUOTED(COPYRIGHT_YEAR_NAME, "$COPYRIGHT_YEAR_NAME",
80                                        [Used by --version])
81AC_DEFINE_UNQUOTED(NEED_LIBGCRYPT_VERSION, "$NEED_LIBGCRYPT_VERSION",
82                                       [Required version of Libgcrypt])
83AC_DEFINE_UNQUOTED(NEED_KSBA_VERSION, "$NEED_KSBA_VERSION",
84                                       [Required version of Libksba])
85
86# Checks for programs.
87missing_dir=`cd $ac_aux_dir && pwd`
88AM_MISSING_PROG(ACLOCAL, aclocal, $missing_dir)
89AM_MISSING_PROG(AUTOCONF, autoconf, $missing_dir)
90AM_MISSING_PROG(AUTOMAKE, automake, $missing_dir)
91AM_MISSING_PROG(AUTOHEADER, autoheader, $missing_dir)
92AM_MISSING_PROG(MAKEINFO, makeinfo, $missing_dir)
93AC_PROG_AWK
94AC_PROG_CC
95AC_PROG_CPP
96AM_PROG_CC_C_O
97AC_PROG_INSTALL
98AC_PROG_LN_S
99AC_PROG_MAKE_SET
100AC_PROG_RANLIB
101#AC_ARG_PROGRAM
102AC_SYS_LARGEFILE
103
104AC_ARG_ENABLE(gcc-warnings,
105	      AC_HELP_STRING([--enable-gcc-warnings],
106			     [enable more verbose gcc warnings]),
107	      [more_gcc_warnings="$enableval"],
108	      [more_gcc_warnings="no"])
109
110if test "$GCC" = yes; then
111    if test "$USE_MAINTAINER_MODE" = "yes" ||
112       test "$more_gcc_warnings" = "yes"; then
113        CFLAGS="$CFLAGS -Wall -Wcast-align -Wshadow -Wstrict-prototypes"
114        CFLAGS="$CFLAGS -Wformat -Wno-format-y2k -Wformat-security"
115        if test "$more_gcc_warnings" = "yes"; then
116            CFLAGS="$CFLAGS -W -Wpointer-arith -Wbad-function-cast"
117            CFLAGS="$CFLAGS -Wwrite-strings"
118            CFLAGS="$CFLAGS -Wno-sign-compare -Wno-missing-field-initializers"
119        fi
120    else
121        CFLAGS="$CFLAGS -Wall"
122    fi
123
124    AC_MSG_CHECKING([if gcc supports -Wno-pointer-sign])
125    _gcc_cflags_save=$CFLAGS
126    CFLAGS="-Wno-pointer-sign"
127    AC_COMPILE_IFELSE(AC_LANG_PROGRAM([]),_gcc_psign=yes,_gcc_psign=no)
128    AC_MSG_RESULT($_gcc_psign)
129    CFLAGS=$_gcc_cflags_save;
130    if test x"$_gcc_psign" = xyes ; then
131       CFLAGS="$CFLAGS -Wno-pointer-sign"
132    fi
133fi
134
135# We need to compile and run a program on the build machine.  A
136# comment in libgpg-error says that the AC_PROG_CC_FOR_BUILD macro in
137# the AC archive is broken for autoconf 2.57.  Given that tehre is no
138# newer version of that macro, we assume that it is also broken for
139# autoconf 2.61 and thus we use a simple but usually sufficient
140# approach.
141AC_MSG_CHECKING(for cc for build)
142if test "$cross_compiling" = "yes"; then
143  CC_FOR_BUILD="${CC_FOR_BUILD-cc}"
144else
145  CC_FOR_BUILD="${CC_FOR_BUILD-$CC}"
146fi
147AC_MSG_RESULT($CC_FOR_BUILD)
148AC_ARG_VAR(CC_FOR_BUILD,[build system C compiler])
149
150
151# Tweaks for certain OSes.
152mmap_needed=yes
153have_w32_system=no
154PRINTABLE_OS_NAME=
155case "${host}" in
156    *-*-mingw32*)
157        PRINTABLE_OS_NAME="MingW32"
158	mmap_needed=no
159        have_w32_system=yes
160        ;;
161    *-*-cygwin*)
162        PRINTABLE_OS_NAME="Cygwin"
163        ;;
164    i?86-emx-os2 | i?86-*-os2*emx )
165        PRINTABLE_OS_NAME="OS/2"
166        ;;
167    i?86-*-msdosdjgpp*)
168        PRINTABLE_OS_NAME="MSDOS/DJGPP"
169        try_dynload=no
170        ;;
171    *-*-freebsd*)
172       # Need to include /usr/local for FreeBSD
173       CPPFLAGS="$CPPFLAGS -I/usr/local/include"
174       LDFLAGS="$LDFLAGS -L/usr/local/lib"
175       ;;
176    *-linux*)
177        PRINTABLE_OS_NAME="GNU/Linux"
178        ;;
179esac
180if test -z "$PRINTABLE_OS_NAME"; then
181  PRINTABLE_OS_NAME=`uname -s || echo "Unknown"`
182fi
183
184AC_DEFINE_UNQUOTED(PRINTABLE_OS_NAME, "$PRINTABLE_OS_NAME",
185                   [A human readable text with the name of the OS])
186
187if test "$have_w32_system" = yes; then
188   AC_DEFINE(HAVE_W32_SYSTEM,1, [Defined if we run on a W32 API based system])
189   AC_DEFINE(HAVE_DOSISH_SYSTEM,1, [Defined if we run on a DOS based system])
190fi
191AM_CONDITIONAL(HAVE_W32_SYSTEM, test "$have_w32_system" = yes)
192
193AM_GNU_GETTEXT_VERSION([0.15])
194AM_GNU_GETTEXT([external],[need-ngettext])
195
196#
197# Checks for libraries.
198#
199AM_ICONV
200
201AC_REPLACE_FUNCS(vasprintf)
202if test "$ac_cv_func_vasprintf" != yes; then
203  GNUPG_CHECK_VA_COPY
204fi
205
206#
207# We need the GNU Pth library
208#
209GNUPG_PATH_PTH
210if test "$have_pth" = "yes"; then
211  AC_DEFINE(USE_GNU_PTH, 1,
212              [Defined if the GNU Portable Thread Library should be used])
213fi
214
215
216#
217# libgpg-error is a library with error codes shared between GnuPG
218# related projects.
219#
220AM_PATH_GPG_ERROR("$NEED_GPG_ERROR_VERSION",
221                  have_gpg_error=yes,have_gpg_error=no)
222AC_DEFINE(GPG_ERR_SOURCE_DEFAULT, GPG_ERR_SOURCE_DIRMNGR,
223          [The default error source for GPGME.])
224
225#
226# Libgcrypt is our generic crypto library
227#
228AM_PATH_LIBGCRYPT("$NEED_LIBGCRYPT_API:$NEED_LIBGCRYPT_VERSION",
229        have_libgcrypt=yes,have_libgcrypt=no)
230
231
232#
233# libassuan is used for IPC
234#
235AM_PATH_LIBASSUAN("$NEED_LIBASSUAN_API:$NEED_LIBASSUAN_VERSION",
236                  have_libassuan=yes,have_libassuan=no)
237if test "$have_libassuan" = "yes"; then
238  have_libassuan=no
239  AM_PATH_LIBASSUAN("$NEED_LIBASSUAN_API:$NEED_LIBASSUAN_VERSION",
240		    have_libassuan=yes,have_libassuan=no)
241fi
242
243
244#
245# libksba is our X.509 support library
246#
247AM_PATH_KSBA("$NEED_KSBA_API:$NEED_KSBA_VERSION",have_ksba=yes,have_ksba=no)
248
249
250
251#
252# Must check for network library requirements before doing link tests
253# for ldap, for example. If ldap libs are static (or dynamic and without
254# ELF runtime link paths), then link will fail and LDAP support won't
255# be detected.
256#
257AC_CHECK_FUNC(gethostbyname, , AC_CHECK_LIB(nsl, gethostbyname,
258	[NETLIBS="-lnsl $NETLIBS"]))
259AC_CHECK_FUNC(setsockopt, , AC_CHECK_LIB(socket, setsockopt,
260	[NETLIBS="-lsocket $NETLIBS"]))
261
262#
263# LDAP libraries/includes
264#
265# From gnupg 1.4:
266# Try and link a LDAP test program to weed out unusable LDAP
267# libraries.  -lldap [-llber [-lresolv]] is for older OpenLDAPs.
268# OpenLDAP, circa 1999, was terrible with creating weird dependencies.
269# This seems to have all been resolved, so I'm simplifying this code
270# significantly.  If all else fails, the user can play
271# guess-the-dependency by using something like ./configure
272# LDAPLIBS="-Lfoo -lbar"
273#
274for MY_LDAPLIBS in ${LDAPLIBS+"$LDAPLIBS"} "-lldap" "-lldap -llber" "-lldap -llber -lresolv" "-lwldap32"; do
275    _ldap_save_libs=$LIBS
276    LIBS="$MY_LDAPLIBS $NETLIBS $LIBS"
277
278    AC_MSG_CHECKING([whether LDAP via \"$MY_LDAPLIBS\" is present and sane])
279    AC_TRY_LINK([
280#ifdef _WIN32
281#include <winsock2.h>
282#include <winldap.h>
283#else
284#include <ldap.h>
285#endif
286],[ldap_open("foobar",1234);],
287                [gnupg_cv_func_ldap_init=yes],[gnupg_cv_func_ldap_init=no])
288    AC_MSG_RESULT([$gnupg_cv_func_ldap_init])
289
290    if test "$gnupg_cv_func_ldap_init" = yes ; then
291       LDAPLIBS=$MY_LDAPLIBS
292       have_ldap=yes
293
294       AC_CHECK_FUNCS(ldap_get_option ldap_set_option)
295       # The extra test for ldap_start_tls_sA is for W32 because
296       # that is the actual function in the library.
297       AC_CHECK_FUNCS(ldap_start_tls_s ldap_start_tls_sA)
298
299       if test "$ac_cv_func_ldap_get_option" != yes ; then
300          AC_MSG_CHECKING([whether LDAP supports ld_errno])
301	  AC_TRY_LINK([#include <ldap.h>],[LDAP *ldap; ldap->ld_errno;],
302	     [gnupg_cv_func_ldap_ld_errno=yes],
303	     [gnupg_cv_func_ldap_ld_errno=no])
304          AC_MSG_RESULT([$gnupg_cv_func_ldap_ld_errno])
305
306	  if test "$gnupg_cv_func_ldap_ld_errno" = yes ; then
307	     AC_DEFINE(HAVE_LDAP_LD_ERRNO,1,
308                      [Define if the LDAP library supports ld_errno])
309          fi
310       fi
311    fi
312
313    LIBS=$_ldap_save_libs
314
315    if test $have_ldap = yes ; then break; fi
316done
317AC_SUBST(LDAPLIBS)
318
319
320
321# Checks for header files.
322AC_HEADER_STDC
323AC_CHECK_HEADERS([string.h locale.h])
324
325
326# Checks for typedefs, structures, and compiler characteristics.
327AC_C_CONST
328AC_C_INLINE
329AC_TYPE_SIZE_T
330AC_TYPE_SIGNAL
331AC_DECL_SYS_SIGLIST
332
333GNUPG_CHECK_TYPEDEF(byte, HAVE_BYTE_TYPEDEF)
334GNUPG_CHECK_TYPEDEF(ushort, HAVE_USHORT_TYPEDEF)
335GNUPG_CHECK_TYPEDEF(ulong, HAVE_ULONG_TYPEDEF)
336
337
338AC_CHECK_TYPES([struct sigaction, sigset_t],,,[#include <signal.h>])
339
340
341# Checks for library functions.
342GNUPG_FUNC_MKDIR_TAKES_ONE_ARG
343
344# begin jnlib checks - fixme: we should have a macros for them
345AC_CHECK_FUNCS([memicmp stpcpy strsep strlwr strtoul memmove stricmp strtol])
346AC_CHECK_FUNCS([memrchr isascii timegm getrusage setrlimit stat setlocale])
347AC_CHECK_FUNCS([flockfile funlockfile])
348AC_CHECK_FUNCS([funopen fopencookie])
349# end jnlib checks
350
351AC_CHECK_FUNCS([gmtime_r getaddrinfo strtoull])
352
353AC_CHECK_FUNCS([mmap])
354if test $ac_cv_func_mmap != yes -a $mmap_needed = yes; then
355  AC_MSG_ERROR([[Sorry, the current implemenation requires mmap.]])
356fi
357
358AC_CHECK_FUNCS([canonicalize_file_name])
359
360#
361# Stuff which goes at the bottom of config.h.
362#
363AH_BOTTOM([
364
365/* Hack used for W32: ldap.m4 also tests for the ASCII version of
366   ldap_start_tls_s because that is the actual symbol used in the
367   library.  winldap.h redefines it to our commonly used value,
368   thus we define our usual macro here.  */
369#ifdef HAVE_LDAP_START_TLS_SA
370# ifndef HAVE_LDAP_START_TLS_S
371#  define HAVE_LDAP_START_TLS_S 1
372# endif
373#endif
374
375/* We use jnlib, so tell other modules about it.  */
376#define HAVE_JNLIB_LOGGING 1
377
378/* We don't want the old assuan codes anymore. */
379#define _ASSUAN_ONLY_GPG_ERRORS 1
380
381/* Our HTTP code is used in estream mode.  */
382#define HTTP_USE_ESTREAM 1
383
384/* We want to use the libgcrypt provided memory allocation for
385   asprintf.  */
386#define _ESTREAM_PRINTF_MALLOC        gcry_malloc
387#define _ESTREAM_PRINTF_FREE          gcry_free
388#define _ESTREAM_PRINTF_EXTRA_INCLUDE "util.h"
389])
390
391
392#
393# Print errors here so that they are visible all
394# together and the user can acquire them all together.
395#
396die=no
397if test "$have_gpg_error" = "no"; then
398   die=yes
399   AC_MSG_NOTICE([[
400***
401*** You need libgpg-error to build this program.
402**  This library is for example available at
403***   ftp://ftp.gnupg.org/gcrypt/libgpg-error
404*** (at least version $NEED_GPG_ERROR_VERSION is required.)
405***]])
406fi
407if test "$have_libgcrypt" = "no"; then
408   die=yes
409   AC_MSG_NOTICE([[
410***
411*** You need libgcrypt to build this program.
412**  This library is for example available at
413***   ftp://ftp.gnupg.org/gcrypt/libgcrypt/
414*** (at least version $NEED_LIBGCRYPT_VERSION using API $NEED_LIBGCRYPT_API is required.)
415***]])
416fi
417if test "$have_libassuan" = "no"; then
418   die=yes
419   AC_MSG_NOTICE([[
420***
421*** You need libassuan to build this program.
422*** This library is for example available at
423***   ftp://ftp.gnupg.org/gcrypt/libassuan/
424*** (at least version $NEED_LIBASSUAN_VERSION is required).
425*** Note, that libassuan must have been build with Pth support.
426***]])
427fi
428if test "$have_ksba" = "no"; then
429   die=yes
430    AC_MSG_NOTICE([[
431***
432*** You need libksba to build this program.
433*** This library is for example available at
434***   ftp://ftp.gnupg.org/gcrypt/libksba/
435*** (at least version $NEED_KSBA_VERSION using API $NEED_KSBA_API is required.)
436***]])
437fi
438if test "$have_ldap" = "no"; then
439   die=yes
440    AC_MSG_NOTICE([[
441***
442*** You need a LDAP library to build this program.
443*** Check out
444***    http://www.openldap.org
445*** for a suitable implementation.
446***]])
447fi
448if test "$have_pth" = "no"; then
449   die=yes
450    AC_MSG_NOTICE([[
451***
452*** GNU Portable Threads Library not found.
453*** Download GNU Pth from ftp://ftp.gnu.org/gnu/pth/
454*** On a Debian GNU/Linux system you might want to try
455***   apt-get install libpth-dev
456***]])
457fi
458
459if test "$die" = "yes"; then
460    AC_MSG_ERROR([[
461***
462*** Required libraries not found. Please consult the above messages
463*** and install them before running configure again.
464***]])
465fi
466
467
468
469AC_CONFIG_FILES([ po/Makefile.in
470Makefile
471m4/Makefile
472jnlib/Makefile
473src/Makefile
474doc/Makefile
475doc/examples/Makefile
476tests/Makefile
477])
478AC_OUTPUT
479