| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | # $NetBSD: var-scope-cmdline.mk,v 1.1 2022/01/23 16:25:54 rillig Exp $ | | 1 | # $NetBSD: var-scope-cmdline.mk,v 1.2 2023/04/07 05:54:16 rillig Exp $ |
2 | # | | 2 | # |
3 | # Tests for variables specified on the command line. | | 3 | # Tests for variables specified on the command line. |
4 | # | | 4 | # |
5 | # Variables that are specified on the command line override those from the | | 5 | # Variables that are specified on the command line override those from the |
6 | # global scope. | | 6 | # global scope. |
7 | # | | 7 | # |
8 | # For performance reasons, the actual implementation is more complex than the | | 8 | # For performance reasons, the actual implementation is more complex than the |
9 | # above single-sentence rule, in order to avoid unnecessary lookups in scopes, | | 9 | # above single-sentence rule, in order to avoid unnecessary lookups in scopes, |
10 | # which before var.c 1.586 from 2020-10-25 calculated the hash value of the | | 10 | # which before var.c 1.586 from 2020-10-25 calculated the hash value of the |
11 | # variable name once for each lookup. Instead, when looking up the value of | | 11 | # variable name once for each lookup. Instead, when looking up the value of |
12 | # a variable, the search often starts in the global scope since that is where | | 12 | # a variable, the search often starts in the global scope since that is where |
13 | # most of the variables are stored. This conflicts with the statement that | | 13 | # most of the variables are stored. This conflicts with the statement that |
14 | # variables from the cmdline scope override global variables, since after the | | 14 | # variables from the cmdline scope override global variables, since after the |
| @@ -51,26 +51,30 @@ | | | @@ -51,26 +51,30 @@ |
51 | # | | 51 | # |
52 | # Another bug was the wrong assumption that "deleting a cmdline variable is | | 52 | # Another bug was the wrong assumption that "deleting a cmdline variable is |
53 | # not possible". Deleting such a variable has been possible since var.c 1.204 | | 53 | # not possible". Deleting such a variable has been possible since var.c 1.204 |
54 | # from 2016-02-19, when the variable modifier ':@' started to delete the | | 54 | # from 2016-02-19, when the variable modifier ':@' started to delete the |
55 | # temporary loop variable after finishing the loop. It was probably not | | 55 | # temporary loop variable after finishing the loop. It was probably not |
56 | # intended back then that a side effect of this seemingly simple change was | | 56 | # intended back then that a side effect of this seemingly simple change was |
57 | # that both global and cmdline variables could now be undefined at will as a | | 57 | # that both global and cmdline variables could now be undefined at will as a |
58 | # side effect of evaluating a variable expression. As of 2021-02-23, this is | | 58 | # side effect of evaluating a variable expression. As of 2021-02-23, this is |
59 | # still possible. | | 59 | # still possible. |
60 | # | | 60 | # |
61 | # Most cmdline variables are set at the very beginning, when parsing the | | 61 | # Most cmdline variables are set at the very beginning, when parsing the |
62 | # command line arguments. Using the special target '.MAKEFLAGS', it is | | 62 | # command line arguments. Using the special target '.MAKEFLAGS', it is |
63 | # possible to set cmdline variables at any later time. | | 63 | # possible to set cmdline variables at any later time. |
| | | 64 | # |
| | | 65 | # See also: |
| | | 66 | # varcmd.mk |
| | | 67 | # varname-makeflags.mk |
64 | | | 68 | |
65 | # A normal global variable, without any cmdline variable nearby. | | 69 | # A normal global variable, without any cmdline variable nearby. |
66 | VAR= global | | 70 | VAR= global |
67 | .info ${VAR} | | 71 | .info ${VAR} |
68 | | | 72 | |
69 | # The global variable is "overridden" by simply deleting it and then | | 73 | # The global variable is "overridden" by simply deleting it and then |
70 | # installing the cmdline variable instead. Since there is no obvious way to | | 74 | # installing the cmdline variable instead. Since there is no obvious way to |
71 | # undefine a cmdline variable, there is no need to remember the old value | | 75 | # undefine a cmdline variable, there is no need to remember the old value |
72 | # of the global variable could become visible again. | | 76 | # of the global variable could become visible again. |
73 | # | | 77 | # |
74 | # See varmod-loop.mk for a non-obvious way to undefine a cmdline variable. | | 78 | # See varmod-loop.mk for a non-obvious way to undefine a cmdline variable. |
75 | .MAKEFLAGS: VAR=makeflags | | 79 | .MAKEFLAGS: VAR=makeflags |
76 | .info ${VAR} | | 80 | .info ${VAR} |