Subject: bug#7642: Build failure on NetBSD 5.0.2 on IA-32

From: Chong Yidong <[email-masked]>
Date: Fri, 17 Dec 2010 22:32:17 +0800

"Nelson H. F. Beebe" <[email-masked]> writes:

> % make distclean
> % env LDFLAGS='-Wl,-rpath,/usr/X11R7/lib -L/usr/X11R7/lib' ./configure
> --without-xaw3d
> % make
> ...
> ld: cannot find -lterminfo
> % ls /usr/lib/libterm*
> /usr/lib/libtermcap.a                   /usr/lib/libtermlib.a
> ...
>
> That is another error: -lterminfo is hard-coded into src/Makefile.

The problem here is that in src/s/netbsd.h, we define

#ifdef HAVE_TERM_H
#define TERMINFO
#define LIBS_TERMCAP -lterminfo
#else
#define LIBS_TERMCAP -ltermcap
#endif

Judging by this report, the existence of term.h does not imply that
terminfo is available.

So, we should go back to the prescription originally given in Bug#6190.
Something like the following patch---Nelson, does it fix this problem?

=== modified file 'configure.in'
*** configure.in	2010-12-10 17:46:40 +0000
--- configure.in	2010-12-17 14:29:37 +0000
***************
*** 2372,2377 ****
--- 2372,2386 ----
  # than to expect to find it in ncurses.
  AC_CHECK_LIB(ncurses, tparm)
  
+ case "$opsys" in
+   netbsd)
+     AC_SEARCH_LIBS(tputs, [ncurses terminfo termcap]);
+     if test $ac_cv_search_tputs = -lterminfo; then
+       AC_DEFINE(TERMINFO, 1, [Define to 1 if you use terminfo instead of termcap.]);
+     fi
+     ;;
+ esac
+ 
  # Do we have res_init, for detecting changes in /etc/resolv.conf?
  
  resolv=no

=== modified file 'src/s/netbsd.h'
*** src/s/netbsd.h	2010-05-21 04:06:34 +0000
--- src/s/netbsd.h	2010-12-17 14:29:31 +0000
***************
*** 45,52 ****
  #define LIBS_DEBUG
  /* -lutil is not needed for NetBSD >0.9.  */
  /* #define LIBS_SYSTEM -lutil */
! #ifdef HAVE_TERM_H
! #define TERMINFO
  #define LIBS_TERMCAP -lterminfo
  #else
  #define LIBS_TERMCAP -ltermcap
--- 45,51 ----
  #define LIBS_DEBUG
  /* -lutil is not needed for NetBSD >0.9.  */
  /* #define LIBS_SYSTEM -lutil */
! #ifdef TERMINFO
  #define LIBS_TERMCAP -lterminfo
  #else
  #define LIBS_TERMCAP -ltermcap

=== modified file 'configure'
*** configure	2010-12-10 17:46:40 +0000
--- configure	2010-12-17 14:30:05 +0000
***************
*** 11833,11838 ****
--- 11833,11904 ----
  fi

+ case "$opsys" in
+   netbsd)
+     { $as_echo "$as_me:${as_lineno-$LINENO}: checking for library containing tputs" >&5
+ $as_echo_n "checking for library containing tputs... " >&6; }
+ if test "${ac_cv_search_tputs+set}" = set; then :
+   $as_echo_n "(cached) " >&6
+ else
+   ac_func_search_save_LIBS=$LIBS
+ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+ /* end confdefs.h.  */
+ 
+ /* Override any GCC internal prototype to avoid an error.
+    Use char because int might match the return type of a GCC
+    builtin and then its argument prototype would still apply.  */
+ #ifdef __cplusplus
+ extern "C"
+ #endif
+ char tputs ();
+ int
+ main ()
+ {
+ return tputs ();
+   ;
+   return 0;
+ }
+ _ACEOF
+ for ac_lib in '' ncurses terminfo termcap; do
+   if test -z "$ac_lib"; then
+     ac_res="none required"
+   else
+     ac_res=-l$ac_lib
+     LIBS="-l$ac_lib  $ac_func_search_save_LIBS"
+   fi
+   if ac_fn_c_try_link "$LINENO"; then :
+   ac_cv_search_tputs=$ac_res
+ fi
+ rm -f core conftest.err conftest.$ac_objext \
+     conftest$ac_exeext
+   if test "${ac_cv_search_tputs+set}" = set; then :
+   break
+ fi
+ done
+ if test "${ac_cv_search_tputs+set}" = set; then :
+ 
+ else
+   ac_cv_search_tputs=no
+ fi
+ rm conftest.$ac_ext
+ LIBS=$ac_func_search_save_LIBS
+ fi
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_search_tputs" >&5
+ $as_echo "$ac_cv_search_tputs" >&6; }
+ ac_res=$ac_cv_search_tputs
+ if test "$ac_res" != no; then :
+   test "$ac_res" = "none required" || LIBS="$ac_res $LIBS"
+ 
+ fi
+ ;
+     if test $ac_cv_search_tputs = -lterminfo; then
+ 
+ $as_echo "#define TERMINFO 1" >>confdefs.h
+ ;
+     fi
+     ;;
+ esac
+ 
  # Do we have res_init, for detecting changes in /etc/resolv.conf?
  
  resolv=no