Title: Improve termcap detection in
Type: Stage:
Components: Build Versions: Python 2.7
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: koobs, pooryorick, r.david.murray, skrah, veremitz
Priority: normal Keywords: patch

Created on 2015-01-20 22:51 by pooryorick, last changed 2019-09-30 01:35 by veremitz.

File name Uploaded Description Edit
34d54cc5ecfd.diff pooryorick, 2015-01-20 22:55 review
Repositories containing patches
Messages (12)
msg234399 - (view) Author: Poor Yorick (pooryorick) * Date: 2015-01-20 22:51
Building Python-2.7.9 using --prefix, with an ncurses that's linked to libtinfo
and a readline that isn't linked to any termcap library, I ran into the trouble
that the curses module wan't buing build with the needed -L and -l flags for
the libtinfo shared object.  I dug into, and ended up overhauling the
readline, curses, and also dbm handling (more on that in another ticket).  I
also made changes to allow to pick up options like -isystem from
$CPPFLAGS, replacing in the process the "optparse" module with the "argparse"
module.  Since argparse requires collections.OrderedDict, which isn't yet built
at this stage, I added Lib_boot/, which uses the pure-Python
OrderedDict from

and had use "argparse_boot" module instead.

The build also ran into trouble with system directories that
explicitly adds to inc_dirs and lib_dirs ahead of those of the alternate

The attached files fixed all these issues in my scenario, allowing a succesful
build and install of Python-2.7.9.
msg234699 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2015-01-25 22:29
At a quick glance this does not seem like a reasonable patch...introducing copies of two stdlib modules is basically a non-starter.  Nor do I  understand from the description what the problem is that it is trying to solve.
msg234981 - (view) Author: Poor Yorick (pooryorick) * Date: 2015-01-29 17:16
An attempt to build python-2.7.9 resulted in this error:

    renaming "readline" since importing it failed ... undefined symbol: UP

This happened because chose "-lncursesw" as the readline terminal
library. Although itself links to, in order to
succeed with the "--as-needed" linker flag, would have to directly
choose  The part of the patch that deals with that does not rely
on the other changes that were made to accomodate -isystem in CPPFLAGS.
msg234982 - (view) Author: Stefan Krah (skrah) * (Python committer) Date: 2015-01-29 17:46
What system are you using?  The patch is quite large, and the existing libtinfo logic should work on most systems.  Is the main problem that ldd is not found?
msg234983 - (view) Author: Poor Yorick (pooryorick) * Date: 2015-01-29 18:06
ldd was found.  That patch does abstract and generalize ldd usage into a
function for reuse.  I'm building Python as part of a rather large software
collection that lives in an alternate prefix.  The main issue with the termcap
library is that with the --as-needed linker flag, which more modern build
systems prefer, linking to isn't sufficient, even when itself links to, but that's what decides to
msg234987 - (view) Author: Poor Yorick (pooryorick) * Date: 2015-01-29 19:36
The wholesale inclusion of two additional files makes the patch look larger
than it is.  The modifications to address three different issues.  The
modifications for each issue don't overlap much, so they could be cherry-picked
fairly easily.  For the readline issue, all that's needed is the new function,
"ldd_find_library_file" and then the changes from line 704 to about line 773
that deal directly with readline and ncurses.
msg234988 - (view) Author: Stefan Krah (skrah) * (Python committer) Date: 2015-01-29 19:56
I think even the curses changes alone are rather large, especially
for 2.7.  Perhaps you could give us exact instructions how to
reproduce the issue (OS, version, build command line).
msg234995 - (view) Author: Poor Yorick (pooryorick) * Date: 2015-01-29 22:37
Larger changes represent more work on the part of the submitter ;) 
The following should reproduce the readline problem:

Have the current detect as the readline termcap library a that itself links against  Without the --as-needed
flag, this is sufficient, since libtinfo ends up being indirectly linked to, through  Not that it was ever the right approach,
but absent --as-needed, it happens to work. 

