2010-05-21 Doug Evans Allow python to find its files if moved from original location. * acinclude.m4 (GDB_AC_DEFINE_RELOCATABLE): New function. (GDB_AC_WITH_DIR): Call it. * configure.ac: If a path is provided to --with-python, define WITH_PYTHON_PATH. * config.in: Regenerate. * configure: Regenerate. * defs.h (python_libdir): Declare. * main.c (python_libdir): Define. (captured_main): Initialize python_libdir. * python/python.c (_initialize_python): If configured with --with-python=/path, call Py_SetProgramName to make sure python can find its libraries and modules. Index: acinclude.m4 =================================================================== RCS file: /cvs/src/src/gdb/acinclude.m4,v retrieving revision 1.35 diff -u -p -r1.35 acinclude.m4 --- acinclude.m4 8 Jan 2010 07:16:43 -0000 1.35 +++ acinclude.m4 21 May 2010 08:04:12 -0000 @@ -403,22 +403,12 @@ AC_DEFUN([CY_AC_TK_PRIVATE_HEADERS], [ fi ]) -dnl GDB_AC_WITH_DIR([VARIABLE], [ARG-NAME], [HELP], [DEFAULT]) -dnl Add a new --with option that defines a directory. -dnl The result is stored in VARIABLE. AC_DEFINE_DIR is called -dnl on this variable, as is AC_SUBST. -dnl ARG-NAME is the base name of the argument (without "--with"). -dnl HELP is the help text to use. -dnl If the user's choice is relative to the prefix, then the +dnl GDB_AC_DEFINE_RELOCATABLE([VARIABLE], [ARG-NAME], [SHELL-VARIABLE]) +dnl For use in processing directory values for --with-foo. +dnl If the path in SHELL_VARIABLE is relative to the prefix, then the dnl result is relocatable, then this will define the C macro dnl VARIABLE_RELOCATABLE to 1; otherwise it is defined as 0. -dnl DEFAULT is the default value, which is used if the user -dnl does not specify the argument. -AC_DEFUN([GDB_AC_WITH_DIR], [ - AC_ARG_WITH([$2], AS_HELP_STRING([--with-][$2][=PATH], [$3]), [ - [$1]=$withval], [[$1]=[$4]]) - AC_DEFINE_DIR([$1], [$1], [$3]) - AC_SUBST([$1]) +AC_DEFUN([GDB_AC_DEFINE_RELOCATABLE], [ if test "x$exec_prefix" = xNONE || test "x$exec_prefix" = 'x${prefix}'; then if test "x$prefix" = xNONE; then test_prefix=/usr/local @@ -429,11 +419,30 @@ AC_DEFUN([GDB_AC_WITH_DIR], [ test_prefix=$exec_prefix fi value=0 - case ${ac_define_dir} in + case [$3] in "${test_prefix}"|"${test_prefix}/"*|\ '${exec_prefix}'|'${exec_prefix}/'*) value=1 ;; esac AC_DEFINE_UNQUOTED([$1]_RELOCATABLE, $value, [Define if the $2 directory should be relocated when GDB is moved.]) +]) + +dnl GDB_AC_WITH_DIR([VARIABLE], [ARG-NAME], [HELP], [DEFAULT]) +dnl Add a new --with option that defines a directory. +dnl The result is stored in VARIABLE. AC_DEFINE_DIR is called +dnl on this variable, as is AC_SUBST. +dnl ARG-NAME is the base name of the argument (without "--with"). +dnl HELP is the help text to use. +dnl If the user's choice is relative to the prefix, then the +dnl result is relocatable, then this will define the C macro +dnl VARIABLE_RELOCATABLE to 1; otherwise it is defined as 0. +dnl DEFAULT is the default value, which is used if the user +dnl does not specify the argument. +AC_DEFUN([GDB_AC_WITH_DIR], [ + AC_ARG_WITH([$2], AS_HELP_STRING([--with-][$2][=PATH], [$3]), [ + [$1]=$withval], [[$1]=[$4]]) + AC_DEFINE_DIR([$1], [$1], [$3]) + AC_SUBST([$1]) + GDB_AC_DEFINE_RELOCATABLE([$1], [$2], ${ac_define_dir}) ]) Index: configure.ac =================================================================== RCS file: /cvs/src/src/gdb/configure.ac,v retrieving revision 1.117 diff -u -p -r1.117 configure.ac --- configure.ac 23 Apr 2010 18:07:26 -0000 1.117 +++ configure.ac 21 May 2010 08:11:50 -0000 @@ -669,6 +669,13 @@ else esac CPPFLAGS=$save_CPPFLAGS LIBS=$save_LIBS + else + case "${with_python}" in + /*) + AC_DEFINE_UNQUOTED(WITH_PYTHON_PATH, "${with_python}", [Define if --with-python contains a path.]) + GDB_AC_DEFINE_RELOCATABLE(PYTHON_PATH, python-path, ${with_python}) + ;; + esac fi fi Index: defs.h =================================================================== RCS file: /cvs/src/src/gdb/defs.h,v retrieving revision 1.273 diff -u -p -r1.273 defs.h --- defs.h 2 May 2010 23:52:14 -0000 1.273 +++ defs.h 21 May 2010 08:04:12 -0000 @@ -157,6 +157,10 @@ extern char *gdb_sysroot; /* GDB datadir, used to store data files. */ extern char *gdb_datadir; +/* If non-NULL, the possibly relocated path to bin/python specified with + --with-python-path. */ +extern char *python_libdir; + /* Search path for separate debug files. */ extern char *debug_file_directory; Index: main.c =================================================================== RCS file: /cvs/src/src/gdb/main.c,v retrieving revision 1.84 diff -u -p -r1.84 main.c --- main.c 16 May 2010 00:18:02 -0000 1.84 +++ main.c 21 May 2010 08:04:12 -0000 @@ -68,6 +68,10 @@ char *gdb_sysroot = 0; /* GDB datadir, used to store data files. */ char *gdb_datadir = 0; +/* If gdb was configured with --with-python=/path, + the possibly relocated path to python's lib directory. */ +char *python_libdir = 0; + struct ui_file *gdb_stdout; struct ui_file *gdb_stderr; struct ui_file *gdb_stdlog; @@ -351,6 +358,14 @@ captured_main (void *data) gdb_datadir = relocate_directory (argv[0], GDB_DATADIR, GDB_DATADIR_RELOCATABLE); +#ifdef WITH_PYTHON_PATH + /* For later use in helping Python find itself. */ + python_libdir = relocate_directory (argv[0], + concat (WITH_PYTHON_PATH, + SLASH_STRING, "lib", NULL), + PYTHON_PATH_RELOCATABLE); +#endif + #ifdef RELOC_SRCDIR add_substitute_path_rule (RELOC_SRCDIR, make_relative_prefix (argv[0], BINDIR, Index: python/python.c =================================================================== RCS file: /cvs/src/src/gdb/python/python.c,v retrieving revision 1.38 diff -u -p -r1.38 python.c --- python/python.c 19 May 2010 23:32:24 -0000 1.38 +++ python/python.c 21 May 2010 08:04:12 -0000 @@ -645,6 +645,17 @@ Enables or disables printing of Python s &show_python_list); #ifdef HAVE_PYTHON +#ifdef WITH_PYTHON_PATH + /* Work around problem where python gets confused about where it is, + and then can't find its libraries, etc. + NOTE: Python assumes the following layout: + /foo/bin/python + /foo/lib/pythonX.Y/... + This must be done before calling Py_Initialize. */ + Py_SetProgramName (concat (ldirname (python_libdir), SLASH_STRING, "bin", + SLASH_STRING, "python", NULL)); +#endif + Py_Initialize (); PyEval_InitThreads ();