Skip to content

bpo-43103: Add configure --without-static-libpython #24418

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Doc/whatsnew/3.10.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
=============
Expand Down
51 changes: 29 additions & 22 deletions Makefile.pre.in
Original file line number Diff line number Diff line change
Expand Up @@ -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@
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)

############################################################################
Expand Down Expand Up @@ -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); \
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
5 changes: 4 additions & 1 deletion Tools/scripts/smelly.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
6 changes: 4 additions & 2 deletions Tools/scripts/stable_abi.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

import argparse
import glob
import re
import os.path
import pathlib
import re
import subprocess
import sys
import sysconfig
Expand Down Expand Up @@ -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")
Expand Down
40 changes: 40 additions & 0 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,8 @@ ac_includes_default="\

ac_subst_vars='LTLIBOBJS
TEST_MODULES
LIBRARY_DEPS
STATIC_LIBPYTHON
OPENSSL_LDFLAGS
OPENSSL_LIBS
OPENSSL_INCLUDES
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
27 changes: 27 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down