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