Skip to content

Commit 801bb0b

Browse files
authored
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.
1 parent 6a41775 commit 801bb0b

File tree

7 files changed

+113
-25
lines changed

7 files changed

+113
-25
lines changed

Doc/whatsnew/3.10.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -820,6 +820,12 @@ Build Changes
820820
821821
(Contributed by Victor Stinner in :issue:`42856`.)
822822
823+
* Add a new configure ``--without-static-libpython`` option to not build the
824+
``libpythonMAJOR.MINOR.a`` static library and not install the ``python.o``
825+
object file.
826+
827+
(Contributed by Victor Stinner in :issue:`43103`.)
828+
823829
824830
C API Changes
825831
=============

Makefile.pre.in

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,9 @@ PY3LIBRARY= @PY3LIBRARY@
236236
DLLLIBRARY= @DLLLIBRARY@
237237
LDLIBRARYDIR= @LDLIBRARYDIR@
238238
INSTSONAME= @INSTSONAME@
239+
LIBRARY_DEPS= @LIBRARY_DEPS@
240+
PY_ENABLE_SHARED= @PY_ENABLE_SHARED@
241+
STATIC_LIBPYTHON= @STATIC_LIBPYTHON@
239242

240243

241244
LIBS= @LIBS@
@@ -578,7 +581,7 @@ clinic: check-clean-src $(srcdir)/Modules/_blake2/blake2s_impl.c
578581
$(PYTHON_FOR_REGEN) $(srcdir)/Tools/clinic/clinic.py --make --srcdir $(srcdir)
579582

580583
# Build the interpreter
581-
$(BUILDPYTHON): Programs/python.o $(LIBRARY) $(LDLIBRARY) $(PY3LIBRARY) $(EXPORTSYMS)
584+
$(BUILDPYTHON): Programs/python.o $(LIBRARY_DEPS)
582585
$(LINKCC) $(PY_CORE_LDFLAGS) $(LINKFORSHARED) -o $@ Programs/python.o $(BLDLIBRARY) $(LIBS) $(MODLIBS) $(SYSLIBS)
583586

584587
platform: $(BUILDPYTHON) pybuilddir.txt
@@ -713,7 +716,7 @@ Makefile Modules/config.c: Makefile.pre \
713716
@echo "The Makefile was updated, you may need to re-run make."
714717

715718

716-
Programs/_testembed: Programs/_testembed.o $(LIBRARY) $(LDLIBRARY) $(PY3LIBRARY) $(EXPORTSYMS)
719+
Programs/_testembed: Programs/_testembed.o $(LIBRARY_DEPS)
717720
$(LINKCC) $(PY_CORE_LDFLAGS) $(LINKFORSHARED) -o $@ Programs/_testembed.o $(BLDLIBRARY) $(LIBS) $(MODLIBS) $(SYSLIBS)
718721

