andrea m.
andrea m.

Reputation: 688

How do I force make to clean and recompile after changes to Makefile itself?

I sometimes change the Makefile but that change itself does not cause make to recompile my sources.

I tried something like this (EXEC is my executable, clean is the usual deletion of source and intermediate compilation output)

$(EXEC): Makefile
         make clean
         make

but this generates an infinite loop... any idea?

Upvotes: 0

Views: 1203

Answers (1)

MadScientist
MadScientist

Reputation: 100836

What you have can't work because after make clean the $(EXEC) file won't exist, so it's always out of date, so it's always rebuilt, and the rebuild will run clean then re-exec itself, so again it will be out of date, so again make will run clean then re-exec itself, etc.

To do what you want you need to list the makefile as a prerequisite of all of the targets. Then you don't need to run clean or re-run make, because all the targets will be out of date when the makefile changes, just as they'd be out of date if the source file changed. So, as an example, add Makefile as a prerequisite to your object file targets:

%.o : %.c Makefile
        $(CC) $(CFLAGS) -c -o $@ $<

Without knowing anything about the rest of your makefile we can't give more specific advice than that.

Upvotes: 2

Related Questions