improve of cmpl.
[bush.git] / aclocal.m4
blob1e423c8692891b2ffa5eb86029efaf51bf2d3a2e
1 dnl
2 dnl Bush specific tests
3 dnl
4 dnl Some derived from PDKSH 5.1.3 autoconf tests
5 dnl
7 AC_DEFUN(BUSH_C_LONG_LONG,
8 [AC_CACHE_CHECK(for long long, ac_cv_c_long_long,
9 [if test "$GCC" = yes; then
10   ac_cv_c_long_long=yes
11 else
12 AC_TRY_RUN([
13 #include <stdlib.h>
14 int
15 main()
17 long long foo = 0;
18 exit(sizeof(long long) < sizeof(long));
20 ], ac_cv_c_long_long=yes, ac_cv_c_long_long=no)
21 fi])
22 if test $ac_cv_c_long_long = yes; then
23   AC_DEFINE(HAVE_LONG_LONG, 1, [Define if the `long long' type works.])
27 dnl
28 dnl This is very similar to AC_C_LONG_DOUBLE, with the fix for IRIX
29 dnl (< changed to <=) added.
30 dnl
31 AC_DEFUN(BUSH_C_LONG_DOUBLE,
32 [AC_CACHE_CHECK(for long double, ac_cv_c_long_double,
33 [if test "$GCC" = yes; then
34   ac_cv_c_long_double=yes
35 else
36 AC_TRY_RUN([
37 #include <stdlib.h>
38 int
39 main()
41   /* The Stardent Vistra knows sizeof(long double), but does not
42      support it. */
43   long double foo = 0.0;
44   /* On Ultrix 4.3 cc, long double is 4 and double is 8.  */
45   /* On IRIX 5.3, the compiler converts long double to double with a warning,
46      but compiles this successfully. */
47   exit(sizeof(long double) <= sizeof(double));
49 ], ac_cv_c_long_double=yes, ac_cv_c_long_double=no)
50 fi])
51 if test $ac_cv_c_long_double = yes; then
52   AC_DEFINE(HAVE_LONG_DOUBLE, 1, [Define if the `long double' type works.])
56 dnl
57 dnl Check for <inttypes.h>.  This is separated out so that it can be
58 dnl AC_REQUIREd.
59 dnl
60 dnl BUSH_HEADER_INTTYPES
61 AC_DEFUN(BUSH_HEADER_INTTYPES,
63  AC_CHECK_HEADERS(inttypes.h)
66 dnl
67 dnl check for typedef'd symbols in header files, but allow the caller to
68 dnl specify the include files to be checked in addition to the default
69 dnl
70 dnl This could be changed to use AC_COMPILE_IFELSE instead of AC_EGREP_CPP
71 dnl 
72 dnl BUSH_CHECK_TYPE(TYPE, HEADERS, DEFAULT[, VALUE-IF-FOUND])
73 AC_DEFUN(BUSH_CHECK_TYPE,
75 AC_REQUIRE([AC_HEADER_STDC])dnl
76 AC_REQUIRE([BUSH_HEADER_INTTYPES])
77 AC_MSG_CHECKING(for $1)
78 AC_CACHE_VAL(bush_cv_type_$1,
79 [AC_EGREP_CPP($1, [#include <sys/types.h>
80 #if STDC_HEADERS
81 #include <stdlib.h>
82 #include <stddef.h>
83 #endif
84 #if HAVE_INTTYPES_H
85 #include <inttypes.h>
86 #endif
87 #if HAVE_STDINT_H
88 #include <stdint.h>
89 #endif
91 ], bush_cv_type_$1=yes, bush_cv_type_$1=no)])
92 AC_MSG_RESULT($bush_cv_type_$1)
93 ifelse($#, 4, [if test $bush_cv_type_$1 = yes; then
94         AC_DEFINE($4)
95         fi])
96 if test $bush_cv_type_$1 = no; then
97   AC_DEFINE_UNQUOTED($1, $3)
102 dnl BUSH_CHECK_DECL(FUNC)
104 dnl Check for a declaration of FUNC in stdlib.h and inttypes.h like
105 dnl AC_CHECK_DECL
107 AC_DEFUN(BUSH_CHECK_DECL,
109 AC_REQUIRE([AC_HEADER_STDC])
110 AC_REQUIRE([BUSH_HEADER_INTTYPES])
111 AC_CACHE_CHECK([for declaration of $1], bush_cv_decl_$1,
112 [AC_TRY_LINK(
114 #if STDC_HEADERS
115 #  include <stdlib.h>
116 #endif
117 #if HAVE_INTTYPES_H
118 #  include <inttypes.h>
119 #endif
121 [return !$1;],
122 bush_cv_decl_$1=yes, bush_cv_decl_$1=no)])
123 bush_tr_func=HAVE_DECL_`echo $1 | tr 'abcdefghijklmnopqrstuvwxyz' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'`
124 if test $bush_cv_decl_$1 = yes; then
125   AC_DEFINE_UNQUOTED($bush_tr_func, 1)
126 else
127   AC_DEFINE_UNQUOTED($bush_tr_func, 0)
131 AC_DEFUN(BUSH_DECL_PRINTF,
132 [AC_MSG_CHECKING(for declaration of printf in <stdio.h>)
133 AC_CACHE_VAL(bush_cv_printf_declared,
134 [AC_TRY_RUN([
135 #include <stdio.h>
136 #ifdef __STDC__
137 typedef int (*_bushfunc)(const char *, ...);
138 #else
139 typedef int (*_bushfunc)();
140 #endif
141 #include <stdlib.h>
143 main()
145 _bushfunc pf;
146 pf = (_bushfunc) printf;
147 exit(pf == 0);
149 ], bush_cv_printf_declared=yes, bush_cv_printf_declared=no,
150    [AC_MSG_WARN(cannot check printf declaration if cross compiling -- defaulting to yes)
151     bush_cv_printf_declared=yes]
153 AC_MSG_RESULT($bush_cv_printf_declared)
154 if test $bush_cv_printf_declared = yes; then
155 AC_DEFINE(PRINTF_DECLARED)
159 AC_DEFUN(BUSH_DECL_SBRK,
160 [AC_MSG_CHECKING(for declaration of sbrk in <unistd.h>)
161 AC_CACHE_VAL(bush_cv_sbrk_declared,
162 [AC_EGREP_HEADER(sbrk, unistd.h,
163  bush_cv_sbrk_declared=yes, bush_cv_sbrk_declared=no)])
164 AC_MSG_RESULT($bush_cv_sbrk_declared)
165 if test $bush_cv_sbrk_declared = yes; then
166 AC_DEFINE(SBRK_DECLARED)
171 dnl Check for sys_siglist[] or _sys_siglist[]
173 AC_DEFUN(BUSH_DECL_UNDER_SYS_SIGLIST,
174 [AC_MSG_CHECKING([for _sys_siglist in signal.h or unistd.h])
175 AC_CACHE_VAL(bush_cv_decl_under_sys_siglist,
176 [AC_TRY_COMPILE([
177 #include <sys/types.h>
178 #include <signal.h>
179 #ifdef HAVE_UNISTD_H
180 #include <unistd.h>
181 #endif], [ char *msg = _sys_siglist[2]; ],
182   bush_cv_decl_under_sys_siglist=yes, bush_cv_decl_under_sys_siglist=no,
183   [AC_MSG_WARN(cannot check for _sys_siglist[] if cross compiling -- defaulting to no)])])dnl
184 AC_MSG_RESULT($bush_cv_decl_under_sys_siglist)
185 if test $bush_cv_decl_under_sys_siglist = yes; then
186 AC_DEFINE(UNDER_SYS_SIGLIST_DECLARED)
190 AC_DEFUN(BUSH_UNDER_SYS_SIGLIST,
191 [AC_REQUIRE([BUSH_DECL_UNDER_SYS_SIGLIST])
192 AC_MSG_CHECKING([for _sys_siglist in system C library])
193 AC_CACHE_VAL(bush_cv_under_sys_siglist,
194 [AC_TRY_RUN([
195 #include <sys/types.h>
196 #include <signal.h>
197 #ifdef HAVE_UNISTD_H
198 #include <unistd.h>
199 #endif
200 #include <stdlib.h>
201 #ifndef UNDER_SYS_SIGLIST_DECLARED
202 extern char *_sys_siglist[];
203 #endif
205 main()
207 char *msg = (char *)_sys_siglist[2];
208 exit(msg == 0);
210         bush_cv_under_sys_siglist=yes, bush_cv_under_sys_siglist=no,
211         [AC_MSG_WARN(cannot check for _sys_siglist[] if cross compiling -- defaulting to no)
212          bush_cv_under_sys_siglist=no])])
213 AC_MSG_RESULT($bush_cv_under_sys_siglist)
214 if test $bush_cv_under_sys_siglist = yes; then
215 AC_DEFINE(HAVE_UNDER_SYS_SIGLIST)
219 AC_DEFUN(BUSH_SYS_SIGLIST,
220 [AC_REQUIRE([AC_DECL_SYS_SIGLIST])
221 AC_MSG_CHECKING([for sys_siglist in system C library])
222 AC_CACHE_VAL(bush_cv_sys_siglist,
223 [AC_TRY_RUN([
224 #include <sys/types.h>
225 #include <signal.h>
226 #ifdef HAVE_UNISTD_H
227 #include <unistd.h>
228 #endif
229 #include <stdlib.h>
230 #if !HAVE_DECL_SYS_SIGLIST
231 extern char *sys_siglist[];
232 #endif
234 main()
236 char *msg = sys_siglist[2];
237 exit(msg == 0);
239         bush_cv_sys_siglist=yes, bush_cv_sys_siglist=no,
240         [AC_MSG_WARN(cannot check for sys_siglist if cross compiling -- defaulting to no)
241          bush_cv_sys_siglist=no])])
242 AC_MSG_RESULT($bush_cv_sys_siglist)
243 if test $bush_cv_sys_siglist = yes; then
244 AC_DEFINE(HAVE_SYS_SIGLIST)
248 dnl Check for the various permutations of sys_siglist and make sure we
249 dnl compile in siglist.o if they're not defined
250 AC_DEFUN(BUSH_CHECK_SYS_SIGLIST, [
251 AC_REQUIRE([BUSH_SYS_SIGLIST])
252 AC_REQUIRE([BUSH_DECL_UNDER_SYS_SIGLIST])
253 AC_REQUIRE([BUSH_FUNC_STRSIGNAL])
254 if test "$bush_cv_sys_siglist" = no && test "$bush_cv_under_sys_siglist" = no && test "$bush_cv_have_strsignal" = no; then
255   SIGLIST_O=siglist.o
256 else
257   SIGLIST_O=
259 AC_SUBST([SIGLIST_O])
262 dnl Check for sys_errlist[] and sys_nerr, check for declaration
263 AC_DEFUN(BUSH_SYS_ERRLIST,
264 [AC_MSG_CHECKING([for sys_errlist and sys_nerr])
265 AC_CACHE_VAL(bush_cv_sys_errlist,
266 [AC_TRY_LINK([#include <errno.h>],
267 [extern char *sys_errlist[];
268  extern int sys_nerr;
269  char *msg = sys_errlist[sys_nerr - 1];],
270     bush_cv_sys_errlist=yes, bush_cv_sys_errlist=no)])dnl
271 AC_MSG_RESULT($bush_cv_sys_errlist)
272 if test $bush_cv_sys_errlist = yes; then
273 AC_DEFINE(HAVE_SYS_ERRLIST)
278 dnl Check if dup2() does not clear the close on exec flag
280 AC_DEFUN(BUSH_FUNC_DUP2_CLOEXEC_CHECK,
281 [AC_MSG_CHECKING(if dup2 fails to clear the close-on-exec flag)
282 AC_CACHE_VAL(bush_cv_dup2_broken,
283 [AC_TRY_RUN([
284 #include <sys/types.h>
285 #include <fcntl.h>
286 #include <stdlib.h>
288 main()
290   int fd1, fd2, fl;
291   fd1 = open("/dev/null", 2);
292   if (fcntl(fd1, 2, 1) < 0)
293     exit(1);
294   fd2 = dup2(fd1, 1);
295   if (fd2 < 0)
296     exit(2);
297   fl = fcntl(fd2, 1, 0);
298   /* fl will be 1 if dup2 did not reset the close-on-exec flag. */
299   exit(fl != 1);
301 ], bush_cv_dup2_broken=yes, bush_cv_dup2_broken=no,
302     [AC_MSG_WARN(cannot check dup2 if cross compiling -- defaulting to no)
303      bush_cv_dup2_broken=no])
305 AC_MSG_RESULT($bush_cv_dup2_broken)
306 if test $bush_cv_dup2_broken = yes; then
307 AC_DEFINE(DUP2_BROKEN)
311 AC_DEFUN(BUSH_FUNC_STRSIGNAL,
312 [AC_MSG_CHECKING([for the existence of strsignal])
313 AC_CACHE_VAL(bush_cv_have_strsignal,
314 [AC_TRY_LINK([#include <sys/types.h>
315 #include <signal.h>
316 #include <string.h>],
317 [char *s = (char *)strsignal(2);],
318  bush_cv_have_strsignal=yes, bush_cv_have_strsignal=no)])
319 AC_MSG_RESULT($bush_cv_have_strsignal)
320 if test $bush_cv_have_strsignal = yes; then
321 AC_DEFINE(HAVE_STRSIGNAL)
325 dnl Check to see if opendir will open non-directories (not a nice thing)
326 AC_DEFUN(BUSH_FUNC_OPENDIR_CHECK,
327 [AC_REQUIRE([AC_HEADER_DIRENT])dnl
328 AC_MSG_CHECKING(if opendir() opens non-directories)
329 AC_CACHE_VAL(bush_cv_opendir_not_robust,
330 [AC_TRY_RUN([
331 #include <stdio.h>
332 #include <sys/types.h>
333 #include <fcntl.h>
334 #ifdef HAVE_UNISTD_H
335 # include <unistd.h>
336 #endif /* HAVE_UNISTD_H */
337 #ifdef HAVE_SYS_STAT_H
338 #include <sys/stat.h>
339 #endif
340 #if defined(HAVE_DIRENT_H)
341 # include <dirent.h>
342 #else
343 # define dirent direct
344 # ifdef HAVE_SYS_NDIR_H
345 #  include <sys/ndir.h>
346 # endif /* SYSNDIR */
347 # ifdef HAVE_SYS_DIR_H
348 #  include <sys/dir.h>
349 # endif /* SYSDIR */
350 # ifdef HAVE_NDIR_H
351 #  include <ndir.h>
352 # endif
353 #endif /* HAVE_DIRENT_H */
354 #include <stdlib.h>
356 main()
358 DIR *dir;
359 int fd, err;
360 err = mkdir("bush-aclocal", 0700);
361 if (err < 0) {
362   perror("mkdir");
363   exit(1);
365 unlink("bush-aclocal/not_a_directory");
366 fd = open("bush-aclocal/not_a_directory", O_WRONLY|O_CREAT|O_EXCL, 0666);
367 write(fd, "\n", 1);
368 close(fd);
369 dir = opendir("bush-aclocal/not_a_directory");
370 unlink("bush-aclocal/not_a_directory");
371 rmdir("bush-aclocal");
372 exit (dir == 0);
373 }], bush_cv_opendir_not_robust=yes,bush_cv_opendir_not_robust=no,
374     [AC_MSG_WARN(cannot check opendir if cross compiling -- defaulting to no)
375      bush_cv_opendir_not_robust=no]
377 AC_MSG_RESULT($bush_cv_opendir_not_robust)
378 if test $bush_cv_opendir_not_robust = yes; then
379 AC_DEFINE(OPENDIR_NOT_ROBUST)
384 AC_DEFUN(BUSH_TYPE_SIGHANDLER,
385 [AC_MSG_CHECKING([whether signal handlers are of type void])
386 AC_CACHE_VAL(bush_cv_void_sighandler,
387 [AC_TRY_COMPILE([#include <sys/types.h>
388 #include <signal.h>
389 #ifdef signal
390 #undef signal
391 #endif
392 #ifdef __cplusplus
393 extern "C"
394 #endif
395 void (*signal ()) ();],
396 [int i;], bush_cv_void_sighandler=yes, bush_cv_void_sighandler=no)])dnl
397 AC_MSG_RESULT($bush_cv_void_sighandler)
398 if test $bush_cv_void_sighandler = yes; then
399 AC_DEFINE(VOID_SIGHANDLER)
404 dnl A signed 16-bit integer quantity
406 AC_DEFUN(BUSH_TYPE_BITS16_T,
408 if test "$ac_cv_sizeof_short" = 2; then
409   AC_CHECK_TYPE(bits16_t, short)
410 elif test "$ac_cv_sizeof_char" = 2; then
411   AC_CHECK_TYPE(bits16_t, char)
412 else
413   AC_CHECK_TYPE(bits16_t, short)
418 dnl An unsigned 16-bit integer quantity
420 AC_DEFUN(BUSH_TYPE_U_BITS16_T,
422 if test "$ac_cv_sizeof_short" = 2; then
423   AC_CHECK_TYPE(u_bits16_t, unsigned short)
424 elif test "$ac_cv_sizeof_char" = 2; then
425   AC_CHECK_TYPE(u_bits16_t, unsigned char)
426 else
427   AC_CHECK_TYPE(u_bits16_t, unsigned short)
432 dnl A signed 32-bit integer quantity
434 AC_DEFUN(BUSH_TYPE_BITS32_T,
436 if test "$ac_cv_sizeof_int" = 4; then
437   AC_CHECK_TYPE(bits32_t, int)
438 elif test "$ac_cv_sizeof_long" = 4; then
439   AC_CHECK_TYPE(bits32_t, long)
440 else
441   AC_CHECK_TYPE(bits32_t, int)
446 dnl An unsigned 32-bit integer quantity
448 AC_DEFUN(BUSH_TYPE_U_BITS32_T,
450 if test "$ac_cv_sizeof_int" = 4; then
451   AC_CHECK_TYPE(u_bits32_t, unsigned int)
452 elif test "$ac_cv_sizeof_long" = 4; then
453   AC_CHECK_TYPE(u_bits32_t, unsigned long)
454 else
455   AC_CHECK_TYPE(u_bits32_t, unsigned int)
459 AC_DEFUN(BUSH_TYPE_PTRDIFF_T,
461 if test "$ac_cv_sizeof_int" = "$ac_cv_sizeof_char_p"; then
462   AC_CHECK_TYPE(ptrdiff_t, int)
463 elif test "$ac_cv_sizeof_long" = "$ac_cv_sizeof_char_p"; then
464   AC_CHECK_TYPE(ptrdiff_t, long)
465 elif test "$ac_cv_type_long_long" = yes && test "$ac_cv_sizeof_long_long" = "$ac_cv_sizeof_char_p"; then
466   AC_CHECK_TYPE(ptrdiff_t, [long long])
467 else
468   AC_CHECK_TYPE(ptrdiff_t, int)
473 dnl A signed 64-bit quantity
475 AC_DEFUN(BUSH_TYPE_BITS64_T,
477 if test "$ac_cv_sizeof_char_p" = 8; then
478   AC_CHECK_TYPE(bits64_t, char *)
479 elif test "$ac_cv_sizeof_double" = 8; then
480   AC_CHECK_TYPE(bits64_t, double)
481 elif test -n "$ac_cv_type_long_long" && test "$ac_cv_sizeof_long_long" = 8; then
482   AC_CHECK_TYPE(bits64_t, [long long])
483 elif test "$ac_cv_sizeof_long" = 8; then
484   AC_CHECK_TYPE(bits64_t, long)
485 else
486   AC_CHECK_TYPE(bits64_t, double)
490 AC_DEFUN(BUSH_TYPE_LONG_LONG,
492 AC_CACHE_CHECK([for long long], bush_cv_type_long_long,
493 [AC_TRY_LINK([
494 long long ll = 1; int i = 63;],
496 long long llm = (long long) -1;
497 return ll << i | ll >> i | llm / ll | llm % ll;
498 ], bush_cv_type_long_long='long long', bush_cv_type_long_long='long')])
499 if test "$bush_cv_type_long_long" = 'long long'; then
500   AC_DEFINE(HAVE_LONG_LONG, 1)
504 AC_DEFUN(BUSH_TYPE_UNSIGNED_LONG_LONG,
506 AC_CACHE_CHECK([for unsigned long long], bush_cv_type_unsigned_long_long,
507 [AC_TRY_LINK([
508 unsigned long long ull = 1; int i = 63;],
510 unsigned long long ullmax = (unsigned long long) -1;
511 return ull << i | ull >> i | ullmax / ull | ullmax % ull;
512 ], bush_cv_type_unsigned_long_long='unsigned long long',
513    bush_cv_type_unsigned_long_long='unsigned long')])
514 if test "$bush_cv_type_unsigned_long_long" = 'unsigned long long'; then
515   AC_DEFINE(HAVE_UNSIGNED_LONG_LONG, 1)
520 dnl Type of struct rlimit fields: some systems (OSF/1, NetBSD, RISC/os 5.0)
521 dnl have a rlim_t, others (4.4BSD based systems) use quad_t, others use
522 dnl long and still others use int (HP-UX 9.01, SunOS 4.1.3).  To simplify
523 dnl matters, this just checks for rlim_t, quad_t, or long.
525 AC_DEFUN(BUSH_TYPE_RLIMIT,
526 [AC_MSG_CHECKING(for size and type of struct rlimit fields)
527 AC_CACHE_VAL(bush_cv_type_rlimit,
528 [AC_TRY_COMPILE([#include <sys/types.h>
529 #include <sys/resource.h>],
530 [rlim_t xxx;], bush_cv_type_rlimit=rlim_t,[
531 AC_TRY_RUN([
532 #include <sys/types.h>
533 #include <sys/time.h>
534 #include <sys/resource.h>
535 #include <stdlib.h>
537 main()
539 #ifdef HAVE_QUAD_T
540   struct rlimit rl;
541   if (sizeof(rl.rlim_cur) == sizeof(quad_t))
542     exit(0);
543 #endif
544   exit(1);
545 }], bush_cv_type_rlimit=quad_t, bush_cv_type_rlimit=long,
546         [AC_MSG_WARN(cannot check quad_t if cross compiling -- defaulting to long)
547          bush_cv_type_rlimit=long])])
549 AC_MSG_RESULT($bush_cv_type_rlimit)
550 if test $bush_cv_type_rlimit = quad_t; then
551 AC_DEFINE(RLIMTYPE, quad_t)
552 elif test $bush_cv_type_rlimit = rlim_t; then
553 AC_DEFINE(RLIMTYPE, rlim_t)
557 AC_DEFUN(BUSH_TYPE_SIG_ATOMIC_T,
558 [AC_CACHE_CHECK([for sig_atomic_t in signal.h], ac_cv_have_sig_atomic_t,
559 [AC_TRY_LINK([
560 #include <signal.h>
561 ],[ sig_atomic_t x; ],
562 ac_cv_have_sig_atomic_t=yes, ac_cv_have_sig_atomic_t=no)])
563 if test "$ac_cv_have_sig_atomic_t" = "no"
564 then
565     AC_CHECK_TYPE(sig_atomic_t,int)
569 AC_DEFUN(BUSH_FUNC_LSTAT,
570 [dnl Cannot use AC_CHECK_FUNCS(lstat) because Linux defines lstat() as an
571 dnl inline function in <sys/stat.h>.
572 AC_CACHE_CHECK([for lstat], bush_cv_func_lstat,
573 [AC_TRY_LINK([
574 #include <sys/types.h>
575 #include <sys/stat.h>
576 ],[ lstat(".",(struct stat *)0); ],
577 bush_cv_func_lstat=yes, bush_cv_func_lstat=no)])
578 if test $bush_cv_func_lstat = yes; then
579   AC_DEFINE(HAVE_LSTAT)
583 AC_DEFUN(BUSH_FUNC_INET_ATON,
585 AC_CACHE_CHECK([for inet_aton], bush_cv_func_inet_aton,
586 [AC_TRY_LINK([
587 #include <sys/types.h>
588 #include <netinet/in.h>
589 #include <arpa/inet.h>
590 struct in_addr ap;], [ inet_aton("127.0.0.1", &ap); ],
591 bush_cv_func_inet_aton=yes, bush_cv_func_inet_aton=no)])
592 if test $bush_cv_func_inet_aton = yes; then
593   AC_DEFINE(HAVE_INET_ATON)
594 else
595   AC_LIBOBJ(inet_aton)
599 AC_DEFUN(BUSH_FUNC_GETENV,
600 [AC_MSG_CHECKING(to see if getenv can be redefined)
601 AC_CACHE_VAL(bush_cv_getenv_redef,
602 [AC_TRY_RUN([
603 #ifdef HAVE_UNISTD_H
604 #  include <unistd.h>
605 #endif
606 #include <stdlib.h>
607 #ifndef __STDC__
608 #  ifndef const
609 #    define const
610 #  endif
611 #endif
612 char *
613 getenv (name)
614 #if defined (__linux__) || defined (__bsdi__) || defined (convex)
615      const char *name;
616 #else
617      char const *name;
618 #endif /* !__linux__ && !__bsdi__ && !convex */
620 return "42";
623 main()
625 char *s;
626 /* The next allows this program to run, but does not allow bush to link
627    when it redefines getenv.  I'm not really interested in figuring out
628    why not. */
629 #if defined (NeXT)
630 exit(1);
631 #endif
632 s = getenv("ABCDE");
633 exit(s == 0);   /* force optimizer to leave getenv in */
635 ], bush_cv_getenv_redef=yes, bush_cv_getenv_redef=no,
636    [AC_MSG_WARN(cannot check getenv redefinition if cross compiling -- defaulting to yes)
637     bush_cv_getenv_redef=yes]
639 AC_MSG_RESULT($bush_cv_getenv_redef)
640 if test $bush_cv_getenv_redef = yes; then
641 AC_DEFINE(CAN_REDEFINE_GETENV)
645 # We should check for putenv before calling this
646 AC_DEFUN(BUSH_FUNC_STD_PUTENV,
648 AC_REQUIRE([AC_HEADER_STDC])
649 AC_REQUIRE([AC_C_PROTOTYPES])
650 AC_CACHE_CHECK([for standard-conformant putenv declaration], bush_cv_std_putenv,
651 [AC_TRY_LINK([
652 #if STDC_HEADERS
653 #include <stdlib.h>
654 #include <stddef.h>
655 #endif
656 #ifndef __STDC__
657 #  ifndef const
658 #    define const
659 #  endif
660 #endif
661 #ifdef PROTOTYPES
662 extern int putenv (char *);
663 #else
664 extern int putenv ();
665 #endif
667 [return (putenv == 0);],
668 bush_cv_std_putenv=yes, bush_cv_std_putenv=no
670 if test $bush_cv_std_putenv = yes; then
671 AC_DEFINE(HAVE_STD_PUTENV)
675 # We should check for unsetenv before calling this
676 AC_DEFUN(BUSH_FUNC_STD_UNSETENV,
678 AC_REQUIRE([AC_HEADER_STDC])
679 AC_REQUIRE([AC_C_PROTOTYPES])
680 AC_CACHE_CHECK([for standard-conformant unsetenv declaration], bush_cv_std_unsetenv,
681 [AC_TRY_LINK([
682 #if STDC_HEADERS
683 #include <stdlib.h>
684 #include <stddef.h>
685 #endif
686 #ifndef __STDC__
687 #  ifndef const
688 #    define const
689 #  endif
690 #endif
691 #ifdef PROTOTYPES
692 extern int unsetenv (const char *);
693 #else
694 extern int unsetenv ();
695 #endif
697 [return (unsetenv == 0);],
698 bush_cv_std_unsetenv=yes, bush_cv_std_unsetenv=no
700 if test $bush_cv_std_unsetenv = yes; then
701 AC_DEFINE(HAVE_STD_UNSETENV)
705 AC_DEFUN(BUSH_FUNC_ULIMIT_MAXFDS,
706 [AC_MSG_CHECKING(whether ulimit can substitute for getdtablesize)
707 AC_CACHE_VAL(bush_cv_ulimit_maxfds,
708 [AC_TRY_RUN([
709 #include <stdlib.h>
710 #ifdef HAVE_ULIMIT_H
711 #include <ulimit.h>
712 #endif
714 main()
716 long maxfds = ulimit(4, 0L);
717 exit (maxfds == -1L);
719 ], bush_cv_ulimit_maxfds=yes, bush_cv_ulimit_maxfds=no,
720    [AC_MSG_WARN(cannot check ulimit if cross compiling -- defaulting to no)
721     bush_cv_ulimit_maxfds=no]
723 AC_MSG_RESULT($bush_cv_ulimit_maxfds)
724 if test $bush_cv_ulimit_maxfds = yes; then
725 AC_DEFINE(ULIMIT_MAXFDS)
729 AC_DEFUN(BUSH_FUNC_GETCWD,
730 [AC_MSG_CHECKING([if getcwd() will dynamically allocate memory with 0 size])
731 AC_CACHE_VAL(bush_cv_getcwd_malloc,
732 [AC_TRY_RUN([
733 #include <stdio.h>
734 #ifdef HAVE_UNISTD_H
735 #include <unistd.h>
736 #endif
737 #include <stdlib.h>
740 main()
742         char    *xpwd;
743         xpwd = getcwd(0, 0);
744         exit (xpwd == 0);
746 ], bush_cv_getcwd_malloc=yes, bush_cv_getcwd_malloc=no,
747    [AC_MSG_WARN(cannot check whether getcwd allocates memory when cross-compiling -- defaulting to no)
748     bush_cv_getcwd_malloc=no]
750 AC_MSG_RESULT($bush_cv_getcwd_malloc)
751 if test $bush_cv_getcwd_malloc = no; then
752 AC_DEFINE(GETCWD_BROKEN)
753 AC_LIBOBJ(getcwd)
758 dnl This needs BUSH_CHECK_SOCKLIB, but since that's not called on every
759 dnl system, we can't use AC_PREREQ
761 AC_DEFUN(BUSH_FUNC_GETHOSTBYNAME,
762 [if test "X$bush_cv_have_gethostbyname" = "X"; then
763 _bush_needmsg=yes
764 else
765 AC_MSG_CHECKING(for gethostbyname in socket library)
766 _bush_needmsg=
768 AC_CACHE_VAL(bush_cv_have_gethostbyname,
769 [AC_TRY_LINK([#include <netdb.h>],
770 [ struct hostent *hp;
771   hp = gethostbyname("localhost");
772 ], bush_cv_have_gethostbyname=yes, bush_cv_have_gethostbyname=no)]
774 if test "X$_bush_needmsg" = Xyes; then
775     AC_MSG_CHECKING(for gethostbyname in socket library)
777 AC_MSG_RESULT($bush_cv_have_gethostbyname)
778 if test "$bush_cv_have_gethostbyname" = yes; then
779 AC_DEFINE(HAVE_GETHOSTBYNAME)
783 AC_DEFUN(BUSH_FUNC_FNMATCH_EXTMATCH,
784 [AC_MSG_CHECKING(if fnmatch does extended pattern matching with FNM_EXTMATCH)
785 AC_CACHE_VAL(bush_cv_fnm_extmatch,
786 [AC_TRY_RUN([
787 #include <fnmatch.h>
790 main()
792 #ifdef FNM_EXTMATCH
793   return (0);
794 #else
795   return (1);
796 #endif
798 ], bush_cv_fnm_extmatch=yes, bush_cv_fnm_extmatch=no,
799     [AC_MSG_WARN(cannot check FNM_EXTMATCH if cross compiling -- defaulting to no)
800      bush_cv_fnm_extmatch=no])
802 AC_MSG_RESULT($bush_cv_fnm_extmatch)
803 if test $bush_cv_fnm_extmatch = yes; then
804 AC_DEFINE(HAVE_LIBC_FNM_EXTMATCH)
808 AC_DEFUN(BUSH_FUNC_POSIX_SETJMP,
809 [AC_REQUIRE([BUSH_SYS_SIGNAL_VINTAGE])
810 AC_MSG_CHECKING(for presence of POSIX-style sigsetjmp/siglongjmp)
811 AC_CACHE_VAL(bush_cv_func_sigsetjmp,
812 [AC_TRY_RUN([
813 #ifdef HAVE_UNISTD_H
814 #include <unistd.h>
815 #endif
816 #include <sys/types.h>
817 #include <signal.h>
818 #include <setjmp.h>
819 #include <stdlib.h>
822 main()
824 #if !defined (_POSIX_VERSION) || !defined (HAVE_POSIX_SIGNALS)
825 exit (1);
826 #else
828 int code;
829 sigset_t set, oset;
830 sigjmp_buf xx;
832 /* get the mask */
833 sigemptyset(&set);
834 sigemptyset(&oset);
835 sigprocmask(SIG_BLOCK, (sigset_t *)NULL, &set);
836 sigprocmask(SIG_BLOCK, (sigset_t *)NULL, &oset);
838 /* save it */
839 code = sigsetjmp(xx, 1);
840 if (code)
841   exit(0);      /* could get sigmask and compare to oset here. */
843 /* change it */
844 sigaddset(&set, SIGINT);
845 sigprocmask(SIG_BLOCK, &set, (sigset_t *)NULL);
847 /* and siglongjmp */
848 siglongjmp(xx, 10);
849 exit(1);
850 #endif
851 }], bush_cv_func_sigsetjmp=present, bush_cv_func_sigsetjmp=missing,
852     [AC_MSG_WARN(cannot check for sigsetjmp/siglongjmp if cross-compiling -- defaulting to missing)
853      bush_cv_func_sigsetjmp=missing]
855 AC_MSG_RESULT($bush_cv_func_sigsetjmp)
856 if test $bush_cv_func_sigsetjmp = present; then
857 AC_DEFINE(HAVE_POSIX_SIGSETJMP)
861 AC_DEFUN(BUSH_FUNC_STRCOLL,
863 AC_MSG_CHECKING(whether or not strcoll and strcmp differ)
864 AC_CACHE_VAL(bush_cv_func_strcoll_broken,
865 [AC_TRY_RUN([
866 #include <stdio.h>
867 #if defined (HAVE_LOCALE_H)
868 #include <locale.h>
869 #endif
870 #include <string.h>
871 #include <stdlib.h>
874 main(c, v)
875 int     c;
876 char    *v[];
878         int     r1, r2;
879         char    *deflocale, *defcoll;
881 #ifdef HAVE_SETLOCALE
882         deflocale = setlocale(LC_ALL, "");
883         defcoll = setlocale(LC_COLLATE, "");
884 #endif
886 #ifdef HAVE_STRCOLL
887         /* These two values are taken from tests/glob-test. */
888         r1 = strcoll("abd", "aXd");
889 #else
890         r1 = 0;
891 #endif
892         r2 = strcmp("abd", "aXd");
894         /* These two should both be greater than 0.  It is permissible for
895            a system to return different values, as long as the sign is the
896            same. */
898         /* Exit with 1 (failure) if these two values are both > 0, since
899            this tests whether strcoll(3) is broken with respect to strcmp(3)
900            in the default locale. */
901         exit (r1 > 0 && r2 > 0);
903 ], bush_cv_func_strcoll_broken=yes, bush_cv_func_strcoll_broken=no,
904    [AC_MSG_WARN(cannot check strcoll if cross compiling -- defaulting to no)
905     bush_cv_func_strcoll_broken=no]
907 AC_MSG_RESULT($bush_cv_func_strcoll_broken)
908 if test $bush_cv_func_strcoll_broken = yes; then
909 AC_DEFINE(STRCOLL_BROKEN)
913 AC_DEFUN(BUSH_FUNC_PRINTF_A_FORMAT,
914 [AC_MSG_CHECKING([for printf floating point output in hex notation])
915 AC_CACHE_VAL(bush_cv_printf_a_format,
916 [AC_TRY_RUN([
917 #include <stdio.h>
918 #include <string.h>
919 #include <stdlib.h>
922 main()
924         double y = 0.0;
925         char abuf[1024];
927         sprintf(abuf, "%A", y);
928         exit(strchr(abuf, 'P') == (char *)0);
930 ], bush_cv_printf_a_format=yes, bush_cv_printf_a_format=no,
931    [AC_MSG_WARN(cannot check printf if cross compiling -- defaulting to no)
932     bush_cv_printf_a_format=no]
934 AC_MSG_RESULT($bush_cv_printf_a_format)
935 if test $bush_cv_printf_a_format = yes; then
936 AC_DEFINE(HAVE_PRINTF_A_FORMAT)
940 AC_DEFUN(BUSH_STRUCT_TERMIOS_LDISC,
942 AC_CHECK_MEMBER(struct termios.c_line, AC_DEFINE(TERMIOS_LDISC), ,[
943 #include <sys/types.h>
944 #include <termios.h>
948 AC_DEFUN(BUSH_STRUCT_TERMIO_LDISC,
950 AC_CHECK_MEMBER(struct termio.c_line, AC_DEFINE(TERMIO_LDISC), ,[
951 #include <sys/types.h>
952 #include <termio.h>
957 dnl Like AC_STRUCT_ST_BLOCKS, but doesn't muck with LIBOBJS
959 dnl sets bush_cv_struct_stat_st_blocks
961 dnl unused for now; we'll see how AC_CHECK_MEMBERS works
963 AC_DEFUN(BUSH_STRUCT_ST_BLOCKS,
965 AC_MSG_CHECKING([for struct stat.st_blocks])
966 AC_CACHE_VAL(bush_cv_struct_stat_st_blocks,
967 [AC_TRY_COMPILE(
969 #include <sys/types.h>
970 #include <sys/stat.h>
974 main()
976 static struct stat a;
977 if (a.st_blocks) return 0;
978 return 0;
980 ], bush_cv_struct_stat_st_blocks=yes, bush_cv_struct_stat_st_blocks=no)
982 AC_MSG_RESULT($bush_cv_struct_stat_st_blocks)
983 if test "$bush_cv_struct_stat_st_blocks" = "yes"; then
984 AC_DEFINE(HAVE_STRUCT_STAT_ST_BLOCKS)
988 AC_DEFUN([BUSH_CHECK_LIB_TERMCAP],
990 if test "X$bush_cv_termcap_lib" = "X"; then
991 _bush_needmsg=yes
992 else
993 AC_MSG_CHECKING(which library has the termcap functions)
994 _bush_needmsg=
996 AC_CACHE_VAL(bush_cv_termcap_lib,
997 [AC_CHECK_FUNC(tgetent, bush_cv_termcap_lib=libc,
998   [AC_CHECK_LIB(termcap, tgetent, bush_cv_termcap_lib=libtermcap,
999     [AC_CHECK_LIB(tinfo, tgetent, bush_cv_termcap_lib=libtinfo,
1000         [AC_CHECK_LIB(curses, tgetent, bush_cv_termcap_lib=libcurses,
1001             [AC_CHECK_LIB(ncurses, tgetent, bush_cv_termcap_lib=libncurses,
1002                 [AC_CHECK_LIB(ncursesw, tgetent, bush_cv_termcap_lib=libncursesw,
1003                     bush_cv_termcap_lib=gnutermcap)])])])])])])
1004 if test "X$_bush_needmsg" = "Xyes"; then
1005 AC_MSG_CHECKING(which library has the termcap functions)
1007 AC_MSG_RESULT(using $bush_cv_termcap_lib)
1008 if test $bush_cv_termcap_lib = gnutermcap && test -z "$prefer_curses"; then
1009 LDFLAGS="$LDFLAGS -L./lib/termcap"
1010 TERMCAP_LIB="./lib/termcap/libtermcap.a"
1011 TERMCAP_DEP="./lib/termcap/libtermcap.a"
1012 elif test $bush_cv_termcap_lib = libtermcap && test -z "$prefer_curses"; then
1013 TERMCAP_LIB=-ltermcap
1014 TERMCAP_DEP=
1015 elif test $bush_cv_termcap_lib = libtinfo; then
1016 TERMCAP_LIB=-ltinfo
1017 TERMCAP_DEP=
1018 elif test $bush_cv_termcap_lib = libncurses; then
1019 TERMCAP_LIB=-lncurses
1020 TERMCAP_DEP=
1021 elif test $bush_cv_termcap_lib = libc; then
1022 TERMCAP_LIB=
1023 TERMCAP_DEP=
1024 else
1025 TERMCAP_LIB=-lcurses
1026 TERMCAP_DEP=
1031 dnl Check for the presence of getpeername in libsocket.
1032 dnl If libsocket is present, check for libnsl and add it to LIBS if
1033 dnl it's there, since most systems with libsocket require linking
1034 dnl with libnsl as well.  This should only be called if getpeername
1035 dnl was not found in libc.
1037 dnl NOTE: IF WE FIND GETPEERNAME, WE ASSUME THAT WE HAVE BIND/CONNECT
1038 dnl       AS WELL
1040 AC_DEFUN(BUSH_CHECK_LIB_SOCKET,
1042 if test "X$bush_cv_have_socklib" = "X"; then
1043 _bush_needmsg=
1044 else
1045 AC_MSG_CHECKING(for socket library)
1046 _bush_needmsg=yes
1048 AC_CACHE_VAL(bush_cv_have_socklib,
1049 [AC_CHECK_LIB(socket, getpeername,
1050         bush_cv_have_socklib=yes, bush_cv_have_socklib=no, -lnsl)])
1051 if test "X$_bush_needmsg" = Xyes; then
1052   AC_MSG_RESULT($bush_cv_have_socklib)
1053   _bush_needmsg=
1055 if test $bush_cv_have_socklib = yes; then
1056   # check for libnsl, add it to LIBS if present
1057   if test "X$bush_cv_have_libnsl" = "X"; then
1058     _bush_needmsg=
1059   else
1060     AC_MSG_CHECKING(for libnsl)
1061     _bush_needmsg=yes
1062   fi
1063   AC_CACHE_VAL(bush_cv_have_libnsl,
1064            [AC_CHECK_LIB(nsl, t_open,
1065                  bush_cv_have_libnsl=yes, bush_cv_have_libnsl=no)])
1066   if test "X$_bush_needmsg" = Xyes; then
1067     AC_MSG_RESULT($bush_cv_have_libnsl)
1068     _bush_needmsg=
1069   fi
1070   if test $bush_cv_have_libnsl = yes; then
1071     LIBS="-lsocket -lnsl $LIBS"
1072   else
1073     LIBS="-lsocket $LIBS"
1074   fi
1075   AC_DEFINE(HAVE_LIBSOCKET)
1076   AC_DEFINE(HAVE_GETPEERNAME)
1080 AC_DEFUN(BUSH_STRUCT_DIRENT_D_INO,
1081 [AC_REQUIRE([AC_HEADER_DIRENT])
1082 AC_MSG_CHECKING(for struct dirent.d_ino)
1083 AC_CACHE_VAL(bush_cv_dirent_has_dino,
1084 [AC_TRY_COMPILE([
1085 #include <stdio.h>
1086 #include <sys/types.h>
1087 #ifdef HAVE_UNISTD_H
1088 # include <unistd.h>
1089 #endif /* HAVE_UNISTD_H */
1090 #if defined(HAVE_DIRENT_H)
1091 # include <dirent.h>
1092 #else
1093 # define dirent direct
1094 # ifdef HAVE_SYS_NDIR_H
1095 #  include <sys/ndir.h>
1096 # endif /* SYSNDIR */
1097 # ifdef HAVE_SYS_DIR_H
1098 #  include <sys/dir.h>
1099 # endif /* SYSDIR */
1100 # ifdef HAVE_NDIR_H
1101 #  include <ndir.h>
1102 # endif
1103 #endif /* HAVE_DIRENT_H */
1105 struct dirent d; int z; z = d.d_ino;
1106 ], bush_cv_dirent_has_dino=yes, bush_cv_dirent_has_dino=no)])
1107 AC_MSG_RESULT($bush_cv_dirent_has_dino)
1108 if test $bush_cv_dirent_has_dino = yes; then
1109 AC_DEFINE(HAVE_STRUCT_DIRENT_D_INO)
1113 AC_DEFUN(BUSH_STRUCT_DIRENT_D_FILENO,
1114 [AC_REQUIRE([AC_HEADER_DIRENT])
1115 AC_MSG_CHECKING(for struct dirent.d_fileno)
1116 AC_CACHE_VAL(bush_cv_dirent_has_d_fileno,
1117 [AC_TRY_COMPILE([
1118 #include <stdio.h>
1119 #include <sys/types.h>
1120 #ifdef HAVE_UNISTD_H
1121 # include <unistd.h>
1122 #endif /* HAVE_UNISTD_H */
1123 #if defined(HAVE_DIRENT_H)
1124 # include <dirent.h>
1125 #else
1126 # define dirent direct
1127 # ifdef HAVE_SYS_NDIR_H
1128 #  include <sys/ndir.h>
1129 # endif /* SYSNDIR */
1130 # ifdef HAVE_SYS_DIR_H
1131 #  include <sys/dir.h>
1132 # endif /* SYSDIR */
1133 # ifdef HAVE_NDIR_H
1134 #  include <ndir.h>
1135 # endif
1136 #endif /* HAVE_DIRENT_H */
1138 struct dirent d; int z; z = d.d_fileno;
1139 ], bush_cv_dirent_has_d_fileno=yes, bush_cv_dirent_has_d_fileno=no)])
1140 AC_MSG_RESULT($bush_cv_dirent_has_d_fileno)
1141 if test $bush_cv_dirent_has_d_fileno = yes; then
1142 AC_DEFINE(HAVE_STRUCT_DIRENT_D_FILENO)
1146 AC_DEFUN(BUSH_STRUCT_DIRENT_D_NAMLEN,
1147 [AC_REQUIRE([AC_HEADER_DIRENT])
1148 AC_MSG_CHECKING(for struct dirent.d_namlen)
1149 AC_CACHE_VAL(bush_cv_dirent_has_d_namlen,
1150 [AC_TRY_COMPILE([
1151 #include <stdio.h>
1152 #include <sys/types.h>
1153 #ifdef HAVE_UNISTD_H
1154 # include <unistd.h>
1155 #endif /* HAVE_UNISTD_H */
1156 #if defined(HAVE_DIRENT_H)
1157 # include <dirent.h>
1158 #else
1159 # define dirent direct
1160 # ifdef HAVE_SYS_NDIR_H
1161 #  include <sys/ndir.h>
1162 # endif /* SYSNDIR */
1163 # ifdef HAVE_SYS_DIR_H
1164 #  include <sys/dir.h>
1165 # endif /* SYSDIR */
1166 # ifdef HAVE_NDIR_H
1167 #  include <ndir.h>
1168 # endif
1169 #endif /* HAVE_DIRENT_H */
1171 struct dirent d; int z; z = d.d_namlen;
1172 ], bush_cv_dirent_has_d_namlen=yes, bush_cv_dirent_has_d_namlen=no)])
1173 AC_MSG_RESULT($bush_cv_dirent_has_d_namlen)
1174 if test $bush_cv_dirent_has_d_namlen = yes; then
1175 AC_DEFINE(HAVE_STRUCT_DIRENT_D_NAMLEN)
1179 AC_DEFUN(BUSH_STRUCT_TIMEVAL,
1180 [AC_MSG_CHECKING(for struct timeval in sys/time.h and time.h)
1181 AC_CACHE_VAL(bush_cv_struct_timeval,
1182 [AC_COMPILE_IFELSE(
1183         [AC_LANG_PROGRAM(
1184                 [[#if HAVE_SYS_TIME_H
1185                   #include <sys/time.h>
1186                   #endif
1187                   #include <time.h>
1188                 ]],
1189                 [[static struct timeval x; x.tv_sec = x.tv_usec;]]
1190         )],
1191         bush_cv_struct_timeval=yes,
1192         bush_cv_struct_timeval=no)
1194 AC_MSG_RESULT($bush_cv_struct_timeval)
1195 if test $bush_cv_struct_timeval = yes; then
1196   AC_DEFINE(HAVE_TIMEVAL)
1200 AC_DEFUN(BUSH_STRUCT_TIMEZONE,
1201 [AC_MSG_CHECKING(for struct timezone in sys/time.h and time.h)
1202 AC_CACHE_VAL(bush_cv_struct_timezone,
1204 AC_EGREP_HEADER(struct timezone, sys/time.h,
1205                 bush_cv_struct_timezone=yes,
1206                 AC_EGREP_HEADER(struct timezone, time.h,
1207                         bush_cv_struct_timezone=yes,
1208                         bush_cv_struct_timezone=no))
1210 AC_MSG_RESULT($bush_cv_struct_timezone)
1211 if test $bush_cv_struct_timezone = yes; then
1212   AC_DEFINE(HAVE_STRUCT_TIMEZONE)
1216 AC_DEFUN(BUSH_STRUCT_WINSIZE,
1217 [AC_MSG_CHECKING(for struct winsize in sys/ioctl.h and termios.h)
1218 AC_CACHE_VAL(bush_cv_struct_winsize_header,
1219 [AC_TRY_COMPILE([#include <sys/types.h>
1220 #include <sys/ioctl.h>], [struct winsize x;],
1221   bush_cv_struct_winsize_header=ioctl_h,
1222   [AC_TRY_COMPILE([#include <sys/types.h>
1223 #include <termios.h>], [struct winsize x;],
1224   bush_cv_struct_winsize_header=termios_h, bush_cv_struct_winsize_header=other)
1225 ])])
1226 if test $bush_cv_struct_winsize_header = ioctl_h; then
1227   AC_MSG_RESULT(sys/ioctl.h)
1228   AC_DEFINE(STRUCT_WINSIZE_IN_SYS_IOCTL)
1229 elif test $bush_cv_struct_winsize_header = termios_h; then
1230   AC_MSG_RESULT(termios.h)
1231   AC_DEFINE(STRUCT_WINSIZE_IN_TERMIOS)
1232 else
1233   AC_MSG_RESULT(not found)
1237 dnl Check type of signal routines (posix, 4.2bsd, 4.1bsd or v7)
1238 AC_DEFUN(BUSH_SYS_SIGNAL_VINTAGE,
1239 [AC_REQUIRE([AC_TYPE_SIGNAL])
1240 AC_MSG_CHECKING(for type of signal functions)
1241 AC_CACHE_VAL(bush_cv_signal_vintage,
1243   AC_TRY_LINK([#include <signal.h>],[
1244     sigset_t ss;
1245     struct sigaction sa;
1246     sigemptyset(&ss); sigsuspend(&ss);
1247     sigaction(SIGINT, &sa, (struct sigaction *) 0);
1248     sigprocmask(SIG_BLOCK, &ss, (sigset_t *) 0);
1249   ], bush_cv_signal_vintage=posix,
1250   [
1251     AC_TRY_LINK([#include <signal.h>], [
1252         int mask = sigmask(SIGINT);
1253         sigsetmask(mask); sigblock(mask); sigpause(mask);
1254     ], bush_cv_signal_vintage=4.2bsd,
1255     [
1256       AC_TRY_LINK([
1257         #include <signal.h>
1258         RETSIGTYPE foo() { }], [
1259                 int mask = sigmask(SIGINT);
1260                 sigset(SIGINT, foo); sigrelse(SIGINT);
1261                 sighold(SIGINT); sigpause(SIGINT);
1262         ], bush_cv_signal_vintage=svr3, bush_cv_signal_vintage=v7
1263     )]
1264   )]
1267 AC_MSG_RESULT($bush_cv_signal_vintage)
1268 if test "$bush_cv_signal_vintage" = posix; then
1269 AC_DEFINE(HAVE_POSIX_SIGNALS)
1270 elif test "$bush_cv_signal_vintage" = "4.2bsd"; then
1271 AC_DEFINE(HAVE_BSD_SIGNALS)
1272 elif test "$bush_cv_signal_vintage" = svr3; then
1273 AC_DEFINE(HAVE_USG_SIGHOLD)
1277 dnl Check if the pgrp of setpgrp() can't be the pid of a zombie process.
1278 AC_DEFUN(BUSH_SYS_PGRP_SYNC,
1279 [AC_REQUIRE([AC_FUNC_GETPGRP])
1280 AC_MSG_CHECKING(whether pgrps need synchronization)
1281 AC_CACHE_VAL(bush_cv_pgrp_pipe,
1282 [AC_TRY_RUN([
1283 #ifdef HAVE_UNISTD_H
1284 #  include <unistd.h>
1285 #endif
1286 #ifdef HAVE_SYS_WAIT_H
1287 #  include <sys/wait.h>
1288 #endif
1289 #include <stdlib.h>
1291 main()
1293 # ifdef GETPGRP_VOID
1294 #  define getpgID()     getpgrp()
1295 # else
1296 #  define getpgID()     getpgrp(0)
1297 #  define setpgid(x,y)  setpgrp(x,y)
1298 # endif
1299         int pid1, pid2, fds[2];
1300         int status;
1301         char ok;
1303         switch (pid1 = fork()) {
1304           case -1:
1305             exit(1);
1306           case 0:
1307             setpgid(0, getpid());
1308             exit(0);
1309         }
1310         setpgid(pid1, pid1);
1312         sleep(2);       /* let first child die */
1314         if (pipe(fds) < 0)
1315           exit(2);
1317         switch (pid2 = fork()) {
1318           case -1:
1319             exit(3);
1320           case 0:
1321             setpgid(0, pid1);
1322             ok = getpgID() == pid1;
1323             write(fds[1], &ok, 1);
1324             exit(0);
1325         }
1326         setpgid(pid2, pid1);
1328         close(fds[1]);
1329         if (read(fds[0], &ok, 1) != 1)
1330           exit(4);
1331         wait(&status);
1332         wait(&status);
1333         exit(ok ? 0 : 5);
1335 ], bush_cv_pgrp_pipe=no,bush_cv_pgrp_pipe=yes,
1336    [AC_MSG_WARN(cannot check pgrp synchronization if cross compiling -- defaulting to no)
1337     bush_cv_pgrp_pipe=no])
1339 AC_MSG_RESULT($bush_cv_pgrp_pipe)
1340 if test $bush_cv_pgrp_pipe = yes; then
1341 AC_DEFINE(PGRP_PIPE)
1345 AC_DEFUN(BUSH_SYS_REINSTALL_SIGHANDLERS,
1346 [AC_REQUIRE([AC_TYPE_SIGNAL])
1347 AC_REQUIRE([BUSH_SYS_SIGNAL_VINTAGE])
1348 AC_MSG_CHECKING([if signal handlers must be reinstalled when invoked])
1349 AC_CACHE_VAL(bush_cv_must_reinstall_sighandlers,
1350 [AC_TRY_RUN([
1351 #include <signal.h>
1352 #ifdef HAVE_UNISTD_H
1353 #include <unistd.h>
1354 #endif
1355 #include <stdlib.h>
1357 typedef RETSIGTYPE sigfunc();
1359 volatile int nsigint;
1361 #ifdef HAVE_POSIX_SIGNALS
1362 sigfunc *
1363 set_signal_handler(sig, handler)
1364      int sig;
1365      sigfunc *handler;
1367   struct sigaction act, oact;
1368   act.sa_handler = handler;
1369   act.sa_flags = 0;
1370   sigemptyset (&act.sa_mask);
1371   sigemptyset (&oact.sa_mask);
1372   sigaction (sig, &act, &oact);
1373   return (oact.sa_handler);
1375 #else
1376 #define set_signal_handler(s, h) signal(s, h)
1377 #endif
1379 RETSIGTYPE
1380 sigint(s)
1381 int s;
1383   nsigint++;
1387 main()
1389         nsigint = 0;
1390         set_signal_handler(SIGINT, sigint);
1391         kill((int)getpid(), SIGINT);
1392         kill((int)getpid(), SIGINT);
1393         exit(nsigint != 2);
1395 ], bush_cv_must_reinstall_sighandlers=no, bush_cv_must_reinstall_sighandlers=yes,
1396    [AC_MSG_WARN(cannot check signal handling if cross compiling -- defaulting to no)
1397     bush_cv_must_reinstall_sighandlers=no]
1399 AC_MSG_RESULT($bush_cv_must_reinstall_sighandlers)
1400 if test $bush_cv_must_reinstall_sighandlers = yes; then
1401 AC_DEFINE(MUST_REINSTALL_SIGHANDLERS)
1405 dnl check that some necessary job control definitions are present
1406 AC_DEFUN(BUSH_SYS_JOB_CONTROL_MISSING,
1407 [AC_REQUIRE([BUSH_SYS_SIGNAL_VINTAGE])
1408 AC_MSG_CHECKING(for presence of necessary job control definitions)
1409 AC_CACHE_VAL(bush_cv_job_control_missing,
1410 [AC_TRY_COMPILE([
1411 #include <sys/types.h>
1412 #ifdef HAVE_SYS_WAIT_H
1413 #include <sys/wait.h>
1414 #endif
1415 #ifdef HAVE_UNISTD_H
1416 #include <unistd.h>
1417 #endif
1418 #include <signal.h>
1420 /* add more tests in here as appropriate */
1422 /* signal type */
1423 #if !defined (HAVE_POSIX_SIGNALS) && !defined (HAVE_BSD_SIGNALS)
1424 #error
1425 #endif
1427 /* signals and tty control. */
1428 #if !defined (SIGTSTP) || !defined (SIGSTOP) || !defined (SIGCONT)
1429 #error
1430 #endif
1432 /* process control */
1433 #if !defined (WNOHANG) || !defined (WUNTRACED) 
1434 #error
1435 #endif
1437 /* Posix systems have tcgetpgrp and waitpid. */
1438 #if defined (_POSIX_VERSION) && !defined (HAVE_TCGETPGRP)
1439 #error
1440 #endif
1442 #if defined (_POSIX_VERSION) && !defined (HAVE_WAITPID)
1443 #error
1444 #endif
1446 /* Other systems have TIOCSPGRP/TIOCGPRGP and wait3. */
1447 #if !defined (_POSIX_VERSION) && !defined (HAVE_WAIT3)
1448 #error
1449 #endif
1451 ], , bush_cv_job_control_missing=present, bush_cv_job_control_missing=missing
1453 AC_MSG_RESULT($bush_cv_job_control_missing)
1454 if test $bush_cv_job_control_missing = missing; then
1455 AC_DEFINE(JOB_CONTROL_MISSING)
1459 dnl check whether named pipes are present
1460 dnl this requires a previous check for mkfifo, but that is awkward to specify
1461 AC_DEFUN(BUSH_SYS_NAMED_PIPES,
1462 [AC_MSG_CHECKING(for presence of named pipes)
1463 AC_CACHE_VAL(bush_cv_sys_named_pipes,
1464 [AC_TRY_RUN([
1465 #include <sys/types.h>
1466 #include <sys/stat.h>
1467 #ifdef HAVE_UNISTD_H
1468 #include <unistd.h>
1469 #endif
1470 #include <stdio.h>
1471 #include <stdlib.h>
1473 /* Add more tests in here as appropriate. */
1475 main()
1477 int fd, err;
1479 #if defined (HAVE_MKFIFO)
1480 exit (0);
1481 #endif
1483 #if !defined (S_IFIFO) && (defined (_POSIX_VERSION) && !defined (S_ISFIFO))
1484 exit (1);
1485 #endif
1487 #if defined (NeXT)
1488 exit (1);
1489 #endif
1490 err = mkdir("bush-aclocal", 0700);
1491 if (err < 0) {
1492   perror ("mkdir");
1493   exit(1);
1495 fd = mknod ("bush-aclocal/sh-np-autoconf", 0666 | S_IFIFO, 0);
1496 if (fd == -1) {
1497   rmdir ("bush-aclocal");
1498   exit (1);
1500 close(fd);
1501 unlink ("bush-aclocal/sh-np-autoconf");
1502 rmdir ("bush-aclocal");
1503 exit(0);
1504 }], bush_cv_sys_named_pipes=present, bush_cv_sys_named_pipes=missing,
1505     [AC_MSG_WARN(cannot check for named pipes if cross-compiling -- defaulting to missing)
1506      bush_cv_sys_named_pipes=missing]
1508 AC_MSG_RESULT($bush_cv_sys_named_pipes)
1509 if test $bush_cv_sys_named_pipes = missing; then
1510 AC_DEFINE(NAMED_PIPES_MISSING)
1514 AC_DEFUN(BUSH_SYS_DEFAULT_MAIL_DIR,
1515 [AC_MSG_CHECKING(for default mail directory)
1516 AC_CACHE_VAL(bush_cv_mail_dir,
1517 [if test -d /var/mail; then
1518    bush_cv_mail_dir=/var/mail
1519  elif test -d /var/spool/mail; then
1520    bush_cv_mail_dir=/var/spool/mail
1521  elif test -d /usr/mail; then
1522    bush_cv_mail_dir=/usr/mail
1523  elif test -d /usr/spool/mail; then
1524    bush_cv_mail_dir=/usr/spool/mail
1525  else
1526    bush_cv_mail_dir=unknown
1527  fi
1529 AC_MSG_RESULT($bush_cv_mail_dir)
1530 AC_DEFINE_UNQUOTED(DEFAULT_MAIL_DIRECTORY, "$bush_cv_mail_dir")
1533 AC_DEFUN(BUSH_HAVE_TIOCGWINSZ,
1534 [AC_MSG_CHECKING(for TIOCGWINSZ in sys/ioctl.h)
1535 AC_CACHE_VAL(bush_cv_tiocgwinsz_in_ioctl,
1536 [AC_TRY_COMPILE([#include <sys/types.h>
1537 #include <sys/ioctl.h>], [int x = TIOCGWINSZ;],
1538   bush_cv_tiocgwinsz_in_ioctl=yes,bush_cv_tiocgwinsz_in_ioctl=no)])
1539 AC_MSG_RESULT($bush_cv_tiocgwinsz_in_ioctl)
1540 if test $bush_cv_tiocgwinsz_in_ioctl = yes; then   
1541 AC_DEFINE(GWINSZ_IN_SYS_IOCTL)
1545 AC_DEFUN(BUSH_HAVE_TIOCSTAT,
1546 [AC_MSG_CHECKING(for TIOCSTAT in sys/ioctl.h)
1547 AC_CACHE_VAL(bush_cv_tiocstat_in_ioctl,
1548 [AC_TRY_COMPILE([#include <sys/types.h>
1549 #include <sys/ioctl.h>], [int x = TIOCSTAT;],
1550   bush_cv_tiocstat_in_ioctl=yes,bush_cv_tiocstat_in_ioctl=no)])
1551 AC_MSG_RESULT($bush_cv_tiocstat_in_ioctl)
1552 if test $bush_cv_tiocstat_in_ioctl = yes; then   
1553 AC_DEFINE(TIOCSTAT_IN_SYS_IOCTL)
1557 AC_DEFUN(BUSH_HAVE_FIONREAD,
1558 [AC_MSG_CHECKING(for FIONREAD in sys/ioctl.h)
1559 AC_CACHE_VAL(bush_cv_fionread_in_ioctl,
1560 [AC_TRY_COMPILE([#include <sys/types.h>
1561 #include <sys/ioctl.h>], [int x = FIONREAD;],
1562   bush_cv_fionread_in_ioctl=yes,bush_cv_fionread_in_ioctl=no)])
1563 AC_MSG_RESULT($bush_cv_fionread_in_ioctl)
1564 if test $bush_cv_fionread_in_ioctl = yes; then   
1565 AC_DEFINE(FIONREAD_IN_SYS_IOCTL)
1570 dnl See if speed_t is declared in <sys/types.h>.  Some versions of linux
1571 dnl require a definition of speed_t each time <termcap.h> is included,
1572 dnl but you can only get speed_t if you include <termios.h> (on some
1573 dnl versions) or <sys/types.h> (on others).
1575 AC_DEFUN(BUSH_CHECK_SPEED_T,
1576 [AC_MSG_CHECKING(for speed_t in sys/types.h)
1577 AC_CACHE_VAL(bush_cv_speed_t_in_sys_types,
1578 [AC_TRY_COMPILE([#include <sys/types.h>], [speed_t x;],
1579   bush_cv_speed_t_in_sys_types=yes,bush_cv_speed_t_in_sys_types=no)])
1580 AC_MSG_RESULT($bush_cv_speed_t_in_sys_types)
1581 if test $bush_cv_speed_t_in_sys_types = yes; then   
1582 AC_DEFINE(SPEED_T_IN_SYS_TYPES)
1586 AC_DEFUN(BUSH_CHECK_GETPW_FUNCS,
1587 [AC_MSG_CHECKING(whether getpw functions are declared in pwd.h)
1588 AC_CACHE_VAL(bush_cv_getpw_declared,
1589 [AC_EGREP_CPP(getpwuid,
1591 #include <sys/types.h>
1592 #ifdef HAVE_UNISTD_H
1593 #  include <unistd.h>
1594 #endif
1595 #include <pwd.h>
1597 bush_cv_getpw_declared=yes,bush_cv_getpw_declared=no)])
1598 AC_MSG_RESULT($bush_cv_getpw_declared)
1599 if test $bush_cv_getpw_declared = yes; then
1600 AC_DEFINE(HAVE_GETPW_DECLS)
1604 AC_DEFUN(BUSH_CHECK_DEV_FD,
1605 [AC_MSG_CHECKING(whether /dev/fd is available)
1606 AC_CACHE_VAL(bush_cv_dev_fd,
1607 [bush_cv_dev_fd=""
1608 if test -d /dev/fd  && (exec test -r /dev/fd/0 < /dev/null) ; then
1609 # check for systems like FreeBSD 5 that only provide /dev/fd/[012]
1610    if (exec test -r /dev/fd/3 3</dev/null) ; then
1611      bush_cv_dev_fd=standard
1612    else
1613      bush_cv_dev_fd=absent
1614    fi
1616 if test -z "$bush_cv_dev_fd" ; then 
1617   if test -d /proc/self/fd && (exec test -r /proc/self/fd/0 < /dev/null) ; then
1618     bush_cv_dev_fd=whacky
1619   else
1620     bush_cv_dev_fd=absent
1621   fi
1624 AC_MSG_RESULT($bush_cv_dev_fd)
1625 if test $bush_cv_dev_fd = "standard"; then
1626   AC_DEFINE(HAVE_DEV_FD)
1627   AC_DEFINE(DEV_FD_PREFIX, "/dev/fd/")
1628 elif test $bush_cv_dev_fd = "whacky"; then
1629   AC_DEFINE(HAVE_DEV_FD)
1630   AC_DEFINE(DEV_FD_PREFIX, "/proc/self/fd/")
1634 AC_DEFUN(BUSH_CHECK_DEV_STDIN,
1635 [AC_MSG_CHECKING(whether /dev/stdin stdout stderr are available)
1636 AC_CACHE_VAL(bush_cv_dev_stdin,
1637 [if (exec test -r /dev/stdin < /dev/null) ; then
1638    bush_cv_dev_stdin=present
1639  else
1640    bush_cv_dev_stdin=absent
1641  fi
1643 AC_MSG_RESULT($bush_cv_dev_stdin)
1644 if test $bush_cv_dev_stdin = "present"; then
1645   AC_DEFINE(HAVE_DEV_STDIN)
1650 dnl Check if HPUX needs _KERNEL defined for RLIMIT_* definitions
1652 AC_DEFUN(BUSH_CHECK_KERNEL_RLIMIT,
1653 [AC_MSG_CHECKING([whether $host_os needs _KERNEL for RLIMIT defines])
1654 AC_CACHE_VAL(bush_cv_kernel_rlimit,
1655 [AC_TRY_COMPILE([
1656 #include <sys/types.h>
1657 #include <sys/resource.h>
1660   int f;
1661   f = RLIMIT_DATA;
1662 ], bush_cv_kernel_rlimit=no,
1663 [AC_TRY_COMPILE([
1664 #include <sys/types.h>
1665 #define _KERNEL
1666 #include <sys/resource.h>
1667 #undef _KERNEL
1670         int f;
1671         f = RLIMIT_DATA;
1672 ], bush_cv_kernel_rlimit=yes, bush_cv_kernel_rlimit=no)]
1674 AC_MSG_RESULT($bush_cv_kernel_rlimit)
1675 if test $bush_cv_kernel_rlimit = yes; then
1676 AC_DEFINE(RLIMIT_NEEDS_KERNEL)
1681 dnl Check for 64-bit off_t -- used for malloc alignment
1683 dnl C does not allow duplicate case labels, so the compile will fail if
1684 dnl sizeof(off_t) is > 4.
1686 AC_DEFUN(BUSH_CHECK_OFF_T_64,
1687 [AC_CACHE_CHECK(for 64-bit off_t, bush_cv_off_t_64,
1688 AC_TRY_COMPILE([
1689 #ifdef HAVE_UNISTD_H
1690 #include <unistd.h>
1691 #endif
1692 #include <sys/types.h>
1694 switch (0) case 0: case (sizeof (off_t) <= 4):;
1695 ], bush_cv_off_t_64=no, bush_cv_off_t_64=yes))
1696 if test $bush_cv_off_t_64 = yes; then
1697         AC_DEFINE(HAVE_OFF_T_64)
1698 fi])
1700 AC_DEFUN(BUSH_CHECK_RTSIGS,
1701 [AC_MSG_CHECKING(for unusable real-time signals due to large values)
1702 AC_CACHE_VAL(bush_cv_unusable_rtsigs,
1703 [AC_TRY_RUN([
1704 #include <sys/types.h>
1705 #include <signal.h>
1706 #include <stdlib.h>
1708 #ifndef NSIG
1709 #  define NSIG 64
1710 #endif
1713 main ()
1715   int n_sigs = 2 * NSIG;
1716 #ifdef SIGRTMIN
1717   int rtmin = SIGRTMIN;
1718 #else
1719   int rtmin = 0;
1720 #endif
1722   exit(rtmin < n_sigs);
1723 }], bush_cv_unusable_rtsigs=yes, bush_cv_unusable_rtsigs=no,
1724     [AC_MSG_WARN(cannot check real-time signals if cross compiling -- defaulting to yes)
1725      bush_cv_unusable_rtsigs=yes]
1727 AC_MSG_RESULT($bush_cv_unusable_rtsigs)
1728 if test $bush_cv_unusable_rtsigs = yes; then
1729 AC_DEFINE(UNUSABLE_RT_SIGNALS)
1734 dnl check for availability of multibyte characters and functions
1736 dnl geez, I wish I didn't have to check for all of this stuff separately
1738 AC_DEFUN(BUSH_CHECK_MULTIBYTE,
1740 AC_CHECK_HEADERS(wctype.h)
1741 AC_CHECK_HEADERS(wchar.h)
1742 AC_CHECK_HEADERS(langinfo.h)
1744 AC_CHECK_HEADERS(mbstr.h)
1746 AC_CHECK_FUNC(mbrlen, AC_DEFINE(HAVE_MBRLEN))
1747 AC_CHECK_FUNC(mbscasecmp, AC_DEFINE(HAVE_MBSCMP))
1748 AC_CHECK_FUNC(mbscmp, AC_DEFINE(HAVE_MBSCMP))
1749 AC_CHECK_FUNC(mbsnrtowcs, AC_DEFINE(HAVE_MBSNRTOWCS))
1750 AC_CHECK_FUNC(mbsrtowcs, AC_DEFINE(HAVE_MBSRTOWCS))
1752 AC_REPLACE_FUNCS(mbschr)
1754 AC_CHECK_FUNC(wcrtomb, AC_DEFINE(HAVE_WCRTOMB))
1755 AC_CHECK_FUNC(wcscoll, AC_DEFINE(HAVE_WCSCOLL))
1756 AC_CHECK_FUNC(wcsdup, AC_DEFINE(HAVE_WCSDUP))
1757 AC_CHECK_FUNC(wcwidth, AC_DEFINE(HAVE_WCWIDTH))
1758 AC_CHECK_FUNC(wctype, AC_DEFINE(HAVE_WCTYPE))
1760 AC_REPLACE_FUNCS(wcswidth)
1762 dnl checks for both mbrtowc and mbstate_t
1763 AC_FUNC_MBRTOWC
1764 if test $ac_cv_func_mbrtowc = yes; then
1765         AC_DEFINE(HAVE_MBSTATE_T)
1768 AC_CHECK_FUNCS(iswlower iswupper towlower towupper iswctype)
1770 AC_CACHE_CHECK([for nl_langinfo and CODESET], bush_cv_langinfo_codeset,
1771 [AC_TRY_LINK(
1772 [#include <langinfo.h>],
1773 [char* cs = nl_langinfo(CODESET);],
1774 bush_cv_langinfo_codeset=yes, bush_cv_langinfo_codeset=no)])
1775 if test $bush_cv_langinfo_codeset = yes; then
1776   AC_DEFINE(HAVE_LANGINFO_CODESET)
1779 dnl check for wchar_t in <wchar.h>
1780 AC_CACHE_CHECK([for wchar_t in wchar.h], bush_cv_type_wchar_t,
1781 [AC_TRY_COMPILE(
1782 [#include <wchar.h>
1785         wchar_t foo;
1786         foo = 0;
1787 ], bush_cv_type_wchar_t=yes, bush_cv_type_wchar_t=no)])
1788 if test $bush_cv_type_wchar_t = yes; then
1789         AC_DEFINE(HAVE_WCHAR_T, 1, [systems should define this type here])
1792 dnl check for wctype_t in <wctype.h>
1793 AC_CACHE_CHECK([for wctype_t in wctype.h], bush_cv_type_wctype_t,
1794 [AC_TRY_COMPILE(
1795 [#include <wctype.h>],
1797         wctype_t foo;
1798         foo = 0;
1799 ], bush_cv_type_wctype_t=yes, bush_cv_type_wctype_t=no)])
1800 if test $bush_cv_type_wctype_t = yes; then
1801         AC_DEFINE(HAVE_WCTYPE_T, 1, [systems should define this type here])
1804 dnl check for wint_t in <wctype.h>
1805 AC_CACHE_CHECK([for wint_t in wctype.h], bush_cv_type_wint_t,
1806 [AC_TRY_COMPILE(
1807 [#include <wctype.h>],
1809         wint_t foo;
1810         foo = 0;
1811 ], bush_cv_type_wint_t=yes, bush_cv_type_wint_t=no)])
1812 if test $bush_cv_type_wint_t = yes; then
1813         AC_DEFINE(HAVE_WINT_T, 1, [systems should define this type here])
1816 dnl check for broken wcwidth
1817 AC_CACHE_CHECK([for wcwidth broken with unicode combining characters],
1818 bush_cv_wcwidth_broken,
1819 [AC_TRY_RUN([
1820 #include <unistd.h>
1821 #include <stdlib.h>
1822 #include <stdio.h>
1824 #include <locale.h>
1825 #include <wchar.h>
1828 main(c, v)
1829 int     c;
1830 char    **v;
1832         int     w;
1834         setlocale(LC_ALL, "en_US.UTF-8");
1835         w = wcwidth (0x0301);
1836         exit (w == 0);  /* exit 0 if wcwidth broken */
1839 bush_cv_wcwidth_broken=yes, bush_cv_wcwidth_broken=no, bush_cv_wcwidth_broken=no)])
1840 if test "$bush_cv_wcwidth_broken" = yes; then
1841         AC_DEFINE(WCWIDTH_BROKEN, 1, [wcwidth is usually not broken])
1844 if test "$am_cv_func_iconv" = yes; then
1845         OLDLIBS="$LIBS"
1846         LIBS="$LIBS $LIBINTL $LIBICONV"
1847         AC_CHECK_FUNCS(locale_charset)
1848         LIBS="$OLDLIBS"
1851 AC_CHECK_SIZEOF(wchar_t, 4)
1855 dnl need: prefix exec_prefix libdir includedir CC TERMCAP_LIB
1856 dnl require:
1857 dnl     AC_PROG_CC
1858 dnl     BUSH_CHECK_LIB_TERMCAP
1860 AC_DEFUN([RL_LIB_READLINE_VERSION],
1862 AC_REQUIRE([BUSH_CHECK_LIB_TERMCAP])
1864 AC_MSG_CHECKING([version of installed readline library])
1866 # What a pain in the ass this is.
1868 # save cpp and ld options
1869 _save_CFLAGS="$CFLAGS"
1870 _save_LDFLAGS="$LDFLAGS"
1871 _save_LIBS="$LIBS"
1873 # Don't set ac_cv_rl_prefix if the caller has already assigned a value.  This
1874 # allows the caller to do something like $_rl_prefix=$withval if the user
1875 # specifies --with-installed-readline=PREFIX as an argument to configure
1877 if test -z "$ac_cv_rl_prefix"; then
1878 test "x$prefix" = xNONE && ac_cv_rl_prefix=$ac_default_prefix || ac_cv_rl_prefix=${prefix}
1881 eval ac_cv_rl_includedir=${ac_cv_rl_prefix}/include
1882 eval ac_cv_rl_libdir=${ac_cv_rl_prefix}/lib
1884 LIBS="$LIBS -lreadline ${TERMCAP_LIB}"
1885 CFLAGS="$CFLAGS -I${ac_cv_rl_includedir}"
1886 LDFLAGS="$LDFLAGS -L${ac_cv_rl_libdir}"
1888 AC_CACHE_VAL(ac_cv_rl_version,
1889 [AC_TRY_RUN([
1890 #include <stdio.h>
1891 #include <readline/readline.h>
1892 #include <stdlib.h>
1894 extern int rl_gnu_readline_p;
1897 main()
1899         FILE *fp;
1900         fp = fopen("conftest.rlv", "w");
1901         if (fp == 0)
1902                 exit(1);
1903         if (rl_gnu_readline_p != 1)
1904                 fprintf(fp, "0.0\n");
1905         else
1906                 fprintf(fp, "%s\n", rl_library_version ? rl_library_version : "0.0");
1907         fclose(fp);
1908         exit(0);
1911 ac_cv_rl_version=`cat conftest.rlv`,
1912 ac_cv_rl_version='0.0',
1913 ac_cv_rl_version='8.0')])
1915 CFLAGS="$_save_CFLAGS"
1916 LDFLAGS="$_save_LDFLAGS"
1917 LIBS="$_save_LIBS"
1919 RL_MAJOR=0
1920 RL_MINOR=0
1922 # (
1923 case "$ac_cv_rl_version" in
1924 2*|3*|4*|5*|6*|7*|8*|9*)
1925         RL_MAJOR=`echo $ac_cv_rl_version | sed 's:\..*$::'`
1926         RL_MINOR=`echo $ac_cv_rl_version | sed -e 's:^.*\.::' -e 's:[[a-zA-Z]]*$::'`
1927         ;;
1928 esac
1930 # (((
1931 case $RL_MAJOR in
1932 [[0-9][0-9]])   _RL_MAJOR=$RL_MAJOR ;;
1933 [[0-9]])        _RL_MAJOR=0$RL_MAJOR ;;
1934 *)              _RL_MAJOR=00 ;;
1935 esac
1937 # (((
1938 case $RL_MINOR in
1939 [[0-9][0-9]])   _RL_MINOR=$RL_MINOR ;;
1940 [[0-9]])        _RL_MINOR=0$RL_MINOR ;;
1941 *)              _RL_MINOR=00 ;;
1942 esac
1944 RL_VERSION="0x${_RL_MAJOR}${_RL_MINOR}"
1946 # Readline versions greater than 4.2 have these defines in readline.h
1948 if test $ac_cv_rl_version = '0.0' ; then
1949         AC_MSG_WARN([Could not test version of installed readline library.])
1950 elif test $RL_MAJOR -gt 4 || { test $RL_MAJOR = 4 && test $RL_MINOR -gt 2 ; } ; then
1951         # set these for use by the caller
1952         RL_PREFIX=$ac_cv_rl_prefix
1953         RL_LIBDIR=$ac_cv_rl_libdir
1954         RL_INCLUDEDIR=$ac_cv_rl_includedir
1955         AC_MSG_RESULT($ac_cv_rl_version)
1956 else
1958 AC_DEFINE_UNQUOTED(RL_READLINE_VERSION, $RL_VERSION, [encoded version of the installed readline library])
1959 AC_DEFINE_UNQUOTED(RL_VERSION_MAJOR, $RL_MAJOR, [major version of installed readline library])
1960 AC_DEFINE_UNQUOTED(RL_VERSION_MINOR, $RL_MINOR, [minor version of installed readline library])
1962 AC_SUBST(RL_VERSION)
1963 AC_SUBST(RL_MAJOR)
1964 AC_SUBST(RL_MINOR)
1966 # set these for use by the caller
1967 RL_PREFIX=$ac_cv_rl_prefix
1968 RL_LIBDIR=$ac_cv_rl_libdir
1969 RL_INCLUDEDIR=$ac_cv_rl_includedir
1971 AC_MSG_RESULT($ac_cv_rl_version)
1976 AC_DEFUN(BUSH_FUNC_CTYPE_NONASCII,
1978 AC_MSG_CHECKING(whether the ctype macros accept non-ascii characters)
1979 AC_CACHE_VAL(bush_cv_func_ctype_nonascii,
1980 [AC_TRY_RUN([
1981 #ifdef HAVE_LOCALE_H
1982 #include <locale.h>
1983 #endif
1984 #include <stdio.h>
1985 #include <ctype.h>
1986 #include <stdlib.h>
1989 main(c, v)
1990 int     c;
1991 char    *v[];
1993         char    *deflocale;
1994         unsigned char x;
1995         int     r1, r2;
1997 #ifdef HAVE_SETLOCALE
1998         /* We take a shot here.  If that locale is not known, try the
1999            system default.  We try this one because '\342' (226) is
2000            known to be a printable character in that locale. */
2001         deflocale = setlocale(LC_ALL, "en_US.ISO8859-1");
2002         if (deflocale == 0)
2003                 deflocale = setlocale(LC_ALL, "");
2004 #endif
2006         x = '\342';
2007         r1 = isprint(x);
2008         x -= 128;
2009         r2 = isprint(x);
2010         exit (r1 == 0 || r2 == 0);
2012 ], bush_cv_func_ctype_nonascii=yes, bush_cv_func_ctype_nonascii=no,
2013    [AC_MSG_WARN(cannot check ctype macros if cross compiling -- defaulting to no)
2014     bush_cv_func_ctype_nonascii=no]
2016 AC_MSG_RESULT($bush_cv_func_ctype_nonascii)
2017 if test $bush_cv_func_ctype_nonascii = yes; then
2018 AC_DEFINE(CTYPE_NON_ASCII)
2022 AC_DEFUN(BUSH_CHECK_WCONTINUED,
2024 AC_MSG_CHECKING(whether WCONTINUED flag to waitpid is unavailable or available but broken)
2025 AC_CACHE_VAL(bush_cv_wcontinued_broken,
2026 [AC_TRY_RUN([
2027 #include <sys/types.h>
2028 #include <sys/wait.h>
2029 #include <unistd.h>
2030 #include <errno.h>
2031 #include <stdlib.h>
2033 #ifndef errno
2034 extern int errno;
2035 #endif
2037 main()
2039         int     x;
2041         x = waitpid(-1, (int *)0, WNOHANG|WCONTINUED);
2042         if (x == -1 && errno == EINVAL)
2043                 exit (1);
2044         else
2045                 exit (0);
2047 ], bush_cv_wcontinued_broken=no,bush_cv_wcontinued_broken=yes,
2048    [AC_MSG_WARN(cannot check WCONTINUED if cross compiling -- defaulting to no)
2049     bush_cv_wcontinued_broken=no]
2051 AC_MSG_RESULT($bush_cv_wcontinued_broken)
2052 if test $bush_cv_wcontinued_broken = yes; then
2053 AC_DEFINE(WCONTINUED_BROKEN)
2058 dnl tests added for bushdb
2062 AC_DEFUN([AM_PATH_LISPDIR],
2063  [AC_ARG_WITH(lispdir, AC_HELP_STRING([--with-lispdir], [override the default lisp directory]),
2064   [ lispdir="$withval" 
2065     AC_MSG_CHECKING([where .elc files should go])
2066     AC_MSG_RESULT([$lispdir])],
2067   [
2068   # If set to t, that means we are running in a shell under Emacs.
2069   # If you have an Emacs named "t", then use the full path.
2070   test x"$EMACS" = xt && EMACS=
2071   AC_CHECK_PROGS(EMACS, emacs xemacs, no)
2072   if test $EMACS != "no"; then
2073     if test x${lispdir+set} != xset; then
2074       AC_CACHE_CHECK([where .elc files should go], [am_cv_lispdir], [dnl
2075         am_cv_lispdir=`$EMACS -batch -q -eval '(while load-path (princ (concat (car load-path) "\n")) (setq load-path (cdr load-path)))' | sed -n -e 's,/$,,' -e '/.*\/lib\/\(x\?emacs\/site-lisp\)$/{s,,${libdir}/\1,;p;q;}' -e '/.*\/share\/\(x\?emacs\/site-lisp\)$/{s,,${datadir}/\1,;p;q;}'`
2076         if test -z "$am_cv_lispdir"; then
2077           am_cv_lispdir='${datadir}/emacs/site-lisp'
2078         fi
2079       ])
2080       lispdir="$am_cv_lispdir"
2081     fi
2082   fi
2083  ])
2084  AC_SUBST(lispdir)
2087 dnl From gnulib
2088 AC_DEFUN([BUSH_FUNC_FPURGE],
2090   AC_CHECK_FUNCS_ONCE([fpurge])
2091   AC_CHECK_FUNCS_ONCE([__fpurge])
2092   AC_CHECK_DECLS([fpurge], , , [#include <stdio.h>])
2095 AC_DEFUN([BUSH_FUNC_SNPRINTF],
2097   AC_CHECK_FUNCS_ONCE([snprintf])
2098   if test X$ac_cv_func_snprintf = Xyes; then
2099     AC_CACHE_CHECK([for standard-conformant snprintf], [bush_cv_func_snprintf],
2100       [AC_TRY_RUN([
2101 #include <stdio.h>
2102 #include <stdlib.h>
2105 main()
2107   int n;
2108   n = snprintf (0, 0, "%s", "0123456");
2109   exit(n != 7);
2111 ], bush_cv_func_snprintf=yes, bush_cv_func_snprintf=no,
2112    [AC_MSG_WARN([cannot check standard snprintf if cross-compiling])
2113     bush_cv_func_snprintf=yes]
2115     if test $bush_cv_func_snprintf = no; then
2116       ac_cv_func_snprintf=no
2117     fi
2118   fi
2119   if test $ac_cv_func_snprintf = no; then
2120     AC_DEFINE(HAVE_SNPRINTF, 0,
2121       [Define if you have a standard-conformant snprintf function.])
2122   fi
2125 AC_DEFUN([BUSH_FUNC_VSNPRINTF],
2127   AC_CHECK_FUNCS_ONCE([vsnprintf])
2128   if test X$ac_cv_func_vsnprintf = Xyes; then
2129     AC_CACHE_CHECK([for standard-conformant vsnprintf], [bush_cv_func_vsnprintf],
2130       [AC_TRY_RUN([
2131 #if HAVE_STDARG_H
2132 #include <stdarg.h>
2133 #else
2134 #include <varargs.h>
2135 #endif
2136 #include <stdio.h>
2137 #include <stdlib.h>
2139 static int
2140 #if HAVE_STDARG_H
2141 foo(const char *fmt, ...)
2142 #else
2143 foo(format, va_alist)
2144      const char *format;
2145      va_dcl
2146 #endif
2148   va_list args;
2149   int n;
2151 #if HAVE_STDARG_H
2152   va_start(args, fmt);
2153 #else
2154   va_start(args);
2155 #endif
2156   n = vsnprintf(0, 0, fmt, args);
2157   va_end (args);
2158   return n;
2162 main()
2164   int n;
2165   n = foo("%s", "0123456");
2166   exit(n != 7);
2168 ], bush_cv_func_vsnprintf=yes, bush_cv_func_vsnprintf=no,
2169    [AC_MSG_WARN([cannot check standard vsnprintf if cross-compiling])
2170     bush_cv_func_vsnprintf=yes]
2172     if test $bush_cv_func_vsnprintf = no; then
2173       ac_cv_func_vsnprintf=no
2174     fi
2175   fi
2176   if test $ac_cv_func_vsnprintf = no; then
2177     AC_DEFINE(HAVE_VSNPRINTF, 0,
2178       [Define if you have a standard-conformant vsnprintf function.])
2179   fi
2182 AC_DEFUN(BUSH_STRUCT_WEXITSTATUS_OFFSET,
2183 [AC_MSG_CHECKING(for offset of exit status in return status from wait)
2184 AC_CACHE_VAL(bush_cv_wexitstatus_offset,
2185 [AC_TRY_RUN([
2186 #include <stdlib.h>
2187 #include <unistd.h>
2189 #include <sys/wait.h>
2192 main(c, v)
2193      int c;
2194      char **v;
2196   pid_t pid, p;
2197   int s, i, n;
2199   s = 0;
2200   pid = fork();
2201   if (pid == 0)
2202     exit (42);
2204   /* wait for the process */
2205   p = wait(&s);
2206   if (p != pid)
2207     exit (255);
2209   /* crack s */
2210   for (i = 0; i < (sizeof(s) * 8); i++)
2211     {
2212       n = (s >> i) & 0xff;
2213       if (n == 42)
2214         exit (i);
2215     }
2217   exit (254);
2219 ], bush_cv_wexitstatus_offset=0, bush_cv_wexitstatus_offset=$?,
2220    [AC_MSG_WARN(cannot check WEXITSTATUS offset if cross compiling -- defaulting to 0)
2221     bush_cv_wexitstatus_offset=0]
2223 if test "$bush_cv_wexitstatus_offset" -gt 32 ; then
2224   AC_MSG_WARN(bad exit status from test program -- defaulting to 0)
2225   bush_cv_wexitstatus_offset=0
2227 AC_MSG_RESULT($bush_cv_wexitstatus_offset)
2228 AC_DEFINE_UNQUOTED([WEXITSTATUS_OFFSET], [$bush_cv_wexitstatus_offset], [Offset of exit status in wait status word])
2231 AC_DEFUN([BUSH_FUNC_SBRK],
2233   AC_MSG_CHECKING([for sbrk])
2234   AC_CACHE_VAL(ac_cv_func_sbrk,
2235   [AC_TRY_LINK([#include <unistd.h>],
2236   [ void *x = sbrk (4096); ],
2237   ac_cv_func_sbrk=yes, ac_cv_func_sbrk=no)])
2238   AC_MSG_RESULT($ac_cv_func_sbrk)
2239   if test X$ac_cv_func_sbrk = Xyes; then
2240     AC_CACHE_CHECK([for working sbrk], [bush_cv_func_sbrk],
2241       [AC_TRY_RUN([
2242 #include <stdlib.h>
2243 #include <unistd.h>
2246 main(int c, char **v)
2248         void *x;
2250         x = sbrk (4096);
2251         exit ((x == (void *)-1) ? 1 : 0);
2253 ], bush_cv_func_sbrk=yes, bush_cv_func_snprintf=sbrk,
2254    [AC_MSG_WARN([cannot check working sbrk if cross-compiling])
2255     bush_cv_func_sbrk=yes]
2257     if test $bush_cv_func_sbrk = no; then
2258       ac_cv_func_sbrk=no
2259     fi
2260   fi
2261   if test $ac_cv_func_sbrk = yes; then
2262     AC_DEFINE(HAVE_SBRK, 1,
2263       [Define if you have a working sbrk function.])
2264   fi
2267 AC_DEFUN(BUSH_FUNC_FNMATCH_EQUIV_FALLBACK,
2268 [AC_MSG_CHECKING(whether fnmatch can be used to check bracket equivalence classes)
2269 AC_CACHE_VAL(bush_cv_fnmatch_equiv_fallback,
2270 [AC_TRY_RUN([
2271 #include <stdlib.h>
2272 #include <unistd.h>
2273 #include <stdio.h>
2274 #include <fnmatch.h>
2275 #include <locale.h>
2277 char *pattern = "[[=a=]]";
2279 /* char *string = "รค"; */
2280 unsigned char string[4] = { '\xc3', '\xa4', '\0' };
2283 main (int c, char **v)
2285   setlocale (LC_ALL, "en_US.UTF-8");
2286   if (fnmatch (pattern, (const char *)string, 0) != FNM_NOMATCH)
2287     exit (0);
2288   exit (1);
2291 ], bush_cv_fnmatch_equiv_fallback=yes, bush_cv_fnmatch_equiv_fallback=no,
2292    [AC_MSG_WARN(cannot check fnmatch if cross compiling -- defaulting to no)
2293     bush_cv_fnmatch_equiv_fallback=no]
2295 AC_MSG_RESULT($bush_cv_fnmatch_equiv_fallback)
2296 if test "$bush_cv_fnmatch_equiv_fallback" = "yes" ; then
2297     bush_cv_fnmatch_equiv_value=1
2298 else
2299     bush_cv_fnmatch_equiv_value=0
2301 AC_DEFINE_UNQUOTED([FNMATCH_EQUIV_FALLBACK], [$bush_cv_fnmatch_equiv_value], [Whether fnmatch can be used for bracket equivalence classes])