From 7164fbe73228ca1a172243e58a9022726d587fe5 Mon Sep 17 00:00:00 2001 From: Nicolas Boulenguez Date: Mon, 20 Jul 2026 22:01:40 +0200 Subject: [PATCH] Add steps.mk and simplify some implementation Makefiles In the process, recommend steps.mk for compiled language, and a minimal Makefile for interpreted ones. steps.mk avoids the duplication of the step names in each Makefile. It provides a consistent and explicit naming scheme. BINS -> step0A:=.exe OBJS -> step0A:%=obj/.o EARLY_STEPS_SRC -> step03:=.js LATE_STEPS -> step4A It allows some patterns to carry an explicit list of desired matches. step%.o: step%.c -> (step0A:=.o): %.o: %.c Unrelated changes. Replace several obsolete (lastword (steps)) constructs with (stepA). ada: replace -p mkdir option with a Make order prerequisite ada: replace force with .PHONY ada: use -o compile option instea of renaming the object erlang: replace a template macro with a loop on targets go: replace most of a template with a loop on targets hare: makefile -> Makefile haxe, scheme, sml: group the recipes by _MODE for readability --- impls/ada.2/Makefile | 74 +++++++--------------- impls/ada/Makefile | 23 +++---- impls/basic/Makefile | 31 +++++---- impls/c.2/Makefile | 31 +++------ impls/c/Makefile | 19 +++--- impls/coffee/Makefile | 9 +-- impls/common-lisp/Makefile | 9 ++- impls/cpp/Makefile | 11 ++-- impls/crystal/Makefile | 11 ++-- impls/cs/Makefile | 14 ++--- impls/d/Makefile | 28 ++++----- impls/elm/Makefile | 37 ++++------- impls/erlang/Makefile | 21 ++----- impls/es6/Makefile | 8 +-- impls/fsharp/Makefile | 19 +++--- impls/go/Makefile | 23 +++---- impls/groovy/Makefile | 23 +++---- impls/hare/Makefile | 13 ++++ impls/hare/makefile | 13 ---- impls/haskell/Makefile | 21 +++---- impls/haxe/Makefile | 126 +++++++++++++++++-------------------- impls/io/Makefile | 5 +- impls/js/Makefile | 7 +-- impls/kotlin/Makefile | 14 ++--- impls/livescript/Makefile | 25 +++----- impls/miniMAL/Makefile | 5 +- impls/nasm/Makefile | 11 ++-- impls/nim/Makefile | 17 ++--- impls/objc/Makefile | 25 +++----- impls/objpascal/Makefile | 24 +++---- impls/ocaml/Makefile | 18 +++--- impls/purs/Makefile | 30 ++------- impls/r/Makefile | 8 +-- impls/rexx/Makefile | 7 +-- impls/rpython/Makefile | 23 +++---- impls/rust/Makefile | 26 +++----- impls/scheme/Makefile | 111 +++++++++++++------------------- impls/skew/Makefile | 14 ++--- impls/sml/Makefile | 52 +++++++-------- impls/swift3/Makefile | 19 +++--- impls/swift4/Makefile | 19 +++--- impls/ts/Makefile | 8 +-- impls/vala/Makefile | 28 +++------ impls/vb/Makefile | 15 ++--- impls/vhdl/Makefile | 26 ++++---- impls/wasm/Makefile | 26 +++----- impls/zig/Makefile | 9 ++- process/guide.md | 8 ++- steps.mk | 66 +++++++++++++++++++ 49 files changed, 493 insertions(+), 717 deletions(-) create mode 100644 impls/hare/Makefile delete mode 100644 impls/hare/makefile create mode 100644 steps.mk diff --git a/impls/ada.2/Makefile b/impls/ada.2/Makefile index 2b17dda639..cff29cfe7c 100644 --- a/impls/ada.2/Makefile +++ b/impls/ada.2/Makefile @@ -1,3 +1,5 @@ +include ../../steps.mk + ifdef DEBUG ADAFLAGS := -Wall -Wextra -gnatw.eH.Y -gnatySdouxy -gnatVa -g -gnataEfoqQ \ -fstack-check -pg @@ -13,62 +15,28 @@ CARGS = $(ADAFLAGS) # Linker arguments. LARGS = $(LDFLAGS) -lreadline -step0 := step0_repl -step13 := step1_read_print \ - step2_eval \ - step3_env -step49 := step4_if_fn_do \ - step5_tco \ - step6_file \ - step7_quote \ - step8_macros \ - step9_try -stepa := stepA_mal -steps := $(step0) $(step13) $(step49) $(stepa) - .PHONY: all clean -all: $(steps) +all: $(step0A) clean: - $(RM) *~ *.adt *.ali *.o b~*.ad[bs] gmon.out $(steps) + $(RM) *~ *.adt *.ali *.o b~*.ad[bs] gmon.out $(step0A) # Tell Make how to detect out-of-date executables, and let gnatmake do # the rest when it must be executed. -sources = $(foreach unit,$1,$(unit).adb $(unit).ads) -TYPES := $(call sources,\ - envs \ - err \ - garbage_collected \ - printer \ - reader \ - readline \ - types \ - types-atoms \ - types-builtins \ - types-fns \ - types-maps \ - types-sequences \ - types-strings \ -) -CORE := $(call sources,\ - core \ -) - -$(step0) : %: %.adb -$(step13): %: %.adb $(TYPES) -$(step49): %: %.adb $(TYPES) $(CORE) -$(stepa) : stepA%: stepa%.adb $(TYPES) $(CORE) -$(steps) : +$(step09): %: %.adb +$(stepA): stepa_mal.adb +$(step1A): envs.adb envs.ads +$(step1A): err.adb err.ads +$(step1A): garbage_collected.adb garbage_collected.ads +$(step1A): printer.adb printer.ads +$(step1A): reader.adb reader.ads +$(step1A): readline.adb readline.ads +$(step1A): types.adb types.ads +$(step1A): types-atoms.adb types-atoms.ads +$(step1A): types-builtins.adb types-builtins.ads +$(step1A): types-fns.adb types-fns.ads +$(step1A): types-maps.adb types-maps.ads +$(step1A): types-sequences.adb types-sequences.ads +$(step1A): types-strings.adb types-strings.ads +$(step4A): core.adb core.ads +$(step0A): gnatmake $< -o $@ -cargs $(CARGS) -largs $(LARGS) - -.PHONY: steps.diff -steps.diff: - diff -u step0_*.adb step1_*.adb || true - diff -u step1_*.adb step2_*.adb || true - diff -u step2_*.adb step3_*.adb || true - diff -u step3_*.adb step4_*.adb || true - diff -u step4_*.adb step5_*.adb || true - diff -u step5_*.adb step6_*.adb || true - diff -u step6_*.adb step7_*.adb || true - diff -u step7_*.adb step8_*.adb || true - diff -u step8_*.adb step9_*.adb || true - diff -u step9_*.adb stepa_*.adb || true diff --git a/impls/ada/Makefile b/impls/ada/Makefile index 99f58b8b46..cbee66ee18 100644 --- a/impls/ada/Makefile +++ b/impls/ada/Makefile @@ -1,23 +1,16 @@ -PROGS=step0_repl step1_read_print step2_eval step3_env step4_if_fn_do \ - step5_tco step6_file step7_quote step8_macros step9_try +include ../../steps.mk -all: ${PROGS} stepA_mal +all: $(step0A) obj: - mkdir -p $@ + mkdir obj # stepA_mal is awkward because GNAT requires the filename to be lowercase -${PROGS} stepa_mal: force obj - gnatmake -O3 -gnata $@.adb -D obj - -# so we make stepa_mal and just move it. -stepA_mal: stepa_mal - mv $< $@ +$(step0A): | obj + gnatmake -O3 -gnata $(subst A,a,$@).adb -D obj -o $@ +# Delegate the dependency handling to gnatmake. +.PHONY: $(step0A) clean: - rm -f ${PROGS} + rm -f $(step0A) rm -rf obj - -.PHONY: force - -force: diff --git a/impls/basic/Makefile b/impls/basic/Makefile index 2fbd365bf9..41541d410d 100644 --- a/impls/basic/Makefile +++ b/impls/basic/Makefile @@ -1,36 +1,35 @@ +include ../../steps.mk + basic_MODE = cbm BASICPP_OPTS = --mode $(basic_MODE) FBC = fbc -lang qb -STEPS4_A = step4_if_fn_do.bas step5_tco.bas step6_file.bas \ - step7_quote.bas step8_macros.bas step9_try.bas stepA_mal.bas -STEPS3_A = step3_env.bas $(STEPS4_A) -STEPS1_A = step1_read_print.bas step2_eval.bas $(STEPS3_A) -STEPS0_A = step0_repl.bas $(STEPS1_A) - -all: $(if $(filter qbasic,$(basic_MODE)),$(subst .bas,,$(STEPS0_A)),$(STEPS0_A)) - -$(STEPS0_A): debug.in.bas mem.in.bas readline.in.bas -$(STEPS1_A): types.in.bas reader.in.bas printer.in.bas -$(STEPS3_A): env.in.bas -$(STEPS4_A): core.in.bas +ifeq (qbasic,$(basic_MODE)) + all: $(step0A) +else + all: $(step0A:=.bas) +endif +$(step0A:=.bas): debug.in.bas mem.in.bas readline.in.bas +$(step1A:=.bas): types.in.bas reader.in.bas printer.in.bas +$(step3A:=.bas): env.in.bas +$(step4A:=.bas): core.in.bas -step%.bas: step%.in.bas +$(step0A:=.bas): %.bas: %.in.bas ./basicpp.py $(BASICPP_OPTS) $< > $@ tests/%.bas: tests/%.in.bas ./basicpp.py $(BASICPP_OPTS) $< > $@ # QBasic specific compilation rule -step%: step%.bas +$(step0A): %: %.bas $(FBC) $< -x $@ # CBM/C64 image rules -%.prg: %.bas +$(step0A:=.prg): %.prg: %.bas cat $< | tr "A-Z" "a-z" > $<.tmp #cat $< | sed 's/["]\@["]\@!/\L&/g' > $<.tmp petcat -w2 -nc -o $@ $<.tmp @@ -58,5 +57,5 @@ mal.d64: mal.prg .args.mal.prg core.mal.prg .PHONY: clean clean: - rm -f $(STEPS0_A) $(subst .bas,,$(STEPS0_A)) *.d64 *.prg + rm -f $(step0A:=.bas) $(step0A) *.d64 *.prg rm -rf ./internal diff --git a/impls/c.2/Makefile b/impls/c.2/Makefile index fb75f9be3e..4b3d9e8f6f 100644 --- a/impls/c.2/Makefile +++ b/impls/c.2/Makefile @@ -1,3 +1,5 @@ +include ../../steps.mk + CC = gcc CFLAGS = -std=c99 -g -Wall -Wextra -fanalyzer @@ -40,37 +42,20 @@ pkgconfig_modules += bdw-gc CFLAGS += $(shell pkg-config --cflags $(pkgconfig_modules)) LDLIBS += $(shell pkg-config --libs $(pkgconfig_modules)) -S0 = step0_repl -S1 = step1_read_print -S2 = step2_eval -S3 = step3_env -S4 = step4_if_fn_do -S5 = step5_tco -S6 = step6_file -S7 = step7_quote -S8 = step8_macros -S9 = step9_try -SA = stepA_mal - -S4+ := $(S4) $(S5) $(S6) $(S7) $(S8) $(S9) $(SA) -S3+ := $(S3) $(S4+) -S1+ := $(S1) $(S2) $(S3+) -S0+ := $(S0) $(S1+) - -all: $(S0+) +all: $(step0A) # GCC could create temporary objects files, but separate recipes for # .o objects give faster build cycles when debugging. -$(S0+): readline.o -$(S1+): error.o hashmap.o linked_list.o printer.o reader.o types.o vector.o -$(S3+): env.o -$(S4+): core.o +$(step0A): readline.o +$(step1A): error.o hashmap.o linked_list.o printer.o reader.o types.o vector.o +$(step3A): env.o +$(step4A): core.o include deps deps: $(CC) -MM -MF- *.c > $@ clean: - rm -f $(S0+) *.o deps gmon.out + rm -f $(step0A) *.o deps gmon.out .PHONY: all clean diff --git a/impls/c/Makefile b/impls/c/Makefile index 56c2e5934c..b1ce2aaabb 100644 --- a/impls/c/Makefile +++ b/impls/c/Makefile @@ -1,3 +1,5 @@ +include ../../steps.mk + USE_READLINE ?= USE_GC ?= 1 CFLAGS ?= -g -O2 @@ -5,11 +7,6 @@ LDFLAGS ?= -g ##################### -SRCS = step0_repl.c step1_read_print.c step2_eval.c step3_env.c \ - step4_if_fn_do.c step5_tco.c step6_file.c step7_quote.c \ - step8_macros.c step9_try.c stepA_mal.c -OBJS = $(SRCS:%.c=%.o) -BINS = $(OBJS:%.o=%) OTHER_OBJS = types.o readline.o reader.o printer.o env.o core.o interop.o OTHER_HDRS = types.h readline.h reader.h printer.h core.h interop.h @@ -45,17 +42,17 @@ override LDLIBS += \ ##################### -all: $(BINS) +all: $(step0A) dist: mal -mal: $(word $(words $(BINS)),$(BINS)) +mal: $(stepA) cp $< $@ -$(OBJS) $(OTHER_OBJS): %.o: %.c $(OTHER_HDRS) +$(step0A:=.o) $(OTHER_OBJS): %.o: %.c $(OTHER_HDRS) -$(patsubst %.o,%,$(filter step%,$(OBJS))): $(OTHER_OBJS) -$(BINS): %: %.o +$(step0A): $(OTHER_OBJS) +$(step0A): %: %.o clean: - rm -f $(OBJS) $(BINS) $(OTHER_OBJS) mal + rm -f *.o $(step0A) mal diff --git a/impls/coffee/Makefile b/impls/coffee/Makefile index 4036473196..11e0823c02 100644 --- a/impls/coffee/Makefile +++ b/impls/coffee/Makefile @@ -1,19 +1,16 @@ +include ../../steps.mk + SOURCES_BASE = node_readline.coffee types.coffee \ reader.coffee printer.coffee SOURCES_LISP = env.coffee core.coffee stepA_mal.coffee SOURCES = $(SOURCES_BASE) $(SOURCES_LISP) -STEPS = step0_repl.coffee step1_read_print.coffee \ - step2_eval.coffee step3_env.coffee step4_if_fn_do.coffee \ - step5_tco.coffee step6_file.coffee step7_quote.coffee \ - step8_macros.coffee step9_try.coffee stepA_mal.coffee - all: node_modules dist node_modules: npm install -$(STEPS): node_modules +$(step0A:=.coffee): node_modules dist: mal.coffee mal diff --git a/impls/common-lisp/Makefile b/impls/common-lisp/Makefile index cdcf59f63a..279a24af4a 100644 --- a/impls/common-lisp/Makefile +++ b/impls/common-lisp/Makefile @@ -1,3 +1,5 @@ +include ../../steps.mk + # Helper functions define record_lisp $(shell (test -f "hist/$(1)_impl" && grep -q $(2) "hist/$(1)_impl") || echo $(2) > "hist/$(1)_impl") @@ -15,9 +17,6 @@ LISP ?= sbcl ABCL ?= abcl MKCL ?= mkcl -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 - # TODO: In theory cl-launch should be able to build standalone executable using # MKCL unfortunately the executable crashes on startup STANDALONE_EXE = sbcl clisp ccl ecl cmucl @@ -31,7 +30,7 @@ $(foreach step, $(call steps), $(call record_lisp,$(patsubst step%,%,$(step)),$( .PRECIOUS: hist/%_impl -all : $(BINS) +all : $(step0A) hist/%_impl: ; @@ -39,7 +38,7 @@ hist/%_impl: ; # 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 -step% : src/step%.lisp src/utils.lisp src/types.lisp src/env.lisp src/printer.lisp src/reader.lisp src/core.lisp hist/%_impl +$(step0A): step% : src/step%.lisp src/utils.lisp src/types.lisp src/env.lisp src/printer.lisp src/reader.lisp src/core.lisp hist/%_impl ifeq ($(LISP),clisp) @echo "==============================================================" diff --git a/impls/cpp/Makefile b/impls/cpp/Makefile index 1c81812297..c601d5ee36 100644 --- a/impls/cpp/Makefile +++ b/impls/cpp/Makefile @@ -1,3 +1,5 @@ +include ../../steps.mk + uname_S := $(shell sh -c 'uname -s 2>/dev/null || echo not') CXX=g++ @@ -19,14 +21,11 @@ LIBSOURCES=Core.cpp Environment.cpp Reader.cpp ReadLine.cpp String.cpp \ Types.cpp Validation.cpp LIBOBJS=$(LIBSOURCES:%.cpp=%.o) -MAINS=$(wildcard step*.cpp) -TARGETS=$(MAINS:%.cpp=%) - .PHONY: all clean .SUFFIXES: .cpp .o -all: $(TARGETS) +all: $(step0A) dist: mal @@ -36,7 +35,7 @@ mal: stepA_mal .deps: *.cpp *.h $(CXX) $(CXXFLAGS) -MM *.cpp > .deps -$(TARGETS): %: %.o libmal.a +$(step0A): %: %.o libmal.a $(LD) $^ -o $@ $(LDFLAGS) libmal.a: $(LIBOBJS) @@ -46,6 +45,6 @@ libmal.a: $(LIBOBJS) $(CXX) $(CXXFLAGS) -c $< -o $@ clean: - rm -rf *.o $(TARGETS) libmal.a .deps mal + rm -rf *.o $(step0A) libmal.a .deps mal -include .deps diff --git a/impls/crystal/Makefile b/impls/crystal/Makefile index 43129aac5c..5695b37de3 100644 --- a/impls/crystal/Makefile +++ b/impls/crystal/Makefile @@ -1,9 +1,8 @@ -STEPS = 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 -all: $(STEPS) -$(STEPS): +include ../../steps.mk + +all: $(step0A) +$(step0A): shards build $@ --release clean: rm -rf .cache/crystal/ .cache/shards/ bin/ lib/ -.PHONY: all clean $(STEPS) +.PHONY: all clean $(step0A) diff --git a/impls/cs/Makefile b/impls/cs/Makefile index 52529a915b..e416573a7a 100644 --- a/impls/cs/Makefile +++ b/impls/cs/Makefile @@ -1,3 +1,5 @@ +include ../../steps.mk + ##################### DEBUG = @@ -10,33 +12,29 @@ OTHER_SOURCES = getline.cs ##################### -SRCS = step0_repl.cs step1_read_print.cs step2_eval.cs step3_env.cs \ - step4_if_fn_do.cs step5_tco.cs step6_file.cs step7_quote.cs \ - step8_macros.cs step9_try.cs stepA_mal.cs - LIB_SRCS = $(filter-out step%,$(OTHER_SOURCES) $(SOURCES)) FLAGS = $(if $(strip $(DEBUG)),-debug+,) ##################### -all: $(patsubst %.cs,%.exe,$(SRCS)) +all: $(step0A:=.exe) dist: mal.exe mal -mal.exe: $(patsubst %.cs,%.exe,$(word $(words $(SOURCES)),$(SOURCES))) +mal.exe: $(stepA).exe cp $< $@ # NOTE/WARNING: static linking triggers mono libraries LGPL # distribution requirements. # http://www.mono-project.com/archived/guiderunning_mono_applications/ -mal: $(patsubst %.cs,%.exe,$(word $(words $(SOURCES)),$(SOURCES))) mal.dll +mal: $(stepA).exe mal.dll mkbundle --static -o $@ $+ --deps mal.dll: $(LIB_SRCS) mcs $(FLAGS) -target:library $+ -out:$@ -%.exe: %.cs mal.dll +$(step0A:=.exe): %.exe: %.cs mal.dll mcs $(FLAGS) -r:mal.dll $< clean: diff --git a/impls/d/Makefile b/impls/d/Makefile index 7872d8920e..26d88bad04 100644 --- a/impls/d/Makefile +++ b/impls/d/Makefile @@ -1,3 +1,5 @@ +include ../../steps.mk + d_MODE ?= gdc D ?= $(d_MODE) @@ -21,34 +23,26 @@ endif ##################### -EARLY_SRCS = step0_repl.d step1_read_print.d step2_eval.d -LATE_SRCS = step3_env.d step4_if_fn_do.d step5_tco.d step6_file.d \ - step7_quote.d step8_macros.d step9_try.d stepA_mal.d -SRCS = $(EARLY_SRCS) $(LATE_SRCS) -OBJS = $(SRCS:%.d=%.o) -BINS = $(OBJS:%.o=%) EARLY_OBJS = types.o readline.o reader.o printer.o env.o -OTHER_OBJS = $(EARLY_OBJS) mal_core.o -EARLY_STEPS_BINS = $(EARLY_SRCS:%.d=%) -LATE_STEPS_BINS = $(LATE_SRCS:%.d=%) +deps3A := mal_core.o ##################### -all: $(BINS) +all: $(step0A) dist: mal -mal: $(word $(words $(BINS)),$(BINS)) +mal: $(stepA) cp $< $@ -$(OBJS) $(OTHER_OBJS): %.o: %.d - $(D) $(CFLAGS) -c $(@:%.o=%.d) $(OF) +$(step0A:=.o) $(EARLY_OBJS) $(deps3A): %.o: %.d + $(D) $(CFLAGS) -c $< $(OF) -$(EARLY_STEPS_BINS): $(EARLY_OBJS) -$(LATE_STEPS_BINS): $(OTHER_OBJS) +$(step0A): $(EARLY_OBJS) +$(step3A): $(deps3A) -$(BINS): %: %.o +$(step0A): %: %.o $(D) $+ $(OF) $(LDFLAGS) clean: - rm -f $(OBJS) $(BINS) $(OTHER_OBJS) mal + rm -f *.o $(step0A) mal diff --git a/impls/elm/Makefile b/impls/elm/Makefile index f52164ec06..ce931ba83c 100644 --- a/impls/elm/Makefile +++ b/impls/elm/Makefile @@ -1,36 +1,23 @@ -SOURCES = src/Step0_repl.elm src/Step1_read_print.elm src/Step2_eval.elm \ - src/Step3_env.elm src/Step4_if_fn_do.elm src/Step5_tco.elm src/Step6_file.elm \ - src/Step7_quote.elm src/Step8_macros.elm src/Step9_try.elm src/StepA_mal.elm - -BINS = $(SOURCES:src/Step%.elm=step%.js) +include ../../steps.mk ELM = node_modules/.bin/elm -all: node_modules $(BINS) +all: node_modules $(step0A:=.js) node_modules: npm install -step%.js: src/Step%.elm node_modules +$(step0A:=.js): s%.js: src/S%.elm node_modules $(ELM) make $< --output $@ -STEP0_SOURCES = src/IO.elm -STEP1_SOURCES = $(STEP0_SOURCES) src/Reader.elm src/Printer.elm src/Utils.elm src/Types.elm src/Env.elm -STEP2_SOURCES = $(STEP1_SOURCES) -STEP3_SOURCES = $(STEP2_SOURCES) -STEP4_SOURCES = $(STEP3_SOURCES) src/Core.elm src/Eval.elm - -step0_repl.js: $(STEP0_SOURCES) -step1_read_print.js: $(STEP1_SOURCES) -step2_eval.js: $(STEP2_SOURCES) -step3_env.js: $(STEP3_SOURCES) -step4_if_fn_do.js: $(STEP4_SOURCES) -step5_tco.js: $(STEP4_SOURCES) -step6_file.js: $(STEP4_SOURCES) -step7_quote.js: $(STEP4_SOURCES) -step8_macros.js: $(STEP4_SOURCES) -step9_try.js: $(STEP4_SOURCES) -stepA_mal.js: $(STEP4_SOURCES) +$(step0A:=.js): src/IO.elm +$(step1A:=.js): src/Reader.elm +$(step1A:=.js): src/Printer.elm +$(step1A:=.js): src/Utils.elm +$(step1A:=.js): src/Types.elm +$(step1A:=.js): src/Env.elm +$(step4A:=.js): src/Core.elm +$(step4A:=.js): src/Eval.elm clean: - rm -f $(BINS) + rm -f $(step0A:=.js) diff --git a/impls/erlang/Makefile b/impls/erlang/Makefile index 5ad84cca76..9435d31fb3 100644 --- a/impls/erlang/Makefile +++ b/impls/erlang/Makefile @@ -1,3 +1,5 @@ +include ../../steps.mk + ##################### SOURCES_BASE = src/atom.erl src/printer.erl src/reader.erl @@ -6,15 +8,9 @@ SOURCES = $(SOURCES_BASE) $(SOURCES_LISP) ##################### -SRCS = step0_repl.erl step1_read_print.erl step2_eval.erl step3_env.erl step4_if_fn_do.erl \ - step5_tco.erl step6_file.erl step7_quote.erl step8_macros.erl step9_try.erl stepA_mal.erl -BINS = $(SRCS:%.erl=%) - -##################### - .PHONY: all dist clean -all: $(BINS) +all: $(step0A) dist: mal @@ -23,14 +19,9 @@ mal: $(SOURCES) MAL_STEP=mal rebar compile escriptize rm src/mal.erl - -define dep_template -.PHONY: $(1) -$(1): src/$(1).erl - MAL_STEP=$(1) rebar compile escriptize -endef - -$(foreach b,$(BINS),$(eval $(call dep_template,$(b)))) +.PHONY: $(step0A) +$(step0A): %: src/%.erl + MAL_STEP=$* rebar compile escriptize clean: rebar clean diff --git a/impls/es6/Makefile b/impls/es6/Makefile index 15ffe6aa49..fbbd4296cf 100644 --- a/impls/es6/Makefile +++ b/impls/es6/Makefile @@ -1,11 +1,9 @@ +include ../../steps.mk + SOURCES_BASE = node_readline.js types.mjs reader.mjs printer.mjs SOURCES_LISP = env.mjs core.mjs stepA_mal.mjs SOURCES = $(SOURCES_BASE) $(SOURCES_LISP) -STEPS = step0_repl.mjs step1_read_print.mjs step2_eval.mjs step3_env.mjs \ - step4_if_fn_do.mjs step5_tco.mjs step6_file.mjs \ - step7_quote.mjs step8_macros.mjs step9_try.mjs stepA_mal.mjs - all: node_modules dist: mal.js mal @@ -13,7 +11,7 @@ dist: mal.js mal node_modules: npm install -$(STEPS): node_modules +$(step0A:=.mjs): node_modules mal.js: $(SOURCES) cat $+ | sed 's/^export //' | grep -v "^import " >> $@ diff --git a/impls/fsharp/Makefile b/impls/fsharp/Makefile index 505d3ee5d3..4b86cd398a 100644 --- a/impls/fsharp/Makefile +++ b/impls/fsharp/Makefile @@ -1,26 +1,21 @@ +include ../../steps.mk + ##################### DEBUG = -SOURCES_BASE = types.fs error.fs node.fs printer.fs tokenizer.fs reader.fs \ - readline.fs -SOURCES_LISP = core.fs env.fs stepA_mal.fs -SOURCES = $(SOURCES_BASE) $(SOURCES_LISP) +DLL_SOURCES = types.fs error.fs node.fs printer.fs tokenizer.fs reader.fs \ + readline.fs core.fs env.fs TERMINAL_SOURCES = terminal.cs ##################### -SRCS = step0_repl.fs step1_read_print.fs step2_eval.fs step3_env.fs \ - step4_if_fn_do.fs step5_tco.fs step6_file.fs step7_quote.fs \ - step8_macros.fs step9_try.fs stepA_mal.fs -DLL_SOURCES = $(filter-out stepA_mal.fs,$(SOURCES)) - FSFLAGS = $(if $(strip $(DEBUG)),--debug+,--debug- --optimize+ --tailcalls+) CSFLAGS = $(if $(strip $(DEBUG)),-debug+,) ##################### -all: $(patsubst %.fs,%.exe,$(SRCS)) +all: $(step0A:=.exe) dist: mal.exe mal @@ -30,7 +25,7 @@ mal.exe: stepA_mal.exe # NOTE/WARNING: static linking triggers mono libraries LGPL # distribution requirements. # http://www.mono-project.com/archived/guiderunning_mono_applications/ -mal: $(patsubst %.fs,%.exe,$(word $(words $(SOURCES)),$(SOURCES))) Mono.Terminal.dll mal.dll +mal: $(stepA).exe Mono.Terminal.dll mal.dll mkbundle --static -o $@ $+ --deps Mono.Terminal.dll: $(TERMINAL_SOURCES) @@ -39,7 +34,7 @@ Mono.Terminal.dll: $(TERMINAL_SOURCES) mal.dll: $(DLL_SOURCES) Mono.Terminal.dll fsharpc $(FSFLAGS) -o $@ -r Mono.Terminal.dll -a $(DLL_SOURCES) -%.exe: %.fs mal.dll +$(step0A:=.exe): %.exe: %.fs mal.dll fsharpc $(FSFLAGS) -o $@ -r mal.dll $< clean: diff --git a/impls/go/Makefile b/impls/go/Makefile index 4968b59cf0..b3add135fc 100644 --- a/impls/go/Makefile +++ b/impls/go/Makefile @@ -1,3 +1,5 @@ +include ../../steps.mk + ##################### SOURCES_BASE = src/types/types.go src/readline/readline.go \ @@ -6,26 +8,17 @@ SOURCES_BASE = src/types/types.go src/readline/readline.go \ ##################### -SRCS = step0_repl.go step1_read_print.go step2_eval.go step3_env.go \ - step4_if_fn_do.go step5_tco.go step6_file.go step7_quote.go \ - step8_macros.go step9_try.go stepA_mal.go -BINS = $(SRCS:%.go=%) - -##################### - -all: $(BINS) +all: $(step0A) dist: mal -mal: $(word $(words $(BINS)),$(BINS)) +mal: $(stepA) cp $< $@ -define dep_template -$(1): $(SOURCES_BASE) src/$(1)/$(1).go - go build -o $$@ ./src/$(1) -endef +$(step0A): $(SOURCES_BASE) + go build -o $@ ./src/$@ +$(foreach b,$(step0A),$(eval $(b): src/$(b)/$(b).go)) -$(foreach b,$(BINS),$(eval $(call dep_template,$(b)))) clean: - rm -f $(BINS) mal + rm -f $(step0A) mal diff --git a/impls/groovy/Makefile b/impls/groovy/Makefile index 888eb9fc24..e9631b3ee4 100644 --- a/impls/groovy/Makefile +++ b/impls/groovy/Makefile @@ -1,28 +1,19 @@ +include ../../steps.mk + CLASSES = types.class reader.class printer.class env.class core.class all: ${CLASSES} dist: mal.jar -step1_read_print.groovy: types.class reader.class printer.class -step2_eval.groovy: types.class reader.class printer.class -step3_env.groovy: types.class reader.class printer.class env.class -step4_if_fn_do.groovy step6_file.groovy step7_quote.groovy step8_macros.groovy step9_try.groovy stepA_mal.groovy: ${CLASSES} - -types.class: types.groovy - groovyc $< - -env.class: env.groovy - groovyc $< - -reader.class: reader.groovy - groovyc $< +$(step1A:=.groovy): types.class reader.class printer.class +$(step3A:=.groovy): env.class +$(step4A:=.groovy): core.class -printer.class: printer.groovy +$(CLASSES): %.class: %.groovy groovyc $< -core.class: core.groovy types.class reader.class printer.class - groovyc $< +core.class: types.class reader.class printer.class mal.jar: ${CLASSES} groovyc stepA_mal.groovy diff --git a/impls/hare/Makefile b/impls/hare/Makefile new file mode 100644 index 0000000000..20f58bd1d4 --- /dev/null +++ b/impls/hare/Makefile @@ -0,0 +1,13 @@ +include ../../steps.mk +# +CC= hare build + +.PHONY: all +all: $(step0A) + +$(step0A): %: %.ha $(wildcard mal/*.ha) + $(CC) -o $@ $< + +.PHONY: clean +clean: + rm $(step0A) diff --git a/impls/hare/makefile b/impls/hare/makefile deleted file mode 100644 index dcffb98177..0000000000 --- a/impls/hare/makefile +++ /dev/null @@ -1,13 +0,0 @@ -CC= hare build - -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 - -.PHONY: all -all: $(BINS) - -%: %.ha $(wildcard mal/*.ha) - $(CC) -o $@ $< - -.PHONY: clean -clean: - rm $(BINS) diff --git a/impls/haskell/Makefile b/impls/haskell/Makefile index aeb0c69915..135a929cd4 100644 --- a/impls/haskell/Makefile +++ b/impls/haskell/Makefile @@ -1,22 +1,19 @@ -BINS4 = step4_if_fn_do step5_tco step6_file step7_quote step8_macros \ - step9_try stepA_mal -BINS3 = step3_env $(BINS4) -BINS1 = step1_read_print step2_eval $(BINS3) -BINS = step0_repl $(BINS1) +include ../../steps.mk + ghc_flags = -Wall -Wextra LDLIBS = -lreadline ##################### -all: $(BINS) +all: $(step0A) -$(BINS): %: %.hs +$(step0A): %: %.hs ghc ${ghc_flags} --make $< $(LDLIBS) -o $@ -$(BINS1): Types.hs Reader.hs Printer.hs -$(BINS3): Env.hs -$(BINS4): Core.hs -$(BINS): Readline.hs +$(step0A): Readline.hs +$(step1A): Types.hs Reader.hs Printer.hs +$(step3A): Env.hs +$(step4A): Core.hs clean: - rm -f $(BINS) *.hi *.o + rm -f $(step0A) *.hi *.o diff --git a/impls/haxe/Makefile b/impls/haxe/Makefile index 4d2133ab33..f832061efc 100644 --- a/impls/haxe/Makefile +++ b/impls/haxe/Makefile @@ -1,104 +1,92 @@ +include ../../steps.mk +# STEP1_DEPS = Compat.hx types/Types.hx reader/Reader.hx printer/Printer.hx -STEP3_DEPS = $(STEP1_DEPS) env/Env.hx -STEP4_DEPS = $(STEP3_DEPS) core/Core.hx - -STEPS = 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 +STEP3_DEPS = env/Env.hx +STEP4_DEPS = core/Core.hx haxe_MODE ?= neko -dist_neko = mal.n -dist_python = mal.py -dist_cpp = cpp/mal - -all: all-$(haxe_MODE) -all-neko: $(foreach x,$(STEPS),$(x).n) - -all-python: $(foreach x,$(STEPS),$(x).py) +# Neko target (neko) -all-cpp: $(foreach x,$(STEPS),cpp/$(x)) +ifeq (neko,$(haxe_MODE)) +all: $(step0A:=.n) -all-js: $(foreach x,$(STEPS),$(x).js) +$(step0A:=.n): s%.n: S%.hx + haxe -main S$* -neko $@ -dist: mal.n mal.py cpp/mal mal.js mal +$(step1A:=.n): $(STEP1_DEPS) +$(step3A:=.n): $(STEP3_DEPS) +$(step4A:=.n): $(STEP4_DEPS) +mal: mal.n + nekotools boot $< + chmod +x $@ mal.n: stepA_mal.n cp $< $@ -mal.py: stepA_mal.py - cp $< $@ - -cpp/mal: cpp/stepA_mal - cp $< $@ - -mal.js: stepA_mal.js - cp $< $@ - - -mal: $(dist_$(haxe_MODE)) - $(if $(filter cpp,$(haxe_MODE)),\ - cp $< $@;,\ - $(if $(filter neko,$(haxe_MODE)),\ - nekotools boot $<;,\ - $(if $(filter js,$(haxe_MODE)),\ - echo "#!/usr/bin/env node" > $@;\ - cat $< >> $@;,\ - $(if $(filter python,$(haxe_MODE)),\ - echo "#!/usr/bin/env python3" > $@;\ - cat $< >> $@;,\ - $(error Invalid haxe_MODE: $(haxe_MODE)))))) - chmod +x $@ - -# Neko target (neko) +# Python 3 target (python) -s%.n: S%.hx - haxe -main $(patsubst %.hx,%,$<) -neko $@ +else ifeq (python,$(haxe_MODE)) +all: $(step0A:=.py) -step1_read_print.n step2_eval.n: $(STEP1_DEPS) -step3_env.n: $(STEP3_DEPS) -step4_if_fn_do.n step5_tco.n step6_file.n step7_quote.n step8_macros.n step9_try.n stepA_mal.n: $(STEP4_DEPS) +$(step0A:=.py): s%.py: S%.hx + haxe -main S$* -python $@ +$(step1A:=.py): $(STEP1_DEPS) +$(step3A:=.py): $(STEP3_DEPS) +$(step4A:=.py): $(STEP4_DEPS) -# Python 3 target (python) +mal: $(stepA).py + (echo '#!/usr/bin/env python3'; cat $<) > $@ + chmod +x $@ -s%.py: S%.hx - haxe -main $(patsubst %.hx,%,$<) -python $@ -step1_read_print.py step2_eval.py: $(STEP1_DEPS) -step3_env.py: $(STEP3_DEPS) -step4_if_fn_do.py step5_tco.py step6_file.py step7_quote.py step8_macros.py step9_try.py stepA_mal.py: $(STEP4_DEPS) +# C++ target (cpp) +else ifeq (cpp,$(haxe_MODE)) +all: $(step0A:%=cpp/%) -# C++ target (cpp) +$(step0A:%=cpp/%): cpp/s%: S%.hx + haxe -main S$* -cpp cpp + cp cpp/S$* $@ -cpp/s%: S%.hx - haxe -main $(patsubst %.hx,%,$<) -cpp cpp - cp $(patsubst cpp/s%,cpp/S%,$@) $@ +$(step1A:%=cpp/%): $(STEP1_DEPS) +$(step3A:%=cpp/%): $(STEP3_DEPS) +$(step4A:%=cpp/%): $(STEP4_DEPS) -cpp/step1_read_print cpp/step2_eval: $(STEP1_DEPS) -cpp/step3_env: $(STEP3_DEPS) -cpp/step4_if_fn_do cpp/step5_tco cpp/step6_file cpp/step7_quote cpp/step8_macros cpp/step9_try cpp/stepA_mal: $(STEP4_DEPS) +mal: cpp/$(stepA) + cp $< $@ + chmod +x $@ # JavaScript target (js) -s%.js: S%.hx - haxe -main $(patsubst %.hx,%,$<) -js $@ +else ifeq (js,$(haxe_MODE)) +all: $(step0A:=.js) + +$(step0A:=.js): s%.js: S%.hx + haxe -main S$* -js $@ -JS_DEPS = node_readline.js node_modules -step0_repl.js: $(JS_DEPS) -step1_read_print.js step2_eval.js: $(STEP1_DEPS) $(JS_DEPS) -step3_env.js: $(STEP3_DEPS) $(JS_DEPS) -step4_if_fn_do.js step5_tco.js step6_file.js step7_quote.js step8_macros.js step9_try.js stepA_mal.js: $(STEP4_DEPS) $(JS_DEPS) +$(step0A:=.js): node_readline.js node_modules +$(step1A:=.js): $(STEP1_DEPS) +$(step3A:=.js): $(STEP3_DEPS) +$(step4A:=.js): $(STEP4_DEPS) node_modules: npm install +mal: + (echo "#!/usr/bin/env node"; cat $<) > $@ + chmod +x $@ + ### +else + $(error Invalid haxe_MODE=$(haxe_MODE)) +endif + clean: rm -f mal.n mal.py cpp/mal mal.js mal - rm -f step*.py step*.js step*.n - [ -e cpp/ ] && rm -r cpp/ || true + rm -f $(step0A:=.py) $(step0A:=.js) $(step0A:=.n) + rm -fr cpp diff --git a/impls/io/Makefile b/impls/io/Makefile index 16310cea7c..983fee9e06 100644 --- a/impls/io/Makefile +++ b/impls/io/Makefile @@ -1,11 +1,10 @@ -STEPS = step0_repl.io step1_read_print.io step2_eval.io step3_env.io step4_if_fn_do.io step5_tco.io \ - step6_file.io step7_quote.io step8_macros.io step9_try.io stepA_mal.io +include ../../steps.mk all: eerie eerie: ln -s /opt/.eerie eerie -$(STEPS): eerie +$(step0A:=.io): eerie clean: diff --git a/impls/js/Makefile b/impls/js/Makefile index faef0bfe28..3c9f7b3fc5 100644 --- a/impls/js/Makefile +++ b/impls/js/Makefile @@ -1,3 +1,4 @@ +include ../../steps.mk TESTS = tests/types.js tests/reader.js @@ -6,10 +7,6 @@ SOURCES_LISP = env.js core.js stepA_mal.js SOURCES = $(SOURCES_BASE) $(SOURCES_LISP) WEB_SOURCES = $(SOURCES:node_readline.js=jq_readline.js) -STEPS = step0_repl.js step1_read_print.js step2_eval.js step3_env.js \ - step4_if_fn_do.js step5_tco.js step6_file.js \ - step7_quote.js step8_macros.js step9_try.js stepA_mal.js - all: node_modules dist: mal.js mal web/mal.js @@ -17,7 +14,7 @@ dist: mal.js mal web/mal.js node_modules: npm install -$(STEPS): node_modules +$(step0A:=.js): node_modules mal.js: $(SOURCES) cat $+ | grep -v "= *require('./" >> $@ diff --git a/impls/kotlin/Makefile b/impls/kotlin/Makefile index 1a9a6dfee1..a45ddca508 100644 --- a/impls/kotlin/Makefile +++ b/impls/kotlin/Makefile @@ -1,10 +1,8 @@ -SOURCES_BASE = reader.kt printer.kt types.kt env.kt core.kt readline.kt -SOURCES_LISP = step0_repl.kt step1_read_print.kt step2_eval.kt step3_env.kt step4_if_fn_do.kt \ - step5_tco.kt step6_file.kt step7_quote.kt step8_macros.kt step9_try.kt stepA_mal.kt +include ../../steps.mk -JARS = $(SOURCES_LISP:%.kt=%.jar) +SOURCES_BASE = reader.kt printer.kt types.kt env.kt core.kt readline.kt -all: $(JARS) +all: $(step0A:=.jar) dist: mal.jar mal @@ -17,7 +15,7 @@ mal: mal.jar chmod +x mal clean: - rm -vf $(JARS) mal.jar mal + rm -vf $(step0A:=.jar) mal.jar mal -$(JARS): %.jar: src/mal/%.kt $(SOURCES_BASE:%.kt=src/mal/%.kt) - kotlinc src/mal/$(@:%.jar=%.kt) $(SOURCES_BASE:%.kt=src/mal/%.kt) -include-runtime -d $@ +$(step0A:=.jar): %.jar: src/mal/%.kt $(SOURCES_BASE:%.kt=src/mal/%.kt) + kotlinc $^ -include-runtime -d $@ diff --git a/impls/livescript/Makefile b/impls/livescript/Makefile index 1afe00026f..3f086de6c8 100644 --- a/impls/livescript/Makefile +++ b/impls/livescript/Makefile @@ -1,10 +1,6 @@ -SOURCES_BASE = reader.ls printer.ls env.ls core.ls utils.ls -SOURCES_STEPS = step0_repl.ls step1_read_print.ls step2_eval.ls \ - step4_if_fn_do.ls step5_tco.ls step6_file.ls step7_quote.ls \ - step8_macros.ls step9_try.ls stepA_mal.ls -SOURCES = $(SOURCES_BASE) $(SOURCES_STEPS) +include ../../steps.mk -BINS = $(SOURCES:%.ls=%.js) +BINS = reader.js printer.js env.js core.js utils.js $(step0A:=.js) LSC = lsc @@ -13,19 +9,12 @@ all: node_modules $(BINS) node_modules: npm install -%.js: %.ls node_modules - $(LSC) -d -c $(@:%.js=%.ls) +$(BINS): %.js: %.ls node_modules + $(LSC) -d -c $< -step1_read_print.js: utils.js reader.js printer.js -step2_eval.js: utils.js reader.js printer.js -step3_env.js: utils.js reader.js printer.js env.js -step4_if_fn_do.js: utils.js reader.js printer.js env.js core.js -step5_tco.js: utils.js reader.js printer.js env.js core.js -step6_file.js: utils.js reader.js printer.js env.js core.js -step7_quote.js: utils.js reader.js printer.js env.js core.js -step8_macros.js: utils.js reader.js printer.js env.js core.js -step9_try.js: utils.js reader.js printer.js env.js core.js -stepA_mal.js: utils.js reader.js printer.js env.js core.js +$(step1A:=.js): utils.js reader.js printer.js +$(step3A:=.js): env.js +$(step4A:=.js): core.js clean: rm -f $(BINS) diff --git a/impls/miniMAL/Makefile b/impls/miniMAL/Makefile index 4d5a808de2..5b240097ea 100644 --- a/impls/miniMAL/Makefile +++ b/impls/miniMAL/Makefile @@ -1,17 +1,16 @@ +include ../../steps.mk SOURCES_BASE = node_readline.js miniMAL-core.json \ types.json reader.json printer.json SOURCES_LISP = env.json core.json stepA_mal.json SOURCES = $(SOURCES_BASE) $(SOURCES_LISP) -FFI_STEPS = step4_if_fn_do step5_tco step6_file \ - step7_quote step8_macros step9_try stepA_mal all: node_modules node_modules: npm install -$(foreach S,$(FFI_STEPS),$(S).json): node_modules +$(step4A:=.json): node_modules dist: mal.json mal diff --git a/impls/nasm/Makefile b/impls/nasm/Makefile index a3cf08c0aa..b10e8d8689 100644 --- a/impls/nasm/Makefile +++ b/impls/nasm/Makefile @@ -1,17 +1,16 @@ - -STEPS = 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 +include ../../steps.mk COMPONENTS = env.asm core.asm reader.asm printer.asm types.asm system.asm exceptions.asm -all: $(STEPS) +all: $(step0A) -%.o: %.asm $(COMPONENTS) +$(step0A:=.o): %.o: %.asm $(COMPONENTS) nasm -felf64 $< -%: %.o +$(step0A): %: %.o ld -o $@ $< .PHONY: clean clean: - rm -f $(STEPS) $(STEPS:%=%.o) + rm -f $(step0A) $(step0A:=.o) diff --git a/impls/nim/Makefile b/impls/nim/Makefile index 11fd6cb91f..4eb9aebead 100644 --- a/impls/nim/Makefile +++ b/impls/nim/Makefile @@ -1,3 +1,5 @@ +include ../../steps.mk + ##################### SOURCES_BASE = types.nim reader.nim printer.nim @@ -5,23 +7,16 @@ SOURCES_REBUILD = $(SOURCES_BASE) env.nim core.nim ##################### -SRCS = step0_repl.nim step1_read_print.nim step2_eval.nim step3_env.nim \ - step4_if_fn_do.nim step5_tco.nim step6_file.nim step7_quote.nim \ - step8_macros.nim step9_try.nim stepA_mal.nim -BINS = $(SRCS:%.nim=%) - -##################### - -all: $(BINS) +all: $(step0A) dist: mal -mal: $(word $(words $(BINS)),$(BINS)) +mal: $(stepA) cp $< $@ -$(BINS): %: %.nim $(SOURCES_REBUILD) +$(step0A): %: %.nim $(SOURCES_REBUILD) nim -d:release --nimcache:nimcache-$@ c $@ clean: - rm -rf nimcache-*/ $(BINS) + rm -rf nimcache-*/ $(step0A) rm -f mal diff --git a/impls/objc/Makefile b/impls/objc/Makefile index 7e6fa2a07c..0c636ba20b 100644 --- a/impls/objc/Makefile +++ b/impls/objc/Makefile @@ -1,12 +1,4 @@ -STEP0_DEPS = mal_readline.c mal_readline.h -STEP1_DEPS = $(STEP0_DEPS) types.h types.m reader.h reader.m printer.h printer.m -STEP2_DEPS = $(STEP1_DEPS) -STEP3_DEPS = $(STEP2_DEPS) env.m -STEP4_DEPS = $(STEP3_DEPS) malfunc.h malfunc.m core.h core.m - -STEPS = 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 +include ../../steps.mk # From: https://blog.tlensing.org/2013/02/24/objective-c-on-linux-setting-up-gnustep-clang-llvm-objective-c-2-0-blocks-runtime-gcd-on-ubuntu-12-04/: # clang `gnustep-config --objc-flags` -o main -x objective-c main.m -fconstant-string-class=NSConstantString -fobjc-nonfragile-abi -fblocks -lgnustep-base -lgnustep-gui -ldispatch -I/usr/local/include/GNUstep -L/usr/local/lib/GNUstep @@ -25,20 +17,19 @@ OBJC_FLAGS := $(shell gnustep-config --objc-flags 2>/dev/null | egrep -v "Enteri OBJC_LIBS := $(filter-out -shared-libgcc,$(shell gnustep-config --base-libs 2>/dev/null | egrep -v "Entering|Leaving")) -ldispatch -lreadline endif -all: $(STEPS) +all: $(step0A) dist: mal mal: stepA_mal cp $< $@ -step0_repl: $(STEP0_DEPS) -step1_read_print: $(STEP1_DEPS) -step2_eval: $(STEP2_DEPS) -step3_env: $(STEP3_DEPS) -step4_if_fn_do step5_tco step6_file step7_quote step8_macros step9_try stepA_mal: $(STEP4_DEPS) +$(step0A): mal_readline.c mal_readline.h +$(step1A): types.h types.m reader.h reader.m printer.h printer.m +$(step3A): env.m +$(step4A): malfunc.h malfunc.m core.h core.m -step%: step%.m +$(step0A): step%: step%.m $(CC) \ -xobjective-c $(filter-out %.h mal_readline%,$+) \ -xc mal_readline.c \ @@ -47,4 +38,4 @@ step%: step%.m $(OBJC_LIBS) clean: - rm -f $(STEPS) *.o *.d mal + rm -f $(step0A) *.o *.d mal diff --git a/impls/objpascal/Makefile b/impls/objpascal/Makefile index b8efc48c43..9400ceed0e 100644 --- a/impls/objpascal/Makefile +++ b/impls/objpascal/Makefile @@ -1,12 +1,4 @@ -STEPS = step0_repl.pas step1_read_print.pas step2_eval.pas \ - step3_env.pas step4_if_fn_do.pas step5_tco.pas \ - step6_file.pas step7_quote.pas step8_macros.pas \ - step9_try.pas stepA_mal.pas - -STEP0_DEPS = mal_readline.pas -STEP1_DEPS = $(STEP0_DEPS) mal_types.pas reader.pas printer.pas -STEP3_DEPS = $(STEP1_DEPS) mal_env.pas -STEP4_DEPS = $(STEP3_DEPS) core.pas +include ../../steps.mk ##################### @@ -17,15 +9,15 @@ USE_READLINE = FPC = fpc -MOBJFPC -ve -Furegexpr/Source $(DEBUG) $(if $(strip $(USE_READLINE)),-dUSE_READLINE,) -all: $(patsubst %.pas,%,$(STEPS)) +all: $(step0A) -step%: step%.pas +$(step0A): %: %.pas $(FPC) $< -step0_repl: $(STEP0_DEPS) -step1_read_print step2_eval: $(STEP1_DEPS) -step3_env: $(STEP3_DEPS) -step4_if_fn_do step5_tco step6_file step7_quote step8_macros step9_try stepA_mal: $(STEP4_DEPS) +$(step0A): mal_readline.pas +$(step1A): mal_types.pas reader.pas printer.pas +$(step3A): mal_env.pas +$(step4A): core.pas clean: - rm -f $(STEPS:%.pas=%) *.o *.ppu regexpr/Source/*.o regexpr/Source/*.ppu mal + rm -f $(step0A) *.o *.ppu regexpr/Source/*.o regexpr/Source/*.ppu mal diff --git a/impls/ocaml/Makefile b/impls/ocaml/Makefile index 1b992475c3..38d0e903a2 100644 --- a/impls/ocaml/Makefile +++ b/impls/ocaml/Makefile @@ -1,36 +1,32 @@ -STEPS = step0_repl.ml step1_read_print.ml step2_eval.ml step3_env.ml \ - step4_if_fn_do.ml step5_tco.ml step6_file.ml step7_quote.ml \ - step8_macros.ml step9_try.ml stepA_mal.ml +include ../../steps.mk + MODULES = types.ml reader.ml printer.ml env.ml core.ml LIBS = str.cmxa unix.cmxa MAL_LIB = mal_lib.cmxa # Apparently necessary with caml 5.0: OPTIONS = -I +str -I +unix -STEP_BINS = $(STEPS:%.ml=%) -LAST_STEP_BIN = $(word $(words $(STEP_BINS)),$(STEP_BINS)) - -all: $(STEP_BINS) +all: $(step0A) dist: mal -mal: $(LAST_STEP_BIN) +mal: $(stepA) cp $< $@ # ocaml repl apparently needs bytecode, not native, compilation. # Just do it all right here: repl: - ocamlc -c $(LIBS:%.cmxa=%.cma) $(MODULES) $(STEPS) + ocamlc -c $(LIBS:%.cmxa=%.cma) $(MODULES) $(step0A:=.ml) rlwrap ocaml $(LIBS:%.cmxa=%.cma) $(MODULES:%.ml=%.cmo) $(MAL_LIB): $(MODULES) ocamlopt -a $(MODULES) -o $@ $(OPTIONS) -$(STEP_BINS): %: %.ml $(MAL_LIB) +$(step0A): %: %.ml $(MAL_LIB) ocamlopt $(LIBS) $(MAL_LIB) $< -o $@ $(OPTIONS) clean: - rm -f $(STEP_BINS) mal mal_lib.* *.cmo *.cmx *.cmi *.o + rm -f $(step0A) mal mal_lib.* *.cmo *.cmx *.cmi *.o format: ocamlformat --inplace --enable-outside-detected-project *.ml diff --git a/impls/purs/Makefile b/impls/purs/Makefile index 5de690be1b..0e6207cbd7 100644 --- a/impls/purs/Makefile +++ b/impls/purs/Makefile @@ -1,35 +1,15 @@ -BINS = step0_repl.js step1_read_print.js step2_eval.js step3_env.js \ - step4_if_fn_do.js step5_tco.js step6_file.js step7_quote.js \ - step8_macros.js step9_try.js stepA_mal.js +include ../../steps.mk OTHER_SRCS = src/Readline.js src/Readline.purs src/Types.purs src/Reader.purs \ src/Printer.purs src/Env.purs src/Core.purs +all: $(step0A:=.js) -all: $(BINS) - -$(BINS): %.js: src/%.purs $(OTHER_SRCS) node_modules/readline-sync - spago bundle-app --main $($(<:src/%=%)) --to $@ - +$(step0A:=.js): s%.js: src/s%.purs $(OTHER_SRCS) node_modules/readline-sync + spago bundle-app --main Mal.S$(firstword $(subst _, ,$*)) --to $@ node_modules/readline-sync: npm install - -##################### - -step0_repl.purs = Mal.Step0 -step1_read_print.purs = Mal.Step1 -step2_eval.purs = Mal.Step2 -step3_env.purs = Mal.Step3 -step4_if_fn_do.purs = Mal.Step4 -step5_tco.purs = Mal.Step5 -step6_file.purs = Mal.Step6 -step7_quote.purs = Mal.Step7 -step8_macros.purs = Mal.Step8 -step9_try.purs = Mal.Step9 -stepA_mal.purs = Mal.StepA - - clean: - rm -rf step*.js output/* \ No newline at end of file + rm -rf $(step0A:=.js) output/* diff --git a/impls/r/Makefile b/impls/r/Makefile index 1b7e65e27f..4c46e97f98 100644 --- a/impls/r/Makefile +++ b/impls/r/Makefile @@ -1,11 +1,9 @@ +include ../../steps.mk + SOURCES_BASE = readline.r types.r reader.r printer.r SOURCES_LISP = env.r core.r stepA_mal.r SOURCES = $(SOURCES_BASE) $(SOURCES_LISP) -STEPS = step0_repl.r step1_read_print.r step2_eval.r step3_env.r \ - step4_if_fn_do.r step5_tco.r step6_file.r \ - step7_quote.r step8_macros.r step9_try.r stepA_mal.r - all: libs dist: mal.r mal @@ -18,7 +16,7 @@ mal: mal.r cat $< >> $@ chmod +x $@ -$(STEPS): libs +$(step0A:=.r): libs .PHONY: libs: lib/rdyncall diff --git a/impls/rexx/Makefile b/impls/rexx/Makefile index b5a49b3b94..6005997f7b 100644 --- a/impls/rexx/Makefile +++ b/impls/rexx/Makefile @@ -1,7 +1,6 @@ -SRCS = step0_repl.rexx step1_read_print.rexx step2_eval.rexx step3_env.rexx \ - step4_if_fn_do.rexx step5_tco.rexx step6_file.rexx step7_quote.rexx \ - step8_macros.rexx step9_try.rexx stepA_mal.rexx -PREPROCESSED = $(SRCS:%.rexx=%.rexxpp) +include ../../steps.mk + +PREPROCESSED = $(step0A:=.rexxpp) all: $(PREPROCESSED) dist diff --git a/impls/rpython/Makefile b/impls/rpython/Makefile index 95a38adfd6..02c87e382e 100644 --- a/impls/rpython/Makefile +++ b/impls/rpython/Makefile @@ -1,32 +1,25 @@ +include ../../steps.mk RPYTHON = rpython -UPPER_STEPS = step4_if_fn_do step5_tco step6_file step7_quote step8_macros step9_try stepA_mal -STEPS = step0_repl step1_read_print step2_eval step3_env $(UPPER_STEPS) - -all: $(STEPS) +all: $(step0A) dist: mal mal: stepA_mal cp $< $@ -%: %.py +$(step0A): %: %.py $(RPYTHON) --output=$@ $< -STEP0_DEPS = mal_readline.py -STEP1_DEPS = $(STEP0_DEPS) mal_types.py reader.py printer.py -STEP3_DEPS = $(STEP1_DEPS) env.py -STEP4_DEPS = $(STEP3_DEPS) core.py - -step0_repl: $(STEP0_DEPS) -step1_read_print step2_eval: $(STEP1_DEPS) -step3_env: $(STEP3_DEPS) -$(UPPER_STEPS): $(STEP4_DEPS) +$(step0A): mal_readline.py +$(step1A): mal_types.py reader.py printer.py +$(step3A): env.py +$(step4A): core.py .PHONY: clean clean: - rm -f mal $(STEPS) *.pyc + rm -f mal $(step0A) *.pyc rm -rf __pycache__ diff --git a/impls/rust/Makefile b/impls/rust/Makefile index 8dab30f396..b3876f63ed 100644 --- a/impls/rust/Makefile +++ b/impls/rust/Makefile @@ -1,28 +1,16 @@ +include ../../steps.mk EXEC_DIR := target/release -UPPER_STEPS := $(EXEC_DIR)/step4_if_fn_do \ - $(EXEC_DIR)/step5_tco \ - $(EXEC_DIR)/step6_file \ - $(EXEC_DIR)/step7_quote \ - $(EXEC_DIR)/step8_macros \ - $(EXEC_DIR)/step9_try \ - $(EXEC_DIR)/stepA_mal -STEP0 := $(EXEC_DIR)/step0_repl -STEP1-2 := $(EXEC_DIR)/step1_read_print \ - $(EXEC_DIR)/step2_eval -STEP3 := $(EXEC_DIR)/step3_env -STEPS := $(STEP0) $(STEP1-2) $(STEP3) $(UPPER_STEPS) +all: $(step0A:%=$(EXEC_DIR)/%) -all: $(STEPS) - -$(STEPS): $(EXEC_DIR)/%: %.rs +$(step0A:%=$(EXEC_DIR)/%): $(EXEC_DIR)/%: %.rs cargo build --release --bin $* -$(STEPS): readline.rs -$(STEP1-2) $(STEP3) $(UPPER_STEPS): types.rs reader.rs printer.rs -$(STEP3) $(UPPER_STEPS): env.rs -$(UPPER_STEPS): core.rs +$(step0A:%=$(EXEC_DIR)/%): readline.rs +$(step1A:%=$(EXEC_DIR)/%): types.rs reader.rs printer.rs +$(step3A:%=$(EXEC_DIR)/%): env.rs +$(step4A:%=$(EXEC_DIR)/%): core.rs lint: rustfmt *.rs diff --git a/impls/scheme/Makefile b/impls/scheme/Makefile index 87b22e450e..ce2e3265f4 100644 --- a/impls/scheme/Makefile +++ b/impls/scheme/Makefile @@ -1,87 +1,60 @@ -BINS = step0_repl step1_read_print step2_eval step3_env step4_if_fn_do step5_tco -BINS += step6_file step7_quote step8_macros step9_try stepA_mal +include ../../steps.mk +# scheme_MODE ?= chibi -CLASSSTEPS = out/step0_repl.class out/step1_read_print.class \ - out/step3_env.class out/step4_if_fn_do.class out/step5_tco.class \ - out/step6_file.class out/step7_quote.class out/step8_macros.class \ - out/step9_try.class out/stepA_mal.class -STEPS = $(if $(filter kawa,$(scheme_MODE)),$(CLASSSTEPS),\ - $(if $(filter chicken,$(scheme_MODE)),$(BINS),\ - $(if $(filter cyclone,$(scheme_MODE)),$(BINS)))) - -KAWA_STEP1_DEPS = out/lib/util.class out/lib/reader.class \ - out/lib/printer.class out/lib/types.class -KAWA_STEP3_DEPS = $(KAWA_STEP1_DEPS) out/lib/env.class -KAWA_STEP4_DEPS = $(KAWA_STEP3_DEPS) out/lib/core.class -CHICKEN_STEP1_DEPS = lib.util.so lib.types.so lib.reader.so lib.printer.so -CHICKEN_STEP3_DEPS = $(CHICKEN_STEP1_DEPS) lib.env.so -CHICKEN_STEP4_DEPS = $(CHICKEN_STEP3_DEPS) lib.core.so -CYCLONE_STEP1_DEPS = lib/util.so lib/reader.so lib/printer.so lib/types.so -CYCLONE_STEP3_DEPS = $(CYCLONE_STEP1_DEPS) lib/env.so -CYCLONE_STEP4_DEPS = $(CYCLONE_STEP3_DEPS) lib/core.so - -STEP1_DEPS = $(if $(filter kawa,$(scheme_MODE)),$(KAWA_STEP1_DEPS),\ - $(if $(filter chicken,$(scheme_MODE)),$(CHICKEN_STEP1_DEPS),\ - $(if $(filter cyclone,$(scheme_MODE)),$(CYCLONE_STEP1_DEPS)))) -STEP3_DEPS = $(if $(filter kawa,$(scheme_MODE)),$(KAWA_STEP3_DEPS),\ - $(if $(filter chicken,$(scheme_MODE)),$(CHICKEN_STEP3_DEPS),\ - $(if $(filter cyclone,$(scheme_MODE)),$(CYCLONE_STEP3_DEPS)))) -STEP4_DEPS = $(if $(filter kawa,$(scheme_MODE)),$(KAWA_STEP4_DEPS),\ - $(if $(filter chicken,$(scheme_MODE)),$(CHICKEN_STEP4_DEPS),\ - $(if $(filter cyclone,$(scheme_MODE)),$(CYCLONE_STEP4_DEPS)))) +# Chicken requires reader, printer after util, types. +deps1 := util types reader printer +deps3 := env +deps4 := core +deps := $(deps1) $(deps3) $(deps4) +ifeq ($(scheme_MODE),kawa) KAWALIB = kawa --r7rs --no-warn-unused -d out -C KAWA = kawa --r7rs --no-warn-unused -d out --main -C + all: $(step0A:%=out/%.class) + $(step0A:%=out/%.class): out/%.class: %.scm + $(KAWA) $< + $(step1A:%=out/%.class): $(deps1:%=out/lib/%.class) + $(step3A:%=out/%.class): $(deps3:%=out/lib/%.class) + $(step4A:%=out/%.class): $(deps4:%=out/lib/%.class) + $(deps:%=out/lib/%.class): out/lib/%.class: lib/%.scm + $(KAWALIB) $< + $(deps:%=lib/%.scm): lib/%.scm: + ln -s $*.sld $@ + +else ifeq ($(scheme_MODE),chicken) CHICKEN = csc -setup-mode -host -O3 -R r7rs CHICKENLIB = $(CHICKEN) -D compiling-extension -J -s -regenerate-import-libraries + all: $(step0A) + $(step0A): %: %.scm + $(CHICKEN) $< + $(step1A): $(deps1:%=lib.%.so) + $(step3A): $(deps3:%=lib.%.so) + $(step4A): $(deps4:%=lib.%.so) + $(deps:%=lib.%.so): lib.%.so: lib/%.sld + $(CHICKENLIB) $< -o $@ + +else ifeq ($(scheme_MODE),cyclone) CYCLONELIB = cyclone -O2 CYCLONE = $(CYCLONELIB) + all: $(step0A) + $(step0A): %: %.scm + $(CYCLONE) $< + $(step1A): $(deps1:%=lib/%.so) + $(step3A): $(deps3:%=lib/%.so) + $(step4A): $(deps4:%=lib/%.so) + $(deps:%=lib/%.so): %.so: %.sld + $(CYCLONELIB) $< + +# chibi gauche sagittarius foment are interpreted +endif -SCMLIB = $(if $(filter kawa,$(scheme_MODE)),$(KAWALIB),\ - $(if $(filter chicken,$(scheme_MODE)),$(CHICKENLIB),\ - $(if $(filter cyclone,$(scheme_MODE)),$(CYCLONELIB)))) -SCM = $(if $(filter kawa,$(scheme_MODE)),$(KAWA),\ - $(if $(filter chicken,$(scheme_MODE)),$(CHICKEN),\ - $(if $(filter cyclone,$(scheme_MODE)),$(CYCLONE)))) - -MKDIR = mkdir -p -SYMLINK = ln -sfr RM = rm -f RMR = rm -rf -all: $(STEPS) - .PHONY: clean -.PRECIOUS: lib/%.scm - -lib/%.scm: lib/%.sld - $(SYMLINK) $< $@ - -out/lib/%.class: lib/%.scm - $(SCMLIB) $< - -out/%.class: %.scm - $(SCM) $< - -lib.%.so: lib/%.sld - $(SCMLIB) $< -o $@ - -lib/%.so: lib/%.sld - $(SCMLIB) $< - -%: %.scm - $(SCM) $< - -out/step1_read_print.class out/step2_eval.class: $(STEP1_DEPS) -out/step3_env.class: $(STEP3_DEPS) -out/step4_if_fn_do.class out/step5_tco.class out/step6_file.class out/step7_quote.class out/step8_macros.class out/step9_try.class out/stepA_mal.class: $(STEP4_DEPS) - -step1_read_print.scm step2_eval.scm: $(STEP1_DEPS) -step3_env.scm: $(STEP3_DEPS) -step4_if_fn_do.scm step5_tco.scm step6_file.scm step7_quote.scm step8_macros.scm step9_try.scm stepA_mal.scm: $(STEP4_DEPS) clean: $(RM) lib/*.scm lib/*.so lib/*.c lib/*.o lib/*.meta - $(RM) lib.*.scm *.build.sh *.install.sh *.link *.so *.c *.o $(BINS) + $(RM) lib.*.scm *.build.sh *.install.sh *.link *.so *.c *.o $(step0A) $(RMR) out diff --git a/impls/skew/Makefile b/impls/skew/Makefile index 58bd6641fc..e7c9aa03ef 100644 --- a/impls/skew/Makefile +++ b/impls/skew/Makefile @@ -1,19 +1,15 @@ -STEPS = 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 +include ../../steps.mk SOURCES_BASE = util.sk types.sk reader.sk printer.sk -STEP3_DEPS = $(SOURCES_BASE) env.sk -STEP4_DEPS = $(STEP3_DEPS) core.sk - -all: $(foreach s,$(STEPS),$(s).js) dist +all: $(step0A:=.js) dist dist: mal -step0_repl.js step1_read_print.js step2_eval.js step3_env.js: $(STEP3_DEPS) -step4_if_fn_do.js step5_tco.js step6_file.js step7_quote.js step8_macros.js step9_try.js stepA_mal.js: $(STEP4_DEPS) +$(step0A:=.js): $(SOURCES_BASE) env.sk +$(step4A:=.js): core.sk -%.js: %.sk +$(step0A:=.js): %.js: %.sk skewc --target=js --release --output-file=$@ $^ mal: stepA_mal.js diff --git a/impls/sml/Makefile b/impls/sml/Makefile index 1792efc453..4eb880dc13 100644 --- a/impls/sml/Makefile +++ b/impls/sml/Makefile @@ -1,4 +1,7 @@ -STEP_BINS = step0_repl step1_read_print step2_eval step3_env step4_if_fn_do step6_file step7_quote step8_macros step9_try stepA_mal +include ../../steps.mk + +# No TCO in this implementation. +step5 := sml_MODE_DEFAULT = polyml sml_MODE_CONFIG = .smlmode @@ -11,51 +14,42 @@ ifneq ($(sml_MODE),$(shell cat $(sml_MODE_CONFIG) 2> /dev/null)) $(shell rm $(sml_MODE_CONFIG) 2> /dev/null) endif -ifeq ($(sml_MODE),mlton) -SMLC = mlton -SMLCOUTFLAG = -output -BUILD_FILE = %.mlb -build_args = $1 -endif -ifeq ($(sml_MODE),mosml) -SMLC = mosmlc -SMLCOUTFLAG = -o -BUILD_FILE = %.mlb -build_args = LargeInt.sml -toplevel $(shell grep "\\.sml" $1) -endif -ifeq ($(sml_MODE),polyml) -SMLC = polyc -SMLCOUTFLAG = -o -BUILD_FILE = .%.poly.sml -build_args = $1 -endif - -all: $(STEP_BINS) +all: $(step0A) dist: mal mal: stepA_mal cp $< $@ -.%.dep: %.mlb +$(step0A:%=.%.dep): .%.dep: %.mlb @echo sml-deps -o $@ $< - $(eval DEPS := $(shell grep "\\.sml" $<)) + $(eval DEPS := $(shell grep '[.]sml' $<)) @echo "$(@:.%.dep=%) $@: $(DEPS)" > $@ -include $(STEP_BINS:%=.%.dep) +include $(step0A:%=.%.dep) -.%.poly.sml: %.mlb +$(step0A:%=.%.poly.sml): .%.poly.sml: %.mlb @echo generate-sml -o $@ $< - @grep "\\.sml" $< | grep -v main | xargs printf "use \"%s\";\n" > $@ + @grep '[.]sml' $< | grep -v main | xargs printf 'use "%s";\n' > $@ # some hackery to let Make track changes in sml_MODE $(sml_MODE_CONFIG): @echo $(sml_MODE) > $@ -$(STEP_BINS): %: $(BUILD_FILE) $(sml_MODE_CONFIG) - $(SMLC) $(SMLCOUTFLAG) $@ $(call build_args,$<) +ifeq ($(sml_MODE),mlton) + $(step0A): %: %.mlb $(sml_MODE_CONFIG) + mlton -output $@ $< +else ifeq ($(sml_MODE),mosml) + $(step0A): %: %.mlb $(sml_MODE_CONFIG) + mosmlc -o $@ LargeInt.sml -toplevel `grep '[.]sml' $<` +else ifeq ($(sml_MODE),polyml) + $(step0A): %: .%.poly.sml $(sml_MODE_CONFIG) + polyc -o $@ $< +else + $(error Unknown sml_MODE: $(sml_MODE)) +endif clean: - rm -f $(STEP_BINS) .*.dep *.ui *.uo .*.poly.sml $(sml_MODE_CONFIG) + rm -f $(step0A) .*.dep *.ui *.uo .*.poly.sml $(sml_MODE_CONFIG) .PHONY: all clean diff --git a/impls/swift3/Makefile b/impls/swift3/Makefile index a76309c52c..921f640a9e 100644 --- a/impls/swift3/Makefile +++ b/impls/swift3/Makefile @@ -1,29 +1,24 @@ +include ../../steps.mk + ifneq ($(shell which xcrun),) SWIFT = xcrun -sdk macosx swiftc else SWIFT = swiftc endif -STEP3_DEPS = Sources/types.swift Sources/reader.swift Sources/printer.swift Sources/env.swift -STEP4_DEPS = $(STEP3_DEPS) Sources/core.swift - -STEPS = 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 - -all: $(STEPS) +all: $(step0A) dist: mal mal: stepA_mal cp $< $@ -step1_read_print step2_eval step3_env: $(STEP3_DEPS) -step4_if_fn_do step5_tco step6_file step7_quote step8_macros step9_try stepA_mal: $(STEP4_DEPS) +$(step1A): Sources/types.swift Sources/reader.swift Sources/printer.swift Sources/env.swift +$(step4A): Sources/core.swift -step%: Sources/step%/main.swift +$(step0A): %: Sources/%/main.swift $(SWIFT) $+ -o $@ clean: - rm -f $(STEPS) mal + rm -f $(step0A) mal diff --git a/impls/swift4/Makefile b/impls/swift4/Makefile index 5bb375446d..bec8dbf183 100644 --- a/impls/swift4/Makefile +++ b/impls/swift4/Makefile @@ -1,28 +1,23 @@ +include ../../steps.mk + ifneq ($(shell which xcrun),) SWIFT = xcrun -sdk macosx swiftc else SWIFT = swiftc endif -STEP3_DEPS = Sources/types.swift Sources/reader.swift Sources/printer.swift Sources/env.swift -STEP4_DEPS = $(STEP3_DEPS) Sources/core.swift - -STEPS = 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 - -all: $(STEPS) +all: $(step0A) dist: mal mal: stepA_mal cp $< $@ -step1_read_print step2_eval step3_env: $(STEP3_DEPS) -step4_if_fn_do step5_tco step6_file step7_quote step8_macros step9_try stepA_mal: $(STEP4_DEPS) +$(step1A): Sources/types.swift Sources/reader.swift Sources/printer.swift Sources/env.swift +$(step4A): Sources/core.swift -step%: Sources/step%/main.swift +$(step0A): %: Sources/%/main.swift $(SWIFT) $+ -o $@ clean: - rm -f $(STEPS) mal + rm -f $(step0A) mal diff --git a/impls/ts/Makefile b/impls/ts/Makefile index 1ea5a79e59..d4fd1ed6fc 100644 --- a/impls/ts/Makefile +++ b/impls/ts/Makefile @@ -1,19 +1,17 @@ -STEPS = 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 +include ../../steps.mk all: ts node_modules: npm install -step%.js: node_modules types.ts reader.ts printer.ts env.ts core.ts step%.ts +$(step0A:=.js): %.js: node_modules types.ts reader.ts printer.ts env.ts core.ts %.ts ./node_modules/.bin/tsc -p ./ .PHONY: ts clean -ts: $(foreach s,$(STEPS),$(s).js) +ts: $(step0A:=.js) clean: rm -f *.js diff --git a/impls/vala/Makefile b/impls/vala/Makefile index 741c8eba5a..a792b3efa7 100644 --- a/impls/vala/Makefile +++ b/impls/vala/Makefile @@ -1,13 +1,9 @@ -PROGRAMS = 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 -AUX1 = gc.vala types.vala reader.vala printer.vala -AUX3 = $(AUX1) env.vala -AUX4 = $(AUX3) core.vala +include ../../steps.mk # Inhibit default make rules, in case they try to build from leftover .c files .SUFFIXES: -all: $(PROGRAMS) +all: $(step0A) # You can define VFLAGS on the command line to add flags to the vala compiler. # Some useful ones: @@ -28,25 +24,17 @@ all: $(PROGRAMS) # -D GC_ALWAYS make the garbage collector run at every opportunity # (good for making occasional GC errors show up sooner) -$(PROGRAMS): %: %.vala +$(step0A): %: %.vala valac $(VFLAGS) -o $@ $^ $(DEFINES) --pkg readline -X -lreadline -step1_read_print step2_eval: override DEFINES += -D NO_ENV +$(step1) $(step2): override DEFINES += -D NO_ENV -step0_repl: -step1_read_print: $(AUX1) -step2_eval: $(AUX1) -step3_env: $(AUX3) -step4_if_fn_do: $(AUX4) -step5_tco: $(AUX4) -step6_file: $(AUX4) -step7_quote: $(AUX4) -step8_macros: $(AUX4) -step9_try: $(AUX4) -stepA_mal: $(AUX4) +$(step1A): gc.vala types.vala reader.vala printer.vala +$(step3A): env.vala +$(step4A): core.vala clean: clean-c - rm -f $(PROGRAMS) + rm -f $(step0A) clean-c: rm -f *.c *.h diff --git a/impls/vb/Makefile b/impls/vb/Makefile index 4f269959e1..61cfc41924 100644 --- a/impls/vb/Makefile +++ b/impls/vb/Makefile @@ -1,29 +1,26 @@ +include ../../steps.mk + ##################### DEBUG = SOURCES_BASE = readline.vb types.vb reader.vb printer.vb -SOURCES_LISP = env.vb core.vb stepA_mal.vb -SOURCES = $(SOURCES_BASE) $(SOURCES_LISP) +SOURCES_LISP = env.vb core.vb ##################### -SRCS = step0_repl.vb step1_read_print.vb step2_eval.vb \ - step3_env.vb step4_if_fn_do.vb step5_tco.vb step6_file.vb \ - step7_quote.vb step8_macros.vb step9_try.vb stepA_mal.vb - LIB_CS_SRCS = getline.cs -LIB_VB_SRCS = $(filter-out step%,$(filter %.vb,$(SOURCES))) +LIB_VB_SRCS = $(SOURCES_BASE) $(SOURCES_LISP) FLAGS = $(if $(strip $(DEBUG)),-debug:full,) ##################### -all: $(patsubst %.vb,%.exe,$(SRCS)) +all: $(step0A:=.exe) dist: mal.exe -mal.exe: $(patsubst %.vb,%.exe,$(word $(words $(SOURCES)),$(SOURCES))) +mal.exe: $(stepA).exe cp $< $@ mal_cs.dll: $(LIB_CS_SRCS) diff --git a/impls/vhdl/Makefile b/impls/vhdl/Makefile index e76b8e104a..f383c40fae 100644 --- a/impls/vhdl/Makefile +++ b/impls/vhdl/Makefile @@ -1,35 +1,31 @@ -SRCS = step0_repl.vhdl step1_read_print.vhdl step2_eval.vhdl step3_env.vhdl \ - step4_if_fn_do.vhdl step5_tco.vhdl step6_file.vhdl step7_quote.vhdl \ - step8_macros.vhdl step9_try.vhdl stepA_mal.vhdl -OBJS = $(SRCS:%.vhdl=%.o) -BINS = $(OBJS:%.o=%) +include ../../steps.mk + OTHER_SRCS = pkg_readline.vhdl types.vhdl printer.vhdl reader.vhdl env.vhdl core.vhdl OTHER_OBJS = $(OTHER_SRCS:%.vhdl=%.o) ##################### -all: $(BINS) +all: $(step0A) dist: mal -mal: $(word $(words $(BINS)),$(BINS)) +mal: $(stepA) cp $< $@ work-obj93.cf: $(OTHER_SRCS) rm -f work-obj93.cf ghdl -i $+ -$(OTHER_OBJS): %.o: %.vhdl work-obj93.cf - ghdl -a -g $(@:%.o=%.vhdl) - -$(OBJS): %.o: %.vhdl $(OTHER_OBJS) - ghdl -a -g $(@:%.o=%.vhdl) +$(OTHER_OBJS): work-obj93.cf +$(step0A:=.o): $(OTHER_OBJS) +$(OTHER_OBJS) $(step0A:=.o): %.o: %.vhdl + ghdl -a -g $< -$(patsubst %.o,%,$(filter step%,$(OBJS))): $(OTHER_OBJS) -$(BINS): %: %.o +$(step0A): $(OTHER_OBJS) +$(step0A): %: %.o ghdl -e -g $@ # ghdl linker creates a lowercase executable; rename it to stepA_mal if [ "$@" = "stepA_mal" ]; then mv stepa_mal $@; fi clean: - rm -f $(OBJS) $(BINS) $(OTHER_OBJS) work-obj93.cf mal + rm -f *.o $(step0A) work-obj93.cf mal diff --git a/impls/wasm/Makefile b/impls/wasm/Makefile index ce06ca4b71..5d9ef9d321 100644 --- a/impls/wasm/Makefile +++ b/impls/wasm/Makefile @@ -1,3 +1,5 @@ +include ../../steps.mk + MODE ?= $(strip \ $(if $(filter wace_libc,$(wasm_MODE)),\ libc,\ @@ -10,31 +12,21 @@ EXT = .wasm WASM_AS ?= wasm-as WAMP ?= node_modules/.bin/wamp -STEP0_DEPS = $(WAMP) platform_$(MODE).wam string.wam printf.wam -STEP1_DEPS = $(STEP0_DEPS) types.wam mem.wam debug.wam reader.wam printer.wam -STEP3_DEPS = $(STEP1_DEPS) env.wam -STEP4_DEPS = $(STEP3_DEPS) core.wam - -STEPS = 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 - -all: $(STEPS:=$(EXT)) +all: $(step0A:=$(EXT)) $(WAMP): npm install -%.wat: %.wam +$(step0A:=.wat): %.wat: %.wam $(WAMP) $(filter %.wam,$^) > $*.wat -%.wasm: %.wat +$(step0A:=.wasm): %.wasm: %.wat $(WASM_AS) $< -o $@ -step0_repl.wat: $(STEP0_DEPS) -step1_read_print.wat step2_eval.wat: $(STEP1_DEPS) -step3_env.wat: $(STEP3_DEPS) -step4_if_fn_do.wat step5_tco.wat step6_file.wat: $(STEP4_DEPS) -step7_quote.wat step8_macros.wat step9_try.wat stepA_mal.wat: $(STEP4_DEPS) +$(step0A:=.wat): $(WAMP) platform_$(MODE).wam string.wam printf.wam +$(step1A:=.wat): types.wam mem.wam debug.wam reader.wam printer.wam +$(step3A:=.wat): env.wam +$(step4A:=.wat): core.wam .PHONY: clean diff --git a/impls/zig/Makefile b/impls/zig/Makefile index 1eda252d6a..c6141264ea 100644 --- a/impls/zig/Makefile +++ b/impls/zig/Makefile @@ -1,14 +1,13 @@ +include ../../steps.mk -STEPS = 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 - -all: $(STEPS) +all: $(step0A) zig_opts += --release=safe zig_opts += -Doptimize=Debug -$(STEPS): +$(step0A): zig build $(zig_opts) -Dname=$@ -Droot_source_file=$@.zig -.PHONY: all $(STEPS) clean +.PHONY: all $(step0A) clean clean: rm -fr .zig-cache/ zig-out/ diff --git a/process/guide.md b/process/guide.md index bda640206d..22474b6b0d 100644 --- a/process/guide.md +++ b/process/guide.md @@ -139,7 +139,13 @@ by the quux_STEP_TO_PROG macro. The top-level Makefile will attempt to build those targets before running tests. If it is a scripting language/uncompiled, then no Makefile is necessary because quux_STEP_TO_PROG will point to a source file that already exists and -does not need to be compiled/built. +does not need to be compiled/built, but a minimal Makefile like the +following will help the test driver. +``` +all clean: +``` + +The `steps.mk` helper may be useful, especially for the compiled case. ## General hints diff --git a/steps.mk b/steps.mk new file mode 100644 index 0000000000..87e2172593 --- /dev/null +++ b/steps.mk @@ -0,0 +1,66 @@ +# Helper for impls/quux/Makefile + +# The following example assumes that +# * the implementation language is compiled and linked in two steps +# * the source files carry the `.qx` extension +# * the quux_STEP_TO_PROG macro maps % to obj/%, +# * only steps 0-2 are implemented (`all` only builds these steps). + +# include ../../steps.mk + +# deps1A := obj/printer.o obj/reader.o +# deps3A := obj/env.o +# deps4A := obj/core.o + +# .PHONY: all +# all: $(step02:%=obj/%) + +# $(step1A:%=obj/%): $(deps1A) +# $(step3A:%=obj/%): $(deps3A) +# $(step4A:%=obj/%): $(deps4A) +# $(step0A:%=obj/%): obj/%: obj/%.o +# LINK -o $@ $^ + +# $(step0A:%=obj/%.o) $(deps1A) $(deps3A) $(deps4A): obj/%.o: %.qx | obj +# COMPILE -o $@ $< + +# obj: +# mkdir obj + +# .PHONY: clean +# clean: +# rm -fr obj + +step0 := step0_repl +step1 := step1_read_print +step2 := step2_eval +step3 := step3_env +step4 := step4_if_fn_do +step5 := step5_tco +step6 := step6_file +step7 := step7_quote +step8 := step8_macros +step9 := step9_try +stepA := stepA_mal + +# Set `step5:=` if you want to remove it from the following ranges. + +step01 = $(step0) $(step1) +step02 = $(step0) $(step1) $(step2) +step03 = $(step0) $(step1) $(step2) $(step3) +step04 = $(step0) $(step1) $(step2) $(step3) $(step4) +step05 = $(step0) $(step1) $(step2) $(step3) $(step4) $(step5) +step06 = $(step0) $(step1) $(step2) $(step3) $(step4) $(step5) $(step6) +step07 = $(step0) $(step1) $(step2) $(step3) $(step4) $(step5) $(step6) $(step7) +step08 = $(step0) $(step1) $(step2) $(step3) $(step4) $(step5) $(step6) $(step7) $(step8) +step09 = $(step0) $(step1) $(step2) $(step3) $(step4) $(step5) $(step6) $(step7) $(step8) $(step9) +step0A = $(step0) $(step1) $(step2) $(step3) $(step4) $(step5) $(step6) $(step7) $(step8) $(step9) $(stepA) +step1A = $(step1) $(step2) $(step3) $(step4) $(step5) $(step6) $(step7) $(step8) $(step9) $(stepA) +step2A = $(step2) $(step3) $(step4) $(step5) $(step6) $(step7) $(step8) $(step9) $(stepA) +step3A = $(step3) $(step4) $(step5) $(step6) $(step7) $(step8) $(step9) $(stepA) +step4A = $(step4) $(step5) $(step6) $(step7) $(step8) $(step9) $(stepA) +step5A = $(step5) $(step6) $(step7) $(step8) $(step9) $(stepA) +step6A = $(step6) $(step7) $(step8) $(step9) $(stepA) +step7A = $(step7) $(step8) $(step9) $(stepA) +step8A = $(step8) $(step9) $(stepA) +step9A = $(step9) $(stepA)