public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Add python-config override options
@ 2021-10-29 13:28 Alexey Lapshin
  0 siblings, 0 replies; only message in thread
From: Alexey Lapshin @ 2021-10-29 13:28 UTC (permalink / raw)
  To: gdb-patches; +Cc: alexey.gerenkov, ivan, Alexey Lapshin

Cross-platform compiling of GDB may fail with using build machine's
python-config because it provides inappropriate LDFLAGS or whatever.

This patch fixes this issue with new configure options:
--with-python-includes
--with-python-ldflags

My configure options I testet with:
../configure ...bla-bla... \ 
--with-python \
--with-python-libdir=$PYTHON_LIB_DIR \
--with-python-includes=-I$PYTHON_INCLUDE_DIR \
--with-python-ldflags="-L$PYTHON_LIB_DIR -lpython3.7m"

---
 gdb/configure    | 75 ++++++++++++++++++++++++++++++++-------------
 gdb/configure.ac | 79 +++++++++++++++++++++++++++++++++---------------
 2 files changed, 109 insertions(+), 45 deletions(-)

diff --git a/gdb/configure b/gdb/configure
index d5c1883c25b..286c59450e3 100755
--- a/gdb/configure
+++ b/gdb/configure
@@ -908,6 +908,8 @@ with_libmpfr_prefix
 with_libmpfr_type
 with_python
 with_python_libdir
+with_python_includes
+with_python_ldflags
 with_guile
 enable_source_highlight
 with_intel_pt
@@ -1659,6 +1661,8 @@ Optional Packages:
                           (auto/yes/no/<python-program>)
   --with-python-libdir[=DIR]
                           search for python's libraries in DIR
+  --with-python-includes  override python-config --includes
+  --with-python-ldflags   override python-config --ldflags
   --with-guile[=GUILE]    include guile support
                           (auto/yes/no/<guile-version>/<pkg-config-program>)
   --with-intel-pt         include Intel Processor Trace support (auto/yes/no)
@@ -11027,6 +11031,31 @@ $as_echo_n "checking whether to use python... " >&6; }
 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $with_python" >&5
 $as_echo "$with_python" >&6; }
 
+
+# Check whether --with-python-libdir was given.
+if test "${with_python_libdir+set}" = set; then :
+  withval=$with_python_libdir;
+fi
+
+
+
+# Check whether --with-python-includes was given.
+if test "${with_python_includes+set}" = set; then :
+  withval=$with_python_includes;
+    python_includes="${with_python_includes}"
+
+fi
+
+
+
+# Check whether --with-python-ldflags was given.
+if test "${with_python_ldflags+set}" = set; then :
+  withval=$with_python_ldflags;
+    python_libs="${with_python_ldflags}"
+
+fi
+
+
 if test "${with_python}" = no; then
   { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: python support disabled; some features may be unavailable." >&5
 $as_echo "$as_me: WARNING: python support disabled; some features may be unavailable." >&2;}
@@ -11180,21 +11209,33 @@ fi
     # We have a python program to use, but it may be too old.
     # Don't flag an error for --with-python=auto (the default).
     have_python_config=yes
-    python_includes=`${python_prog} ${srcdir}/python/python-config.py --includes`
+    if test -z "${python_includes}"; then
+      python_includes=`${python_prog} ${srcdir}/python/python-config.py --includes`
+    else
+      true
+    fi
     if test $? != 0; then
       have_python_config=failed
       if test "${with_python}" != auto; then
 	as_fn_error $? "failure running python-config --includes" "$LINENO" 5
       fi
     fi
-    python_libs=`${python_prog} ${srcdir}/python/python-config.py --ldflags`
+    if test -z "${python_libs}"; then
+      python_libs=`${python_prog} ${srcdir}/python/python-config.py --ldflags`
+    else
+      true
+    fi
     if test $? != 0; then
       have_python_config=failed
       if test "${with_python}" != auto; then
 	as_fn_error $? "failure running python-config --ldflags" "$LINENO" 5
       fi
     fi
