there was an #include directive missing
[openmpi-llc.git] / config / ompi_setup_libevent.m4
blob4ca5ff83101a4057ef46cd0ebe9b600ed3d78865
1 dnl
2 dnl Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
3 dnl                         University Research and Technology
4 dnl                         Corporation.  All rights reserved.
5 dnl Copyright (c) 2004-2005 The University of Tennessee and The University
6 dnl                         of Tennessee Research Foundation.  All rights
7 dnl                         reserved.
8 dnl Copyright (c) 2004-2005 High Performance Computing Center Stuttgart, 
9 dnl                         University of Stuttgart.  All rights reserved.
10 dnl Copyright (c) 2004-2005 The Regents of the University of California.
11 dnl                         All rights reserved.
12 dnl $COPYRIGHT$
13 dnl 
14 dnl Additional copyrights may follow
15 dnl 
16 dnl $HEADER$
17 dnl
19 AC_DEFUN([OMPI_SETUP_LIBEVENT],[
21 dnl OMPI: don't use AC_LIBOBJ
22 sources=
24 dnl Check for optional stuff
25 AC_ARG_WITH(event-rtsig,
26   AC_HELP_STRING([--with-event-rtsig],
27                  [compile with support for real time signals (experimental)]),
28   [usertsig=yes], [usertsig=no])
30 dnl Checks for libraries.
31 dnl AC_CHECK_LIB(socket, socket)
33 dnl Checks for header files.
34 AC_HEADER_STDC
35 AC_CHECK_HEADERS(inttypes.h stdint.h poll.h signal.h unistd.h sys/epoll.h sys/time.h sys/queue.h sys/event.h)
36 if test "x$ac_cv_header_sys_queue_h" = "xyes"; then
37         AC_MSG_CHECKING(for TAILQ_FOREACH in sys/queue.h)
38         AC_EGREP_CPP(yes,
40 #include <sys/queue.h>
41 #ifdef TAILQ_FOREACH
42  yes
43 #endif
44 ],      [AC_MSG_RESULT(yes)
45          AC_DEFINE(HAVE_TAILQFOREACH, 1,
46                 [Define if TAILQ_FOREACH is defined in <sys/queue.h>])],
47         AC_MSG_RESULT(no)
48         )
51 if test "x$ac_cv_header_sys_time_h" = "xyes"; then
52         AC_MSG_CHECKING(for timeradd in sys/time.h)
53         AC_EGREP_CPP(yes,
55 #include <sys/time.h>
56 #ifdef timeradd
57  yes
58 #endif
59 ],      [ AC_DEFINE(HAVE_TIMERADD, 1,
60                 [Define if timeradd is defined in <sys/time.h>])
61           AC_MSG_RESULT(yes)] ,AC_MSG_RESULT(no)
65 dnl Checks for typedefs, structures, and compiler characteristics.
66 AC_HEADER_TIME
68 dnl Checks for library functions.
69 AC_CHECK_FUNCS(gettimeofday)
71 needsignal=no
72 haveselect=no
73 AC_CHECK_FUNCS(select, [haveselect=yes], )
74 if test "x$haveselect" = "xyes" ; then
75         # OMPI: Don't use AC_LIBOBJ
76         sources="select.c $sources"
77         needsignal=yes
80 havepoll=no
81 havertsig=no
82 AC_CHECK_FUNCS(poll, [havepoll=yes], )
83 case "$host" in
84     *apple-darwin*)
85         haveworkingpoll=0
86     ;;
87     *)
88         if test "$havepoll" = "yes" ; then
89             haveworkingpoll=1
90         else
91             haveworkingpoll=0
92         fi
93     ;;
94 esac
95 AC_DEFINE_UNQUOTED([HAVE_WORKING_POLL], [$haveworkingpoll], 
96                    [Whether poll works for file descriptors and devices])
97 if test "x$havepoll" = "xyes" -a "$haveworkingpoll" = "1" ; then
98         # OMPI: Don't use AC_LIBOBJ
99         sources="poll.c $sources"
100         needsignal=yes
102         if test "x$usertsig" = "xyes" ; then
103                 AC_CHECK_FUNCS(sigtimedwait, [havertsig=yes], )
104         fi
106 if test "x$havertsig" = "xyes" ; then
107         AC_MSG_CHECKING(for F_SETSIG in fcntl.h)
108         AC_EGREP_CPP(yes,
110 #define _GNU_SOURCE
111 #include <fcntl.h>
112 #ifdef F_SETSIG
114 #endif
115 ],      [ AC_MSG_RESULT(yes) ], [ AC_MSG_RESULT(no); havertsig=no])
117 if test "x$havertsig" = "xyes" ; then
118         AC_DEFINE(HAVE_RTSIG, 1, [Define if your system supports POSIX realtime signals])
119         # OMPI: Don't use AC_LIBOBJ
120         sources="rtsig.c $sources"
121         AC_MSG_CHECKING(for working rtsig on pipes)
122         AC_TRY_RUN(
124 #define _GNU_SOURCE
125 #include <fcntl.h>
126 #include <signal.h>
127 #include <unistd.h>
128 #include <stdlib.h>
130 int sigio()
132         exit(0);
135 int main()
137         int fd[2];
139         pipe(fd);
140         signal(SIGIO, sigio);
141         fcntl(fd[0], F_SETOWN, getpid());
142         fcntl(fd[0], F_SETSIG, SIGIO);
143         fcntl(fd[0], F_SETFL, fcntl(fd[0], F_GETFL) | O_ASYNC);
144         write(fd[1], "", 1);
145         return 1;
147 ],      [ AC_MSG_RESULT(yes)
148           AC_DEFINE(HAVE_WORKING_RTSIG, 1, [Define if realtime signals work on pipes])],
149         AC_MSG_RESULT(no))
152 haveepoll=no
153 AC_CHECK_FUNCS(epoll_ctl, [haveepoll=yes], )
154 if test "x$haveepoll" = "xyes" -a "$cross_compiling" != "yes" ; then
156         # OMPI: Unfortunately, this test is not sufficient on some
157         # Linux distros (e.g., RH 9), where the function is defined
158         # and you can link against it, but it's hardwired to return
159         # ENOSYS -- and /usr/include/gnu/stubs.h fails to define
160         # __stub_epoll_ctl (the usual mechanism in glibc to indicate
161         # that a function is a stub and isn't really implemented).
162         # Hence, the test succeeds because it thinks it can use
163         # epoll_ctl (and friends).  So we have to do a better test
164         # after we determine that epoll_ctl is linkable.  Grumble.
165         # If we are cross compiling, just trust AC_CHECK_FUNCS
167         AC_MSG_CHECKING([for epoll_ctl on broken Linux distros])
168         rm -f conftest.out
169         AC_RUN_IFELSE(AC_LANG_PROGRAM([[
170 AC_INCLUDES_DEFAULT
171 #include <sys/epoll.h>]], 
172 [[int i = epoll_create(2);
173 FILE *fp = fopen("conftest.out", "w");
174 fprintf(fp, "%d", i);
175 fclose(fp);]]))
176         haveepoll=no
177         if test -f conftest.out -a "`cat conftest.out`" = "0"; then
178             haveepoll=yes
179         fi
180         rm -f conftest.out
181         AC_MSG_RESULT([$haveepoll])
184 if test "x$haveepoll" = "xyes" ; then
185         AC_DEFINE(HAVE_EPOLL, 1,
186                 [Define if your system supports the epoll system calls])
187         # OMPI: Don't use AC_LIBOBJ
188         sources="epoll.c $sources"
189         needsignal=yes
192 havekqueue=no
193 if test "x$ac_cv_header_sys_event_h" = "xyes"; then
194         AC_CHECK_FUNCS(kqueue, [havekqueue=yes], )
195         if test "x$havekqueue" = "xyes" ; then
196                 AC_MSG_CHECKING(for working kqueue)
197                 AC_TRY_RUN(
198 #include <sys/types.h>
199 #include <sys/time.h>
200 #include <sys/event.h>
201 #include <stdio.h>
202 #include <unistd.h>
203 #include <fcntl.h>
204 #include <stdlib.h>
207 main(int argc, char **argv)
209         int kq;
210         int n;
211         int fd[[2]];
212         struct kevent ev;
213         struct timespec ts;
214         char buf[[8000]];
216         if (pipe(fd) == -1)
217                 exit(1);
218         if (fcntl(fd[[1]], F_SETFL, O_NONBLOCK) == -1)
219                 exit(1);
221         while ((n = write(fd[[1]], buf, sizeof(buf))) == sizeof(buf))
222                 ;
224         if ((kq = kqueue()) == -1)
225                 exit(1);
227         ev.ident = fd[[1]];
228         ev.filter = EVFILT_WRITE;
229         ev.flags = EV_ADD | EV_ENABLE;
230         n = kevent(kq, &ev, 1, NULL, 0, NULL);
231         if (n == -1)
232                 exit(1);
233         
234         read(fd[[0]], buf, sizeof(buf));
236         ts.tv_sec = 0;
237         ts.tv_nsec = 0;
238         n = kevent(kq, NULL, 0, &ev, 1, &ts);
239         if (n == -1 || n == 0)
240                 exit(1);
242         exit(0);
243 }, [AC_MSG_RESULT(yes)
244     AC_DEFINE(HAVE_WORKING_KQUEUE, 1,
245                 [Define if kqueue works correctly with pipes])
246     sources="kqueue.c $sources"], AC_MSG_RESULT(no), AC_MSG_RESULT(no))
247     # OMPI: don't use AC_LIBOBJ
248         fi
251 haveepollsyscall=no
252 if test "x$ac_cv_header_sys_epoll_h" = "xyes"; then
253         if test "x$haveepoll" = "xno" ; then
254                 AC_MSG_CHECKING(for epoll system call)
255                 AC_TRY_RUN(
256 #include <stdint.h>
257 #include <sys/param.h>
258 #include <sys/types.h>
259 #include <sys/syscall.h>
260 #include <sys/epoll.h>
261 #include <unistd.h>
262 #include <stdlib.h>
265 epoll_create(int size)
267         return (syscall(__NR_epoll_create, size));
271 main(int argc, char **argv)
273         int epfd;
275         epfd = epoll_create(256);
276         exit (epfd == -1 ? 1 : 0);
277 }, [AC_MSG_RESULT(yes)
278     AC_DEFINE(HAVE_EPOLL, 1,
279         [Define if your system supports the epoll system calls])
280     needsignal=yes
281     # OMPI: don't use AC_LIBOBJ
282     sources="epoll_sub.c epoll.c $sources"
283     ], AC_MSG_RESULT(no), AC_MSG_RESULT(no))
284         fi
287 if test "x$needsignal" = "xyes" ; then
288     # OMPI: don't use AC_LIBOBJ
289     sources="signal.c $sources"
292 # OMPI: AC_REPLACE_FUNCS doesn't have much meaning here because it
293 # uses AC_LIBOBJ; use our own test
294 #AC_REPLACE_FUNCS(err)
295 AC_CHECK_FUNC(err, [], [sources="err.c $sources"])
297 AC_TYPE_PID_T
298 AC_TYPE_SIZE_T
299 AC_CHECK_TYPE(u_int64_t, unsigned long long)
300 AC_CHECK_TYPE(u_int32_t, unsigned int)
301 AC_CHECK_TYPE(u_int16_t, unsigned short)
302 AC_CHECK_TYPE(u_int8_t, unsigned char)
305 # OMPI: Save the libobj sources
306 OMPI_LIBEVENT_SOURCES="$sources"
307 AC_SUBST(OMPI_LIBEVENT_SOURCES)
309 # OMPI: All done
310 unset sources])dnl