lmi-commits
[Top][All Lists]
Advanced

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

[lmi-commits] [lmi] master a034d7f 4/5: Fix defect exposed 20200402T1125


From: Greg Chicares
Subject: [lmi-commits] [lmi] master a034d7f 4/5: Fix defect exposed 20200402T1125Z: 'make' subtlety
Date: Thu, 2 Apr 2020 19:47:21 -0400 (EDT)

branch: master
commit a034d7f2cf61ce3146b7233dbd4b2da0b863a88c
Author: Gregory W. Chicares <address@hidden>
Commit: Gregory W. Chicares <address@hidden>

    Fix defect exposed 20200402T1125Z: 'make' subtlety
    
    Variable assignments via $(eval include ...) take effect before
    recursive expansions on subsequent makefile lines, but not before
    immediate expansions and not before other makefiles are included.
    See commit 8b8a6608da8 of 20200402T1125Z for a demonstration.
    
    Replaced
      $(eval include $(LMI_ENV_FILE))
    in a recipe with the directive
      include $(LMI_ENV_FILE)
    which takes effect earlier. Moved assignments of 'make' variables
    out of 'set_toolchain.sh' and into a new 'transume_toolchain.sh'
    (so named to discourage unintended use, as nobody really knows what
    transumption means, and the risk of transmissible spongiform
    encephalopathy should ward off the incautious).
    
    It is not necessarily obvious that these lines must be executed in the
    order given:
      $(shell $(CURDIR)/transume_toolchain.sh > $(LMI_ENV_FILE))
      include $(LMI_ENV_FILE)
    but the gnu make maintainer endorses that sort of usage here:
    
    https://lists.gnu.org/archive/html/help-make/2006-04/msg00142.html
    |   $(shell setvars -m > /tmp/somefile)
    |   include /tmp/somefile
    
    Removed an unnecessary 'export' from the definition of $(LMI_ENV_FILE).
    Made that variable nominate a file in /tmp, rather than in the current
    directory, because there's no longer a convenient way to remove it after
    use. Resisted the urge to give it a static name like /tmp/lmi_env_file
    because of recent experience with .git/FETCH_HEAD, which may acquire
    permissions that prevent its use by group members; if /tmp becomes
    cluttered by these files, 'rm /tmp/lmi_env_*' will clean them up.
---
 GNUmakefile           | 15 +++++++--------
 set_toolchain.sh      |  9 ---------
 transume_toolchain.sh | 32 ++++++++++++++++++++++++++++++++
 3 files changed, 39 insertions(+), 17 deletions(-)

diff --git a/GNUmakefile b/GNUmakefile
index 4d99b2f..d9a1c71 100644
--- a/GNUmakefile
+++ b/GNUmakefile
@@ -82,8 +82,7 @@ MAKEFLAGS := \
 
 
################################################################################
 
-# Remake this makefile to "source" a script that sets various crucial
-# environment variables.
+# Remake this makefile.
 #
 # For similar usage elsewhere, $(srcdir) is generally preferred to
 # $(CURDIR), especially in submakefiles made in other directories,
@@ -91,14 +90,14 @@ MAKEFLAGS := \
 # $(srcdir) has not yet been assigned, and it's best to remake this
 # makefile early.
 
-export LMI_ENV_FILE := env_$(shell date -u +'%s_%N').eraseme
+GNUmakefile $(CURDIR)/GNUmakefile:: ;
 
-GNUmakefile $(CURDIR)/GNUmakefile:: $(LMI_ENV_FILE)
-       $(eval include $(LMI_ENV_FILE))
-       @rm $(LMI_ENV_FILE)
+# "Source" various crucial environment variables.
 
-$(LMI_ENV_FILE):
-       @. $(CURDIR)/set_toolchain.sh
+LMI_ENV_FILE := /tmp/lmi_env_$(shell date -u +'%s_%N').eraseme
+$(shell $(CURDIR)/transume_toolchain.sh > $(LMI_ENV_FILE))
+include $(LMI_ENV_FILE)
+$(LMI_ENV_FILE):: ;
 
 
################################################################################
 
diff --git a/set_toolchain.sh b/set_toolchain.sh
index f4a43c0..6d24347 100755
--- a/set_toolchain.sh
+++ b/set_toolchain.sh
@@ -130,15 +130,6 @@ case "$lmi_build_type" in
         ;;
     (*) ;;
 esac
-if [ -n "$LMI_ENV_FILE" ]; then
-    {
-    printf '%s\n' "export LMI_COMPILER := $LMI_COMPILER"
-    printf '%s\n' "export LMI_TRIPLET  := $LMI_TRIPLET"
-    printf '%s\n' "export PATH         := $PATH"
-    printf '%s\n' "export WINEPATH     := $WINEPATH"
-    printf '%s\n' "export PERFORM      := $PERFORM"
-    } > "$LMI_ENV_FILE"
-fi
 }
 
 # This script is to be sourced, so use 'return' because 'exit' would
diff --git a/transume_toolchain.sh b/transume_toolchain.sh
new file mode 100755
index 0000000..7947e30
--- /dev/null
+++ b/transume_toolchain.sh
@@ -0,0 +1,32 @@
+#!/bin/sh
+
+# Recast definitions from 'set_toolchain.sh' for use in makefiles.
+
+# Copyright (C) 2020 Gregory W. Chicares.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License version 2 as
+# published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+#
+# http://savannah.nongnu.org/projects/lmi
+# email: <address@hidden>
+# snail: Chicares, 186 Belle Woods Drive, Glastonbury CT 06033, USA
+
+# See 'GNUmakefile' for suggested use.
+
+. ./set_toolchain.sh
+
+printf '%s\n' "export LMI_COMPILER := $LMI_COMPILER"
+printf '%s\n' "export LMI_TRIPLET  := $LMI_TRIPLET"
+printf '%s\n' "export PATH         := $PATH"
+printf '%s\n' "export WINEPATH     := $WINEPATH"
+printf '%s\n' "export PERFORM      := $PERFORM"



reply via email to

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