Skip to content

Commit 8e02bb5

Browse files
committed
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
1 parent 2bbfaa5 commit 8e02bb5

49 files changed

Lines changed: 486 additions & 716 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

impls/ada.2/Makefile

Lines changed: 21 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
include ../../steps.mk
2+
13
ifdef DEBUG
24
ADAFLAGS := -Wall -Wextra -gnatw.eH.Y -gnatySdouxy -gnatVa -g -gnataEfoqQ \
35
-fstack-check -pg
@@ -13,62 +15,28 @@ CARGS = $(ADAFLAGS)
1315
# Linker arguments.
1416
LARGS = $(LDFLAGS) -lreadline
1517

16-
step0 := step0_repl
17-
step13 := step1_read_print \
18-
step2_eval \
19-
step3_env
20-
step49 := step4_if_fn_do \
21-
step5_tco \
22-
step6_file \
23-
step7_quote \
24-
step8_macros \
25-
step9_try
26-
stepa := stepA_mal
27-
steps := $(step0) $(step13) $(step49) $(stepa)
28-
2918
.PHONY: all clean
30-
all: $(steps)
19+
all: $(step0A)
3120
clean:
32-
$(RM) *~ *.adt *.ali *.o b~*.ad[bs] gmon.out $(steps)
21+
$(RM) *~ *.adt *.ali *.o b~*.ad[bs] gmon.out $(step0A)
3322

3423
# Tell Make how to detect out-of-date executables, and let gnatmake do
3524
# the rest when it must be executed.
36-
sources = $(foreach unit,$1,$(unit).adb $(unit).ads)
37-
TYPES := $(call sources,\
38-
envs \
39-
err \
40-
garbage_collected \
41-
printer \
42-
reader \
43-
readline \
44-
types \
45-
types-atoms \
46-
types-builtins \
47-
types-fns \
48-
types-maps \
49-
types-sequences \
50-
types-strings \
51-
)
52-
CORE := $(call sources,\
53-
core \
54-
)
55-
56-
$(step0) : %: %.adb
57-
$(step13): %: %.adb $(TYPES)
58-
$(step49): %: %.adb $(TYPES) $(CORE)
59-
$(stepa) : stepA%: stepa%.adb $(TYPES) $(CORE)
60-
$(steps) :
25+
$(step09): %: %.adb
26+
$(stepA): stepa_mal.adb
27+
$(step1A): envs.adb envs.ads
28+
$(step1A): err.adb err.ads
29+
$(step1A): garbage_collected.adb garbage_collected.ads
30+
$(step1A): printer.adb printer.ads
31+
$(step1A): reader.adb reader.ads
32+
$(step1A): readline.adb readline.ads
33+
$(step1A): types.adb types.ads
34+
$(step1A): types-atoms.adb types-atoms.ads
35+
$(step1A): types-builtins.adb types-builtins.ads
36+
$(step1A): types-fns.adb types-fns.ads
37+
$(step1A): types-maps.adb types-maps.ads
38+
$(step1A): types-sequences.adb types-sequences.ads
39+
$(step1A): types-strings.adb types-strings.ads
40+
$(step4A): core.adb core.ads
41+
$(step0A):
6142
gnatmake $< -o $@ -cargs $(CARGS) -largs $(LARGS)
62-
63-
.PHONY: steps.diff
64-
steps.diff:
65-
diff -u step0_*.adb step1_*.adb || true
66-
diff -u step1_*.adb step2_*.adb || true
67-
diff -u step2_*.adb step3_*.adb || true
68-
diff -u step3_*.adb step4_*.adb || true
69-
diff -u step4_*.adb step5_*.adb || true
70-
diff -u step5_*.adb step6_*.adb || true
71-
diff -u step6_*.adb step7_*.adb || true
72-
diff -u step7_*.adb step8_*.adb || true
73-
diff -u step8_*.adb step9_*.adb || true
74-
diff -u step9_*.adb stepa_*.adb || true

impls/ada/Makefile

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,16 @@
1-
PROGS=step0_repl step1_read_print step2_eval step3_env step4_if_fn_do \
2-
step5_tco step6_file step7_quote step8_macros step9_try
1+
include ../../steps.mk
32

