blob: 68f36e725d2c4c8f1c69f39e40107e6cd09231da [file] [log] [blame]
Roland McGrath6d2b3492002-12-30 00:51:30 +00001dnl
2dnl This file contains macros used in configure.ac.
3dnl automake uses this file to generate aclocal.m4, which is used by autoconf.
4dnl
5
6dnl ### A macro to find the include directory, useful for cross-compiling.
7AC_DEFUN(AC_INCLUDEDIR,
8[AC_REQUIRE([AC_PROG_AWK])dnl
9AC_SUBST(includedir)
10AC_MSG_CHECKING(for primary include directory)
11includedir=/usr/include
12if test -n "$GCC"
13then
14 >conftest.c
15 new_includedir=`
16 $CC -v -E conftest.c 2>&1 | $AWK '
17 /^End of search list/ { print last; exit }
18 { last = [$]1 }
19 '
20 `
21 rm -f conftest.c
22 if test -n "$new_includedir" && test -d "$new_includedir"
23 then
24 includedir=$new_includedir
25 fi
26fi
27AC_MSG_RESULT($includedir)
28])
29
30dnl ### A macro to set gcc warning flags.
31define(AC_WARNFLAGS,
32[AC_SUBST(WARNFLAGS)
33if test -z "$WARNFLAGS"
34then
35 if test -n "$GCC"
36 then
37 # If we're using gcc we want warning flags.
38 WARNFLAGS=-Wall
39 fi
40fi
41])
42
43dnl ### A macro to determine if we have a "MP" type procfs
44AC_DEFUN(AC_MP_PROCFS,
45[AC_MSG_CHECKING(for MP procfs)
46AC_CACHE_VAL(ac_cv_mp_procfs,
47[AC_RUN_IFELSE([AC_LANG_SOURCE([[
48#include <stdio.h>
49#include <signal.h>
50#include <sys/procfs.h>
51
52main()
53{
54 int pid;
55 char proc[32];
56 FILE *ctl;
57 FILE *status;
58 int cmd;
59 struct pstatus pstatus;
60
61 if ((pid = fork()) == 0) {
62 pause();
63 exit(0);
64 }
65 sprintf(proc, "/proc/%d/ctl", pid);
66 if ((ctl = fopen(proc, "w")) == NULL)
67 goto fail;
68 sprintf(proc, "/proc/%d/status", pid);
69 if ((status = fopen (proc, "r")) == NULL)
70 goto fail;
71 cmd = PCSTOP;
72 if (write (fileno (ctl), &cmd, sizeof cmd) < 0)
73 goto fail;
74 if (read (fileno (status), &pstatus, sizeof pstatus) < 0)
75 goto fail;
76 kill(pid, SIGKILL);
77 exit(0);
78fail:
79 kill(pid, SIGKILL);
80 exit(1);
81}
82]])],[ac_cv_mp_procfs=yes],[ac_cv_mp_procfs=no],[
83# Guess or punt.
84case "$host_os" in
85svr4.2*|svr5*)
86 ac_cv_mp_procfs=yes
87 ;;
88*)
89 ac_cv_mp_procfs=no
90 ;;
91esac
92])])
93AC_MSG_RESULT($ac_cv_mp_procfs)
94if test "$ac_cv_mp_procfs" = yes
95then
96 AC_DEFINE([HAVE_MP_PROCFS], 1,
97[Define if you have a SVR4 MP type procfs.
98I.E. /dev/xxx/ctl, /dev/xxx/status.
99Also implies that you have the pr_lwp member in prstatus.])
100fi
101])
102
103dnl ### A macro to determine if procfs is pollable.
104AC_DEFUN(AC_POLLABLE_PROCFS,
105[AC_MSG_CHECKING(for pollable procfs)
106AC_CACHE_VAL(ac_cv_pollable_procfs,
107[AC_RUN_IFELSE([AC_LANG_SOURCE([[
108#include <stdio.h>
109#include <signal.h>
110#include <sys/procfs.h>
111#include <sys/stropts.h>
112#include <poll.h>
113
114#ifdef HAVE_MP_PROCFS
115#define PIOCSTOP PCSTOP
116#define POLLWANT POLLWRNORM
117#define PROC "/proc/%d/ctl"
118#define PROC_MODE "w"
119int IOCTL (int fd, int cmd, int arg) {
120 return write (fd, &cmd, sizeof cmd);
121}
122#else
123#define POLLWANT POLLPRI
124#define PROC "/proc/%d"
125#define PROC_MODE "r+"
126#define IOCTL ioctl
127#endif
128
129main()
130{
131 int pid;
132 char proc[32];
133 FILE *pfp;
134 struct pollfd pfd;
135
136 if ((pid = fork()) == 0) {
137 pause();
138 exit(0);
139 }
140 sprintf(proc, PROC, pid);
141 if ((pfp = fopen(proc, PROC_MODE)) == NULL)
142 goto fail;
143 if (IOCTL(fileno(pfp), PIOCSTOP, NULL) < 0)
144 goto fail;
145 pfd.fd = fileno(pfp);
146 pfd.events = POLLWANT;
147 if (poll(&pfd, 1, 0) < 0)
148 goto fail;
149 if (!(pfd.revents & POLLWANT))
150 goto fail;
151 kill(pid, SIGKILL);
152 exit(0);
153fail:
154 kill(pid, SIGKILL);
155 exit(1);
156}
157]])],[ac_cv_pollable_procfs=yes],[ac_cv_pollable_procfs=no],[
158# Guess or punt.
159case "$host_os" in
160solaris2*|irix5*|svr4.2uw*|svr5*)
161 ac_cv_pollable_procfs=yes
162 ;;
163*)
164 ac_cv_pollable_procfs=no
165 ;;
166esac
167])])
168AC_MSG_RESULT($ac_cv_pollable_procfs)
169if test "$ac_cv_pollable_procfs" = yes
170then
171 AC_DEFINE([HAVE_POLLABLE_PROCFS], 1,
172[Define if you have SVR4 and the poll system call works on /proc files.])
173fi
174])
175
176dnl ### A macro to determine if the prstatus structure has a pr_syscall member.
177AC_DEFUN(AC_STRUCT_PR_SYSCALL,
178[AC_MSG_CHECKING(for pr_syscall in struct prstatus)
179AC_CACHE_VAL(ac_cv_struct_pr_syscall,
180[AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/procfs.h>]], [[#ifdef HAVE_MP_PROCFS
181pstatus_t s;
182s.pr_lwp.pr_syscall
183#else
184prstatus_t s;
185s.pr_syscall
186#endif]])],[ac_cv_struct_pr_syscall=yes],[ac_cv_struct_pr_syscall=no])])
187AC_MSG_RESULT($ac_cv_struct_pr_syscall)
188if test "$ac_cv_struct_pr_syscall" = yes
189then
190 AC_DEFINE([HAVE_PR_SYSCALL], 1,
191[Define if the prstatus structure in sys/procfs.h has a pr_syscall member.])
192fi
193])
194
195dnl ### A macro to determine whether stat64 is defined.
196AC_DEFUN(AC_STAT64,
197[AC_MSG_CHECKING(for stat64 in (asm|sys)/stat.h)
198AC_CACHE_VAL(ac_cv_type_stat64,
199[AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#ifdef LINUX
200#include <linux/types.h>
201#include <asm/stat.h>
202#else
203#include <sys/stat.h>
204#endif]], [[struct stat64 st;]])],[ac_cv_type_stat64=yes],[ac_cv_type_stat64=no])])
205AC_MSG_RESULT($ac_cv_type_stat64)
206if test "$ac_cv_type_stat64" = yes
207then
208 AC_DEFINE([HAVE_STAT64], 1,
209[Define if stat64 is available in asm/stat.h.])
210fi
211])
212
213dnl ### A macro to determine if off_t is a long long
214AC_DEFUN(AC_OFF_T_IS_LONG_LONG,
215[AC_MSG_CHECKING(for long long off_t)
216AC_CACHE_VAL(ac_cv_have_long_long_off_t,
217[AC_RUN_IFELSE([AC_LANG_SOURCE([[#include <sys/types.h>
218main () {
219 if (sizeof (off_t) == sizeof (long long) &&
220 sizeof (off_t) > sizeof (long))
221 return 0;
222 return 1;
223}
224]])],[ac_cv_have_long_long_off_t=yes],[ac_cv_have_long_long_off_t=no],[# Should try to guess here
225ac_cv_have_long_long_off_t=no
226])])
227AC_MSG_RESULT($ac_cv_have_long_long_off_t)
228if test "$ac_cv_have_long_long_off_t" = yes
229then
230 AC_DEFINE([HAVE_LONG_LONG_OFF_T], 1, [Define if off_t is a long long.])
231fi
232])
233
234dnl ### A macro to determine if rlim_t is a long long
235AC_DEFUN(AC_RLIM_T_IS_LONG_LONG,
236[AC_MSG_CHECKING(for long long rlim_t)
237AC_CACHE_VAL(ac_cv_have_long_long_rlim_t,
238[AC_RUN_IFELSE([AC_LANG_SOURCE([[#include <sys/types.h>
239#include <sys/time.h>
240#include <sys/resource.h>
241main () {
242 if (sizeof (rlim_t) == sizeof (long long) &&
243 sizeof (rlim_t) > sizeof (long))
244 return 0;
245 return 1;
246}
247]])],[ac_cv_have_long_long_rlim_t=yes],[ac_cv_have_long_long_rlim_t=no],[# Should try to guess here
248ac_cv_have_long_long_rlim_t=no
249])])
250AC_MSG_RESULT($ac_cv_have_long_long_rlim_t)
251if test "$ac_cv_have_long_long_rlim_t" = yes
252then
253 AC_DEFINE([HAVE_LONG_LONG_RLIM_T], 1, [Define if rlim_t is a long long.])
254fi
255])
256
257dnl ### A macro to determine endianness of long long
258AC_DEFUN(AC_LITTLE_ENDIAN_LONG_LONG,
259[AC_MSG_CHECKING(for little endian long long)
260AC_CACHE_VAL(ac_cv_have_little_endian_long_long,
261[AC_RUN_IFELSE([AC_LANG_SOURCE([[
262int main () {
263 union {
264 long long ll;
265 long l [2];
266 } u;
267 u.ll = 0x12345678;
268 if (u.l[0] == 0x12345678)
269 return 0;
270 return 1;
271}
272]])],[ac_cv_have_little_endian_long_long=yes],[ac_cv_have_little_endian_long_long=no],[# Should try to guess here
273ac_cv_have_little_endian_long_long=no
274])])
275AC_MSG_RESULT($ac_cv_have_little_endian_long_long)
276if test "$ac_cv_have_little_endian_long_long" = yes
277then
278 AC_DEFINE([HAVE_LITTLE_ENDIAN_LONG_LONG], 1,
279[Define if long long is little-endian.])
280fi
281])