From dd6ee0fb6715881b204fb4cb124db9134c1a6c7d Mon Sep 17 00:00:00 2001
From: Michael Heimpold <mhei@heimpold.de>
Date: Mon, 2 Dec 2019 22:42:28 +0100
Subject: [PATCH] ext/opcache: fix detection of shm/mmap

The detection of sysvipc and mmap doesn't work well when cross-compiling,
so I decided to only check for the availability of the functions involved.
This is not a clean solution, but works for now(tm) :-)

It should be discussed with upstream to find a better solution.

This solves the issue reported at
https://github.com/openwrt/packages/issues/1010
and makes opcache usable on OpenWrt.

Signed-off-by: Michael Heimpold <mhei@heimpold.de>
---
 ext/opcache/config.m4 | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

--- a/ext/opcache/config.m4
+++ b/ext/opcache/config.m4
@@ -89,7 +89,10 @@ int main() {
 }
 ]])],[dnl
     AC_DEFINE(HAVE_SHM_IPC, 1, [Define if you have SysV IPC SHM support])
-    msg=yes],[msg=no],[msg=no])
+    msg=yes],[msg=no],[dnl
+    AC_CHECK_FUNC(shmget,[dnl
+        AC_DEFINE(HAVE_SHM_IPC, 1, [Define if you have SysV IPC SHM support])
+        msg=yes],[msg=no])])
   AC_MSG_RESULT([$msg])
 
   AC_MSG_CHECKING(for mmap() using MAP_ANON shared memory support)
@@ -141,7 +144,10 @@ int main() {
 }
 ]])],[dnl
     AC_DEFINE(HAVE_SHM_MMAP_ANON, 1, [Define if you have mmap(MAP_ANON) SHM support])
-    msg=yes],[msg=no],[msg=no])
+    msg=yes],[msg=no],[dnl
+    AC_CHECK_FUNC(mmap,[dnl
+        AC_DEFINE(HAVE_SHM_MMAP_ANON, 1, [Define if you have mmap(MAP_ANON) SHM support])
+        msg=yes],[msg=no])])
   AC_MSG_RESULT([$msg])
 
   PHP_CHECK_FUNC_LIB(shm_open, rt)
