From 6f9aea2bf2ffc55f9a52766279e3d429b35fbb7a Mon Sep 17 00:00:00 2001
From: "Jay Freeman (saurik)" <saurik@saurik.com>
Date: Sat, 15 Jun 2013 03:44:26 -0700
Subject: [PATCH] Isolate linkage of libreadline and libtermcap.

---
 Makefile.am  |  2 +-
 configure    | 20 ++++++++++++++++++--
 configure.ac | 16 ++++++++++++----
 3 files changed, 31 insertions(+), 7 deletions(-)

diff --git a/Makefile.am b/Makefile.am
index 8430a18..0d73879 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -20,7 +20,7 @@ libcycript_la_SOURCES += lex.cy.cpp
 
 bin_PROGRAMS = cycript
 cycript_SOURCES = Console.cpp Display.cpp
-cycript_LDFLAGS = $(LTLIBAPR) -ldl
+cycript_LDFLAGS = $(LTLIBAPR) $(LTLIBREADLINE) $(LTLIBTERMCAP) -ldl
 cycript_LDADD = libcycript.la
 
 ldid = true
diff --git a/configure b/configure
index cf19be9..2558712 100755
--- a/configure
+++ b/configure
@@ -652,6 +652,8 @@ SO
 LTFLAGS
 LTLIBICONV
 LIBICONV
+LTLIBTERMCAP
+LTLIBREADLINE
 CY_OBJECTIVEC_FALSE
 CY_OBJECTIVEC_TRUE
 GNUSTEP_CONFIG
@@ -19958,6 +19960,11 @@ fi
 
 
 
+
+
+    cy_save=$LIBS
+    LIBS=
+
   { $as_echo "$as_me:${as_lineno-$LINENO}: checking for a readline compatible library" >&5
 $as_echo_n "checking for a readline compatible library... " >&6; }
 if ${ax_cv_lib_readline+:} false; then :
@@ -20085,14 +20092,20 @@ done
     fi
   fi
 
-case $vl_cv_lib_readline in #(
+    LTLIBREADLINE=$LIBS
+    LIBS=$cy_save
+
+case $ax_cv_lib_readline in #(
   no) :
     as_fn_error $? "missing \"libreadline\"" "$LINENO" 5 ;; #(
   *) :
      ;;
 esac
 
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for library containing cur_term" >&5
+
+    cy_save=$LIBS
+    LIBS=
+    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for library containing cur_term" >&5
 $as_echo_n "checking for library containing cur_term... " >&6; }
 if ${ac_cv_search_cur_term+:} false; then :
   $as_echo_n "(cached) " >&6
@@ -20148,6 +20161,9 @@ if test "$ac_res" != no; then :
 
 fi
 
+    LTLIBTERMCAP=$LIBS
+    LIBS=$cy_save
+
 
 ac_ext=c
 ac_cpp='$CPP $CPPFLAGS'
diff --git a/configure.ac b/configure.ac
index bf703f2..2a89196 100644
--- a/configure.ac
+++ b/configure.ac
@@ -236,12 +236,20 @@ AS_CASE([$CY_EXECUTE], [1], [
 
 AM_CONDITIONAL([CY_OBJECTIVEC], [test "x$CY_OBJECTIVEC" = x1])
 
-AX_LIB_READLINE
-AS_CASE([$vl_cv_lib_readline], [no], [AC_MSG_ERROR([missing "libreadline"])])
+AC_DEFUN([CY_LT_LIB], [
+    cy_save=$LIBS
+    LIBS=
+    ]$2[
+    ]$1[=$LIBS
+    LIBS=$cy_save
+    AC_SUBST(]$1[)
+])
+
+CY_LT_LIB([LTLIBREADLINE], [AX_LIB_READLINE])
+AS_CASE([$ax_cv_lib_readline], [no], [AC_MSG_ERROR([missing "libreadline"])])
 
 dnl XXX: AX_LIB_READLINE totally lied: it was suposed to figure this out :(
-dnl XXX: this should only be linked into the main binary (not the library)
-AC_SEARCH_LIBS([cur_term], [termcap])
+CY_LT_LIB([LTLIBTERMCAP], [AC_SEARCH_LIBS([cur_term], [termcap])])
 
 dnl XXX: saurik doesn't understand what this does
 dnl AM_ICONV {{{
-- 
2.49.0