[bug #61957] Document the side effect of mentioning a file explicitly.

2022-01-28 Thread Dmitry Goncharov
Additional Item Attachment, bug #61957 (project make):

File name: sv61957_side_effect_doc.diff   Size:1 KB
   




___

Reply to this item at:

  

___
  Message sent via Savannah
  https://savannah.gnu.org/




[bug #61957] Document the side effect of mentioning a file explicitly.

2022-01-28 Thread Dmitry Goncharov
URL:
  

 Summary: Document the side effect of mentioning a file
explicitly.
 Project: make
Submitted by: dgoncharov
Submitted on: Sat 29 Jan 2022 01:32:57 AM UTC
Severity: 3 - Normal
  Item Group: Documentation
  Status: None
 Privacy: Public
 Assigned to: None
 Open/Closed: Open
 Discussion Lock: Any
   Component Version: SCM
Operating System: None
   Fixed Release: None
   Triage Status: None

___

Details:

Mentioning a file explicitly in order to prevent the file from being
intermediate has the side effect of making rules which depend on this implicit
prerequisite eligible for compatibility search.

The patch in the attachment documents this side effect and adds a hint of how
to avoid it.




___

Reply to this item at:

  

___
  Message sent via Savannah
  https://savannah.gnu.org/




[bug #61955] Remade Makefiles & Phony Targets

2022-01-28 Thread Dmitry Goncharov
Follow-up Comment #2, bug #61955 (project make):

> I see that this is not documented in the manual so that should be fixed; > I
will convert this into a documentation bug.


Еhere is https://savannah.gnu.org/bugs/?61623 with a patch that documents
phony makefile targets.

___

Reply to this item at:

  

___
  Message sent via Savannah
  https://savannah.gnu.org/




[bug #61955] Remade Makefiles & Phony Targets

2022-01-28 Thread Paul D. Smith
Update of bug #61955 (project make):

  Item Group: Bug => Documentation  

___

Follow-up Comment #1:

You say you have a makefile that you "always want rebuilt", but that's not
really true.  What you actually want is to rebuild the makefile exactly one
time every time you run the make command.

When make re-execs itself to reload makefiles, no state is preserved from the
previous invocation (other than MAKE_RESTARTS).  So, the second instance of
make has no idea that the first instance already rebuilt the target, other
than due to normal methods of checking timestamps.

If you achieved the goal of "always rebuilding" the makefile, then make would
recurse forever rebuilding the makefile and re-exec'ing itself.  Each instance
would say: do I need to update test.mk?  And each time the answer would be
"yes", so it would update it then re-exec itself, and that instance would do
the same thing.

> note how test.mk is generated but MAKE_RESTARTS is not set.

Make has a special case for PHONY included makefiles; the comments say:


Check for makefiles that are either phony or a :: target with
commands, but no dependencies.  These will always be remade,
which will cause an infinite restart loop, so don't try to
remake it


I see that this is not documented in the manual so that should be fixed; I
will convert this into a documentation bug.

In the next release of GNU make this situation is noted in a debug message:


Makefile 'test.mk' might loop; not remaking it.


> sometimes Make restarts more than one time, which is unexpected.

No, it's completely expected.  In fact in a perfect system make would recurse
forever and never stop, but in fact in most systems today make is able to
restart itself so fast that the timestamp of the FORCE target (which is "now")
is the same as the timestamp on the file and once that happens make decides
that the included file does not get remade and does not re-exec.

If you want the included file to be remade exactly one time, then you should
do that.  One way is to ensure that the makefile doesn't exist the first time,
and only that time, something like:


ifeq ($(MAKE_RESTARTS),)
  _ := $(shell rm -f test.mk)
endif
include test.mk

...

test.mk: ; touch $@


___

Reply to this item at:

  

___
  Message sent via Savannah
  https://savannah.gnu.org/




Re: [BUG] --warn-undefined-variable is not triggered in prerequisites

2022-01-28 Thread Paul Smith
On Fri, 2022-01-28 at 01:09 +0100, Alejandro Colomar (man-pages) wrote:
> I'd like make to warn about this.  It took me a while to debug 
> a Makefile bug, which I thought was not happening, since make should
> have warned me.  Isn't this supposed to trigger the warning?

In previous versions of GNU make, the value of MAKEFLAGS set inside a
makefile is only re-parsed once before all makefiles are read (from the
environment) and again after all makefiles are read.

So, changes to this variable within the makefile don't take effect
until after all makefiles are parsed.  In your situation the variable
in question is part of a prerequisite list and that's expanded while
parsing the makefile, so the option is not set yet and you don't get
warnings.  Undefined variables used in a recipe WOULD be warned about
since recipes are expanded after all makefiles are parsed.

To make this option do what you want you must pass it in either via the
command line:

   $ make --warn-undefined-variables

or the environment:

   $ MAKEFLAGS=--warn-undefined-variables make

or:

   $ GNUMAKEFLAG=--warn-undefined-variables make

In the next release of GNU make, this has been changed; from the NEWS
file:

* If the MAKEFLAGS variable is modified in a makefile, it will be re-parsed
  immediately rather than after all makefiles have been read.  Note that
  although all options are parsed immediately, some special effects won't
  appear until after all makefiles are read.




Re: [BUG] --warn-undefined-variable is not triggered in prerequisites

2022-01-28 Thread Alejandro Colomar (man-pages)
Hi Paul,

On 1/28/22 23:49, Paul Smith wrote:
> On Fri, 2022-01-28 at 01:09 +0100, Alejandro Colomar (man-pages) wrote:
>> I'd like make to warn about this.  It took me a while to debug 
>> a Makefile bug, which I thought was not happening, since make should
>> have warned me.  Isn't this supposed to trigger the warning?
> 
> In previous versions of GNU make, the value of MAKEFLAGS set inside a
> makefile is only re-parsed once before all makefiles are read (from the
> environment) and again after all makefiles are read.
> 
> So, changes to this variable within the makefile don't take effect
> until after all makefiles are parsed.  In your situation the variable
> in question is part of a prerequisite list and that's expanded while
> parsing the makefile, so the option is not set yet and you don't get
> warnings.  Undefined variables used in a recipe WOULD be warned about
> since recipes are expanded after all makefiles are parsed.
> 
> To make this option do what you want you must pass it in either via the
> command line:
> 
>$ make --warn-undefined-variables
> 
> or the environment:
> 
>$ MAKEFLAGS=--warn-undefined-variables make
> 
> or:
> 
>$ GNUMAKEFLAG=--warn-undefined-variables make
> 
> In the next release of GNU make, this has been changed; from the NEWS
> file:
> 
> * If the MAKEFLAGS variable is modified in a makefile, it will be re-parsed
>   immediately rather than after all makefiles have been read.  Note that
>   although all options are parsed immediately, some special effects won't
>   appear until after all makefiles are read.

Sounds like good news :)

I'll be waiting for that release!

Cheers,

Alex


-- 
Alejandro Colomar
Linux man-pages comaintainer; https://www.kernel.org/doc/man-pages/
http://www.alejandro-colomar.es/



Re: [BUG] --warn-undefined-variable is not triggered in prerequisites

2022-01-28 Thread Alejandro Colomar (man-pages)
Hi Martin,

On 1/28/22 02:42, Martin Dorey wrote:
> That already seems to have been fixed:
Hmm, it seems that the bug is only triggered if the option is passed in
the Makefile itself with MAKEFLAGS+=...


I haven't tested make git HEAD, but I bet it's probably reproducible
there too.  See below.

Thanks,

Alex



$ make --version
GNU Make 4.3
Built for x86_64-pc-linux-gnu
Copyright (C) 1988-2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later

This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
$ dpkg -l make | grep make
ii  make   4.3-4.1  amd64utility for directing
compilation
$ cat Makefile
MAKEFILE += --warn-undefined-variables

.PHONY: a
a: $(foo)
$(info a)
@:
$ make
a
$ make --warn-undefined-variables
Makefile:4: warning: undefined variable 'foo'
a



-- 
Alejandro Colomar
Linux man-pages comaintainer; https://www.kernel.org/doc/man-pages/
http://www.alejandro-colomar.es/



[bug #61955] Remade Makefiles & Phony Targets

2022-01-28 Thread anonymous
URL:
  

 Summary: Remade Makefiles & Phony Targets
 Project: make
Submitted by: None
Submitted on: Fri 28 Jan 2022 08:56:59 PM UTC
Severity: 3 - Normal
  Item Group: Bug
  Status: None
 Privacy: Public
 Assigned to: None
 Open/Closed: Open
 Discussion Lock: Any
   Component Version: 4.3
Operating System: POSIX-Based
   Fixed Release: None
   Triage Status: None

___

Details:

Hi!

I am using make v4.3.

I have a Makefile I always want rebuilt, and included.

include test.mk

.PHONY: all
all:
@echo MAKE_RESTARTS: $(MAKE_RESTARTS)

.PHONY: test.mk
test.mk:
touch $@


this results in:

make --debug
GNU Make 4.3
Built for x86_64-pc-linux-gnu
Copyright (C) 1988-2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later 
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Reading makefiles...
Updating makefiles
touch test.mk
Updating goal targets
 File 'all' does not exist.
Must remake target 'all'.
MAKE_RESTARTS:
Successfully remade target file 'all'.


note how test.mk is generated but MAKE_RESTARTS is not set.

Using the FORCE approach documented here:
https://www.gnu.org/software/make/manual/html_node/Force-Targets.html

include test.mk

.PHONY: all
all:
@echo MAKE_RESTARTS: $(MAKE_RESTARTS)

FORCE:
test.mk: FORCE
touch $@


results in somewhat expected behavior. test.mk is generated and MAKE_RESTARTS
is set. sometimes Make restarts more than one time, which is unexpected.


➜  test make --debug
GNU Make 4.3
Built for x86_64-pc-linux-gnu
Copyright (C) 1988-2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later 
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Reading makefiles...
Updating makefiles
touch test.mk
Re-executing[1]: make --debug
GNU Make 4.3
Built for x86_64-pc-linux-gnu
Copyright (C) 1988-2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later 
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Reading makefiles...
Updating makefiles
touch test.mk
Updating goal targets
 File 'all' does not exist.
Must remake target 'all'.
MAKE_RESTARTS: 1
Successfully remade target file 'all'.
➜  test make --debug
GNU Make 4.3
Built for x86_64-pc-linux-gnu
Copyright (C) 1988-2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later 
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Reading makefiles...
Updating makefiles
touch test.mk
Re-executing[1]: make --debug
GNU Make 4.3
Built for x86_64-pc-linux-gnu
Copyright (C) 1988-2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later 
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Reading makefiles...
Updating makefiles
touch test.mk
Re-executing[2]: make --debug
GNU Make 4.3
Built for x86_64-pc-linux-gnu
Copyright (C) 1988-2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later 
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Reading makefiles...
Updating makefiles
touch test.mk
Updating goal targets
 File 'all' does not exist.
Must remake target 'all'.
MAKE_RESTARTS: 2






___

Reply to this item at:

  

___
  Message sent via Savannah
  https://savannah.gnu.org/