kernelthread.com

GNU Makefile

The Towers of Hanoi as GNU Makefile.

# # The Towers Of Hanoi # GNU Make # Copyright (C) 1999 Amit Singh. All Rights Reserved. # http://hanoi.kernelthread.com # # hanoi.mk # Last tested with GNU Make version 3.79.1 # # Use the following command to solve a 3 (say) disk puzzle: # # make -f hanoi.mk N=3 # # WARNING: THIS IS RECURSIVE AT THE PROCESS LEVEL! DO NOT TRY # "TOO BIG" VALUES OF N! YOU HAVE BEEN WARNED. # # If you change the name of this makefile to anything other than # 'hanoi.mk', then either change the "MAKEFILE = ..." line below # appropriately, or pass "MAKEFILE=..." on the make command line # itself. For example, if you change the name of this makefile to # 'foo', say, then: # # make -f foo N=3 MAKEFILE=foo # ifndef $(INITIALIZED) MAKEFILE = hanoi.mk F = 1 U = 2 T = 3 INITIALIZED = 1 endif all: hanoi hanoi: ifeq ($N,1) @echo "$(F) --> $(T)" else @$(MAKE) -s -f $(MAKEFILE) F=$(F) U=$(T) T=$(U) N=$(shell expr $(N) - 1) @echo "$(F) --> $(T)" @$(MAKE) -s -f $(MAKEFILE) F=$(U) U=$(F) T=$(T) N=$(shell expr $(N) - 1) endif

Download

hanoi.mk