From 7d4ccea736c1ce325de00c23dee28c61de47e638 Mon Sep 17 00:00:00 2001
From: "Kevin P. Fleming" <kpfleming@digium.com>
Date: Wed, 25 Jul 2012 12:21:54 +0000
Subject: [PATCH] Enable usage of system-provided NetBSD editline library if
 available.

This patch changes the Asterisk configure script and build system to detect
the presence of the NetBSD editline library (libedit) on the system. If it is
found, it will be used in preference to the version included in the Asterisk
source tree.

(closes issue ASTERISK-18725)
Reported by: Jeffrey C. Ollie
Review: https://reviewboard.asterisk.org/r/1528/
Patches:
  0001-Allow-linking-building-against-an-external-editline.patch uploaded by jcollie (license #5373) (heavily modified by kpfleming)



git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@370481 65c4cc65-6c06-0410-ace0-fbb531ad65f3
---
 CHANGES                                 |   2 +
 build_tools/menuselect-deps.in          |   1 +
 configure                               | 161 +++++++++++++++++++++++-
 configure.ac                            |  25 +++-
 contrib/scripts/install_prereq          |   4 +-
 include/asterisk/autoconfig.h.in        |   3 +
 main/Makefile                           |  15 ++-
 main/asterisk.c                         |  29 ++---
 main/cli.c                              |   2 +-
 main/editline/configure                 |   2 +-
 main/editline/configure.in              |   2 +-
 main/editline/readline.c                |   2 +-
 main/editline/{readline => }/readline.h |   0
 makeopts.in                             |   4 +
 14 files changed, 215 insertions(+), 37 deletions(-)
 rename main/editline/{readline => }/readline.h (100%)

diff --git a/CHANGES b/CHANGES
index a0fce4547d..a64b38e47f 100644
--- a/CHANGES
+++ b/CHANGES
@@ -399,6 +399,8 @@ Core
    CONNECTED_LINE_SEND_SUB_ARGS.  For CCSS, use cc_callback_sub instead of
    cc_callback_macro in channel configurations.
 
+ * Asterisk can now use a system-provided NetBSD editline library (libedit) if it
+   is available.
 
 AGI
 ------------------
diff --git a/build_tools/menuselect-deps.in b/build_tools/menuselect-deps.in
index e8ab91a608..6f4418b26a 100644
--- a/build_tools/menuselect-deps.in
+++ b/build_tools/menuselect-deps.in
@@ -27,6 +27,7 @@ IXJUSER=@PBX_IXJUSER@
 JACK=@PBX_JACK@
 KQUEUE=@PBX_KQUEUE@
 LDAP=@PBX_LDAP@
+LIBEDIT=@PBX_LIBEDIT@
 LIBXML2=@PBX_LIBXML2@
 LTDL=@PBX_LTDL@
 LUA=@PBX_LUA@
diff --git a/configure b/configure
index 2005fa01f3..4933b842d4 100755
--- a/configure
+++ b/configure
@@ -1,5 +1,5 @@
 #! /bin/sh
-# From configure.ac Revision: 369346 .
+# From configure.ac Revision: 370407 .
 # Guess values for system-dependent variables and create Makefiles.
 # Generated by GNU Autoconf 2.68 for asterisk trunk.
 #
@@ -649,6 +649,9 @@ CONFIG_NEON
 CONFIG_MYSQLCLIENT
 PBX_MISDN_FAC_ERROR
 PBX_MISDN_FAC_RESULT
+LIBEDIT_LIBS
+LIBEDIT_CFLAGS
+LIBEDIT_INTERNAL
 ILBC_LIBS
 ILBC_CFLAGS
 ILBC_INTERNAL
@@ -934,6 +937,10 @@ PBX_LIBXML2
 LIBXML2_DIR
 LIBXML2_INCLUDE
 LIBXML2_LIB
+PBX_LIBEDIT
+LIBEDIT_DIR
+LIBEDIT_INCLUDE
+LIBEDIT_LIB
 CURL_LIB
 CURL_INCLUDE
 _libcurl_config
@@ -1214,6 +1221,7 @@ with_jack
 with_kqueue
 with_ldap
 with_libcurl
+with_libedit
 with_libxml2
 with_ltdl
 with_lua
@@ -1281,6 +1289,8 @@ PKG_CONFIG_PATH
 PKG_CONFIG_LIBDIR
 ILBC_CFLAGS
 ILBC_LIBS
+LIBEDIT_CFLAGS
+LIBEDIT_LIBS
 GMIME_CFLAGS
 GMIME_LIBS
 GTK2_CFLAGS
@@ -1940,6 +1950,8 @@ Optional Packages:
   --with-kqueue=PATH      use kqueue support files in PATH
   --with-ldap=PATH        use OpenLDAP files in PATH
   --with-libcurl=DIR      look for the curl library in DIR
+  --with-libedit=PATH     use NetBSD Editline library files in PATH, use
+                          'internal' Editline otherwise
   --with-libxml2=PATH     use LibXML2 files in PATH
   --with-ltdl=PATH        use libtool files in PATH
   --with-lua=PATH         use Lua files in PATH
@@ -2006,6 +2018,10 @@ Some influential environment variables:
               path overriding pkg-config's built-in search path
   ILBC_CFLAGS C compiler flags for ILBC, overriding pkg-config
   ILBC_LIBS   linker flags for ILBC, overriding pkg-config
+  LIBEDIT_CFLAGS
+              C compiler flags for LIBEDIT, overriding pkg-config
+  LIBEDIT_LIBS
+              linker flags for LIBEDIT, overriding pkg-config
   GMIME_CFLAGS
               C compiler flags for GMIME, overriding pkg-config
   GMIME_LIBS  linker flags for GMIME, overriding pkg-config
@@ -9213,6 +9229,38 @@ _ACEOF
   unset _libcurl_with
 
 
+    LIBEDIT_DESCRIP="NetBSD Editline library"
+    LIBEDIT_OPTION="libedit"
+    PBX_LIBEDIT=0
+
+# Check whether --with-libedit was given.
+if test "${with_libedit+set}" = set; then :
+  withval=$with_libedit;
+	case ${withval} in
+	n|no)
+	USE_LIBEDIT=no
+	# -1 is a magic value used by menuselect to know that the package
+	# was disabled, other than 'not found'
+	PBX_LIBEDIT=-1
+	;;
+	y|ye|yes)
+	ac_mandatory_list="${ac_mandatory_list} LIBEDIT"
+	;;
+	*)
+	LIBEDIT_DIR="${withval}"
+	ac_mandatory_list="${ac_mandatory_list} LIBEDIT"
+	;;
+	esac
+
+fi
+
+
+
+
+
+
+
+
     LIBXML2_DESCRIP="LibXML2"
     LIBXML2_OPTION="libxml2"
     PBX_LIBXML2=0