-    python_prefix=`${python_prog} ${srcdir}/python/python-config.py --exec-prefix`
+    if test -z "${with_python_libdir}"; then
+      python_prefix=`${python_prog} ${srcdir}/python/python-config.py --exec-prefix`
+    else
+      true
+    fi
     if test $? != 0; then
       have_python_config=failed
       if test "${with_python}" != auto; then
@@ -11207,9 +11248,11 @@ fi
     # path from the python_prefix either, because that include path
     # depends on the Python version.  So, there is nothing much we can
     # do except assume that the compiler will be able to find those files.
-    python_includes=
-    python_libs=
-    have_python_config=no
+    if  test -n "${python_includes}"  &&  test -n "${python_libs}" ; then
+      have_python_config=yes
+    else
+      have_python_config=no
+    fi
   fi
 
   # If we have python-config, only try the configuration it provides.
@@ -11377,21 +11420,6 @@ _ACEOF
   fi
 fi
 
-
-# Check whether --with-python-libdir was given.
-if test "${with_python_libdir+set}" = set; then :
-  withval=$with_python_libdir;
-else
-
-    # If no python libdir is specified then select one based on
-    # python's prefix path.
-    if test -n "${python_prefix}"; then
-      with_python_libdir=${python_prefix}/lib
-    fi
-
-fi
-
-
 if test "${have_libpython}" != no; then
 
 $as_echo "#define HAVE_PYTHON 1" >>confdefs.h
@@ -11402,6 +11430,11 @@ $as_echo "#define HAVE_PYTHON 1" >>confdefs.h
   CONFIG_INSTALL="$CONFIG_INSTALL install-python"
   ENABLE_CFLAGS="$ENABLE_CFLAGS \$(SUBDIR_PYTHON_CFLAGS)"
 
+  # If no python libdir is specified then select one based on
+  # python's prefix path.
+  if  -z "${with_python_libdir}"  &&  test -n "${python_prefix}" ; then
+    with_python_libdir=${python_prefix}/lib
+  fi
   if test -n "${with_python_libdir}"; then
 
 cat >>confdefs.h <<_ACEOF
