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