Source-Changes-HG archive

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

[src/trunk]: src/usr.bin/make Explain variable expansion better. Requested by...



details:   https://anonhg.NetBSD.org/src/rev/16a5be8f9334
branches:  trunk
changeset: 755564:16a5be8f9334
user:      christos <christos%NetBSD.org@localhost>
date:      Wed Jun 09 16:58:22 2010 +0000

description:
Explain variable expansion better. Requested by Aleksey Cheusov

diffstat:

 usr.bin/make/make.1 |  43 ++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 40 insertions(+), 3 deletions(-)

diffs (68 lines):

diff -r 84a80f544ee2 -r 16a5be8f9334 usr.bin/make/make.1
--- a/usr.bin/make/make.1       Wed Jun 09 14:08:17 2010 +0000
+++ b/usr.bin/make/make.1       Wed Jun 09 16:58:22 2010 +0000
@@ -1,4 +1,4 @@
-.\"    $NetBSD: make.1,v 1.174 2010/06/06 17:28:48 wiz Exp $
+.\"    $NetBSD: make.1,v 1.175 2010/06/09 16:58:22 christos Exp $
 .\"
 .\" Copyright (c) 1990, 1993
 .\"    The Regents of the University of California.  All rights reserved.
@@ -29,7 +29,7 @@
 .\"
 .\"    from: @(#)make.1        8.4 (Berkeley) 3/19/94
 .\"
-.Dd June 6, 2010
+.Dd June 9, 2010
 .Dt MAKE 1
 .Os
 .Sh NAME
@@ -536,11 +536,48 @@
 .Pq Ql \&$
 the string is expanded again.
 .Pp
-Variable substitution occurs at two distinct times, depending on where
+Variable substitution occurs at three distinct times, depending on where
 the variable is being used.
+.Bl -enum
+.It 
 Variables in dependency lines are expanded as the line is read.
+.It
 Variables in shell commands are expanded when the shell command is
 executed.
+.It
+.Dq .for
+loop index variables are expanded on each loop iteration. 
+Note that other variables are not expanded inside loops so 
+the following example code:
+.Bd -literal -offset indent
+
+.Dv .for i in 1 2 3
+a+=     ${i}
+j=      ${i}
+b+=     ${j}
+.Dv .endfor
+
+all:
+        @echo ${a}
+       @echo ${b}
+
+.Ed
+will print:
+.Bd -literal -offset indent
+1 2 3
+3 3 3
+
+.Ed
+Because while ${a} contains
+.Dq 1 2 3
+after the loop is executed, ${b}
+contains
+.Dq ${j} ${j} ${j}
+which expands to
+.Dq 3 3 3
+since after the loop completes ${j} contains
+.Dq 3 .
+.El
 .Ss Variable classes
 The four different classes of variables (in order of increasing precedence)
 are:



Home | Main Index | Thread Index | Old Index