From: Mike Hommey <glandium@debian.org>
Date: Wed, 1 Jul 2009 08:23:43 +0200
Subject: Build js shell and xpcshell against libreadline

---
 config/autoconf.mk.in        |    2 ++
 configure.in                 |   23 +++++++++++++++++++++++
 js/src/Makefile.in           |    5 +++++
 js/src/config/autoconf.mk.in |    2 ++
 js/src/configure.in          |   23 +++++++++++++++++++++++
 5 files changed, 55 insertions(+), 0 deletions(-)

diff --git a/config/autoconf.mk.in b/config/autoconf.mk.in
index c695e74..d1a7d98 100644
--- a/config/autoconf.mk.in
+++ b/config/autoconf.mk.in
@@ -87,6 +87,8 @@ MOZ_X11			= @MOZ_X11@
 MOZ_PANGO = @MOZ_PANGO@
 
 MOZ_JS_LIBS		   = @MOZ_JS_LIBS@
+HAVE_READLINE	= @HAVE_READLINE@
+READLINE_LIBS	= @READLINE_LIBS@
 
 MOZ_DEBUG	= @MOZ_DEBUG@
 MOZ_DEBUG_MODULES = @MOZ_DEBUG_MODULES@
diff --git a/configure.in b/configure.in
index 16ba74b..24dbdc9 100644
--- a/configure.in
+++ b/configure.in
@@ -4357,6 +4357,29 @@ fi
 
 AC_SUBST(SYSTEM_HUNSPELL)
 
+dnl readline Support
+dnl ========================================================
+READLINE_DIR=no
+MOZ_ARG_WITH_STRING(readline,
+[  --with-readline[=PFX]
+                          Use libreadline [installed at prefix PFX]],
+    READLINE_DIR=$withval)
+
+if test -n "${READLINE_DIR}" -a "${READLINE_DIR}" != "no"; then
+    _SAVE_LDFLAGS=$LDFLAGS
+    LDFLAGS="-L${READLINE_DIR}/lib $LDFLAGS"
+    AC_CHECK_LIB(readline, readline, [HAVE_READLINE=1 READLINE_LIBS="-lreadline"],
+          [HAVE_READLINE= READLINE_LIBS=])
+    LDFLAGS=$_SAVE_LDFLAGS
+fi
+
+if test "${READLINE_DIR}" -a -d "${READLINE_DIR}" -a "$HAVE_READLINE" = 1; then
+    READLINE_LIBS="-L${READLINE_DIR}/lib ${READLINE_LIBS}"
+fi
+
+AC_SUBST(HAVE_READLINE)
+AC_SUBST(READLINE_LIBS)
+
 dnl ========================================================
 dnl Java SDK support
 dnl ========================================================
diff --git a/js/src/Makefile.in b/js/src/Makefile.in
index a000a71..1ef703d 100644
--- a/js/src/Makefile.in
+++ b/js/src/Makefile.in
@@ -55,6 +55,11 @@ LIBS		= -L. $(MOZ_JS_LIBS) $(NSPR_LIBS)
 # Make sure the library is built before the js binary
 $(SIMPLE_PROGRAMS): $(DLL_PREFIX)$(LIBRARY_NAME)$(DLL_SUFFIX)
 
+ifdef HAVE_READLINE
+DEFINES	+= -DEDITLINE
+LIBS	+= $(READLINE_LIBS)
+endif
+
 ifdef WINCE
 EXTRA_LIBS += $(JEMALLOC_LIBS)
 endif
diff --git a/js/src/config/autoconf.mk.in b/js/src/config/autoconf.mk.in
index e83f107..5b007c4 100644
--- a/js/src/config/autoconf.mk.in
+++ b/js/src/config/autoconf.mk.in
@@ -72,6 +72,8 @@ DIST		= $(DEPTH)/$(TOP_DIST)
 endif
 
 MOZ_JS_LIBS		   = @MOZ_JS_LIBS@
+HAVE_READLINE	= @HAVE_READLINE@
+READLINE_LIBS	= @READLINE_LIBS@
 
 MOZ_SYNC_BUILD_FILES = @MOZ_SYNC_BUILD_FILES@
 
diff --git a/js/src/configure.in b/js/src/configure.in
index e2eefd7..917e0ef 100644
--- a/js/src/configure.in
+++ b/js/src/configure.in
@@ -3879,6 +3879,29 @@ if test -n "$MOZ_NATIVE_NSPR"; then
     CFLAGS=$_SAVE_CFLAGS
 fi
 
+dnl readline Support
+dnl ========================================================
+READLINE_DIR=no
+MOZ_ARG_WITH_STRING(readline,
+[  --with-readline[=PFX]
+                          Use libreadline [installed at prefix PFX]],
+    READLINE_DIR=$withval)
+
+if test -n "${READLINE_DIR}" -a "${READLINE_DIR}" != "no"; then
+    _SAVE_LDFLAGS=$LDFLAGS
+    LDFLAGS="-L${READLINE_DIR}/lib $LDFLAGS"
+    AC_CHECK_LIB(readline, readline, [HAVE_READLINE=1 READLINE_LIBS="-lreadline"],
+          [HAVE_READLINE= READLINE_LIBS=])
+    LDFLAGS=$_SAVE_LDFLAGS
+fi
+
+if test "${READLINE_DIR}" -a -d "${READLINE_DIR}" -a "$HAVE_READLINE" = 1; then
+    READLINE_LIBS="-L${READLINE_DIR}/lib ${READLINE_LIBS}"
+fi
+
+AC_SUBST(HAVE_READLINE)
+AC_SUBST(READLINE_LIBS)
+
 dnl ========================================================
 dnl Use ARM userspace kernel helpers; tell NSPR to enable
 dnl their usage and use them in spidermonkey.
