See ChangeLog: Wed Mar 17 13:09:03 CET 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           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 ################################################################
347
348 # GNUPG_PROG_NM - find the path to a BSD-compatible name lister
349 AC_DEFUN(GNUPG_PROG_NM,
350 [AC_MSG_CHECKING([for BSD-compatible nm])
351 AC_CACHE_VAL(ac_cv_path_NM,
352 [if test -n "$NM"; then
353   # Let the user override the test.
354   ac_cv_path_NM="$NM"
355 else
356   IFS="${IFS=   }"; ac_save_ifs="$IFS"; IFS="${IFS}:"
357   for ac_dir in /usr/ucb /usr/ccs/bin $PATH /bin; do
358     test -z "$ac_dir" && ac_dir=.
359     if test -f $ac_dir/nm; then
360       # Check to see if the nm accepts a BSD-compat flag.
361       # Adding the `sed 1q' prevents false positives on HP-UX, which says:
362       #   nm: unknown option "B" ignored
363       if ($ac_dir/nm -B /dev/null 2>&1 | sed '1q'; exit 0) | egrep /dev/null >/dev/null; then
364         ac_cv_path_NM="$ac_dir/nm -B"
365       elif ($ac_dir/nm -p /dev/null 2>&1 | sed '1q'; exit 0) | egrep /dev/null >/dev/null; then
366         ac_cv_path_NM="$ac_dir/nm -p"
367       else
368         ac_cv_path_NM="$ac_dir/nm"
369       fi
370       break
371     fi
372   done
373   IFS="$ac_save_ifs"
374   test -z "$ac_cv_path_NM" && ac_cv_path_NM=nm
375 fi])
376 NM="$ac_cv_path_NM"
377 AC_MSG_RESULT([$NM])
378 AC_SUBST(NM)
379 ])
380
381 # GNUPG_SYS_NM_PARSE - Check for command ro grab the raw symbol name followed
382 # by C symbol name from nm.
383 AC_DEFUN(GNUPG_SYS_NM_PARSE,
384 [AC_REQUIRE([AC_CANONICAL_HOST])dnl
385 AC_REQUIRE([GNUPG_PROG_NM])dnl
386 # Check for command to grab the raw symbol name followed by C symbol from nm.
387 AC_MSG_CHECKING([command to parse $NM output])
388 AC_CACHE_VAL(ac_cv_sys_global_symbol_pipe,
389 [# These are sane defaults that work on at least a few old systems.
390 # {They come from Ultrix.  What could be older than Ultrix?!! ;)}
391
392 changequote(,)dnl
393 # Character class describing NM global symbol codes.
394 ac_symcode='[BCDEGRSTU]'
395
396 # Regexp to match symbols that can be accessed directly from C.
397 ac_sympat='\([_A-Za-z][_A-Za-z0-9]*\)'
398
399 # Transform the above into a raw symbol and a C symbol.
400 ac_symxfrm='\1 \1'
401
402 # Define system-specific variables.
403 case "$host_os" in
404 aix*)
405   ac_symcode='[BCDTU]'
406   ;;
407 sunos* | cygwin32* | mingw32*)
408   ac_sympat='_\([_A-Za-z][_A-Za-z0-9]*\)'
409   ac_symxfrm='_\1 \1'
410   ;;
411 irix*)
412   # Cannot use undefined symbols on IRIX because inlined functions mess us up.
413   ac_symcode='[BCDEGRST]'
414   ;;
415 solaris*)
416   ac_symcode='[BDTU]'
417   ;;
418 esac
419
420 # If we're using GNU nm, then use its standard symbol codes.
421 if $NM -V 2>&1 | egrep '(GNU|with BFD)' > /dev/null; then
422   ac_symcode='[ABCDGISTUW]'
423 fi
424
425 case "$host_os" in
426 cygwin32* | mingw32*)
427   # We do not want undefined symbols on cygwin32.  The user must
428   # arrange to define them via -l arguments.
429   ac_symcode='[ABCDGISTW]'
430   ;;
431 esac
432 changequote([,])dnl
433
434 # Write the raw and C identifiers.
435 ac_cv_sys_global_symbol_pipe="sed -n -e 's/^.* $ac_symcode $ac_sympat$/$ac_symxfrm/p'"
436
437 # Check to see that the pipe works correctly.
438 ac_pipe_works=no
439 cat > conftest.$ac_ext <<EOF
440 #ifdef __cplusplus
441 extern "C" {
442 #endif
443 char nm_test_var;
444 void nm_test_func(){}
445 #ifdef __cplusplus
446 }
447 #endif
448 int main(){nm_test_var='a';nm_test_func;return 0;}
449 EOF
450 if AC_TRY_EVAL(ac_compile); then
451   # Now try to grab the symbols.
452   ac_nlist=conftest.nm
453   if AC_TRY_EVAL(NM conftest.$ac_objext \| $ac_cv_sys_global_symbol_pipe \> $ac_nlist) && test -s "$ac_nlist"; then
454
455     # Try sorting and uniquifying the output.
456     if sort "$ac_nlist" | uniq > "$ac_nlist"T; then
457       mv -f "$ac_nlist"T "$ac_nlist"
458       ac_wcout=`wc "$ac_nlist" 2>/dev/null`
459 changequote(,)dnl
460       ac_count=`echo "X$ac_wcout" | sed -e 's,^X,,' -e 's/^[    ]*\([0-9][0-9]*\).*$/\1/'`
461 changequote([,])dnl
462       (test "$ac_count" -ge 0) 2>/dev/null || ac_count=-1
463     else
464       rm -f "$ac_nlist"T
465       ac_count=-1
466     fi
467
468     # Make sure that we snagged all the symbols we need.
469     if egrep ' nm_test_var$' "$ac_nlist" >/dev/null; then
470       if egrep ' nm_test_func$' "$ac_nlist" >/dev/null; then
471         cat <<EOF > conftest.c
472 #ifdef __cplusplus
473 extern "C" {
474 #endif
475
476 EOF
477         # Now generate the symbol file.
478         sed 's/^.* \(.*\)$/extern char \1;/' < "$ac_nlist" >> conftest.c
479
480         cat <<EOF >> conftest.c
481 #if defined (__STDC__) && __STDC__
482 # define __ptr_t void *
483 #else
484 # define __ptr_t char *
485 #endif
486
487 /* The number of symbols in dld_preloaded_symbols, -1 if unsorted. */
488 int dld_preloaded_symbol_count = $ac_count;
489
490 /* The mapping between symbol names and symbols. */
491 struct {
492   char *name;
493   __ptr_t address;
494 }
495 changequote(,)dnl
496 dld_preloaded_symbols[] =
497 changequote([,])dnl
498 {
499 EOF
500         sed 's/^\(.*\) \(.*\)$/  {"\1", (__ptr_t) \&\2},/' < "$ac_nlist" >> conftest.c
501         cat <<\EOF >> conftest.c
502   {0, (__ptr_t) 0}
503 };
504
505 #ifdef __cplusplus
506 }
507 #endif
508 EOF
509         # Now try linking the two files.
510         mv conftest.$ac_objext conftestm.$ac_objext
511         ac_save_LIBS="$LIBS"
512         ac_save_CFLAGS="$CFLAGS"
513         LIBS="conftestm.$ac_objext"
514         CFLAGS="$CFLAGS$no_builtin_flag"
515         if AC_TRY_EVAL(ac_link) && test -s conftest; then
516           ac_pipe_works=yes
517         else
518           echo "configure: failed program was:" >&AC_FD_CC
519           cat conftest.c >&AC_FD_CC
520         fi
521         LIBS="$ac_save_LIBS"
522         CFLAGS="$ac_save_CFLAGS"
523       else
524         echo "cannot find nm_test_func in $ac_nlist" >&AC_FD_CC
525       fi
526     else
527       echo "cannot find nm_test_var in $ac_nlist" >&AC_FD_CC
528     fi
529   else
530     echo "cannot run $ac_cv_sys_global_symbol_pipe" >&AC_FD_CC
531   fi
532 else
533   echo "$progname: failed program was:" >&AC_FD_CC
534   cat conftest.c >&AC_FD_CC
535 fi
536 rm -rf conftest*
537
538 # Do not use the global_symbol_pipe unless it works.
539 test "$ac_pipe_works" = yes || ac_cv_sys_global_symbol_pipe=
540 ])
541
542 ac_result=yes
543 if test -z "$ac_cv_sys_global_symbol_pipe"; then
544    ac_result=no
545 fi
546 AC_MSG_RESULT($ac_result)
547 ])
548
549 # GNUPG_SYS_LIBTOOL_CYGWIN32 - find tools needed on cygwin32
550 AC_DEFUN(GNUPG_SYS_LIBTOOL_CYGWIN32,
551 [AC_CHECK_TOOL(DLLTOOL, dlltool, false)
552 AC_CHECK_TOOL(AS, as, false)
553 ])
554
555 # GNUPG_SYS_SYMBOL_UNDERSCORE - does the compiler prefix global symbols
556 #                            with an underscore?
557 AC_DEFUN(GNUPG_SYS_SYMBOL_UNDERSCORE,
558 [AC_REQUIRE([GNUPG_PROG_NM])dnl
559 AC_REQUIRE([GNUPG_SYS_NM_PARSE])dnl
560 AC_MSG_CHECKING([for _ prefix in compiled symbols])
561 AC_CACHE_VAL(ac_cv_sys_symbol_underscore,
562 [ac_cv_sys_symbol_underscore=no
563 cat > conftest.$ac_ext <<EOF
564 void nm_test_func(){}
565 int main(){nm_test_func;return 0;}
566 EOF
567 if AC_TRY_EVAL(ac_compile); then
568   # Now try to grab the symbols.
569   ac_nlist=conftest.nm
570   if AC_TRY_EVAL(NM conftest.$ac_objext \| $ac_cv_sys_global_symbol_pipe \> $ac_nlist) && test -s "$ac_nlist"; then
571     # See whether the symbols have a leading underscore.
572     if egrep '^_nm_test_func' "$ac_nlist" >/dev/null; then
573       ac_cv_sys_symbol_underscore=yes
574     else
575       if egrep '^nm_test_func ' "$ac_nlist" >/dev/null; then
576         :
577       else
578         echo "configure: cannot find nm_test_func in $ac_nlist" >&AC_FD_CC
579       fi
580     fi
581   else
582     echo "configure: cannot run $ac_cv_sys_global_symbol_pipe" >&AC_FD_CC
583   fi
584 else
585   echo "configure: failed program was:" >&AC_FD_CC
586   cat conftest.c >&AC_FD_CC
587 fi
588 rm -rf conftest*
589 ])
590 AC_MSG_RESULT($ac_cv_sys_symbol_underscore)
591 if test x$ac_cv_sys_symbol_underscore = xyes; then
592   AC_DEFINE(WITH_SYMBOL_UNDERSCORE,1,
593   [define if compiled symbols have a leading underscore])
594 fi
595 ])
596
597
598 dnl *-*wedit:notab*-*  Please keep this as the last line.