[Python-Dev] use cases for "python-config" versus "pkg-config python"
Michael Haubenwallner
michael.haubenwallner at ssi-schaefer.com
Mon Jun 2 20:11:15 CEST 2014
Hi,
following up myself with a patch proposal:
On 05/28/2014 04:51 PM, Michael Haubenwallner wrote:
> Stumbling over problems on AIX (Modules/python.exp not found) building libxml2 as python module
> let me wonder about the intended use-cases for 'python-config' and 'pkg-config python'.
>
> FWIW, I can see these distinct use cases here, and I'm kindly asking if I got them right:
>
> * Build an application containing a python interpreter (like python$EXE itself):
> + link against libpython.so
> + re-export symbols from libpython.so for python-modules (platform-specific)
> + This is similar to build against any other library, thus
> = 'python.pc' is installed (for 'pkg-config python').
>
> * Build a python-module (like build/lib.<platform>-<pyver>/*.so):
> + no need to link against libpython.so, instead
> + expect symbols from libpython.so to be available at runtime, platform-specific either as
> + undefined symbols at build-time (Linux, others), or
> + a list of symbols to import from "the main executable" (AIX)
> + This is specific to python-modules, thus
> = 'python-config' is installed.
>
Based on these use-cases, I'm on a trip towards a patch improving AIX support here,
where the attached one is a draft against python-tip (next step is to have python-config
not print $LIBS, but $LINKFORMODULE only).
Thoughts?
Thank you!
/haubi/
-------------- next part --------------
diff -r dc3afbee4ad1 Makefile.pre.in
--- a/Makefile.pre.in Mon Jun 02 01:32:23 2014 -0700
+++ b/Makefile.pre.in Mon Jun 02 19:57:54 2014 +0200
@@ -87,6 +87,9 @@
SGI_ABI= @SGI_ABI@
CCSHARED= @CCSHARED@
LINKFORSHARED= @LINKFORSHARED@
+BLINKFORSHARED= @BLINKFORSHARED@
+LINKFORMODULE= @LINKFORMODULE@
+BLINKFORMODULE= @BLINKFORMODULE@
ARFLAGS= @ARFLAGS@
# Extra C flags added for building the interpreter object files.
CFLAGSFORSHARED=@CFLAGSFORSHARED@
@@ -540,7 +543,7 @@
# Build the interpreter
$(BUILDPYTHON): Modules/python.o $(LIBRARY) $(LDLIBRARY) $(PY3LIBRARY)
- $(LINKCC) $(PY_LDFLAGS) $(LINKFORSHARED) -o $@ Modules/python.o $(BLDLIBRARY) $(LIBS) $(MODLIBS) $(SYSLIBS) $(LDLAST)
+ $(LINKCC) $(PY_LDFLAGS) $(BLINKFORSHARED) -o $@ Modules/python.o $(BLDLIBRARY) $(LIBS) $(MODLIBS) $(SYSLIBS) $(LDLAST)
platform: $(BUILDPYTHON) pybuilddir.txt
$(RUNSHARED) $(PYTHON_FOR_BUILD) -c 'import sys ; from sysconfig import get_platform ; print(get_platform()+"-"+sys.version[0:3])' >platform
@@ -666,7 +669,7 @@
fi
Modules/_testembed: Modules/_testembed.o $(LIBRARY) $(LDLIBRARY) $(PY3LIBRARY)
- $(LINKCC) $(PY_LDFLAGS) $(LINKFORSHARED) -o $@ Modules/_testembed.o $(BLDLIBRARY) $(LIBS) $(MODLIBS) $(SYSLIBS) $(LDLAST)
+ $(LINKCC) $(PY_LDFLAGS) $(BLINKFORSHARED) -o $@ Modules/_testembed.o $(BLDLIBRARY) $(LIBS) $(MODLIBS) $(SYSLIBS) $(LDLAST)
############################################################################
# Importlib
@@ -1310,7 +1313,7 @@
# pkgconfig directory
LIBPC= $(LIBDIR)/pkgconfig
-libainstall: all python-config
+libainstalldirs:
@for i in $(LIBDIR) $(LIBPL) $(LIBPC); \
do \
if test ! -d $(DESTDIR)$$i; then \
@@ -1319,6 +1322,16 @@
else true; \
fi; \
done
+
+# resolve Makefile variables eventually found in configured python.pc values
+$(DESTDIR)$(LIBPC)/python-$(VERSION).pc: Misc/python.pc Makefile libainstalldirs
+ @echo "Resolving more values for $(LIBPC)/python-$(VERSION).pc"; \
+ if test set = "$${PYTHON_PC_CONTENT:+set}"; \
+ then echo '$(PYTHON_PC_CONTENT)' | tr '@' '\n' > $@; \
+ else PYTHON_PC_CONTENT="`awk -v ORS='@' '{print $0}' < Misc/python.pc`" $(MAKE) $@ `grep = Misc/python.pc`; \
+ fi
+
+libainstall: all python-config libainstalldirs $(DESTDIR)$(LIBPC)/python-$(VERSION).pc
@if test -d $(LIBRARY); then :; else \
if test "$(PYTHONFRAMEWORKDIR)" = no-framework; then \
if test "$(SHLIB_SUFFIX)" = .dll; then \
@@ -1338,7 +1351,6 @@
$(INSTALL_DATA) Modules/Setup $(DESTDIR)$(LIBPL)/Setup
$(INSTALL_DATA) Modules/Setup.local $(DESTDIR)$(LIBPL)/Setup.local
$(INSTALL_DATA) Modules/Setup.config $(DESTDIR)$(LIBPL)/Setup.config
- $(INSTALL_DATA) Misc/python.pc $(DESTDIR)$(LIBPC)/python-$(VERSION).pc
$(INSTALL_SCRIPT) $(srcdir)/Modules/makesetup $(DESTDIR)$(LIBPL)/makesetup
$(INSTALL_SCRIPT) $(srcdir)/install-sh $(DESTDIR)$(LIBPL)/install-sh
$(INSTALL_SCRIPT) python-config.py $(DESTDIR)$(LIBPL)/python-config.py
@@ -1540,6 +1552,7 @@
-rm -rf build platform
-rm -rf $(PYTHONFRAMEWORKDIR)
-rm -f python-config.py python-config
+ -rm -f Misc/python.pc
# Make things extra clean, before making a distribution:
# remove all generated files, even Makefile[.pre]
@@ -1612,7 +1625,7 @@
.PHONY: frameworkinstallmaclib frameworkinstallapps frameworkinstallunixtools
.PHONY: frameworkaltinstallunixtools recheck autoconf clean clobber distclean
.PHONY: smelly funny patchcheck touch altmaninstall commoninstall
-.PHONY: gdbhooks
+.PHONY: gdbhooks libainstalldirs
# IF YOU PUT ANYTHING HERE IT WILL GO AWAY
# Local Variables:
diff -r dc3afbee4ad1 Misc/python-config.in
--- a/Misc/python-config.in Mon Jun 02 01:32:23 2014 -0700
+++ b/Misc/python-config.in Mon Jun 02 19:57:54 2014 +0200
@@ -55,7 +55,7 @@
if not getvar('Py_ENABLE_SHARED'):
libs.insert(0, '-L' + getvar('LIBPL'))
if not getvar('PYTHONFRAMEWORK'):
- libs.extend(getvar('LINKFORSHARED').split())
+ libs.extend(getvar('LINKFORMODULE').split())
print(' '.join(libs))
elif opt == '--extension-suffix':
diff -r dc3afbee4ad1 Misc/python-config.sh.in
--- a/Misc/python-config.sh.in Mon Jun 02 01:32:23 2014 -0700
+++ b/Misc/python-config.sh.in Mon Jun 02 19:57:54 2014 +0200
@@ -43,7 +43,6 @@
LIBS="@LIBS@ $SYSLIBS -lpython${VERSION}${ABIFLAGS}"
BASECFLAGS="@BASECFLAGS@"
LDLIBRARY="@LDLIBRARY@"
-LINKFORSHARED="@LINKFORSHARED@"
OPT="@OPT@"
PY_ENABLE_SHARED="@PY_ENABLE_SHARED@"
LDVERSION="@LDVERSION@"
@@ -53,6 +52,7 @@
PYTHONFRAMEWORK="@PYTHONFRAMEWORK@"
INCDIR="-I$includedir/python${VERSION}${ABIFLAGS}"
PLATINCDIR="-I$includedir/python${VERSION}${ABIFLAGS}"
+LINKFORMODULE="@LINKFORMODULE@"
# Scan for --help or unknown argument.
for ARG in $*
@@ -88,15 +88,15 @@
echo "$LIBS"
;;
--ldflags)
- LINKFORSHAREDUSED=
+ LINKFORMODULEUSED=
if [ -z "$PYTHONFRAMEWORK" ] ; then
- LINKFORSHAREDUSED=$LINKFORSHARED
+ LINKFORMODULEUSED=$LINKFORMODULE
fi
LIBPLUSED=
if [ "$PY_ENABLE_SHARED" = "0" ] ; then
LIBPLUSED="-L$LIBPL"
fi
- echo "$LIBPLUSED -L$libdir $LIBS $LINKFORSHAREDUSED"
+ echo "$LIBPLUSED -L$libdir $LIBS $LINKFORMODULEUSED"
;;
--extension-suffix)
echo "$SO"
diff -r dc3afbee4ad1 Misc/python.pc.in
--- a/Misc/python.pc.in Mon Jun 02 01:32:23 2014 -0700
+++ b/Misc/python.pc.in Mon Jun 02 19:57:54 2014 +0200
@@ -9,5 +9,5 @@
Requires:
Version: @VERSION@
Libs.private: @LIBS@
-Libs: -L${libdir} -lpython at VERSION@@ABIFLAGS@
+Libs: -L${libdir} -lpython at VERSION@@ABIFLAGS@ @LINKFORSHARED@
Cflags: -I${includedir}/python at VERSION@@ABIFLAGS@
diff -r dc3afbee4ad1 configure.ac
--- a/configure.ac Mon Jun 02 01:32:23 2014 -0700
+++ b/configure.ac Mon Jun 02 19:57:54 2014 +0200
@@ -1948,6 +1948,9 @@
AC_SUBST(BLDSHARED)
AC_SUBST(CCSHARED)
AC_SUBST(LINKFORSHARED)
+AC_SUBST(BLINKFORSHARED)
+AC_SUBST(LINKFORMODULE)
+AC_SUBST(BLINKFORMODULE)
# SHLIB_SUFFIX is the extension of shared libraries `(including the dot!)
# -- usually .so, .sl on HP-UX, .dll on Cygwin
@@ -1975,8 +1978,8 @@
then
case $ac_sys_system/$ac_sys_release in
AIX*)
- BLDSHARED="Modules/ld_so_aix \$(CC) -bI:Modules/python.exp"
- LDSHARED="\$(BINLIBDEST)/config/ld_so_aix \$(CC) -bI:\$(BINLIBDEST)/config/python.exp"
+ BLDSHARED="Modules/ld_so_aix \$(CC) \$(BLINKFORMODULE)"
+ LDSHARED="\$(LIBPL)/ld_so_aix \$(CC) \$(LINKFORMODULE)"
;;
IRIX/5*) LDSHARED="ld -shared";;
IRIX*/6*) LDSHARED="ld ${SGI_ABI} -shared -all";;
@@ -2136,13 +2139,21 @@
esac
fi
AC_MSG_RESULT($CCSHARED)
-# LINKFORSHARED are the flags passed to the $(CC) command that links
-# the python executable -- this is only needed for a few systems
+# LINKFORSHARED are the flags passed to the $(CC) command that links an
+# application using a python interpreter -- this is only needed for a few systems
+# BLINKFORSHARED is for the python executable -- defaults to LINKFORSHARED
+# LINKFORMODULE are the flags passed to the $(CC) command that links a
+# modules to be imported by the python interpreter of such an application.
+# BLINKFORMODULE is for modules built in this python's Modules/ directory.
+# Use ${} here if necessary, as these end up in python-config.sh too.
AC_MSG_CHECKING(LINKFORSHARED)
if test -z "$LINKFORSHARED"
then
case $ac_sys_system/$ac_sys_release in
- AIX*) LINKFORSHARED='-Wl,-bE:Modules/python.exp -lld';;
+ AIX*) BLINKFORSHARED='-Wl,-bE:Modules/python.exp -lld'
+ LINKFORSHARED='-Wl,-bE:${LIBPL}/python.exp -lld'
+ BLINKFORMODULE='-Wl,-bI:Modules/python.exp'
+ LINKFORMODULE='-Wl,-bI:${LIBPL}/python.exp';;
hp*|HP*)
LINKFORSHARED="-Wl,-E -Wl,+s";;
# LINKFORSHARED="-Wl,-E -Wl,+s -Wl,+b\$(BINLIBDEST)/lib-dynload";;
@@ -2193,6 +2204,9 @@
fi
AC_MSG_RESULT($LINKFORSHARED)
+test -n "${BLINKFORSHARED}" || BLINKFORSHARED="${LINKFORSHARED}"
+test -n "${LINKFORMODULE}" || LINKFORMODULE="${LINKFORSHARED}"
+test -n "${BLINKFORMODULE}" || BLINKFORMODULE="${LINKFORMODULE}"
AC_SUBST(CFLAGSFORSHARED)
AC_MSG_CHECKING(CFLAGSFORSHARED)
More information about the Python-Dev
mailing list