719722
############################################################################
@@ -1305,19 +1308,21 @@ altbininstall: $(BUILDPYTHON) @FRAMEWORKPYTHONW@
13051308
fi; \
13061309
(cd $(DESTDIR)$(BINDIR); $(LN) python$(LDVERSION)$(EXE) python$(VERSION)$(EXE)); \
13071310
fi
1308-
if test -f $(LDLIBRARY) && test "$(PYTHONFRAMEWORKDIR)" = "no-framework" ; then \
1309-
if test -n "$(DLLLIBRARY)" ; then \
1310-
$(INSTALL_SHARED) $(DLLLIBRARY) $(DESTDIR)$(BINDIR); \
1311-
else \
1312-
$(INSTALL_SHARED) $(LDLIBRARY) $(DESTDIR)$(LIBDIR)/$(INSTSONAME); \
1313-
if test $(LDLIBRARY) != $(INSTSONAME); then \
1314-
(cd $(DESTDIR)$(LIBDIR); $(LN) -sf $(INSTSONAME) $(LDLIBRARY)) \
1315-
fi \
1316-
fi; \
1317-
if test -n "$(PY3LIBRARY)"; then \
1318-
$(INSTALL_SHARED) $(PY3LIBRARY) $(DESTDIR)$(LIBDIR)/$(PY3LIBRARY); \
1311+
@if test "$(PY_ENABLE_SHARED)" = 1 -o "$(STATIC_LIBPYTHON)" = 1; then \
1312+
if test -f $(LDLIBRARY) && test "$(PYTHONFRAMEWORKDIR)" = "no-framework" ; then \
1313+
if test -n "$(DLLLIBRARY)" ; then \
1314+
$(INSTALL_SHARED) $(DLLLIBRARY) $(DESTDIR)$(BINDIR); \
1315+
else \
1316+
$(INSTALL_SHARED) $(LDLIBRARY) $(DESTDIR)$(LIBDIR)/$(INSTSONAME); \
1317+
if test $(LDLIBRARY) != $(INSTSONAME); then \
1318+
(cd $(DESTDIR)$(LIBDIR); $(LN) -sf $(INSTSONAME) $(LDLIBRARY)) \
1319+
fi \
1320+
fi; \
1321+
if test -n "$(PY3LIBRARY)"; then \
1322+
$(INSTALL_SHARED) $(PY3LIBRARY) $(DESTDIR)$(LIBDIR)/$(PY3LIBRARY); \
1323+
fi; \
1324+
else true; \
13191325
fi; \
1320-
else true; \
13211326
fi
13221327
if test "x$(LIPO_32BIT_FLAGS)" != "x" ; then \
13231328
rm -f $(DESTDIR)$(BINDIR)python$(VERSION)-32$(EXE); \
@@ -1661,19 +1666,21 @@ libainstall: @DEF_MAKE_RULE@ python-config
16611666
else true; \
16621667
fi; \
16631668
done
1664-
@if test -d $(LIBRARY); then :; else \
1665-
if test "$(PYTHONFRAMEWORKDIR)" = no-framework; then \
1666-
if test "$(SHLIB_SUFFIX)" = .dll; then \
1667-
$(INSTALL_DATA) $(LDLIBRARY) $(DESTDIR)$(LIBPL) ; \
1669+
@if test "$(STATIC_LIBPYTHON)" = 1; then \
1670+
if test -d $(LIBRARY); then :; else \
1671+
if test "$(PYTHONFRAMEWORKDIR)" = no-framework; then \
1672+
if test "$(SHLIB_SUFFIX)" = .dll; then \
1673+
$(INSTALL_DATA) $(LDLIBRARY) $(DESTDIR)$(LIBPL) ; \
1674+
else \
1675+
$(INSTALL_DATA) $(LIBRARY) $(DESTDIR)$(LIBPL)/$(LIBRARY) ; \
1676+
fi; \
16681677
else \
1669-
$(INSTALL_DATA) $(LIBRARY) $(DESTDIR)$(LIBPL)/$(LIBRARY) ; \
1678+
echo Skip install of $(LIBRARY) - use make frameworkinstall; \
16701679
fi; \
1671-
else \
1672-
echo Skip install of $(LIBRARY) - use make frameworkinstall; \
16731680
fi; \
1681+
$(INSTALL_DATA) Programs/python.o $(DESTDIR)$(LIBPL)/python.o; \
16741682
fi
16751683
$(INSTALL_DATA) Modules/config.c $(DESTDIR)$(LIBPL)/config.c
1676-
$(INSTALL_DATA) Programs/python.o $(DESTDIR)$(LIBPL)/python.o
16771684
$(INSTALL_DATA) $(srcdir)/Modules/config.c.in $(DESTDIR)$(LIBPL)/config.c.in
16781685
$(INSTALL_DATA) Makefile $(DESTDIR)$(LIBPL)/Makefile
16791686
$(INSTALL_DATA) $(srcdir)/Modules/Setup $(DESTDIR)$(LIBPL)/Setup
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Add a new configure ``--without-static-libpython`` option to not build the
2+
``libpythonMAJOR.MINOR.a`` static library and not install the ``python.o``
3+
object file.

Tools/scripts/smelly.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,11 +136,14 @@ def check_extensions():
136136

137137

138138
def main():
139+
nsymbol = 0
140+
139141
# static library
140142
LIBRARY = sysconfig.get_config_var('LIBRARY')
141143
if not LIBRARY:
142144
raise Exception("failed to get LIBRARY variable from sysconfig")
143-
nsymbol = check_library(LIBRARY)
145+
if os.path.exists(LIBRARY):
146+
nsymbol += check_library(LIBRARY)
144147

145148
# dynamic library
146149
LDLIBRARY = sysconfig.get_config_var('LDLIBRARY')

Tools/scripts/stable_abi.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22

33
import argparse
44
import glob
5-
import re
5+
import os.path
66
import pathlib
7+
import re
78
import subprocess
89
import sys
910
import sysconfig
@@ -213,7 +214,8 @@ def check_symbols(parser_args):
213214
LIBRARY = sysconfig.get_config_var("LIBRARY")
214215
if not LIBRARY:
215216
raise Exception("failed to get LIBRARY variable from sysconfig")
216-
check_library(parser_args.stable_abi_file, LIBRARY, abi_funcs)
217+
if os.path.exists(LIBRARY):
218+
check_library(parser_args.stable_abi_file, LIBRARY, abi_funcs)
217219