@@ -17998,8 +18046,8 @@ $as_echo "#define HAVE_ILBC 1" >>confdefs.h
 fi
    fi
 
-      if test "$PBX_ILBC" = '1'; then
-	 ILBC_INTERNAL='no'
+      if test "$PBX_ILBC" = "1"; then
+	 ILBC_INTERNAL="no"
       fi
    fi
    if test "${ILBC_INTERNAL}" = "yes"; then
@@ -18007,6 +18055,113 @@ fi
    fi
 fi
 
+LIBEDIT_INTERNAL="yes"
+
+LIBEDIT_SYSTEM="yes"
+if test "${USE_LIBEDIT}" != "no"; then
+   if test "${LIBEDIT_DIR}" = "internal"; then
+      LIBEDIT_SYSTEM="no"
+   elif test "${LIBEDIT_DIR}" != ""; then
+      LIBEDIT_INTERNAL="no"
+   fi
+   if test "${LIBEDIT_SYSTEM}" = "yes"; then
+
+   if test "x${PBX_LIBEDIT}" != "x1" -a "${USE_LIBEDIT}" != "no"; then
+
+pkg_failed=no
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for LIBEDIT" >&5
+$as_echo_n "checking for LIBEDIT... " >&6; }
+
+if test -n "$LIBEDIT_CFLAGS"; then
+    pkg_cv_LIBEDIT_CFLAGS="$LIBEDIT_CFLAGS"
+ elif test -n "$PKG_CONFIG"; then
+    if test -n "$PKG_CONFIG" && \
+    { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"libedit\""; } >&5
+  ($PKG_CONFIG --exists --print-errors "libedit") 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }; then
+  pkg_cv_LIBEDIT_CFLAGS=`$PKG_CONFIG --cflags "libedit" 2>/dev/null`
+		      test "x$?" != "x0" && pkg_failed=yes
+else
+  pkg_failed=yes
+fi
+ else
+    pkg_failed=untried
+fi
+if test -n "$LIBEDIT_LIBS"; then
+    pkg_cv_LIBEDIT_LIBS="$LIBEDIT_LIBS"
+ elif test -n "$PKG_CONFIG"; then
+    if test -n "$PKG_CONFIG" && \
+    { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"libedit\""; } >&5
+  ($PKG_CONFIG --exists --print-errors "libedit") 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }; then
+  pkg_cv_LIBEDIT_LIBS=`$PKG_CONFIG --libs "libedit" 2>/dev/null`
+		      test "x$?" != "x0" && pkg_failed=yes
+else
+  pkg_failed=yes
+fi
+ else
+    pkg_failed=untried
+fi
+
+
+
+if test $pkg_failed = yes; then
+   	{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+
+if $PKG_CONFIG --atleast-pkgconfig-version 0.20; then
+        _pkg_short_errors_supported=yes
+else
+        _pkg_short_errors_supported=no
+fi
+        if test $_pkg_short_errors_supported = yes; then
+	        LIBEDIT_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors --cflags --libs "libedit" 2>&1`
+        else
+	        LIBEDIT_PKG_ERRORS=`$PKG_CONFIG --print-errors --cflags --libs "libedit" 2>&1`
+        fi
+	# Put the nasty error message in config.log where it belongs
+	echo "$LIBEDIT_PKG_ERRORS" >&5
+
+
+            PBX_LIBEDIT=0
+
+
+elif test $pkg_failed = untried; then
+     	{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+
+            PBX_LIBEDIT=0
+
+
+else
+	LIBEDIT_CFLAGS=$pkg_cv_LIBEDIT_CFLAGS
+	LIBEDIT_LIBS=$pkg_cv_LIBEDIT_LIBS
+        { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
+
+            PBX_LIBEDIT=1
+            LIBEDIT_INCLUDE="$LIBEDIT_CFLAGS"
+            LIBEDIT_LIB="$LIBEDIT_LIBS"
+
+$as_echo "#define HAVE_LIBEDIT 1" >>confdefs.h
+
+
+fi
+   fi
+
+      if test "$PBX_LIBEDIT" = "1"; then
+	 LIBEDIT_INTERNAL="no"
+      fi
+   fi
+   if test "${LIBEDIT_INTERNAL}" = "yes"; then
+      PBX_LIBEDIT=1
+   fi
+fi
+
 
 if test "x${PBX_ICONV}" != "x1" -a "${USE_ICONV}" != "no"; then
    pbxlibdir=""
diff --git a/configure.ac b/configure.ac
index 55377d3184..99ed5110ed 100644
--- a/configure.ac
+++ b/configure.ac
@@ -406,6 +406,7 @@ AST_EXT_LIB_SETUP([JACK], [Jack Audio Connection Kit], [jack])
 AST_EXT_LIB_SETUP([KQUEUE], [kqueue support], [kqueue])
 AST_EXT_LIB_SETUP([LDAP], [OpenLDAP], [ldap])
 AST_LIBCURL_CHECK_CONFIG([], [7.10.1])
+AST_EXT_LIB_SETUP([LIBEDIT], [NetBSD Editline library], [libedit], [, use 'internal' Editline otherwise])
 AST_EXT_LIB_SETUP([LIBXML2], [LibXML2], [libxml2])
 AST_EXT_LIB_SETUP([LTDL], [libtool], [ltdl])
 AST_EXT_LIB_SETUP([LUA], [Lua], [lua])
@@ -1262,8 +1263,8 @@ if test "${USE_ILBC}" != "no"; then
    fi
    if test "${ILBC_SYSTEM}" = "yes"; then
       AST_PKG_CONFIG_CHECK(ILBC, libilbc)
-      if test "$PBX_ILBC" = '1'; then
-	 ILBC_INTERNAL='no'
+      if test "$PBX_ILBC" = "1"; then
+	 ILBC_INTERNAL="no"
       fi
    fi
    if test "${ILBC_INTERNAL}" = "yes"; then
@@ -1271,6 +1272,26 @@ if test "${USE_ILBC}" != "no"; then
    fi
 fi
 
+LIBEDIT_INTERNAL="yes"
+AC_SUBST(LIBEDIT_INTERNAL)
+LIBEDIT_SYSTEM="yes"
+if test "${USE_LIBEDIT}" != "no"; then
+   if test "${LIBEDIT_DIR}" = "internal"; then
+      LIBEDIT_SYSTEM="no"
+   elif test "${LIBEDIT_DIR}" != ""; then
+      LIBEDIT_INTERNAL="no"
+   fi
+   if test "${LIBEDIT_SYSTEM}" = "yes"; then
+      AST_PKG_CONFIG_CHECK(LIBEDIT, libedit)
+      if test "$PBX_LIBEDIT" = "1"; then
+	 LIBEDIT_INTERNAL="no"
+      fi
+   fi
+   if test "${LIBEDIT_INTERNAL}" = "yes"; then
+      PBX_LIBEDIT=1
+   fi
+fi
+
 AST_EXT_LIB_CHECK([ICONV], [iconv], [iconv_open], [iconv.h])
 # GNU libiconv #define's iconv_open to libiconv_open, so we need to search for that symbol
 AST_EXT_LIB_CHECK([ICONV], [iconv], [libiconv_open], [iconv.h])
diff --git a/contrib/scripts/install_prereq b/contrib/scripts/install_prereq
index 609d400bec..55da3ebfce 100755
--- a/contrib/scripts/install_prereq
+++ b/contrib/scripts/install_prereq
@@ -27,11 +27,11 @@ PACKAGES_DEBIAN="$PACKAGES_DEBIAN libcurl-dev libspeex-dev libspeexdsp-dev libog
 PACKAGES_DEBIAN="$PACKAGES_DEBIAN libpq-dev unixodbc-dev libsqlite0-dev libmysqlclient15-dev libneon27-dev libgmime-dev libusb-dev liblua5.1-0-dev lua5.1"
 PACKAGES_DEBIAN="$PACKAGES_DEBIAN libopenh323-dev libvpb-dev libgtk2.0-dev libmysqlclient-dev libbluetooth-dev libradiusclient-ng-dev freetds-dev"
 PACKAGES_DEBIAN="$PACKAGES_DEBIAN libsnmp-dev libiksemel-dev libcorosync-dev libnewt-dev libpopt-dev libical-dev libspandsp-dev libjack-dev"
-PACKAGES_DEBIAN="$PACKAGES_DEBIAN libresample-dev libc-client-dev binutils-dev libsrtp-dev libgsm1-dev"
+PACKAGES_DEBIAN="$PACKAGES_DEBIAN libresample-dev libc-client-dev binutils-dev libsrtp-dev libgsm1-dev libedit-dev"
 PACKAGES_RH="automake gcc gcc-c++ ncurses-devel openssl-devel libxml2-devel unixODBC-devel libcurl-devel libogg-devel libvorbis-devel speex-devel"
 PACKAGES_RH="$PACKAGES_RH spandsp-devel freetds-devel net-snmp-devel iksemel-devel corosynclib-devel newt-devel popt-devel libtool-ltdl-devel lua-devel"
 PACKAGES_RH="$PACKAGES_RH libsqlite3x-devel radiusclient-ng-devel portaudio-devel postgresql-devel libresample-devel neon-devel libical-devel"
-PACKAGES_RH="$PACKAGES_RH openldap-devel gmime22-devel sqlite2-devel mysql-devel bluez-libs-devel jack-audio-connection-kit-devel gsm-devel"
+PACKAGES_RH="$PACKAGES_RH openldap-devel gmime22-devel sqlite2-devel mysql-devel bluez-libs-devel jack-audio-connection-kit-devel gsm-devel libedit-devel"
 
 PACKAGES_OBSD="popt gmake wget libxml libogg libvorbis curl iksemel spandsp speex iodbc freetds-0.63p1-msdblib mysql-client gmime sqlite sqlite3 jack"
 
diff --git a/include/asterisk/autoconfig.h.in b/include/asterisk/autoconfig.h.in
index 4817262695..9288cce545 100644
--- a/include/asterisk/autoconfig.h.in
+++ b/include/asterisk/autoconfig.h.in
@@ -376,6 +376,9 @@
 /* Define to 1 if you have the OpenLDAP library. */
 #undef HAVE_LDAP
 
+/* Define if your system has the LIBEDIT libraries. */
+#undef HAVE_LIBEDIT
+
 /* Define to 1 if you have the <libintl.h> header file. */
 #undef HAVE_LIBINTL_H
 
diff --git a/main/Makefile b/main/Makefile
index 4d446f08c2..0ff0deaf86 100644
--- a/main/Makefile
+++ b/main/Makefile
@@ -144,7 +144,14 @@ testexpr2: ast_expr2f.c ast_expr2.c ast_expr2.h
 	$(CC) -g -o testexpr2 ast_expr2f.o ast_expr2.o -lm
 	rm ast_expr2.o ast_expr2f.o
 
+ifneq ($(LIBEDIT_INTERNAL),no)
+LIBEDIT_OBJ=editline/libedit.a
+LIBEDIT_INCLUDE=-Ieditline
+endif
+
 db.o: _ASTCFLAGS+=$(SQLITE3_INCLUDE)
+asterisk.o: _ASTCFLAGS+=$(LIBEDIT_INCLUDE)
+cli.o: _ASTCFLAGS+=$(LIBEDIT_INCLUDE)
 
 ifneq ($(findstring ENABLE_UPLOADS,$(MENUSELECT_CFLAGS)),)
 http.o: _ASTCFLAGS+=$(GMIME_INCLUDE)
@@ -228,13 +235,13 @@ endif
 
 endif
 
-$(MAIN_TGT): $(OBJS) $(ASTSSL_LIB) editline/libedit.a $(AST_EMBED_LDSCRIPTS)
+$(MAIN_TGT): $(OBJS) $(ASTSSL_LIB) $(LIBEDIT_OBJ) $(AST_EMBED_LDSCRIPTS)
 	@$(CC) -c -o buildinfo.o $(_ASTCFLAGS) buildinfo.c $(ASTCFLAGS)
-	$(ECHO_PREFIX) echo "   [LD] $(OBJS) editline/libedit.a $(AST_EMBED_LDSCRIPTS) -> $@"
+	$(ECHO_PREFIX) echo "   [LD] $(OBJS) $(LIBEDIT_OBJ) $(AST_EMBED_LDSCRIPTS) -> $@"
 ifneq ($(findstring chan_h323,$(MENUSELECT_CHANNELS)),)
-	$(CMD_PREFIX) $(CC) $(STATIC_BUILD) -o $@ $(ASTLINK) $(AST_EMBED_LDFLAGS) $(_ASTLDFLAGS) $(ASTLDFLAGS) $(OBJS) $(ASTSSL_LDLIBS) editline/libedit.a $(AST_EMBED_LDSCRIPTS) buildinfo.o $(AST_LIBS) $(AST_EMBED_LIBS) $(GMIMELDFLAGS)
+	$(CMD_PREFIX) $(CC) $(STATIC_BUILD) -o $@ $(ASTLINK) $(AST_EMBED_LDFLAGS) $(_ASTLDFLAGS) $(ASTLDFLAGS) $(OBJS) $(ASTSSL_LDLIBS) $(LIBEDIT_OBJ) $(AST_EMBED_LDSCRIPTS) buildinfo.o $(AST_LIBS) $(AST_EMBED_LIBS) $(GMIMELDFLAGS) $(LIBEDIT_LIB)
 else
-	$(CMD_PREFIX) $(CXX) $(STATIC_BUILD) -o $@ $(ASTLINK) $(AST_EMBED_LDFLAGS) $(_ASTLDFLAGS) $(ASTLDFLAGS) $(H323LDFLAGS) $(OBJS) $(ASTSSL_LDLIBS) editline/libedit.a $(AST_EMBED_LDSCRIPTS) buildinfo.o $(AST_LIBS) $(AST_EMBED_LIBS) $(H323LDLIBS) $(GMIMELDFLAGS)
+	$(CMD_PREFIX) $(CXX) $(STATIC_BUILD) -o $@ $(ASTLINK) $(AST_EMBED_LDFLAGS) $(_ASTLDFLAGS) $(ASTLDFLAGS) $(H323LDFLAGS) $(OBJS) $(ASTSSL_LDLIBS) $(LIBEDIT_OBJ) $(AST_EMBED_LDSCRIPTS) buildinfo.o $(AST_LIBS) $(AST_EMBED_LIBS) $(H323LDLIBS) $(GMIMELDFLAGS) $(LIBEDIT_LIB)
 endif
 
 ifeq ($(GNU_LD),1)
diff --git a/main/asterisk.c b/main/asterisk.c
index 23d6c2320c..e06d70a4aa 100644
--- a/main/asterisk.c
+++ b/main/asterisk.c
@@ -98,6 +98,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
 #endif
 #endif
 #include <regex.h>
+#include <histedit.h>
 
 #if defined(SOLARIS)
 int daemon(int, int);  /* defined in libresolv of all places */
@@ -2704,7 +2705,7 @@ static char *cli_complete(EditLine *editline, int ch)
 			int mlen = 0, maxmbuf = 2048;
 			/* Start with a 2048 byte buffer */
 			if (!(mbuf = ast_malloc(maxmbuf))) {
-				lf->cursor[0] = savechr;
+				*((char *) lf->cursor) = savechr;
 				return (char *)(CC_ERROR);
 			}
 			snprintf(buf, sizeof(buf), "_COMMAND MATCHESARRAY \"%s\" \"%s\"", lf->buffer, ptr);
@@ -2716,7 +2717,7 @@ static char *cli_complete(EditLine *editline, int ch)
 					/* Every step increment buffer 1024 bytes */
 					maxmbuf += 1024;
 					if (!(mbuf = ast_realloc(mbuf, maxmbuf))) {
-						lf->cursor[0] = savechr;
+						*((char *) lf->cursor) = savechr;
 						return (char *)(CC_ERROR);
 					}
 				}
@@ -2778,7 +2779,7 @@ static char *cli_complete(EditLine *editline, int ch)
 		ast_free(matches);
 	}
 
-	lf->cursor[0] = savechr;
+	*((char *) lf->cursor) = savechr;
 
 	return (char *)(long)retval;
 }
@@ -2861,29 +2862,13 @@ static int ast_el_write_history(char *filename)
 
 static int ast_el_read_history(char *filename)
 {
-	char buf[MAX_HISTORY_COMMAND_LENGTH];
-	FILE *f;
-	int ret = -1;
+	HistEvent ev;
 
-	if (el_hist == NULL || el == NULL)
+	if (el_hist == NULL || el == NULL) {
 		ast_el_initialize();
-
-	if ((f = fopen(filename, "r")) == NULL)
-		return ret;
-
-	while (!feof(f)) {
-		if (!fgets(buf, sizeof(buf), f))
-			break;
-		if (!strcmp(buf, "_HiStOrY_V2_\n"))
-			continue;
-		if (ast_all_zeros(buf))
-			continue;
-		if ((ret = ast_el_add_history(buf)) == -1)
-			break;
 	}
-	fclose(f);
 
-	return ret;
+	return history(el_hist, &ev, H_LOAD, filename);
 }
 
 static void ast_remotecontrol(char *data)
diff --git a/main/cli.c b/main/cli.c
index bb20bc1fa9..7f71da924c 100644
--- a/main/cli.c
+++ b/main/cli.c
@@ -39,6 +39,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
 #include <regex.h>
 #include <pwd.h>
 #include <grp.h>
+#include <editline/readline.h>
 
 #include "asterisk/cli.h"
 #include "asterisk/linkedlists.h"
@@ -48,7 +49,6 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
 #include "asterisk/utils.h"
 #include "asterisk/app.h"
 #include "asterisk/lock.h"
-#include "editline/readline/readline.h"
 #include "asterisk/threadstorage.h"
 #include "asterisk/translate.h"
 
diff --git a/main/editline/configure b/main/editline/configure
index b5fc6e02c3..d5d0a4deaf 100755
--- a/main/editline/configure
+++ b/main/editline/configure
@@ -2031,7 +2031,7 @@ TCSRCS="TEST/test.c"
 
 if test "x$enable_readline" = "xyes" ; then
   CCSRCS="$CCSRCS readline.c"
-  IHDRS="$IHDRS readline/readline.h"
+  IHDRS="$IHDRS readline.h"
   IHDR_LINKS="readline.h readline/history.h"
   HDR_DIRS="$HDR_DIRS include/readline"
   LIB_A_LINKS="$LIB_A_LINKS libedit.a libreadline.a"
diff --git a/main/editline/configure.in b/main/editline/configure.in
index db533343d0..d8bc706b1f 100644
--- a/main/editline/configure.in
+++ b/main/editline/configure.in
@@ -235,7 +235,7 @@ TCSRCS="TEST/test.c"
 dnl Add files to the lists if readline compatibility is enabled.
 if test "x$enable_readline" = "xyes" ; then
   CCSRCS="$CCSRCS readline.c"
-  IHDRS="$IHDRS readline/readline.h"
+  IHDRS="$IHDRS readline.h"
   IHDR_LINKS="readline.h readline/history.h"
   HDR_DIRS="$HDR_DIRS include/readline"
   LIB_A_LINKS="$LIB_A_LINKS libedit.a libreadline.a"
diff --git a/main/editline/readline.c b/main/editline/readline.c
index 77827c3f91..adf054d633 100644
--- a/main/editline/readline.c
+++ b/main/editline/readline.c
@@ -58,7 +58,7 @@ __RCSID("$NetBSD: readline.c,v 1.21 2002/03/18 16:20:36 christos Exp $");
 #endif
 
 #include "histedit.h"
-#include "readline/readline.h"
+#include "readline.h"
 #include "el.h"
 #include "fcns.h"		/* for EL_NUM_FCNS */
 
diff --git a/main/editline/readline/readline.h b/main/editline/readline.h
similarity index 100%
rename from main/editline/readline/readline.h
rename to main/editline/readline.h
diff --git a/makeopts.in b/makeopts.in
index bcb3a51441..dd10f9b54a 100644
--- a/makeopts.in
+++ b/makeopts.in
@@ -169,6 +169,10 @@ JACK_LIB=@JACK_LIB@
 LDAP_INCLUDE=@LDAP_INCLUDE@
 LDAP_LIB=@LDAP_LIB@
 
+LIBEDIT_INTERNAL=@LIBEDIT_INTERNAL@
+LIBEDIT_INCLUDE=@LIBEDIT_INCLUDE@
+LIBEDIT_LIB=@LIBEDIT_LIB@
+
 LUA_INCLUDE=@LUA_INCLUDE@
 LUA_LIB=@LUA_LIB@
 
-- 
GitLab