Skip to content

Commit 25ecc04

Browse files
authored
bpo-45573: Introduce extension module flags in Makefile (GH-29594)
``configure`` now uses a standardized format to forward state, compiler flags, and linker flags to ``Makefile``, ``setup.py``, and ``Modules/Setup``. ``makesetup`` use the new variables by default if a module line does not contain any compiler or linker flags. ``setup.py`` has a new function ``addext()``. For a module ``egg``, configure adds: * ``MODULE_EGG`` with value yes, missing, disabled, or n/a * ``MODULE_EGG_CFLAGS`` * ``MODULE_EGG_LDFLAGS`` ``Makefile.pre.in`` may also provide ``MODULE_EGG_DEPS`` that lists dependencies such as header files and static libs. Signed-off-by: Christian Heimes <christian@python.org>
1 parent fc4474e commit 25ecc04

File tree

8 files changed

+435
-103
lines changed

8 files changed

+435
-103
lines changed

Makefile.pre.in

+14-4
Original file line numberDiff line numberDiff line change
@@ -201,12 +201,26 @@ RUNSHARED= @RUNSHARED@
201201
# ensurepip options
202202
ENSUREPIP= @ENSUREPIP@
203203

204+
# Internal static libraries
205+
LIBMPDEC_A= Modules/_decimal/libmpdec/libmpdec.a
206+
LIBEXPAT_A= Modules/expat/libexpat.a
207+
204208
# OpenSSL options for setup.py so sysconfig can pick up AC_SUBST() vars.
205209
OPENSSL_INCLUDES=@OPENSSL_INCLUDES@
206210
OPENSSL_LIBS=@OPENSSL_LIBS@
207211
OPENSSL_LDFLAGS=@OPENSSL_LDFLAGS@
208212
OPENSSL_RPATH=@OPENSSL_RPATH@
209213

214+
# Module compiler and linker flags
215+
# yes: module is available
216+
# missing: build dependency is missing
217+
# disabled: module is disabled
218+
# n/a: module is not available on the current platform
219+
# MODULE_EGG=yes # yes, missing, disabled, n/a
220+
# MODULE_EGG_CFLAGS=
221+
# MODULE_EGG_LDFLAGS=
222+
@MODULE_BLOCK@
223+
210224
# Default zoneinfo.TZPATH. Added here to expose it in sysconfig.get_config_var
211225
TZPATH=@TZPATH@
212226

@@ -535,8 +549,6 @@ LIBMPDEC_HEADERS= \
535549
$(srcdir)/Modules/_decimal/libmpdec/typearith.h \
536550
$(srcdir)/Modules/_decimal/libmpdec/umodarith.h
537551

538-
LIBMPDEC_A= Modules/_decimal/libmpdec/libmpdec.a
539-
540552
##########################################################################
541553
# pyexpat's expat library
542554

@@ -562,8 +574,6 @@ LIBEXPAT_HEADERS= \
562574
Modules/expat/xmltok.h \
563575
Modules/expat/xmltok_impl.h
564576

565-
LIBEXPAT_A= Modules/expat/libexpat.a
566-
567577
#########################################################################
568578
# Rules
569579

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
``configure`` now uses a unified format to set state, compiler flags, and
2+
linker flags in Makefile. The new macro ``PY_STDLIB_MOD`` sets three
3+
variables that are consumed by ``Modules/Setup`` and ``setup.py``.

Modules/Setup

+12-3
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,15 @@
4242
# You can also use any Make variable that is detected by configure and
4343
# defined in Makefile.pre.in, e.g. OpenSSL flags $(OPENSSL_INCLUDES).
4444
#
45+
# Rules generated by makesetup use additional variables:
46+
#
47+
# - All source file rules have a dependency on $(PYTHON_HEADERS) and on
48+
# optional variable $(MODULES_{mod_upper}_DEPS).
49+
# - If no <cpparg> and no <library> arguments are given, then makesetup
50+
# defaults to $(MODULES_{mod_upper}_CFLAGS) cppargs and
51+
# $(MODULES_{mod_upper}_LDFLAGS) libraries. The variables are typically
52+
# defined by configure.
53+
#
4554
# The build process works like this:
4655
#
4756
# 1. Build all modules that are declared as static in Modules/Setup,
@@ -149,7 +158,7 @@ time timemodule.c
149158
#_contextvars _contextvarsmodule.c
150159
#_csv _csv.c
151160
#_datetime _datetimemodule.c
152-
#_decimal _decimal/_decimal.c $(DECIMAL_CFLAGS) $(DECIMAL_LDFLAGS)
161+
#_decimal _decimal/_decimal.c
153162
#_heapq _heapqmodule.c
154163
#_json _json.c
155164
#_lsprof _lsprof.c rotatingtree.c
@@ -172,8 +181,8 @@ time timemodule.c
172181
#select selectmodule.c
173182

174183
# XML
175-
#_elementtree _elementtree.c $(EXPAT_CFLAGS)
176-
#pyexpat pyexpat.c $(EXPAT_CFLAGS) $(EXPAT_LDFLAGS)
184+
#_elementtree _elementtree.c
185+
#pyexpat pyexpat.c
177186

