Common Lisp: Keep track of the implementation used to build a step
authorIqbal Ansari <iqbalansari02@yahoo.com>
Tue, 15 Nov 2016 18:54:49 +0000 (00:24 +0530)
committerIqbal Ansari <iqbalansari02@yahoo.com>
Fri, 18 Nov 2016 12:41:20 +0000 (18:11 +0530)
Rebuild the step if the implementation changes

.gitignore
common-lisp/Makefile
common-lisp/hist/.keepdir [new file with mode: 0644]

index a640383..9620846 100644 (file)
@@ -119,6 +119,7 @@ basic/step8_macros.bas
 basic/step9_try.bas
 basic/stepA_mal.bas
 basic/*.prg
-common-lisp/*.image
 common-lisp/*.fasl
 common-lisp/*.lib
+common-lisp/images/*
+common-lisp/hist/*
index 7701f17..c3cd49e 100644 (file)
@@ -1,18 +1,39 @@
-ROOT_DIR = $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
-SOURCES_LISP = env.lisp core.lisp stepA_mal.lisp
-SOURCES = utils.lisp types.lisp reader.lisp printer.lisp $(SOURCES_LISP)
+# Helper functions
+define record_lisp
+       $(shell (test -f "hist/$(1)_impl" && grep -q $(2) "hist/$(1)_impl") || echo $(2) > "hist/$(1)_impl")
+endef
+
+define steps
+       $(if $(MAKECMDGOALS),\
+               $(if $(findstring all,$(MAKECMDGOALS)),\
+                       stepA_mal,\
+                       $(filter step%, $(MAKECMDGOALS))),\
+               stepA_mal)
+endef
+
+ROOT_DIR := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
+SOURCES_LISP := env.lisp core.lisp stepA_mal.lisp
+SOURCES := utils.lisp types.lisp reader.lisp printer.lisp $(SOURCES_LISP)
 LISP ?= sbcl
 
-all : stepA_mal
+# Record the Common Lisp implementation used for all steps built in this
+# invocation This is used in the targets to rebuild the step if the
+# implementation changes
+$(foreach step, $(call steps), $(call record_lisp,$(patsubst step%,%,$(step)),$(LISP)))
 
+.PRECIOUS: hist/%_impl
 .PHONY: stats
 
-step% : step%.lisp utils.lisp types.lisp env.lisp printer.lisp reader.lisp core.lisp
-       cl-launch -v -l $(LISP) +Q -S $(ROOT_DIR) -s $@ -d $@.image -o $@ -E 'mal:main' -e '(load "~/quicklisp/setup.lisp")'
+all : stepA_mal
+
+hist/%_impl: ;
+
+step% : step%.lisp utils.lisp types.lisp env.lisp printer.lisp reader.lisp core.lisp hist/%_impl
+       cl-launch --verbose --lisp $(LISP) --source-registry $(ROOT_DIR) --system $@ --dump images/$@.$(LISP).image -o $@ --entry 'mal:main'
 
 clean:
        find . -name 'step*' -executable -exec git check-ignore \{\} \; -delete
-       rm -f *.lib *.fas[l]
+       rm -f *.lib *.fas[l] images/* hist/*_impl
 
 stats: $(SOURCES)
        @wc $^
diff --git a/common-lisp/hist/.keepdir b/common-lisp/hist/.keepdir
new file mode 100644 (file)
index 0000000..e69de29