Subject: bug#10677: [Chris Leyon] Re: bug#10677: 24.0.93; missing pathmax.h on Solaris

From: Paul Eggert <[email-masked]>
Date: Fri, 02 Mar 2012 19:29:38 -0800

Thanks for diagnosing the problem.  The ncurses 'configure' stuff
changed recently, and it continues to be a mess (with comments
indicating that it's a mess, sigh), but I see two things that cause
your problem.  First, 'configure' modifies LIBS for the tputs link
test and then never sets it back, which is normally a no-no (and is a
no-no here); and second, 'configure' assumes that if you can
successfully link to tputs then tputs will work but (as you've found)
this does not always work with dynamic linking.

I can reproduce the problem on my Solaris 10 host when I configure with

   configure --with-x-toolkit=lucid --with-gif=no \
     LDFLAGS=-L/opt/sfw/lib \
     CPPFLAGS=-I/opt/sfw/include

and the following patch fixes it for me.  Can you give it a try?  It
will mean you'll need full set of build tools (which Solaris doesn't
have), so you may need to apply the patch on an up-to-date Linux box,
do a 'make', then 'make distclean', then copy the result to Solaris 10
and run it there.  If that's too much to ask, I suppose I could install
it into the trunk and let you try the next pretest.

2012-03-03  Paul Eggert  <[email-masked]>

	configure: fix ncurses 'configure' issue on Solaris 10 (Bug#10677)
	* configure.in (LIBS_TERMCAP): Default this to the result of
	the tputs library search.  Do a run-time test for the linkability
	of tputs unless cross-compiling, as that's more reliable if the
	link flags and libraries are messed up.  Don't change LIBS as
	a result of the test, as that may mess up later tests.

=== modified file 'configure.in'
--- configure.in	2012-02-27 03:20:00 +0000
+++ configure.in	2012-03-03 02:20:34 +0000
@@ -2784,11 +2784,43 @@
 # It's better to believe a function is not available
 # than to expect to find it in ncurses.
 # Also we need tputs and friends to be able to build at all.
-have_tputs_et_al=true
+AC_MSG_CHECKING([for library containing tputs])
+# Run a test program that contains a call to tputs, a call that is
+# never executed.  This tests whether a pre-'main' dynamic linker
+# works with the library.  It's too much trouble to actually call
+# tputs in the test program, due to portability hassles.  When
+# cross-compiling, assume the test program will run if it links.
+AC_DEFUN([tputs_link_source], [
+  AC_LANG_SOURCE(
+     [[extern void tputs (const char *, int, int (*)(int));
+       int main (int argc, char **argv)
+       {
+	  if (argc == 10000)
+	    tputs (argv[0], 0, 0);
+	  return 0;
+       }]])
+])
 # Maybe curses should be tried earlier?
 # See http://debbugs.gnu.org/cgi/bugreport.cgi?bug=9736#35
-AC_SEARCH_LIBS(tputs, [ncurses terminfo termcap curses], , have_tputs_et_al=false)
-if test "$have_tputs_et_al" != true; then
+for tputs_library in '' ncurses terminfo termcap curses; do
+  OLIBS=$LIBS
+  if test -z "$tputs_library"; then
+    LIBS_TERMCAP=
+    msg='none required'
+  else
+    LIBS_TERMCAP=-l$tputs_library
+    msg=$LIBS_TERMCAP
+    LIBS="$LIBS_TERMCAP $LIBS"
+  fi
+  AC_RUN_IFELSE([tputs_link_source], [], [msg=no],
+    [AC_LINK_IFELSE([tputs_link_source], [], [msg=no])])
+  LIBS=$OLIBS
+  if test "X$msg" != Xno; then
+    break
+  fi
+done
+AC_MSG_RESULT([$msg])
+if test "X$msg" = Xno; then
   AC_MSG_ERROR([The required function `tputs' was not found in any library.
 These libraries were tried: libncurses, libterminfo, libtermcap, libcurses.
 Please try installing whichever of these libraries is most appropriate
@@ -2807,7 +2839,6 @@
 ## freebsd < 40000, ms-w32, msdos, netbsd < 599002500, and
 ## darwin|gnu without ncurses.
 TERMINFO=no
-LIBS_TERMCAP=
 case "$opsys" in
   ## cygwin: Fewer environment variables to go wrong, more terminal types.
   ## hpux10-20: Use the system provided termcap(3) library.
@@ -2872,10 +2903,6 @@
 TERMCAP_OBJ=tparam.o
 if test $TERMINFO = yes; then
   AC_DEFINE(TERMINFO, 1, [Define to 1 if you use terminfo instead of termcap.])
-
-  ## Default used to be -ltermcap.  Add a case above if need something else.
-  test "x$LIBS_TERMCAP" = "x" && LIBS_TERMCAP="-lcurses"
-
   TERMCAP_OBJ=terminfo.o
 fi
 AC_SUBST(LIBS_TERMCAP)