218220
# dynamic library
219221
LDLIBRARY = sysconfig.get_config_var("LDLIBRARY")

configure

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -624,6 +624,8 @@ ac_includes_default="\
624624

625625
ac_subst_vars='LTLIBOBJS
626626
TEST_MODULES
627+
LIBRARY_DEPS
628+
STATIC_LIBPYTHON
627629
OPENSSL_LDFLAGS
628630
OPENSSL_LIBS
629631
OPENSSL_INCLUDES
@@ -856,6 +858,7 @@ with_openssl
856858
with_ssl_default_suites
857859
with_builtin_hashlib_hashes
858860
with_experimental_isolated_subinterpreters
861+
with_static_libpython
859862
enable_test_modules
860863
'
861864
ac_precious_vars='build_alias
@@ -1602,6 +1605,9 @@ Optional Packages:
16021605
--with-experimental-isolated-subinterpreters
16031606
better isolate subinterpreters, experimental build
16041607
mode (default is no)
1608+
--without-static-libpython
1609+
do not build libpythonMAJOR.MINOR.a and do not
1610+
install python.o (default is yes)
16051611

16061612
Some influential environment variables:
16071613
MACHDEP name for machine-dependent library files
@@ -17776,6 +17782,40 @@ $as_echo "no" >&6; }
1777617782
fi
1777717783

1777817784

17785+
# --with-static-libpython
17786+
STATIC_LIBPYTHON=1
17787+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for --with-static-libpython" >&5
17788+
$as_echo_n "checking for --with-static-libpython... " >&6; }
17789+
17790+
# Check whether --with-static-libpython was given.
17791+
if test "${with_static_libpython+set}" = set; then :
17792+
withval=$with_static_libpython;
17793+
if test "$withval" = no
17794+
then
17795+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
17796+
$as_echo "no" >&6; };
17797+
STATIC_LIBPYTHON=0
17798+
else
17799+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
17800+
$as_echo "yes" >&6; };
17801+
fi
17802+
else
17803+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
17804+
$as_echo "yes" >&6; }
17805+
fi
17806+
17807+
LIBRARY_DEPS='$(PY3LIBRARY) $(EXPORTSYMS)'
17808+
if test "$PY_ENABLE_SHARED" = 1; then
17809+
LIBRARY_DEPS="\$(LDLIBRARY) $LIBRARY_DEPS"
17810+
if test "$STATIC_LIBPYTHON" = 1; then
17811+
LIBRARY_DEPS="\$(LIBRARY) $LIBRARY_DEPS"
17812+
fi
17813+
else
17814+
LIBRARY_DEPS="\$(LIBRARY) $LIBRARY_DEPS"
17815+
fi
17816+
17817+
17818+
1777917819
# Check whether to disable test modules. Once set, setup.py will not build
1778017820
# test extension modules and "make install" will not install test suites.
1778117821
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for --disable-test-modules" >&5

configure.ac

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5882,6 +5882,33 @@ else
58825882
fi],
58835883
[AC_MSG_RESULT(no)])
58845884

5885+
# --with-static-libpython
5886+
STATIC_LIBPYTHON=1
5887+
AC_MSG_CHECKING(for --with-static-libpython)
5888+
AC_ARG_WITH(static-libpython,
5889+
AS_HELP_STRING([--without-static-libpython],
5890+
[do not build libpythonMAJOR.MINOR.a and do not install python.o (default is yes)]),
5891+
[
5892+
if test "$withval" = no
5893+
then
5894+
AC_MSG_RESULT(no);
5895+
STATIC_LIBPYTHON=0
5896+
else
5897+
AC_MSG_RESULT(yes);
5898+
fi],
5899+
[AC_MSG_RESULT(yes)])
5900+
LIBRARY_DEPS='$(PY3LIBRARY) $(EXPORTSYMS)'
5901+
if test "$PY_ENABLE_SHARED" = 1; then
5902+
LIBRARY_DEPS="\$(LDLIBRARY) $LIBRARY_DEPS"
5903+
if test "$STATIC_LIBPYTHON" = 1; then
5904+
LIBRARY_DEPS="\$(LIBRARY) $LIBRARY_DEPS"
5905+
fi
5906+
else
5907+
LIBRARY_DEPS="\$(LIBRARY) $LIBRARY_DEPS"
5908+
fi
5909+
AC_SUBST(STATIC_LIBPYTHON)
5910+
AC_SUBST(LIBRARY_DEPS)
5911+
58855912
# Check whether to disable test modules. Once set, setup.py will not build
58865913
# test extension modules and "make install" will not install test suites.
58875914
AC_MSG_CHECKING(for --disable-test-modules)

0 commit comments

Comments
 (0)