On 09/15/2017 06:52 PM, Christopher Li wrote: > On Thu, Sep 14, 2017 at 2:45 PM, Uwe Kleine-König <uwe@xxxxxxxxxxxxxxxxx> wrote: >> >> -# Generating file version.h if current version has changed >> SPARSE_VERSION:=$(shell git describe 2>/dev/null || echo '$(VERSION)') >> -VERSION_H := $(shell cat version.h 2>/dev/null) >> -ifneq ($(lastword $(VERSION_H)),"$(SPARSE_VERSION)") >> -$(info $(shell echo ' GEN 'version.h)) >> -$(shell echo '#define SPARSE_VERSION "$(SPARSE_VERSION)"' > version.h) >> -endif > > You don't need to move them to into a rule section. > > You can use "ifneq ($(MAKECMDGOALS),clean)" So it still triggers when doing make clean all Also you don't want to generate it for $(make check). IMHO that's hardly manageable to get done consistently this way and the easiest is a separate rule for version.h that is triggered by make dependencies as I suggested > to wrap it. GNU make document even show that as examples > of using $(MAKECMDGOALS). IMHO that is no prove that the idea is sane. >> +version.h: FORCE >> + $(QUIET_GEN)echo '#define SPARSE_VERSION "$(SPARSE_VERSION)"' > version.h.tmp; \ >> + if cmp -s version.h version.h.tmp; then \ >> + rm version.h.tmp; \ >> + else \ >> + mv version.h.tmp version.h; \ >> + fi >> + >> +.PHONY: FORCE >> + >> +lib.o: version.h >> + > > The above section is not needed if you use the ifneq test on $(MAKECMDGOALS).> I also test it and found the problem that, the version.h was force > to obsolete. Two consequent make will always show "GEN version.h" > line. Then maybe split it into CHECK version.h GEN version.h ? The GEN would be skipped if version.h doesn't need an update. Best regards Uwe
Attachment:
signature.asc
Description: OpenPGP digital signature