This is the mail archive of the archer@sourceware.org mailing list for the Archer project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[python] allow build gdb to find python library


As suggested by Thiago, this patch lets the build gdb find the python
library.

I added some empty __init__.py files to make this work.  This cleans
up the Makefile, which is nice.

I also added a new gdb.pythonlibdir variable so that the require code
would know what to do in the two different scenarios.

Tom

2008-11-24  Tom Tromey  <tromey@redhat.com>

	* python/lib/gdb/libstdcxx/v6/__init__.py: New file.
	* python/lib/gdb/libstdcxx/__init__.py: New file.
	* python/lib/gdb/function/__init__.py: New file.
	* python/lib/gdb/command/__init__.py: New file.
	* gdbinit.in: Set up python library.
	* python/lib/gdb/command/require.py (RequireSubcommand.complete):
	Use gdb.pythonlibdir.
	* python/python.c (_initialize_python): Set gdb.pythonlibdir.
	* Makefile.in (.gdbinit): New target.
	(all): Depend on .gdbinit.
	(PY_DIRS): Remove.
	(PY_FILES): Update.
	(install-python): Don't make dummy __init__.py files.

diff --git a/gdb/Makefile.in b/gdb/Makefile.in
index 497e26e..935748d 100644
--- a/gdb/Makefile.in
+++ b/gdb/Makefile.in
@@ -869,7 +869,7 @@ generated_files = config.h observer.h observer.inc ada-lex.c \
 	$(COMPILE) $<
 	$(POSTCOMPILE)
 
-all: gdb$(EXEEXT) $(CONFIG_ALL)
+all: gdb$(EXEEXT) $(CONFIG_ALL) .gdbinit
 	@$(MAKE) $(FLAGS_TO_PASS) DO=all "DODIRS=`echo $(SUBDIRS) | sed 's/testsuite//'`" subdir_do
 .PHONY: all-tui
 all-tui: $(TUI)$(EXEEXT)
@@ -1221,6 +1221,12 @@ stamp-h: config.in config.status
 	  CONFIG_LINKS= \
 	  $(SHELL) config.status
 
+.gdbinit: gdbinit.in config.status
+	CONFIG_FILES=".gdbinit:gdbinit.in" \
+	  CONFIG_COMMANDS= \
+	  CONFIG_HEADERS= \
+	  $(SHELL) config.status
+
 config.status: configure configure.tgt configure.host
 	$(SHELL) config.status --recheck
 
@@ -1913,31 +1919,21 @@ python-value.o: $(srcdir)/python/python-value.c
 	$(COMPILE) $(PYTHON_CFLAGS) $(srcdir)/python/python-value.c
 	$(POSTCOMPILE)
 
-# All Python install directories.  These must be sorted, shallowest
-# first.  These are maintained by hand because that is simpler than
-# writing portable sh to make the __init__.py files, and the result is
-# faster.
-PY_DIRS = gdb gdb/command gdb/function gdb/libstdcxx gdb/libstdcxx/v6
-
 # All python library files, with the "python/lib" stripped off.
 # Note that we should only install files in the "gdb" module.
-PY_FILES = gdb/backtrace.py gdb/command/alias.py \
+PY_FILES = gdb/FrameIterator.py gdb/command/alias.py \
     gdb/command/backtrace.py gdb/command/require.py \
+    gdb/command/__init__.py gdb/libstdcxx/v6/printers.py \
+    gdb/libstdcxx/v6/__init__.py gdb/libstdcxx/__init__.py \
     gdb/function/caller_is.py gdb/function/in_scope.py \
-    gdb/FrameIterator.py gdb/__init__.py gdb/libstdcxx/v6/printers.py
+    gdb/function/__init__.py gdb/backtrace.py gdb/__init__.py
 
 # Install the Python library.  Python library files go under
-# $(GDB_DATADIR_PATH)/python.  We create a dummy __init__.py for
-# each directory, to make importing work properly.  If there is a real
-# __init__.py in PY_FILES, it will overwrite the dummy file.
+# $(GDB_DATADIR_PATH)/python.
 install-python:
-	dirs='$(PY_DIRS)'; for dir in $$dirs; do \
-	  $(SHELL) $(srcdir)/../mkinstalldirs $(DESTDIR)$(GDB_DATADIR_PATH)/python/$$dir; \
-	  if ! test -f $(DESTDIR)$(GDB_DATADIR_PATH)/python/$$dir/__init__.py; then \
-	    echo > $(DESTDIR)$(GDB_DATADIR_PATH)/python/$$dir/__init__.py; \
-	  fi; \
-	done; \
 	files='$(PY_FILES)'; for file in $$files; do \
