Skip to content

Commit 5b671b6

Browse files
committed
Remove Readline library integration
This removes the GNU Readline library integration and relies on the libedit library if present. Issue is that there are several ext/readline libraries and GNU Readline license (GNU GPL 3) is not compatible with the PHP license. There was a similar attempt to fix this (GH-3823) and now fix continues here. Changes: - `--with-libedit` configure option removed (only `--with-readline` stays) This also fixes the phpdbg readline integration on *nix systems (using libedit library) for history (up/down keys and similar nice features).
1 parent 5e7a1cc commit 5b671b6

28 files changed

+54
-495
lines changed

.circleci/config.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ jobs:
5757
libxml2-dev \
5858
libxslt1-dev \
5959
libpq-dev \
60-
libreadline-dev \
60+
libedit-dev \
6161
libldap2-dev \
6262
libsodium-dev \
6363
libargon2-0-dev \

.github/actions/apk/action.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ runs:
4141
libzip-dev \
4242
oniguruma-dev \
4343
openssl-dev \
44-
readline-dev \
44+
libedit-dev \
4545
sqlite-dev \
4646
tidyhtml-dev \
4747
krb5-dev \

.github/actions/apt-x32/action.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ runs:
2828
libonig-dev:i386 \
2929
libpng-dev:i386 \
3030
libpq-dev:i386 \
31-
libreadline-dev:i386 \
31+
libedit-dev:i386 \
3232
libsasl2-dev:i386 \
3333
libsodium-dev:i386 \
3434
libsqlite3-dev:i386 \

.github/actions/configure-macos/action.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ runs:
4545
--enable-sysvshm \
4646
--enable-shmop \
4747
--enable-pcntl \
48-
--with-readline="$BREW_OPT"/readline \
48+
--with-readline \
4949
--enable-mbstring \
5050
--with-curl \
5151
--with-gettext="$BREW_OPT"/gettext \

.github/actions/configure-x64/action.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ runs:
4141
--enable-sysvshm \
4242
--enable-shmop \
4343
--enable-pcntl \
44-
--without-readline --with-libedit \
44+
--with-readline \
4545
--enable-mbstring \
4646
--with-curl \
4747
--with-gettext \

build/php.m4

+17
Original file line numberDiff line numberDiff line change
@@ -2002,6 +2002,23 @@ $2],
20022002
]))])])
20032003
])
20042004

2005+
dnl
2006+
dnl
2007+
dnl PHP_SETUP_EDIT([shared-add], [action-if-found], [action-if-not-found])
2008+
dnl
2009+
dnl Common setup macro for linking libedit library.
2010+
dnl
2011+
AC_DEFUN([PHP_SETUP_EDIT], [
2012+
PKG_CHECK_MODULES([EDIT], [libedit], [
2013+
PHP_EVAL_INCLINE([$EDIT_CFLAGS])
2014+
PHP_EVAL_LIBLINE([$EDIT_LIBS], [$1])
2015+
AC_DEFINE([HAVE_LIBEDIT], [1],
2016+
[Define to 1 if 'libedit' library is available.])
2017+
$2
2018+
],
2019+
[$3])
2020+
])
2021+
20052022
dnl ----------------------------------------------------------------------------
20062023
dnl Misc. macros
20072024
dnl ----------------------------------------------------------------------------

ext/readline/config.m4

+13-104
Original file line numberDiff line numberDiff line change
@@ -1,103 +1,17 @@
1-
PHP_ARG_WITH([libedit],
2-
[for libedit readline replacement],
3-
[AS_HELP_STRING([--with-libedit],
4-
[Include libedit readline replacement (CLI/CGI only)])])
1+
PHP_ARG_WITH([readline],
2+
[for readline support],
3+
[AS_HELP_STRING([--with-readline],
4+
[Include readline support using the libedit library (CLI/CGI only)])])
55

6-
if test "$PHP_LIBEDIT" = "no"; then
7-
PHP_ARG_WITH([readline],
8-
[for readline support],
9-
[AS_HELP_STRING([[--with-readline[=DIR]]],
10-
[Include readline support (CLI/CGI only)])])
11-
else
12-
dnl "register" the --with-readline option to prevent invalid "unknown
13-
dnl configure option" warning
14-
php_with_readline=no
15-
fi
16-
17-
if test "$PHP_READLINE" && test "$PHP_READLINE" != "no"; then
18-
for i in $PHP_READLINE /usr/local /usr; do
19-
AS_IF([test -f $i/include/readline/readline.h], [READLINE_DIR=$i; break;])
20-
done
21-
22-
AS_VAR_IF([READLINE_DIR],,
23-
[AC_MSG_ERROR([Please reinstall readline - I cannot find readline.h])])
24-
25-
PHP_ADD_INCLUDE([$READLINE_DIR/include])
26-
27-
PHP_READLINE_LIBS=""
28-
AC_CHECK_LIB([ncurses], [tgetent], [
29-
PHP_ADD_LIBRARY([ncurses],, [READLINE_SHARED_LIBADD])
30-
PHP_READLINE_LIBS="$PHP_READLINE_LIBS -lncurses"
31-
],
32-
[AC_CHECK_LIB([termcap], [tgetent], [
33-
PHP_ADD_LIBRARY([termcap],, [READLINE_SHARED_LIBADD])
34-
PHP_READLINE_LIBS="$PHP_READLINE_LIBS -ltermcap"
35-
])
36-
])
37-
38-
PHP_CHECK_LIBRARY([readline], [readline],
39-
[PHP_ADD_LIBRARY_WITH_PATH([readline],
40-
[$READLINE_DIR/$PHP_LIBDIR],
41-
[READLINE_SHARED_LIBADD])],
42-
[AC_MSG_FAILURE([The readline library not found.])],
43-
[-L$READLINE_DIR/$PHP_LIBDIR $PHP_READLINE_LIBS])
44-
45-
PHP_CHECK_LIBRARY([readline], [rl_callback_read_char],
46-
[AC_DEFINE([HAVE_RL_CALLBACK_READ_CHAR], [1])],
47-
[],
48-
[-L$READLINE_DIR/$PHP_LIBDIR $PHP_READLINE_LIBS])
49-
50-
PHP_CHECK_LIBRARY([readline], [rl_on_new_line],
51-
[AC_DEFINE([HAVE_RL_ON_NEW_LINE], [1])],
52-
[],
53-
[-L$READLINE_DIR/$PHP_LIBDIR $PHP_READLINE_LIBS])
54-
55-
PHP_CHECK_LIBRARY([readline], [rl_completion_matches],
56-
[AC_DEFINE([HAVE_RL_COMPLETION_MATCHES], [1])],
57-
[],
58-
[-L$READLINE_DIR/$PHP_LIBDIR $PHP_READLINE_LIBS])
6+
if test "$PHP_READLINE" != "no"; then
7+
AS_VAR_IF([PHP_READLINE], [yes],,
8+
[AC_MSG_WARN([m4_text_wrap([
9+
The directory argument is not supported anymore, rely on pkg-config.
10+
Replace '--with-readline=$PHP_READLINE' with '--with-realine' and use
11+
environment variables 'PKG_CONFIG_PATH', 'EDIT_LIBS', or 'EDIT_CFLAGS'.
12+
])])])
5913

