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