4fc7fc
commit 1f67d8286b5da9266a138198ef1f15c27cbb0010
4fc7fc
Author: H.J. Lu <hjl.tools@gmail.com>
4fc7fc
Date:   Mon Nov 15 16:28:39 2021 -0800
4fc7fc
4fc7fc
    elf: Use a temporary file to generate Makefile fragments [BZ #28550]
4fc7fc
    
4fc7fc
    1. Use a temporary file to generate Makefile fragments for DSO sorting
4fc7fc
    tests and use -include on them.
4fc7fc
    2. Add Makefile fragments to postclean-generated so that a "make clean"
4fc7fc
    removes the autogenerated fragments and a subsequent "make" regenerates
4fc7fc
    them.
4fc7fc
    
4fc7fc
    This partially fixes BZ #28550.
4fc7fc
    
4fc7fc
    Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
4fc7fc
4fc7fc
diff --git a/elf/Makefile b/elf/Makefile
4fc7fc
index 3b5e1f59e6696a2b..22a8060f7d3bb1a1 100644
4fc7fc
--- a/elf/Makefile
4fc7fc
+++ b/elf/Makefile
4fc7fc
@@ -986,6 +986,7 @@ tests-special += \
4fc7fc
   # tests-special
4fc7fc
 endif
4fc7fc
 
4fc7fc
+ifndef avoid-generated
4fc7fc
 # DSO sorting tests:
4fc7fc
 # The dso-ordering-test.py script generates testcase source files in $(objpfx),
4fc7fc
 # creating a $(objpfx)<testcase-name>-dir for each testcase, and creates a
4fc7fc
@@ -993,9 +994,14 @@ endif
4fc7fc
 define include_dsosort_tests
4fc7fc
 $(objpfx)$(1).generated-makefile: $(1)
4fc7fc
 	$(PYTHON) $(..)scripts/dso-ordering-test.py \
4fc7fc
-	--description-file $$< --objpfx $(objpfx) --output-makefile $$@
4fc7fc
-include $(objpfx)$(1).generated-makefile
4fc7fc
+	--description-file $$< --objpfx $(objpfx) --output-makefile $$@T
4fc7fc
+	mv $$@T $$@
4fc7fc
+-include $(objpfx)$(1).generated-makefile
4fc7fc
 endef
4fc7fc
+endif
4fc7fc
+
4fc7fc
+postclean-generated += $(objpfx)/dso-sort-tests-2.generated-makefile \
4fc7fc
+		       $(objpfx)/dso-sort-tests-2.generated-makefile
4fc7fc
 
4fc7fc
 # Generate from each testcase description file
4fc7fc
 ifeq (yes,$(have-tunables))