4-
all: ${PROGS} stepA_mal
3+
all: $(step0A)
54

65
obj:
7-
mkdir -p $@
6+
mkdir obj
87

98
# stepA_mal is awkward because GNAT requires the filename to be lowercase
10-
${PROGS} stepa_mal: force obj
11-
gnatmake -O3 -gnata $@.adb -D obj
12-
13-
# so we make stepa_mal and just move it.
14-
stepA_mal: stepa_mal
15-
mv $< $@
9+
$(step0A): | obj
10+
gnatmake -O3 -gnata $(subst A,a,$@).adb -D obj -o $@
11+
# Delegate the dependency handling to gnatmake.
12+
.PHONY: $(step0A)
1613

1714
clean:
18-
rm -f ${PROGS}
15+
rm -f $(step0A)
1916
rm -rf obj
20-
21-
.PHONY: force
22-
23-
force:

impls/basic/Makefile

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,35 @@
1+
include ../../steps.mk
2+
13
basic_MODE = cbm
24
BASICPP_OPTS = --mode $(basic_MODE)
35

46
FBC = fbc -lang qb
57

6-
STEPS4_A = step4_if_fn_do.bas step5_tco.bas step6_file.bas \
7-
step7_quote.bas step8_macros.bas step9_try.bas stepA_mal.bas
8-
STEPS3_A = step3_env.bas $(STEPS4_A)
9-
STEPS1_A = step1_read_print.bas step2_eval.bas $(STEPS3_A)
10-
STEPS0_A = step0_repl.bas $(STEPS1_A)
11-
12-
all: $(if $(filter qbasic,$(basic_MODE)),$(subst .bas,,$(STEPS0_A)),$(STEPS0_A))
13-
14-
$(STEPS0_A): debug.in.bas mem.in.bas readline.in.bas
15-
$(STEPS1_A): types.in.bas reader.in.bas printer.in.bas
16-
$(STEPS3_A): env.in.bas
17-
$(STEPS4_A): core.in.bas
8+
ifeq (qbasic,$(basic_MODE))
9+
all: $(step0A)
10+
else
11+
all: $(step0A:=.bas)
12+
endif
1813

14+
$(step0A:=.bas): debug.in.bas mem.in.bas readline.in.bas
15+
$(step1A:=.bas): types.in.bas reader.in.bas printer.in.bas
16+
$(step3A:=.bas): env.in.bas
17+
$(step4A:=.bas): core.in.bas
1918

2019

21-
step%.bas: step%.in.bas
20+
$(step0A:=.bas): %.bas: %.in.bas
2221
./basicpp.py $(BASICPP_OPTS) $< > $@
2322

2423
tests/%.bas: tests/%.in.bas
2524
./basicpp.py $(BASICPP_OPTS) $< > $@
2625

2726
# QBasic specific compilation rule
28-
step%: step%.bas
27+
$(step0A): %: %.bas
2928
$(FBC) $< -x $@
3029

3130
# CBM/C64 image rules
3231

33-
%.prg: %.bas
32+
$(step0A:=.prg): %.prg: %.bas
3433
cat $< | tr "A-Z" "a-z" > $<.tmp
3534
#cat $< | sed 's/["]\@<!\<\w\+\>["]\@!/\L&/g' > $<.tmp
3635
petcat -w2 -nc -o $@ $<.tmp
@@ -58,5 +57,5 @@ mal.d64: mal.prg .args.mal.prg core.mal.prg
5857
.PHONY: clean
5958

6059
clean:
61-
rm -f $(STEPS0_A) $(subst .bas,,$(STEPS0_A)) *.d64 *.prg
60+
rm -f $(step0A:=.bas) $(step0A) *.d64 *.prg
6261
rm -rf ./internal

impls/c.2/Makefile

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
include ../../steps.mk
2+
13
CC = gcc
24

