Reworking of python support to cope with PEP 3149 changes in latest python 3.2

* Thu Dec 30 2010 David Malcolm <dmalcolm@redhat.com> - 2.0.46-2
- big reworking of the support-multiple-python-builds patch to deal with
PEP 3149: the latest Python 3.2 onwards uses include paths and library names
that don't fit prior naming patterns, and so we must query python3-config for
this information.  To complicate things further, python 2's python-config
doesn't understand all of the options needed ("--extension-suffix").  I've
thus added new Makefile variables as needed, to be supplied by the specfile by
invoking the appropriate config tool (or by hardcoding the old value for
"--extension-suffix" i.e. ".so")
- rework python3 manifest for PEP 3149, and rebuild for newer python3
This commit is contained in:
David Malcolm 2010-12-30 10:50:53 -05:00
parent 6120de7432
commit fb1cbdda8d
3 changed files with 140 additions and 56 deletions

View File

@ -1,44 +0,0 @@
diff --git a/libsemanage/src/Makefile b/libsemanage/src/Makefile
index 7acf63d..cdd8388 100644
--- a/libsemanage/src/Makefile
+++ b/libsemanage/src/Makefile
@@ -1,9 +1,15 @@
+# Support building the Python bindings multiple times, against various Python
+# runtimes (e.g. Python 2 vs Python 3) by optionally prefixing the build
+# targets with "PYPREFIX":
+PYTHON ?= python
+PYPREFIX ?=
+
# Installation directories.
PREFIX ?= $(DESTDIR)/usr
LIBDIR ?= $(PREFIX)/lib
SHLIBDIR ?= $(PREFIX)/lib
INCLUDEDIR ?= $(PREFIX)/include
-PYLIBVER ?= $(shell python -c 'import sys;print "python%d.%d" % sys.version_info[0:2]')
+PYLIBVER ?= $(shell $(PYTHON) -c 'import sys;print("python%d.%d" % sys.version_info[0:2])')
PYINC ?= /usr/include/${PYLIBVER}
PYLIBDIR ?= $(LIBDIR)/${PYLIBVER}
RUBYLIBVER ?= $(shell ruby -e 'print RUBY_VERSION.split(".")[0..1].join(".")')
@@ -34,9 +40,9 @@ SWIGIF= semanageswig_python.i
SWIGRUBYIF= semanageswig_ruby.i
SWIGCOUT= semanageswig_wrap.c
SWIGRUBYCOUT= semanageswig_ruby_wrap.c
-SWIGLOBJ:= $(patsubst %.c,%.lo,$(SWIGCOUT))
+SWIGLOBJ:= $(patsubst %.c,$(PYPREFIX)%.lo,$(SWIGCOUT))
SWIGRUBYLOBJ:= $(patsubst %.c,%.lo,$(SWIGRUBYCOUT))
-SWIGSO=_semanage.so
+SWIGSO=$(PYPREFIX)_semanage.so
SWIGFILES=$(SWIGSO) semanage.py
SWIGRUBYSO=_rubysemanage.so
LIBSO=$(TARGET).$(LIBVERSION)
@@ -132,7 +138,9 @@ install: all
install-pywrap: pywrap
test -d $(PYLIBDIR)/site-packages || install -m 755 -d $(PYLIBDIR)/site-packages
- install -m 755 $(SWIGFILES) $(PYLIBDIR)/site-packages
+ install -m 755 $(SWIGSO) $(PYLIBDIR)/site-packages/_semanage.so
+ install -m 755 semanage.py $(PYLIBDIR)/site-packages
+
install-rubywrap: rubywrap
test -d $(RUBYINSTALL) || install -m 755 -d $(RUBYINSTALL)

View File

