Commit d4fcdb1e authored by Jeffrey Yasskin's avatar Jeffrey Yasskin

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.
parent 74e4561a
...@@ -259,6 +259,11 @@ def _parse_makefile(filename, vars=None): ...@@ -259,6 +259,11 @@ def _parse_makefile(filename, vars=None):
# bogus variable reference; just drop it since we can't deal # bogus variable reference; just drop it since we can't deal
variables.remove(name) 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 # save the results in the global dictionary
vars.update(done) vars.update(done)
return vars return vars
......
...@@ -59,12 +59,18 @@ MAKESETUP= $(srcdir)/Modules/makesetup ...@@ -59,12 +59,18 @@ MAKESETUP= $(srcdir)/Modules/makesetup
# Compiler options # Compiler options
OPT= @OPT@ OPT= @OPT@
BASECFLAGS= @BASECFLAGS@ 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 # 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 # be able to build extension modules using the directories specified in the
# environment variables # environment variables
CPPFLAGS= -I. -IInclude -I$(srcdir)/Include @CPPFLAGS@ PY_CPPFLAGS= -I. -IInclude -I$(srcdir)/Include $(CONFIGURE_CPPFLAGS) $(CPPFLAGS)
LDFLAGS= @LDFLAGS@ PY_LDFLAGS= $(CONFIGURE_LDFLAGS) $(LDFLAGS)
LDLAST= @LDLAST@ LDLAST= @LDLAST@
SGI_ABI= @SGI_ABI@ SGI_ABI= @SGI_ABI@
CCSHARED= @CCSHARED@ CCSHARED= @CCSHARED@
...@@ -73,7 +79,7 @@ ARFLAGS= @ARFLAGS@ ...@@ -73,7 +79,7 @@ ARFLAGS= @ARFLAGS@
# Extra C flags added for building the interpreter object files. # Extra C flags added for building the interpreter object files.
CFLAGSFORSHARED=@CFLAGSFORSHARED@ CFLAGSFORSHARED=@CFLAGSFORSHARED@
# C flags used for building the interpreter object files # 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 # Machine-dependent subdirectories
...@@ -411,7 +417,7 @@ coverage: ...@@ -411,7 +417,7 @@ coverage:
# Build the interpreter # Build the interpreter
$(BUILDPYTHON): Modules/python.o $(LIBRARY) $(LDLIBRARY) $(BUILDPYTHON): Modules/python.o $(LIBRARY) $(LDLIBRARY)
$(LINKCC) $(LDFLAGS) $(LINKFORSHARED) -o $@ \ $(LINKCC) $(PY_LDFLAGS) $(LINKFORSHARED) -o $@ \
Modules/python.o \ Modules/python.o \
$(BLDLIBRARY) $(LIBS) $(MODLIBS) $(SYSLIBS) $(LDLAST) $(BLDLIBRARY) $(LIBS) $(MODLIBS) $(SYSLIBS) $(LDLAST)
...@@ -422,8 +428,8 @@ platform: $(BUILDPYTHON) ...@@ -422,8 +428,8 @@ platform: $(BUILDPYTHON)
# Build the shared modules # Build the shared modules
sharedmods: $(BUILDPYTHON) sharedmods: $(BUILDPYTHON)
@case $$MAKEFLAGS in \ @case $$MAKEFLAGS in \
*s*) $(RUNSHARED) CC='$(CC)' LDSHARED='$(BLDSHARED)' LDFLAGS='$(LDFLAGS)' OPT='$(OPT)' ./$(BUILDPYTHON) -E $(srcdir)/setup.py -q 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='$(LDFLAGS)' OPT='$(OPT)' ./$(BUILDPYTHON) -E $(srcdir)/setup.py build;; \ *) $(RUNSHARED) CC='$(CC)' LDSHARED='$(BLDSHARED)' LDFLAGS='$(PY_LDFLAGS)' OPT='$(OPT)' ./$(BUILDPYTHON) -E $(srcdir)/setup.py build;; \
esac esac
# Build static library # Build static library
...@@ -440,18 +446,18 @@ $(LIBRARY): $(LIBRARY_OBJS) ...@@ -440,18 +446,18 @@ $(LIBRARY): $(LIBRARY_OBJS)
libpython$(VERSION).so: $(LIBRARY_OBJS) libpython$(VERSION).so: $(LIBRARY_OBJS)
if test $(INSTSONAME) != $(LDLIBRARY); then \ 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) $@; \ $(LN) -f $(INSTSONAME) $@; \
else \ else \
$(LDSHARED) $(LDFLAGS) -o $@ $(LIBRARY_OBJS) $(MODLIBS) $(SHLIBS) $(LIBC) $(LIBM) $(LDLAST); \ $(LDSHARED) $(PY_LDFLAGS) -o $@ $(LIBRARY_OBJS) $(MODLIBS) $(SHLIBS) $(LIBC) $(LIBM) $(LDLAST); \
fi fi
libpython$(VERSION).dylib: $(LIBRARY_OBJS) 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) 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 # Copy up the gdb python hooks into a position where they can be automatically
# loaded by gdb during Lib/test/test_gdb.py # loaded by gdb during Lib/test/test_gdb.py
...@@ -497,7 +503,7 @@ $(PYTHONFRAMEWORKDIR)/Versions/$(VERSION)/$(PYTHONFRAMEWORK): \ ...@@ -497,7 +503,7 @@ $(PYTHONFRAMEWORKDIR)/Versions/$(VERSION)/$(PYTHONFRAMEWORK): \
# for a shared core library; otherwise, this rule is a noop. # for a shared core library; otherwise, this rule is a noop.
$(DLLLIBRARY) libpython$(VERSION).dll.a: $(LIBRARY_OBJS) $(DLLLIBRARY) libpython$(VERSION).dll.a: $(LIBRARY_OBJS)
if test -n "$(DLLLIBRARY)"; then \ if test -n "$(DLLLIBRARY)"; then \
$(LDSHARED) $(LDFLAGS) -Wl,--out-implib=$@ -o $(DLLLIBRARY) $^ \ $(LDSHARED) $(PY_LDFLAGS) -Wl,--out-implib=$@ -o $(DLLLIBRARY) $^ \
$(LIBS) $(MODLIBS) $(SYSLIBS) $(LDLAST); \ $(LIBS) $(MODLIBS) $(SYSLIBS) $(LDLAST); \
else true; \ else true; \
fi fi
...@@ -541,10 +547,10 @@ Modules/getbuildinfo.o: $(PARSER_OBJS) \ ...@@ -541,10 +547,10 @@ Modules/getbuildinfo.o: $(PARSER_OBJS) \
$(SIGNAL_OBJS) \ $(SIGNAL_OBJS) \
$(MODOBJS) \ $(MODOBJS) \
$(srcdir)/Modules/getbuildinfo.c $(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 Modules/getpath.o: $(srcdir)/Modules/getpath.c Makefile
$(CC) -c $(PY_CFLAGS) -DPYTHONPATH='"$(PYTHONPATH)"' \ $(CC) -c $(PY_CORE_CFLAGS) -DPYTHONPATH='"$(PYTHONPATH)"' \
-DPREFIX='"$(prefix)"' \ -DPREFIX='"$(prefix)"' \
-DEXEC_PREFIX='"$(exec_prefix)"' \ -DEXEC_PREFIX='"$(exec_prefix)"' \
-DVERSION='"$(VERSION)"' \ -DVERSION='"$(VERSION)"' \
...@@ -552,7 +558,7 @@ Modules/getpath.o: $(srcdir)/Modules/getpath.c Makefile ...@@ -552,7 +558,7 @@ Modules/getpath.o: $(srcdir)/Modules/getpath.c Makefile
-o $@ $(srcdir)/Modules/getpath.c -o $@ $(srcdir)/Modules/getpath.c
Modules/python.o: $(srcdir)/Modules/python.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) $(IO_OBJS): $(IO_H)
...@@ -561,7 +567,7 @@ $(GRAMMAR_H) $(GRAMMAR_C): $(PGEN) $(GRAMMAR_INPUT) ...@@ -561,7 +567,7 @@ $(GRAMMAR_H) $(GRAMMAR_C): $(PGEN) $(GRAMMAR_INPUT)
-$(PGEN) $(GRAMMAR_INPUT) $(GRAMMAR_H) $(GRAMMAR_C) -$(PGEN) $(GRAMMAR_INPUT) $(GRAMMAR_H) $(GRAMMAR_C)
$(PGEN): $(PGENOBJS) $(PGEN): $(PGENOBJS)
$(CC) $(OPT) $(LDFLAGS) $(PGENOBJS) $(LIBS) -o $(PGEN) $(CC) $(OPT) $(PY_LDFLAGS) $(PGENOBJS) $(LIBS) -o $(PGEN)
Parser/grammar.o: $(srcdir)/Parser/grammar.c \ Parser/grammar.o: $(srcdir)/Parser/grammar.c \
$(srcdir)/Include/token.h \ $(srcdir)/Include/token.h \
...@@ -581,10 +587,10 @@ $(AST_C): $(AST_ASDL) $(ASDLGEN_FILES) ...@@ -581,10 +587,10 @@ $(AST_C): $(AST_ASDL) $(ASDLGEN_FILES)
Python/compile.o Python/symtable.o Python/ast.o: $(GRAMMAR_H) $(AST_H) Python/compile.o Python/symtable.o Python/ast.o: $(GRAMMAR_H) $(AST_H)
Python/getplatform.o: $(srcdir)/Python/getplatform.c 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 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 \ Objects/unicodectype.o: $(srcdir)/Objects/unicodectype.c \
$(srcdir)/Objects/unicodetype_db.h $(srcdir)/Objects/unicodetype_db.h
...@@ -1130,7 +1136,7 @@ config.status: $(srcdir)/configure ...@@ -1130,7 +1136,7 @@ config.status: $(srcdir)/configure
# Some make's put the object file in the current directory # Some make's put the object file in the current directory
.c.o: .c.o:
$(CC) -c $(PY_CFLAGS) -o $@ $< $(CC) -c $(PY_CORE_CFLAGS) -o $@ $<
# Run reindent on the library # Run reindent on the library
reindent: reindent:
......
...@@ -1530,6 +1530,12 @@ Extension Modules ...@@ -1530,6 +1530,12 @@ Extension Modules
Build 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 #8854: Fix finding Visual Studio 2008 on Windows x64.
- Issue #1759169, #8864: Drop _XOPEN_SOURCE on Solaris, define it for - Issue #1759169, #8864: Drop _XOPEN_SOURCE on Solaris, define it for
......
...@@ -219,7 +219,7 @@ sed -e 's/[ ]*#.*//' -e '/^[ ]*$/d' | ...@@ -219,7 +219,7 @@ sed -e 's/[ ]*#.*//' -e '/^[ ]*$/d' |
case $doconfig in case $doconfig in
no) cc="$cc \$(CCSHARED) \$(CFLAGS) \$(CPPFLAGS)";; no) cc="$cc \$(CCSHARED) \$(CFLAGS) \$(CPPFLAGS)";;
*) *)
cc="$cc \$(PY_CFLAGS)";; cc="$cc \$(PY_CORE_CFLAGS)";;
esac esac
rule="$obj: $src; $cc $cpps -c $src -o $obj" rule="$obj: $src; $cc $cpps -c $src -o $obj"
echo "$rule" >>$rulesf echo "$rule" >>$rulesf
......
...@@ -1929,11 +1929,11 @@ else ...@@ -1929,11 +1929,11 @@ else
cat confdefs.h - <<_ACEOF >conftest.$ac_ext cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */ /* end confdefs.h. */
$ac_includes_default $ac_includes_default
enum { N = $2 / 2 - 1 };
int int
main () main ()
{ {
static int test_array [1 - 2 * !(enum { N = $2 / 2 - 1 }; static int test_array [1 - 2 * !(0 < ($ac_type) ((((($ac_type) 1 << N) << N) - 1) * 2 + 1))];
0 < ($ac_type) ((((($ac_type) 1 << N) << N) - 1) * 2 + 1))];
test_array [0] = 0 test_array [0] = 0
; ;
...@@ -1944,11 +1944,11 @@ if ac_fn_c_try_compile "$LINENO"; then : ...@@ -1944,11 +1944,11 @@ if ac_fn_c_try_compile "$LINENO"; then :
cat confdefs.h - <<_ACEOF >conftest.$ac_ext cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */ /* end confdefs.h. */
$ac_includes_default $ac_includes_default
enum { N = $2 / 2 - 1 };
int int
main () main ()
{ {
static int test_array [1 - 2 * !(enum { N = $2 / 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 + 1)
< ($ac_type) ((((($ac_type) 1 << N) << N) - 1) * 2 + 2))]; < ($ac_type) ((((($ac_type) 1 << N) << N) - 1) * 2 + 2))];
test_array [0] = 0 test_array [0] = 0
...@@ -3158,9 +3158,12 @@ then ...@@ -3158,9 +3158,12 @@ then
(it is also a good idea to do 'make clean' before compiling)" "$LINENO" 5 (it is also a good idea to do 'make clean' before compiling)" "$LINENO" 5
fi fi
# If the user set CFLAGS, use this instead of the automatically # Don't let AC_PROG_CC set the default CFLAGS. It normally sets -g -O2
# determined setting # when the compiler supports them, but we don't always want -O2, and
preset_cflags="$CFLAGS" # we set -g later.
if test -z "$CFLAGS"; then
CFLAGS=
fi
ac_ext=c ac_ext=c
ac_cpp='$CPP $CPPFLAGS' ac_cpp='$CPP $CPPFLAGS'
ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
...@@ -3952,10 +3955,6 @@ 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_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
ac_compiler_gnu=$ac_cv_c_compiler_gnu ac_compiler_gnu=$ac_cv_c_compiler_gnu
if test ! -z "$preset_cflags"
then
CFLAGS=$preset_cflags
fi
......
...@@ -461,14 +461,13 @@ then ...@@ -461,14 +461,13 @@ then
(it is also a good idea to do 'make clean' before compiling)]) (it is also a good idea to do 'make clean' before compiling)])
fi fi
# If the user set CFLAGS, use this instead of the automatically # Don't let AC_PROG_CC set the default CFLAGS. It normally sets -g -O2
# determined setting # when the compiler supports them, but we don't always want -O2, and
preset_cflags="$CFLAGS" # we set -g later.
AC_PROG_CC if test -z "$CFLAGS"; then
if test ! -z "$preset_cflags" CFLAGS=
then
CFLAGS=$preset_cflags
fi fi
AC_PROG_CC
AC_SUBST(CXX) AC_SUBST(CXX)
AC_SUBST(MAINCC) AC_SUBST(MAINCC)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment