1From 24b4e273bd503760a485e92ca418e4699767ec51 Mon Sep 17 00:00:00 2001
2From: Shyim <github@shyim.de>
3Date: Thu, 28 Dec 2023 10:38:42 +0100
4Subject: [PATCH] [php]: add with-grpc-dir to configure and add pkg-config
5 support
6
7---
8 config.m4 | 48 +++++++++++++++++++++++++-------------
9 1 file changed, 32 insertions(+), 16 deletions(-)
10
11diff --git a/config.m4 b/config.m4
12index 5600df34ccfa3..c2186a41d21f5 100755
13--- a/config.m4
14+++ b/config.m4
15@@ -7,35 +7,51 @@ PHP_ARG_ENABLE(coverage, whether to include code coverage symbols,
16 PHP_ARG_ENABLE(tests, whether to compile helper methods for tests,
17 [ --enable-tests Enable tests methods], no, no)
18
19+PHP_ARG_WITH(grpc-dir, for grpc,
20+[ --with-grpc-dir[=DIR] Set the path to grpc install prefix.], yes)
21+
22 dnl Check whether to enable tests
23 if test "$PHP_TESTS" != "no"; then
24 CPPFLAGS="$CPPFLAGS -DGRPC_PHP_DEBUG"
25 fi
26
27 if test "$PHP_GRPC" != "no"; then
28- dnl Write more examples of tests here...
29-
30- dnl # --with-grpc -> check with-path
31- SEARCH_PATH="/usr/local /usr" # you might want to change this
32- SEARCH_FOR="include/grpc/grpc.h" # you most likely want to change this
33- if test -r $PHP_GRPC/$SEARCH_FOR; then # path given as parameter
34- GRPC_DIR=$PHP_GRPC
35- else # search default path list
36+ AC_PATH_PROG(PKG_CONFIG, pkg-config, no)
37+
38+ if test "$PHP_GRPC_DIR" = "yes" -a -x $PKG_CONFIG; then
39+ AC_MSG_CHECKING([for grpc using pkg-config])
40+
41+ if ! $PKG_CONFIG --exists grpc ; then
42+ AC_MSG_ERROR([grpc not found])
43+ fi
44+
45+ GRPC_VERSION=`$PKG_CONFIG grpc --modversion`
46+ AC_MSG_RESULT([found version $GRPC_VERSION])
47+
48+ PHP_GRPC_LIBS=`$PKG_CONFIG grpc --libs`
49+ PHP_GRPC_INCS=`$PKG_CONFIG grpc --cflags`
50+
51+ PHP_EVAL_LIBLINE($PHP_GRPC_LIBS, AMQP_SHARED_LIBADD)
52+ PHP_EVAL_INCLINE($PHP_GRPC_INCS)
53+ else
54 AC_MSG_CHECKING([for grpc files in default path])
55+
56+ SEARCH_PATH="$PHP_GRPC_DIR /usr/local /usr"
57+
58 for i in $SEARCH_PATH ; do
59- if test -r $i/$SEARCH_FOR; then
60+ if test -r $i/include/grpc/grpc.h; then
61 GRPC_DIR=$i
62 AC_MSG_RESULT(found in $i)
63 fi
64 done
65- fi
66- if test -z "$GRPC_DIR"; then
67- AC_MSG_RESULT([not found])
68- AC_MSG_ERROR([Please reinstall the grpc distribution])
69- fi
70
71- dnl # --with-grpc -> add include path
72- PHP_ADD_INCLUDE($GRPC_DIR/include)
73+ if test -z "$GRPC_DIR"; then
74+ AC_MSG_RESULT([not found])
75+ AC_MSG_ERROR([Please reinstall the grpc distribution])
76+ fi
77+
78+ PHP_ADD_INCLUDE($GRPC_DIR/include)
79+ fi
80
81 LIBS="-lpthread $LIBS"
82