35
CFLAGS = -std=c99 -g -Wall -Wextra -fanalyzer
@@ -40,37 +42,20 @@ pkgconfig_modules += bdw-gc
4042
CFLAGS += $(shell pkg-config --cflags $(pkgconfig_modules))
4143
LDLIBS += $(shell pkg-config --libs $(pkgconfig_modules))
4244

43-
S0 = step0_repl
44-
S1 = step1_read_print
45-
S2 = step2_eval
46-
S3 = step3_env
47-
S4 = step4_if_fn_do
48-
S5 = step5_tco
49-
S6 = step6_file
50-
S7 = step7_quote
51-
S8 = step8_macros
52-
S9 = step9_try
53-
SA = stepA_mal
54-
55-
S4+ := $(S4) $(S5) $(S6) $(S7) $(S8) $(S9) $(SA)
56-
S3+ := $(S3) $(S4+)
57-
S1+ := $(S1) $(S2) $(S3+)
58-
S0+ := $(S0) $(S1+)
59-
60-
all: $(S0+)
45+
all: $(step0A)
6146

6247
# GCC could create temporary objects files, but separate recipes for
6348
# .o objects give faster build cycles when debugging.
64-
$(S0+): readline.o
65-
$(S1+): error.o hashmap.o linked_list.o printer.o reader.o types.o vector.o
66-
$(S3+): env.o
67-
$(S4+): core.o
49+
$(step0A): readline.o
50+
$(step1A): error.o hashmap.o linked_list.o printer.o reader.o types.o vector.o
51+
$(step3A): env.o
52+
$(step4A): core.o
6853

6954
include deps
7055
deps:
7156
$(CC) -MM -MF- *.c > $@
7257

7358
clean:
74-
rm -f $(S0+) *.o deps gmon.out
59+
rm -f $(step0A) *.o deps gmon.out
7560

7661
.PHONY: all clean

impls/c/Makefile

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
1+
include ../../steps.mk
2+
13
USE_READLINE ?=
24
USE_GC ?= 1
35
CFLAGS ?= -g -O2
46
LDFLAGS ?= -g
57

68
#####################
79

8-
SRCS = step0_repl.c step1_read_print.c step2_eval.c step3_env.c \
9-
step4_if_fn_do.c step5_tco.c step6_file.c step7_quote.c \
10-
step8_macros.c step9_try.c stepA_mal.c
11-
OBJS = $(SRCS:%.c=%.o)
12-
BINS = $(OBJS:%.o=%)
1310
OTHER_OBJS = types.o readline.o reader.o printer.o env.o core.o interop.o
1411
OTHER_HDRS = types.h readline.h reader.h printer.h core.h interop.h
1512

@@ -45,17 +42,17 @@ override LDLIBS += \
4542

4643
#####################
4744

48-
all: $(BINS)
45+
all: $(step0A)
4946

5047
dist: mal
5148

52-
mal: $(word $(words $(BINS)),$(BINS))
49+
mal: $(stepA)
5350
cp $< $@
5451

55-
$(OBJS) $(OTHER_OBJS): %.o: %.c $(OTHER_HDRS)
52+
$(step0A:=.o) $(OTHER_OBJS): %.o: %.c $(OTHER_HDRS)
5653

57-
$(patsubst %.o,%,$(filter step%,$(OBJS))): $(OTHER_OBJS)
58-
$(BINS): %: %.o
54+
$(step0A): $(OTHER_OBJS)
55+
$(step0A): %: %.o
5956

6057
clean:
61-
rm -f $(OBJS) $(BINS) $(OTHER_OBJS) mal
58+
rm -f *.o $(step0A) mal

impls/coffee/Makefile

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,16 @@
1+
include ../../steps.mk
2+
13
SOURCES_BASE = node_readline.coffee types.coffee \
24
reader.coffee printer.coffee
35
SOURCES_LISP = env.coffee core.coffee stepA_mal.coffee
46
SOURCES = $(SOURCES_BASE) $(SOURCES_LISP)
57

6-
STEPS = step0_repl.coffee step1_read_print.coffee \
7-
step2_eval.coffee step3_env.coffee step4_if_fn_do.coffee \
8-
step5_tco.coffee step6_file.coffee step7_quote.coffee \
9-
step8_macros.coffee step9_try.coffee stepA_mal.coffee
10-
118
all: node_modules dist
129