+	  dir=`echo "$$file" | sed 's,/[^/]*$$,,'`; \
+	  $(SHELL) $(srcdir)/../mkinstalldirs $(DESTDIR)$(GDB_DATADIR_PATH)/python/$$dir; \
 	  $(INSTALL_DATA) $(srcdir)/python/lib/$$file $(DESTDIR)$(GDB_DATADIR_PATH)/python/$$file; \
 	done
 
diff --git a/gdb/gdbinit.in b/gdb/gdbinit.in
index ffb7f53..a2e7e94 100644
--- a/gdb/gdbinit.in
+++ b/gdb/gdbinit.in
@@ -1,5 +1,15 @@
 echo Setting up the environment for debugging gdb.\n
 
+# Set up the Python library and "require" command.
+python
+from os.path import abspath
+gdb.datadir = abspath ('@srcdir@/python/lib')
+gdb.pythonlibdir = gdb.datadir
+gdb.__path__ = [gdb.datadir + '/gdb']
+sys.path.insert(0, gdb.datadir)
+end
+source @srcdir@/python/lib/gdb/__init__.py
+
 set complaints 1
 
 b internal_error
diff --git a/gdb/python/lib/gdb/command/__init__.py b/gdb/python/lib/gdb/command/__init__.py
new file mode 100644
index 0000000..8b13789
--- /dev/null
+++ b/gdb/python/lib/gdb/command/__init__.py
@@ -0,0 +1 @@
+
diff --git a/gdb/python/lib/gdb/command/require.py b/gdb/python/lib/gdb/command/require.py
index 36b63e5..f75faad 100644
--- a/gdb/python/lib/gdb/command/require.py
+++ b/gdb/python/lib/gdb/command/require.py
@@ -41,7 +41,7 @@ class RequireSubcommand (gdb.Command):
             exec ('import gdb.' + self.name + '.' + cmd, globals ())
 
     def complete (self, text, word):
-        dir = gdb.datadir + '/python/gdb/' + self.name
+        dir = gdb.pythonlibdir + '/gdb/' + self.name
         result = []
         for file in os.listdir(dir):
             if not file.startswith (word) or not file.endswith ('.py'):
diff --git a/gdb/python/lib/gdb/function/__init__.py b/gdb/python/lib/gdb/function/__init__.py
new file mode 100644
index 0000000..8b13789
--- /dev/null
+++ b/gdb/python/lib/gdb/function/__init__.py
@@ -0,0 +1 @@
+
diff --git a/gdb/python/lib/gdb/libstdcxx/__init__.py b/gdb/python/lib/gdb/libstdcxx/__init__.py
new file mode 100644
index 0000000..8b13789
--- /dev/null
+++ b/gdb/python/lib/gdb/libstdcxx/__init__.py
@@ -0,0 +1 @@
+
diff --git a/gdb/python/lib/gdb/libstdcxx/v6/__init__.py b/gdb/python/lib/gdb/libstdcxx/v6/__init__.py
new file mode 100644
index 0000000..8b13789
--- /dev/null
+++ b/gdb/python/lib/gdb/libstdcxx/v6/__init__.py
@@ -0,0 +1 @@
+
diff --git a/gdb/python/python.c b/gdb/python/python.c
index 52860eb..7b46f0d 100644
--- a/gdb/python/python.c
+++ b/gdb/python/python.c
@@ -1300,10 +1300,11 @@ class GdbOutputFile:\n\
 sys.stderr = GdbOutputFile()\n\
 sys.stdout = GdbOutputFile()\n\
 if hasattr (gdb, 'datadir'):\n\
-  sys.path.insert(0, gdb.datadir + '/python')\n\
-  gdb.__path__ = [gdb.datadir + '/python/gdb']\n\
+  gdb.pythonlibdir = gdb.datadir + '/python'\n\
+  sys.path.insert(0, gdb.pythonlibdir)\n\
+  gdb.__path__ = [gdb.pythonlibdir + '/gdb']\n\
   from os.path import exists\n\
-  ipy = gdb.datadir + '/python/gdb/__init__.py'\n\
+  ipy = gdb.pythonlibdir + '/gdb/__init__.py'\n\
   if exists (ipy):\n\
     execfile (ipy)\n\
 ");


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]