bugmake - Bugs: bug #61955, Remade Makefiles & Phony...

 
 

bug #61955: Remade Makefiles & Phony Targets

Submitter:  None
Submitted:  Fri 28 Jan 2022 08:56:59 PM UTC
   
 
Severity:  3 - Normal Item Group:  Documentation
Status:  Duplicate Privacy:  Public
Assigned to:  None Open/Closed:  Closed
Component Version:  4.3 Operating System:  POSIX-Based
Fixed Release:  None Triage Status:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Wed 03 Aug 2022 04:17:02 AM UTC, comment #3: 

Duplicate of bug #61623

Paul D. Smith <psmith>
Group administrator
Sat 29 Jan 2022 01:20:53 AM UTC, comment #2: 


> 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.

Dmitry Goncharov <dgoncharov>
Fri 28 Jan 2022 11:15:36 PM UTC, 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 $@


Paul D. Smith <psmith>
Group administrator
Fri 28 Jan 2022 08:56:59 PM UTC, original submission:  

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 <http://gnu.org/licenses/gpl.html>
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 <http://gnu.org/licenses/gpl.html>
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 <http://gnu.org/licenses/gpl.html>
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 <http://gnu.org/licenses/gpl.html>
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 <http://gnu.org/licenses/gpl.html>
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 <http://gnu.org/licenses/gpl.html>
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


Anonymous

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by dgoncharov (Posted a comment)
  • -email is unavailable- added by psmith (Posted a comment)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only logged-in users can vote.

     

    Follow 3 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2022-08-03 psmith StatusNone Duplicate
        Open/ClosedOpen Closed
    2022-01-28 psmith Item GroupBug Documentation

    Back to the top

    Powered by Savane 3.13-3230.
    Corresponding source code