I use a file to remember the last value of such options, like this:
.PHONY: force
compiler_flags: force
echo '$(CC_FLAGS)' | cmp -s - $@ || echo '$(CC_FLAGS)' > $@
The cmp || echo
bit means the file compiler_flags
is only touched when the setting changes, so now you can write something like
$(OBJECTS): compiler_flags
to cause a rebuild of $(OBJECTS)
whenever the compiler flags change. The rule for compiler_flags will be executed every time you run make, but a rebuild of $(OBJECTS)
will be triggered only if the compiler_flags
file was actually modified.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…