Imported from ../bash-2.01.1.tar.gz.
[platform/upstream/bash.git] / aclocal.m4
1 dnl
2 dnl Bash specific tests
3 dnl
4 dnl Some derived from PDKSH 5.1.3 autoconf tests
5 dnl
6 dnl
7 dnl Check if dup2() does not clear the close on exec flag
8 dnl
9 AC_DEFUN(BASH_DUP2_CLOEXEC_CHECK,
10 [AC_MSG_CHECKING(if dup2 fails to clear the close-on-exec flag)
11 AC_CACHE_VAL(bash_cv_dup2_broken,
12 [AC_TRY_RUN([
13 #include <sys/types.h>
14 #include <fcntl.h>
15 main()
16 {
17   int fd1, fd2, fl;
18   fd1 = open("/dev/null", 2);
19   if (fcntl(fd1, 2, 1) < 0)
20     exit(1);
21   fd2 = dup2(fd1, 1);
22   if (fd2 < 0)
23     exit(2);
24   fl = fcntl(fd2, 1, 0);
25   /* fl will be 1 if dup2 did not reset the close-on-exec flag. */
26   exit(fl != 1);
27 }
28 ], bash_cv_dup2_broken=yes, bash_cv_dup2_broken=no,
29     AC_MSG_ERROR(cannot check dup2 if cross compiling))
30 ])
31 AC_MSG_RESULT($bash_cv_dup2_broken)
32 if test $bash_cv_dup2_broken = yes; then
33 AC_DEFINE(DUP2_BROKEN)
34 fi
35 ])
36
37 dnl Check type of signal routines (posix, 4.2bsd, 4.1bsd or v7)
38 AC_DEFUN(BASH_SIGNAL_CHECK,
39 [AC_REQUIRE([AC_TYPE_SIGNAL])
40 AC_MSG_CHECKING(for type of signal functions)
41 AC_CACHE_VAL(bash_cv_signal_vintage,
42 [
43   AC_TRY_LINK([#include <signal.h>],[
44     sigset_t ss;
45     struct sigaction sa;
46     sigemptyset(&ss); sigsuspend(&ss);
47     sigaction(SIGINT, &sa, (struct sigaction *) 0);
48     sigprocmask(SIG_BLOCK, &ss, (sigset_t *) 0);
49   ], bash_cv_signal_vintage=posix,
50   [
51     AC_TRY_LINK([#include <signal.h>], [
52         int mask = sigmask(SIGINT);
53         sigsetmask(mask); sigblock(mask); sigpause(mask);
54     ], bash_cv_signal_vintage=4.2bsd,
55     [
56       AC_TRY_LINK([
57         #include <signal.h>
58         RETSIGTYPE foo() { }], [
59                 int mask = sigmask(SIGINT);
60                 sigset(SIGINT, foo); sigrelse(SIGINT);
61                 sighold(SIGINT); sigpause(SIGINT);
62         ], bash_cv_signal_vintage=svr3, bash_cv_signal_vintage=v7
63     )]
64   )]
65 )
66 ])
67 AC_MSG_RESULT($bash_cv_signal_vintage)
68 if test "$bash_cv_signal_vintage" = posix; then
69 AC_DEFINE(HAVE_POSIX_SIGNALS)
70 elif test "$bash_cv_signal_vintage" = "4.2bsd"; then
71 AC_DEFINE(HAVE_BSD_SIGNALS)
72 elif test "$bash_cv_signal_vintage" = svr3; then
73 AC_DEFINE(HAVE_USG_SIGHOLD)
74 fi
75 ])
76
77 dnl Check if the pgrp of setpgrp() can't be the pid of a zombie process.
78 AC_DEFUN(BASH_PGRP_SYNC,
79 [AC_REQUIRE([AC_FUNC_GETPGRP])
80 AC_MSG_CHECKING(whether pgrps need synchronization)
81 AC_CACHE_VAL(bash_cv_pgrp_pipe,
82 [AC_TRY_RUN([
83 #ifdef HAVE_UNISTD_H
84 #  include <unistd.h>
85 #endif
86 main()
87 {
88 # ifdef GETPGRP_VOID
89 #  define getpgID()     getpgrp()
90 # else
91 #  define getpgID()     getpgrp(0)
92 #  define setpgid(x,y)  setpgrp(x,y)
93 # endif
94         int pid1, pid2, fds[2];
95         int status;
96         char ok;
97
98         switch (pid1 = fork()) {
99           case -1:
100             exit(1);
101           case 0:
102             setpgid(0, getpid());
103             exit(0);
104         }
105         setpgid(pid1, pid1);
106
107         sleep(2);       /* let first child die */
108
109         if (pipe(fds) < 0)
110           exit(2);
111
112         switch (pid2 = fork()) {
113           case -1:
114             exit(3);
115           case 0:
116             setpgid(0, pid1);
117             ok = getpgID() == pid1;
118             write(fds[1], &ok, 1);
119             exit(0);
120         }
121         setpgid(pid2, pid1);
122
123         close(fds[1]);
124         if (read(fds[0], &ok, 1) != 1)
125           exit(4);
126         wait(&status);
127         wait(&status);
128         exit(ok ? 0 : 5);
129 }
130 ], bash_cv_pgrp_pipe=no,bash_cv_pgrp_pipe=yes,
131    AC_MSG_ERROR(cannot check pgrp synchronization if cross compiling))
132 ])
133 AC_MSG_RESULT($bash_cv_pgrp_pipe)
134 if test $bash_cv_pgrp_pipe = yes; then
135 AC_DEFINE(PGRP_PIPE)
136 fi
137 ])
138
139 dnl
140 dnl check for typedef'd symbols in header files, but allow the caller to
141 dnl specify the include files to be checked in addition to the default
142 dnl 
143 dnl BASH_CHECK_TYPE(TYPE, HEADERS, DEFAULT[, VALUE-IF-FOUND])
144 AC_DEFUN(BASH_CHECK_TYPE,
145 [AC_REQUIRE([AC_HEADER_STDC])dnl
146 AC_MSG_CHECKING(for $1)
147 AC_CACHE_VAL(bash_cv_type_$1,
148 [AC_EGREP_CPP($1, [#include <sys/types.h>
149 #if STDC_HEADERS
150 #include <stdlib.h>
151 #endif
152 $2
153 ], bash_cv_type_$1=yes, bash_cv_type_$1=no)])
154 AC_MSG_RESULT($bash_cv_type_$1)
155 ifelse($#, 4, [if test $bash_cv_type_$1 = yes; then
156         AC_DEFINE($4)
157         fi])
158 if test $bash_cv_type_$1 = no; then
159   AC_DEFINE($1, $3)
160 fi
161 ])
162
163 dnl
164 dnl Type of struct rlimit fields: some systems (OSF/1, NetBSD, RISC/os 5.0)
165 dnl have a rlim_t, others (4.4BSD based systems) use quad_t, others use
166 dnl long and still others use int (HP-UX 9.01, SunOS 4.1.3).  To simplify
167 dnl matters, this just checks for rlim_t, quad_t, or long.
168 dnl
169 AC_DEFUN(BASH_RLIMIT_TYPE,
170 [AC_MSG_CHECKING(for size and type of struct rlimit fields)
171 AC_CACHE_VAL(bash_cv_type_rlimit,
172 [AC_TRY_COMPILE([#include <sys/types.h>],
173 [rlim_t xxx;], bash_cv_type_rlimit=rlim_t,[
174 AC_TRY_RUN([
175 #include <sys/types.h>
176 #include <sys/time.h>
177 #include <sys/resource.h>
178 main()
179 {
180 #ifdef HAVE_QUAD_T
181   struct rlimit rl;
182   if (sizeof(rl.rlim_cur) == sizeof(quad_t))
183     exit(0);
184 #endif
185   exit(1);
186 }], bash_cv_type_rlimit=quad_t, bash_cv_type_rlimit=long,
187         AC_MSG_ERROR(cannot check quad_t if cross compiling))])
188 ])
189 AC_MSG_RESULT($bash_cv_type_rlimit)
190 if test $bash_cv_type_rlimit = quad_t; then
191 AC_DEFINE(RLIMTYPE, quad_t)
192 elif test $bash_cv_type_rlimit = rlim_t; then
193 AC_DEFINE(RLIMTYPE, rlim_t)
194 fi
195 ])
196
197 dnl
198 dnl Check for sys_siglist[] or _sys_siglist[]
199 dnl
200 AC_DEFUN(BASH_DECL_UNDER_SYS_SIGLIST,
201 [AC_MSG_CHECKING([for _sys_siglist in signal.h or unistd.h])
202 AC_CACHE_VAL(bash_cv_decl_under_sys_siglist,
203 [AC_TRY_COMPILE([
204 #include <sys/types.h>
205 #include <signal.h>
206 #ifdef HAVE_UNISTD_H
207 #include <unistd.h>
208 #endif], [ char *msg = _sys_siglist[2]; ],
209   bash_cv_decl_under_sys_siglist=yes, bash_cv_decl_under_sys_siglist=no,
210 AC_MSG_ERROR(cannot check for _sys_siglist[] if cross compiling))])dnl
211 AC_MSG_RESULT($bash_cv_decl_under_sys_siglist)
212 if test $bash_cv_decl_under_sys_siglist = yes; then
213 AC_DEFINE(UNDER_SYS_SIGLIST_DECLARED)
214 fi
215 ])
216
217 AC_DEFUN(BASH_UNDER_SYS_SIGLIST,
218 [AC_REQUIRE([BASH_DECL_UNDER_SYS_SIGLIST])
219 AC_MSG_CHECKING([for _sys_siglist in system C library])
220 AC_CACHE_VAL(bash_cv_under_sys_siglist,
221 [AC_TRY_RUN([
222 #include <sys/types.h>
223 #include <signal.h>
224 #ifdef HAVE_UNISTD_H
225 #include <unistd.h>
226 #endif
227 #ifndef UNDER_SYS_SIGLIST_DECLARED
228 extern char *_sys_siglist[];
229 #endif
230 main()
231 {
232 char *msg = (char *)_sys_siglist[2];
233 exit(msg == 0);
234 }],
235 bash_cv_under_sys_siglist=yes, bash_cv_under_sys_siglist=no,
236 AC_MSG_ERROR(cannot check for _sys_siglist[] if cross compiling))])dnl
237 AC_MSG_RESULT($bash_cv_under_sys_siglist)
238 if test $bash_cv_under_sys_siglist = yes; then
239 AC_DEFINE(HAVE_UNDER_SYS_SIGLIST)
240 fi
241 ])
242
243 AC_DEFUN(BASH_SYS_SIGLIST,
244 [AC_REQUIRE([AC_DECL_SYS_SIGLIST])
245 AC_MSG_CHECKING([for sys_siglist in system C library])
246 AC_CACHE_VAL(bash_cv_sys_siglist,
247 [AC_TRY_RUN([
248 #include <sys/types.h>
249 #include <signal.h>
250 #ifdef HAVE_UNISTD_H
251 #include <unistd.h>
252 #endif
253 #ifndef SYS_SIGLIST_DECLARED
254 extern char *sys_siglist[];
255 #endif
256 main()
257 {
258 char *msg = sys_siglist[2];
259 exit(msg == 0);
260 }],
261 bash_cv_sys_siglist=yes, bash_cv_sys_siglist=no,
262 AC_MSG_ERROR(cannot check for sys_siglist if cross compiling))])dnl
263 AC_MSG_RESULT($bash_cv_sys_siglist)
264 if test $bash_cv_sys_siglist = yes; then
265 AC_DEFINE(HAVE_SYS_SIGLIST)
266 fi
267 ])
268
269 dnl Check for sys_errlist[] and sys_nerr, check for declaration
270 AC_DEFUN(BASH_SYS_ERRLIST,
271 [AC_MSG_CHECKING([for sys_errlist and sys_nerr])
272 AC_CACHE_VAL(bash_cv_sys_errlist,
273 [AC_TRY_LINK([#include <errno.h>],
274 [extern char *sys_errlist[];
275  extern int sys_nerr;
276  char *msg = sys_errlist[sys_nerr - 1];],
277     bash_cv_sys_errlist=yes, bash_cv_sys_errlist=no)])dnl
278 AC_MSG_RESULT($bash_cv_sys_errlist)
279 if test $bash_cv_sys_errlist = yes; then
280 AC_DEFINE(HAVE_SYS_ERRLIST)
281 fi
282 ])
283
284 dnl Check to see if opendir will open non-directories (not a nice thing)
285 AC_DEFUN(BASH_FUNC_OPENDIR_CHECK,
286 [AC_REQUIRE([AC_HEADER_DIRENT])dnl
287 AC_MSG_CHECKING(if opendir() opens non-directories)
288 AC_CACHE_VAL(bash_cv_opendir_not_robust,
289 [AC_TRY_RUN([
290 #include <stdio.h>
291 #include <sys/types.h>
292 #include <fcntl.h>
293 #ifdef HAVE_UNISTD_H
294 # include <unistd.h>
295 #endif /* HAVE_UNISTD_H */
296 #if defined(HAVE_DIRENT_H)
297 # include <dirent.h>
298 #else
299 # define dirent direct
300 # ifdef HAVE_SYS_NDIR_H
301 #  include <sys/ndir.h>
302 # endif /* SYSNDIR */
303 # ifdef HAVE_SYS_DIR_H
304 #  include <sys/dir.h>
305 # endif /* SYSDIR */
306 # ifdef HAVE_NDIR_H
307 #  include <ndir.h>
308 # endif
309 #endif /* HAVE_DIRENT_H */
310 main()
311 {
312 DIR *dir;
313 int fd;
314 unlink("/tmp/not_a_directory");
315 fd = open("/tmp/not_a_directory", O_WRONLY|O_CREAT, 0666);
316 write(fd, "\n", 1);
317 close(fd);
318 dir = opendir("/tmp/not_a_directory");
319 unlink("/tmp/not_a_directory");
320 exit (dir == 0);
321 }], bash_cv_opendir_not_robust=yes,bash_cv_opendir_not_robust=no,
322     AC_MSG_ERROR(cannot check opendir if cross compiling))])
323 AC_MSG_RESULT($bash_cv_opendir_not_robust)
324 if test $bash_cv_opendir_not_robust = yes; then
325 AC_DEFINE(OPENDIR_NOT_ROBUST)
326 fi
327 ])
328
329 dnl
330 AC_DEFUN(BASH_TYPE_SIGHANDLER,
331 [AC_MSG_CHECKING([whether signal handlers are of type void])
332 AC_CACHE_VAL(bash_cv_void_sighandler,
333 [AC_TRY_COMPILE([#include <sys/types.h>
334 #include <signal.h>
335 #ifdef signal
336 #undef signal
337 #endif
338 #ifdef __cplusplus
339 extern "C"
340 #endif
341 void (*signal ()) ();],
342 [int i;], bash_cv_void_sighandler=yes, bash_cv_void_sighandler=no)])dnl
343 AC_MSG_RESULT($bash_cv_void_sighandler)
344 if test $bash_cv_void_sighandler = yes; then
345 AC_DEFINE(VOID_SIGHANDLER)
346 fi
347 ])
348
349 AC_DEFUN(BASH_FUNC_STRSIGNAL,
350 [AC_MSG_CHECKING([for the existance of strsignal])
351 AC_CACHE_VAL(bash_cv_have_strsignal,
352 [AC_TRY_LINK([#include <sys/types.h>
353 #include <signal.h>],
354 [char *s = (char *)strsignal(2);],
355  bash_cv_have_strsignal=yes, bash_cv_have_strsignal=no)])
356 AC_MSG_RESULT($bash_cv_have_strsignal)
357 if test $bash_cv_have_strsignal = yes; then
358 AC_DEFINE(HAVE_STRSIGNAL)
359 fi
360 ])
361
362 AC_DEFUN(BASH_FUNC_LSTAT,
363 [dnl Cannot use AC_CHECK_FUNCS(lstat) because Linux defines lstat() as an
364 dnl inline function in <sys/stat.h>.
365 AC_CACHE_CHECK([for lstat], bash_cv_func_lstat,
366 [AC_TRY_LINK([
367 #include <sys/types.h>
368 #include <sys/stat.h>
369 ],[ lstat("",(struct stat *)0); ],
370 bash_cv_func_lstat=yes, bash_cv_func_lstat=no)])
371 if test $bash_cv_func_lstat = yes; then
372   AC_DEFINE(HAVE_LSTAT)
373 fi
374 ])
375
376 AC_DEFUN(BASH_STRUCT_TERMIOS_LDISC,
377 [AC_MSG_CHECKING([for a c_line member of struct termios])
378 AC_CACHE_VAL(bash_cv_termios_ldisc,
379 [AC_TRY_COMPILE([#include <sys/types.h>
380 #include <termios.h>],[struct termios t; int i; i = t.c_line;],
381   bash_cv_termios_ldisc=yes, bash_cv_termios_ldisc=no)])dnl
382 AC_MSG_RESULT($bash_cv_termios_ldisc)
383 if test $bash_cv_termios_ldisc = yes; then
384 AC_DEFINE(TERMIOS_LDISC)
385 fi
386 ])
387
388 AC_DEFUN(BASH_STRUCT_TERMIO_LDISC,
389 [AC_MSG_CHECKING([for a c_line member of struct termio])
390 AC_CACHE_VAL(bash_cv_termio_ldisc,
391 [AC_TRY_COMPILE([#include <sys/types.h>
392 #include <termio.h>],[struct termio t; int i; i = t.c_line;],
393   bash_cv_termio_ldisc=yes, bash_cv_termio_ldisc=no)])dnl
394 AC_MSG_RESULT($bash_cv_termio_ldisc)
395 if test $bash_cv_termio_ldisc = yes; then
396 AC_DEFINE(TERMIO_LDISC)
397 fi
398 ])
399
400 AC_DEFUN(BASH_FUNC_GETENV,
401 [AC_MSG_CHECKING(to see if getenv can be redefined)
402 AC_CACHE_VAL(bash_cv_getenv_redef,
403 [AC_TRY_RUN([
404 #ifdef HAVE_UNISTD_H
405 #  include <unistd.h>
406 #endif
407 #ifndef __STDC__
408 #  ifndef const
409 #    define const
410 #  endif
411 #endif
412 char *
413 getenv (name)
414 #if defined (__linux__) || defined (__bsdi__) || defined (convex)
415      const char *name;
416 #else
417      char const *name;
418 #endif /* !__linux__ && !__bsdi__ && !convex */
419 {
420 return "42";
421 }
422 main()
423 {
424 char *s;
425 /* The next allows this program to run, but does not allow bash to link
426    when it redefines getenv.  I'm not really interested in figuring out
427    why not. */
428 #if defined (NeXT)
429 exit(1);
430 #endif
431 s = getenv("ABCDE");
432 exit(s == 0);   /* force optimizer to leave getenv in */
433 }
434 ], bash_cv_getenv_redef=yes, bash_cv_getenv_redef=no,
435 AC_MSG_ERROR(cannot check getenv redefinition if cross compiling))])
436 AC_MSG_RESULT($bash_cv_getenv_redef)
437 if test $bash_cv_getenv_redef = yes; then
438 AC_DEFINE(CAN_REDEFINE_GETENV)
439 fi
440 ])
441
442 AC_DEFUN(BASH_FUNC_PRINTF,
443 [AC_MSG_CHECKING(for declaration of printf in <stdio.h>)
444 AC_CACHE_VAL(bash_cv_printf_declared,
445 [AC_TRY_RUN([
446 #include <stdio.h>
447 #ifdef __STDC__
448 typedef int (*_bashfunc)(const char *, ...);
449 #else
450 typedef int (*_bashfunc)();
451 #endif
452 main()
453 {
454 _bashfunc pf;
455 pf = (_bashfunc) printf;
456 exit(pf == 0);
457 }
458 ],bash_cv_printf_declared=yes, bash_cv_printf_declared=no,
459 AC_MSG_ERROR(cannot check printf declaration if cross compiling))])
460 AC_MSG_RESULT($bash_cv_printf_declared)
461 if test $bash_cv_printf_declared = yes; then
462 AC_DEFINE(PRINTF_DECLARED)
463 fi
464 ])
465
466 AC_DEFUN(BASH_FUNC_ULIMIT_MAXFDS,
467 [AC_MSG_CHECKING(whether ulimit can substitute for getdtablesize)
468 AC_CACHE_VAL(bash_cv_ulimit_maxfds,
469 [AC_TRY_RUN([
470 main()
471 {
472 long maxfds = ulimit(4, 0L);
473 exit (maxfds == -1L);
474 }
475 ],bash_cv_ulimit_maxfds=yes, bash_cv_ulimit_maxfds=no,
476 AC_MSG_ERROR(cannot check ulimit if cross compiling))])
477 AC_MSG_RESULT($bash_cv_ulimit_maxfds)
478 if test $bash_cv_ulimit_maxfds = yes; then
479 AC_DEFINE(ULIMIT_MAXFDS)
480 fi
481 ])
482
483 AC_DEFUN(BASH_CHECK_LIB_TERMCAP,
484 [
485 if test "X$bash_cv_termcap_lib" = "X"; then
486 _bash_needmsg=yes
487 else
488 AC_MSG_CHECKING(which library has the termcap functions)
489 _bash_needmsg=
490 fi
491 AC_CACHE_VAL(bash_cv_termcap_lib,
492 [AC_CHECK_LIB(termcap, tgetent, bash_cv_termcap_lib=libtermcap,
493     [AC_CHECK_LIB(curses, tgetent, bash_cv_termcap_lib=libcurses,
494         [AC_CHECK_LIB(ncurses, tgetent, bash_cv_termcap_lib=libncurses,
495             bash_cv_termcap_lib=gnutermcap)])])])
496 if test "X$_bash_needmsg" = "Xyes"; then
497 AC_MSG_CHECKING(which library has the termcap functions)
498 fi
499 AC_MSG_RESULT(using $bash_cv_termcap_lib)
500 if test $bash_cv_termcap_lib = gnutermcap; then
501 LDFLAGS="$LDFLAGS -L./lib/termcap"
502 TERMCAP_LIB="./lib/termcap/libtermcap.a"
503 TERMCAP_DEP="./lib/termcap/libtermcap.a"
504 elif test $bash_cv_termcap_lib = libtermcap && test -z "$prefer_curses"; then
505 TERMCAP_LIB=-ltermcap
506 TERMCAP_DEP=
507 elif test $bash_cv_termcap_lib = libncurses; then
508 TERMCAP_LIB=-lncurses
509 TERMCAP_DEP=
510 else
511 TERMCAP_LIB=-lcurses
512 TERMCAP_DEP=
513 fi
514 ])
515
516 AC_DEFUN(BASH_FUNC_GETCWD,
517 [AC_MSG_CHECKING([if getcwd() calls popen()])
518 AC_CACHE_VAL(bash_cv_getcwd_calls_popen,
519 [AC_TRY_RUN([
520 #include <stdio.h>
521 #ifdef HAVE_UNISTD_H
522 #include <unistd.h>
523 #endif
524
525 #ifndef __STDC__
526 #ifndef const
527 #define const
528 #endif
529 #endif
530
531 int popen_called;
532
533 FILE *
534 popen(command, type)
535      const char *command;
536      const char *type;
537 {
538         popen_called = 1;
539         return (FILE *)NULL;
540 }
541
542 FILE *_popen(command, type)
543      const char *command;
544      const char *type;
545 {
546   return (popen (command, type));
547 }
548
549 int
550 pclose(stream)
551 FILE *stream;
552 {
553         return 0;
554 }
555
556 int
557 _pclose(stream)
558 FILE *stream;
559 {
560         return 0;
561 }
562
563 main()
564 {
565         char    lbuf[32];
566         popen_called = 0;
567         getcwd(lbuf, 32);
568         exit (popen_called);
569 }
570 ], bash_cv_getcwd_calls_popen=no, bash_cv_getcwd_calls_popen=yes,
571 AC_MSG_ERROR(cannot check whether getcwd calls popen if cross compiling))])
572 AC_MSG_RESULT($bash_cv_getcwd_calls_popen)
573 if test $bash_cv_getcwd_calls_popen = yes; then
574 AC_DEFINE(GETCWD_BROKEN)
575 fi
576 ])
577
578 AC_DEFUN(BASH_STRUCT_DIRENT_D_INO,
579 [AC_REQUIRE([AC_HEADER_DIRENT])
580 AC_MSG_CHECKING(if struct dirent has a d_ino member)
581 AC_CACHE_VAL(bash_cv_dirent_has_dino,
582 [AC_TRY_COMPILE([
583 #include <stdio.h>
584 #include <sys/types.h>
585 #ifdef HAVE_UNISTD_H
586 # include <unistd.h>
587 #endif /* HAVE_UNISTD_H */
588 #if defined(HAVE_DIRENT_H)
589 # include <dirent.h>
590 #else
591 # define dirent direct
592 # ifdef HAVE_SYS_NDIR_H
593 #  include <sys/ndir.h>
594 # endif /* SYSNDIR */
595 # ifdef HAVE_SYS_DIR_H
596 #  include <sys/dir.h>
597 # endif /* SYSDIR */
598 # ifdef HAVE_NDIR_H
599 #  include <ndir.h>
600 # endif
601 #endif /* HAVE_DIRENT_H */
602 ],[
603 struct dirent d; int z; z = d.d_ino;
604 ], bash_cv_dirent_has_dino=yes, bash_cv_dirent_has_dino=no)])
605 AC_MSG_RESULT($bash_cv_dirent_has_dino)
606 if test $bash_cv_dirent_has_dino = yes; then
607 AC_DEFINE(STRUCT_DIRENT_HAS_D_INO)
608 fi
609 ])
610
611 AC_DEFUN(BASH_STRUCT_DIRENT_D_FILENO,
612 [AC_REQUIRE([AC_HEADER_DIRENT])
613 AC_MSG_CHECKING(if struct dirent has a d_fileno member)
614 AC_CACHE_VAL(bash_cv_dirent_has_d_fileno,
615 [AC_TRY_COMPILE([
616 #include <stdio.h>
617 #include <sys/types.h>
618 #ifdef HAVE_UNISTD_H
619 # include <unistd.h>
620 #endif /* HAVE_UNISTD_H */
621 #if defined(HAVE_DIRENT_H)
622 # include <dirent.h>
623 #else
624 # define dirent direct
625 # ifdef HAVE_SYS_NDIR_H
626 #  include <sys/ndir.h>
627 # endif /* SYSNDIR */
628 # ifdef HAVE_SYS_DIR_H
629 #  include <sys/dir.h>
630 # endif /* SYSDIR */
631 # ifdef HAVE_NDIR_H
632 #  include <ndir.h>
633 # endif
634 #endif /* HAVE_DIRENT_H */
635 ],[
636 struct dirent d; int z; z = d.d_fileno;
637 ], bash_cv_dirent_has_d_fileno=yes, bash_cv_dirent_has_d_fileno=no)])
638 AC_MSG_RESULT($bash_cv_dirent_has_d_fileno)
639 if test $bash_cv_dirent_has_d_fileno = yes; then
640 AC_DEFINE(STRUCT_DIRENT_HAS_D_FILENO)
641 fi
642 ])
643
644 AC_DEFUN(BASH_REINSTALL_SIGHANDLERS,
645 [AC_REQUIRE([AC_TYPE_SIGNAL])
646 AC_REQUIRE([BASH_SIGNAL_CHECK])
647 AC_MSG_CHECKING([if signal handlers must be reinstalled when invoked])
648 AC_CACHE_VAL(bash_cv_must_reinstall_sighandlers,
649 [AC_TRY_RUN([
650 #include <signal.h>
651 #ifdef HAVE_UNISTD_H
652 #include <unistd.h>
653 #endif
654
655 typedef RETSIGTYPE sigfunc();
656
657 int nsigint;
658
659 #ifdef HAVE_POSIX_SIGNALS
660 sigfunc *
661 set_signal_handler(sig, handler)
662      int sig;
663      sigfunc *handler;
664 {
665   struct sigaction act, oact;
666   act.sa_handler = handler;
667   act.sa_flags = 0;
668   sigemptyset (&act.sa_mask);
669   sigemptyset (&oact.sa_mask);
670   sigaction (sig, &act, &oact);
671   return (oact.sa_handler);
672 }
673 #else
674 #define set_signal_handler(s, h) signal(s, h)
675 #endif
676
677 RETSIGTYPE
678 sigint(s)
679 int s;
680 {
681   nsigint++;
682 }
683
684 main()
685 {
686         nsigint = 0;
687         set_signal_handler(SIGINT, sigint);
688         kill((int)getpid(), SIGINT);
689         kill((int)getpid(), SIGINT);
690         exit(nsigint != 2);
691 }
692 ], bash_cv_must_reinstall_sighandlers=no, bash_cv_must_reinstall_sighandlers=yes,
693 AC_MSG_ERROR(cannot check signal handling if cross compiling))])
694 AC_MSG_RESULT($bash_cv_must_reinstall_sighandlers)
695 if test $bash_cv_must_reinstall_sighandlers = yes; then
696 AC_DEFINE(MUST_REINSTALL_SIGHANDLERS)
697 fi
698 ])
699
700 AC_DEFUN(BASH_FUNC_SBRK_DECLARED,
701 [AC_MSG_CHECKING(for declaration of sbrk in <unistd.h>)
702 AC_CACHE_VAL(bash_cv_sbrk_declared,
703 [AC_EGREP_HEADER(sbrk, unistd.h,
704  bash_cv_sbrk_declared=yes, bash_cv_sbrk_declared=no)])
705 AC_MSG_RESULT($bash_cv_sbrk_declared)
706 if test $bash_cv_sbrk_declared = yes; then
707 AC_DEFINE(SBRK_DECLARED)
708 fi
709 ])
710
711 dnl check that some necessary job control definitions are present
712 AC_DEFUN(BASH_JOB_CONTROL_MISSING,
713 [AC_REQUIRE([BASH_SIGNAL_CHECK])
714 AC_MSG_CHECKING(for presence of necessary job control definitions)
715 AC_CACHE_VAL(bash_cv_job_control_missing,
716 [AC_TRY_RUN([
717 #include <sys/types.h>
718 #ifdef HAVE_SYS_WAIT_H
719 #include <sys/wait.h>
720 #endif
721 #ifdef HAVE_UNISTD_H
722 #include <unistd.h>
723 #endif
724 #include <signal.h>
725
726 /* Add more tests in here as appropriate. */
727 main()
728 {
729 /* signal type */
730 #if !defined (HAVE_POSIX_SIGNALS) && !defined (HAVE_BSD_SIGNALS)
731 exit(1);
732 #endif
733
734 /* signals and tty control. */
735 #if !defined (SIGTSTP) || !defined (SIGSTOP) || !defined (SIGCONT)
736 exit (1);
737 #endif
738
739 /* process control */
740 #if !defined (WNOHANG) || !defined (WUNTRACED) 
741 exit(1);
742 #endif
743
744 /* Posix systems have tcgetpgrp and waitpid. */
745 #if defined (_POSIX_VERSION) && !defined (HAVE_TCGETPGRP)
746 exit(1);
747 #endif
748
749 #if defined (_POSIX_VERSION) && !defined (HAVE_WAITPID)
750 exit(1);
751 #endif
752
753 /* Other systems have TIOCSPGRP/TIOCGPRGP and wait3. */
754 #if !defined (_POSIX_VERSION) && !defined (HAVE_WAIT3)
755 exit(1);
756 #endif
757
758 exit(0);
759 }],bash_cv_job_control_missing=present, bash_cv_job_control_missing=missing,
760         AC_MSG_ERROR(cannot check job control if cross-compiling))
761 ])
762 AC_MSG_RESULT($bash_cv_job_control_missing)
763 if test $bash_cv_job_control_missing = missing; then
764 AC_DEFINE(JOB_CONTROL_MISSING)
765 fi
766 ])
767
768 dnl check whether named pipes are present
769 dnl this requires a previous check for mkfifo, but that is awkward to specify
770 AC_DEFUN(BASH_SYS_NAMED_PIPES,
771 [AC_MSG_CHECKING(for presence of named pipes)
772 AC_CACHE_VAL(bash_cv_sys_named_pipes,
773 [AC_TRY_RUN([
774 #include <sys/types.h>
775 #include <sys/stat.h>
776 #ifdef HAVE_UNISTD_H
777 #include <unistd.h>
778 #endif
779
780 /* Add more tests in here as appropriate. */
781 main()
782 {
783 int fd;
784
785 #if defined (HAVE_MKFIFO)
786 exit (0);
787 #endif
788
789 #if !defined (S_IFIFO) && (defined (_POSIX_VERSION) && !defined (S_ISFIFO))
790 exit (1);
791 #endif
792
793 #if defined (NeXT)
794 exit (1);
795 #endif
796
797 fd = mknod ("/tmp/sh-np-autoconf", 0666 | S_IFIFO, 0);
798 if (fd == -1)
799   exit (1);
800 close(fd);
801 unlink ("/tmp/sh-np-autoconf");
802 exit(0);
803 }],bash_cv_sys_named_pipes=present, bash_cv_sys_named_pipes=missing,
804         AC_MSG_ERROR(cannot check for named pipes if cross-compiling))
805 ])
806 AC_MSG_RESULT($bash_cv_sys_named_pipes)
807 if test $bash_cv_sys_named_pipes = missing; then
808 AC_DEFINE(NAMED_PIPES_MISSING)
809 fi
810 ])
811
812 AC_DEFUN(BASH_FUNC_POSIX_SETJMP,
813 [AC_REQUIRE([BASH_SIGNAL_CHECK])
814 AC_MSG_CHECKING(for presence of POSIX-style sigsetjmp/siglongjmp)
815 AC_CACHE_VAL(bash_cv_func_sigsetjmp,
816 [AC_TRY_RUN([
817 #ifdef HAVE_UNISTD_H
818 #include <unistd.h>
819 #endif
820 #include <sys/types.h>
821 #include <signal.h>
822 #include <setjmp.h>
823
824 main()
825 {
826 #if !defined (_POSIX_VERSION) || !defined (HAVE_POSIX_SIGNALS)
827 exit (1);
828 #else
829
830 int code;
831 sigset_t set, oset;
832 sigjmp_buf xx;
833
834 /* get the mask */
835 sigemptyset(&set);
836 sigemptyset(&oset);
837 sigprocmask(SIG_BLOCK, (sigset_t *)NULL, &set);
838 sigprocmask(SIG_BLOCK, (sigset_t *)NULL, &oset);
839
840 /* save it */
841 code = sigsetjmp(xx, 1);
842 if (code)
843   exit(0);      /* could get sigmask and compare to oset here. */
844
845 /* change it */
846 sigaddset(&set, SIGINT);
847 sigprocmask(SIG_BLOCK, &set, (sigset_t *)NULL);
848
849 /* and siglongjmp */
850 siglongjmp(xx, 10);
851 exit(1);
852 #endif
853 }],bash_cv_func_sigsetjmp=present, bash_cv_func_sigsetjmp=missing,
854    AC_MSG_ERROR(cannot check for sigsetjmp/siglongjmp if cross-compiling))
855 ])
856 AC_MSG_RESULT($bash_cv_func_sigsetjmp)
857 if test $bash_cv_func_sigsetjmp = present; then
858 AC_DEFINE(HAVE_POSIX_SIGSETJMP)
859 fi
860 ])
861
862 AC_DEFUN(BASH_HAVE_TIOCGWINSZ,
863 [AC_MSG_CHECKING(for TIOCGWINSZ in sys/ioctl.h)
864 AC_CACHE_VAL(bash_cv_tiocgwinsz_in_ioctl,
865 [AC_TRY_COMPILE([#include <sys/types.h>
866 #include <sys/ioctl.h>], [int x = TIOCGWINSZ;],
867   bash_cv_tiocgwinsz_in_ioctl=yes,bash_cv_tiocgwinsz_in_ioctl=no)])
868 AC_MSG_RESULT($bash_cv_tiocgwinsz_in_ioctl)
869 if test $bash_cv_tiocgwinsz_in_ioctl = yes; then   
870 AC_DEFINE(GWINSZ_IN_SYS_IOCTL)
871 fi
872 ])
873
874 AC_DEFUN(BASH_STRUCT_WINSIZE,
875 [AC_MSG_CHECKING(for struct winsize in sys/ioctl.h)
876 AC_CACHE_VAL(bash_cv_struct_winsize_in_ioctl,
877 [AC_TRY_COMPILE([#include <sys/types.h>
878 #include <sys/ioctl.h>], [struct winsize x;],
879   bash_cv_struct_winsize_in_ioctl=yes,bash_cv_struct_winsize_in_ioctl=no)])
880 AC_MSG_RESULT($bash_cv_struct_winsize_in_ioctl)
881 if test $bash_cv_struct_winsize_in_ioctl = yes; then   
882 AC_DEFINE(STRUCT_WINSIZE_IN_SYS_IOCTL)
883 fi
884 ])
885
886 AC_DEFUN(BASH_HAVE_TIOCSTAT,
887 [AC_MSG_CHECKING(for TIOCSTAT in sys/ioctl.h)
888 AC_CACHE_VAL(bash_cv_tiocstat_in_ioctl,
889 [AC_TRY_COMPILE([#include <sys/types.h>
890 #include <sys/ioctl.h>], [int x = TIOCSTAT;],
891   bash_cv_tiocstat_in_ioctl=yes,bash_cv_tiocstat_in_ioctl=no)])
892 AC_MSG_RESULT($bash_cv_tiocstat_in_ioctl)
893 if test $bash_cv_tiocstat_in_ioctl = yes; then   
894 AC_DEFINE(TIOCSTAT_IN_SYS_IOCTL)
895 fi
896 ])
897
898 AC_DEFUN(BASH_HAVE_FIONREAD,
899 [AC_MSG_CHECKING(for FIONREAD in sys/ioctl.h)
900 AC_CACHE_VAL(bash_cv_fionread_in_ioctl,
901 [AC_TRY_COMPILE([#include <sys/types.h>
902 #include <sys/ioctl.h>], [int x = FIONREAD;],
903   bash_cv_fionread_in_ioctl=yes,bash_cv_fionread_in_ioctl=no)])
904 AC_MSG_RESULT($bash_cv_fionread_in_ioctl)
905 if test $bash_cv_fionread_in_ioctl = yes; then   
906 AC_DEFINE(FIONREAD_IN_SYS_IOCTL)
907 fi
908 ])
909
910 dnl
911 dnl See if speed_t is declared in <sys/types.h>.  Some versions of linux
912 dnl require a definition of speed_t each time <termcap.h> is included,
913 dnl but you can only get speed_t if you include <termios.h> (on some
914 dnl versions) or <sys/types.h> (on others).
915 dnl
916 AC_DEFUN(BASH_MISC_SPEED_T,
917 [AC_MSG_CHECKING(for speed_t in sys/types.h)
918 AC_CACHE_VAL(bash_cv_speed_t_in_sys_types,
919 [AC_TRY_COMPILE([#include <sys/types.h>], [speed_t x;],
920   bash_cv_speed_t_in_sys_types=yes,bash_cv_speed_t_in_sys_types=no)])
921 AC_MSG_RESULT($bash_cv_speed_t_in_sys_types)
922 if test $bash_cv_speed_t_in_sys_types = yes; then   
923 AC_DEFINE(SPEED_T_IN_SYS_TYPES)
924 fi
925 ])
926
927 AC_DEFUN(BASH_CHECK_GETPW_FUNCS,
928 [AC_MSG_CHECKING(whether programs are able to redeclare getpw functions)
929 AC_CACHE_VAL(bash_cv_can_redecl_getpw,
930 [AC_TRY_COMPILE([#include <sys/types.h>
931 #include <pwd.h>
932 extern struct passwd *getpwent();
933 extern struct passwd *getpwuid();
934 extern struct passwd *getpwnam();],
935 [struct passwd *z; z = getpwent(); z = getpwuid(0); z = getpwnam("root");],
936   bash_cv_can_redecl_getpw=yes,bash_cv_can_redecl_getpw=no)])
937 AC_MSG_RESULT($bash_cv_can_redecl_getpw)
938 if test $bash_cv_can_redecl_getpw = no; then
939 AC_DEFINE(HAVE_GETPW_DECLS)
940 fi
941 ])
942
943 AC_DEFUN(BASH_CHECK_DEV_FD,
944 [AC_MSG_CHECKING(whether /dev/fd is available)
945 AC_CACHE_VAL(bash_cv_dev_fd,
946 [if test -d /dev/fd  && test -r /dev/fd/0; then
947    bash_cv_dev_fd=standard
948  elif test -d /proc/self/fd && test -r /proc/self/fd/0; then
949    bash_cv_dev_fd=whacky
950  else
951    bash_cv_dev_fd=absent
952  fi
953 ])
954 AC_MSG_RESULT($bash_cv_dev_fd)
955 if test $bash_cv_dev_fd = "standard"; then
956   AC_DEFINE(HAVE_DEV_FD)
957   AC_DEFINE(DEV_FD_PREFIX, "/dev/fd/")
958 elif test $bash_cv_dev_fd = "whacky"; then
959   AC_DEFINE(HAVE_DEV_FD)
960   AC_DEFINE(DEV_FD_PREFIX, "/proc/self/fd/")
961 fi
962 ])
963
964 dnl
965 dnl Check for the presence of getpeername (the only networking function
966 dnl bash currently requires) in libsocket.  If libsocket is present,
967 dnl check for libnsl and add it to LIBS if it's there, since most
968 dnl systems with libsocket require linking with libnsl as well.
969 dnl This should only be called if getpeername was not found in libc.
970 dnl
971 AC_DEFUN(BASH_CHECK_SOCKLIB,
972 [
973 if test "X$bash_cv_have_socklib" = "X"; then
974 _bash_needmsg=
975 else
976 AC_MSG_CHECKING(for socket library)
977 _bash_needmsg=yes
978 fi
979 AC_CACHE_VAL(bash_cv_have_socklib,
980 [AC_CHECK_LIB(socket, getpeername,
981         bash_cv_have_socklib=yes, bash_cv_have_socklib=no, -lnsl)])
982 if test "X$_bash_needmsg" = Xyes; then
983   AC_MSG_RESULT($bash_cv_have_socklib)
984   _bash_needmsg=
985 fi
986 if test $bash_cv_have_socklib = yes; then
987   # check for libnsl, add it to LIBS if present
988   if test "X$bash_cv_have_libnsl" = "X"; then
989     _bash_needmsg=
990   else
991     AC_MSG_CHECKING(for libnsl)
992     _bash_needmsg=yes
993   fi
994   AC_CACHE_VAL(bash_cv_have_libnsl,
995            [AC_CHECK_LIB(nsl, t_open,
996                  bash_cv_have_libnsl=yes, bash_cv_have_libnsl=no)])
997   if test "X$_bash_needmsg" = Xyes; then
998     AC_MSG_RESULT($bash_cv_have_libnsl)
999     _bash_needmsg=
1000   fi
1001   if test $bash_cv_have_libnsl = yes; then
1002     LIBS="-lsocket -lnsl $LIBS"
1003   else
1004     LIBS="-lsocket $LIBS"
1005   fi
1006   AC_DEFINE(HAVE_LIBSOCKET)
1007   AC_DEFINE(HAVE_GETPEERNAME)
1008 fi
1009 ])
1010
1011 AC_DEFUN(BASH_DEFAULT_MAIL_DIR,
1012 [AC_MSG_CHECKING(for default mail directory)
1013 AC_CACHE_VAL(bash_cv_mail_dir,
1014 [if test -d /var/mail; then
1015    bash_cv_mail_dir=/var/mail
1016  elif test -d /usr/mail; then
1017    bash_cv_mail_dir=/usr/mail
1018  elif test -d /var/spool/mail; then
1019    bash_cv_mail_dir=/var/spool/mail
1020  elif test -d /usr/spool/mail; then
1021    bash_cv_mail_dir=/usr/spool/mail
1022  else
1023    bash_cv_mail_dir=unknown
1024  fi
1025 ])
1026 AC_MSG_RESULT($bash_cv_mail_dir)
1027 if test $bash_cv_mail_dir = "/var/mail"; then
1028    AC_DEFINE(DEFAULT_MAIL_DIRECTORY, "/var/mail")
1029 elif test $bash_cv_mail_dir = "/usr/mail"; then
1030    AC_DEFINE(DEFAULT_MAIL_DIRECTORY, "/usr/mail")
1031 elif test $bash_cv_mail_dir = "/var/spool/mail"; then
1032    AC_DEFINE(DEFAULT_MAIL_DIRECTORY, "/var/spool/mail")
1033 elif test $bash_cv_mail_dir = "/usr/spool/mail"; then
1034    AC_DEFINE(DEFAULT_MAIL_DIRECTORY, "/usr/spool/mail")
1035 else
1036    AC_DEFINE(DEFAULT_MAIL_DIRECTORY, "unknown")
1037 fi
1038 ])
1039
1040 dnl
1041 dnl Check if HPUX needs _KERNEL defined for RLIMIT_* definitions
1042 dnl
1043 AC_DEFUN(BASH_KERNEL_RLIMIT_CHECK,
1044 [AC_MSG_CHECKING([whether $host_os needs _KERNEL for RLIMIT defines])
1045 AC_CACHE_VAL(bash_cv_kernel_rlimit,
1046 [AC_TRY_COMPILE([
1047 #include <sys/types.h>
1048 #include <sys/resource.h>
1049 ],
1050 [
1051   int f;
1052   f = RLIMIT_DATA;
1053 ], bash_cv_kernel_rlimit=no,
1054     [AC_TRY_COMPILE([
1055      #include <sys/types.h>
1056      #define _KERNEL
1057      #include <sys/resource.h>
1058      #undef _KERNEL
1059      ],
1060      [
1061         int f;
1062         f = RLIMIT_DATA;
1063      ], bash_cv_kernel_rlimit=yes, bash_cv_kernel_rlimit=no)]
1064 )])
1065 AC_MSG_RESULT($bash_cv_kernel_rlimit)
1066 if test $bash_cv_kernel_rlimit = yes; then
1067 AC_DEFINE(RLIMIT_NEEDS_KERNEL)
1068 fi
1069 ])
1070
1071 AC_DEFUN(BASH_FUNC_STRCOLL,
1072 [
1073 AC_MSG_CHECKING(whether or not strcoll and strcmp differ)
1074 AC_CACHE_VAL(bash_cv_func_strcoll_broken,
1075 [AC_TRY_RUN([
1076 #include <stdio.h>
1077 #if defined (HAVE_LOCALE_H)
1078 #include <locale.h>
1079 #endif
1080
1081 main(c, v)
1082 int     c;
1083 char    *v[];
1084 {
1085         int     r1, r2;
1086         char    *deflocale, *defcoll;
1087
1088 #ifdef HAVE_SETLOCALE
1089         deflocale = setlocale(LC_ALL, "");
1090         defcoll = setlocale(LC_COLLATE, "");
1091 #endif
1092
1093 #ifdef HAVE_STRCOLL
1094         /* These two values are taken from tests/glob-test. */
1095         r1 = strcoll("abd", "aXd");
1096 #else
1097         r1 = 0;
1098 #endif
1099         r2 = strcmp("abd", "aXd");
1100
1101         /* These two should both be greater than 0.  It is permissible for
1102            a system to return different values, as long as the sign is the
1103            same. */
1104
1105         /* Exit with 1 (failure) if these two values are both > 0, since
1106            this tests whether strcoll(3) is broken with respect to strcmp(3)
1107            in the default locale. */
1108         exit (r1 > 0 && r2 > 0);
1109 }
1110 ], bash_cv_func_strcoll_broken=yes, bash_cv_func_strcoll_broken=no,
1111    AC_MSG_ERROR(cannot check strcoll if cross compiling))
1112 ])
1113 AC_MSG_RESULT($bash_cv_func_strcoll_broken)
1114 if test $bash_cv_func_strcoll_broken = yes; then
1115 AC_DEFINE(STRCOLL_BROKEN)
1116 fi
1117 ])