Re: make.1: sync variable substitution bits with NetBSD

2022-10-12 Thread Omar Polo
On 2022/10/12 10:45:49 +, Klemens Nanni  wrote:
> Anyone willing to OK either the previous NetBSD/FreeBSD sync diff or the
> following minimal one which just mentions missing types?
> 
> We can always improve from there, but being stuck at an incomplete and
> thus misleading manual sucks.

agreed, and fwiw i think it's important to document when variable
substitution occurs.  ok for me, but please fix the typo:

> Index: make.1
> ===
> RCS file: /cvs/src/usr.bin/make/make.1,v
> retrieving revision 1.131
> diff -u -p -r1.131 make.1
> --- make.126 Jan 2020 12:40:50 -  1.131
> +++ make.130 Dec 2020 17:36:54 -
> @@ -600,9 +600,9 @@ If the variable name contains only a sin
>  braces or parentheses are not required.
>  This shorter form is not recommended.
>  .Pp
> -Variable substitution occurs at two distinct times, depending on where
> -the variable is being used.
> -Variables in dependency lines are expanded as the line is read.
> +Variable substitution occurs at distinct times, depending on the type of 
> line.
> +Variables in dependency lines, conditinal directives and include statements 
> are
  ^^

> +expanded as the line is read.
>  Variables in shell commands are expanded when the shell command is
>  executed.
>  .Pp




Re: make.1: sync variable substitution bits with NetBSD

2022-10-12 Thread Klemens Nanni
On Sat, Nov 13, 2021 at 10:09:27AM +, Klemens Nanni wrote:
> On Sat, Dec 26, 2020 at 05:19:55PM +0100, Klemens Nanni wrote:
> > Our make(1) is behind NetBSD's and FreeBSD's make(1) on at least the
> > rules of variable substitution.
> > 
> > Our DESCRIPION says
> > 
> >  There are seven different types of lines in a makefile: dependency 
> > lines,
> >  shell commands, variable assignments, include statements, conditional
> >  directives, for loops, and comments.  Of these, include statements,
> >  conditional directives and for loops are extensions.
> > 
> > but our VARIABLES merely explains
> > 
> >  Variable substitution occurs at two distinct times, depending on where
> >  the variable is being used.  Variables in dependency lines are expanded
> >  as the line is read.  Variables in shell commands are expanded when the
> >  shell command is executed.
> > 
> > and therefore fails to explain behaviour for the other five line types.
> > 
> > 
> > http://man.netbsd.org/make.1#VARIABLE%20ASSIGNMENTS (same as FreeBSD in
> > this regard) does go into more detail here:
> > 
> > Variable substitution occurs at three distinct times, depending on where
> >  the variable is being used.
> > 
> >  1.   Variables in dependency lines are expanded as the line is 
> > read.
> > 
> >  2.   Variables in shell commands are expanded when the shell 
> > command is
> >   executed.
> > 
> >  3.   ``.for'' loop index variables are expanded on each loop 
> > iteration.
> >   Note that other variables are not expanded inside loops so 
> > the fol-
> >   lowing example code:
> > 
> >   [...]
> > 
> > 
> > Diff below sync this list in VARIABLES as is.
> > 
> > After that I'd like to expand it and explain behaviour for other types;
> > I've scratched my head on make's behaviour for too long and the manual
> > failed to cover this completely.
> > 
> > Feedback? OK?
> 
> I came across this again, so I would really like to fix our manual.

The sparc64 ofwboot libz dependency bug reminded me of our make(1) still
missing different cases of variable expansion.

> In https://marc.info/?l=openbsd-tech=160935207004852=2
> on 2020-12-30 espie said:
> > I do think we want to write something specific for .for loop variables
> > which are actually very special compared to the rest.
> > 
> > I'm not incredibly happy with the way netbsd explains it, not surprisingly.
> 
> which didn't result in any update to our manual.
> 
> I'm still in favour of syncing with NetBSD (first), they're wording and
> example explains the missing pieces.
> 
> We can gladly polish things afterwards if someone comes up with
> something better.
> 
> OK?

No feedback whatsoever.

Anyone willing to OK either the previous NetBSD/FreeBSD sync diff or the
following minimal one which just mentions missing types?

We can always improve from there, but being stuck at an incomplete and
thus misleading manual sucks.


Index: make.1
===
RCS file: /cvs/src/usr.bin/make/make.1,v
retrieving revision 1.131
diff -u -p -r1.131 make.1
--- make.1  26 Jan 2020 12:40:50 -  1.131
+++ make.1  30 Dec 2020 17:36:54 -
@@ -600,9 +600,9 @@ If the variable name contains only a sin
 braces or parentheses are not required.
 This shorter form is not recommended.
 .Pp
-Variable substitution occurs at two distinct times, depending on where
-the variable is being used.
-Variables in dependency lines are expanded as the line is read.
+Variable substitution occurs at distinct times, depending on the type of line.
+Variables in dependency lines, conditinal directives and include statements are
+expanded as the line is read.
 Variables in shell commands are expanded when the shell command is
 executed.
 .Pp



Re: make.1: sync variable substitution bits with NetBSD

