public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Joel Brobecker <brobecker@adacore.com>
To: gdb-patches@sourceware.org
Cc: Joel Brobecker <brobecker@adacore.com>
Subject: [RFC] python-config.py --ldflags should return relocated path to libpython
Date: Thu, 08 Jul 2010 22:25:00 -0000	[thread overview]
Message-ID: <1278627885-9416-1-git-send-email-brobecker@adacore.com> (raw)

This is the fix that I alluded to in my earlier email:
http://www.sourceware.org/ml/gdb-patches/2010-07/msg00167.html.

There are currently 2 issues, I think, with python-config --ldflags:

  1. When python is configured with --enable-shared:
     -L<prefix>/lib is missing.  This is a problem if python was
     installed in a non-standard location.

  2. When Python is configured without --enable-shared:
     The path to the libpython archive is provided in the command output,
     but the path that gets returned is the path used at configure time.
     If the Python install was copied over to a different machine and
     then installed at a different location, then the path in -L<path>
     is incorrect (by comparison, python-config --cflags returns
     the location with the correct prefix).

I think that one might be able to work around the situation by adding
the missing -L option to LDFLAGS either during make or configure...
I will also admit that the situation is a little unorthodox, in the fact
that Python is installed at a different prefix than the one that was
used when configuring the build...

But the thing is it's been really useful on platforms where it's a pain
to build it (think Windows, for instance). 

This patch should fix both situations.  I will also send the patch
upstream to the Python developers, to see what they say.

gdb/ChangeLog:

        * python/python-config.py: When --ldflags is specified, make sure
        that the paths printed are relative to the run-time prefix.
        Always provide the path to libpython, even when the python
        install provides a shared version of libpython.

Tested on x86_64-linux, with 2.5 and 2.6. Briefly tested with 2.7,
but only by running python-config.py and visually verifying the output.

---
 gdb/python/python-config.py |   15 ++++++++++++++-
 1 files changed, 14 insertions(+), 1 deletions(-)

diff --git a/gdb/python/python-config.py b/gdb/python/python-config.py
index 0230eb4..aa4aea3 100644
--- a/gdb/python/python-config.py
+++ b/gdb/python/python-config.py
@@ -50,8 +50,21 @@ for opt in opt_flags:
         # add the prefix/lib/pythonX.Y/config dir, but only if there is no
         # shared library in prefix/lib/.
         if opt == '--ldflags':
+            # Provide the location where the Python library is installed.
+            # We always provide it, because Python may have been installed
+            # at a non-standard location.
             if not getvar('Py_ENABLE_SHARED'):
-                libs.insert(0, '-L' + getvar('LIBPL'))
+                # There is no shared library in prefix/lib.  The static
+                # library is in prefix/lib/pythonX.Y/config.
+                #
+                # Note that we cannot use getvar('LIBPL') like we used to,
+                # because it provides the location at build time, which might
+                # be different from the actual location at runtime.
+                libdir = sysconfig.get_python_lib(standard_lib=True) + '/config'
+            else:
+                # The Python shared library is installed in prefix/lib.
+                libdir = sysconfig.PREFIX + '/lib'
+            libs.insert(0, '-L' + libdir)
             libs.extend(getvar('LINKFORSHARED').split())
         print ' '.join(libs)
 
-- 
1.7.1

             reply	other threads:[~2010-07-08 22:25 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-07-08 22:25 Joel Brobecker [this message]
2010-07-08 23:04 ` Joel Brobecker
2010-07-28 17:23 ` Joel Brobecker
2010-08-05 18:25   ` Tom Tromey
2010-08-05 18:54 ` Jan Kratochvil
2010-08-11 19:08   ` Joel Brobecker
2010-08-11 19:10     ` Jan Kratochvil
2010-08-11 19:39       ` Joel Brobecker
2010-08-11 19:48         ` Jan Kratochvil
2010-08-16 14:50     ` Joel Brobecker

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1278627885-9416-1-git-send-email-brobecker@adacore.com \
    --to=brobecker@adacore.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).