Based on:
https://www.mail-archive.com/gcc-patches@gcc.gnu.org/msg236329.html

Signed-off-by: Romain Naour <romain.na...@gmail.com>
Cc: Ben Dakin-Norris <ben.dakin-nor...@navtechradar.com>
Cc: Maxim Kochetkov <fido_...@inbox.ru>
Cc: Thomas Petazzoni <thomas.petazz...@bootlin.com>
Cc: Yann E. MORIN <yann.morin.1...@free.fr>
Cc: Cc: David Malcolm <dmalc...@gcc.gnu.org>
---
This patch should be backported to gcc 10 and gcc 9.
---
 gcc/Makefile.in | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/gcc/Makefile.in b/gcc/Makefile.in
index 5f43d9d..c68d146 100644
--- a/gcc/Makefile.in
+++ b/gcc/Makefile.in
@@ -1685,6 +1685,10 @@ $(FULL_DRIVER_NAME): ./xgcc
 	rm -f $@
 	$(LN_S) $< $@
 
+# SELFTEST_DEPS need to be set before including language makefile fragments.
+# Otherwise $(SELFTEST_DEPS) is empty when used from various <LANG>/Make-lang.in.
+SELFTEST_DEPS = $(GCC_PASSES) stmp-int-hdrs $(srcdir)/testsuite/selftests
+
 #
 # Language makefile fragments.
 
@@ -1949,8 +1953,6 @@ DEVNULL=$(if $(findstring mingw,$(build)),nul,/dev/null)
 SELFTEST_FLAGS = -nostdinc $(DEVNULL) -S -o $(DEVNULL) \
 	-fself-test=$(srcdir)/testsuite/selftests
 
-SELFTEST_DEPS = $(GCC_PASSES) stmp-int-hdrs $(srcdir)/testsuite/selftests
-
 # Run the selftests during the build once we have a driver and the frontend,
 # so that self-test failures are caught as early as possible.
 # Use "s-selftest-FE" to ensure that we only run the selftests if the
-- 
2.7.4

