Imported Upstream version 2.0.28
[platform/upstream/gpg2.git] / acinclude.m4
1 dnl macros to configure gnupg
2 dnl Copyright (C) 1998, 1999, 2000, 2001, 2003 Free Software Foundation, Inc.
3 dnl
4 dnl This file is part of GnuPG.
5 dnl
6 dnl GnuPG is free software; you can redistribute it and/or modify
7 dnl it under the terms of the GNU General Public License as published by
8 dnl the Free Software Foundation; either version 3 of the License, or
9 dnl (at your option) any later version.
10 dnl 
11 dnl GnuPG is distributed in the hope that it will be useful,
12 dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
13 dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 dnl GNU General Public License for more details.
15 dnl 
16 dnl You should have received a copy of the GNU General Public License
17 dnl along with this program; if not, see <http://www.gnu.org/licenses/>.
18
19 dnl GNUPG_CHECK_TYPEDEF(TYPE, HAVE_NAME)
20 dnl Check whether a typedef exists and create a #define $2 if it exists
21 dnl
22 AC_DEFUN([GNUPG_CHECK_TYPEDEF],
23   [ AC_MSG_CHECKING(for $1 typedef)
24     AC_CACHE_VAL(gnupg_cv_typedef_$1,
25     [AC_TRY_COMPILE([#define _GNU_SOURCE 1
26     #include <stdlib.h>
27     #include <sys/types.h>], [
28     #undef $1
29     int a = sizeof($1);
30     ], gnupg_cv_typedef_$1=yes, gnupg_cv_typedef_$1=no )])
31     AC_MSG_RESULT($gnupg_cv_typedef_$1)
32     if test "$gnupg_cv_typedef_$1" = yes; then
33         AC_DEFINE($2,1,[Defined if a `]$1[' is typedef'd])
34     fi
35   ])
36
37
38 dnl GNUPG_CHECK_GNUMAKE
39 dnl
40 AC_DEFUN([GNUPG_CHECK_GNUMAKE],
41   [ 
42     if ${MAKE-make} --version 2>/dev/null | grep '^GNU ' >/dev/null 2>&1; then
43         :
44     else
45         AC_MSG_WARN([[
46 ***
47 *** It seems that you are not using GNU make.  Some make tools have serious
48 *** flaws and you may not be able to build this software at all. Before you
49 *** complain, please try GNU make:  GNU make is easy to build and available
50 *** at all GNU archives.  It is always available from ftp.gnu.org:/gnu/make.
51 ***]])
52     fi
53   ])
54
55 dnl GNUPG_CHECK_FAQPROG
56 dnl
57 AC_DEFUN([GNUPG_CHECK_FAQPROG],
58   [ AC_MSG_CHECKING(for faqprog.pl)
59     if faqprog.pl -V 2>/dev/null | grep '^faqprog.pl ' >/dev/null 2>&1; then
60         working_faqprog=yes
61         FAQPROG="faqprog.pl"
62     else 
63         working_faqprog=no
64         FAQPROG=": "
65     fi
66     AC_MSG_RESULT($working_faqprog)
67     AC_SUBST(FAQPROG)
68     AM_CONDITIONAL(WORKING_FAQPROG, test "$working_faqprog" = "yes" )
69
70 dnl     if test $working_faqprog = no; then
71 dnl         AC_MSG_WARN([[
72 dnl ***
73 dnl *** It seems that the faqprog.pl program is not installed;
74 dnl *** however it is only needed if you want to change the FAQ.
75 dnl ***  (faqprog.pl should be available at:
76 dnl ***    ftp://ftp.gnupg.org/gcrypt/contrib/faqprog.pl )
77 dnl *** No need to worry about this warning.
78 dnl ***]])
79 dnl     fi
80    ])       
81
82 dnl GNUPG_CHECK_DOCBOOK_TO_TEXI
83 dnl
84 AC_DEFUN([GNUPG_CHECK_DOCBOOK_TO_TEXI],
85   [
86     AC_CHECK_PROG(DOCBOOK_TO_TEXI, docbook2texi, yes, no)
87     AC_MSG_CHECKING(for sgml to texi tools)
88     working_sgmltotexi=no
89     if test "$ac_cv_prog_DOCBOOK_TO_TEXI" = yes; then
90       if sgml2xml -v /dev/null 2>&1 | grep 'SP version' >/dev/null 2>&1 ; then
91             working_sgmltotexi=yes
92       fi
93     fi
94     AC_MSG_RESULT($working_sgmltotexi)
95     AM_CONDITIONAL(HAVE_DOCBOOK_TO_TEXI, test "$working_sgmltotexi" = "yes" )
96    ])       
97
98
99
100 dnl GNUPG_CHECK_ENDIAN
101 dnl define either LITTLE_ENDIAN_HOST or BIG_ENDIAN_HOST
102 dnl
103 AC_DEFUN([GNUPG_CHECK_ENDIAN],
104   [
105     tmp_assumed_endian=big
106     if test "$cross_compiling" = yes; then
107       case "$host_cpu" in
108          i@<:@345678@:>@* )
109             tmp_assumed_endian=little
110             ;;
111          *)
112             ;;
113       esac
114       AC_MSG_WARN(cross compiling; assuming $tmp_assumed_endian endianess)
115     fi
116     AC_MSG_CHECKING(endianess)
117     AC_CACHE_VAL(gnupg_cv_c_endian,
118       [ gnupg_cv_c_endian=unknown
119         # See if sys/param.h defines the BYTE_ORDER macro.
120         AC_TRY_COMPILE([#include <sys/types.h>
121         #include <sys/param.h>], [
122         #if !BYTE_ORDER || !BIG_ENDIAN || !LITTLE_ENDIAN
123          bogus endian macros
124         #endif], [# It does; now see whether it defined to BIG_ENDIAN or not.
125         AC_TRY_COMPILE([#include <sys/types.h>
126         #include <sys/param.h>], [
127         #if BYTE_ORDER != BIG_ENDIAN
128          not big endian
129         #endif], gnupg_cv_c_endian=big, gnupg_cv_c_endian=little)])
130         if test "$gnupg_cv_c_endian" = unknown; then
131             AC_TRY_RUN([main () {
132               /* Are we little or big endian?  From Harbison&Steele.  */
133               union
134               {
135                 long l;
136                 char c[sizeof (long)];
137               } u;
138               u.l = 1;
139               exit (u.c[sizeof (long) - 1] == 1);
140               }],
141               gnupg_cv_c_endian=little,
142               gnupg_cv_c_endian=big,
143               gnupg_cv_c_endian=$tmp_assumed_endian
144             )
145         fi
146       ])
147     AC_MSG_RESULT([$gnupg_cv_c_endian])
148     if test "$gnupg_cv_c_endian" = little; then
149       AC_DEFINE(LITTLE_ENDIAN_HOST,1,
150                 [Defined if the host has little endian byte ordering])
151     else
152       AC_DEFINE(BIG_ENDIAN_HOST,1,
153                 [Defined if the host has big endian byte ordering])
154     fi
155   ])
156
157
158
159
160 # GNUPG_BUILD_PROGRAM(NAME,DEFAULT)
161 # Add a --enable-NAME option to configure an set the
162 # shell variable build_NAME either to "yes" or "no".  DEFAULT must
163 # either be "yes" or "no" and decided on the default value for
164 # build_NAME and whether --enable-NAME or --disable-NAME is shown with 
165 # ./configure --help
166 AC_DEFUN([GNUPG_BUILD_PROGRAM],
167   [build_$1=$2
168    m4_if([$2],[yes],[
169       AC_ARG_ENABLE([$1], AC_HELP_STRING([--disable-$1],
170                                          [do not build the $1 program]),
171                            build_$1=$enableval, build_$1=$2)
172     ],[
173       AC_ARG_ENABLE([$1], AC_HELP_STRING([--enable-$1],
174                                          [build the $1 program]),
175                            build_$1=$enableval, build_$1=$2)
176     ])
177    case "$build_$1" in
178          no|yes)
179            ;;
180          *) 
181            AC_MSG_ERROR([only yes or no allowed for feature --enable-$1])
182            ;;
183    esac
184   ])
185
186
187
188
189 # Check whether mlock is broken (hpux 10.20 raises a SIGBUS if mlock
190 # is not called from uid 0 (not tested whether uid 0 works)
191 # For DECs Tru64 we have also to check whether mlock is in librt
192 # mlock is there a macro using memlk()
193 dnl GNUPG_CHECK_MLOCK
194 dnl
195 AC_DEFUN([GNUPG_CHECK_MLOCK],
196   [ AC_CHECK_FUNCS(mlock)
197     if test "$ac_cv_func_mlock" = "no"; then
198         AC_CHECK_HEADERS(sys/mman.h)
199         if test "$ac_cv_header_sys_mman_h" = "yes"; then
200             # Add librt to LIBS:
201             AC_CHECK_LIB(rt, memlk)
202             AC_CACHE_CHECK([whether mlock is in sys/mman.h],
203                             gnupg_cv_mlock_is_in_sys_mman,
204                 [AC_TRY_LINK([
205                     #include <assert.h>
206                     #ifdef HAVE_SYS_MMAN_H
207                     #include <sys/mman.h>
208                     #endif
209                 ], [
210                     int i;
211
212                     /* glibc defines this for functions which it implements
213                      * to always fail with ENOSYS.  Some functions are actually
214                      * named something starting with __ and the normal name
215                      * is an alias.  */
216                     #if defined (__stub_mlock) || defined (__stub___mlock)
217                     choke me
218                     #else
219                     mlock(&i, 4);
220                     #endif
221                     ; return 0;
222                 ],
223                 gnupg_cv_mlock_is_in_sys_mman=yes,
224                 gnupg_cv_mlock_is_in_sys_mman=no)])
225             if test "$gnupg_cv_mlock_is_in_sys_mman" = "yes"; then
226                 AC_DEFINE(HAVE_MLOCK,1,
227                           [Defined if the system supports an mlock() call])
228             fi
229         fi
230     fi
231     if test "$ac_cv_func_mlock" = "yes"; then
232         AC_MSG_CHECKING(whether mlock is broken)
233           AC_CACHE_VAL(gnupg_cv_have_broken_mlock,
234              AC_TRY_RUN([
235                 #include <stdlib.h>
236                 #include <unistd.h>
237                 #include <errno.h>
238                 #include <sys/mman.h>
239                 #include <sys/types.h>
240                 #include <fcntl.h>
241
242                 int main()
243                 {
244                     char *pool;
245                     int err;
246                     long int pgsize = getpagesize();
247
248                     pool = malloc( 4096 + pgsize );
249                     if( !pool )
250                         return 2;
251                     pool += (pgsize - ((long int)pool % pgsize));
252
253                     err = mlock( pool, 4096 );
254                     if( !err || errno == EPERM )
255                         return 0; /* okay */
256
257                     return 1;  /* hmmm */
258                 }
259
260             ],
261             gnupg_cv_have_broken_mlock="no",
262             gnupg_cv_have_broken_mlock="yes",
263             gnupg_cv_have_broken_mlock="assume-no"
264            )
265          )
266          if test "$gnupg_cv_have_broken_mlock" = "yes"; then
267              AC_DEFINE(HAVE_BROKEN_MLOCK,1,
268                        [Defined if the mlock() call does not work])
269              AC_MSG_RESULT(yes)
270              AC_CHECK_FUNCS(plock)
271          else
272             if test "$gnupg_cv_have_broken_mlock" = "no"; then
273                 AC_MSG_RESULT(no)
274             else
275                 AC_MSG_RESULT(assuming no)
276             fi
277          fi
278     fi
279   ])
280
281
282 dnl Stolen from gcc
283 dnl Define MKDIR_TAKES_ONE_ARG if mkdir accepts only one argument instead
284 dnl of the usual 2.
285 AC_DEFUN([GNUPG_FUNC_MKDIR_TAKES_ONE_ARG],
286 [AC_CHECK_HEADERS(sys/stat.h unistd.h direct.h)
287 AC_CACHE_CHECK([if mkdir takes one argument], gnupg_cv_mkdir_takes_one_arg,
288 [AC_TRY_COMPILE([
289 #include <sys/types.h>
290 #ifdef HAVE_SYS_STAT_H
291 # include <sys/stat.h>
292 #endif
293 #ifdef HAVE_UNISTD_H
294 # include <unistd.h>
295 #endif
296 #ifdef HAVE_DIRECT_H
297 # include <direct.h>
298 #endif], [mkdir ("foo", 0);],
299         gnupg_cv_mkdir_takes_one_arg=no, gnupg_cv_mkdir_takes_one_arg=yes)])
300 if test $gnupg_cv_mkdir_takes_one_arg = yes ; then
301   AC_DEFINE(MKDIR_TAKES_ONE_ARG,1,
302             [Defined if mkdir() does not take permission flags])
303 fi
304 ])
305
306
307
308