2002-06-02 Marcus Brinkmann <marcus@g10code.de>
[gpgme.git] / acinclude.m4
1 dnl Macros to configure gpgme
2
3 dnl GNUPG_FIX_HDR_VERSION(FILE, NAME)
4 dnl Make the version number in gcrypt/gcrypt.h the same as the one here.
5 dnl (this is easier than to have a .in file just for one substitution)
6 dnl We must use a temp file in the current directory because make distcheck 
7 dnl install all sourcefiles RO.
8 dnl (wk 2001-12-18)
9 AC_DEFUN(GNUPG_FIX_HDR_VERSION,
10   [ sed "s/^#define $2 \".*/#define $2 \"$VERSION\"/" $srcdir/$1 > fixhdr.tmp
11     if cmp -s $srcdir/$1 fixhdr.tmp 2>/dev/null; then
12         rm -f fixhdr.tmp
13     else
14         rm -f $srcdir/$1
15         if mv fixhdr.tmp $srcdir/$1 ; then
16             :
17         else
18             AC_MSG_ERROR([[
19 ***
20 *** Failed to fix the version string macro $2 in $1.
21 *** The old file has been saved as fixhdr.tmp
22 ***]])
23         fi
24         AC_MSG_WARN([fixed the $2 macro in $1])
25     fi
26   ])
27
28
29 dnl GNUPG_CHECK_TYPEDEF(TYPE, HAVE_NAME)
30 dnl Check whether a typedef exists and create a #define $2 if it exists
31 dnl
32 AC_DEFUN(GNUPG_CHECK_TYPEDEF,
33   [ AC_MSG_CHECKING(for $1 typedef)
34     AC_CACHE_VAL(gnupg_cv_typedef_$1,
35     [AC_TRY_COMPILE([#include <stdlib.h>
36     #include <sys/types.h>], [
37     #undef $1
38     int a = sizeof($1);
39     ], gnupg_cv_typedef_$1=yes, gnupg_cv_typedef_$1=no )])
40     AC_MSG_RESULT($gnupg_cv_typedef_$1)
41     if test "$gnupg_cv_typedef_$1" = yes; then
42         AC_DEFINE($2, ,
43          [Define to 1 if $1 is defined in the <sys/types.h> header file.])
44     fi
45   ])
46
47 dnl ##
48 dnl ##  GNU Pth - The GNU Portable Threads
49 dnl ##  Copyright (c) 1999-2002 Ralf S. Engelschall <rse@engelschall.com>
50 dnl ##
51 dnl ##  This file is part of GNU Pth, a non-preemptive thread scheduling
52 dnl ##  library which can be found at http://www.gnu.org/software/pth/.
53 dnl ##
54 dnl ##  This library is free software; you can redistribute it and/or
55 dnl ##  modify it under the terms of the GNU Lesser General Public
56 dnl ##  License as published by the Free Software Foundation; either
57 dnl ##  version 2.1 of the License, or (at your option) any later version.
58 dnl ##
59 dnl ##  This library is distributed in the hope that it will be useful,
60 dnl ##  but WITHOUT ANY WARRANTY; without even the implied warranty of
61 dnl ##  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
62 dnl ##  Lesser General Public License for more details.
63 dnl ##
64 dnl ##  You should have received a copy of the GNU Lesser General Public
65 dnl ##  License along with this library; if not, write to the Free Software
66 dnl ##  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
67 dnl ##  USA, or contact Ralf S. Engelschall <rse@engelschall.com>.
68 dnl ##
69 dnl ##  pth.m4: Autoconf macro for locating GNU Pth from within
70 dnl ##          configure.in of third-party software packages
71 dnl ##
72
73 dnl ##
74 dnl ##  Synopsis:
75 dnl ##  AC_CHECK_PTH([MIN-VERSION [,          # minimum Pth version, e.g. 1.2.0
76 dnl ##                DEFAULT-WITH-PTH [,     # default value for --with-pth option
77 dnl ##                DEFAULT-WITH-PTH-TEST [,# default value for --with-pth-test option
78 dnl ##                EXTEND-VARS [,          # whether CFLAGS/LDFLAGS/etc are extended
79 dnl ##                ACTION-IF-FOUND [,      # action to perform if Pth was found
80 dnl ##                ACTION-IF-NOT-FOUND     # action to perform if Pth was not found
81 dnl ##                ]]]]]])
82 dnl ##  Examples:
83 dnl ##  AC_CHECK_PTH(1.2.0)
84 dnl ##  AC_CHECK_PTH(1.2.0,,,no,CFLAGS="$CFLAGS -DHAVE_PTH $PTH_CFLAGS")
85 dnl ##  AC_CHECK_PTH(1.2.0,yes,yes,yes,CFLAGS="$CFLAGS -DHAVE_PTH")
86 dnl ##
87 dnl
88 dnl #   auxilliary macros
89 AC_DEFUN(_AC_PTH_ERROR, [dnl
90 AC_MSG_RESULT([*FAILED*])
91 dnl define(_ac_pth_line,dnl
92 dnl "+------------------------------------------------------------------------+")
93 dnl echo " _ac_pth_line" 1>&2
94 cat <<EOT | sed -e 's/^[[       ]]*/ | /' -e 's/>>/  /' 1>&2
95 $1
96 EOT
97 dnl echo " _ac_pth_line" 1>&2
98 dnl undefine(_ac_pth_line)
99 exit 1
100 ])
101 AC_DEFUN(_AC_PTH_VERBOSE, [dnl
102 if test ".$verbose" = .yes; then
103     AC_MSG_RESULT([  $1])
104 fi
105 ])
106 dnl #   the user macro
107 AC_DEFUN(AC_CHECK_PTH, [dnl
108 dnl
109 dnl #   prerequisites
110 AC_REQUIRE([AC_PROG_CC])dnl
111 AC_REQUIRE([AC_PROG_CPP])dnl
112 dnl
113 PTH_CPPFLAGS=''
114 PTH_CFLAGS=''
115 PTH_LDFLAGS=''
116 PTH_LIBS=''
117 AC_SUBST(PTH_CPPFLAGS)
118 AC_SUBST(PTH_CFLAGS)
119 AC_SUBST(PTH_LDFLAGS)
120 AC_SUBST(PTH_LIBS)
121 dnl #   command line options
122 AC_MSG_CHECKING(for GNU Pth)
123 _AC_PTH_VERBOSE([])
124 AC_ARG_WITH(pth,dnl
125 [  --with-pth[=ARG]        Build with GNU Pth Library  (default=]ifelse([$2],,yes,$2)[)],dnl
126 ,dnl
127 with_pth="ifelse([$2],,yes,$2)"
128 )dnl
129 AC_ARG_WITH(pth-test,dnl
130 [  --with-pth-test         Perform GNU Pth Sanity Test (default=]ifelse([$3],,yes,$3)[)],dnl
131 ,dnl
132 with_pth_test="ifelse([$3],,yes,$3)"
133 )dnl
134 _AC_PTH_VERBOSE([+ Command Line Options:])
135 _AC_PTH_VERBOSE([    o --with-pth=$with_pth])
136 _AC_PTH_VERBOSE([    o --with-pth-test=$with_pth_test])
137 dnl
138 dnl #   configuration
139 if test ".$with_pth" != .no; then
140     _pth_subdir=no
141     _pth_subdir_opts=''
142     case "$with_pth" in
143         subdir:* )
144             _pth_subdir=yes
145             changequote(, )dnl
146             _pth_subdir_opts=`echo $with_pth | sed -e 's/^subdir:[^     ]*[     ]*//'`
147             with_pth=`echo $with_pth | sed -e 's/^subdir:\([^   ]*\).*$/\1/'`
148             changequote([, ])dnl
149             ;;
150     esac
151     _pth_version=""
152     _pth_location=""
153     _pth_type=""
154     _pth_cppflags=""
155     _pth_cflags=""
156     _pth_ldflags=""
157     _pth_libs=""
158     if test ".$with_pth" = .yes; then
159         #   via config script in $PATH
160         changequote(, )dnl
161         _pth_version=`(pth-config --version) 2>/dev/null |\
162                       sed -e 's/^.*\([0-9]\.[0-9]*[ab.][0-9]*\).*$/\1/'`
163         changequote([, ])dnl
164         if test ".$_pth_version" != .; then
165             _pth_location=`pth-config --prefix`
166             _pth_type='installed'
167             _pth_cppflags=`pth-config --cflags`
168             _pth_cflags=`pth-config --cflags`
169             _pth_ldflags=`pth-config --ldflags`
170             _pth_libs=`pth-config --libs`
171         fi
172     elif test -d "$with_pth"; then
173         with_pth=`echo $with_pth | sed -e 's;/*$;;'`
174         _pth_found=no
175         #   via locally included source tree
176         if test ".$_pth_subdir" = .yes; then
177             _pth_location="$with_pth"
178             _pth_type='local'
179             _pth_cppflags="-I$with_pth"
180             _pth_cflags="-I$with_pth"
181             if test -f "$with_pth/ltconfig"; then
182                 _pth_ldflags="-L$with_pth/.libs"
183             else
184                 _pth_ldflags="-L$with_pth"
185             fi
186             _pth_libs="-lpth"
187             changequote(, )dnl
188             _pth_version=`grep '^const char PTH_Hello' $with_pth/pth_vers.c |\
189                           sed -e 's;^.*Version[         ]*\([0-9]*\.[0-9]*[.ab][0-9]*\)[        ].*$;\1;'`
190             changequote([, ])dnl
191             _pth_found=yes
192             ac_configure_args="$ac_configure_args --enable-subdir $_pth_subdir_opts"
193             with_pth_test=no
194         fi
195         #   via config script under a specified directory
196         #   (a standard installation, but not a source tree)
197         if test ".$_pth_found" = .no; then
198             for _dir in $with_pth/bin $with_pth; do
199                 if test -f "$_dir/pth-config"; then
200                     test -f "$_dir/pth-config.in" && continue # pth-config in source tree!
201                     changequote(, )dnl
202                     _pth_version=`($_dir/pth-config --version) 2>/dev/null |\
203                                   sed -e 's/^.*\([0-9]\.[0-9]*[ab.][0-9]*\).*$/\1/'`
204                     changequote([, ])dnl
205                     if test ".$_pth_version" != .; then
206                         _pth_location=`$_dir/pth-config --prefix`
207                         _pth_type="installed"
208                         _pth_cppflags=`$_dir/pth-config --cflags`
209                         _pth_cflags=`$_dir/pth-config --cflags`
210                         _pth_ldflags=`$_dir/pth-config --ldflags`
211                         _pth_libs=`$_dir/pth-config --libs`
212                         _pth_found=yes
213                         break
214                     fi
215                 fi
216             done
217         fi
218         #   in any subarea under a specified directory
219         #   (either a special installation or a Pth source tree)
220         if test ".$_pth_found" = .no; then
221             changequote(, )dnl
222             _pth_found=0
223             for _file in x `find $with_pth -name "pth.h" -type f -print`; do
224                 test .$_file = .x && continue
225                 _dir=`echo $_file | sed -e 's;[^/]*$;;' -e 's;\(.\)/$;\1;'`
226                 _pth_version=`($_dir/pth-config --version) 2>/dev/null |\
227                               sed -e 's/^.*\([0-9]\.[0-9]*[ab.][0-9]*\).*$/\1/'`
228                 if test ".$_pth_version" = .; then
229                     _pth_version=`grep '^#define PTH_VERSION_STR' $_file |\
230                                   sed -e 's;^#define[   ]*PTH_VERSION_STR[      ]*"\([0-9]*\.[0-9]*[.ab][0-9]*\)[       ].*$;\1;'`
231                 fi
232                 _pth_cppflags="-I$_dir"
233                 _pth_cflags="-I$_dir"
234                 _pth_found=`expr $_pth_found + 1`
235             done
236             for _file in x `find $with_pth -name "libpth.[aso]" -type f -print`; do
237                 test .$_file = .x && continue
238                 _dir=`echo $_file | sed -e 's;[^/]*$;;' -e 's;\(.\)/$;\1;'`
239                 _pth_ldflags="-L$_dir"
240                 _pth_libs="-lpth"
241                 _pth_found=`expr $_pth_found + 1`
242             done
243             changequote([, ])dnl
244             if test ".$_pth_found" = .2; then
245                 _pth_location="$with_pth"
246                 _pth_type="uninstalled"
247             else
248                 _pth_version=''
249             fi
250         fi
251     fi
252     _AC_PTH_VERBOSE([+ Determined Location:])
253     _AC_PTH_VERBOSE([    o path: $_pth_location])
254     _AC_PTH_VERBOSE([    o type: $_pth_type])
255     if test ".$_pth_version" = .; then
256         if test ".$with_pth" != .yes; then
257              _AC_PTH_ERROR([dnl
258              Unable to locate GNU Pth under $with_pth.
259              Please specify the correct path to either a GNU Pth installation tree
260              (use --with-pth=DIR if you used --prefix=DIR for installing GNU Pth in
261              the past) or to a GNU Pth source tree (use --with-pth=DIR if DIR is a
262              path to a pth-X.Y.Z/ directory; but make sure the package is already
263              built, i.e., the "configure; make" step was already performed there).])
264         else
265              _AC_PTH_ERROR([dnl
266              Unable to locate GNU Pth in any system-wide location (see \$PATH).
267              Please specify the correct path to either a GNU Pth installation tree
268              (use --with-pth=DIR if you used --prefix=DIR for installing GNU Pth in
269              the past) or to a GNU Pth source tree (use --with-pth=DIR if DIR is a
270              path to a pth-X.Y.Z/ directory; but make sure the package is already
271              built, i.e., the "configure; make" step was already performed there).])
272         fi
273     fi
274     dnl #
275     dnl #  Check whether the found version is sufficiently new
276     dnl #
277     _req_version="ifelse([$1],,1.0.0,$1)"
278     for _var in _pth_version _req_version; do
279         eval "_val=\"\$${_var}\""
280         _major=`echo $_val | sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\([[ab.]]\)\([[0-9]]*\)/\1/'`
281         _minor=`echo $_val | sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\([[ab.]]\)\([[0-9]]*\)/\2/'`
282         _rtype=`echo $_val | sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\([[ab.]]\)\([[0-9]]*\)/\3/'`
283         _micro=`echo $_val | sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\([[ab.]]\)\([[0-9]]*\)/\4/'`
284         case $_rtype in
285             "a" ) _rtype=0 ;;
286             "b" ) _rtype=1 ;;
287             "." ) _rtype=2 ;;
288         esac
289         _hex=`echo dummy | awk '{ printf("%d%02d%1d%02d", major, minor, rtype, micro); }' \
290               "major=$_major" "minor=$_minor" "rtype=$_rtype" "micro=$_micro"`
291         eval "${_var}_hex=\"\$_hex\""
292     done
293     _AC_PTH_VERBOSE([+ Determined Versions:])
294     _AC_PTH_VERBOSE([    o existing: $_pth_version -> 0x$_pth_version_hex])
295     _AC_PTH_VERBOSE([    o required: $_req_version -> 0x$_req_version_hex])
296     _ok=0
297     if test ".$_pth_version_hex" != .; then
298         if test ".$_req_version_hex" != .; then
299             if test $_pth_version_hex -ge $_req_version_hex; then
300                 _ok=1
301             fi
302         fi
303     fi
304     if test ".$_ok" = .0; then
305         _AC_PTH_ERROR([dnl
306         Found Pth version $_pth_version, but required at least version $_req_version.
307         Upgrade Pth under $_pth_location to $_req_version or higher first, please.])
308     fi
309     dnl #
310     dnl #   Perform Pth Sanity Compile Check
311     dnl #
312     if test ".$with_pth_test" = .yes; then
313         _ac_save_CPPFLAGS="$CPPFLAGS"
314         _ac_save_CFLAGS="$CFLAGS"
315         _ac_save_LDFLAGS="$LDFLAGS"
316         _ac_save_LIBS="$LIBS"
317         CPPFLAGS="$CPPFLAGS $_pth_cppflags"
318         CFLAGS="$CFLAGS $_pth_cflags"
319         LDFLAGS="$LDFLAGS $_pth_ldflags"
320         LIBS="$LIBS $_pth_libs"
321         _AC_PTH_VERBOSE([+ Test Build Environment:])
322         _AC_PTH_VERBOSE([    o CPPFLAGS=\"$CPPFLAGS\"])
323         _AC_PTH_VERBOSE([    o CFLAGS=\"$CFLAGS\"])
324         _AC_PTH_VERBOSE([    o LDFLAGS=\"$LDFLAGS\"])
325         _AC_PTH_VERBOSE([    o LIBS=\"$LIBS\"])
326         cross_compile=no
327         define(_code1, [dnl
328         #include <stdio.h>
329         #include <pth.h>
330         ])
331         define(_code2, [dnl
332         int main(int argc, char *argv[])
333         {
334             FILE *fp;
335             if (!(fp = fopen("conftestval", "w")))
336                 exit(1);
337             fprintf(fp, "hmm");
338             fclose(fp);
339             pth_init();
340             pth_kill();
341             if (!(fp = fopen("conftestval", "w")))
342                 exit(1);
343             fprintf(fp, "yes");
344             fclose(fp);
345             exit(0);
346         }
347         ])
348         _AC_PTH_VERBOSE([+ Performing Sanity Checks:])
349         _AC_PTH_VERBOSE([    o pre-processor test])
350         AC_TRY_CPP(_code1, _ok=yes, _ok=no)
351         if test ".$_ok" != .yes; then
352             _AC_PTH_ERROR([dnl
353             Found GNU Pth $_pth_version under $_pth_location, but
354             was unable to perform a sanity pre-processor check. This means
355             the GNU Pth header pth.h was not found.
356             We used the following build environment:
357             >> CPP="$CPP"
358             >> CPPFLAGS="$CPPFLAGS"
359             See config.log for possibly more details.])
360         fi
361         _AC_PTH_VERBOSE([    o link check])
362         AC_TRY_LINK(_code1, _code2, _ok=yes, _ok=no)
363         if test ".$_ok" != .yes; then
364             _AC_PTH_ERROR([dnl
365             Found GNU Pth $_pth_version under $_pth_location, but
366             was unable to perform a sanity linker check. This means
367             the GNU Pth library libpth.a was not found.
368             We used the following build environment:
369             >> CC="$CC"
370             >> CFLAGS="$CFLAGS"
371             >> LDFLAGS="$LDFLAGS"
372             >> LIBS="$LIBS"
373             See config.log for possibly more details.])
374         fi
375         _AC_PTH_VERBOSE([    o run-time check])
376         AC_TRY_RUN(_code1 _code2, _ok=`cat conftestval`, _ok=no, _ok=no)
377         if test ".$_ok" != .yes; then
378             if test ".$_ok" = .no; then
379                 _AC_PTH_ERROR([dnl
380                 Found GNU Pth $_pth_version under $_pth_location, but
381                 was unable to perform a sanity execution check. This usually
382                 means that the GNU Pth shared library libpth.so is present
383                 but \$LD_LIBRARY_PATH is incomplete to execute a Pth test.
384                 In this case either disable this test via --without-pth-test,
385                 or extend \$LD_LIBRARY_PATH, or build GNU Pth as a static
386                 library only via its --disable-shared Autoconf option.
387                 We used the following build environment:
388                 >> CC="$CC"
389                 >> CFLAGS="$CFLAGS"
390                 >> LDFLAGS="$LDFLAGS"
391                 >> LIBS="$LIBS"
392                 See config.log for possibly more details.])
393             else
394                 _AC_PTH_ERROR([dnl
395                 Found GNU Pth $_pth_version under $_pth_location, but
396                 was unable to perform a sanity run-time check. This usually
397                 means that the GNU Pth library failed to work and possibly
398                 caused a core dump in the test program. In this case it
399                 is strongly recommended that you re-install GNU Pth and this
400                 time make sure that it really passes its "make test" procedure.
401                 We used the following build environment:
402                 >> CC="$CC"
403                 >> CFLAGS="$CFLAGS"
404                 >> LDFLAGS="$LDFLAGS"
405                 >> LIBS="$LIBS"
406                 See config.log for possibly more details.])
407             fi
408         fi
409         _extendvars="ifelse([$4],,yes,$4)"
410         if test ".$_extendvars" != .yes; then
411             CPPFLAGS="$_ac_save_CPPFLAGS"
412             CFLAGS="$_ac_save_CFLAGS"
413             LDFLAGS="$_ac_save_LDFLAGS"
414             LIBS="$_ac_save_LIBS"
415         fi
416     else
417         _extendvars="ifelse([$4],,yes,$4)"
418         if test ".$_extendvars" = .yes; then
419             if test ".$_pth_subdir" = .yes; then
420                 CPPFLAGS="$CPPFLAGS $_pth_cppflags"
421                 CFLAGS="$CFLAGS $_pth_cflags"
422                 LDFLAGS="$LDFLAGS $_pth_ldflags"
423                 LIBS="$LIBS $_pth_libs"
424             fi
425         fi
426     fi
427     PTH_CPPFLAGS="$_pth_cppflags"
428     PTH_CFLAGS="$_pth_cflags"
429     PTH_LDFLAGS="$_pth_ldflags"
430     PTH_LIBS="$_pth_libs"
431     AC_SUBST(PTH_CPPFLAGS)
432     AC_SUBST(PTH_CFLAGS)
433     AC_SUBST(PTH_LDFLAGS)
434     AC_SUBST(PTH_LIBS)
435     _AC_PTH_VERBOSE([+ Final Results:])
436     _AC_PTH_VERBOSE([    o PTH_CPPFLAGS=\"$PTH_CPPFLAGS\"])
437     _AC_PTH_VERBOSE([    o PTH_CFLAGS=\"$PTH_CFLAGS\"])
438     _AC_PTH_VERBOSE([    o PTH_LDFLAGS=\"$PTH_LDFLAGS\"])
439     _AC_PTH_VERBOSE([    o PTH_LIBS=\"$PTH_LIBS\"])
440 fi
441 if test ".$with_pth" != .no; then
442     AC_MSG_RESULT([version $_pth_version, $_pth_type under $_pth_location])
443     ifelse([$5], , :, [$5])
444 else
445     AC_MSG_RESULT([no])
446     ifelse([$6], , :, [$6])
447 fi
448 ])
449