Then, make sure the --as-needed flag is passed to the link command for the module.  In that case, even though there is a "-lncurses" argument,
the linke will not link to because
doesn't directly need any symbols provided by  The readline
module will then fail to load because terminal library symbols like UP will be

Without --as-needed, superfluous links between shared objects proliferate
through a software collection.  --as-needed is becoming more common, so it
would be good if didn't break because of it.
msg235005 - (view) Author: Stefan Krah (skrah) * (Python committer) Date: 2015-01-29 23:48
I still don't understand why libncurses is linked against libtinfo but
libreadline is not.  Again, what is your OS?

Example Ubuntu (a modern system):

$ ldd /lib/x86_64-linux-gnu/ =>  (0x00007fff5bfed000) => /lib/x86_64-linux-gnu/ (0x00007fcb8b43a000) => /lib/x86_64-linux-gnu/ (0x00007fcb8b211000) => /lib/x86_64-linux-gnu/ (0x00007fcb8ae4a000)
        /lib64/ (0x00007fcb8b87d000)

$ ldd /lib/x86_64-linux-gnu/ =>  (0x00007fff8c5fe000) => /lib/x86_64-linux-gnu/ (0x00007f43055a0000) => /lib/x86_64-linux-gnu/ (0x00007f43051da000)
        /lib64/ (0x00007f4305a2b000)
msg235007 - (view) Author: Poor Yorick (pooryorick) * Date: 2015-01-30 00:13
Ths OS is RHEL 6, but that's not so important because the entire collection,
including readline, is built from source and installed into an alternate
location.  With the exception of a few essential shared objects from the
system, everything else is contained in the alternate location.  Here's what
the readline INSTALL document says:

    Readline uses the termcap functions, but does not link with the termcap or
    curses library itself, allowing applications which link with readline 
    to choose an appropriate library.

So if you don't monkey with the readline distribution, but build and install it
as-is, you get a that's not linked to a termcap library.  That's
the situation for our software collection.
msg235035 - (view) Author: Stefan Krah (skrah) * (Python committer) Date: 2015-01-30 15:00
Ok thanks, I understand the issue now.  I'm focusing this issue
on the termcap detection.  For the other parts of the patch
you'd have to open separate issues.

As an aside, the ncurses maintainer seems to endorse a distro
enforced choice for libreadline's termcap:
msg235036 - (view) Author: Stefan Krah (skrah) * (Python committer) Date: 2015-01-30 15:21
FWIW, even
enforces -ncurses linking of readline.

[They should be compiling ncurses with tinfo split out though and
 use -tinfo instead.]
Date User Action Args
2019-09-30 01:35:11veremitzsetnosy: + veremitz
2016-11-13 01:26:54koobssetnosy: + koobs
2015-01-30 15:21:32skrahsetmessages: + msg235036
2015-01-30 15:00:50skrahsetmessages: + msg235035
title: curses, readline, tinfo, and also --prefix, dbm, CPPFLAGS -> Improve termcap detection in
2015-01-30 00:13:03pooryoricksetmessages: + msg235007
2015-01-29 23:48:22skrahsetmessages: + msg235005
2015-01-29 22:37:17pooryoricksetmessages: + msg234995
2015-01-29 19:56:04skrahsetmessages: + msg234988
2015-01-29 19:36:25pooryoricksetmessages: + msg234987
2015-01-29 18:06:49pooryoricksetmessages: + msg234983
2015-01-29 17:46:49skrahsetnosy: + skrah
messages: + msg234982
2015-01-29 17:16:10pooryoricksetmessages: + msg234981
2015-01-25 22:29:30r.david.murraysetnosy: + r.david.murray
messages: + msg234699
2015-01-20 22:55:06pooryoricksetfiles: + 34d54cc5ecfd.diff
keywords: + patch
2015-01-20 22:54:16pooryoricksethgrepos: + hgrepo292
2015-01-20 22:53:57pooryoricksethgrepos: - hgrepo291
2015-01-20 22:53:48pooryoricksethgrepos: + hgrepo291
2015-01-20 22:53:09pooryoricksethgrepos: - hgrepo290
2015-01-20 22:51:23pooryorickcreate