@@ -440,7 +440,17 @@ DTRACE_DEPS = \
440440
441441# Default target
442442all: @DEF_MAKE_ALL_RULE@
443- build_all: $(BUILDPYTHON) oldsharedmods sharedmods gdbhooks Programs/_testembed python-config
443+ build_all: check-clean-src $(BUILDPYTHON) oldsharedmods sharedmods gdbhooks \
444+ Programs/_testembed python-config
445+
446+ # Check that the source is clean when building out of source.
447+ check-clean-src:
448+ @if test -n "$(VPATH)" -a -f "$(srcdir)/Programs/python.o"; then \
449+ echo "Error: The source directory ($(srcdir)) is not clean" ; \
450+ echo "Building Python out of the source tree (in $(abs_builddir)) requires a clean source tree ($(abs_srcdir))" ; \
451+ echo "Try to run: make -C \"$(srcdir)\" clean" ; \
452+ exit 1; \
453+ fi
444454
445455# Profile generation build must start from a clean tree.
446456profile-clean-stamp:
@@ -542,7 +552,7 @@ coverage-report: regen-grammar regen-importlib
542552# Run "Argument Clinic" over all source files
543553# (depends on python having already been built)
544554.PHONY=clinic
545- clinic: $(BUILDPYTHON) $(srcdir)/Modules/_blake2/blake2s_impl.c
555+ clinic: check-clean-src $(BUILDPYTHON) $(srcdir)/Modules/_blake2/blake2s_impl.c
546556 $(RUNSHARED) $(PYTHON_FOR_BUILD) $(srcdir)/Tools/clinic/clinic.py --make --srcdir $(srcdir)
547557
548558# Build the interpreter
@@ -1100,7 +1110,7 @@ altinstall: commoninstall
11001110 $$ensurepip --root=$(DESTDIR)/ ; \
11011111 fi
11021112
1103- commoninstall: @FRAMEWORKALTINSTALLFIRST@ \
1113+ commoninstall: check-clean-src @FRAMEWORKALTINSTALLFIRST@ \
11041114 altbininstall libinstall inclinstall libainstall \
11051115 sharedinstall oldsharedinstall altmaninstall \
11061116 @FRAMEWORKALTINSTALLLAST@
@@ -1722,7 +1732,7 @@ patchcheck: @DEF_MAKE_RULE@
17221732Python/thread.o: @THREADHEADERS@
17231733
17241734# Declare targets that aren't real files
1725- .PHONY: all build_all sharedmods oldsharedmods test quicktest
1735+ .PHONY: all build_all sharedmods check-clean-src oldsharedmods test quicktest
17261736.PHONY: install altinstall oldsharedinstall bininstall altbininstall
17271737.PHONY: maninstall libinstall inclinstall libainstall sharedinstall
17281738.PHONY: frameworkinstall frameworkinstallframework frameworkinstallstructure
0 commit comments