psss / rpms / libsemanage

Forked from rpms/libsemanage 5 years ago
Clone
Blob Blame History Raw
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)