Subject: bug#64577: 29.0.92; configure on NetBSD forces unstable terminfo library

From: Valtteri Vuorikoski <[email-masked]>
Date: Wed, 12 Jul 2023 15:57:29 +0300

On Wed, Jul 12, 2023 at 03:11:02PM +0300, Eli Zaretskii wrote:
> > configure on NetBSD forces using the native libterminfo library, even
> > when ncurses is available. When started with a TERM such xterm-256color,
> > this results in abort() in tputs1 (TERM=xterm works).
> > 
> > Hacking configure to use ncurses when available provides stable
> > operation on xterm-256color.
> 
> I'm not sure I understand.  The configure script first looks for a
> library with tputs, and it tries tinfo, ncurses, terminfo, curses,
> termcap, tinfow, ncursesw, in that order.  I understand that in your
> case it finds ncurses, which is good, right?
> 
> After that, the configure script decides whether to use terminfo or
> termcap.  It is here that for netbsd we decide to use termcap in
> certain situations instead of terminfo.  In your case, since ncurses
> was found, LIBS_TERMCAP should have been set to -lncurses, and this
> code:
> 
>   netbsd)
>     if test "x$LIBS_TERMCAP" != "x-lterminfo"; then
>       TERMINFO=no
>       LIBS_TERMCAP="-ltermcap"
>     fi
> 
> should have set TERMINFO=no, which disables linking against terminfo.
> 
> So I don't think I understand what is going on there.

Finding ncurses is good, but unfortunately ncurses isn't what ends up
getting used. configure says:

checking for library containing tputs... -lncurses

but this happens:

$ ldd src/emacs | egrep 'term|curses'
     -lterminfo.1 => /usr/lib/libterminfo.so.1

Disabling the test above results in src/emacs being linked with
ncurses. That is, when I remove the whole "netbsd" special case
from configure this is the result:

$ ldd ~/emacs/bin/emacs | egrep 'term|curses'
   -lncurses.6 => /usr/pkg/lib/libncurses.so.6

> As I don't have access to a netbsd system, could you please post the
> config.log you get when configuring with a fresh tree of
> emacs-29.0.92, and also show the "set -x" expansion of the relevant
> parts of the configure script?  (Please compress those when posting if
> they are larger than, say, 0.5MB.)  I would like to use those to
> understand what happens on your system and why the configure script
> decides to use terminfo.

These are attached.

After some further investigation, it turns out that in NetBSD 9.3,
libtermcap is a symlink to libterminfo. So the configure test ends up
forcing -ltermcap and TERMINFO=no because LIBS_TERMCAP=-lncurses (so
!= -lterminfo), which actually links with libterminfo due to the
symlink.

So with current NetBSD, I don't think the test as it stands could ever
do anything useful, since there is only terminfo and apparently a
termcap-like compatibility wrapper around terminfo.

Looking at a git mirror of NetBSD system sources, this seems to have
been the case since at least 2010.

> Also, do you happen to know when terminfo on NetBSD started to be
> buggy?  I would think that the change in bug#6190 did work at the
> time, so at least back then NetBSD did have a workable terminfo.  When
> did it start failing?

I have a build of emacs 27.0.91 on another system built with a similar
environment (ncurses should be available but emacs is linked with
libterminfo) and it also aborts in tparam1 with TERM=xterm-256color,
so looks like this has been happening for quite a while.

 -Valtteri