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