Changes 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 AC_CHECK_TOOL(DLLTOOL, dlltool, :)
73 AC_CHECK_TOOL(WINDRES, windres, :)
74
75
76 AC_SUBST(LIBGPGME_LT_CURRENT)
77 AC_SUBST(LIBGPGME_LT_AGE)
78 AC_SUBST(LIBGPGME_LT_REVISION)
79 AC_DEFINE_UNQUOTED(NEED_GPG_VERSION, "$NEED_GPG_VERSION",
80                                      [Min. needed GnuPG version.])
81 AC_DEFINE_UNQUOTED(NEED_GPGSM_VERSION, "$NEED_GPGSM_VERSION",
82                                        [Min. needed GPGSM version.])
83
84 AC_SUBST(PACKAGE)
85 AC_SUBST(VERSION)
86 AC_DEFINE_UNQUOTED(PACKAGE, "$PACKAGE", [Name of this package])
87 AC_DEFINE_UNQUOTED(VERSION, "$VERSION", [Version of this package])
88
89 # Don't default to build static libs.
90 AC_DISABLE_STATIC
91 AC_PROG_LIBTOOL
92
93 # For now we hardcode the use of version scripts.  It would be better
94 # to write a test for this or even implement this within libtool.
95 have_ld_version_script=no
96 case "${host}" in
97     *-*-linux*)
98         have_ld_version_script=yes
99         ;;
100     *-*-gnu*)
101         have_ld_version_script=yes
102         ;;
103 esac
104 AM_CONDITIONAL(HAVE_LD_VERSION_SCRIPT, test "$have_ld_version_script" = "yes")
105
106 GPG_DEFAULT=no
107 GPGSM_DEFAULT=no
108 component_system=None
109 have_dosish_system=no
110 have_w32_system=no
111 case "${host}" in
112     *-mingw32*)
113         # special stuff for Windoze NT
114         have_dosish_system=yes
115         have_w32_system=yes
116         GPG_DEFAULT='c:\\gnupg\\gpg.exe'
117         # XXX Assuan is not supported in this configuration.
118         #GPGSM_DEFAULT='c:\\gnupg\\gpgsm.exe'
119         #component_system='COM+'
120         ;;
121     *)
122         AC_CHECK_PTH(1.2.0,,,no,have_pth=yes)
123         if test "$have_pth" = yes; then
124           AC_DEFINE(HAVE_PTH, ,[Define if we have Pth.])
125           CFLAGS="$CFLAGS $PTH_CFLAGS"
126         fi
127         AC_CHECK_LIB(pthread,pthread_create,have_pthread=yes)
128         if test "$have_pthread" = yes; then
129           AC_DEFINE(HAVE_PTHREAD, ,[Define if we have pthread.])
130         fi
131
132         # XXX: Probably use exec-prefix here?
133 #       GPG_DEFAULT='/usr/bin/gpg'
134 #       GPGSM_DEFAULT='/usr/bin/gpgsm'
135         ;;
136 esac
137
138 if test "$have_dosish_system" = yes; then
139    AC_DEFINE(HAVE_DOSISH_SYSTEM,1,
140              [Defined if we run on some of the PCDOS like systems 
141               (DOS, Windoze. OS/2) with special properties like
142               no file modes])
143 fi
144 AM_CONDITIONAL(HAVE_DOSISH_SYSTEM, test "$have_dosish_system" = yes)
145
146 if test "$have_w32_system" = yes; then
147    AC_DEFINE(HAVE_W32_SYSTEM,1, [Defined if we run on a W32 API based system])
148 fi
149 AM_CONDITIONAL(HAVE_W32_SYSTEM, test "$have_w32_system" = yes)
150
151
152 AM_CONDITIONAL(HAVE_PTH, test "$have_pth" = "yes")
153 AM_CONDITIONAL(HAVE_PTHREAD, test "$have_pthread" = "yes")
154
155
156 # Checks for header files.
157 AC_CHECK_HEADERS(sys/select.h)
158
159
160 # Type checks.
161 AC_CHECK_SIZEOF(unsigned int)
162 AC_SYS_LARGEFILE
163 AC_TYPE_OFF_T
164
165 # Checks for compiler features.
166 if test "$GCC" = yes; then
167     CFLAGS="$CFLAGS -Wall -Wcast-align -Wshadow -Wstrict-prototypes"
168 fi
169
170
171 # Checks for library functions.
172 AC_FUNC_FSEEKO
173
174 AC_CHECK_FUNCS(stpcpy)
175
176 AC_REPLACE_FUNCS(vasprintf)
177 if test "$ac_cv_func_vasprintf" != yes; then
178   GNUPG_CHECK_VA_COPY
179 fi
180
181 # Try to find a thread-safe version of ttyname().
182 AC_REPLACE_FUNCS(ttyname_r)
183 if test "$ac_cv_func_ttyname_r" != yes; then
184   AC_MSG_WARN([
185 ***
186 *** ttyname() is not thread-safe and ttyname_r() does not exist
187 ***])
188 fi
189
190 # Try to find a thread-safe version of getenv().
191 have_thread_safe_getenv=no
192 jm_GLIBC21
193 if test $GLIBC21 = yes; then
194   have_thread_safe_getenv=yes
195 fi
196 if test $have_thread_safe_getenv = yes; then
197   AC_DEFINE(HAVE_THREAD_SAFE_GETENV, [1], [Define if getenv() is thread-safe])
198 fi
199 have_getenv_r=no
200 AC_CHECK_FUNCS(getenv_r, have_getenv_r=yes)
201 if test $have_getenv_r = no && test $have_thread_safe_getenv = no; then
202   AC_MSG_WARN([
203 ***
204 *** getenv() is not thread-safe and getenv_r() does not exist
205 ***])
206 fi
207
208 # For converting time strings to seconds since Epoch, we need the timegm
209 # function.
210 AC_CHECK_FUNCS(timegm)
211 if test "$ac_cv_func_timegm" != yes; then
212   AC_MSG_WARN([
213 ***
214 *** timegm() not available - a non-thread-safe kludge will be used
215 *** and the TZ variable might be changed at runtime.
216 ***])
217 fi
218
219 # Checking for libgpg-error.
220 AM_PATH_GPG_ERROR(0.5,, AC_MSG_ERROR([libgpg-error was not found]))
221 AC_DEFINE(GPG_ERR_SOURCE_DEFAULT, GPG_ERR_SOURCE_GPGME,
222           [The default error source for GPGME.])
223
224
225
226 # Checks for system services
227 NO_OVERRIDE=no
228 AC_ARG_WITH(gpg,
229             AC_HELP_STRING([--with-gpg=PATH], [use GnuPG binary at PATH]),
230             GPG=$withval, NO_OVERRIDE=yes)
231 if test "$NO_OVERRIDE" = "yes" || test "$GPG" = "yes"; then
232   GPG=
233   NO_OVERRIDE=yes
234   if test "$cross_compiling" != "yes"; then
235     AC_PATH_PROG(GPG, gpg)
236   fi
237   if test -z "$GPG"; then
238     GPG="$GPG_DEFAULT"
239   fi
240 fi
241 if test "$GPG" = no; then
242   if test "$NO_OVERRIDE" = "yes"; then
243     if test "$cross_compiling" != "yes"; then
244       AC_MSG_WARN([
245 ***
246 *** Could not find GnuPG, install GnuPG or use --with-gpg=PATH to enable it
247 ***])
248     else
249       AC_MSG_ERROR([
250 ***
251 *** Can not determine path to GnuPG when cross-compiling, use --with-gpg=PATH
252 ***])
253     fi
254   fi
255 else
256   AC_DEFINE_UNQUOTED(GPG_PATH, "$GPG", [Path to the GnuPG binary.])
257   AC_SUBST(GPG)
258 fi
259 dnl Check for GnuPG version requirement.
260 GPG_VERSION=unknown
261 ok=maybe
262 if test -z "$GPG" -o "x$GPG" = "xno"; then
263   ok=no
264 else
265   if test "$cross_compiling" = "yes"; then
266     AC_MSG_WARN([GnuPG version can not be checked when cross compiling])
267     ok=no
268   else
269     if test ! -x "$GPG"; then
270       AC_MSG_WARN([GnuPG not executable, version check disabled])
271       ok=no
272     fi
273   fi
274 fi
275 if test "$ok" = "maybe"; then
276   AC_MSG_CHECKING(for GnuPG >= $NEED_GPG_VERSION)
277   req_major=`echo $NEED_GPG_VERSION | \
278              sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\1/'`
279   req_minor=`echo $NEED_GPG_VERSION | \
280              sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\2/'`
281   req_micro=`echo $NEED_GPG_VERSION | \
282              sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\3/'`
283   gpg_version=`$GPG --version | grep ^gpg`
284   major=`echo $gpg_version | \
285          sed 's/^gpg (GnuPG) \([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*/\1/'`
286   minor=`echo $gpg_version | \
287          sed 's/^gpg (GnuPG) \([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*/\2/'`
288   micro=`echo $gpg_version | \
289          sed 's/^gpg (GnuPG) \([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*/\3/'`
290   GPG_VERSION=`echo $gpg_version | sed 's/^gpg (GnuPG) //'`
291
292   if test "$major" -gt "$req_major"; then
293     ok=yes
294   else
295     if test "$major" -eq "$req_major"; then
296       if test "$minor" -gt "$req_minor"; then
297         ok=yes
298       else
299         if test "$minor" -eq "$req_minor"; then
300           if test "$micro" -ge "$req_micro"; then
301             ok=yes
302           fi
303         fi
304       fi
305     fi
306   fi
307   if test "$ok" = "yes"; then
308     AC_MSG_RESULT(yes)
309   else
310     AC_MSG_RESULT(no)
311     AC_MSG_WARN([GnuPG must be at least version $NEED_GPG_VERSION])
312   fi
313 fi
314 AM_CONDITIONAL(RUN_GPG_TESTS, test "$ok" = "yes")
315 AC_SUBST(GPG_PATH)
316
317 NO_OVERRIDE=no
318 AC_ARG_WITH(gpgsm,
319             AC_HELP_STRING([--with-gpgsm=PATH], [use GpgSM binary at PATH]),
320             GPGSM=$withval, NO_OVERRIDE=yes)
321 if test "$NO_OVERRIDE" = "yes" || test "$GPGSM" = "yes"; then
322   GPGSM=
323   NO_OVERRIDE=yes
324   if test "$cross_compiling" != "yes"; then
325     AC_PATH_PROG(GPGSM, gpgsm)
326   fi
327   if test -z "$GPGSM"; then
328     GPGSM="$GPGSM_DEFAULT"
329   fi
330 fi
331 if test "$GPGSM" = no; then
332   if test "$NO_OVERRIDE" = "yes"; then
333     if test "$cross_compiling" != "yes"; then
334       AC_MSG_WARN([
335 ***
336 *** Could not find GpgSM, install GpgSM or use --with-gpgsm=PATH to enable it
337 ***])
338     else
339       AC_MSG_ERROR([
340 ***
341 *** Can not determine path to GpgSM when cross-compiling, use --with-gpgsm=PATH
342 ***])
343     fi
344   fi
345 else
346   AC_DEFINE_UNQUOTED(GPGSM_PATH, "$GPGSM", [Path to the GPGSM binary.])
347   AC_DEFINE(ENABLE_GPGSM,1,[Whether GPGSM support is enabled])
348 fi
349 AM_CONDITIONAL(HAVE_GPGSM, test "$GPGSM" != "no")
350
351
352 dnl Check for GPGSM version requirement.
353 GPGSM_VERSION=unknown
354 ok=maybe
355 if test -z "$GPGSM" -o "x$GPGSM" = "xno"; then
356   ok=no
357 else
358   if test "$cross_compiling" = "yes"; then
359     AC_MSG_WARN([GPGSM version can not be checked when cross compiling])
360     ok=no
361   else
362     if test ! -x "$GPGSM"; then
363       AC_MSG_WARN([GPGSM not executable, version check disabled])
364       ok=no
365     fi
366   fi
367 fi
368 if test "$ok" = "maybe"; then
369   AC_MSG_CHECKING(for GPGSM >= $NEED_GPGSM_VERSION)
370   req_major=`echo $NEED_GPGSM_VERSION | \
371              sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\1/'`
372   req_minor=`echo $NEED_GPGSM_VERSION | \
373              sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\2/'`
374   req_micro=`echo $NEED_GPGSM_VERSION | \
375              sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\3/'`
376   gpgsm_version=`$GPGSM --version | grep ^gpgsm`
377   major=`echo $gpgsm_version | \
378          sed 's/^gpgsm (GnuPG) \([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*/\1/'`
379   minor=`echo $gpgsm_version | \
380          sed 's/^gpgsm (GnuPG) \([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*/\2/'`
381   micro=`echo $gpgsm_version | \
382          sed 's/^gpgsm (GnuPG) \([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*/\3/'`
383   GPGSM_VERSION=`echo $gpgsm_version | sed 's/^gpgsm (GnuPG) //'`
384
385   if test "$major" -gt "$req_major"; then
386     ok=yes
387   else
388     if test "$major" -eq "$req_major"; then
389       if test "$minor" -gt "$req_minor"; then
390         ok=yes
391       else
392         if test "$minor" -eq "$req_minor"; then
393           if test "$micro" -ge "$req_micro"; then
394             ok=yes
395           fi
396         fi
397       fi
398     fi
399   fi
400   if test "$ok" = "yes"; then
401     AC_MSG_RESULT(yes)
402   else
403     AC_MSG_RESULT(no)
404     AC_MSG_WARN([GPGSM must be at least version $NEED_GPGSM_VERSION])
405   fi
406 fi
407 AM_CONDITIONAL(RUN_GPGSM_TESTS, test "$ok" = "yes")
408
409 # FIXME: Only build if supported.
410 AM_CONDITIONAL(BUILD_ASSUAN, test "$GPGSM" != "no")
411
412
413 # The assuan code uses funopen but it will also build without it.  So
414 # test for it.  Frankly, this is not required in gpgme, but thats the
415 # way we handle it in libassuan.
416 AC_CHECK_FUNCS(funopen)
417 if test $ac_cv_func_funopen != yes; then
418     # No funopen but we can implement that in terms of fopencookie.
419     AC_CHECK_FUNCS(fopencookie)
420     if test $ac_cv_func_fopencookie = yes; then
421         AC_LIBOBJ([funopen])
422     else
423         AC_MSG_WARN([
424 ***
425 *** No implementation of fopencookie or funopen available
426 ***])
427     fi
428 fi
429
430 # More assuan replacement functions.
431 AC_REPLACE_FUNCS(isascii)
432 AC_REPLACE_FUNCS(putc_unlocked)
433 AC_REPLACE_FUNCS(memrchr)
434
435 # More assuan checks.
436 AC_CHECK_HEADERS([sys/uio.h])
437
438 # End of assuan checks.
439
440 AM_CONDITIONAL(BUILD_COMPLUS, test "$component_system" = "COM+")
441
442 # Make the version number in gpgme/gpgme.h the same as the one here.
443 # (this is easier than to have a *.in file just for one substitution)
444 GNUPG_FIX_HDR_VERSION(gpgme/gpgme.h, GPGME_VERSION)
445
446 # Generate values for the DLL version info
447 if test "$have_w32_system" = yes; then
448     BUILD_TIMESTAMP=`date --iso-8601=minutes`
449     changequote(,)dnl 
450     BUILD_FILEVERSION=`echo "$VERSION" | sed 's/\([0-9.]*\).*/\1./;s/\./,/g'`
451     changequote([,])dnl
452     case "$VERSION" in
453       *-cvs) BUILD_FILEVERSION="${BUILD_FILEVERSION}0" ;;
454       *-rc*) BUILD_FILEVERSION="${BUILD_FILEVERSION}1" ;;
455       *)     BUILD_FILEVERSION="${BUILD_FILEVERSION}2" ;;
456     esac
457 fi
458 AC_SUBST(BUILD_TIMESTAMP)
459 AC_SUBST(BUILD_FILEVERSION)
460
461
462 # Substitution used for gpgme-config 
463 GPGME_CONFIG_LIBS="-lgpgme"
464 GPGME_CONFIG_CFLAGS=""
465 AC_SUBST(GPGME_CONFIG_API_VERSION)
466 AC_SUBST(GPGME_CONFIG_LIBS)
467 AC_SUBST(GPGME_CONFIG_CFLAGS)
468
469 # Frob'da Variables
470 LTLIBOBJS=`echo "$LIB@&t@OBJS" |
471            sed 's,\.[[^.]]* ,.lo ,g;s,\.[[^.]]*$,.lo,'`
472 AC_SUBST(LTLIBOBJS)
473
474 #
475 # Create config files 
476
477 AC_CONFIG_FILES(Makefile assuan/Makefile gpgme/Makefile
478                 tests/Makefile tests/gpg/Makefile tests/gpgsm/Makefile
479                 doc/Makefile complus/Makefile
480                 gpgme/versioninfo.rc)
481 AC_CONFIG_FILES(gpgme/gpgme-config, chmod +x gpgme/gpgme-config)
482 AC_OUTPUT
483
484 echo "
485         GPGME v${VERSION} has been configured as follows:
486
487         GnuPG path:    $GPG
488         GnuPG version: $GPG_VERSION, min. $NEED_GPG_VERSION
489
490         GpgSM path:    $GPGSM
491         GpgSM version: $GPGSM_VERSION, min. $NEED_GPGSM_VERSION
492
493         GPGME Pthread: $have_pthread
494         GPGME Pth:     $have_pth
495 "