r147958 - in /trunk/libstdc++-v3: ChangeLog Mak...
Tom Tromey
tromey@redhat.com
Fri May 29 22:11:00 GMT 2009
Here's another version of the patch.
This one does not make assumptions about the relative path from the
objfile to the python code. Instead, it computes it at runtime.
Let me know what you think.
Tom
2009-05-29 Tom Tromey <tromey@redhat.com>
PR libstdc++/40289:
* python/Makefile.in: Rebuild.
* python/hook.in: Compute module path relative to objfile.
* python/Makefile.am (pythondir): Redefine.
(gdb.py): Subst toolexeclibdir.
(install-data-local): Rewrite.
Index: python/hook.in
===================================================================
--- python/hook.in (revision 147958)
+++ python/hook.in (working copy)
@@ -16,9 +16,37 @@
import sys
import gdb
+import os
+import os.path
-# Update module path.
-dir = '@dir@'
+pythondir = '@pythondir@'
+libdir = '@toolexeclibdir@'
+
+# Update module path. We want to find the relative path from libdir
+# to pythondir, and then we want to apply that relative path to the
+# directory holding the objfile with which this file is associated.
+# This preserves relocatability of the gcc tree.
+
+# Do a simple normalization that removes duplicate separators.
+pythondir = os.path.join (*['/'] + pythondir.split (os.sep))
+libdir = os.path.join (*['/'] + libdir.split (os.sep))
+
+prefix = os.path.commonprefix ([libdir, pythondir])
+# In some bizarre configuration we might have found a match in the
+# middle of a directory name.
+if prefix[-1] != '/':
+ prefix = os.path.dirname (prefix)
+
+# Strip off the prefix.
+pythondir = pythondir[len (prefix):]
+libdir = libdir[len (prefix):]
+
+# Compute the ".."s needed to get from libdir to the prefix.
+dotdots = ('..' + os.sep) * len (libdir.split (os.sep))
+
+objfile = gdb.current_objfile ().filename
+dir = os.path.join (os.path.dirname (objfile), dotdots, pythondir)
+
if not dir in sys.path:
sys.path.insert(0, dir)
Index: python/Makefile.am
===================================================================
--- python/Makefile.am (revision 147958)
+++ python/Makefile.am (working copy)
@@ -24,7 +24,7 @@
include $(top_srcdir)/fragment.am
## Where to install the module code.
-pythondir = $(pkgdatadir)/python
+pythondir = $(datadir)/gcc-$(gcc_version)/python
all-local: gdb.py
@@ -34,10 +34,27 @@
libstdcxx/__init__.py
gdb.py: hook.in Makefile
- sed -e 's,@dir@,$(pythondir),' < $(srcdir)/hook.in > $@
+ sed -e 's,@pythondir@,$(pythondir),' \
+ -e 's,@toolexeclibdir@,$(toolexeclibdir),' < $(srcdir)/hook.in > $@
install-data-local: gdb.py
@$(mkdir_p) $(DESTDIR)$(toolexeclibdir)
- @libname=`cd $(toolexeclibdir) && ls -r libstdc++* | fgrep -v gdb.py | sed 1q`; \
+## We want to install gdb.py as SOMETHING-gdb.py. SOMETHING is the
+## full name of the final library. We want to ignore symlinks, the
+## .la file, and any previous -gdb.py file. This is inherently
+## fragile, but there does not seem to be a better option, because
+## libtool hides the real names from us.
+ @here=`pwd`; cd $(toolexeclibdir); \
+ for file in libstdc++*; do \
+ case $$file in \
+ *-gdb.py) ;; \
+ *.la) ;; \
+ *) if test -h $$file; then \
+ continue; \
+ fi; \
+ libname=$$file;; \
+ esac; \
+ done; \
+ cd $$here; \
echo " $(INSTALL_DATA) gdb.py $(DESTDIR)$(toolexeclibdir)/$$libname-gdb.py"; \
$(INSTALL_DATA) gdb.py $(DESTDIR)$(toolexeclibdir)/$$libname-gdb.py
More information about the Gcc-patches
mailing list