bug-make
[Top][All Lists]
Advanced

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

Re: Make: Unexpected Behavior with Dependencies and include Statement


From: Mike Shal
Subject: Re: Make: Unexpected Behavior with Dependencies and include Statement
Date: Wed, 23 Sep 2015 13:06:26 -0400


On Wed, Sep 23, 2015 at 12:57 PM, John Westing <address@hidden> wrote:
I made a typo in my previous email: The following make file duplicates the problem, the one in the previous email does not:

    a.d:
        gcc -m32 -MM -o $@ a.c
        sed 's!a.o!$@ a.o!' --in-place $@
    
    a.o:
        gcc -c -m32 -o $@ a.c
    
    all: a.d a.o
    
    -include a.d



See: https://www.gnu.org/software/make/manual/html_node/Remaking-Makefiles.html#Remaking-Makefiles

Specifically, after reading all the Makefiles (like "a.d", since it's included), if any of them need to be rebuilt, it will be updated and then make re-executes itself. You can get a clue that this is happening by adding $(info Starting make) or something at the top of your Makefile. Then you'll see:

Starting make
gcc -m32 -MM -o a.d a.c
sed 's!a.o!a.d a.o!' --in-place a.d
Starting make
make: 'a.d' is up to date.

So make runs, sees that a.d needs to be updated, updates it automatically, restarts, re-reads all the Makfiles, and now it tries to build 'a.d' since you specified that as a target.

Though normally you don't want to include .d files as targets in your Makefile. Just generate them as a side-effect of compilation with -MMD or whatever in gcc and then include them, and you can avoid the whole issue.

-Mike

reply via email to

[Prev in Thread] Current Thread [Next in Thread]