60-
CFLAGS_SAVE=$CFLAGS
61-
LDFLAGS_SAVE=$LDFLAGS
62-
LIBS_SAVE=$LIBS
63-
CFLAGS="$CFLAGS $INCLUDES"
64-
LDFLAGS="$LDFLAGS -L$READLINE_DIR/$PHP_LIBDIR"
65-
LIBS="$LIBS -lreadline"
66-
67-
dnl Sanity and minimum version check if readline library has variable
68-
dnl rl_pending_input.
69-
AC_CHECK_DECL([rl_pending_input],, [AC_MSG_FAILURE([
70-
Invalid readline installation detected. Try --with-libedit instead.
71-
])], [
72-
#include <stdio.h>
73-
#include <readline/readline.h>
74-
])
75-
76-
AC_CHECK_DECL([rl_erase_empty_line],
77-
[AC_DEFINE([HAVE_ERASE_EMPTY_LINE], [1])],, [
78-
#include <stdio.h>
79-
#include <readline/readline.h>
80-
])
81-
CFLAGS=$CFLAGS_SAVE
82-
LDFLAGS=$LDFLAGS_SAVE
83-
LIBS=$LIBS_SAVE
84-
85-
AC_DEFINE([HAVE_HISTORY_LIST], [1])
86-
AC_DEFINE([HAVE_LIBREADLINE], [1],
87-
[Define to 1 if readline extension uses the 'readline' library.])
88-
89-
elif test "$PHP_LIBEDIT" != "no"; then
90-
AS_VAR_IF([PHP_LIBEDIT], [yes],,
91-
[AC_MSG_WARN(m4_text_wrap([
92-
The libedit directory argument is not supported anymore, rely on
93-
pkg-config. Replace '--with-libedit=$PHP_LIBEDIT' with '--with-libedit'
94-
and use environment variables 'PKG_CONFIG_PATH', 'EDIT_LIBS', or
95-
'EDIT_CFLAGS'.
96-
]))])
97-
98-
PKG_CHECK_MODULES([EDIT], [libedit])
99-
PHP_EVAL_LIBLINE([$EDIT_LIBS], [READLINE_SHARED_LIBADD])
100-
PHP_EVAL_INCLINE([$EDIT_CFLAGS])
14+
PHP_SETUP_EDIT([READLINE_SHARED_LIBADD])
10115

10216
AC_CHECK_LIB([ncurses], [tgetent],
10317
[PHP_ADD_LIBRARY([ncurses],, [READLINE_SHARED_LIBADD])],
@@ -148,12 +62,7 @@ elif test "$PHP_LIBEDIT" != "no"; then
14862
CFLAGS=$CFLAGS_SAVE
14963
LIBS=$LIBS_SAVE
15064

151-
AC_DEFINE([HAVE_LIBEDIT], [1],
152-
[Define to 1 if readline extension uses the 'libedit' library.])
153-
fi
154-
155-
if test "$PHP_READLINE" != "no" || test "$PHP_LIBEDIT" != "no"; then
156-
dnl Add -Wno-strict-prototypes as depends on user libs
65+
dnl Add -Wno-strict-prototypes as depends on user libs
15766
PHP_NEW_EXTENSION([readline],
15867
[readline.c readline_cli.c],
15968
[$ext_shared],

ext/readline/php_readline.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@
2020
#ifdef HAVE_LIBEDIT
2121
#define READLINE_LIB "libedit"
2222
#else
23-
#define READLINE_LIB "readline"
23+
#define READLINE_LIB ""
2424
#endif
2525

26-
#if defined(HAVE_LIBREADLINE) || defined(HAVE_LIBEDIT)
26+
#ifdef HAVE_LIBEDIT
2727

2828
extern zend_module_entry readline_module_entry;
2929
#define phpext_readline_ptr &readline_module_entry
@@ -35,6 +35,6 @@ extern zend_module_entry readline_module_entry;
3535

3636
#define phpext_readline_ptr NULL
3737

38-
#endif /* HAVE_LIBREADLINE */
38+
#endif /* HAVE_LIBEDIT */
3939

4040
#endif /* PHP_READLINE_H */

0 commit comments

Comments
 (0)