diff --git a/gdb/configure.ac b/gdb/configure.ac
index d4cfb6a7624..5680e620119 100644
--- a/gdb/configure.ac
+++ b/gdb/configure.ac
@@ -784,6 +784,36 @@ AC_ARG_WITH(python,
 AC_MSG_CHECKING([whether to use python])
 AC_MSG_RESULT([$with_python])
 
+dnl Use --with-python-libdir to control where GDB looks for the Python
+dnl libraries.
+dnl
+dnl If this is not given then the default will be based on the value
+dnl passed to --with-python, which is in the python_prefix variable.
+dnl If the --with-python option wasn't given then the default value in
+dnl python_prefix is based on running the 'gdb/python/python-config
+dnl --exec-prefix' script.
+AC_ARG_WITH(python-libdir,
+  AS_HELP_STRING([--with-python-libdir@<:@=DIR@:>@], [search for python's libraries in DIR]),
+  [],[])
+
+dnl Use --with-python-includes to override python-config values
+dnl
+dnl If this is given then using instead of python-config --includes
+AC_ARG_WITH(python-includes,
+  AS_HELP_STRING([--with-python-includes], [override python-config --includes]),
+  [
+    python_includes="${with_python_includes}"
+  ],[])
+
+dnl Use --with-python-ldflags to override python-config values
+dnl
+dnl If this is given then using instead of python-config --ldflags
+AC_ARG_WITH(python-ldflags,
+  AS_HELP_STRING([--with-python-ldflags], [override python-config --ldflags]),
+  [
+    python_libs="${with_python_ldflags}"
+  ],[])
+
 if test "${with_python}" = no; then
   AC_MSG_WARN([python support disabled; some features may be unavailable.])
   have_libpython=no
@@ -856,21 +886,33 @@ else
     # We have a python program to use, but it may be too old.
     # Don't flag an error for --with-python=auto (the default).
     have_python_config=yes
-    python_includes=`${python_prog} ${srcdir}/python/python-config.py --includes`
+    if test -z "${python_includes}"; then
+      python_includes=`${python_prog} ${srcdir}/python/python-config.py --includes`
+    else
+      true
+    fi
     if test $? != 0; then
       have_python_config=failed
       if test "${with_python}" != auto; then
 	AC_MSG_ERROR(failure running python-config --includes)
       fi
     fi
-    python_libs=`${python_prog} ${srcdir}/python/python-config.py --ldflags`
+    if test -z "${python_libs}"; then
+      python_libs=`${python_prog} ${srcdir}/python/python-config.py --ldflags`
+    else
+      true
+    fi
     if test $? != 0; then
       have_python_config=failed
       if test "${with_python}" != auto; then
 	AC_MSG_ERROR(failure running python-config --ldflags)
       fi
     fi
-    python_prefix=`${python_prog} ${srcdir}/python/python-config.py --exec-prefix`
+    if test -z "${with_python_libdir}"; then
+      python_prefix=`${python_prog} ${srcdir}/python/python-config.py --exec-prefix`
+    else
+      true
+    fi
     if test $? != 0; then
       have_python_config=failed
       if test "${with_python}" != auto; then
@@ -883,9 +925,11 @@ else
     # path from the python_prefix either, because that include path
     # depends on the Python version.  So, there is nothing much we can
     # do except assume that the compiler will be able to find those files.
-    python_includes=
-    python_libs=
-    have_python_config=no
+    if [ test -n "${python_includes}" ] && [ test -n "${python_libs}" ]; then
+      have_python_config=yes
+    else
+      have_python_config=no
+    fi
   fi
 
   # If we have python-config, only try the configuration it provides.
@@ -928,24 +972,6 @@ else
   fi
 fi
 
-dnl Use --with-python-libdir to control where GDB looks for the Python
-dnl libraries.
-dnl
-dnl If this is not given then the default will be based on the value
-dnl passed to --with-python, which is in the python_prefix variable.
-dnl If the --with-python option wasn't given then the default value in
-dnl python_prefix is based on running the 'gdb/python/python-config
-dnl --exec-prefix' script.
-AC_ARG_WITH(python-libdir,
-  AS_HELP_STRING([--with-python-libdir@<:@=DIR@:>@], [search for python's libraries in DIR]),
-  [],[
-    # If no python libdir is specified then select one based on
-    # python's prefix path.
-    if test -n "${python_prefix}"; then
-      with_python_libdir=${python_prefix}/lib
-    fi
-  ])
-
 if test "${have_libpython}" != no; then
   AC_DEFINE(HAVE_PYTHON, 1, [Define if Python interpreter is being linked in.])
   CONFIG_OBS="$CONFIG_OBS \$(SUBDIR_PYTHON_OBS)"
@@ -954,6 +980,11 @@ if test "${have_libpython}" != no; then
   CONFIG_INSTALL="$CONFIG_INSTALL install-python"
   ENABLE_CFLAGS="$ENABLE_CFLAGS \$(SUBDIR_PYTHON_CFLAGS)"
 
+  # If no python libdir is specified then select one based on
+  # python's prefix path.
+  if [ -z "${with_python_libdir}" ] && [ test -n "${python_prefix}" ]; then
+    with_python_libdir=${python_prefix}/lib
+  fi
   if test -n "${with_python_libdir}"; then
     AC_DEFINE_UNQUOTED(WITH_PYTHON_LIBDIR, "${with_python_libdir}",
 		       [Directory containing Python's standard libraries from --with-python-libdir.])
-- 
2.25.1


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-10-29 13:30 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-29 13:28 [PATCH] Add python-config override options Alexey Lapshin

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).