## Wednesday, April 19, 2006

### A small bug fix to my keep state shoehorning

A while back I wrote about a way to shoehorn Sun Make's "keep state" functionality into GNU Make. With a fairly simple Makefile it's possible to get GNU Make to rebuild targets when the targets' commands have changed. I blogged this here and wrote it up for Ask Mr Make here.

One reader was having trouble with the system because every single Make he did caused a certain target to be built. It turned out this was because he'd done something like:
target:    $(call do, commands) The space after the , and before the commands was messing up my signature system's comparison and causing it to think that the commands changed every time. This is easily fixed by stripping the commands. Here's the updated signature file (with the changed parts highlighted in blue): include gmsllast_target := dump_var = \$$(eval 1 := (1))define new_rule@echo "(call map,dump_var,@ % < ? ^ + *)" > S@(if (wildcard F),,touch F)@echo @: F >> Sendefdefine do(eval S := *.sig)(eval F := *.force)(eval C := (strip 1))(if (call sne,@,(last_target)),(call new_rule),(eval last_target := @))@echo "(subst$$,\$$,$$(if $$(call sne,(strip 1),C),$$(shell touch$F)))" >> $S$Cendef

Another common thing people have asked for is that the signature system rebuild targets when the Makefile has changed. Currently the signature system cannot spot an edit to the Makefile that changes the commands. It's pretty simple to Make this happen (although this will cause all targets to be built when the Makefile is updated) by adding the following line in new_rule above: