Fix unescaping in matlab, miniMAL and rpython.
[jackhill/mal.git] / common-lisp / Makefile
1 # Helper functions
2 define record_lisp
3 $(shell (test -f "hist/$(1)_impl" && grep -q $(2) "hist/$(1)_impl") || echo $(2) > "hist/$(1)_impl")
4 endef
5
6 define steps
7 $(if $(MAKECMDGOALS),\
8 $(if $(findstring all,$(MAKECMDGOALS)),\
9 stepA_mal,\
10 $(filter step%, $(MAKECMDGOALS))),\
11 stepA_mal)
12 endef
13
14 LISP ?= sbcl
15 ABCL ?= abcl
16 MKCL ?= mkcl
17
18 # TODO: In theory cl-launch should be able to build standalone executable using
19 # MKCL unfortunately the executable crashes on startup
20 STANDALONE_EXE = sbcl clisp ccl ecl cmucl
21
22 ROOT_DIR := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
23 SOURCES_LISP := src/env.lisp src/core.lisp src/stepA_mal.lisp
24 SOURCES := src/utils.lisp src/types.lisp src/reader.lisp src/printer.lisp $(SOURCES_LISP)
25
26 # Record the Common Lisp implementation used for all steps built in this
27 # invocation This is used in the targets to rebuild the step if the
28 # implementation changes
29 $(foreach step, $(call steps), $(call record_lisp,$(patsubst step%,%,$(step)),$(LISP)))
30
31 .PRECIOUS: hist/%_impl
32 .PHONY: stats
33
34 all : stepA_mal
35
36 hist/%_impl: ;
37
38 # CL_LAUNCH_VERSION is only defined while building it. We change to the
39 # directory of the CL_LAUNCH_FILE in --wrap script so that the script can find the dumped
40 # image even if invoked from some directory different from where it
41 # currently resides
42 step% : src/step%.lisp src/utils.lisp src/types.lisp src/env.lisp src/printer.lisp src/reader.lisp src/core.lisp hist/%_impl
43
44 ifeq ($(LISP),clisp)
45 @echo "=============================================================="
46 @echo "WARNING: This build might fail since GNU Clisp does not have bundled version of asdf (yet)"
47 @echo "Please do something like below to make it work"
48 @echo "(mkdir -p ~/common-lisp/ && cd ~/common-lisp && git clone -b release https://gitlab.common-lisp.net/asdf/asdf.git && cd asdf && make)"
49 @echo "=============================================================="
50 endif
51
52 ifneq ($(filter $(LISP),$(STANDALONE_EXE)),)
53 cl-launch --wrap 'if [ -z "$$CL_LAUNCH_VERSION" ] ; then cd "$$(dirname $$CL_LAUNCH_FILE)" ; fi' --verbose --lisp $(LISP) --source-registry $(ROOT_DIR) --system $@ --dump '!' -o $@ --entry 'mal:main'
54 else ifeq ($(LISP),abcl)
55 echo -n '#!/bin/sh\ncd `dirname $$0` ; $(ABCL) --noinform --noinit --nosystem --load run-abcl.lisp -- $@ $$@' > $@
56 chmod +x $@
57 else ifeq ($(LISP),mkcl)
58 $(MKCL) -eval '(progn (require "asdf") (push *default-pathname-defaults* asdf:*central-registry*) (asdf:load-system "$@") (quit))'
59 echo -n '#!/bin/sh\ncd `dirname $$0` ; $(MKCL) -q -load run-mkcl.lisp -- $@ $$@' > $@
60 chmod +x $@
61 else ifeq ($(LISP),allegro)
62 cl-launch --wrap 'if [ -z "$$CL_LAUNCH_VERSION" ] ; then cd "$$(dirname $$CL_LAUNCH_FILE)" ; fi' --verbose --lisp $(LISP) --source-registry $(ROOT_DIR) --system $@ --dump images/$@.$(LISP).image -o $@ --entry 'mal:main'
63 else
64 @echo "Unsupported Lisp implementation $(LISP)"
65 @exit 1
66 endif
67
68 clean:
69 find . -maxdepth 1 -name 'step*' -executable -delete
70 rm -f *.lib *.fas[l] images/* hist/*_impl
71
72 stats: $(SOURCES)
73 @wc $^
74 @printf "%5s %5s %5s %s\n" `grep -E "^[[:space:]]*;|^[[:space:]]*$$" $^ | wc` "[comments/blanks]"
75
76 stats-lisp: $(SOURCES_LISP)
77 @wc $^
78 @printf "%5s %5s %5s %s\n" `grep -E "^[[:space:]]*;|^[[:space:]]*$$" $^ | wc` "[comments/blanks]"