xref: /PHP-7.2/ext/opcache/config.m4 (revision 92227026)
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
346  PHP_NEW_EXTENSION(opcache,
347	ZendAccelerator.c \
348	zend_accelerator_blacklist.c \
349	zend_accelerator_debug.c \
350	zend_accelerator_hash.c \
351	zend_accelerator_module.c \
352	zend_persist.c \
353	zend_persist_calc.c \
354	zend_file_cache.c \
355	zend_shared_alloc.c \
356	zend_accelerator_util_funcs.c \
357	shared_alloc_shm.c \
358	shared_alloc_mmap.c \
359	shared_alloc_posix.c \
360	Optimizer/zend_optimizer.c \
361	Optimizer/pass1_5.c \
362	Optimizer/pass2.c \
363	Optimizer/pass3.c \
364	Optimizer/optimize_func_calls.c \
365	Optimizer/block_pass.c \
366	Optimizer/optimize_temp_vars_5.c \
367	Optimizer/nop_removal.c \
368	Optimizer/compact_literals.c \
369	Optimizer/zend_cfg.c \
370	Optimizer/zend_dfg.c \
371	Optimizer/dfa_pass.c \
372	Optimizer/zend_ssa.c \
373	Optimizer/zend_inference.c \
374	Optimizer/zend_func_info.c \
375	Optimizer/zend_call_graph.c \
376	Optimizer/sccp.c \
377	Optimizer/scdf.c \
378	Optimizer/dce.c \
379	Optimizer/compact_vars.c \
380	Optimizer/zend_dump.c,
381	shared,,-DZEND_ENABLE_STATIC_TSRMLS_CACHE=1,,yes)
382
383  PHP_ADD_BUILD_DIR([$ext_builddir/Optimizer], 1)
384  PHP_ADD_EXTENSION_DEP(opcache, pcre)
385fi
386