summaryrefslogtreecommitdiff
path: root/aclocal.m4
blob: 6986bd87ba4667a40845d0cf5996da4292cc00b0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
dnl ### A macro to find the include directory, useful for cross-compiling.
AC_DEFUN(AC_INCLUDEDIR,
[AC_REQUIRE([AC_PROG_AWK])dnl
AC_SUBST(includedir)
AC_MSG_CHECKING(for primary include directory)
includedir=/usr/include
if test -n "$GCC"
then
	>conftest.c
	new_includedir=`
		$CC -v -E conftest.c 2>&1 | $AWK '
			/^End of search list/ { print last; exit }
			{ last = [$]1 }
		'
	`
	rm -f conftest.c
	if test -n "$new_includedir" && test -d "$new_includedir"
	then
		includedir=$new_includedir
	fi
fi
AC_MSG_RESULT($includedir)
])

dnl ### A macro to automatically set different CC and HOSTCC if using gcc.
define(AC_PROG_HOSTCC,
[AC_SUBST(HOSTCC)dnl
if test -z "$HOSTCC"
then
	HOSTCC="$CC"
	if test -n "$GCC"
	then
		# Find out if gcc groks our host.
		worked=
		last=
		for i in $1
		do
			test "x$i" = "x$last" && continue
			last="$i"
			CC="$HOSTCC -b $i"
			AC_MSG_CHECKING([for working $CC])
			AC_TRY_LINK(,,
				worked=1
				break
			)
			AC_MSG_RESULT(no)
		done
		if test -z "$worked"
		then
			CC="$HOSTCC"
		else
			AC_MSG_RESULT(yes)
		fi
	fi
fi
])

dnl ### A macro to set gcc warning flags.
define(AC_WARNFLAGS,
[AC_SUBST(WARNFLAGS)
if test -z "$WARNFLAGS"
then
	if test -n "$GCC"
	then
		# If we're using gcc we want warning flags.
		WARNFLAGS=-Wall
	fi
fi
])

dnl ### A macro to determine if we have a "MP" type procfs
AC_DEFUN(AC_MP_PROCFS,
[AC_MSG_CHECKING(for MP procfs)
AC_CACHE_VAL(ac_cv_mp_procfs,
[AC_TRY_RUN([
#include <stdio.h>
#include <signal.h>
#include <sys/procfs.h>

main()
{
	int pid;
	char proc[32];
	FILE *ctl;
	FILE *status;
	int cmd;
	struct pstatus pstatus;

	if ((pid = fork()) == 0) {
		pause();
		exit(0);
	}
	sprintf(proc, "/proc/%d/ctl", pid);
	if ((ctl = fopen(proc, "w")) == NULL)
		goto fail;
	sprintf(proc, "/proc/%d/status", pid);
	if ((status = fopen (proc, "r")) == NULL)
		goto fail;
	cmd = PCSTOP;
	if (write (fileno (ctl), &cmd, sizeof cmd) < 0)
		goto fail;
	if (read (fileno (status), &pstatus, sizeof pstatus) < 0)
		goto fail;
	kill(pid, SIGKILL);
	exit(0);
fail:
	kill(pid, SIGKILL);
	exit(1);
}
],
ac_cv_mp_procfs=yes,
ac_cv_mp_procfs=no,
[
# Guess or punt.
case "$host_os" in
svr4.2*|svr5*)
	ac_cv_mp_procfs=yes
	;;
*)
	ac_cv_mp_procfs=no
	;;
esac
])])
AC_MSG_RESULT($ac_cv_mp_procfs)
if test "$ac_cv_mp_procfs" = yes
then
	AC_DEFINE(HAVE_MP_PROCFS)
fi
])

dnl ### A macro to determine if procfs is pollable.
AC_DEFUN(AC_POLLABLE_PROCFS,
[AC_MSG_CHECKING(for pollable procfs)
AC_CACHE_VAL(ac_cv_pollable_procfs,
[AC_TRY_RUN([
#include <stdio.h>
#include <signal.h>
#include <sys/procfs.h>
#include <sys/stropts.h>
#include <poll.h>

#ifdef HAVE_MP_PROCFS
#define PIOCSTOP	PCSTOP
#define POLLWANT	POLLWRNORM
#define PROC		"/proc/%d/ctl"
#define PROC_MODE	"w"
int IOCTL (int fd, int cmd, int arg) {
	return write (fd, &cmd, sizeof cmd);
}
#else
#define POLLWANT	POLLPRI
#define	PROC		"/proc/%d"
#define PROC_MODE	"r+"
#define IOCTL		ioctl
#endif

main()
{
	int pid;
	char proc[32];
	FILE *pfp;
	struct pollfd pfd;

	if ((pid = fork()) == 0) {
		pause();
		exit(0);
	}
	sprintf(proc, PROC, pid);
	if ((pfp = fopen(proc, PROC_MODE)) == NULL)
		goto fail;
	if (IOCTL(fileno(pfp), PIOCSTOP, NULL) < 0)
		goto fail;
	pfd.fd = fileno(pfp);
	pfd.events = POLLWANT;
	if (poll(&pfd, 1, 0) < 0)
		goto fail;
	if (!(pfd.revents & POLLWANT))
		goto fail;
	kill(pid, SIGKILL);
	exit(0);
fail:
	kill(pid, SIGKILL);
	exit(1);
}
],
ac_cv_pollable_procfs=yes,
ac_cv_pollable_procfs=no,
[
# Guess or punt.
case "$host_os" in
solaris2*|irix5*|svr4.2uw*|svr5*)
	ac_cv_pollable_procfs=yes
	;;
*)
	ac_cv_pollable_procfs=no
	;;
esac
])])
AC_MSG_RESULT($ac_cv_pollable_procfs)
if test "$ac_cv_pollable_procfs" = yes
then
	AC_DEFINE(HAVE_POLLABLE_PROCFS)