1310
node_modules:
1411
npm install
1512

16-
$(STEPS): node_modules
13+
$(step0A:=.coffee): node_modules
1714

1815
dist: mal.coffee mal
1916

impls/common-lisp/Makefile

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
include ../../steps.mk
2+
13
# Helper functions
24
define record_lisp
35
$(shell (test -f "hist/$(1)_impl" && grep -q $(2) "hist/$(1)_impl") || echo $(2) > "hist/$(1)_impl")
@@ -15,9 +17,6 @@ LISP ?= sbcl
1517
ABCL ?= abcl
1618
MKCL ?= mkcl
1719

18-
BINS = step0_repl step1_read_print step2_eval step3_env step4_if_fn_do \
19-
step5_tco step6_file step7_quote step8_macros step9_try stepA_mal
20-
2120
# TODO: In theory cl-launch should be able to build standalone executable using
2221
# MKCL unfortunately the executable crashes on startup
2322
STANDALONE_EXE = sbcl clisp ccl ecl cmucl
@@ -31,15 +30,15 @@ $(foreach step, $(call steps), $(call record_lisp,$(patsubst step%,%,$(step)),$(
3130

3231
.PRECIOUS: hist/%_impl
3332

34-
all : $(BINS)
33+
all : $(step0A)
3534

3635
hist/%_impl: ;
3736

3837
# CL_LAUNCH_VERSION is only defined while building it. We change to the
3938
# directory of the CL_LAUNCH_FILE in --wrap script so that the script can find the dumped
4039
# image even if invoked from some directory different from where it
4140
# 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
41+
$(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
4342

4443
ifeq ($(LISP),clisp)
4544
@echo "=============================================================="

impls/cpp/Makefile

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
include ../../steps.mk
2+
13
uname_S := $(shell sh -c 'uname -s 2>/dev/null || echo not')
24

35
CXX=g++
@@ -19,14 +21,11 @@ LIBSOURCES=Core.cpp Environment.cpp Reader.cpp ReadLine.cpp String.cpp \
1921
Types.cpp Validation.cpp
2022
LIBOBJS=$(LIBSOURCES:%.cpp=%.o)
2123

22-
MAINS=$(wildcard step*.cpp)
23-
TARGETS=$(MAINS:%.cpp=%)
24-
2524
.PHONY: all clean
2625

2726
.SUFFIXES: .cpp .o
2827

29-
all: $(TARGETS)
28+
all: $(step0A)
3029

3130
dist: mal
3231

@@ -36,7 +35,7 @@ mal: stepA_mal
3635
.deps: *.cpp *.h
3736
$(CXX) $(CXXFLAGS) -MM *.cpp > .deps
3837

39-
$(TARGETS): %: %.o libmal.a
38+
$(step0A): %: %.o libmal.a
4039
$(LD) $^ -o $@ $(LDFLAGS)
4140

4241
libmal.a: $(LIBOBJS)
@@ -46,6 +45,6 @@ libmal.a: $(LIBOBJS)
4645
$(CXX) $(CXXFLAGS) -c $< -o $@
4746

4847
clean:
49-
rm -rf *.o $(TARGETS) libmal.a .deps mal
48+
rm -rf *.o $(step0A) libmal.a .deps mal
5049

5150
-include .deps

impls/crystal/Makefile

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
STEPS = step0_repl step1_read_print step2_eval step3_env \
2-
step4_if_fn_do step5_tco step6_file step7_quote step8_macros \
3-
step9_try stepA_mal
4-
all: $(STEPS)
5-
$(STEPS):
1+
include ../../steps.mk
2+
3+
all: $(step0A)
4+
$(step0A):
65
shards build $@ --release
76
clean:
87
rm -rf .cache/crystal/ .cache/shards/ bin/ lib/
9-
.PHONY: all clean $(STEPS)
8+
.PHONY: all clean $(step0A)

0 commit comments

Comments
 (0)