Chris Johns 257c9267cf gdb/python: Use python-config for the configuration if found.
- Do not assume the installed paths for the header and library.
  Ask python-config if found.

Close #3537.
2018-12-25 10:15:55 +11:00

266 lines
7.3 KiB
INI

#
# GDB Common Version 1.
#
# This configuration file configure's, make's and install's gdb.
#
#
# Python
#
# GDB uses python internally so we need to link to a suitable python
# dev kit. The dev kit for python is the header and a library. These
# files are versioned where the header file is located in a directory
# based on:
#
# pythonM.m/Python.h
#
# where 'M' is the major version number and 'm' is the minor verison
# number. The library is:
#
# libpythonM.m.a
#
# The python command is 'pythonM' which means we need to query it for
# the minor number.
#
# The python running the RSB may not be suitable, for example a MSC,
# MSYS or Cygwin version on Windows when we want the MinGW python dev
# file. A specific version cannot be forced because older versions of
# GDB can only link to 'python2'.
#
# Host support can perform a complex query of the system, for example
# Windows and set '%{gdb_python2}' and '%{gdb_python3}' with the full
# path to that version's executable.
#
# A configuration of GDB can set the version required by setting
# '%{gdb-python-version}' to the versions command, eg python2.
#
# The procedure is:
#
# 1. If the macros '%{gdb_python2}' or '%{gdb_python3}' are present
# use that path they contain. Assume the path is valid.
#
# 2. Does the version of gdb specify a version of python that must be
# used. Override with '%define gdb-python-version python2'.
#
# 3. Search for 'python2' and if not found search for 'python3'.
#
%if %{defined gdb-python2}
%define gdb-enable-python %{gdb_python2}
%else
%if %{defined gdb-python3}
%define gdb-enable-python %{gdb_python3}
%else
%if %{defined gdb-python-version}
%define gdb-enable-python %(command -v %{gdb-python-version} || true)
%else
%define gdb-enable-python %(command -v python2 || true)
%if %{gdb-enable-python} == %{nil}
%define gdb-enable-python %(command -v python3 || true)
%endif
%if %{gdb-enable-python} == %{nil}
%define gdb-enable-python %(command -v python || true})
%endif
%endif
%if %{gdb-enable-python} == %{nil}
%error "gdb: python: no valid version of python found"
%endif
%endif
%endif
#
# Get the Python's major and minor version from the python
# command. The headers and libraries are installed under a major/minor
# (mm) version path and name.
#
# The library file name can vary across the hosts so wildcard the search.
#
%if %{!defined gdb-python-config}
%define gdb-python-config %{nil}
%endif
%if %{gdb-python-config} == %{nil}
%define gdb-python-config %(command -v %{gdb-enable-python}-config || true)
%endif
%define gdb-python-ver-mm %(%{gdb-enable-python} --version 2>&1 | sed -e 's/.* //g' | rev | cut -d'.' -f2- | rev)
%define gdb-python-header Python.h
%define gdb-python-ver-header python%{gdb-python-ver-mm}/%{gdb-python-header}
%define gdb-python-ver-lib libpython%{gdb-python-ver-mm}.*
%if %{host_includes} == %{nil}
%define gdb-host-incs %{nil}
%else
%define gdb-host-incs -I '%{host_includes}'
%endif
%if %{gdb-python-config} != %{nil}
%define gdb-python-config-incs -I '%(%{gdb-python-config} --includes)'
%define gdb-python-header-check %(%{_sbdir}/sb/rtems-build-dep -c %{__cc} %{gdb-host-incs} %{gdb-python-config-incs} -H %{gdb-python-header})
%else
%define gdb-python-header-check %(%{_sbdir}/sb/rtems-build-dep -c %{__cc} %{gdb-host-incs} -H %{gdb-python-ver-header})
%endif
%if %{gdb-python-header-check} == not-found
%error "gdb: python: header file not found: %{gdb-python-ver-header}, please install"
%endif
#
# Too hard to find on MacOS (darwin), the header is good enough.
#
%ifnos darwin
%if %{host_ldflags} == %{nil}
%define gdb-host-libs %{nil}
%else
%define gdb-host-libs -L '%{host_ldflags}'
%endif
%if %{gdb-python-config} != %{nil}
%define gdb-python-config-libs -l '%(%{gdb-python-config} --ldflags)'
%define gdb-python-lib-check %(%{_sbdir}/sb/rtems-build-dep -c %{__cc} %{gdb-host-libs} %{gdb-python-config-libs})
%else
%define gdb-python-lib-check %(%{_sbdir}/sb/rtems-build-dep -c %{__cc} %{gdb-host-libs} -l %{gdb-python-ver-lib})
%endif
%if %{gdb-python-lib-check} == not-found
%error "gdb: python: library file not found: %{gdb-python-ver-lib}, please install"
%endif
%endif
#
# See if the simulator has been disabled for Windows.
#
# Build using the system's readline, it is in better shape
# than GDB's one with MSYS2.
#
%if %{_host_os} == win32
%if %{defined win32-gdb-disable-sim}
%define gdb-disable-sim 1
%endif
%define with_system_readline 1
%endif
#
# Default to building simulators.
#
%ifn %{defined gdb-disable-sim}
%define gdb-disable-sim 0
%else
%undefine gdb-sim-options
%endif
%include %{_configdir}/checks.cfg
#
# Select Snapshot Macro Maps
#
%select gdb-snapshot
%select expat-snapshot
#
# The description.
#
Name: %{_target}-gdb-%{gdb_version}-%{_host}-%{release}
Summary: GDB v%{gdb_version} for target %{_target} on host %{_host}
Version: %{gdb_version}
Release: %{release}
URL: http://www.gnu.org/software/gdb/
#
# GDB has changed it default extension.
#
%ifn %{defined gdb_src_ext}
%define gdb_src_ext gz
%endif
#
# Source
#
%source set gdb http://ftp.gnu.org/gnu/gdb/gdb-%{gdb_version}.tar.%{gdb_src_ext}
#
# Disable Python on Cxc builds for now.
#
%if "%{_build}" != "%{_host}"
%define without_python
%endif
#
# The --with-python option is either the default which is auto or the path to
# the specific python to be used.
#
%if %{defined with_python_path}
%define with_python_option --with-python=%{with_python_path}
%else
%if %{defined gdb-enable-python}
%define with_python_option --with-python=%{gdb-enable-python}
%else
%define with_python_option --with-python
%endif
%endif
#
#
# Prepare the source code.
#
%prep
build_top=$(pwd)
gdb_source=%{?gdb_external:%{gdb_expand_name}}%{!?gdb_external:"gdb-%{gdb_version}"}
source_dir_gdb=${gdb_source}
%source setup gdb -q -n ${gdb_source}
%patch setup gdb -p1
cd ${build_top}
%build
build_top=$(pwd)
%{build_directory}
mkdir -p ${build_dir}
cd ${build_dir}
%{host_build_flags}
if test "%{_build}" != "%{_host}" ; then
GDB_LIBS_STATIC="-lexpat"
else
GDB_LIBS_STATIC="-lexpat"
GDB_LIBS="%{_forced_static}"
fi
LIBS_STATIC=${GDB_LIBS_STATIC} \
LIBS=${GDB_LIBS} \
../${source_dir_gdb}/configure \
--build=%{_build} --host=%{_host} \
--target=%{_target} \
--verbose --disable-nls \
--disable-gas --disable-binutils --disable-ld --disable-gold --disable-gprof \
%{?with_system_readline:--with-system-readline} \
--without-included-gettext \
--disable-win32-registry \
--disable-werror \
%{!?gdb-disable-sim:--enable-sim}%{?gdb-disable-sim:--disable-sim} \
%{?gdb-sim-options:%{gdb-sim-options}} \
--without-zlib \
--with-expat \
--with-guile=no \
%{!?without_python:%{with_python_option}} \
--prefix=%{_prefix} --bindir=%{_bindir} \
--exec-prefix=%{_exec_prefix} \
--includedir=%{_includedir} --libdir=%{_libdir} \
--mandir=%{_mandir} --infodir=%{_infodir}
%{__make} %{?_smp_mflags} all
cd ${build_top}
%install
build_top=$(pwd)
%{__rmdir} $SB_BUILD_ROOT
cd ${build_dir}
%{__make} DESTDIR=$SB_BUILD_ROOT install
# Dropped in FSF-binutils-2.9.5, but Cygwin still ships it.
%{__rmdir} $SB_BUILD_ROOT%{_infodir}/configure.info*
%{__rmfile} $SB_BUILD_ROOT%{_infodir}/dir
touch $SB_BUILD_ROOT%{_infodir}/dir
cd ${build_top}