-
Notifications
You must be signed in to change notification settings - Fork 3
/
Makefile.smlnj
266 lines (195 loc) · 7.67 KB
/
Makefile.smlnj
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
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
SML := sml
# -32 or -64
# empty is default
SML_BITMODE :=
SML_FLAGS :=
HEAP_SUFFIX := $(shell $(SML) $(SML_BITMODE) @SMLsuffix)
# directory of CM product
CM_SUFFIX := $(shell $(SML) $(SML_BITMODE) < script/suffix.sml 2>&1 >/dev/null)
MLBUILD := ml-build
MLBUILD_FLAGS :=
MLDEPENDS := ml-makedepend
MLDEPENDS_FLAGS := -n
# for profiling, set '-DMEASURE'
SML_DULIST :=
SMLDOC := smldoc
SMLDOC_ARGFILE := formatlib/smldoc.cfg
PREFIX := /usr/local/sml
BINDIR := $(PREFIX)/bin
LIBDIR := $(PREFIX)/lib
DOCDIR := $(PREFIX)/doc
HEAPDIR := $(BINDIR)/.heap
SMLFORMAT := bin/smlformat
SMLFORMAT_IMAGE := bin/.heap/smlformat.$(HEAP_SUFFIX)
SMLFORMAT_LIB := .cm/$(CM_SUFFIX)/smlformat-lib.cm
SMLFORMAT_LIB_COMPAT := \
.cm/$(CM_SUFFIX)/smlformatlib.cm
PPG_EXT := cmtool/.cm/$(CM_SUFFIX)/ppg-ext.cm
SMLFORMAT_TOOL := cmtool/.cm/$(CM_SUFFIX)/smlformat-tool.cm
DEPENDS := generator/main/sources.cm.d \
formatlib/test/sources.cm.d \
smlformat-lib.cm.d \
smlformatlib.cm.d
TEST_TARGET := bin/formattest.$(HEAP_SUFFIX)
EXAMPLE_TARGET := bin/CMIntegration.$(HEAP_SUFFIX) \
bin/FormatExpressionParser.$(HEAP_SUFFIX) \
bin/MLParser.$(HEAP_SUFFIX)
OVERVIEW_SRC := example/Overview/Examples.ppg \
example/Overview/Types.ppg \
example/Overview/sources.cm
# A wrapper of ml-makedepend
# $(1) - the 1st target of the generated rule.
# $@ - name of the target to generate the rule.
define mldepends
@echo " [GEN] $@"
@truncate --size 0 $@
$(MLDEPENDS) $(MLDEPENDS_FLAGS) $(SML_BITMODE) $(SML_DULIST) -f $@ $< $(1)
sed -i -e "s|^\([^#][^:]\+\):|\1 $@:|" $@
endef
all: smlformat
.PHONY: smlformat
smlformat: smlformat-nodoc doc
.PHONY: smlformat-nodoc
smlformat-nodoc: smlformat-bin smlformat-lib ppg-ext smlformat-tool
.PHONY: smlformat-bin
smlformat-bin: $(SMLFORMAT)
.PHONY: smlformat-lib
smlformat-lib: $(SMLFORMAT_LIB) $(SMLFORMAT_LIB_COMPAT)
.PHONY: ppg-ext
ppg-ext: $(PPG_EXT)
.PHONY: smlformat-tool
smlformat-tool: $(SMLFORMAT_TOOL)
$(SMLFORMAT): $(SMLFORMAT_IMAGE)
sed \
-e "s|@SML@|$(SML)|" \
-e "s|@SML_FLAGS@|$(SML_BITMODE) $(SML_FLAGS)|" \
-e "s|@HEAP_IMAGE@|$<|" \
script/smlformat.in > $@
chmod +x $@
$(SMLFORMAT_IMAGE): generator/main/sources.cm
@echo " [SMLNJ] $@"
@install -d $(dir $@)
@$(MLBUILD) $(SML_BITMODE) $(SML_DULIST) $(MLBUILD_FLAGS) $< Main.main $@
$(SMLFORMAT_LIB) $(SMLFORMAT_LIB_COMPAT): .cm/$(CM_SUFFIX)/%.cm: %.cm
@echo " [SMLNJ] $@"
# force rebuilding even for 'stabilize true'
@$(RM) $@
@echo 'CM.stabilize true "$<";' | $(SML) $(SML_BITMODE) $(SML_DULIST)
$(PPG_EXT) $(SMLFORMAT_TOOL): cmtool/.cm/$(CM_SUFFIX)/%.cm: cmtool/%.cm
@echo " [SMLNJ] $@"
# force rebuilding even for 'stabilize true'
#@$(RM) $@
@echo 'CM.stabilize true "$<";' | $(SML) $(SML_BITMODE) $(SML_DULIST)
smlformat-lib.cm.d smlformatlib.cm.d: %.cm.d: %.cm
$(RM) .cm/$(CM_SUFFIX)/$<
$(call mldepends,.cm/$(CM_SUFFIX)/$<)
generator/main/sources.cm.d: %.cm.d: %.cm
$(call mldepends,$(SMLFORMAT_IMAGE))
formatlib/test/sources.cm.d: %.cm.d: %.cm
$(call mldepends,$(dir $<).cm/$(CM_SUFFIX))
ifeq (,$(findstring clean,$(MAKECMDGOALS)))
include $(DEPENDS)
endif
.PHONY: install-nodoc
install-nodoc: $(SMLFORMAT) $(SMLFORMAT_LIB) $(SMLFORMAT_LIB_COMPAT) $(PPG_EXT) $(SMLFORMAT_TOOL)
@install -D -m 755 -t $(BINDIR) $(SMLFORMAT)
@install -D -m 644 -t $(BINDIR)/.heap $(SMLFORMAT_IMAGE)
@install -D -m 644 -t $(LIBDIR)/smlformat-lib.cm/.cm/$(CM_SUFFIX) $(SMLFORMAT_LIB)
@install -D -m 644 -t $(LIBDIR)/smlformatlib.cm/.cm/$(CM_SUFFIX) $(SMLFORMAT_LIB_COMPAT)
@install -D -m 644 -t $(LIBDIR)/ppg-ext.cm/.cm/$(CM_SUFFIX) $(PPG_EXT)
@install -D -m 644 -t $(LIBDIR)/smlformat-tool.cm/.cm/$(CM_SUFFIX) $(SMLFORMAT_TOOL)
@echo "================================================================"
@echo "Add enties to your pathconfig (e.g. ~/.smlnj-pathconfig):"
@echo "\tsmlformat $(BINDIR)"
@echo "\tsmlformat-lib.cm $(LIBDIR)/smlformat-lib.cm"
@echo "\tsmlformatlib.cm $(LIBDIR)/smlformatlib.cm"
@echo "\tppg-ext.cm $(LIBDIR)/ppg-ext.cm"
@echo "\tsmlformat-tool.cm $(LIBDIR)/smlformat-tool.cm"
@echo "================================================================"
.PHONY: install
install: install-doc install-nodoc
.PHONY: doc
doc:
@echo " [SMLDoc]"
@$(RM) -r doc/api
@install -d doc/api
@$(SMLDOC) -c UTF-8 -a $(SMLDOC_ARGFILE) -d doc/api
.PHONY: install-doc
install-doc: doc
@install -d $(DOCDIR)
@cp -prT doc $(DOCDIR)/smlformat-lib
@echo "================================================================"
@echo "Generated API Documents of SMLFormat"
@echo "\t$(DOCDIR)/smlformat-lib"
@echo "================================================================"
$(TEST_TARGET): formatlib/test/.cm/$(CM_SUFFIX)
@install -d $(dir $@)
@$(MLBUILD) $(SML_BITMODE) $(SML_DULIST) $(MLBUILD_FLAGS) formatlib/test/sources.cm TestMain.test\' $@
.PHONY: test
test: $(TEST_TARGET)
$(SML) $(SML_BITMODE) $(SML_DULIST) $(SML_FLAGS) @SMLload=$<
$(EXAMPLE_TARGET): $(SMLFORMAT) $(PPG_EXT) $(SMLFORMAT_TOOL)
$(EXAMPLE_TARGET): bin/%.$(HEAP_SUFFIX): example/%/sources.cm cmtool/local_pathconfig
@echo " [SMLNJ] $(@.$(HEAP_SUFFIX):=)"
@install -d $(dir $@)
@CM_LOCAL_PATHCONFIG=cmtool/local_pathconfig \
$(MLBUILD) $(SML_BITMODE) $(SML_DULIST) $(MLBUILD_FLAGS) $< Main.main $@
# .ppg
OVERVIEW_PPG := $(foreach ppg,$(filter %.ppg,$(OVERVIEW_SRC)),$(ppg).sml)
OVERVIEW_TARGET := $(foreach file,\
$(filter %.sml,$(OVERVIEW_PPG) $(OVERVIEW_SRC)),\
$(dir $(file)).cm/SKEL/$(notdir $(file)))
$(OVERVIEW_TARGET): example/Overview/sources.cm cmtool/local_pathconfig
@echo " [SMLNJ] example/Overview"
@echo 'CM.stabilize false "$<";' | CM_LOCAL_PATHCONFIG=cmtool/local_pathconfig $(SML) $(SML_BITMODE) $(SML_DULIST)
example/Overview/sources.cm.d: %.cm.d: %.cm cmtool/local_pathconfig
@echo " [GEN] $@"
@truncate --size 0 $@
# depends on local path
@CM_LOCAL_PATHCONFIG=cmtool/local_pathconfig \
$(MLDEPENDS) $(MLDEPENDS_FLAGS) $(SML_BITMODE) $(SML_DULIST) -f $@ $< '$(OVERVIEW_TARGET)'
@sed -i -e "s|^\([^#][^:]\+\):|\1 $@:|" $@
ifneq (,$(findstring example,$(MAKECMDGOALS)))
include example/Overview/sources.cm.d
endif
.PHONY: example_overview
example_overview: $(OVERVIEW_TARGET)
.PHONY: example
example: $(EXAMPLE_TARGET) example_overview
.PHONY: clean
clean:
-$(RM) -r .cm/
-$(RM) -r cmtool/.cm/
-$(RM) -r formatlib/main/.cm/
-$(RM) -r formatlib/test/.cm/
-$(RM) -r generator/main/.cm/
-$(RM) -r bin/.heap
-$(RM) $(SMLFORMAT)
-$(RM) $(SMLFORMAT_IMAGE)
-$(RM) $(SMLFORMAT_LIB)
-$(RM) $(SMLFORMAT_LIB_COMPAT)
-$(RM) $(DEPENDS)
-$(RM) $(TEST_TARGET)
-$(RM) $(EXAMPLE_TARGET)
-$(RM) -r example/CMIntegration/.cm
-$(RM) -r example/FormatExpressionParser/.cm
-$(RM) -r example/MLParser/.cm
-$(RM) -r example/Overview/.cm
-$(RM) -r doc/api
-$(RM) generator/main/ml.lex.sml
-$(RM) generator/main/ml.grm.sig
-$(RM) generator/main/ml.grm.sml
-$(RM) generator/main/ml.grm.desc
-$(RM) example/CMIntegration/Tree.ppg.sml
-$(RM) example/MLParser/Absyn.ppg.sml
-$(RM) example/MLParser/ml.grm.sig
-$(RM) example/MLParser/ml.grm.sml
-$(RM) example/MLParser/ml.grm.desc
-$(RM) example/MLParser/ml.lex.sml
-$(RM) example/FormatExpressionParser/Parser.grm.sig
-$(RM) example/FormatExpressionParser/Parser.grm.sml
-$(RM) example/FormatExpressionParser/Parser.grm.desc
-$(RM) example/FormatExpressionParser/Lexer.lex.sml
-$(RM) example/Overview/Types.ppg.sml
-$(RM) example/Overview/Examples.ppg.sml
-$(RM) example/Overview/sources.cm.d