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