diff options
author | Victor Stinner <vstinner@redhat.com> | 2019-05-23 03:30:23 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-05-23 03:30:23 +0200 |
commit | 0a8e57248b913851640c64375600f05157c997df (patch) | |
tree | 79352007eef8deb7530c38d460554183e6c960a2 /Misc | |
parent | ef5bb25e2d6147cd44be9c9b166525fb30485be0 (diff) | |
download | cpython-git-0a8e57248b913851640c64375600f05157c997df.tar.gz |
bpo-36721: Add --embed option to python-config (GH-13500)
To embed Python into an application, a new --embed option must be
passed to "python3-config --libs --embed" to get "-lpython3.8" (link
the application to libpython). To support both 3.8 and older, try
"python3-config --libs --embed" first and fallback to "python3-config
--libs" (without --embed) if the previous command fails.
Add a pkg-config "python-3.8-embed" module to embed Python into an
application: "pkg-config python-3.8-embed --libs" includes
"-lpython3.8". To support both 3.8 and older, try "pkg-config
python-X.Y-embed --libs" first and fallback to "pkg-config python-X.Y
--libs" (without --embed) if the previous command fails (replace
"X.Y" with the Python version).
On the other hand, "pkg-config python3.8 --libs" no longer contains
"-lpython3.8". C extensions must not be linked to libpython (except
on Android, case handled by the script); this change is backward
incompatible on purpose.
"make install" now also installs "python-3.8-embed.pc".
Diffstat (limited to 'Misc')
-rw-r--r-- | Misc/NEWS.d/next/Build/2019-05-22-16-19-18.bpo-36721.9aRwfZ.rst | 16 | ||||
-rw-r--r-- | Misc/python-config.in | 12 | ||||
-rw-r--r-- | Misc/python-config.sh.in | 9 | ||||
-rw-r--r-- | Misc/python-embed.pc.in | 13 | ||||
-rw-r--r-- | Misc/python.pc.in | 6 |
5 files changed, 50 insertions, 6 deletions
diff --git a/Misc/NEWS.d/next/Build/2019-05-22-16-19-18.bpo-36721.9aRwfZ.rst b/Misc/NEWS.d/next/Build/2019-05-22-16-19-18.bpo-36721.9aRwfZ.rst new file mode 100644 index 0000000000..1c266586a3 --- /dev/null +++ b/Misc/NEWS.d/next/Build/2019-05-22-16-19-18.bpo-36721.9aRwfZ.rst @@ -0,0 +1,16 @@ +To embed Python into an application, a new ``--embed`` option must be passed to +``python3-config --libs --embed`` to get ``-lpython3.8`` (link the application +to libpython). To support both 3.8 and older, try ``python3-config --libs +--embed`` first and fallback to ``python3-config --libs`` (without ``--embed``) +if the previous command fails. + +Add a pkg-config ``python-3.8-embed`` module to embed Python into an +application: ``pkg-config python-3.8-embed --libs`` includes ``-lpython3.8``. +To support both 3.8 and older, try ``pkg-config python-X.Y-embed --libs`` first +and fallback to ``pkg-config python-X.Y --libs`` (without ``--embed``) if the +previous command fails (replace ``X.Y`` with the Python version). + +On the other hand, ``pkg-config python3.8 --libs`` no longer contains +``-lpython3.8``. C extensions must not be linked to libpython (except on +Android, case handled by the script); this change is backward incompatible on +purpose. diff --git a/Misc/python-config.in b/Misc/python-config.in index 1df30d261d..727c4a8682 100644 --- a/Misc/python-config.in +++ b/Misc/python-config.in @@ -9,7 +9,8 @@ import sys import sysconfig valid_opts = ['prefix', 'exec-prefix', 'includes', 'libs', 'cflags', - 'ldflags', 'extension-suffix', 'help', 'abiflags', 'configdir'] + 'ldflags', 'extension-suffix', 'help', 'abiflags', 'configdir', + 'embed'] def exit_with_usage(code=1): print("Usage: {0} [{1}]".format( @@ -47,8 +48,13 @@ for opt in opt_flags: print(' '.join(flags)) elif opt in ('--libs', '--ldflags'): - libpython = getvar('LIBPYTHON') - libs = [libpython] if libpython else [] + libs = [] + if '--embed' in opt_flags: + libs.append('-lpython' + pyver + sys.abiflags) + else: + libpython = getvar('LIBPYTHON') + if libpython: + libs.append(libpython) libs.extend(getvar('LIBS').split() + getvar('SYSLIBS').split()) # add the prefix/lib/pythonX.Y/config dir, but only if there is no diff --git a/Misc/python-config.sh.in b/Misc/python-config.sh.in index 33991ef0c5..59101d5a55 100644 --- a/Misc/python-config.sh.in +++ b/Misc/python-config.sh.in @@ -42,6 +42,7 @@ LIBC="@LIBC@" SYSLIBS="$LIBM $LIBC" ABIFLAGS="@ABIFLAGS@" LIBS="@LIBPYTHON@ @LIBS@ $SYSLIBS" +LIBS_EMBED="-lpython${VERSION}${ABIFLAGS} @LIBS@ $SYSLIBS" BASECFLAGS="@BASECFLAGS@" LDLIBRARY="@LDLIBRARY@" OPT="@OPT@" @@ -53,6 +54,7 @@ SO="@EXT_SUFFIX@" PYTHONFRAMEWORK="@PYTHONFRAMEWORK@" INCDIR="-I$includedir/python${VERSION}${ABIFLAGS}" PLATINCDIR="-I$includedir/python${VERSION}${ABIFLAGS}" +PY_EMBED=0 # Scan for --help or unknown argument. for ARG in $* @@ -61,6 +63,9 @@ do --help) exit_with_usage 0 ;; + --embed) + PY_EMBED=1 + ;; --prefix|--exec-prefix|--includes|--libs|--cflags|--ldflags|--extension-suffix|--abiflags|--configdir) ;; *) @@ -69,6 +74,10 @@ do esac done +if [ $PY_EMBED = 1 ] ; then + LIBS="$LIBS_EMBED" +fi + for ARG in "$@" do case "$ARG" in diff --git a/Misc/python-embed.pc.in b/Misc/python-embed.pc.in new file mode 100644 index 0000000000..2be9df8143 --- /dev/null +++ b/Misc/python-embed.pc.in @@ -0,0 +1,13 @@ +# See: man pkg-config +prefix=@prefix@ +exec_prefix=@exec_prefix@ +libdir=@libdir@ +includedir=@includedir@ + +Name: Python +Description: Embed Python into an application +Requires: +Version: @VERSION@ +Libs.private: @LIBS@ +Libs: -L${libdir} -lpython@VERSION@@ABIFLAGS@ +Cflags: -I${includedir}/python@VERSION@@ABIFLAGS@ diff --git a/Misc/python.pc.in b/Misc/python.pc.in index ae698674bb..87e04decc2 100644 --- a/Misc/python.pc.in +++ b/Misc/python.pc.in @@ -5,9 +5,9 @@ libdir=@libdir@ includedir=@includedir@ Name: Python -Description: Python library -Requires: +Description: Build a C extension for Python +Requires: Version: @VERSION@ Libs.private: @LIBS@ -Libs: -L${libdir} -lpython@VERSION@@ABIFLAGS@ +Libs: Cflags: -I${includedir}/python@VERSION@@ABIFLAGS@ |