Issue #9189: Allow users to set $CFLAGS, $CPPFLAGS, and $LDFLAGS when running
configure to append to Python's default values for those variables, and similarly allow users to set $XXFLAGS on the make command line to append to the values set by configure. In the makefile, this renames the variables that used to be $XXFLAGS to $PY_XXFLAGS, and renames the old $PY_CFLAGS to $PY_CORE_CFLAGS. To compensate, sysconfig now aliases $XXFLAGS=$PY_XXFLAGS so that scripts using it keep working. I see that as the right interface, not a backward-compatibility hack, since these are logically the $XXFLAGS variables; we just use a different name in the makefile to deal with make's semantics.
This commit is contained in:
parent
74e4561a3c
commit
d4fcdb1ea8
|
@ -259,6 +259,11 @@ def _parse_makefile(filename, vars=None):
|
|||
# bogus variable reference; just drop it since we can't deal
|
||||
variables.remove(name)
|
||||
|
||||
# Add in CFLAGS, LDFLAGS, and CPPFLAGS, which are named with a
|
||||
# prefix in the Makefile.
|
||||
for var in ('CFLAGS', 'LDFLAGS', 'CPPFLAGS'):
|
||||
done[var] = done['PY_' + var]
|
||||
|
||||
# save the results in the global dictionary
|
||||
vars.update(done)
|
||||
return vars
|
||||
|
|
|
@ -59,12 +59,18 @@ MAKESETUP= $(srcdir)/Modules/makesetup
|
|||
# Compiler options
|
||||
OPT= @OPT@
|
||||
BASECFLAGS= @BASECFLAGS@
|
||||
CFLAGS= $(BASECFLAGS) @CFLAGS@ $(OPT) $(EXTRA_CFLAGS)
|
||||
CONFIGURE_CFLAGS= @CFLAGS@
|
||||
CONFIGURE_CPPFLAGS= @CPPFLAGS@
|
||||
CONFIGURE_LDFLAGS= @LDFLAGS@
|
||||
# Avoid assigning CFLAGS, LDFLAGS, etc. so users can use them on the
|
||||
# command line to append to these values without stomping the pre-set
|
||||
# values.
|
||||
PY_CFLAGS= $(BASECFLAGS) $(OPT) $(CONFIGURE_CFLAGS) $(CFLAGS) $(EXTRA_CFLAGS)
|
||||
# Both CPPFLAGS and LDFLAGS need to contain the shell's value for setup.py to
|
||||
# be able to build extension modules using the directories specified in the
|
||||
# environment variables
|
||||
CPPFLAGS= -I. -IInclude -I$(srcdir)/Include @CPPFLAGS@
|
||||
LDFLAGS= @LDFLAGS@
|
||||
PY_CPPFLAGS= -I. -IInclude -I$(srcdir)/Include $(CONFIGURE_CPPFLAGS) $(CPPFLAGS)
|
||||
PY_LDFLAGS= $(CONFIGURE_LDFLAGS) $(LDFLAGS)
|
||||
LDLAST= @LDLAST@
|
||||
SGI_ABI= @SGI_ABI@
|
||||
CCSHARED= @CCSHARED@
|
||||
|
@ -73,7 +79,7 @@ ARFLAGS= @ARFLAGS@
|
|||
# Extra C flags added for building the interpreter object files.
|
||||
CFLAGSFORSHARED=@CFLAGSFORSHARED@
|
||||
# C flags used for building the interpreter object files
|
||||
PY_CFLAGS= $(CFLAGS) $(CPPFLAGS) $(CFLAGSFORSHARED) -DPy_BUILD_CORE
|
||||
PY_CORE_CFLAGS= $(PY_CFLAGS) $(PY_CPPFLAGS) $(CFLAGSFORSHARED) -DPy_BUILD_CORE
|
||||
|
||||
|
||||
# Machine-dependent subdirectories
|
||||
|
@ -411,7 +417,7 @@ coverage:
|
|||
|
||||
# Build the interpreter
|
||||
$(BUILDPYTHON): Modules/python.o $(LIBRARY) $(LDLIBRARY)
|
||||
$(LINKCC) $(LDFLAGS) $(LINKFORSHARED) -o $@ \
|
||||
$(LINKCC) $(PY_LDFLAGS) $(LINKFORSHARED) -o $@ \
|
||||
Modules/python.o \
|
||||
$(BLDLIBRARY) $(LIBS) $(MODLIBS) $(SYSLIBS) $(LDLAST)
|
||||
|
||||
|
@ -422,8 +428,8 @@ platform: $(BUILDPYTHON)
|
|||
# Build the shared modules
|
||||
sharedmods: $(BUILDPYTHON)
|
||||
@case $$MAKEFLAGS in \
|
||||
*s*) $(RUNSHARED) CC='$(CC)' LDSHARED='$(BLDSHARED)' LDFLAGS='$(LDFLAGS)' OPT='$(OPT)' ./$(BUILDPYTHON) -E $(srcdir)/setup.py -q build;; \
|
||||
*) $(RUNSHARED) CC='$(CC)' LDSHARED='$(BLDSHARED)' LDFLAGS='$(LDFLAGS)' OPT='$(OPT)' ./$(BUILDPYTHON) -E $(srcdir)/setup.py build;; \
|
||||
*s*) $(RUNSHARED) CC='$(CC)' LDSHARED='$(BLDSHARED)' LDFLAGS='$(PY_LDFLAGS)' OPT='$(OPT)' ./$(BUILDPYTHON) -E $(srcdir)/setup.py -q build;; \
|
||||
*) $(RUNSHARED) CC='$(CC)' LDSHARED='$(BLDSHARED)' LDFLAGS='$(PY_LDFLAGS)' OPT='$(OPT)' ./$(BUILDPYTHON) -E $(srcdir)/setup.py build;; \
|
||||
esac
|
||||
|
||||
# Build static library
|
||||
|
@ -440,18 +446,18 @@ $(LIBRARY): $(LIBRARY_OBJS)
|
|||
|
||||
libpython$(VERSION).so: $(LIBRARY_OBJS)
|
||||
if test $(INSTSONAME) != $(LDLIBRARY); then \
|
||||
$(LDSHARED) $(LDFLAGS) -Wl,-h$(INSTSONAME) -o $(INSTSONAME) $(LIBRARY_OBJS) $(MODLIBS) $(SHLIBS) $(LIBC) $(LIBM) $(LDLAST); \
|
||||
$(LDSHARED) $(PY_LDFLAGS) -Wl,-h$(INSTSONAME) -o $(INSTSONAME) $(LIBRARY_OBJS) $(MODLIBS) $(SHLIBS) $(LIBC) $(LIBM) $(LDLAST); \
|
||||
$(LN) -f $(INSTSONAME) $@; \
|
||||
else \
|
||||
$(LDSHARED) $(LDFLAGS) -o $@ $(LIBRARY_OBJS) $(MODLIBS) $(SHLIBS) $(LIBC) $(LIBM) $(LDLAST); \
|
||||
$(LDSHARED) $(PY_LDFLAGS) -o $@ $(LIBRARY_OBJS) $(MODLIBS) $(SHLIBS) $(LIBC) $(LIBM) $(LDLAST); \
|
||||
fi
|
||||
|
||||
libpython$(VERSION).dylib: $(LIBRARY_OBJS)
|
||||
$(CC) -dynamiclib -Wl,-single_module $(LDFLAGS) -undefined dynamic_lookup -Wl,-install_name,$(prefix)/lib/libpython$(VERSION).dylib -Wl,-compatibility_version,$(VERSION) -Wl,-current_version,$(VERSION) -o $@ $(LIBRARY_OBJS) $(SHLIBS) $(LIBC) $(LIBM) $(LDLAST); \
|
||||
$(CC) -dynamiclib -Wl,-single_module $(PY_LDFLAGS) -undefined dynamic_lookup -Wl,-install_name,$(prefix)/lib/libpython$(VERSION).dylib -Wl,-compatibility_version,$(VERSION) -Wl,-current_version,$(VERSION) -o $@ $(LIBRARY_OBJS) $(SHLIBS) $(LIBC) $(LIBM) $(LDLAST); \
|
||||
|
||||
|
||||
libpython$(VERSION).sl: $(LIBRARY_OBJS)
|
||||
$(LDSHARED) $(LDFLAGS) -o $@ $(LIBRARY_OBJS) $(MODLIBS) $(SHLIBS) $(LIBC) $(LIBM) $(LDLAST)
|
||||
$(LDSHARED) $(PY_LDFLAGS) -o $@ $(LIBRARY_OBJS) $(MODLIBS) $(SHLIBS) $(LIBC) $(LIBM) $(LDLAST)
|
||||
|
||||
# Copy up the gdb python hooks into a position where they can be automatically
|
||||
# loaded by gdb during Lib/test/test_gdb.py
|
||||
|
@ -497,7 +503,7 @@ $(PYTHONFRAMEWORKDIR)/Versions/$(VERSION)/$(PYTHONFRAMEWORK): \
|
|||
# for a shared core library; otherwise, this rule is a noop.
|
||||
$(DLLLIBRARY) libpython$(VERSION).dll.a: $(LIBRARY_OBJS)
|
||||
if test -n "$(DLLLIBRARY)"; then \
|
||||
$(LDSHARED) $(LDFLAGS) -Wl,--out-implib=$@ -o $(DLLLIBRARY) $^ \
|
||||
$(LDSHARED) $(PY_LDFLAGS) -Wl,--out-implib=$@ -o $(DLLLIBRARY) $^ \
|
||||
$(LIBS) $(MODLIBS) $(SYSLIBS) $(LDLAST); \
|
||||
else true; \
|
||||
fi
|
||||
|
@ -541,10 +547,10 @@ Modules/getbuildinfo.o: $(PARSER_OBJS) \
|
|||
$(SIGNAL_OBJS) \
|
||||
$(MODOBJS) \
|
||||
$(srcdir)/Modules/getbuildinfo.c
|
||||
$(CC) -c $(PY_CFLAGS) -DSVNVERSION="\"`LC_ALL=C $(SVNVERSION)`\"" -o $@ $(srcdir)/Modules/getbuildinfo.c
|
||||
$(CC) -c $(PY_CORE_CFLAGS) -DSVNVERSION="\"`LC_ALL=C $(SVNVERSION)`\"" -o $@ $(srcdir)/Modules/getbuildinfo.c
|
||||
|
||||
Modules/getpath.o: $(srcdir)/Modules/getpath.c Makefile
|
||||
$(CC) -c $(PY_CFLAGS) -DPYTHONPATH='"$(PYTHONPATH)"' \
|
||||
$(CC) -c $(PY_CORE_CFLAGS) -DPYTHONPATH='"$(PYTHONPATH)"' \
|
||||
-DPREFIX='"$(prefix)"' \
|
||||
-DEXEC_PREFIX='"$(exec_prefix)"' \
|
||||
-DVERSION='"$(VERSION)"' \
|
||||
|
@ -552,7 +558,7 @@ Modules/getpath.o: $(srcdir)/Modules/getpath.c Makefile
|
|||
-o $@ $(srcdir)/Modules/getpath.c
|
||||
|
||||
Modules/python.o: $(srcdir)/Modules/python.c
|
||||
$(MAINCC) -c $(PY_CFLAGS) -o $@ $(srcdir)/Modules/python.c
|
||||
$(MAINCC) -c $(PY_CORE_CFLAGS) -o $@ $(srcdir)/Modules/python.c
|
||||
|
||||
$(IO_OBJS): $(IO_H)
|
||||
|
||||
|
@ -561,7 +567,7 @@ $(GRAMMAR_H) $(GRAMMAR_C): $(PGEN) $(GRAMMAR_INPUT)
|
|||
-$(PGEN) $(GRAMMAR_INPUT) $(GRAMMAR_H) $(GRAMMAR_C)
|
||||
|
||||
$(PGEN): $(PGENOBJS)
|
||||
$(CC) $(OPT) $(LDFLAGS) $(PGENOBJS) $(LIBS) -o $(PGEN)
|
||||
$(CC) $(OPT) $(PY_LDFLAGS) $(PGENOBJS) $(LIBS) -o $(PGEN)
|
||||
|
||||
Parser/grammar.o: $(srcdir)/Parser/grammar.c \
|
||||
$(srcdir)/Include/token.h \
|
||||
|
@ -581,10 +587,10 @@ $(AST_C): $(AST_ASDL) $(ASDLGEN_FILES)
|
|||
Python/compile.o Python/symtable.o Python/ast.o: $(GRAMMAR_H) $(AST_H)
|
||||
|
||||
Python/getplatform.o: $(srcdir)/Python/getplatform.c
|
||||
$(CC) -c $(PY_CFLAGS) -DPLATFORM='"$(MACHDEP)"' -o $@ $(srcdir)/Python/getplatform.c
|
||||
$(CC) -c $(PY_CORE_CFLAGS) -DPLATFORM='"$(MACHDEP)"' -o $@ $(srcdir)/Python/getplatform.c
|
||||
|
||||
Python/importdl.o: $(srcdir)/Python/importdl.c
|
||||
$(CC) -c $(PY_CFLAGS) -I$(DLINCLDIR) -o $@ $(srcdir)/Python/importdl.c
|
||||
$(CC) -c $(PY_CORE_CFLAGS) -I$(DLINCLDIR) -o $@ $(srcdir)/Python/importdl.c
|
||||
|
||||
Objects/unicodectype.o: $(srcdir)/Objects/unicodectype.c \
|
||||
$(srcdir)/Objects/unicodetype_db.h
|
||||
|
@ -1130,7 +1136,7 @@ config.status: $(srcdir)/configure
|
|||
|
||||
# Some make's put the object file in the current directory
|
||||
.c.o:
|
||||
$(CC) -c $(PY_CFLAGS) -o $@ $<
|
||||
$(CC) -c $(PY_CORE_CFLAGS) -o $@ $<
|
||||
|
||||
# Run reindent on the library
|
||||
reindent:
|
||||
|
|
|
@ -1530,6 +1530,12 @@ Extension Modules
|
|||
Build
|
||||
-----
|
||||
|
||||
- Issue #9189: Make a user-specified CFLAGS, CPPFLAGS, or LDFLAGS
|
||||
setting override the configure and makefile defaults, without
|
||||
deleting options the user didn't intend to override. Developers
|
||||
should no longer need to specify OPT or EXTRA_CFLAGS, although those
|
||||
variables are still present for backward-compatibility.
|
||||
|
||||
- Issue #8854: Fix finding Visual Studio 2008 on Windows x64.
|
||||
|
||||
- Issue #1759169, #8864: Drop _XOPEN_SOURCE on Solaris, define it for
|
||||
|
|
|
@ -219,7 +219,7 @@ sed -e 's/[ ]*#.*//' -e '/^[ ]*$/d' |
|
|||
case $doconfig in
|
||||
no) cc="$cc \$(CCSHARED) \$(CFLAGS) \$(CPPFLAGS)";;
|
||||
*)
|
||||
cc="$cc \$(PY_CFLAGS)";;
|
||||
cc="$cc \$(PY_CORE_CFLAGS)";;
|
||||
esac
|
||||
rule="$obj: $src; $cc $cpps -c $src -o $obj"
|
||||
echo "$rule" >>$rulesf
|
||||
|
|
|
@ -1929,11 +1929,11 @@ else
|
|||
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
|
||||
/* end confdefs.h. */
|
||||
$ac_includes_default
|
||||
enum { N = $2 / 2 - 1 };
|
||||
int
|
||||
main ()
|
||||
{
|
||||
static int test_array [1 - 2 * !(enum { N = $2 / 2 - 1 };
|
||||
0 < ($ac_type) ((((($ac_type) 1 << N) << N) - 1) * 2 + 1))];
|
||||
static int test_array [1 - 2 * !(0 < ($ac_type) ((((($ac_type) 1 << N) << N) - 1) * 2 + 1))];
|
||||
test_array [0] = 0
|
||||
|
||||
;
|
||||
|
@ -1944,11 +1944,11 @@ if ac_fn_c_try_compile "$LINENO"; then :
|
|||
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
|
||||
/* end confdefs.h. */
|
||||
$ac_includes_default
|
||||
enum { N = $2 / 2 - 1 };
|
||||
int
|
||||
main ()
|
||||
{
|
||||
static int test_array [1 - 2 * !(enum { N = $2 / 2 - 1 };
|
||||
($ac_type) ((((($ac_type) 1 << N) << N) - 1) * 2 + 1)
|
||||
static int test_array [1 - 2 * !(($ac_type) ((((($ac_type) 1 << N) << N) - 1) * 2 + 1)
|
||||
< ($ac_type) ((((($ac_type) 1 << N) << N) - 1) * 2 + 2))];
|
||||
test_array [0] = 0
|
||||
|
||||
|
@ -3158,9 +3158,12 @@ then
|
|||
(it is also a good idea to do 'make clean' before compiling)" "$LINENO" 5
|
||||
fi
|
||||
|
||||
# If the user set CFLAGS, use this instead of the automatically
|
||||
# determined setting
|
||||
preset_cflags="$CFLAGS"
|
||||
# Don't let AC_PROG_CC set the default CFLAGS. It normally sets -g -O2
|
||||
# when the compiler supports them, but we don't always want -O2, and
|
||||
# we set -g later.
|
||||
if test -z "$CFLAGS"; then
|
||||
CFLAGS=
|
||||
fi
|
||||
ac_ext=c
|
||||
ac_cpp='$CPP $CPPFLAGS'
|
||||
ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
|
||||
|
@ -3952,10 +3955,6 @@ ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
|
|||
ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
|
||||
ac_compiler_gnu=$ac_cv_c_compiler_gnu
|
||||
|
||||
if test ! -z "$preset_cflags"
|
||||
then
|
||||
CFLAGS=$preset_cflags
|
||||
fi
|
||||
|
||||
|
||||
|
||||
|
|
13
configure.in
13
configure.in
|
@ -461,14 +461,13 @@ then
|
|||
(it is also a good idea to do 'make clean' before compiling)])
|
||||
fi
|
||||
|
||||
# If the user set CFLAGS, use this instead of the automatically
|
||||
# determined setting
|
||||
preset_cflags="$CFLAGS"
|
||||
AC_PROG_CC
|
||||
if test ! -z "$preset_cflags"
|
||||
then
|
||||
CFLAGS=$preset_cflags
|
||||
# Don't let AC_PROG_CC set the default CFLAGS. It normally sets -g -O2
|
||||
# when the compiler supports them, but we don't always want -O2, and
|
||||
# we set -g later.
|
||||
if test -z "$CFLAGS"; then
|
||||
CFLAGS=
|
||||
fi
|
||||
AC_PROG_CC
|
||||
|
||||
AC_SUBST(CXX)
|
||||
AC_SUBST(MAINCC)
|
||||
|
|
Loading…
Reference in New Issue