Merged changes from upstream libassuan to allow building a W32 DLL.
[gpgme.git] / configure.ac
1 # configure.ac for GPGME
2 # Copyright (C) 2000 Werner Koch (dd9jn)
3 # Copyright (C) 2001, 2002, 2003, 2004, 2005 g10 Code GmbH
4
5 # This file is part of GPGME.
6
7 # GPGME is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU Lesser General Public License as
9 # published by the Free Software Foundation; either version 2.1 of the
10 # License, or (at your option) any later version.
11
12 # GPGME is distributed in the hope that it will be useful, but WITHOUT
13 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 # or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General
15 # Public License for more details.
16
17 # You should have received a copy of the GNU Lesser General Public
18 # License along with this program; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
20  
21 # (Process this file with autoconf to produce a configure script.)
22
23 AC_PREREQ(2.59)
24 min_automake_version="1.9.3"
25
26 # Version number: Remember to change it immediately *after* a release.
27 AC_INIT(gpgme, 1.1.0-cvs, [bug-gpgme@gnupg.org])
28 # LT Version numbers, remember to change them just *before* a release.
29 #   (Code changed:                      REVISION++)
30 #   (Interfaces added/removed/changed:  CURRENT++, REVISION=0)
31 #   (Interfaces added:                  AGE++)
32 #   (Interfaces removed/changed:        AGE=0)
33 #
34 LIBGPGME_LT_CURRENT=14
35 # Subtract 2 from this value if you want to make the LFS transition an
36 # ABI break.  [Note to self: Remove this comment with the next regular break.]
37 LIBGPGME_LT_AGE=3
38 LIBGPGME_LT_REVISION=3
39
40 # If the API is changed in an incompatible way: increment the next counter.
41 GPGME_CONFIG_API_VERSION=1
42
43 NEED_GPG_VERSION=1.2.2
44 NEED_GPGSM_VERSION=1.9.6
45 ##############################################
46
47
48 PACKAGE=$PACKAGE_NAME
49 VERSION=$PACKAGE_VERSION
50
51 AC_CONFIG_SRCDIR(gpgme/gpgme.h)
52 dnl FIXME: Enable this with autoconf 2.59.
53 dnl AC_CONFIG_MACRO_DIR(m4)
54 AM_CONFIG_HEADER(config.h)
55 AM_INIT_AUTOMAKE($PACKAGE, $VERSION)
56 AM_MAINTAINER_MODE
57 AC_CANONICAL_HOST
58
59 # Enable GNU extensions on systems that have them.
60 AC_GNU_SOURCE
61
62 AH_VERBATIM([_REENTRANT],
63 [/* To allow the use of GPGME in multithreaded programs we have to use
64   special features from the library.
65   IMPORTANT: gpgme is not yet fully reentrant and you should use it
66   only from one thread.  */
67 #ifndef _REENTRANT
68 # define _REENTRANT 1
69 #endif])
70
71 AC_PROG_CC
72
73
74 AC_SUBST(LIBGPGME_LT_CURRENT)
75 AC_SUBST(LIBGPGME_LT_AGE)
76 AC_SUBST(LIBGPGME_LT_REVISION)
77 AC_DEFINE_UNQUOTED(NEED_GPG_VERSION, "$NEED_GPG_VERSION",
78                                      [Min. needed GnuPG version.])
79 AC_DEFINE_UNQUOTED(NEED_GPGSM_VERSION, "$NEED_GPGSM_VERSION",
80                                        [Min. needed GPGSM version.])
81
82 AC_SUBST(PACKAGE)
83 AC_SUBST(VERSION)
84 AC_DEFINE_UNQUOTED(PACKAGE, "$PACKAGE", [Name of this package])
85 AC_DEFINE_UNQUOTED(VERSION, "$VERSION", [Version of this package])
86
87 # Don't default to build static libs.
88 AC_DISABLE_STATIC
89 AC_PROG_LIBTOOL
90
91 # For now we hardcode the use of version scripts.  It would be better
92 # to write a test for this or even implement this within libtool.
93 have_ld_version_script=no
94 case "${host}" in
95     *-*-linux*)
96         have_ld_version_script=yes
97         ;;
98     *-*-gnu*)
99         have_ld_version_script=yes
100         ;;
101 esac
102 AM_CONDITIONAL(HAVE_LD_VERSION_SCRIPT, test "$have_ld_version_script" = "yes")
103
104 GPG_DEFAULT=no
105 GPGSM_DEFAULT=no
106 component_system=None
107 have_dosish_system=no
108 have_w32_system=no
109 case "${host}" in
110     *-mingw32*)
111         # special stuff for Windoze NT
112         have_dosish_system=yes
113         have_w32_system=yes
114         GPG_DEFAULT='c:\\gnupg\\gpg.exe'
115         # XXX Assuan is not supported in this configuration.
116         #GPGSM_DEFAULT='c:\\gnupg\\gpgsm.exe'
117         #component_system='COM+'
118         ;;
119     *)
120         AC_CHECK_PTH(1.2.0,,,no,have_pth=yes)
121         if test "$have_pth" = yes; then
122           AC_DEFINE(HAVE_PTH, ,[Define if we have Pth.])
123           CFLAGS="$CFLAGS $PTH_CFLAGS"
124         fi
125         AC_CHECK_LIB(pthread,pthread_create,have_pthread=yes)
126         if test "$have_pthread" = yes; then
127           AC_DEFINE(HAVE_PTHREAD, ,[Define if we have pthread.])
128         fi
129
130         # XXX: Probably use exec-prefix here?
131 #       GPG_DEFAULT='/usr/bin/gpg'
132 #       GPGSM_DEFAULT='/usr/bin/gpgsm'
133         ;;
134 esac
135
136 if test "$have_dosish_system" = yes; then
137    AC_DEFINE(HAVE_DOSISH_SYSTEM,1,
138              [Defined if we run on some of the PCDOS like systems 
139               (DOS, Windoze. OS/2) with special properties like
140               no file modes])
141 fi
142 AM_CONDITIONAL(HAVE_DOSISH_SYSTEM, test "$have_dosish_system" = yes)
143
144 if test "$have_w32_system" = yes; then
145    AC_DEFINE(HAVE_W32_SYSTEM,1, [Defined if we run on a W32 API based system])
146 fi
147 AM_CONDITIONAL(HAVE_W32_SYSTEM, test "$have_w32_system" = yes)
148
149
150 AM_CONDITIONAL(HAVE_PTH, test "$have_pth" = "yes")
151 AM_CONDITIONAL(HAVE_PTHREAD, test "$have_pthread" = "yes")
152
153
154 # Checks for header files.
155 AC_CHECK_HEADERS(sys/select.h)
156
157
158 # Type checks.
159 AC_CHECK_SIZEOF(unsigned int)
160 AC_SYS_LARGEFILE
161 AC_TYPE_OFF_T
162
163 # Checks for compiler features.
164 if test "$GCC" = yes; then
165     CFLAGS="$CFLAGS -Wall -Wcast-align -Wshadow -Wstrict-prototypes"
166 fi
167
168
169 # Checks for library functions.
170 AC_FUNC_FSEEKO
171
172 AC_CHECK_FUNCS(stpcpy)
173
174 AC_REPLACE_FUNCS(vasprintf)
175 if test "$ac_cv_func_vasprintf" != yes; then
176   GNUPG_CHECK_VA_COPY
177 fi
178
179 # Try to find a thread-safe version of ttyname().
180 AC_REPLACE_FUNCS(ttyname_r)
181 if test "$ac_cv_func_ttyname_r" != yes; then
182   AC_MSG_WARN([
183 ***
184 *** ttyname() is not thread-safe and ttyname_r() does not exist
185 ***])
186 fi
187
188 # Try to find a thread-safe version of getenv().
189 have_thread_safe_getenv=no
190 jm_GLIBC21
191 if test $GLIBC21 = yes; then
192   have_thread_safe_getenv=yes
193 fi
194 if test $have_thread_safe_getenv = yes; then
195   AC_DEFINE(HAVE_THREAD_SAFE_GETENV, [1], [Define if getenv() is thread-safe])
196 fi
197 have_getenv_r=no
198 AC_CHECK_FUNCS(getenv_r, have_getenv_r=yes)
199 if test $have_getenv_r = no && test $have_thread_safe_getenv = no; then
200   AC_MSG_WARN([
201 ***
202 *** getenv() is not thread-safe and getenv_r() does not exist
203 ***])
204 fi
205
206 # For converting time strings to seconds since Epoch, we need the timegm
207 # function.
208 AC_CHECK_FUNCS(timegm)
209 if test "$ac_cv_func_timegm" != yes; then
210   AC_MSG_WARN([
211 ***
212 *** timegm() not available - a non-thread-safe kludge will be used
213 *** and the TZ variable might be changed at runtime.
214 ***])
215 fi
216
217 # Checking for libgpg-error.
218 AM_PATH_GPG_ERROR(0.5,, AC_MSG_ERROR([libgpg-error was not found]))
219 AC_DEFINE(GPG_ERR_SOURCE_DEFAULT, GPG_ERR_SOURCE_GPGME,
220           [The default error source for GPGME.])
221
222
223
224 # Checks for system services
225 NO_OVERRIDE=no
226 AC_ARG_WITH(gpg,
227             AC_HELP_STRING([--with-gpg=PATH], [use GnuPG binary at PATH]),
228             GPG=$withval, NO_OVERRIDE=yes)
229 if test "$NO_OVERRIDE" = "yes" || test "$GPG" = "yes"; then
230   GPG=
231   NO_OVERRIDE=yes
232   if test "$cross_compiling" != "yes"; then
233     AC_PATH_PROG(GPG, gpg)
234   fi
235   if test -z "$GPG"; then
236     GPG="$GPG_DEFAULT"
237   fi
238 fi
239 if test "$GPG" = no; then
240   if test "$NO_OVERRIDE" = "yes"; then
241     if test "$cross_compiling" != "yes"; then
242       AC_MSG_WARN([
243 ***
244 *** Could not find GnuPG, install GnuPG or use --with-gpg=PATH to enable it
245 ***])
246     else
247       AC_MSG_ERROR([
248 ***
249 *** Can not determine path to GnuPG when cross-compiling, use --with-gpg=PATH
250 ***])
251     fi
252   fi
253 else
254   AC_DEFINE_UNQUOTED(GPG_PATH, "$GPG", [Path to the GnuPG binary.])
255   AC_SUBST(GPG)
256 fi
257 dnl Check for GnuPG version requirement.
258 GPG_VERSION=unknown
259 ok=maybe
260 if test -z "$GPG" -o "x$GPG" = "xno"; then
261   ok=no
262 else
263   if test "$cross_compiling" = "yes"; then
264     AC_MSG_WARN([GnuPG version can not be checked when cross compiling])
265     ok=no
266   else
267     if test ! -x "$GPG"; then
268       AC_MSG_WARN([GnuPG not executable, version check disabled])
269       ok=no
270     fi
271   fi
272 fi
273 if test "$ok" = "maybe"; then
274   AC_MSG_CHECKING(for GnuPG >= $NEED_GPG_VERSION)
275   req_major=`echo $NEED_GPG_VERSION | \
276              sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\1/'`
277   req_minor=`echo $NEED_GPG_VERSION | \
278              sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\2/'`
279   req_micro=`echo $NEED_GPG_VERSION | \
280              sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\3/'`
281   gpg_version=`$GPG --version | grep ^gpg`
282   major=`echo $gpg_version | \
283          sed 's/^gpg (GnuPG) \([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*/\1/'`
284   minor=`echo $gpg_version | \
285          sed 's/^gpg (GnuPG) \([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*/\2/'`
286   micro=`echo $gpg_version | \
287          sed 's/^gpg (GnuPG) \([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*/\3/'`
288   GPG_VERSION=`echo $gpg_version | sed 's/^gpg (GnuPG) //'`
289
290   if test "$major" -gt "$req_major"; then
291     ok=yes
292   else
293     if test "$major" -eq "$req_major"; then
294       if test "$minor" -gt "$req_minor"; then
295         ok=yes
296       else
297         if test "$minor" -eq "$req_minor"; then
298           if test "$micro" -ge "$req_micro"; then
299             ok=yes
300           fi
301         fi
302       fi
303     fi
304   fi
305   if test "$ok" = "yes"; then
306     AC_MSG_RESULT(yes)
307   else
308     AC_MSG_RESULT(no)
309     AC_MSG_WARN([GnuPG must be at least version $NEED_GPG_VERSION])
310   fi
311 fi
312 AM_CONDITIONAL(RUN_GPG_TESTS, test "$ok" = "yes")
313 AC_SUBST(GPG_PATH)
314
315 NO_OVERRIDE=no
316 AC_ARG_WITH(gpgsm,
317             AC_HELP_STRING([--with-gpgsm=PATH], [use GpgSM binary at PATH]),
318             GPGSM=$withval, NO_OVERRIDE=yes)
319 if test "$NO_OVERRIDE" = "yes" || test "$GPGSM" = "yes"; then
320   GPGSM=
321   NO_OVERRIDE=yes
322   if test "$cross_compiling" != "yes"; then
323     AC_PATH_PROG(GPGSM, gpgsm)
324   fi
325   if test -z "$GPGSM"; then
326     GPGSM="$GPGSM_DEFAULT"
327   fi
328 fi
329 if test "$GPGSM" = no; then
330   if test "$NO_OVERRIDE" = "yes"; then
331     if test "$cross_compiling" != "yes"; then
332       AC_MSG_WARN([
333 ***
334 *** Could not find GpgSM, install GpgSM or use --with-gpgsm=PATH to enable it
335 ***])
336     else
337       AC_MSG_ERROR([
338 ***
339 *** Can not determine path to GpgSM when cross-compiling, use --with-gpgsm=PATH
340 ***])
341     fi
342   fi
343 else
344   AC_DEFINE_UNQUOTED(GPGSM_PATH, "$GPGSM", [Path to the GPGSM binary.])
345   AC_SUBST(GPGSM)
346 fi
347 AM_CONDITIONAL(HAVE_GPGSM, test "$GPGSM" != "no")
348 dnl Check for GPGSM version requirement.
349 GPGSM_VERSION=unknown
350 ok=maybe
351 if test -z "$GPGSM" -o "x$GPGSM" = "xno"; then
352   ok=no
353 else
354   if test "$cross_compiling" = "yes"; then
355     AC_MSG_WARN([GPGSM version can not be checked when cross compiling])
356     ok=no
357   else
358     if test ! -x "$GPGSM"; then
359       AC_MSG_WARN([GPGSM not executable, version check disabled])
360       ok=no
361     fi
362   fi
363 fi
364 if test "$ok" = "maybe"; then
365   AC_MSG_CHECKING(for GPGSM >= $NEED_GPGSM_VERSION)
366   req_major=`echo $NEED_GPGSM_VERSION | \
367              sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\1/'`
368   req_minor=`echo $NEED_GPGSM_VERSION | \
369              sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\2/'`
370   req_micro=`echo $NEED_GPGSM_VERSION | \
371              sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\3/'`
372   gpgsm_version=`$GPGSM --version | grep ^gpgsm`
373   major=`echo $gpgsm_version | \
374          sed 's/^gpgsm (GnuPG) \([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*/\1/'`
375   minor=`echo $gpgsm_version | \
376          sed 's/^gpgsm (GnuPG) \([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*/\2/'`
377   micro=`echo $gpgsm_version | \
378          sed 's/^gpgsm (GnuPG) \([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*/\3/'`
379   GPGSM_VERSION=`echo $gpgsm_version | sed 's/^gpgsm (GnuPG) //'`
380
381   if test "$major" -gt "$req_major"; then
382     ok=yes
383   else
384     if test "$major" -eq "$req_major"; then
385       if test "$minor" -gt "$req_minor"; then
386         ok=yes
387       else
388         if test "$minor" -eq "$req_minor"; then
389           if test "$micro" -ge "$req_micro"; then
390             ok=yes
391           fi
392         fi
393       fi
394     fi
395   fi
396   if test "$ok" = "yes"; then
397     AC_MSG_RESULT(yes)
398   else
399     AC_MSG_RESULT(no)
400     AC_MSG_WARN([GPGSM must be at least version $NEED_GPGSM_VERSION])
401   fi
402 fi
403 AM_CONDITIONAL(RUN_GPGSM_TESTS, test "$ok" = "yes")
404
405 # FIXME: Only build if supported.
406 AM_CONDITIONAL(BUILD_ASSUAN, test "$GPGSM" != "no")
407
408
409 # The assuan code uses funopen but it will also build without it.  So
410 # test for it.  Frankly, this is not required in gpgme, but thats the
411 # way we handle it in libassuan.
412 AC_CHECK_FUNCS(funopen)
413 if test $ac_cv_func_funopen != yes; then
414     # No funopen but we can implement that in terms of fopencookie.
415     AC_CHECK_FUNCS(fopencookie)
416     if test $ac_cv_func_fopencookie = yes; then
417         AC_LIBOBJ([funopen])
418     else
419         AC_MSG_WARN([
420 ***
421 *** No implementation of fopencookie or funopen available
422 ***])
423     fi
424 fi
425
426 # More assuan replacement functions.
427 AC_REPLACE_FUNCS(isascii)
428 AC_REPLACE_FUNCS(putc_unlocked)
429 AC_REPLACE_FUNCS(memrchr)
430
431 # More assuan checks.
432 AC_CHECK_HEADERS([sys/uio.h])
433
434 # End of assuan checks.
435
436 AM_CONDITIONAL(BUILD_COMPLUS, test "$component_system" = "COM+")
437
438 # Make the version number in gpgme/gpgme.h the same as the one here.
439 # (this is easier than to have a *.in file just for one substitution)
440 GNUPG_FIX_HDR_VERSION(gpgme/gpgme.h, GPGME_VERSION)
441
442 # Substitution used for gpgme-config 
443 GPGME_CONFIG_LIBS="-lgpgme"
444 GPGME_CONFIG_CFLAGS=""
445 AC_SUBST(GPGME_CONFIG_API_VERSION)
446 AC_SUBST(GPGME_CONFIG_LIBS)
447 AC_SUBST(GPGME_CONFIG_CFLAGS)
448
449 # Frob'da Variables
450 LTLIBOBJS=`echo "$LIB@&t@OBJS" |
451            sed 's,\.[[^.]]* ,.lo ,g;s,\.[[^.]]*$,.lo,'`
452 AC_SUBST(LTLIBOBJS)
453
454 #
455 # Create config files 
456
457 AC_CONFIG_FILES(Makefile assuan/Makefile gpgme/Makefile
458                 tests/Makefile tests/gpg/Makefile tests/gpgsm/Makefile
459                 doc/Makefile complus/Makefile)
460 AC_CONFIG_FILES(gpgme/gpgme-config, chmod +x gpgme/gpgme-config)
461 AC_OUTPUT
462
463 echo "
464         GPGME v${VERSION} has been configured as follows:
465
466         GnuPG path:    $GPG
467         GnuPG version: $GPG_VERSION, min. $NEED_GPG_VERSION
468
469         GpgSM path:    $GPGSM
470         GpgSM version: $GPGSM_VERSION, min. $NEED_GPGSM_VERSION
471
472         GPGME Pthread: $have_pthread
473         GPGME Pth:     $have_pth
474 "