xref: /PHP-5.3/sapi/fpm/config.m4 (revision 851a04bb)
1dnl
2dnl $Id$
3dnl
4
5PHP_ARG_ENABLE(fpm,,
6[  --enable-fpm              EXPERIMENTAL: Enable building of the fpm SAPI executable], no, no)
7
8dnl configure checks {{{
9AC_DEFUN([AC_FPM_STDLIBS],
10[
11  AC_CHECK_FUNCS(setenv clearenv setproctitle)
12
13  AC_SEARCH_LIBS(socket, socket)
14  AC_SEARCH_LIBS(inet_addr, nsl)
15
16  AC_CHECK_HEADERS([errno.h fcntl.h stdio.h stdlib.h unistd.h sys/uio.h])
17  AC_CHECK_HEADERS([sys/select.h sys/socket.h sys/time.h])
18  AC_CHECK_HEADERS([arpa/inet.h netinet/in.h])
19  AC_CHECK_HEADERS([sysexits.h])
20])
21
22AC_DEFUN([AC_FPM_PRCTL],
23[
24  AC_MSG_CHECKING([for prctl])
25
26  AC_TRY_COMPILE([ #include <sys/prctl.h> ], [prctl(0, 0, 0, 0, 0);], [
27    AC_DEFINE([HAVE_PRCTL], 1, [do we have prctl?])
28    AC_MSG_RESULT([yes])
29  ], [
30    AC_MSG_RESULT([no])
31  ])
32])
33
34AC_DEFUN([AC_FPM_CLOCK],
35[
36  have_clock_gettime=no
37
38  AC_MSG_CHECKING([for clock_gettime])
39
40  AC_TRY_LINK([ #include <time.h> ], [struct timespec ts; clock_gettime(CLOCK_MONOTONIC, &ts);], [
41    have_clock_gettime=yes
42    AC_MSG_RESULT([yes])
43  ], [
44    AC_MSG_RESULT([no])
45  ])
46
47  if test "$have_clock_gettime" = "no"; then
48    AC_MSG_CHECKING([for clock_gettime in -lrt])
49
50    SAVED_LIBS="$LIBS"
51    LIBS="$LIBS -lrt"
52
53    AC_TRY_LINK([ #include <time.h> ], [struct timespec ts; clock_gettime(CLOCK_MONOTONIC, &ts);], [
54      have_clock_gettime=yes
55      AC_MSG_RESULT([yes])
56    ], [
57      LIBS="$SAVED_LIBS"
58      AC_MSG_RESULT([no])
59    ])
60  fi
61
62  if test "$have_clock_gettime" = "yes"; then
63    AC_DEFINE([HAVE_CLOCK_GETTIME], 1, [do we have clock_gettime?])
64  fi
65
66  have_clock_get_time=no
67
68  if test "$have_clock_gettime" = "no"; then
69    AC_MSG_CHECKING([for clock_get_time])
70
71    AC_TRY_RUN([ #include <mach/mach.h>
72      #include <mach/clock.h>
73      #include <mach/mach_error.h>
74
75      int main()
76      {
77        kern_return_t ret; clock_serv_t aClock; mach_timespec_t aTime;
78        ret = host_get_clock_service(mach_host_self(), REALTIME_CLOCK, &aClock);
79
80        if (ret != KERN_SUCCESS) {
81          return 1;
82        }
83
84        ret = clock_get_time(aClock, &aTime);
85        if (ret != KERN_SUCCESS) {
86          return 2;
87        }
88
89        return 0;
90      }
91    ], [
92      have_clock_get_time=yes
93      AC_MSG_RESULT([yes])
94    ], [
95      AC_MSG_RESULT([no])
96    ])
97  fi
98
99  if test "$have_clock_get_time" = "yes"; then
100    AC_DEFINE([HAVE_CLOCK_GET_TIME], 1, [do we have clock_get_time?])
101  fi
102])
103
104AC_DEFUN([AC_FPM_TRACE],
105[
106  have_ptrace=no
107  have_broken_ptrace=no
108
109  AC_MSG_CHECKING([for ptrace])
110
111  AC_TRY_COMPILE([
112    #include <sys/types.h>
113    #include <sys/ptrace.h> ], [ptrace(0, 0, (void *) 0, 0);], [
114    have_ptrace=yes
115    AC_MSG_RESULT([yes])
116  ], [
117    AC_MSG_RESULT([no])
118  ])
119
120  if test "$have_ptrace" = "yes"; then
121    AC_MSG_CHECKING([whether ptrace works])
122
123    AC_TRY_RUN([
124      #include <unistd.h>
125      #include <signal.h>
126      #include <sys/wait.h>
127      #include <sys/types.h>
128      #include <sys/ptrace.h>
129      #include <errno.h>
130
131      #if !defined(PTRACE_ATTACH) && defined(PT_ATTACH)
132      #define PTRACE_ATTACH PT_ATTACH
133      #endif
134
135      #if !defined(PTRACE_DETACH) && defined(PT_DETACH)
136      #define PTRACE_DETACH PT_DETACH
137      #endif
138
139      #if !defined(PTRACE_PEEKDATA) && defined(PT_READ_D)
140      #define PTRACE_PEEKDATA PT_READ_D
141      #endif
142
143      int main()
144      {
145        long v1 = (unsigned int) -1; /* copy will fail if sizeof(long) == 8 and we've got "int ptrace()" */
146        long v2;
147        pid_t child;
148        int status;
149
150        if ( (child = fork()) ) { /* parent */
151          int ret = 0;
152
153          if (0 > ptrace(PTRACE_ATTACH, child, 0, 0)) {
154            return 2;
155          }
156
157          waitpid(child, &status, 0);
158
159      #ifdef PT_IO
160          struct ptrace_io_desc ptio = {
161            .piod_op = PIOD_READ_D,
162            .piod_offs = &v1,
163            .piod_addr = &v2,
164            .piod_len = sizeof(v1)
165          };
166
167          if (0 > ptrace(PT_IO, child, (void *) &ptio, 0)) {
168            ret = 3;
169          }
170      #else
171          errno = 0;
172
173          v2 = ptrace(PTRACE_PEEKDATA, child, (void *) &v1, 0);
174
175          if (errno) {
176            ret = 4;
177          }
178      #endif
179          ptrace(PTRACE_DETACH, child, (void *) 1, 0);
180
181          kill(child, SIGKILL);
182
183          return ret ? ret : (v1 != v2);
184        }
185        else { /* child */
186          sleep(10);
187          return 0;
188        }
189      }
190    ], [
191      AC_MSG_RESULT([yes])
192    ], [
193      have_ptrace=no
194      have_broken_ptrace=yes
195      AC_MSG_RESULT([no])
196    ])
197  fi
198
199  if test "$have_ptrace" = "yes"; then
200    AC_DEFINE([HAVE_PTRACE], 1, [do we have ptrace?])
201  fi
202
203  have_mach_vm_read=no
204
205  if test "$have_broken_ptrace" = "yes"; then
206    AC_MSG_CHECKING([for mach_vm_read])
207
208    AC_TRY_COMPILE([ #include <mach/mach.h>
209      #include <mach/mach_vm.h>
210    ], [
211      mach_vm_read((vm_map_t)0, (mach_vm_address_t)0, (mach_vm_size_t)0, (vm_offset_t *)0, (mach_msg_type_number_t*)0);
212    ], [
213      have_mach_vm_read=yes
214      AC_MSG_RESULT([yes])
215    ], [
216      AC_MSG_RESULT([no])
217    ])
218  fi
219
220  if test "$have_mach_vm_read" = "yes"; then
221    AC_DEFINE([HAVE_MACH_VM_READ], 1, [do we have mach_vm_read?])
222  fi
223
224  proc_mem_file=""
225
226  if test -r /proc/$$/mem ; then
227    proc_mem_file="mem"
228  else
229    if test -r /proc/$$/as ; then
230      proc_mem_file="as"
231    fi
232  fi
233
234  if test -n "$proc_mem_file" ; then
235    AC_MSG_CHECKING([for proc mem file])
236
237    AC_TRY_RUN([
238      #define _GNU_SOURCE
239      #define _FILE_OFFSET_BITS 64
240      #include <stdint.h>
241      #include <unistd.h>
242      #include <sys/types.h>
243      #include <sys/stat.h>
244      #include <fcntl.h>
245      #include <stdio.h>
246      int main()
247      {
248        long v1 = (unsigned int) -1, v2 = 0;
249        char buf[128];
250        int fd;
251        sprintf(buf, "/proc/%d/$proc_mem_file", getpid());
252        fd = open(buf, O_RDONLY);
253        if (0 > fd) {
254          return 1;
255        }
256        if (sizeof(long) != pread(fd, &v2, sizeof(long), (uintptr_t) &v1)) {
257          close(fd);
258          return 1;
259        }
260        close(fd);
261        return v1 != v2;
262      }
263    ], [
264      AC_MSG_RESULT([$proc_mem_file])
265    ], [
266      proc_mem_file=""
267      AC_MSG_RESULT([no])
268    ])
269  fi
270
271  if test -n "$proc_mem_file"; then
272    AC_DEFINE_UNQUOTED([PROC_MEM_FILE], "$proc_mem_file", [/proc/pid/mem interface])
273  fi
274
275  fpm_trace_type=""
276
277  if test "$have_ptrace" = "yes"; then
278    fpm_trace_type=ptrace
279
280  elif test -n "$proc_mem_file"; then
281    fpm_trace_type=pread
282
283  elif test "$have_mach_vm_read" = "yes" ; then
284    fpm_trace_type=mach
285
286  else
287    AC_MSG_WARN([FPM Trace - ptrace, pread, or mach: could not be found])
288  fi
289
290])
291
292AC_DEFUN([AC_FPM_BUILTIN_ATOMIC],
293[
294  AC_MSG_CHECKING([if gcc supports __sync_bool_compare_and_swap])
295  AC_TRY_LINK(,
296  [
297    int variable = 1;
298    return (__sync_bool_compare_and_swap(&variable, 1, 2)
299           && __sync_add_and_fetch(&variable, 1)) ? 1 : 0;
300  ],
301  [
302    AC_MSG_RESULT([yes])
303    AC_DEFINE(HAVE_BUILTIN_ATOMIC, 1, [Define to 1 if gcc supports __sync_bool_compare_and_swap() a.o.])
304  ],
305  [
306    AC_MSG_RESULT([no])
307  ])
308])
309
310AC_DEFUN([AC_FPM_LQ],
311[
312  have_lq=no
313
314  AC_MSG_CHECKING([for TCP_INFO])
315
316  AC_TRY_COMPILE([ #include <netinet/tcp.h> ], [struct tcp_info ti; int x = TCP_INFO;], [
317    have_lq=tcp_info
318    AC_MSG_RESULT([yes])
319  ], [
320    AC_MSG_RESULT([no])
321  ])
322
323  if test "$have_lq" = "tcp_info"; then
324    AC_DEFINE([HAVE_LQ_TCP_INFO], 1, [do we have TCP_INFO?])
325  fi
326
327  if test "$have_lq" = "no" ; then
328    AC_MSG_CHECKING([for SO_LISTENQLEN])
329
330    AC_TRY_COMPILE([ #include <sys/socket.h> ], [int x = SO_LISTENQLIMIT; int y = SO_LISTENQLEN;], [
331      have_lq=so_listenq
332      AC_MSG_RESULT([yes])
333    ], [
334      AC_MSG_RESULT([no])
335    ])
336
337    if test "$have_lq" = "tcp_info"; then
338      AC_DEFINE([HAVE_LQ_SO_LISTENQ], 1, [do we have SO_LISTENQxxx?])
339    fi
340  fi
341])
342dnl }}}
343
344AC_DEFUN([AC_FPM_SYSCONF],
345[
346	AC_MSG_CHECKING([for sysconf])
347
348	AC_TRY_COMPILE([ #include <unistd.h> ], [sysconf(_SC_CLK_TCK);], [
349		AC_DEFINE([HAVE_SYSCONF], 1, [do we have sysconf?])
350		AC_MSG_RESULT([yes])
351	], [
352		AC_MSG_RESULT([no])
353	])
354])
355dnl }}}
356
357AC_DEFUN([AC_FPM_TIMES],
358[
359	AC_MSG_CHECKING([for times])
360
361	AC_TRY_COMPILE([ #include <sys/times.h> ], [struct tms t; times(&t);], [
362		AC_DEFINE([HAVE_TIMES], 1, [do we have times?])
363		AC_MSG_RESULT([yes])
364	], [
365		AC_MSG_RESULT([no])
366	])
367])
368dnl }}}
369
370AC_DEFUN([AC_FPM_KQUEUE],
371[
372	AC_MSG_CHECKING([for kqueue])
373
374	AC_TRY_COMPILE(
375	[
376		#include <sys/types.h>
377		#include <sys/event.h>
378		#include <sys/time.h>
379	], [
380		int kfd;
381		struct kevent k;
382		kfd = kqueue();
383		/* 0 -> STDIN_FILENO */
384		EV_SET(&k, 0, EVFILT_READ , EV_ADD | EV_CLEAR, 0, 0, NULL);
385	], [
386		AC_DEFINE([HAVE_KQUEUE], 1, [do we have kqueue?])
387		AC_MSG_RESULT([yes])
388	], [
389		AC_MSG_RESULT([no])
390	])
391])
392dnl }}}
393
394AC_DEFUN([AC_FPM_PORT],
395[
396	AC_MSG_CHECKING([for port framework])
397
398	AC_TRY_COMPILE(
399	[
400		#include <port.h>
401	], [
402		int port;
403
404		port = port_create();
405		if (port < 0) {
406			return 1;
407		}
408	], [
409		AC_DEFINE([HAVE_PORT], 1, [do we have port framework?])
410		AC_MSG_RESULT([yes])
411	], [
412		AC_MSG_RESULT([no])
413	])
414])
415dnl }}}
416
417AC_DEFUN([AC_FPM_DEVPOLL],
418[
419	AC_MSG_CHECKING([for /dev/poll])
420
421	AC_TRY_COMPILE(
422	[
423		#include <stdio.h>
424		#include <sys/devpoll.h>
425	], [
426		int n, dp;
427		struct dvpoll dvp;
428		dp = 0;
429		dvp.dp_fds = NULL;
430		dvp.dp_nfds = 0;
431		dvp.dp_timeout = 0;
432		n = ioctl(dp, DP_POLL, &dvp)
433	], [
434		AC_DEFINE([HAVE_DEVPOLL], 1, [do we have /dev/poll?])
435		AC_MSG_RESULT([yes])
436	], [
437		AC_MSG_RESULT([no])
438	])
439])
440dnl }}}
441
442AC_DEFUN([AC_FPM_EPOLL],
443[
444	AC_MSG_CHECKING([for epoll])
445
446	AC_TRY_COMPILE(
447	[
448		#include <sys/epoll.h>
449	], [
450		int epollfd;
451		struct epoll_event e;
452
453		epollfd = epoll_create(1);
454		if (epollfd < 0) {
455			return 1;
456		}
457
458		e.events = EPOLLIN | EPOLLET;
459		e.data.fd = 0;
460
461		if (epoll_ctl(epollfd, EPOLL_CTL_ADD, 0, &e) == -1) {
462			return 1;
463		}
464
465		e.events = 0;
466		if (epoll_wait(epollfd, &e, 1, 1) < 0) {
467			return 1;
468		}
469	], [
470		AC_DEFINE([HAVE_EPOLL], 1, [do we have epoll?])
471		AC_MSG_RESULT([yes])
472	], [
473		AC_MSG_RESULT([no])
474	])
475])
476dnl }}}
477
478AC_DEFUN([AC_FPM_POLL],
479[
480	AC_MSG_CHECKING([for poll])
481
482	AC_TRY_COMPILE(
483	[
484		#include <poll.h>
485	], [
486		struct pollfd fds[2];
487
488		fds[0].fd = 0;
489		fds[0].events = POLLIN;
490
491		fds[1].fd = 0;
492		fds[1].events = POLLIN;
493
494		 poll(fds, 2, 1);
495	], [
496		AC_DEFINE([HAVE_POLL], 1, [do we have poll?])
497		AC_MSG_RESULT([yes])
498	], [
499		AC_MSG_RESULT([no])
500	])
501])
502dnl }}}
503
504AC_DEFUN([AC_FPM_SELECT],
505[
506	AC_MSG_CHECKING([for select])
507
508	AC_TRY_COMPILE(
509	[
510		/* According to POSIX.1-2001 */
511		#include <sys/select.h>
512
513		/* According to earlier standards */
514		#include <sys/time.h>
515		#include <sys/types.h>
516		#include <unistd.h>
517	], [
518		fd_set fds;
519		struct timeval t;
520		t.tv_sec = 0;
521		t.tv_usec = 42;
522		FD_ZERO(&fds);
523		/* 0 -> STDIN_FILENO */
524		FD_SET(0, &fds);
525		select(FD_SETSIZE, &fds, NULL, NULL, &t);
526	], [
527		AC_DEFINE([HAVE_SELECT], 1, [do we have select?])
528		AC_MSG_RESULT([yes])
529	], [
530		AC_MSG_RESULT([no])
531	])
532])
533dnl }}}
534
535
536AC_MSG_CHECKING(for FPM build)
537if test "$PHP_FPM" != "no"; then
538  AC_MSG_RESULT($PHP_FPM)
539
540  AC_FPM_STDLIBS
541  AC_FPM_PRCTL
542  AC_FPM_CLOCK
543  AC_FPM_TRACE
544  AC_FPM_BUILTIN_ATOMIC
545  AC_FPM_LQ
546	AC_FPM_SYSCONF
547	AC_FPM_TIMES
548	AC_FPM_KQUEUE
549	AC_FPM_PORT
550	AC_FPM_DEVPOLL
551	AC_FPM_EPOLL
552	AC_FPM_POLL
553	AC_FPM_SELECT
554
555  PHP_ARG_WITH(fpm-user,,
556  [  --with-fpm-user[=USER]  Set the user for php-fpm to run as. (default: nobody)], nobody, no)
557
558  PHP_ARG_WITH(fpm-group,,
559  [  --with-fpm-group[=GRP]  Set the group for php-fpm to run as. For a system user, this
560                  should usually be set to match the fpm username (default: nobody)], nobody, no)
561
562  if test -z "$PHP_FPM_USER" -o "$PHP_FPM_USER" = "yes" -o "$PHP_FPM_USER" = "no"; then
563    php_fpm_user="nobody"
564  else
565    php_fpm_user="$PHP_FPM_USER"
566  fi
567
568  if test -z "$PHP_FPM_GROUP" -o "$PHP_FPM_GROUP" = "yes" -o "$PHP_FPM_GROUP" = "no"; then
569    php_fpm_group="nobody"
570  else
571    php_fpm_group="$PHP_FPM_GROUP"
572  fi
573
574  PHP_SUBST_OLD(php_fpm_user)
575  PHP_SUBST_OLD(php_fpm_group)
576  php_fpm_sysconfdir=`eval echo $sysconfdir`
577  PHP_SUBST_OLD(php_fpm_sysconfdir)
578  php_fpm_localstatedir=`eval echo $localstatedir`
579  PHP_SUBST_OLD(php_fpm_localstatedir)
580  php_fpm_prefix=`eval echo $prefix`
581  PHP_SUBST_OLD(php_fpm_prefix)
582
583  AC_DEFINE_UNQUOTED(PHP_FPM_USER, "$php_fpm_user", [fpm user name])
584  AC_DEFINE_UNQUOTED(PHP_FPM_GROUP, "$php_fpm_group", [fpm group name])
585
586  PHP_OUTPUT(sapi/fpm/php-fpm.conf sapi/fpm/init.d.php-fpm sapi/fpm/php-fpm.service sapi/fpm/php-fpm.8 sapi/fpm/status.html)
587  PHP_ADD_MAKEFILE_FRAGMENT([$abs_srcdir/sapi/fpm/Makefile.frag], [$abs_srcdir/sapi/fpm], [sapi/fpm])
588
589  SAPI_FPM_PATH=sapi/fpm/php-fpm
590  PHP_SUBST(SAPI_FPM_PATH)
591
592  if test "$fpm_trace_type" && test -f "$abs_srcdir/sapi/fpm/fpm/fpm_trace_$fpm_trace_type.c"; then
593    PHP_FPM_TRACE_FILES="fpm/fpm_trace.c fpm/fpm_trace_$fpm_trace_type.c"
594  fi
595
596  PHP_FPM_CFLAGS="-I$abs_srcdir/sapi/fpm"
597
598  INSTALL_IT=":"
599  PHP_FPM_FILES="fpm/fastcgi.c \
600    fpm/fpm.c \
601    fpm/fpm_children.c \
602    fpm/fpm_cleanup.c \
603    fpm/fpm_clock.c \
604    fpm/fpm_conf.c \
605    fpm/fpm_env.c \
606    fpm/fpm_events.c \
607		fpm/fpm_log.c \
608    fpm/fpm_main.c \
609    fpm/fpm_php.c \
610    fpm/fpm_php_trace.c \
611    fpm/fpm_process_ctl.c \
612    fpm/fpm_request.c \
613    fpm/fpm_shm.c \
614    fpm/fpm_scoreboard.c \
615    fpm/fpm_signals.c \
616    fpm/fpm_sockets.c \
617    fpm/fpm_status.c \
618    fpm/fpm_stdio.c \
619    fpm/fpm_unix.c \
620    fpm/fpm_worker_pool.c \
621    fpm/zlog.c \
622		fpm/events/select.c \
623		fpm/events/poll.c \
624		fpm/events/epoll.c \
625		fpm/events/kqueue.c \
626		fpm/events/devpoll.c \
627		fpm/events/port.c \
628  "
629
630  PHP_SELECT_SAPI(fpm, program, $PHP_FPM_FILES $PHP_FPM_TRACE_FILES, $PHP_FPM_CFLAGS, '$(SAPI_FPM_PATH)')
631
632  case $host_alias in
633      *aix*)
634        BUILD_FPM="echo '\#! .' > php.sym && echo >>php.sym && nm -BCpg \`echo \$(PHP_GLOBAL_OBJS) \$(PHP_SAPI_OBJS) | sed 's/\([A-Za-z0-9_]*\)\.lo/\1.o/g'\` | \$(AWK) '{ if (((\$\$2 == \"T\") || (\$\$2 == \"D\") || (\$\$2 == \"B\")) && (substr(\$\$3,1,1) != \".\")) { print \$\$3 } }' | sort -u >> php.sym && \$(LIBTOOL) --mode=link \$(CC) -export-dynamic \$(CFLAGS_CLEAN) \$(EXTRA_CFLAGS) \$(EXTRA_LDFLAGS_PROGRAM) \$(LDFLAGS) -Wl,-brtl -Wl,-bE:php.sym \$(PHP_RPATHS) \$(PHP_GLOBAL_OBJS) \$(PHP_SAPI_OBJS) \$(EXTRA_LIBS) \$(SAPI_EXTRA_LIBS) \$(ZEND_EXTRA_LIBS) -o \$(SAPI_FPM_PATH)"
635        ;;
636      *darwin*)
637        BUILD_FPM="\$(CC) \$(CFLAGS_CLEAN) \$(EXTRA_CFLAGS) \$(EXTRA_LDFLAGS_PROGRAM) \$(LDFLAGS) \$(NATIVE_RPATHS) \$(PHP_GLOBAL_OBJS:.lo=.o) \$(PHP_SAPI_OBJS:.lo=.o) \$(PHP_FRAMEWORKS) \$(EXTRA_LIBS) \$(SAPI_EXTRA_LIBS) \$(ZEND_EXTRA_LIBS) -o \$(SAPI_FPM_PATH)"
638      ;;
639      *)
640        BUILD_FPM="\$(LIBTOOL) --mode=link \$(CC) -export-dynamic \$(CFLAGS_CLEAN) \$(EXTRA_CFLAGS) \$(EXTRA_LDFLAGS_PROGRAM) \$(LDFLAGS) \$(PHP_RPATHS) \$(PHP_GLOBAL_OBJS) \$(PHP_SAPI_OBJS) \$(EXTRA_LIBS) \$(SAPI_EXTRA_LIBS) \$(ZEND_EXTRA_LIBS) -o \$(SAPI_FPM_PATH)"
641      ;;
642  esac
643
644  PHP_SUBST(BUILD_FPM)
645else
646  AC_MSG_RESULT(no)
647fi
648