Skip to content

Commit a87e7f5

Browse files
committed
Switch from curl-config to pkg-config for curl extension
First attemp to fix multiarch support (#74125) for curl introduce some debian specificity (dpkg command) so is not suitable for other environmant. This is mostly related to a broken "curl-config" config on debian which doesn't provide the correct build options, while pkg-config works as expected. This new attemp rely on pkg-config output instead. Notice: this make pkg-config a hard dependency. Is there system without pkg-config ?
1 parent debbaba commit a87e7f5

File tree

1 file changed

+76
-54
lines changed

1 file changed

+76
-54
lines changed

ext/curl/config.m4

Lines changed: 76 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -6,75 +6,97 @@ PHP_ARG_WITH(curl, for cURL support,
66
[ --with-curl[=DIR] Include cURL support])
77

88
if test "$PHP_CURL" != "no"; then
9-
if test -r $PHP_CURL/include/curl/easy.h; then
10-
CURL_DIR=$PHP_CURL
9+
if test -z "$PKG_CONFIG"; then
10+
AC_PATH_PROG(PKG_CONFIG, pkg-config, no)
11+
fi
12+
13+
if test -x "$PKG_CONFIG"; then
14+
dnl using pkg-config output
15+
16+
AC_MSG_CHECKING(for libcurl.pc)
17+
if test "$PHP_CURL" == "yes"; then
18+
PKNAME=libcurl
19+
AC_MSG_RESULT(using default path)
20+
elif test -r $PHP_CURL/$PHP_LIBDIR/pkgconfig/libcurl.pc; then
21+
PKNAME=$PHP_CURL/$PHP_LIBDIR/pkgconfig/libcurl.pc
22+
AC_MSG_RESULT(using $PKNAME)
23+
elif test -r $PHP_CURL/lib/pkgconfig/libcurl.pc; then
24+
PKNAME=$PHP_CURL/lib/pkgconfig/libcurl.pc
25+
AC_MSG_RESULT(using $PKNAME)
26+
else
27+
AC_MSG_ERROR(Could not find libcurl.pc)
28+
fi
29+
30+
AC_MSG_CHECKING(for cURL 7.10.5 or greater)
31+
if $PKG_CONFIG --atleast-version 7.10.5 $PKNAME; then
32+
curl_version_full=`$PKG_CONFIG --modversion $PKNAME`
33+
AC_MSG_RESULT($curl_version_full)
34+
else
35+
AC_MSG_ERROR(cURL version 7.10.5 or later is required to compile php with cURL support)
36+
fi
37+
38+
CURL_LIBS=`$PKG_CONFIG --libs $PKNAME`
39+
CURL_INCL=`$PKG_CONFIG --cflags $PKNAME`
40+
CURL_SSL=`$PKG_CONFIG --variable=supported_features $PKNAME| $EGREP SSL`
1141
else
12-
AC_MSG_CHECKING(for cURL in default path)
13-
for i in /usr/local /usr; do
14-
if test -r $i/include/curl/easy.h; then
15-
CURL_DIR=$i
16-
AC_MSG_RESULT(found in $i)
17-
break
18-
fi
19-
done
42+
dnl fallback to old vay, using curl-config
43+
44+
if test -r $PHP_CURL/include/curl/easy.h; then
45+
CURL_DIR=$PHP_CURL
46+
else
47+
AC_MSG_CHECKING(for cURL in default path)
48+
for i in /usr/local /usr; do
49+
if test -r $i/include/curl/easy.h; then
50+
CURL_DIR=$i
51+
AC_MSG_RESULT(found in $i)
52+
break
53+
fi
54+
done
55+
fi
56+
2057
if test -z "$CURL_DIR"; then
2158
AC_MSG_RESULT(not found)
22-
if which dpkg-architecture>/dev/null; then
23-
AC_MSG_CHECKING(for cURL in multiarch path)
24-
CURL_MULTIARCH_INCLUDE=/usr/include/$(dpkg-architecture -qDEB_HOST_MULTIARCH)
25-
if test -r $CURL_MULTIARCH_INCLUDE/curl/easy.h; then
26-
CURL_DIR=/usr
27-
AC_MSG_RESULT(found in $CURL_MULTIARCH_INCLUDE)
28-
else
29-
AC_MSG_RESULT(not found)
30-
fi
31-
fi
59+
AC_MSG_ERROR(Please reinstall the libcurl distribution -
60+
easy.h should be in <curl-dir>/include/curl/)
3261
fi
33-
fi
3462

35-
if test -z "$CURL_DIR"; then
36-
AC_MSG_ERROR(Could not find cURL, please reinstall the libcurl distribution -
37-
easy.h should be in <curl-dir>/include/curl/)
38-
fi
63+
CURL_CONFIG="curl-config"
64+
AC_MSG_CHECKING(for cURL 7.10.5 or greater)
3965

40-
CURL_CONFIG="curl-config"
41-
AC_MSG_CHECKING(for cURL 7.10.5 or greater)
66+
if ${CURL_DIR}/bin/curl-config --libs > /dev/null 2>&1; then
67+
CURL_CONFIG=${CURL_DIR}/bin/curl-config
68+
else
69+
if ${CURL_DIR}/curl-config --libs > /dev/null 2>&1; then
70+
CURL_CONFIG=${CURL_DIR}/curl-config
71+
fi
72+
fi
4273

43-
if ${CURL_DIR}/bin/curl-config --libs > /dev/null 2>&1; then
44-
CURL_CONFIG=${CURL_DIR}/bin/curl-config
45-
else
46-
if ${CURL_DIR}/curl-config --libs > /dev/null 2>&1; then
47-
CURL_CONFIG=${CURL_DIR}/curl-config
74+
curl_version_full=`$CURL_CONFIG --version`
75+
curl_version=`echo ${curl_version_full} | sed -e 's/libcurl //' | $AWK 'BEGIN { FS = "."; } { printf "%d", ($1 * 1000 + $2) * 1000 + $3;}'`
76+
if test "$curl_version" -ge 7010005; then
77+
AC_MSG_RESULT($curl_version_full)
78+
CURL_LIBS=`$CURL_CONFIG --libs`
79+
CURL_INCL=`$CURL_CONFIG --cflags`
80+
CURL_SSL=`$CURL_CONFIG --feature | $EGREP SSL`
81+
else
82+
AC_MSG_ERROR(cURL version 7.10.5 or later is required to compile php with cURL support)
4883
fi
4984
fi
5085

51-
curl_version_full=`$CURL_CONFIG --version`
52-
curl_version=`echo ${curl_version_full} | sed -e 's/libcurl //' | $AWK 'BEGIN { FS = "."; } { printf "%d", ($1 * 1000 + $2) * 1000 + $3;}'`
53-
if test "$curl_version" -ge 7010005; then
54-
AC_MSG_RESULT($curl_version_full)
55-
CURL_LIBS=`$CURL_CONFIG --libs`
56-
else
57-
AC_MSG_ERROR(cURL version 7.10.5 or later is required to compile php with cURL support)
58-
fi
86+
dnl common stuff (pkg-config / curl-config)
5987

60-
if test -z "$CURL_MULTIARCH_INCLUDE"; then
61-
PHP_ADD_INCLUDE($CURL_DIR/include)
62-
else
63-
PHP_ADD_INCLUDE($CURL_MULTIARCH_INCLUDE)
64-
fi
6588
PHP_EVAL_LIBLINE($CURL_LIBS, CURL_SHARED_LIBADD)
66-
PHP_ADD_LIBRARY_WITH_PATH(curl, $CURL_DIR/$PHP_LIBDIR, CURL_SHARED_LIBADD)
89+
PHP_EVAL_INCLINE($CURL_INCL, CURL_SHARED_LIBADD)
6790

6891
AC_MSG_CHECKING([for SSL support in libcurl])
69-
CURL_SSL=`$CURL_CONFIG --feature | $EGREP SSL`
70-
if test "$CURL_SSL" = "SSL"; then
92+
if test -n "$CURL_SSL"; then
7193
AC_MSG_RESULT([yes])
7294
AC_DEFINE([HAVE_CURL_SSL], [1], [Have cURL with SSL support])
7395

7496
save_CFLAGS="$CFLAGS"
75-
CFLAGS="`$CURL_CONFIG --cflags`"
76-
save_LDFLAGS="$LDFLAGS"
77-
LDFLAGS="`$CURL_CONFIG --libs`"
97+
CFLAGS=$CURL_INCL
98+
save_LDFLAGS="$CFLAGS"
99+
LDFLAGS=$CURL_LIBS
78100

79101
AC_PROG_CPP
80102
AC_MSG_CHECKING([for openssl support in libcurl])
@@ -145,21 +167,21 @@ int main(int argc, char *argv[])
145167
],[
146168
AC_MSG_ERROR(There is something wrong. Please check config.log for more information.)
147169
],[
148-
$CURL_LIBS -L$CURL_DIR/$PHP_LIBDIR
170+
$CURL_LIBS
149171
])
150172

151173
PHP_CHECK_LIBRARY(curl,curl_easy_strerror,
152174
[
153175
AC_DEFINE(HAVE_CURL_EASY_STRERROR,1,[ ])
154176
],[],[
155-
$CURL_LIBS -L$CURL_DIR/$PHP_LIBDIR
177+
$CURL_LIBS
156178
])
157179

158180
PHP_CHECK_LIBRARY(curl,curl_multi_strerror,
159181
[
160182
AC_DEFINE(HAVE_CURL_MULTI_STRERROR,1,[ ])
161183
],[],[
162-
$CURL_LIBS -L$CURL_DIR/$PHP_LIBDIR
184+
$CURL_LIBS
163185
])
164186

165187
PHP_NEW_EXTENSION(curl, interface.c multi.c share.c curl_file.c, $ext_shared)

0 commit comments

Comments
 (0)