@ -0,0 +1,83 @@
diff -up libsemanage-2.0.46/src/Makefile.support-multiple-python-builds libsemanage-2.0.46/src/Makefile
--- libsemanage-2.0.46/src/Makefile.support-multiple-python-builds 2010-12-21 16:30:25.000000000 -0500
+++ libsemanage-2.0.46/src/Makefile 2010-12-30 10:29:56.436647017 -0500
@@ -1,11 +1,39 @@
+# Support building the Python bindings multiple times, against various Python
+# runtimes (e.g. Python 2 vs Python 3) by optionally prefixing the build
+# targets with "PYPREFIX":
+PYTHON ?= python
+PYPREFIX ?=
+
+# PEP 3149 (in Python 3.2) complicates this by changing the extension for
+# Python modules and the path for Python headers; it now must be queried from
+# the python version in question (e.g. via "python3-config --extension-suffix")
+# Unfortunately, earlier versions of python don't support the
+# "--extension-suffix" option to their -config tools
+PY_DSO_SUFFIX ?= .so
+
# Installation directories.
PREFIX ?= $(DESTDIR)/usr
LIBDIR ?= $(PREFIX)/lib
SHLIBDIR ?= $(PREFIX)/lib
INCLUDEDIR ?= $(PREFIX)/include
-PYLIBVER ?= $(shell python -c 'import sys;print "python%d.%d" % sys.version_info[0:2]')
+
+PYLIBVER ?= $(shell $(PYTHON) -c 'import sys;print("python%d.%d" % sys.version_info[0:2])')
PYINC ?= /usr/include/${PYLIBVER}
+
+# PEP 3149 means that the path for Python headers might be something like:
+# /usr/include/python3.2mu
+# and the libraries might be named:
+# libpython3.2mu.so.1.0
+# Support invoking the Makefile in this way:
+# make \
+# PY_INCLUDE_FLAGS="$(python-config --includes)" \
+# PY_LD_FLAGS="$(python-config --libs)" \
+# pywrap
+#
+PY_INCLUDE_FLAGS ?= -I ${PYINC}
PYLIBDIR ?= $(LIBDIR)/${PYLIBVER}
+PY_LD_FLAGS ?= -l$(PYLIBVER)
+
RUBYLIBVER ?= $(shell ruby -e 'print RUBY_VERSION.split(".")[0..1].join(".")')
RUBYPLATFORM ?= $(shell ruby -e 'print RUBY_PLATFORM')
RUBYINC ?= $(LIBDIR)/ruby/$(RUBYLIBVER)/$(RUBYPLATFORM)
@@ -34,9 +62,9 @@ SWIGIF= semanageswig_python.i
SWIGRUBYIF= semanageswig_ruby.i
SWIGCOUT= semanageswig_wrap.c
SWIGRUBYCOUT= semanageswig_ruby_wrap.c
-SWIGLOBJ:= $(patsubst %.c,%.lo,$(SWIGCOUT))
+SWIGLOBJ:= $(patsubst %.c,$(PYPREFIX)%.lo,$(SWIGCOUT))
SWIGRUBYLOBJ:= $(patsubst %.c,%.lo,$(SWIGRUBYCOUT))
-SWIGSO=_semanage.so
+SWIGSO=$(PYPREFIX)_semanage$(PY_DSO_SUFFIX)
SWIGFILES=$(SWIGSO) semanage.py
SWIGRUBYSO=_rubysemanage.so
LIBSO=$(TARGET).$(LIBVERSION)
@@ -63,13 +91,13 @@ pywrap: all $(SWIGLOBJ) $(SWIGSO)
rubywrap: all $(SWIGRUBYSO)
$(SWIGLOBJ): $(SWIGCOUT)
- $(CC) $(filter-out -Werror, $(CFLAGS)) -I$(PYINC) -fPIC -DSHARED -c -o $@ $<
+ $(CC) $(filter-out -Werror, $(CFLAGS)) $(PY_INCLUDE_FLAGS) -fPIC -DSHARED -c -o $@ $<
$(SWIGRUBYLOBJ): $(SWIGRUBYCOUT)
$(CC) $(filter-out -Werror,$(CFLAGS)) -I$(RUBYINC) -fPIC -DSHARED -c -o $@ $<
$(SWIGSO): $(SWIGLOBJ)
- $(CC) $(CFLAGS) $(LDFLAGS) -shared -o $@ $< -L. -lsemanage -l$(PYLIBVER) -L$(LIBDIR) -Wl,-soname,$@,-z,defs
+ $(CC) $(CFLAGS) $(LDFLAGS) -shared -o $@ $< -L. -lsemanage $(PY_LD_FLAGS) -L$(LIBDIR) -Wl,-soname,$@,-z,defs
$(SWIGRUBYSO): $(SWIGRUBYLOBJ)
$(CC) $(CFLAGS) $(LDFLAGS) -shared -o $@ $^ -L. -lsemanage -L$(LIBDIR) -Wl,-soname,$@
@@ -132,7 +160,9 @@ install: all
install-pywrap: pywrap
test -d $(PYLIBDIR)/site-packages || install -m 755 -d $(PYLIBDIR)/site-packages
- install -m 755 $(SWIGFILES) $(PYLIBDIR)/site-packages
+ install -m 755 $(SWIGSO) $(PYLIBDIR)/site-packages/_semanage$(PY_DSO_SUFFIX)
+ install -m 755 semanage.py $(PYLIBDIR)/site-packages
+
install-rubywrap: rubywrap
test -d $(RUBYINSTALL) || install -m 755 -d $(RUBYINSTALL)

View File

