-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
239 lines (185 loc) · 5.58 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
MAKEFLAGS += --no-builtin-rules --no-builtin-variables --warn-undefined-variables
BUILD ?= build
-include $(BUILD)/config.mk
VERBOSE ?= 0
TRACE ?= # 0 1 2 i unit[1|2] repl[1|2|i] topl[1|2]
SRC ?= $(CURDIR)
ONLY ?= 0123i
DESTDIR ?=
NAME ?= extol
PREFIX ?= $(BUILD)/local
BINDIR ?= $(PREFIX)/bin
DATADIR ?= $(PREFIX)/share
DOCDIR ?= $(PREFIX)/share/doc/$(NAME)
PLC ?= gplc
PLC_FLAGS ?= --global-size 128000 --local-size 32000 -C -O2 --fixed-sizes --no-top-level --strip
CONFIG_VARIABLES = VERBOSE ONLY DESTDIR NAME PREFIX BINDIR DATADIR DOCDIR PLC PLC_FLAGS
ifneq ($(VERBOSE),1)
MAKEFLAGS += --silent
endif
/ := $(SRC)/
! := $(BUILD)/
./ :=
ifeq ($/,$(CURDIR)/)
/ :=
endif
ifeq ($!,./)
! :=
./ = ./
endif
toolkit_sources = $(shell find $/src/toolkit -iname '*.xtl')
extol_sources = $(toolkit_sources) $/src/main.xtl $(shell find $/src/extol -iname '*.xtl')
prelude_sources = $(shell find $/src/prelude -iname '*.xtl')
# TODO runtime_sources = $(shell find $/src/runtime -iname '*.pl')
.PHONY: default
default: 2
@true
.PHONY: everything
everything: check extras
.PHONY: extras
extras: docker
.PHONY: check1 check2 check
check0: # TODO: eunit0
check1: unit1 test1 # TODO: eunit1
check2: unit2 test2 # TODO: eunit2
eunit: eunit0 eunit1 # TODO: eunit2
unit: unit1 unit2
check: check0 check1 check2 diff23 testi
@echo [--] ALL TESTS PASSED
test-%: test1-% test2-%
@true
eunit-%: eunit0-% eunit1-% eunit2-%
@true
check0-%: eunit0-%
@true
check1-%: unit1-% test1-% eunit1-%
@true
check2-%: unit2-% test2-% eunit2-%
@true
.PHONY: testi
testi: install-if-needed
echo [I ] INTEGRATION TESTS
STAGE=I EXTOL=$(BINDIR)/$(NAME) $(SHELL) $/test/run
testi-%: install-if-needed
echo [I ] INTEGRATION TESTS $*
STAGE=I EXTOL=$(BINDIR)/$(NAME) $(SHELL) $/test/run "$*"
trace = $(foreach x,$(1) all,$(if $(findstring $(x) , $(TRACE) ),EXTOL_TRACE=1))
define make_stage
ifneq (,$$(findstring $(1),$$(ONLY)))
STAGE$(1)_PL := $!stage$(1).pl
STAGE$(1) := $!stage$(1)
else
STAGE$(1)_PL :=
STAGE$(1) :=
endif
.PHONY: test$(1)
test$(1): $$(STAGE$(1))
echo [$(1) ] INTEGRATION TESTS
$$(call trace,test1 test 1) STAGE=$(1) EXTOL=$$!stage$(1) $$(SHELL) $/test/run
test$(1)-%: $$(STAGE$(1))
echo [$(1) ] INTEGRATION TESTS $$*
$$(call trace,$$@ test $(1)) STAGE=$(1) EXTOL=$$!stage$(1) $$(SHELL) $/test/run "$$*"
.PHONY: diff$(1)$(2)
diff$(1)$(2): $!stage$(2).pl $$(STAGE$(1)_PL)
@echo [$(2) ] DIFF
diff --unified=2 --brief $$^ || echo [$(2)] DIFF FAILED
.PHONY: unit$(2)
unit$(2): $!stage$(2)
@echo [$(2) ] UNIT $$<
$$(call trace,$$@ unit $(2)) $(./)$$< test
unit$(2)-%: $!stage$(2)
@echo [$(2) ] UNIT $$< $$*
$$(call trace,unit$(2) unit $(2)) $(./)$$< test $$*
.PHONY: unit$(2)
eunit$(1): $!stage$(1)
@echo [$(1)E] EVAL UNIT $$<
$$(call trace,$$@ enuit $(1)) $(./)$$< eval-tests $/src/main.xtl
eunit$(1)-%: $!stage$(1)
@echo [$(1)E] UNIT $$< $$*
$$(call trace,eunit$(1) eunit $(1)) $(./)$$< eval-tests $/src/main.xtl $$*
$!stage$(2).pl: $$(STAGE$(1)) $$!embedded-prelude.pl
@echo [$(2) ] TOPL $$@
@rm -f $$@
$$(call trace,topl$(1) topl $(1)) $(./)$!stage$(1) extoltoprolog $/src/main.xtl $$@ --inject-prolog $$!embedded-prelude.pl $$(stage$(2)_extra_flags)
$!stage$(1): $!stage$(1).pl
@echo [$(1) ] PLC $$@
$(PLC) $(PLC_FLAGS) $$< -o $$@
.PHONY: $(1)
$(1): $!stage$(1)
.PHONY: repl$(1)
repl$(1): $(1)
@echo [$(1) ] REPL
$$(call trace,$$@ repl $(1)) $(./)$!stage$(1) repl
endef
$!stage1.pl: $(prelude_sources)
stage1_extra_flags = --no-prelude --inject $/src/prelude/prelude.xtl
stage2_extra_flags =
stage3_extra_flags =
$(eval $(call make_stage,0,1))
$(eval $(call make_stage,1,2))
$(eval $(call make_stage,2,3))
%/.:
@echo [--] MKDIR $@
mkdir -p $@
configure: $!Makefile
@echo [--] CONFIG $!config.mk
@echo $$'$(foreach var,$(CONFIG_VARIABLES),\n$(var) := $($(var))\n)' > $!config.mk
$!Makefile: | $!.
@echo [--] CREATE $@
echo $$'BUILD=.\nSRC=$(realpath $(SRC))\ninclude $$(SRC)/Makefile' > $@
$!stage0.pl: $/bootstrap/stage0.pl | $!.
@echo [0 ] COPY $@
cp $< $@
.PHONY: reboot
reboot: 2
@echo [--] BOOT $/bootstrap/stage0.pl
$(call trace,reboot topl 2) $(./)$!stage2 extoltoprolog $/src/main.xtl $!stage0.pl --slim --inject-prolog $!embedded-prelude.pl
cp $!stage0.pl $/bootstrap/stage0.pl
@echo [--] REBOOT COMPLETE
.PHONY: clean
clean:
@echo [--] CLEAN
rm -f $!stage0.pl $!stage1.pl $!stage2.pl $!stage3.pl $!stage0 $!stage1 $!stage2 $!stage3
.PHONY: repl
repl: repl2
.PHONY: repli
repli: install-if-needed
@echo [I ] REPL
$(call trace,repli repl i) $(BINDIR)/$(NAME) repl
unit-%: unit1-% unit2-%
@echo [--] UNIT TEST "'$*'" PASSED
.PHONY: todo
todo:
cd $/. && git grep -En 'TOD[O]|- \[ \]'
.PHONY: install
install: $!stage2
@echo [I ] INSTALL $(DESTDIR)$(PREFIX)
set -o pipefail; ( \
install -Cvm 755 $!stage2 -DT $(DESTDIR)$(BINDIR)/$(NAME) ; \
install -Cvm 644 $/README.md $/LICENSE.md $/NOTICE -Dt $(DESTDIR)$(DOCDIR) ; \
install -Cvm 644 $/integrations/emacs/extol.el -DT $(DESTDIR)$(DATADIR)/emacs/site-lisp/$(NAME).el ; \
) | sed 's/^/[I ] + /'
.PHONY: install-if-needed
ifneq (,$(findstring i,$(ONLY)))
install-if-needed: install
@true
else
install-if-needed:
@true
endif
.PHONY: docker
docker:
docker build $/. -t extol
.PHONY: docker-repl
docker-repl: docker
docker run --rm --interactive --tty extol
$!generate-embedded-prelude.pl: $/src/generate-embedded-prelude.xtl $(prelude_sources) $!stage0
@echo '[0 ]' TOPL $@
$(call trace,topl 0 topl0) $!stage0 extoltoprolog --slim $< $@
$!generate-embedded-prelude: $!generate-embedded-prelude.pl
@echo '[0 ]' PLC $@
$(PLC) $(PLC_FLAGS) $< -o $@
$!embedded-prelude.pl: $!generate-embedded-prelude
@echo '[0 ]' GEN $@
unset EXTOL_TRACE; ./$< > $@.out
mv $@.out $@