From 801bb0b5035f8eeafe389dc082c02dfafaa07f6a Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Wed, 17 Feb 2021 11:14:42 +0100 Subject: bpo-43103: Add configure --without-static-libpython (GH-24418) Add a new configure --without-static-libpython option to not build the libpythonMAJOR.MINOR.a static library and not install the python.o object file. Fix smelly.py and stable_abi.py tools when libpython3.10.a is missing. --- Doc/whatsnew/3.10.rst | 6 +++ Makefile.pre.in | 51 ++++++++++++---------- .../Build/2021-02-02-16-26-44.bpo-43103.VWeyP_.rst | 3 ++ Tools/scripts/smelly.py | 5 ++- Tools/scripts/stable_abi.py | 6 ++- configure | 40 +++++++++++++++++ configure.ac | 27 ++++++++++++ 7 files changed, 113 insertions(+), 25 deletions(-) create mode 100644 Misc/NEWS.d/next/Build/2021-02-02-16-26-44.bpo-43103.VWeyP_.rst diff --git a/Doc/whatsnew/3.10.rst b/Doc/whatsnew/3.10.rst index c282edc..0fba27c 100644 --- a/Doc/whatsnew/3.10.rst +++ b/Doc/whatsnew/3.10.rst @@ -820,6 +820,12 @@ Build Changes (Contributed by Victor Stinner in :issue:`42856`.) +* Add a new configure ``--without-static-libpython`` option to not build the + ``libpythonMAJOR.MINOR.a`` static library and not install the ``python.o`` + object file. + + (Contributed by Victor Stinner in :issue:`43103`.) + C API Changes ============= diff --git a/Makefile.pre.in b/Makefile.pre.in index 0d9fdc7..d3ac2da 100644 --- a/Makefile.pre.in +++ b/Makefile.pre.in @@ -236,6 +236,9 @@ PY3LIBRARY= @PY3LIBRARY@ DLLLIBRARY= @DLLLIBRARY@ LDLIBRARYDIR= @LDLIBRARYDIR@ INSTSONAME= @INSTSONAME@ +LIBRARY_DEPS= @LIBRARY_DEPS@ +PY_ENABLE_SHARED= @PY_ENABLE_SHARED@ +STATIC_LIBPYTHON= @STATIC_LIBPYTHON@ LIBS= @LIBS@ @@ -578,7 +581,7 @@ clinic: check-clean-src $(srcdir)/Modules/_blake2/blake2s_impl.c $(PYTHON_FOR_REGEN) $(srcdir)/Tools/clinic/clinic.py --make --srcdir $(srcdir) # Build the interpreter -$(BUILDPYTHON): Programs/python.o $(LIBRARY) $(LDLIBRARY) $(PY3LIBRARY) $(EXPORTSYMS) +$(BUILDPYTHON): Programs/python.o $(LIBRARY_DEPS) $(LINKCC) $(PY_CORE_LDFLAGS) $(LINKFORSHARED) -o $@ Programs/python.o $(BLDLIBRARY) $(LIBS) $(MODLIBS) $(SYSLIBS) platform: $(BUILDPYTHON) pybuilddir.txt @@ -713,7 +716,7 @@ Makefile Modules/config.c: Makefile.pre \ @echo "The Makefile was updated, you may need to re-run make." -Programs/_testembed: Programs/_testembed.o $(LIBRARY) $(LDLIBRARY) $(PY3LIBRARY) $(EXPORTSYMS) +Programs/_testembed: Programs/_testembed.o $(LIBRARY_DEPS) $(LINKCC) $(PY_CORE_LDFLAGS) $(LINKFORSHARED) -o $@ Programs/_testembed.o $(BLDLIBRARY) $(LIBS) $(MODLIBS) $(SYSLIBS) ############################################################################ @@ -1305,19 +1308,21 @@ altbininstall: $(BUILDPYTHON) @FRAMEWORKPYTHONW@ fi; \ (cd $(DESTDIR)$(BINDIR); $(LN) python$(LDVERSION)$(EXE) python$(VERSION)$(EXE)); \ fi - if test -f $(LDLIBRARY) && test "$(PYTHONFRAMEWORKDIR)" = "no-framework" ; then \ - if test -n "$(DLLLIBRARY)" ; then \ - $(INSTALL_SHARED) $(DLLLIBRARY) $(DESTDIR)$(BINDIR); \ - else \ - $(INSTALL_SHARED) $(LDLIBRARY) $(DESTDIR)$(LIBDIR)/$(INSTSONAME); \ - if test $(LDLIBRARY) != $(INSTSONAME); then \ - (cd $(DESTDIR)$(LIBDIR); $(LN) -sf $(INSTSONAME) $(LDLIBRARY)) \ - fi \ - fi; \ - if test -n "$(PY3LIBRARY)"; then \ - $(INSTALL_SHARED) $(PY3LIBRARY) $(DESTDIR)$(LIBDIR)/$(PY3LIBRARY); \ + @if test "$(PY_ENABLE_SHARED)" = 1 -o "$(STATIC_LIBPYTHON)" = 1; then \ + if test -f $(LDLIBRARY) && test "$(PYTHONFRAMEWORKDIR)" = "no-framework" ; then \ + if test -n "$(DLLLIBRARY)" ; then \ + $(INSTALL_SHARED) $(DLLLIBRARY) $(DESTDIR)$(BINDIR); \ + else \ + $(INSTALL_SHARED) $(LDLIBRARY) $(DESTDIR)$(LIBDIR)/$(INSTSONAME); \ + if test $(LDLIBRARY) != $(INSTSONAME); then \ + (cd $(DESTDIR)$(LIBDIR); $(LN) -sf $(INSTSONAME) $(LDLIBRARY)) \ + fi \ + fi; \ + if test -n "$(PY3LIBRARY)"; then \ + $(INSTALL_SHARED) $(PY3LIBRARY) $(DESTDIR)$(LIBDIR)/$(PY3LIBRARY); \ + fi; \ + else true; \ fi; \ - else true; \ fi if test "x$(LIPO_32BIT_FLAGS)" != "x" ; then \ rm -f $(DESTDIR)$(BINDIR)python$(VERSION)-32$(EXE); \ @@ -1661,19 +1666,21 @@ libainstall: @DEF_MAKE_RULE@ python-config else true; \ fi; \ done - @if test -d $(LIBRARY); then :; else \ - if test "$(PYTHONFRAMEWORKDIR)" = no-framework; then \ - if test "$(SHLIB_SUFFIX)" = .dll; then \ - $(INSTALL_DATA) $(LDLIBRARY) $(DESTDIR)$(LIBPL) ; \ + @if test "$(STATIC_LIBPYTHON)" = 1; then \ + if test -d $(LIBRARY); then :; else \ + if test "$(PYTHONFRAMEWORKDIR)" = no-framework; then \ + if test "$(SHLIB_SUFFIX)" = .dll; then \ + $(INSTALL_DATA) $(LDLIBRARY) $(DESTDIR)$(LIBPL) ; \ + else \ + $(INSTALL_DATA) $(LIBRARY) $(DESTDIR)$(LIBPL)/$(LIBRARY) ; \ + fi; \ else \ - $(INSTALL_DATA) $(LIBRARY) $(DESTDIR)$(LIBPL)/$(LIBRARY) ; \ + echo Skip install of $(LIBRARY) - use make frameworkinstall; \ fi; \ - else \ - echo Skip install of $(LIBRARY) - use make frameworkinstall; \ fi; \ + $(INSTALL_DATA) Programs/python.o $(DESTDIR)$(LIBPL)/python.o; \ fi $(INSTALL_DATA) Modules/config.c $(DESTDIR)$(LIBPL)/config.c - $(INSTALL_DATA) Programs/python.o $(DESTDIR)$(LIBPL)/python.o $(INSTALL_DATA) $(srcdir)/Modules/config.c.in $(DESTDIR)$(LIBPL)/config.c.in $(INSTALL_DATA) Makefile $(DESTDIR)$(LIBPL)/Makefile $(INSTALL_DATA) $(srcdir)/Modules/Setup $(DESTDIR)$(LIBPL)/Setup diff --git a/Misc/NEWS.d/next/Build/2021-02-02-16-26-44.bpo-43103.VWeyP_.rst b/Misc/NEWS.d/next/Build/2021-02-02-16-26-44.bpo-43103.VWeyP_.rst new file mode 100644 index 0000000..edf04c1 --- /dev/null +++ b/Misc/NEWS.d/next/Build/2021-02-02-16-26-44.bpo-43103.VWeyP_.rst @@ -0,0 +1,3 @@ +Add a new configure ``--without-static-libpython`` option to not build the +``libpythonMAJOR.MINOR.a`` static library and not install the ``python.o`` +object file. diff --git a/Tools/scripts/smelly.py b/Tools/scripts/smelly.py index e8a375c..fb01660 100755 --- a/Tools/scripts/smelly.py +++ b/Tools/scripts/smelly.py @@ -136,11 +136,14 @@ def check_extensions(): def main(): + nsymbol = 0 + # static library LIBRARY = sysconfig.get_config_var('LIBRARY') if not LIBRARY: raise Exception("failed to get LIBRARY variable from sysconfig") - nsymbol = check_library(LIBRARY) + if os.path.exists(LIBRARY): + nsymbol += check_library(LIBRARY) # dynamic library LDLIBRARY = sysconfig.get_config_var('LDLIBRARY') diff --git a/Tools/scripts/stable_abi.py b/Tools/scripts/stable_abi.py index 47547a9..117dfeb 100755 --- a/Tools/scripts/stable_abi.py +++ b/Tools/scripts/stable_abi.py @@ -2,8 +2,9 @@ import argparse import glob -import re +import os.path import pathlib +import re import subprocess import sys import sysconfig @@ -213,7 +214,8 @@ def check_symbols(parser_args): LIBRARY = sysconfig.get_config_var("LIBRARY") if not LIBRARY: raise Exception("failed to get LIBRARY variable from sysconfig") - check_library(parser_args.stable_abi_file, LIBRARY, abi_funcs) + if os.path.exists(LIBRARY): + check_library(parser_args.stable_abi_file, LIBRARY, abi_funcs) # dynamic library LDLIBRARY = sysconfig.get_config_var("LDLIBRARY") diff --git a/configure b/configure index 8e0cc71..8c94825 100755 --- a/configure +++ b/configure @@ -624,6 +624,8 @@ ac_includes_default="\ ac_subst_vars='LTLIBOBJS TEST_MODULES +LIBRARY_DEPS +STATIC_LIBPYTHON OPENSSL_LDFLAGS OPENSSL_LIBS OPENSSL_INCLUDES @@ -856,6 +858,7 @@ with_openssl with_ssl_default_suites with_builtin_hashlib_hashes with_experimental_isolated_subinterpreters +with_static_libpython enable_test_modules ' ac_precious_vars='build_alias @@ -1602,6 +1605,9 @@ Optional Packages: --with-experimental-isolated-subinterpreters better isolate subinterpreters, experimental build mode (default is no) + --without-static-libpython + do not build libpythonMAJOR.MINOR.a and do not + install python.o (default is yes) Some influential environment variables: MACHDEP name for machine-dependent library files @@ -17776,6 +17782,40 @@ $as_echo "no" >&6; } fi +# --with-static-libpython +STATIC_LIBPYTHON=1 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for --with-static-libpython" >&5 +$as_echo_n "checking for --with-static-libpython... " >&6; } + +# Check whether --with-static-libpython was given. +if test "${with_static_libpython+set}" = set; then : + withval=$with_static_libpython; +if test "$withval" = no +then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; }; + STATIC_LIBPYTHON=0 +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; }; +fi +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } +fi + +LIBRARY_DEPS='$(PY3LIBRARY) $(EXPORTSYMS)' +if test "$PY_ENABLE_SHARED" = 1; then + LIBRARY_DEPS="\$(LDLIBRARY) $LIBRARY_DEPS" + if test "$STATIC_LIBPYTHON" = 1; then + LIBRARY_DEPS="\$(LIBRARY) $LIBRARY_DEPS" + fi +else + LIBRARY_DEPS="\$(LIBRARY) $LIBRARY_DEPS" +fi + + + # Check whether to disable test modules. Once set, setup.py will not build # test extension modules and "make install" will not install test suites. { $as_echo "$as_me:${as_lineno-$LINENO}: checking for --disable-test-modules" >&5 diff --git a/configure.ac b/configure.ac index 60c5d8e..2995793 100644 --- a/configure.ac +++ b/configure.ac @@ -5882,6 +5882,33 @@ else fi], [AC_MSG_RESULT(no)]) +# --with-static-libpython +STATIC_LIBPYTHON=1 +AC_MSG_CHECKING(for --with-static-libpython) +AC_ARG_WITH(static-libpython, + AS_HELP_STRING([--without-static-libpython], + [do not build libpythonMAJOR.MINOR.a and do not install python.o (default is yes)]), +[ +if test "$withval" = no +then + AC_MSG_RESULT(no); + STATIC_LIBPYTHON=0 +else + AC_MSG_RESULT(yes); +fi], +[AC_MSG_RESULT(yes)]) +LIBRARY_DEPS='$(PY3LIBRARY) $(EXPORTSYMS)' +if test "$PY_ENABLE_SHARED" = 1; then + LIBRARY_DEPS="\$(LDLIBRARY) $LIBRARY_DEPS" + if test "$STATIC_LIBPYTHON" = 1; then + LIBRARY_DEPS="\$(LIBRARY) $LIBRARY_DEPS" + fi +else + LIBRARY_DEPS="\$(LIBRARY) $LIBRARY_DEPS" +fi +AC_SUBST(STATIC_LIBPYTHON) +AC_SUBST(LIBRARY_DEPS) + # Check whether to disable test modules. Once set, setup.py will not build # test extension modules and "make install" will not install test suites. AC_MSG_CHECKING(for --disable-test-modules) -- cgit v0.12