@ -10,7 +10,7 @@
Summary: SELinux binary policy manipulation library
Name: libsemanage
Version: 2.0.46
Release: 1%{?dist}
Release: 2%{?dist}
License: LGPLv2+
Group: System Environment/Libraries
Source: http://www.nsa.gov/selinux/archives/libsemanage-%{version}.tgz
@ -20,7 +20,7 @@ Source1: semanage.conf
# Add support to src/Makefile to support building the python bindings multiple
# times, against different Python runtimes:
Patch1: libsemanage-2.0.45-support-multiple-python-builds.patch
Patch1: libsemanage-2.0.46-support-multiple-python-builds.patch
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
BuildRequires: libselinux-devel >= %{libselinuxver} swig ustr-devel
@ -90,7 +90,7 @@ SELinux management applications.
%prep
%setup -q
%patch -p2 -b .rhat
%patch1 -p2 -b .support-multiple-python-builds
%patch1 -p1 -b .support-multiple-python-builds
%build
# To support building the Python wrapper against multiple Python runtimes
@ -99,10 +99,17 @@ SELinux management applications.
BuildPythonWrapper() {
BinaryName=$1
Prefix=$2
PyDsoSuffix=$3
PyIncludeFlags=$4
PyLdFlags=$5
# Perform the build from the upstream Makefile:
make \
PYTHON=$BinaryName PYPREFIX=$Prefix \
PYTHON=$BinaryName \
PYPREFIX=$Prefix \
PY_DSO_SUFFIX=$PyDsoSuffix \
PY_INCLUDE_FLAGS="$PyIncludeFlags" \
PY_LD_FLAGS="$PyLdFlags" \
CFLAGS="%{optflags}" LIBDIR="%{_libdir}" SHLIBDIR="%{_lib}" \
pywrap
}
@ -111,18 +118,34 @@ make clean
make CFLAGS="%{optflags}" swigify
make CFLAGS="%{optflags}" LIBDIR="%{_libdir}" SHLIBDIR="%{_lib}" all
BuildPythonWrapper %{__python} python2
BuildPythonWrapper \
%{__python} \
python2 \
.so \
"$(python-config --includes)" \
"$(python-config --libs)"
%if 0%{?with_python3}
BuildPythonWrapper %{__python3} python3
BuildPythonWrapper \
%{__python3} \
python3 \
$(python3-config --extension-suffix) \
"$(python3-config --includes)" \
"$(python3-config --libs)"
%endif # with_python3
%install
InstallPythonWrapper() {
BinaryName=$1
Prefix=$2
PyDsoSuffix=$3
PyIncludeFlags=$4
PyLdFlags=$5
make \
PYTHON=$BinaryName PYPREFIX=$Prefix \
PYTHON=$BinaryName \
PYPREFIX=$Prefix \
PY_DSO_SUFFIX=$PyDsoSuffix PY_INCLUDE_FLAGS=$PyIncludeFlags \
DESTDIR="${RPM_BUILD_ROOT}" LIBDIR="${RPM_BUILD_ROOT}%{_libdir}" SHLIBDIR="${RPM_BUILD_ROOT}/%{_libdir}" \
install-pywrap
}
@ -132,11 +155,22 @@ mkdir -p ${RPM_BUILD_ROOT}/%{_libdir}
mkdir -p ${RPM_BUILD_ROOT}%{_includedir}
make DESTDIR="${RPM_BUILD_ROOT}" LIBDIR="${RPM_BUILD_ROOT}%{_libdir}" SHLIBDIR="${RPM_BUILD_ROOT}/%{_libdir}" install
InstallPythonWrapper %{__python} python2
%if 0%{?with_python3}
InstallPythonWrapper %{__python3} python3
%endif # with_python3
InstallPythonWrapper \
%{__python} \
python2 \
.so \
"$(python-config --includes)" \
"$(python-config --libs)"
%if 0%{?with_python3}
InstallPythonWrapper \
%{__python3} \
python3 \
$(python3-config --extension-suffix) \
"$(python3-config --includes)" \
"$(python3-config --libs)"
%endif # with_python3
cp %{SOURCE1} ${RPM_BUILD_ROOT}/etc/selinux/semanage.conf
ln -sf %{_libdir}/libsemanage.so.1 ${RPM_BUILD_ROOT}/%{_libdir}/libsemanage.so
@ -172,13 +206,24 @@ rm -rf ${RPM_BUILD_ROOT}
%if 0%{?with_python3}
%files python3
%defattr(-,root,root)
%{python3_sitearch}/_semanage.so
%{python3_sitearch}/_semanage.cpython-3?mu.so
%{python3_sitearch}/semanage.py*
%{python3_sitearch}/__pycache__/semanage*
%endif # if with_python3
%changelog
* Thu Dec 30 2010 David Malcolm <dmalcolm@redhat.com> - 2.0.46-2
- big reworking of the support-multiple-python-builds patch to deal with
PEP 3149: the latest Python 3.2 onwards uses include paths and library names
that don't fit prior naming patterns, and so we must query python3-config for
this information. To complicate things further, python 2's python-config
doesn't understand all of the options needed ("--extension-suffix"). I've
thus added new Makefile variables as needed, to be supplied by the specfile by
invoking the appropriate config tool (or by hardcoding the old value for
"--extension-suffix" i.e. ".so")
- rework python3 manifest for PEP 3149, and rebuild for newer python3
* Tue Dec 21 2010 Dan Walsh <dwalsh@redhat.com> - 2.0.46-1
- Update to upstream
* Fix compliation under GCC 4.6 by Justin Mattock