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