bugmake - Bugs: bug #51495, Notice when a rule changed, so...

 
 

bug #51495: Notice when a rule changed, so target needs rebuilding

Submitter:  Nadav Har'El <nyh>
Submitted:  Tue 18 Jul 2017 07:07:31 AM UTC
   
 
Severity:  3 - Normal Item Group:  Enhancement
Status:  None Privacy:  Public
Assigned to:  None Open/Closed:  Open
Component Version:  None Operating System:  Any
Fixed Release:  None Triage Status:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Fri 08 Mar 2019 09:36:14 AM UTC, comment #4: 

I have not read "GNU Make Book".

Anyway, IIRC, the document of ninja-build mentioned it had borrowed the idea from Linux Kernel build system.

Linux kernel build system works with GNU Make, and achieved the similar feature by meta-programming.

Masahiro Yamada <masahiroy>
Fri 08 Mar 2019 09:04:36 AM UTC, comment #3: 

FYI, an advanced trick to support automatic rebuilding when a rule is changed is explained in the "GNU Make Book"
by John Graham-Cumming, Chapter 3. So it's possible to emulate this functionality with some effort in Make's metaprogramming. Although, I admit, I'd prefer a built-in option.

Anonymous
Sun 30 Dec 2018 03:45:43 PM UTC, comment #2: 

Henrik, thanks, this is indeed a nice suggestion, which is indeed a trick worthy to appear in a make book :-)

It has two problems, though, compared to real built-in support for this feature:
The first problem is of course unwieldiness - it is harder and uglier to create a makefile this way (splitting it into many separate makefiles), and it's easier and more natural to just forget to do it - so most makefiles will continue not to enjoy this feature.
The second problem is that it doesn't support user-specified parameters. In your example, imagine that a user runs "make LDFLAGS="-lm -s". link.mk hasn't changed, so the makefile will not know that the linking stage needs to run again, even though the rule did change because LDFLAGS changed since the last run.

Nadav Har'El <nyh>
Tue 18 Jul 2017 01:46:08 PM UTC, comment #1: 

The quick and easy way to accomplish this today is of course to also add the Makefile to the prerequisites of targets. If you don't want every target to be rebuilt when only one rule has changed it is also possible to split the Makefile up into several files with only one rule in each file. Example:

Makefile:
-8<----------------------
all: myprog

include $(wildcard *.mk)
-8<----------------------

link.mk:
-8<----------------------
OBJFILES=file1.o file2.o
LDFLAGS=-lm

myprog: $(OBJFILES) link.mk
        gcc -o $@ $(OBJFILES) $(LDFLAGS)
-8<----------------------

compile.mk:
-8<----------------------
CFLAGS=-ansi -pedantic

%.o: %.c compile.mk
        gcc -c $(CFLAGS) -o $@ $<
-8<----------------------


Henrik Carlqvist <henca>
Tue 18 Jul 2017 07:07:31 AM UTC, original submission:  

It's no secret that in recent years, many alternatives to the classic "make" have come up. Most of them differ from "make" in non-interesting ways, which reflects more on their author's preferences than they are actual improvements. However, there are cases where such alternative build systems actually came up with new ideas which can be adopted by "make" without rewriting it. The idea I propose here comes from the "ninja" build system:

The problem this idea is trying to solve is that sometimes you modify the Makefile and change one or many of the rules (either directly or indirectly by modifying some variable), and running "make" does not rebuild anything because none of the dependency files changed. Sure, one can do "make clean; make". But it's very easy to forget and end up with a broken build.

What ninja does is to keep a file (.ninja_log in the build directory) which lists each of the targets that were built, with a hash of the rule that was used to build it. When building again, we consider a target as outdated not only if one of its dependencies is changed, but also if the target's rule no longer matches the saved hash.

Nadav Har'El <nyh>

 

(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 masahiroy (Posted a comment)
  • -email is unavailable- added by henca (Posted a comment)
  • -email is unavailable- added by nyh (Submitted the item)
  •  

    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.

     

    No changes have been made to this item

    Back to the top

    Powered by Savane 3.13-f8d8.
    Corresponding source code