2021-11-13 Thread Klemens Nanni
On Sat, Dec 26, 2020 at 05:19:55PM +0100, Klemens Nanni wrote:
> Our make(1) is behind NetBSD's and FreeBSD's make(1) on at least the
> rules of variable substitution.
> 
> Our DESCRIPION says
> 
>  There are seven different types of lines in a makefile: dependency lines,
>  shell commands, variable assignments, include statements, conditional
>  directives, for loops, and comments.  Of these, include statements,
>  conditional directives and for loops are extensions.
> 
> but our VARIABLES merely explains
> 
>  Variable substitution occurs at two distinct times, depending on where
>  the variable is being used.  Variables in dependency lines are expanded
>  as the line is read.  Variables in shell commands are expanded when the
>  shell command is executed.
> 
> and therefore fails to explain behaviour for the other five line types.
> 
> 
> http://man.netbsd.org/make.1#VARIABLE%20ASSIGNMENTS (same as FreeBSD in
> this regard) does go into more detail here:
> 
> Variable substitution occurs at three distinct times, depending on where
>  the variable is being used.
> 
>  1.   Variables in dependency lines are expanded as the line is read.
> 
>  2.   Variables in shell commands are expanded when the shell command 
> is
>   executed.
> 
>  3.   ``.for'' loop index variables are expanded on each loop 
> iteration.
>   Note that other variables are not expanded inside loops so the 
> fol-
>   lowing example code:
> 
>   [...]
> 
> 
> Diff below sync this list in VARIABLES as is.
> 
> After that I'd like to expand it and explain behaviour for other types;
> I've scratched my head on make's behaviour for too long and the manual
> failed to cover this completely.
> 
> Feedback? OK?

I came across this again, so I would really like to fix our manual.

In https://marc.info/?l=openbsd-tech=160935207004852=2
on 2020-12-30 espie said:
> I do think we want to write something specific for .for loop variables
> which are actually very special compared to the rest.
> 
> I'm not incredibly happy with the way netbsd explains it, not surprisingly.

which didn't result in any update to our manual.

I'm still in favour of syncing with NetBSD (first), they're wording and
example explains the missing pieces.

We can gladly polish things afterwards if someone comes up with
something better.

OK?

Index: make.1
===
RCS file: /cvs/src/usr.bin/make/make.1,v
retrieving revision 1.134
diff -u -p -r1.134 make.1
--- make.1  11 Nov 2021 20:42:54 -  1.134
+++ make.1  13 Nov 2021 09:58:34 -
@@ -600,11 +600,48 @@ If the variable name contains only a sin
 braces or parentheses are not required.
 This shorter form is not recommended.
 .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
 .Pp
 The four different classes of variables (in order of increasing precedence)
 are:



Re: make.1: sync variable substitution bits with NetBSD

2020-12-30 Thread Klemens Nanni
On Wed, Dec 30, 2020 at 07:12:58PM +0100, Marc Espie wrote:
> I do think we want to write something specific for .for loop variables
> which are actually very special compared to the rest.
> 
> I'm not incredibly happy with the way netbsd explains it, not surprisingly.
Do you want to work on this in-tree after sync?



Re: make.1: sync variable substitution bits with NetBSD

2020-12-30 Thread Marc Espie
I do think we want to write something specific for .for loop variables
which are actually very special compared to the rest.

I'm not incredibly happy with the way netbsd explains it, not surprisingly.



make.1: sync variable substitution bits with NetBSD

2020-12-26 Thread Klemens Nanni
Our make(1) is behind NetBSD's and FreeBSD's make(1) on at least the
rules of variable substitution.

Our DESCRIPION says

 There are seven different types of lines in a makefile: dependency lines,
 shell commands, variable assignments, include statements, conditional
 directives, for loops, and comments.  Of these, include statements,
 conditional directives and for loops are extensions.

but our VARIABLES merely explains

 Variable substitution occurs at two distinct times, depending on where
 the variable is being used.  Variables in dependency lines are expanded
 as the line is read.  Variables in shell commands are expanded when the
 shell command is executed.

and therefore fails to explain behaviour for the other five line types.


http://man.netbsd.org/make.1#VARIABLE%20ASSIGNMENTS (same as FreeBSD in
this regard) does go into more detail here:

Variable substitution occurs at three distinct times, depending on where
 the variable is being used.

 1.   Variables in dependency lines are expanded as the line is read.

 2.   Variables in shell commands are expanded when the shell command is
  executed.

 3.   ``.for'' loop index variables are expanded on each loop iteration.
  Note that other variables are not expanded inside loops so the 
fol-
  lowing example code:

  [...]


Diff below sync this list in VARIABLES as is.

After that I'd like to expand it and explain behaviour for other types;
I've scratched my head on make's behaviour for too long and the manual
failed to cover this completely.

Feedback? OK?


Index: make.1
===
RCS file: /cvs/src/usr.bin/make/make.1,v
retrieving revision 1.131
diff -u -p -r1.131 make.1
--- make.1  26 Jan 2020 12:40:50 -  1.131
+++ make.1  26 Dec 2020 16:17:51 -
@@ -600,11 +600,48 @@ If the variable name contains only a sin
 braces or parentheses are not required.
 This shorter form is not recommended.
 .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
 .Pp
 The four different classes of variables (in order of increasing precedence)
 are: