add some demo keys
[gnupg.git] / acinclude.m4
1 dnl macros to configure g10
2
3
4 dnl GNUPG_MSG_PRINT(STRING)
5 dnl print a message
6 dnl
7 define(GNUPG_MSG_PRINT,
8   [ echo $ac_n "$1"" $ac_c" 1>&AC_FD_MSG
9   ])
10
11
12 dnl GNUPG_CHECK_TYPEDEF(TYPE, HAVE_NAME)
13 dnl Check whether a typedef exists and create a #define $2 if it exists
14 dnl
15 AC_DEFUN(GNUPG_CHECK_TYPEDEF,
16   [ AC_MSG_CHECKING(for $1 typedef)
17     AC_CACHE_VAL(gnupg_cv_typedef_$1,
18     [AC_TRY_COMPILE([#include <stdlib.h>
19     #include <sys/types.h>], [
20     #undef $1
21     int a = sizeof($1);
22     ], gnupg_cv_typedef_$1=yes, gnupg_cv_typedef_$1=no )])
23     AC_MSG_RESULT($gnupg_cv_typedef_$1)
24     if test "$gnupg_cv_typedef_$1" = yes; then
25         AC_DEFINE($2)
26     fi
27   ])
28
29
30
31 dnl GNUPG_LINK_FILES( SRC, DEST )
32 dnl same as AC_LINK_FILES, but collect the files to link in
33 dnl some special variables and do the link
34 dnl when GNUPG_DO_LINK_FILES is called
35 dnl This is a workaround for AC_LINK_FILES, because it does not work
36 dnl correct when using a caching scheme
37 dnl
38 define(GNUPG_LINK_FILES,
39   [ if test "x$wk_link_files_src" = "x"; then
40         wk_link_files_src="$1"
41         wk_link_files_dst="$2"
42     else
43         wk_link_files_src="$wk_link_files_src $1"
44         wk_link_files_dst="$wk_link_files_dst $2"
45     fi
46   ])
47 define(GNUPG_DO_LINK_FILES,
48   [ AC_LINK_FILES( $wk_link_files_src, $wk_link_files_dst )
49   ])
50
51
52 dnl GNUPG_CHECK_ENDIAN
53 dnl define either LITTLE_ENDIAN_HOST or BIG_ENDIAN_HOST
54 dnl
55 define(GNUPG_CHECK_ENDIAN,
56   [ if test "$cross_compiling" = yes; then
57         AC_MSG_WARN(cross compiling; assuming little endianess)
58     fi
59     AC_MSG_CHECKING(endianess)
60     AC_CACHE_VAL(gnupg_cv_c_endian,
61       [ gnupg_cv_c_endian=unknown
62         # See if sys/param.h defines the BYTE_ORDER macro.
63         AC_TRY_COMPILE([#include <sys/types.h>
64         #include <sys/param.h>], [
65         #if !BYTE_ORDER || !BIG_ENDIAN || !LITTLE_ENDIAN
66          bogus endian macros
67         #endif], [# It does; now see whether it defined to BIG_ENDIAN or not.
68         AC_TRY_COMPILE([#include <sys/types.h>
69         #include <sys/param.h>], [
70         #if BYTE_ORDER != BIG_ENDIAN
71          not big endian
72         #endif], gnupg_cv_c_endian=big, gnupg_cv_c_endian=little)])
73         if test "$gnupg_cv_c_endian" = unknown; then
74             AC_TRY_RUN([main () {
75               /* Are we little or big endian?  From Harbison&Steele.  */
76               union
77               {
78                 long l;
79                 char c[sizeof (long)];
80               } u;
81               u.l = 1;
82               exit (u.c[sizeof (long) - 1] == 1);
83               }],
84               gnupg_cv_c_endian=little,
85               gnupg_cv_c_endian=big,
86               gnupg_cv_c_endian=little
87             )
88         fi
89       ])
90     AC_MSG_RESULT([$gnupg_cv_c_endian])
91     if test "$gnupg_cv_c_endian" = little; then
92       AC_DEFINE(LITTLE_ENDIAN_HOST)
93     else
94       AC_DEFINE(BIG_ENDIAN_HOST)
95     fi
96   ])
97
98 dnl GNUPG_CHECK_CACHE
99 dnl
100 define(GNUPG_CHECK_CACHE,
101   [ AC_MSG_CHECKING(cached information)
102     gnupg_hostcheck="$target"
103     AC_CACHE_VAL(gnupg_cv_hostcheck, [ gnupg_cv_hostcheck="$gnupg_hostcheck" ])
104     if test "$gnupg_cv_hostcheck" != "$gnupg_hostcheck"; then
105         AC_MSG_RESULT(changed)
106         AC_MSG_WARN(config.cache exists!)
107         AC_MSG_ERROR(you must do 'make distclean' first to compile for
108                  different target or different parameters.)
109     else
110         AC_MSG_RESULT(ok)
111     fi
112   ])
113
114
115 ######################################################################
116 # Check for -fPIC etc (taken from libtool)
117 # This sets CFLAGS_PIC to the required flags
118 #           NO_PIC to yes if it is not possible to
119 #                  generate PIC
120 ######################################################################
121 dnl GNUPG_CHECK_PIC
122 dnl
123 define(GNUPG_CHECK_PIC,
124   [ AC_MSG_CHECKING(for option to create PIC)
125     CFLAGS_PIC=
126     NO_PIC=no
127     if test "$cross_compiling" = yes; then
128         AC_MSG_RESULT(assume none)
129     else
130         if test "$GCC" = yes; then
131             CFLAGS_PIC="-fPIC"
132         else
133             case "$host_os" in
134               aix3* | aix4*)
135                 # All rs/6000 code is PIC
136                 # but is there any non-rs/6000 AIX platform?
137                 ;;
138
139               hpux9* | hpux10*)
140                 CFLAGS_PIC="+Z"
141                 ;;
142
143               irix5* | irix6*)
144                 # PIC (with -KPIC) is the default.
145                 ;;
146
147               osf3* | osf4*)
148                 # FIXME - pic_flag is probably required for
149                 # hppa*-osf* and i860-osf*
150                 ;;
151
152               sco3.2v5*)
153                 CFLAGS_PIC='-Kpic'
154                 ;;
155
156               solaris2* | solaris7* )
157                 CFLAGS_PIC='-KPIC'
158                 ;;
159
160               sunos4*)
161                 CFLAGS_PIC='-PIC'
162                 ;;
163
164               *)
165                 NO_PIC=yes
166                 ;;
167             esac
168         fi
169
170         case "$host_cpu" in
171         rs6000 | powerpc | powerpcle)
172           # Yippee! All RS/6000 and PowerPC code is position-independent.
173           CFLAGS_PIC=""
174           ;;
175         esac
176
177         if test "$NO_PIC" = yes; then
178             AC_MSG_RESULT(not possible)
179         else
180             if test -z "$CFLAGS_PIC"; then
181                AC_MSG_RESULT(none)
182             else
183                 AC_MSG_RESULT($CFLAGS_PIC)
184             fi
185         fi
186     fi
187   ])
188
189
190 ######################################################################
191 # Check for rdynamic flag
192 # This sets CFLAGS_RDYNAMIC to the required flags
193 ######################################################################
194 dnl GNUPG_CHECK_RDYNAMIC
195 dnl
196 define(GNUPG_CHECK_RDYNAMIC,
197   [ AC_MSG_CHECKING(how to specify -rdynamic)
198     CFLAGS_RDYNAMIC=
199     if test "$cross_compiling" = yes; then
200         AC_MSG_RESULT(assume none)
201     else
202         case "$host_os" in
203           solaris* )
204             CFLAGS_RDYNAMIC="-Wl,-dy"
205             ;;
206
207           freebsd2* | osf4* )
208             CFLAGS_RDYNAMIC=""
209             ;;
210           * )
211             CFLAGS_RDYNAMIC="-Wl,-export-dynamic"
212             ;;
213         esac
214         AC_MSG_RESULT($CFLAGS_RDYNAMIC)
215     fi
216   ])
217
218
219 #####################################################################
220 # Check for SysV IPC  (from GIMP)
221 #   And see whether we have a SHM_LOCK (FreeBSD does not have it).
222 #####################################################################
223 dnl GNUPG_CHECK_IPC
224 dnl
225 define(GNUPG_CHECK_IPC,
226    [ AC_CHECK_HEADERS(sys/ipc.h sys/shm.h)
227      if test "$ac_cv_header_sys_shm_h" = "yes"; then
228        AC_MSG_CHECKING(whether IPC_RMID allowes subsequent attaches)
229        AC_CACHE_VAL(gnupg_cv_ipc_rmid_deferred_release,
230           AC_TRY_RUN([
231              #include <sys/types.h>
232              #include <sys/ipc.h>
233              #include <sys/shm.h>
234              int main()
235              {
236                int id;
237                char *shmaddr;
238              id = shmget (IPC_PRIVATE, 4, IPC_CREAT | 0777);
239              if (id == -1)
240                exit (2);
241                shmaddr = shmat (id, 0, 0);
242                shmctl (id, IPC_RMID, 0);
243                if ((char*) shmat (id, 0, 0) == (char*) -1)
244                {
245                  shmdt (shmaddr);
246                  exit (1);
247                }
248                shmdt (shmaddr);
249                shmdt (shmaddr);
250                exit (0);
251              }
252          ],
253          gnupg_cv_ipc_rmid_deferred_release="yes",
254          gnupg_cv_ipc_rmid_deferred_release="no",
255          gnupg_cv_ipc_rmid_deferred_release="assume-no")
256        )
257        if test "$gnupg_cv_ipc_rmid_deferred_release" = "yes"; then
258            AC_DEFINE(IPC_RMID_DEFERRED_RELEASE)
259            AC_MSG_RESULT(yes)
260        else
261           if test "$gnupg_cv_ipc_rmid_deferred_release" = "no"; then
262               AC_MSG_RESULT(no)
263           else
264               AC_MSG_RESULT([assuming no])
265           fi
266        fi
267
268        AC_MSG_CHECKING(whether SHM_LOCK is available)
269        AC_CACHE_VAL(gnupg_cv_ipc_have_shm_lock,
270           AC_TRY_COMPILE([#include <sys/types.h>
271              #include <sys/ipc.h>
272              #include <sys/shm.h>],[
273              int foo( int shm_id ) {  shmctl(shm_id, SHM_LOCK, 0); }
274              ],
275              gnupg_cv_ipc_have_shm_lock="yes",
276              gnupg_cv_ipc_have_shm_lock="no"
277           )
278        )
279        if test "$gnupg_cv_ipc_have_shm_lock" = "yes"; then
280          AC_DEFINE(IPC_HAVE_SHM_LOCK)
281          AC_MSG_RESULT(yes)
282        else
283          AC_MSG_RESULT(no)
284        fi
285      fi
286    ])
287
288
289 ######################################################################
290 # Check whether mlock is broken (hpux 10.20 raises a SIGBUS if mlock
291 # is not called from uid 0 (not tested whether uid 0 works)
292 ######################################################################
293 dnl GNUPG_CHECK_MLOCK
294 dnl
295 define(GNUPG_CHECK_MLOCK,
296   [ AC_CHECK_FUNCS(mlock)
297     if test "$ac_cv_func_mlock" = "yes"; then
298         AC_MSG_CHECKING(whether mlock is broken)
299           AC_CACHE_VAL(gnupg_cv_have_broken_mlock,
300              AC_TRY_RUN([
301                 #include <stdlib.h>
302                 #include <unistd.h>
303                 #include <errno.h>
304                 #include <sys/mman.h>
305                 #include <sys/types.h>
306                 #include <fcntl.h>
307
308                 int main()
309                 {
310                     char *pool;
311                     int err;
312                     long int pgsize = getpagesize();
313
314                     pool = malloc( 4096 + pgsize );
315                     if( !pool )
316                         return 2;
317                     pool += (pgsize - ((long int)pool % pgsize));
318
319                     err = mlock( pool, 4096 );
320                     if( !err || errno == EPERM )
321                         return 0; /* okay */
322
323                     return 1;  /* hmmm */
324                 }
325
326             ],
327             gnupg_cv_have_broken_mlock="no",
328             gnupg_cv_have_broken_mlock="yes",
329             gnupg_cv_have_broken_mlock="assume-no"
330            )
331          )
332          if test "$gnupg_cv_have_broken_mlock" = "yes"; then
333              AC_DEFINE(HAVE_BROKEN_MLOCK)
334              AC_MSG_RESULT(yes)
335          else
336             if test "$gnupg_cv_have_broken_mlock" = "no"; then
337                 AC_MSG_RESULT(no)
338             else
339                 AC_MSG_RESULT(assuming no)
340             fi
341          fi
342     fi
343   ])
344
345
346 dnl *-*wedit:notab*-*  Please keep this as the last line.