See ChangeLog: Sat Jun 26 12:15:59 CEST 1999 Werner Koch
[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           hpux* )
208             CFLAGS_RDYNAMIC="-Wl,-E"
209             ;;
210
211           openbsd* | freebsd2* | osf4* | irix* )
212             CFLAGS_RDYNAMIC=""
213             ;;
214
215           * )
216             CFLAGS_RDYNAMIC="-Wl,-export-dynamic"
217             ;;
218         esac
219         AC_MSG_RESULT($CFLAGS_RDYNAMIC)
220     fi
221   ])
222
223
224 #####################################################################
225 # Check for SysV IPC  (from GIMP)
226 #   And see whether we have a SHM_LOCK (FreeBSD does not have it).
227 #####################################################################
228 dnl GNUPG_CHECK_IPC
229 dnl
230 define(GNUPG_CHECK_IPC,
231    [ AC_CHECK_HEADERS(sys/ipc.h sys/shm.h)
232      if test "$ac_cv_header_sys_shm_h" = "yes"; then
233        AC_MSG_CHECKING(whether IPC_RMID allowes subsequent attaches)
234        AC_CACHE_VAL(gnupg_cv_ipc_rmid_deferred_release,
235           AC_TRY_RUN([
236              #include <sys/types.h>
237              #include <sys/ipc.h>
238              #include <sys/shm.h>
239              int main()
240              {
241                int id;
242                char *shmaddr;
243              id = shmget (IPC_PRIVATE, 4, IPC_CREAT | 0777);
244              if (id == -1)
245                exit (2);
246                shmaddr = shmat (id, 0, 0);
247                shmctl (id, IPC_RMID, 0);
248                if ((char*) shmat (id, 0, 0) == (char*) -1)
249                {
250                  shmdt (shmaddr);
251                  exit (1);
252                }
253                shmdt (shmaddr);
254                shmdt (shmaddr);
255                exit (0);
256              }
257          ],
258          gnupg_cv_ipc_rmid_deferred_release="yes",
259          gnupg_cv_ipc_rmid_deferred_release="no",
260          gnupg_cv_ipc_rmid_deferred_release="assume-no")
261        )
262        if test "$gnupg_cv_ipc_rmid_deferred_release" = "yes"; then
263            AC_DEFINE(IPC_RMID_DEFERRED_RELEASE)
264            AC_MSG_RESULT(yes)
265        else
266           if test "$gnupg_cv_ipc_rmid_deferred_release" = "no"; then
267               AC_MSG_RESULT(no)
268           else
269               AC_MSG_RESULT([assuming no])
270           fi
271        fi
272
273        AC_MSG_CHECKING(whether SHM_LOCK is available)
274        AC_CACHE_VAL(gnupg_cv_ipc_have_shm_lock,
275           AC_TRY_COMPILE([#include <sys/types.h>
276              #include <sys/ipc.h>
277              #include <sys/shm.h>],[
278              int foo( int shm_id ) {  shmctl(shm_id, SHM_LOCK, 0); }
279              ],
280              gnupg_cv_ipc_have_shm_lock="yes",
281              gnupg_cv_ipc_have_shm_lock="no"
282           )
283        )
284        if test "$gnupg_cv_ipc_have_shm_lock" = "yes"; then
285          AC_DEFINE(IPC_HAVE_SHM_LOCK)
286          AC_MSG_RESULT(yes)
287        else
288          AC_MSG_RESULT(no)
289        fi
290      fi
291    ])
292
293
294 ######################################################################
295 # Check whether mlock is broken (hpux 10.20 raises a SIGBUS if mlock
296 # is not called from uid 0 (not tested whether uid 0 works)
297 ######################################################################
298 dnl GNUPG_CHECK_MLOCK
299 dnl
300 define(GNUPG_CHECK_MLOCK,
301   [ AC_CHECK_FUNCS(mlock)
302     if test "$ac_cv_func_mlock" = "yes"; then
303         AC_MSG_CHECKING(whether mlock is broken)
304           AC_CACHE_VAL(gnupg_cv_have_broken_mlock,
305              AC_TRY_RUN([
306                 #include <stdlib.h>
307                 #include <unistd.h>
308                 #include <errno.h>
309                 #include <sys/mman.h>
310                 #include <sys/types.h>
311                 #include <fcntl.h>
312
313                 int main()
314                 {
315                     char *pool;
316                     int err;
317                     long int pgsize = getpagesize();
318
319                     pool = malloc( 4096 + pgsize );
320                     if( !pool )
321                         return 2;
322                     pool += (pgsize - ((long int)pool % pgsize));
323
324                     err = mlock( pool, 4096 );
325                     if( !err || errno == EPERM )
326                         return 0; /* okay */
327
328                     return 1;  /* hmmm */
329                 }
330
331             ],
332             gnupg_cv_have_broken_mlock="no",
333             gnupg_cv_have_broken_mlock="yes",
334             gnupg_cv_have_broken_mlock="assume-no"
335            )
336          )
337          if test "$gnupg_cv_have_broken_mlock" = "yes"; then
338              AC_DEFINE(HAVE_BROKEN_MLOCK)
339              AC_MSG_RESULT(yes)
340          else
341             if test "$gnupg_cv_have_broken_mlock" = "no"; then
342                 AC_MSG_RESULT(no)
343             else
344                 AC_MSG_RESULT(assuming no)
345             fi
346          fi
347     fi
348   ])
349
350
351 ################################################################
352
353 # GNUPG_PROG_NM - find the path to a BSD-compatible name lister
354 AC_DEFUN(GNUPG_PROG_NM,
355 [AC_MSG_CHECKING([for BSD-compatible nm])
356 AC_CACHE_VAL(ac_cv_path_NM,
357 [if test -n "$NM"; then
358   # Let the user override the test.
359   ac_cv_path_NM="$NM"
360 else
361   IFS="${IFS=   }"; ac_save_ifs="$IFS"; IFS="${IFS}:"
362   for ac_dir in /usr/ucb /usr/ccs/bin $PATH /bin; do
363     test -z "$ac_dir" && ac_dir=.
364     if test -f $ac_dir/nm; then
365       # Check to see if the nm accepts a BSD-compat flag.
366       # Adding the `sed 1q' prevents false positives on HP-UX, which says:
367       #   nm: unknown option "B" ignored
368       if ($ac_dir/nm -B /dev/null 2>&1 | sed '1q'; exit 0) | egrep /dev/null >/dev/null; then
369         ac_cv_path_NM="$ac_dir/nm -B"
370       elif ($ac_dir/nm -p /dev/null 2>&1 | sed '1q'; exit 0) | egrep /dev/null >/dev/null; then
371         ac_cv_path_NM="$ac_dir/nm -p"
372       else
373         ac_cv_path_NM="$ac_dir/nm"
374       fi
375       break
376     fi
377   done
378   IFS="$ac_save_ifs"
379   test -z "$ac_cv_path_NM" && ac_cv_path_NM=nm
380 fi])
381 NM="$ac_cv_path_NM"
382 AC_MSG_RESULT([$NM])
383 AC_SUBST(NM)
384 ])
385
386 # GNUPG_SYS_NM_PARSE - Check for command ro grab the raw symbol name followed
387 # by C symbol name from nm.
388 AC_DEFUN(GNUPG_SYS_NM_PARSE,
389 [AC_REQUIRE([AC_CANONICAL_HOST])dnl
390 AC_REQUIRE([GNUPG_PROG_NM])dnl
391 # Check for command to grab the raw symbol name followed by C symbol from nm.
392 AC_MSG_CHECKING([command to parse $NM output])
393 AC_CACHE_VAL(ac_cv_sys_global_symbol_pipe,
394 [# These are sane defaults that work on at least a few old systems.
395 # {They come from Ultrix.  What could be older than Ultrix?!! ;)}
396
397 changequote(,)dnl
398 # Character class describing NM global symbol codes.
399 ac_symcode='[BCDEGRSTU]'
400
401 # Regexp to match symbols that can be accessed directly from C.
402 ac_sympat='\([_A-Za-z][_A-Za-z0-9]*\)'
403
404 # Transform the above into a raw symbol and a C symbol.
405 ac_symxfrm='\1 \1'
406
407 # Define system-specific variables.
408 case "$host_os" in
409 aix*)
410   ac_symcode='[BCDTU]'
411   ;;
412 freebsd* | netbsd* | openbsd* | sunos* | cygwin32* | mingw32*)
413   ac_sympat='_\([_A-Za-z][_A-Za-z0-9]*\)'
414   ac_symxfrm='_\1 \1'
415   ;;
416 irix*)
417   # Cannot use undefined symbols on IRIX because inlined functions mess us up.
418   ac_symcode='[BCDEGRST]'
419   ;;
420 solaris*)
421   ac_symcode='[BDTU]'
422   ;;
423 esac
424
425 # If we're using GNU nm, then use its standard symbol codes.
426 if $NM -V 2>&1 | egrep '(GNU|with BFD)' > /dev/null; then
427   ac_symcode='[ABCDGISTUW]'
428 fi
429
430 case "$host_os" in
431 cygwin32* | mingw32*)
432   # We do not want undefined symbols on cygwin32.  The user must
433   # arrange to define them via -l arguments.
434   ac_symcode='[ABCDGISTW]'
435   ;;
436 esac
437 changequote([,])dnl
438
439 # Write the raw and C identifiers.
440 ac_cv_sys_global_symbol_pipe="sed -n -e 's/^.* $ac_symcode $ac_sympat$/$ac_symxfrm/p'"
441
442 # Check to see that the pipe works correctly.
443 ac_pipe_works=no
444 cat > conftest.$ac_ext <<EOF
445 #ifdef __cplusplus
446 extern "C" {
447 #endif
448 char nm_test_var;
449 void nm_test_func(){}
450 #ifdef __cplusplus
451 }
452 #endif
453 int main(){nm_test_var='a';nm_test_func;return 0;}
454 EOF
455 if AC_TRY_EVAL(ac_compile); then
456   # Now try to grab the symbols.
457   ac_nlist=conftest.nm
458   if AC_TRY_EVAL(NM conftest.$ac_objext \| $ac_cv_sys_global_symbol_pipe \> $ac_nlist) && test -s "$ac_nlist"; then
459
460     # Try sorting and uniquifying the output.
461     if sort "$ac_nlist" | uniq > "$ac_nlist"T; then
462       mv -f "$ac_nlist"T "$ac_nlist"
463       ac_wcout=`wc "$ac_nlist" 2>/dev/null`
464 changequote(,)dnl
465       ac_count=`echo "X$ac_wcout" | sed -e 's,^X,,' -e 's/^[    ]*\([0-9][0-9]*\).*$/\1/'`
466 changequote([,])dnl
467       (test "$ac_count" -ge 0) 2>/dev/null || ac_count=-1
468     else
469       rm -f "$ac_nlist"T
470       ac_count=-1
471     fi
472
473     # Make sure that we snagged all the symbols we need.
474     if egrep ' nm_test_var$' "$ac_nlist" >/dev/null; then
475       if egrep ' nm_test_func$' "$ac_nlist" >/dev/null; then
476         cat <<EOF > conftest.c
477 #ifdef __cplusplus
478 extern "C" {
479 #endif
480
481 EOF
482         # Now generate the symbol file.
483         sed 's/^.* \(.*\)$/extern char \1;/' < "$ac_nlist" >> conftest.c
484
485         cat <<EOF >> conftest.c
486 #if defined (__STDC__) && __STDC__
487 # define __ptr_t void *
488 #else
489 # define __ptr_t char *
490 #endif
491
492 /* The number of symbols in dld_preloaded_symbols, -1 if unsorted. */
493 int dld_preloaded_symbol_count = $ac_count;
494
495 /* The mapping between symbol names and symbols. */
496 struct {
497   char *name;
498   __ptr_t address;
499 }
500 changequote(,)dnl
501 dld_preloaded_symbols[] =
502 changequote([,])dnl
503 {
504 EOF
505         sed 's/^\(.*\) \(.*\)$/  {"\1", (__ptr_t) \&\2},/' < "$ac_nlist" >> conftest.c
506         cat <<\EOF >> conftest.c
507   {0, (__ptr_t) 0}
508 };
509
510 #ifdef __cplusplus
511 }
512 #endif
513 EOF
514         # Now try linking the two files.
515         mv conftest.$ac_objext conftestm.$ac_objext
516         ac_save_LIBS="$LIBS"
517         ac_save_CFLAGS="$CFLAGS"
518         LIBS="conftestm.$ac_objext"
519         CFLAGS="$CFLAGS$no_builtin_flag"
520         if AC_TRY_EVAL(ac_link) && test -s conftest; then
521           ac_pipe_works=yes
522         else
523           echo "configure: failed program was:" >&AC_FD_CC
524           cat conftest.c >&AC_FD_CC
525         fi
526         LIBS="$ac_save_LIBS"
527         CFLAGS="$ac_save_CFLAGS"
528       else
529         echo "cannot find nm_test_func in $ac_nlist" >&AC_FD_CC
530       fi
531     else
532       echo "cannot find nm_test_var in $ac_nlist" >&AC_FD_CC
533     fi
534   else
535     echo "cannot run $ac_cv_sys_global_symbol_pipe" >&AC_FD_CC
536   fi
537 else
538   echo "$progname: failed program was:" >&AC_FD_CC
539   cat conftest.c >&AC_FD_CC
540 fi
541 rm -rf conftest*
542
543 # Do not use the global_symbol_pipe unless it works.
544 test "$ac_pipe_works" = yes || ac_cv_sys_global_symbol_pipe=
545 ])
546
547 ac_result=yes
548 if test -z "$ac_cv_sys_global_symbol_pipe"; then
549    ac_result=no
550 fi
551 AC_MSG_RESULT($ac_result)
552 ])
553
554 # GNUPG_SYS_LIBTOOL_CYGWIN32 - find tools needed on cygwin32
555 AC_DEFUN(GNUPG_SYS_LIBTOOL_CYGWIN32,
556 [AC_CHECK_TOOL(DLLTOOL, dlltool, false)
557 AC_CHECK_TOOL(AS, as, false)
558 ])
559
560 # GNUPG_SYS_SYMBOL_UNDERSCORE - does the compiler prefix global symbols
561 #                              with an underscore?
562 AC_DEFUN(GNUPG_SYS_SYMBOL_UNDERSCORE,
563 [if test "$cross_compiling" = yes; then
564     AC_MSG_CHECKING([for _ prefix in compiled symbols])
565     ac_cv_sys_symbol_underscore=yes
566     AC_MSG_RESULT(assume yes)
567 else
568 AC_REQUIRE([GNUPG_PROG_NM])dnl
569 AC_REQUIRE([GNUPG_SYS_NM_PARSE])dnl
570 AC_MSG_CHECKING([for _ prefix in compiled symbols])
571 AC_CACHE_VAL(ac_cv_sys_symbol_underscore,
572 [ac_cv_sys_symbol_underscore=no
573 cat > conftest.$ac_ext <<EOF
574 void nm_test_func(){}
575 int main(){nm_test_func;return 0;}
576 EOF
577 if AC_TRY_EVAL(ac_compile); then
578   # Now try to grab the symbols.
579   ac_nlist=conftest.nm
580   if AC_TRY_EVAL(NM conftest.$ac_objext \| $ac_cv_sys_global_symbol_pipe \> $ac_nlist) && test -s "$ac_nlist"; then
581     # See whether the symbols have a leading underscore.
582     if egrep '^_nm_test_func' "$ac_nlist" >/dev/null; then
583       ac_cv_sys_symbol_underscore=yes
584     else
585       if egrep '^nm_test_func ' "$ac_nlist" >/dev/null; then
586         :
587       else
588         echo "configure: cannot find nm_test_func in $ac_nlist" >&AC_FD_CC
589       fi
590     fi
591   else
592     echo "configure: cannot run $ac_cv_sys_global_symbol_pipe" >&AC_FD_CC
593   fi
594 else
595   echo "configure: failed program was:" >&AC_FD_CC
596   cat conftest.c >&AC_FD_CC
597 fi
598 rm -rf conftest*
599 ])
600 AC_MSG_RESULT($ac_cv_sys_symbol_underscore)
601 fi
602 if test x$ac_cv_sys_symbol_underscore = xyes; then
603   AC_DEFINE(WITH_SYMBOL_UNDERSCORE,1,
604   [define if compiled symbols have a leading underscore])
605 fi
606 ])
607
608
609 dnl *-*wedit:notab*-*  Please keep this as the last line.