[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lmi-commits] [lmi] odd/source_script_in_makefile fc9727f 1/8: Construct

From: Greg Chicares
Subject: [lmi-commits] [lmi] odd/source_script_in_makefile fc9727f 1/8: Construct a unique temporary filename to avoid collisions
Date: Fri, 17 May 2019 21:31:37 -0400 (EDT)

branch: odd/source_script_in_makefile
commit fc9727f853e8330254cda9ab9b44dce9a442d547
Author: Gregory W. Chicares <address@hidden>
Commit: Gregory W. Chicares <address@hidden>

    Construct a unique temporary filename to avoid collisions
    Replaced a static filename with a uniquified one. Added a recipe line
    to remove that file after use. Noted an open question: is the former
    static filename, now still used as a target name, utterly arbitrary?
 parent.make | 16 +++++++++++++---
 set.sh      |  5 ++++-
 2 files changed, 17 insertions(+), 4 deletions(-)

diff --git a/parent.make b/parent.make
index 09eefce..6808af1 100644
--- a/parent.make
+++ b/parent.make
@@ -1,3 +1,9 @@
+# IMPORTANT: the former 'env.make' has been replaced by
+#    env.$(LMI_TIMESTAMP).eraseme
+# in the non-commented-out code, but not in any comments.
+# Yet 'env.make' remains as a target; is that target's name
+# actually arbitrary?
 # This demonstration shows a way to source a script in a makefile,
 # and export environment variables set by that script to make's
 # environment, thus:
@@ -7,8 +13,8 @@
 #    then writes 'make' assignments like "export foo := bar"
 #    for each desired environment variable
 # To test:
-#   $export LMI_IN=X; make -f parent.make all
-#   $export LMI_IN=Q; make -f parent.make all
+#   $export LMI_IN=Russia; LANG=ru_RU make -f parent.make all
+#   $export LMI_IN=Mongolia; LANG=mn_MN make -f parent.make all
 # and check what appears on stdout.
 # A file named 'env.make' is created in the source directory.
@@ -21,6 +27,8 @@
 # prerequisite may impair the efficiency that was gained by
 # writing the double-colon rule.
+export LMI_TIMESTAMP := $(shell date -u +'%s.%N')
 # No good: syntax error.
 #include set.sh
@@ -31,10 +39,12 @@
 #parent.make: env.make
 parent.make parent.make:: env.make ;
 # $(eval include) here is necessary and sufficient.
-       $(eval include env.make)
+       $(eval include env.$(LMI_TIMESTAMP).eraseme)
        @echo "eval: LMI_IN in 'parent.make': $$LMI_IN"
        @echo "eval: LMI_OUT1 in 'parent.make': $$LMI_OUT1"
        @echo "eval: LMI_OUT2 in 'parent.make': $$LMI_OUT2"
+# '--force': the file won't be there when this makefile is remade
+       rm --force env.$(LMI_TIMESTAMP).eraseme
 # Doesn't execute recipe without ".PHONY":
 .PHONY: env.make
diff --git a/set.sh b/set.sh
index 8ae899a..07483b6 100755
--- a/set.sh
+++ b/set.sh
@@ -2,6 +2,9 @@
+# $LMI_TIMESTAMP is defined by the makefile that sources this script.
+# shellcheck disable=SC2154
+echo "LMI_TIMESTAMP in 'set.sh': $LMI_TIMESTAMP"
 echo "LMI_IN in 'set.sh': $LMI_IN"
 echo "LMI_OUT1 entering 'set.sh': $LMI_OUT1"
 echo "LMI_OUT2 entering 'set.sh': $LMI_OUT2"
@@ -12,7 +15,7 @@ echo "LMI_OUT2 leaving 'set.sh': $LMI_OUT2"
     echo "export LMI_OUT1 := $LMI_OUT1"
     echo "export LMI_OUT2 := $LMI_OUT2"
-} > env.make
+} > env."$LMI_TIMESTAMP".eraseme

reply via email to

[Prev in Thread] Current Thread [Next in Thread]