2016-11-15 21:54:49 +03:00
|
|
|
# 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
|
|
|
|
|
2017-08-23 21:15:05 +03:00
|
|
|
LISP ?= sbcl
|
|
|
|
ABCL ?= abcl
|
2017-08-24 16:28:17 +03:00
|
|
|
MKCL ?= mkcl
|
2017-08-23 21:15:05 +03:00
|
|
|
|
2024-08-06 20:02:16 +03:00
|
|
|
BINS = step0_repl step1_read_print step2_eval step3_env step4_if_fn_do \
|
|
|
|
step5_tco step6_file step7_quote step8_macros step9_try stepA_mal
|
|
|
|
|
2017-08-24 16:28:17 +03:00
|
|
|
# TODO: In theory cl-launch should be able to build standalone executable using
|
|
|
|
# MKCL unfortunately the executable crashes on startup
|
2017-08-23 21:15:05 +03:00
|
|
|
STANDALONE_EXE = sbcl clisp ccl ecl cmucl
|
|
|
|
|
2016-11-15 21:54:49 +03:00
|
|
|
ROOT_DIR := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
|
2016-11-02 13:10:01 +03:00
|
|
|
|
2016-11-15 21:54:49 +03:00
|
|
|
# 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)))
|
2016-11-02 13:10:01 +03:00
|
|
|
|
2016-11-15 21:54:49 +03:00
|
|
|
.PRECIOUS: hist/%_impl
|
2016-11-02 13:10:01 +03:00
|
|
|
|
2024-08-06 20:02:16 +03:00
|
|
|
all : $(BINS)
|
2016-11-15 21:54:49 +03:00
|
|
|
|
|
|
|
hist/%_impl: ;
|
|
|
|
|
2016-11-18 14:16:15 +03:00
|
|
|
# CL_LAUNCH_VERSION is only defined while building it. We change to the
|
|
|
|
# directory of the CL_LAUNCH_FILE in --wrap script so that the script can find the dumped
|
|
|
|
# image even if invoked from some directory different from where it
|
|
|
|
# currently resides
|
2016-11-22 14:55:16 +03:00
|
|
|
step% : src/step%.lisp src/utils.lisp src/types.lisp src/env.lisp src/printer.lisp src/reader.lisp src/core.lisp hist/%_impl
|
2017-08-23 21:15:05 +03:00
|
|
|
|
|
|
|
ifeq ($(LISP),clisp)
|
|
|
|
@echo "=============================================================="
|
|
|
|
@echo "WARNING: This build might fail since GNU Clisp does not have bundled version of asdf (yet)"
|
|
|
|
@echo "Please do something like below to make it work"
|
|
|
|
@echo "(mkdir -p ~/common-lisp/ && cd ~/common-lisp && git clone -b release https://gitlab.common-lisp.net/asdf/asdf.git && cd asdf && make)"
|
|
|
|
@echo "=============================================================="
|
|
|
|
endif
|
|
|
|
|
|
|
|
ifneq ($(filter $(LISP),$(STANDALONE_EXE)),)
|
2024-08-06 20:02:16 +03:00
|
|
|
sbcl --eval '(load "~/quicklisp/setup.lisp")' --eval '(asdf:initialize-source-registry `(:source-registry (:tree "$(ROOT_DIR)") :inherit-configuration))' --eval '(ql:quickload :uiop)' --eval '(ql:quickload :cl-readline)' --eval '(ql:quickload :genhash)' --eval '(asdf:load-system "$@")' --eval '(asdf:operate :build-op "$@")' --eval "(save-lisp-and-die \"$@\" :executable t :toplevel #'(lambda () (mal:main)))" --quit
|
2017-08-23 21:15:05 +03:00
|
|
|
else ifeq ($(LISP),abcl)
|
2016-11-20 22:41:55 +03:00
|
|
|
echo -n '#!/bin/sh\ncd `dirname $$0` ; $(ABCL) --noinform --noinit --nosystem --load run-abcl.lisp -- $@ $$@' > $@
|
|
|
|
chmod +x $@
|
2017-08-24 16:28:17 +03:00
|
|
|
else ifeq ($(LISP),mkcl)
|
|
|
|
$(MKCL) -eval '(progn (require "asdf") (push *default-pathname-defaults* asdf:*central-registry*) (asdf:load-system "$@") (quit))'
|
|
|
|
echo -n '#!/bin/sh\ncd `dirname $$0` ; $(MKCL) -q -load run-mkcl.lisp -- $@ $$@' > $@
|
|
|
|
chmod +x $@
|
|
|
|
else ifeq ($(LISP),allegro)
|
2016-11-18 14:16:15 +03:00
|
|
|
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'
|
2017-08-24 16:28:17 +03:00
|
|
|
else
|
|
|
|
@echo "Unsupported Lisp implementation $(LISP)"
|
|
|
|
@exit 1
|
2016-11-20 22:41:55 +03:00
|
|
|
endif
|
2016-11-02 13:10:01 +03:00
|
|
|
|
|
|
|
clean:
|
2017-08-23 21:19:52 +03:00
|
|
|
find . -maxdepth 1 -name 'step*' -executable -delete
|
2016-11-15 21:54:49 +03:00
|
|
|
rm -f *.lib *.fas[l] images/* hist/*_impl
|