178187
# hashing builtins
179188
#_blake2 _blake2/blake2module.c _blake2/blake2b_impl.c _blake2/blake2s_impl.c

Modules/makesetup

+8-2
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ sed -e 's/[ ]*#.*//' -e '/^[ ]*$/d' |
154154
cpps=
155155
libs=
156156
mods=
157+
mods_upper=
157158
skip=
158159
for arg in $line
159160
do
@@ -194,11 +195,17 @@ sed -e 's/[ ]*#.*//' -e '/^[ ]*$/d' |
194195
*.*) echo 1>&2 "bad word $arg in $line"
195196
exit 1;;
196197
-u) skip=libs; libs="$libs -u";;
197-
[a-zA-Z_]*) mods="$mods $arg";;
198+
[a-zA-Z_]*)
199+
mods="$mods $arg"
200+
mods_upper=$(echo $mods | tr '[a-z]' '[A-Z]');;
198201
*) echo 1>&2 "bad word $arg in $line"
199202
exit 1;;
200203
esac
201204
done
205+
if test -z "$cpps" -a -z "$libs"; then
206+
cpps="\$(MODULE_${mods_upper}_CFLAGS)"
207+
libs="\$(MODULE_${mods_upper}_LDFLAGS)"
208+
fi
202209
case $doconfig in
203210
yes)
204211
LIBS="$LIBS $libs"
@@ -245,7 +252,6 @@ sed -e 's/[ ]*#.*//' -e '/^[ ]*$/d' |
245252
*)
246253
cc="$cc \$(PY_BUILTIN_MODULE_CFLAGS)";;
247254
esac
248-
mods_upper=$(echo $mods | tr '[a-z]' '[A-Z]')
249255
# force rebuild when header file or module build flavor (static/shared) is changed
250256
rule="$obj: $src \$(MODULE_${mods_upper}_DEPS) \$(PYTHON_HEADERS) Modules/config.c; $cc $cpps -c $src -o $obj"
251257
echo "$rule" >>$rulesf

aclocal.m4

+50
Original file line numberDiff line numberDiff line change
@@ -619,3 +619,53 @@ AS_IF([test "$AS_TR_SH([with_]m4_tolower([$1]))" = "yes"],
619619
[AC_DEFINE([HAVE_][$1], 1, [Enable ]m4_tolower([$1])[ support])])
620620
])dnl PKG_HAVE_DEFINE_WITH_MODULES
621621

622+
# AM_CONDITIONAL -*- Autoconf -*-
623+
624+
# Copyright (C) 1997-2020 Free Software Foundation, Inc.
625+
#
626+
# This file is free software; the Free Software Foundation
627+
# gives unlimited permission to copy and/or distribute it,
628+
# with or without modifications, as long as this notice is preserved.
629+
630+
# AM_CONDITIONAL(NAME, SHELL-CONDITION)
631+
# -------------------------------------
632+
# Define a conditional.
633+
AC_DEFUN([AM_CONDITIONAL],
634+
[AC_PREREQ([2.52])dnl
635+
m4_if([$1], [TRUE], [AC_FATAL([$0: invalid condition: $1])],
636+
[$1], [FALSE], [AC_FATAL([$0: invalid condition: $1])])dnl
637+
AC_SUBST([$1_TRUE])dnl
638+
AC_SUBST([$1_FALSE])dnl
639+
_AM_SUBST_NOTMAKE([$1_TRUE])dnl
640+
_AM_SUBST_NOTMAKE([$1_FALSE])dnl
641+
m4_define([_AM_COND_VALUE_$1], [$2])dnl
642+
if $2; then
643+
$1_TRUE=
644+
$1_FALSE='#'
645+
else
646+
$1_TRUE='#'
647+
$1_FALSE=
648+
fi
649+
AC_CONFIG_COMMANDS_PRE(
650+
[if test -z "${$1_TRUE}" && test -z "${$1_FALSE}"; then
651+
AC_MSG_ERROR([[conditional "$1" was never defined.
652+
Usually this means the macro was only invoked conditionally.]])
653+
fi])])
654+
655+
# Copyright (C) 2006-2020 Free Software Foundation, Inc.
656+
#
657+
# This file is free software; the Free Software Foundation
658+
# gives unlimited permission to copy and/or distribute it,
659+
# with or without modifications, as long as this notice is preserved.
660+
661+
# _AM_SUBST_NOTMAKE(VARIABLE)
662+
# ---------------------------
663+
# Prevent Automake from outputting VARIABLE = @VARIABLE@ in Makefile.in.
664+
# This macro is traced by Automake.
665+
AC_DEFUN([_AM_SUBST_NOTMAKE])
666+
667+
# AM_SUBST_NOTMAKE(VARIABLE)
668+
# --------------------------
669+
# Public sister of _AM_SUBST_NOTMAKE.
670+
AC_DEFUN([AM_SUBST_NOTMAKE], [_AM_SUBST_NOTMAKE($@)])
671+

0 commit comments

Comments
 (0)