fi
])

dnl ### A macro to determine if the prstatus structure has a pr_syscall member.
AC_DEFUN(AC_STRUCT_PR_SYSCALL,
[AC_MSG_CHECKING(for pr_syscall in struct prstatus)
AC_CACHE_VAL(ac_cv_struct_pr_syscall,
[AC_TRY_COMPILE([#include <sys/procfs.h>],
[#ifdef HAVE_MP_PROCFS
pstatus_t s;
s.pr_lwp.pr_syscall
#else
prstatus_t s;
s.pr_syscall
#endif],
ac_cv_struct_pr_syscall=yes,
ac_cv_struct_pr_syscall=no)])
AC_MSG_RESULT($ac_cv_struct_pr_syscall)
if test "$ac_cv_struct_pr_syscall" = yes
then
	AC_DEFINE(HAVE_PR_SYSCALL)
fi
])

dnl ### A macro to detect the presence of the sig_atomic_t in signal.h
AC_DEFUN(AC_SIG_ATOMIC_T,
[AC_MSG_CHECKING(for sig_atomic_t in signal.h)
AC_CACHE_VAL(ac_cv_sig_atomic_t,
[AC_TRY_COMPILE([#include <signal.h>],
[sig_atomic_t x;],
ac_cv_sig_atomic_t=yes,
ac_cv_sig_atomic_t=no)])
AC_MSG_RESULT($ac_cv_sig_atomic_t)
if test "$ac_cv_sig_atomic_t" = yes
then
	AC_DEFINE(HAVE_SIG_ATOMIC_T)
fi
])

dnl ### A macro to determine if sys_errlist is declared.
AC_DEFUN(AC_DECL_SYS_ERRLIST,
[AC_MSG_CHECKING([for sys_errlist declaration])
AC_CACHE_VAL(ac_cv_decl_sys_errlist,
[AC_TRY_COMPILE([#include <sys/types.h>
#include <errno.h>
#include <stdio.h>
/* Somebody might declare sys_errlist in unistd.h.  */
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif], [char *msg = *(sys_errlist + 1);],
  ac_cv_decl_sys_errlist=yes, ac_cv_decl_sys_errlist=no)])dnl
AC_MSG_RESULT($ac_cv_decl_sys_errlist)
if test $ac_cv_decl_sys_errlist = yes; then
  AC_DEFINE(SYS_ERRLIST_DECLARED)
fi
])

dnl ### A macro to determine if _sys_siglist is declared.
AC_DEFUN(AC_DECL__SYS_SIGLIST,
[AC_MSG_CHECKING([for _sys_siglist declaration])
AC_CACHE_VAL(ac_cv_decl__sys_siglist,
[AC_TRY_COMPILE([#include <sys/types.h>
#include <signal.h>
/* Somebody might declare _sys_siglist in unistd.h.  */
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif], [char *msg = *(_sys_siglist + 1);],
  ac_cv_decl__sys_siglist=yes, ac_cv_decl__sys_siglist=no)])dnl
AC_MSG_RESULT($ac_cv_decl__sys_siglist)
if test $ac_cv_decl__sys_siglist = yes; then
  AC_DEFINE(SYS_SIGLIST_DECLARED)
fi
])

dnl ### A macro to determine if the msghdr structure has a msg_control member.
AC_DEFUN(AC_STRUCT_MSG_CONTROL,
[AC_MSG_CHECKING(for msg_control in struct msghdr)
AC_CACHE_VAL(ac_cv_struct_msg_control,
[AC_TRY_COMPILE([#include <sys/types.h>
#include <sys/socket.h>],
[#undef msg_control
struct msghdr m; m.msg_control;],
ac_cv_struct_msg_control=yes,
ac_cv_struct_msg_control=no)])
AC_MSG_RESULT($ac_cv_struct_msg_control)
if test "$ac_cv_struct_msg_control" = yes
then
	AC_DEFINE(HAVE_MSG_CONTROL)
fi
])

dnl ### A macro to determine whether stat64 is defined.
AC_DEFUN(AC_STAT64,
[AC_MSG_CHECKING(for stat64 in (asm|sys)/stat.h)
AC_CACHE_VAL(ac_cv_type_stat64,
[AC_TRY_COMPILE([#ifdef linux
#include <asm/stat.h>
#else
#include <sys/stat.h>
#endif],
[struct stat64 st;],
ac_cv_type_stat64=yes,
ac_cv_type_stat64=no)])
AC_MSG_RESULT($ac_cv_type_stat64)
if test "$ac_cv_type_stat64" = yes
then
	AC_DEFINE(HAVE_STAT64)
fi
])

dnl ### A macro to determine whether we have long long
AC_DEFUN(AC_LONG_LONG,
[AC_MSG_CHECKING(for long long)
AC_CACHE_VAL(ac_cv_type_long_long,
[AC_TRY_COMPILE([],
[long long x = 20;],
ac_cv_type_long_long=yes,
ac_cv_type_long_long=no)])
AC_MSG_RESULT($ac_cv_type_long_long)
if test "$ac_cv_type_long_long" = yes
then
	AC_DEFINE(HAVE_LONG_LONG)
fi
])

dnl ### A macro to determine if off_t is a long long
AC_DEFUN(AC_OFF_T_IS_LONG_LONG,
[AC_MSG_CHECKING(for long long off_t)
AC_CACHE_VAL(ac_cv_have_long_long_off_t,
[AC_TRY_RUN([#include <sys/types.h>
main () {
	if (sizeof (off_t) == sizeof (long long) &&
	    sizeof (off_t) > sizeof (long))
	    return 0;
	return 1;
}
],
ac_cv_have_long_long_off_t=yes,
ac_cv_have_long_long_off_t=no,
[# Should try to guess here
ac_cv_have_long_long_off_t=no
])])
AC_MSG_RESULT($ac_cv_have_long_long_off_t)
if test "$ac_cv_have_long_long_off_t" = yes
then
	AC_DEFINE(HAVE_LONG_LONG_OFF_T)
fi
])

dnl ### A macro to determine if rlim_t is a long long
AC_DEFUN(AC_RLIM_T_IS_LONG_LONG,
[AC_MSG_CHECKING(for long long rlim_t)
AC_CACHE_VAL(ac_cv_have_long_long_rlim_t,
[AC_TRY_RUN([#include <sys/types.h>
#include <sys/time.h>
#include <sys/resource.h>
main () {
	if (sizeof (rlim_t) == sizeof (long long) &&
	    sizeof (rlim_t) > sizeof (long))
	    return 0;
	return 1;
}
],
ac_cv_have_long_long_rlim_t=yes,
ac_cv_have_long_long_rlim_t=no,
[# Should try to guess here
ac_cv_have_long_long_rlim_t=no
])])
AC_MSG_RESULT($ac_cv_have_long_long_rlim_t)
if test "$ac_cv_have_long_long_rlim_t" = yes
then
	AC_DEFINE(HAVE_LONG_LONG_RLIM_T)
fi
])

dnl ### A macro to determine whether sin6_scope_id is available.
AC_DEFUN(AC_SIN6_SCOPE_ID,
[AC_MSG_CHECKING(for sin6_scope_id in sockaddr_in6)
AC_CACHE_VAL(ac_cv_have_sin6_scope_id,
[AC_TRY_COMPILE([#include <netinet/in.h>],
[ struct sockaddr_in6 s; s.sin6_scope_id = 0; ],
ac_cv_have_sin6_scope_id=yes,
ac_cv_have_sin6_scope_id=no)])
AC_MSG_RESULT($ac_cv_have_sin6_scope_id)
if test "$ac_cv_have_sin6_scope_id" = "yes" ; then
       AC_DEFINE(HAVE_SIN6_SCOPE_ID)
else
       AC_MSG_CHECKING(for sin6_scope_id in linux sockaddr_in6)
       AC_CACHE_VAL(ac_cv_have_sin6_scope_id_linux,
       [AC_TRY_COMPILE([#include <linux/in6.h>],
       [ struct sockaddr_in6 s; s.sin6_scope_id = 0; ],
       ac_cv_have_sin6_scope_id_linux=yes,
       ac_cv_have_sin6_scope_id_linux=no)])
       AC_MSG_RESULT($ac_cv_have_sin6_scope_id_linux)
       if test "$ac_cv_have_sin6_scope_id_linux" = "yes" ; then
               AC_DEFINE(HAVE_SIN6_SCOPE_ID)
               AC_DEFINE(HAVE_SIN6_SCOPE_ID_LINUX)
       fi
fi
])