xref: /PHP-7.1/ext/opcache/config.m4 (revision 7f6387b5)
1dnl
2dnl $Id$
3dnl
4
5PHP_ARG_ENABLE(opcache, whether to enable Zend OPcache support,
6[  --disable-opcache       Disable Zend OPcache support], yes)
7
8PHP_ARG_ENABLE(opcache-file, whether to enable file based caching,
9[  --disable-opcache-file  Disable file based caching], yes, no)
10
11PHP_ARG_ENABLE(huge-code-pages, whether to enable copying PHP CODE pages into HUGE PAGES,
12[  --disable-huge-code-pages
13                          Disable copying PHP CODE pages into HUGE PAGES], yes, no)
14
15if test "$PHP_OPCACHE" != "no"; then
16
17  if test "$PHP_OPCACHE_FILE" = "yes"; then
18    AC_DEFINE(HAVE_OPCACHE_FILE_CACHE, 1, [Define to enable file based caching (experimental)])
19  fi
20
21  if test "$PHP_HUGE_CODE_PAGES" = "yes"; then
22    AC_DEFINE(HAVE_HUGE_CODE_PAGES, 1, [Define to enable copying PHP CODE pages into HUGE PAGES (experimental)])
23  fi
24
25  AC_CHECK_FUNC(mprotect,[
26    AC_DEFINE(HAVE_MPROTECT, 1, [Define if you have mprotect() function])
27  ])
28
29  AC_CHECK_HEADERS([unistd.h sys/uio.h])
30
31  AC_MSG_CHECKING(for sysvipc shared memory support)
32  AC_TRY_RUN([
33#include <sys/types.h>
34#include <sys/wait.h>
35#include <sys/ipc.h>
36#include <sys/shm.h>
37#include <unistd.h>
38#include <string.h>
39
40int main() {
41  pid_t pid;
42  int status;
43  int ipc_id;
44  char *shm;
45  struct shmid_ds shmbuf;
46
47  ipc_id = shmget(IPC_PRIVATE, 4096, (IPC_CREAT | SHM_R | SHM_W));
48  if (ipc_id == -1) {
49    return 1;
50  }
51
52  shm = shmat(ipc_id, NULL, 0);
53  if (shm == (void *)-1) {
54    shmctl(ipc_id, IPC_RMID, NULL);
55    return 2;
56  }
57
58  if (shmctl(ipc_id, IPC_STAT, &shmbuf) != 0) {
59    shmdt(shm);
60    shmctl(ipc_id, IPC_RMID, NULL);
61    return 3;
62  }
63
64  shmbuf.shm_perm.uid = getuid();
65  shmbuf.shm_perm.gid = getgid();
66  shmbuf.shm_perm.mode = 0600;
67
68  if (shmctl(ipc_id, IPC_SET, &shmbuf) != 0) {
69    shmdt(shm);
70    shmctl(ipc_id, IPC_RMID, NULL);
71    return 4;
72  }
73
74  shmctl(ipc_id, IPC_RMID, NULL);
75
76  strcpy(shm, "hello");
77
78  pid = fork();
79  if (pid < 0) {
80    return 5;
81  } else if (pid == 0) {
82    strcpy(shm, "bye");
83    return 6;
84  }
85  if (wait(&status) != pid) {
86    return 7;
87  }
88  if (!WIFEXITED(status) || WEXITSTATUS(status) != 6) {
89    return 8;
90  }
91  if (strcmp(shm, "bye") != 0) {
92    return 9;
93  }
94  return 0;
95}
96],dnl
97    AC_DEFINE(HAVE_SHM_IPC, 1, [Define if you have SysV IPC SHM support])
98    msg=yes,msg=no,msg=no)
99  AC_MSG_RESULT([$msg])
100
101  AC_MSG_CHECKING(for mmap() using MAP_ANON shared memory support)
102  AC_TRY_RUN([
103#include <sys/types.h>
104#include <sys/wait.h>
105#include <sys/mman.h>
106#include <unistd.h>
107#include <string.h>
108
109#ifndef MAP_ANON
110# ifdef MAP_ANONYMOUS
111#  define MAP_ANON MAP_ANONYMOUS
112# endif
113#endif
114#ifndef MAP_FAILED
115# define MAP_FAILED ((void*)-1)
116#endif
117
118int main() {
119  pid_t pid;
120  int status;
121  char *shm;
122
123  shm = mmap(NULL, 4096, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANON, -1, 0);
124  if (shm == MAP_FAILED) {
125    return 1;
126  }
127
128  strcpy(shm, "hello");
129
130  pid = fork();
131  if (pid < 0) {
132    return 5;
133  } else if (pid == 0) {
134    strcpy(shm, "bye");
135    return 6;
136  }
137  if (wait(&status) != pid) {
138    return 7;
139  }
140  if (!WIFEXITED(status) || WEXITSTATUS(status) != 6) {
141    return 8;
142  }
143  if (strcmp(shm, "bye") != 0) {
144    return 9;
145  }
146  return 0;
147}
148],dnl
149    AC_DEFINE(HAVE_SHM_MMAP_ANON, 1, [Define if you have mmap(MAP_ANON) SHM support])
150    msg=yes,msg=no,msg=no)
151  AC_MSG_RESULT([$msg])
152
153  AC_MSG_CHECKING(for mmap() using /dev/zero shared memory support)
154  AC_TRY_RUN([
155#include <sys/types.h>
156#include <sys/wait.h>
157#include <sys/mman.h>
158#include <sys/stat.h>
159#include <fcntl.h>
160#include <unistd.h>
161#include <string.h>
162
163#ifndef MAP_FAILED
164# define MAP_FAILED ((void*)-1)
165#endif
166
167int main() {
168  pid_t pid;
169  int status;
170  int fd;
171  char *shm;
172
173  fd = open("/dev/zero", O_RDWR, S_IRUSR | S_IWUSR);
174  if (fd == -1) {
175    return 1;
176  }
177
178  shm = mmap(NULL, 4096, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
179  if (shm == MAP_FAILED) {
180    return 2;
181  }
182
183  strcpy(shm, "hello");
184
185  pid = fork();
186  if (pid < 0) {
187    return 5;
188  } else if (pid == 0) {
189    strcpy(shm, "bye");
190    return 6;
191  }
192  if (wait(&status) != pid) {
193    return 7;
194  }
195  if (!WIFEXITED(status) || WEXITSTATUS(status) != 6) {
196    return 8;
197  }
198  if (strcmp(shm, "bye") != 0) {
199    return 9;
200  }
201  return 0;
202}
203],dnl
204    AC_DEFINE(HAVE_SHM_MMAP_ZERO, 1, [Define if you have mmap("/dev/zero") SHM support])
205    msg=yes,msg=no,msg=no)
206  AC_MSG_RESULT([$msg])
207
208  AC_MSG_CHECKING(for mmap() using shm_open() shared memory support)
209  AC_TRY_RUN([
210#include <sys/types.h>
211#include <sys/wait.h>
212#include <sys/mman.h>
213#include <sys/stat.h>
214#include <fcntl.h>
215#include <unistd.h>
216#include <string.h>
217#include <stdlib.h>
218#include <stdio.h>
219
220#ifndef MAP_FAILED
221# define MAP_FAILED ((void*)-1)
222#endif
223
224int main() {
225  pid_t pid;
226  int status;
227  int fd;
228  char *shm;
229  char tmpname[4096];
230
231  sprintf(tmpname,"test.shm.%dXXXXXX", getpid());
232  if (mktemp(tmpname) == NULL) {
233    return 1;
234  }
235  fd = shm_open(tmpname, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);
236  if (fd == -1) {
237    return 2;
238  }
239  if (ftruncate(fd, 4096) < 0) {
240    close(fd);
241    shm_unlink(tmpname);
242    return 3;
243  }
244
245  shm = mmap(NULL, 4096, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
246  if (shm == MAP_FAILED) {
247    return 4;
248  }
249  shm_unlink(tmpname);
250  close(fd);
251
252  strcpy(shm, "hello");
253
254  pid = fork();
255  if (pid < 0) {
256    return 5;
257  } else if (pid == 0) {
258    strcpy(shm, "bye");
259    return 6;
260  }
261  if (wait(&status) != pid) {
262    return 7;
263  }
264  if (!WIFEXITED(status) || WEXITSTATUS(status) != 6) {
265    return 8;
266  }
267  if (strcmp(shm, "bye") != 0) {
268    return 9;
269  }
270  return 0;
271}
272],dnl
273    AC_DEFINE(HAVE_SHM_MMAP_POSIX, 1, [Define if you have POSIX mmap() SHM support])
274    msg=yes,msg=no,msg=no)
275  AC_MSG_RESULT([$msg])
276
277  AC_MSG_CHECKING(for mmap() using regular file shared memory support)
278  AC_TRY_RUN([
279#include <sys/types.h>
280#include <sys/wait.h>
281#include <sys/mman.h>
282#include <sys/stat.h>
283#include <fcntl.h>
284#include <unistd.h>
285#include <string.h>
286#include <stdlib.h>
287#include <stdio.h>
288
289#ifndef MAP_FAILED
290# define MAP_FAILED ((void*)-1)
291#endif
292
293int main() {
294  pid_t pid;
295  int status;
296  int fd;
297  char *shm;
298  char tmpname[4096];
299
300  sprintf(tmpname,"test.shm.%dXXXXXX", getpid());
301  if (mktemp(tmpname) == NULL) {
302    return 1;
303  }
304  fd = open(tmpname, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);
305  if (fd == -1) {
306    return 2;
307  }
308  if (ftruncate(fd, 4096) < 0) {
309    close(fd);
310    unlink(tmpname);
311    return 3;
312  }
313
314  shm = mmap(NULL, 4096, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
315  if (shm == MAP_FAILED) {
316    return 4;
317  }
318  unlink(tmpname);
319  close(fd);
320
321  strcpy(shm, "hello");
322
323  pid = fork();
324  if (pid < 0) {
325    return 5;
326  } else if (pid == 0) {
327    strcpy(shm, "bye");
328    return 6;
329  }
330  if (wait(&status) != pid) {
331    return 7;
332  }
333  if (!WIFEXITED(status) || WEXITSTATUS(status) != 6) {
334    return 8;
335  }
336  if (strcmp(shm, "bye") != 0) {
337    return 9;
338  }
339  return 0;
340}
341],dnl
342    AC_DEFINE(HAVE_SHM_MMAP_FILE, 1, [Define if you have mmap() SHM support])
343    msg=yes,msg=no,msg=no)
344  AC_MSG_RESULT([$msg])
345
346flock_type=unknown
347AC_MSG_CHECKING("whether flock struct is linux ordered")
348AC_TRY_RUN([
349  #include <fcntl.h>
350  struct flock lock = { 1, 2, 3, 4, 5 };
351  int main() {
352    if(lock.l_type == 1 && lock.l_whence == 2 && lock.l_start == 3 && lock.l_len == 4) {
353		return 0;
354    }
355    return 1;
356  }
357], [
358	flock_type=linux
359    AC_DEFINE([HAVE_FLOCK_LINUX], [], [Struct flock is Linux-type])
360    AC_MSG_RESULT("yes")
361], AC_MSG_RESULT("no") )
362
363AC_MSG_CHECKING("whether flock struct is BSD ordered")
364AC_TRY_RUN([
365  #include <fcntl.h>
366  struct flock lock = { 1, 2, 3, 4, 5 };
367  int main() {
368    if(lock.l_start == 1 && lock.l_len == 2 && lock.l_type == 4 && lock.l_whence == 5) {
369		return 0;
370    }
371    return 1;
372  }
373], [
374	flock_type=bsd
375    AC_DEFINE([HAVE_FLOCK_BSD], [], [Struct flock is BSD-type])
376    AC_MSG_RESULT("yes")
377], AC_MSG_RESULT("no") )
378
379if test "$flock_type" = "unknown"; then
380	AC_MSG_ERROR([Don't know how to define struct flock on this system[,] set --enable-opcache=no])
381fi
382
383  PHP_NEW_EXTENSION(opcache,
384	ZendAccelerator.c \
385	zend_accelerator_blacklist.c \
386	zend_accelerator_debug.c \
387	zend_accelerator_hash.c \
388	zend_accelerator_module.c \
389	zend_persist.c \
390	zend_persist_calc.c \
391	zend_file_cache.c \
392	zend_shared_alloc.c \
393	zend_accelerator_util_funcs.c \
394	shared_alloc_shm.c \
395	shared_alloc_mmap.c \
396	shared_alloc_posix.c \
397	Optimizer/zend_optimizer.c \
398	Optimizer/pass1_5.c \
399	Optimizer/pass2.c \
400	Optimizer/pass3.c \
401	Optimizer/optimize_func_calls.c \
402	Optimizer/block_pass.c \
403	Optimizer/optimize_temp_vars_5.c \
404	Optimizer/nop_removal.c \
405	Optimizer/compact_literals.c \
406	Optimizer/zend_cfg.c \
407	Optimizer/zend_dfg.c \
408	Optimizer/dfa_pass.c \
409	Optimizer/zend_ssa.c \
410	Optimizer/zend_inference.c \
411	Optimizer/zend_func_info.c \
412	Optimizer/zend_call_graph.c \
413	Optimizer/zend_dump.c,
414	shared,,-DZEND_ENABLE_STATIC_TSRMLS_CACHE=1,,yes)
415
416  PHP_ADD_BUILD_DIR([$ext_builddir/Optimizer], 1)
417  PHP_ADD_EXTENSION_DEP(opcache, pcre)
418fi
419