Checkin of new directory structure.
[pspp-builds.git] / acinclude.m4
1 dnl Copyright (C) 2005, 2006 Free Software Foundation, Inc.
2 dnl This file is free software; the Free Software Foundation
3 dnl gives unlimited permission to copy and/or distribute it,
4 dnl with or without modifications, as long as this notice is preserved.
5
6 dnl Check longest integer in digits.
7
8 AC_DEFUN([BLP_INT_DIGITS],
9 [
10 AC_MSG_CHECKING(number of digits in LONG_MIN (incl. sign))
11 AC_CACHE_VAL(blp_int_digits,
12              [AC_TRY_RUN([#include <stdio.h>
13                           #include <limits.h>
14                           int
15                           main()
16                           {
17                             int len;
18                             char s[80];
19                             sprintf(s, "%ld", LONG_MAX);
20                             len = strlen(s);
21                             sprintf(s, "%ld", LONG_MIN);
22                             if(strlen(s)>len) len=strlen(s);
23                             sprintf(s, "%lu", ULONG_MAX);
24                             if(strlen(s)>len) len=strlen(s);
25                             exit(len);
26                           }
27                          ],
28                          eval "blp_int_digits=19",
29                          eval "blp_int_digits=$?"
30                          if test "$blp_int_digits" -lt 11; then
31                            blp_int_digits=11
32                          fi,
33                          eval "blp_int_digits=19")
34              ])
35 AC_DEFINE_UNQUOTED([INT_DIGITS], $blp_int_digits,
36         [Number of digits in longest `long' value, including sign.
37          This is usually 11, for 32-bit `long's, or 19, for 64-bit
38          `long's.])
39 AC_MSG_RESULT($blp_int_digits) ])dnl
40
41 dnl Check quality of this machine's sprintf implementation.
42
43 AC_DEFUN([BLP_IS_SPRINTF_GOOD],
44 [
45 AC_MSG_CHECKING(if sprintf returns a char count)
46 AC_CACHE_VAL(blp_is_sprintf_good,
47              [AC_TRY_RUN([#include <stdio.h>
48                           int 
49                           main()
50                           {
51                             char s[8];
52                             exit((int)sprintf(s, "abcdefg")!=7);
53                           }
54                          ], 
55                          eval "blp_is_sprintf_good=yes",
56                          eval "blp_is_sprintf_good=no",
57                          eval "blp_is_sprintf_good=no")
58              ])
59 if test "$blp_is_sprintf_good" = yes; then
60   AC_DEFINE([HAVE_GOOD_SPRINTF], 1, 
61         [Define if sprintf() returns the number of characters written
62          to the destination string, excluding the null terminator.])
63   AC_MSG_RESULT(yes)
64 else
65   AC_MSG_RESULT(no)
66 fi
67 ])dnl
68
69 dnl Check for proper random number generator.
70
71 AC_DEFUN([BLP_RANDOM],
72 [
73 AC_MSG_CHECKING(random number generator)
74 AC_CACHE_VAL(blp_random_good, 
75   AC_TRY_COMPILE([#include <stdlib.h>], [int x=RAND_MAX;], 
76     blp_random_good=yes, blp_random_good=no))
77 if test "$blp_random_good" = yes; then
78   AC_DEFINE([HAVE_GOOD_RANDOM], 1, 
79         [Define if rand() and company work according to ANSI.])
80   AC_MSG_RESULT(good)
81 else
82   AC_MSG_RESULT(bad)
83 fi
84 ])dnl
85
86 dnl Check for readline and history libraries.
87
88 dnl Modified for PSPP by Ben Pfaff, based on readline.m4 serial 3 from
89 dnl gnulib, which was written by Simon Josefsson, with help from Bruno
90 dnl Haible and Oskar Liljeblad.
91
92 AC_DEFUN([PSPP_READLINE],
93 [
94   dnl Prerequisites of AC_LIB_LINKFLAGS_BODY.
95   AC_REQUIRE([AC_LIB_PREPARE_PREFIX])
96   AC_REQUIRE([AC_LIB_RPATH])
97
98   dnl Search for libreadline and define LIBREADLINE, LTLIBREADLINE and
99   dnl INCREADLINE accordingly.
100   AC_LIB_LINKFLAGS_BODY([readline])
101   AC_LIB_LINKFLAGS_BODY([history])
102
103   dnl Add $INCREADLINE to CPPFLAGS before performing the following checks,
104   dnl because if the user has installed libreadline and not disabled its use
105   dnl via --without-libreadline-prefix, he wants to use it. The AC_TRY_LINK
106   dnl will then succeed.
107   am_save_CPPFLAGS="$CPPFLAGS"
108   AC_LIB_APPENDTOVAR([CPPFLAGS], [$INCREADLINE $INCHISTORY])
109
110   AC_CACHE_CHECK(for readline, gl_cv_lib_readline, [
111     gl_cv_lib_readline=no
112     am_save_LIBS="$LIBS"
113     dnl On some systems, -lreadline doesn't link without an additional
114     dnl -lncurses or -ltermcap.
115     dnl Try -lncurses before -ltermcap, because libtermcap is unsecure
116     dnl by design and obsolete since 1994. Try -lcurses last, because
117     dnl libcurses is unusable on some old Unices.
118     for extra_lib in "" ncurses termcap curses; do
119       LIBS="$am_save_LIBS $LIBREADLINE $LIBHISTORY"
120       if test -n "$extra_lib"; then
121         LIBS="$LIBS -l$extra_lib"
122       fi
123       AC_TRY_LINK([#include <stdio.h>
124 #include <readline/readline.h>
125 #include <readline/history.h>],
126         [readline((char*)0); add_history((char*)0);],
127         gl_cv_lib_readline=yes)
128       if test "$gl_cv_lib_readline" = yes; then
129         if test -n "$extra_lib"; then
130           LIBREADLINE="$LIBREADLINE $LIBHISTORY -l$extra_lib"
131           LTLIBREADLINE="$LTLIBREADLINE $LTLIBHISTORY -l$extra_lib"
132         fi
133         break
134       fi
135     done
136     LIBS="$am_save_LIBS"
137   ])
138
139   if test "$gl_cv_lib_readline" = yes; then
140     AC_DEFINE(HAVE_READLINE, 1, [Define if you have the readline library.])
141   fi
142
143   if test "$gl_cv_lib_readline" = yes; then
144     AC_MSG_CHECKING([how to link with libreadline])
145     AC_MSG_RESULT([$LIBREADLINE])
146   else
147     dnl If $LIBREADLINE didn't lead to a usable library, we don't
148     dnl need $INCREADLINE either.
149     CPPFLAGS="$am_save_CPPFLAGS"
150     LIBREADLINE=
151     LTLIBREADLINE=
152     LIBHISTORY=
153     LTLIBHISTORY=
154   fi
155   AC_SUBST(LIBREADLINE)
156   AC_SUBST(LTLIBREADLINE)
157 ])
158
159 dnl aclocal.m4 ends here