Learning Make with the Towers of Hanoi


of the : (e.g. foo.o) and $< to the file on the right-hand side (e.g. foo.c). As before $* is set to the part of the filename that is matched by the % (e.g. foo). No Phony PatternsEarlier I mentioned that the all target is phony because it's not a real file and we don't want Make confused if there were a real file called all in the current directory. The same is true for the other targets in this example. For example, if there were a file called a-c.D then we'd never see the messages for moving a disc from peg a to peg c. What you'd like to specify is something like:

.PHONY: a-c.%

so that any movement of discs from a to c would be considered phony. Unfortunately, there's no such syntax in GNU Make, .PHONY can only be used with explicit target names and trying to specify all the possible combinations of a, b, c and different numbers of D's would be impossible. ConclusionThe designers of Make didn't intend it to be used in this way, but it's a good example of the power of GNU Make that it can solve a puzzle like the Towers of Hanoi. Next month I'll get back to more mundane topics and show you a single character you can insert into your Makefiles to speed them up.

About the author

AgileConnection is one of the growing communities of the TechWell network.

Featuring fresh, insightful stories, TechWell.com is the place to go for what is happening in software development and delivery.  Join the conversation now!