Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to force make to run clean target if makefile changed

Tags:

makefile

If makefile changes, make rebuilds all targets right?

But how to tell make that if after makefile changed, it shall run make clean and then make?

Or how to instruct make to run some other command in that situation? Do I have to write a special kind of target?

like image 402
devemouse Avatar asked May 05 '11 06:05

devemouse


2 Answers

Crude but effective (I can't think of anything more elegant):

include marker

marker: Makefile
    @touch $@
    $(MAKE) clean
    $(MAKE)
like image 155
Beta Avatar answered Nov 18 '22 17:11

Beta


You could try this:

all: Makefile.uptodate yourMainTarget

Makefile.uptodate: Makefile
    make clean
    touch Makefile.uptodate

I'm not a make expert so I don't know if that's a horrible hack, but it worked in my limited tests ;-)

like image 4
Joachim Sauer Avatar answered Nov 18 '22 17:11

Joachim Sauer