-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathMakefile.polyml
262 lines (203 loc) · 8.21 KB
/
Makefile.polyml
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
## Copyright (C) 2020 Takayuki Goto
POLYML := poly
POLYMLC := polyc
POLYMLFLAGS := -q --error-exit \
--eval 'PolyML.suffixes := ".sig"::".ppg.sml"::(!PolyML.suffixes)' \
--use ./script/load.sml
MLLEX := mllex-polyml
MLYACC := mlyacc-polyml
SMLDOC := smldoc
SMLDOC_ARGFILE := formatlib/smldoc.cfg
# install directories
PREFIX := /usr/local/polyml
BINDIR := $(PREFIX)/bin
LIBDIR := $(PREFIX)/lib
DOCDIR := $(PREFIX)/doc
SMLFORMAT := bin/smlformat
SMLFORMAT_VER := 1.0.0
SMLFORMAT_LIB := lib/smlformat-lib/smlformat-lib-$(SMLFORMAT_VER).poly
# dependencies
MLYACC_LIB := $(LIBDIR)/mlyacc-lib/mlyacc-lib-1.0.0.poly
SMLNJ_UTIL_LIB := $(LIBDIR)/smlnj-lib-110.82/smlnj-util-lib-0.0.1.poly
SMLUNIT_LIB := $(LIBDIR)/smlunit-lib/smlunit-lib.poly
SMLFORMAT_LIB_SRC := \
formatlib/main/export.sml \
formatlib/main/ml_bind.sml \
formatlib/main/AssocResolver.sml \
formatlib/main/BASIC_FORMATTERS.sig \
formatlib/main/BasicFormatters.sml \
formatlib/main/FORMAT_EXPRESSION.sig \
formatlib/main/FormatExpression.sml \
formatlib/main/FormatExpressionTypes.sml \
formatlib/main/PreProcessedExpression.sml \
formatlib/main/PreProcessor.sml \
formatlib/main/PrettyPrinter.sml \
formatlib/main/PRINTER_PARAMETER.sig \
formatlib/main/PrinterParameter.sml \
formatlib/main/SMLFORMAT.sig \
formatlib/main/SMLFormat.sml \
formatlib/main/Truncator.sml
SMLFORMAT_SRC := generator/main/Utility.sml \
generator/main/ErrorQueue.sml \
generator/main/FormatTemplate.sml \
generator/main/AST.sig \
generator/main/Ast.sml \
generator/main/ASTUTIL.sig \
generator/main/AstUtil.sml \
generator/main/Constants_MLton.sml \
generator/main/ml.grm.sig \
generator/main/ml.grm.sml \
generator/main/TokenTable.sml \
generator/main/ml.lex.sml \
generator/main/MLPARSER.sig \
generator/main/MLParser.sml \
generator/main/FORMATTER_GENERATOR.sig \
generator/main/FormatterGenerator.sml \
generator/main/BasicFormattersEnv.sml \
generator/main/PPGMain.sml \
generator/main/Main.sml \
generator/main/Main_PolyML.sml
MLPARSER_SRC := example/MLParser/Absyn.ppg.sml \
example/MLParser/call-main.sml \
example/MLParser/Main.sml \
example/MLParser/ml.grm.sig \
example/MLParser/ml.grm.sml \
example/MLParser/ml.lex.sml
FORMAT_EXPR_PARSER_SRC := \
example/FormatExpressionParser/Ast.sml \
example/FormatExpressionParser/Lexer.lex.sml \
example/FormatExpressionParser/Parser.grm.sig \
example/FormatExpressionParser/Parser.grm.sml \
example/FormatExpressionParser/Main.sml
OVERVIEW_SRC := example/Overview/Examples.ppg.sml \
example/Overview/Types.ppg.sml \
example/Overview/ml_bind.sml
TEST_SRC := \
formatlib/test/BasicFormattersTest0001.sml \
formatlib/test/call-main.sml \
formatlib/test/load.sml \
formatlib/test/PPLibTest.sml \
formatlib/test/PrinterParameterTest0001.sml \
formatlib/test/PrinterParameterTest0002.sml \
formatlib/test/SMLFormatTest0001.sml \
formatlib/test/SMLFormatTest0002.sml \
formatlib/test/SMLFormatTest0003.sml \
formatlib/test/SMLFormatTest0004.sml \
formatlib/test/SMLFormatTest0005.sml \
formatlib/test/SMLFormatTest0006.sml \
formatlib/test/SMLFormatTest0007.sml \
formatlib/test/SMLFormatTest0008.sml \
formatlib/test/SMLFormatTest0009.sml \
formatlib/test/SMLFormatTest0010.sml \
formatlib/test/SMLFormatTest0011.sml \
formatlib/test/SMLFormatTestUtil.sml \
formatlib/test/TestMain.sml
EXAMPLES := bin/mlparser \
bin/fmt_expr_parser \
bin/overview.poly
TEST := bin/formatlib-test
define build-module
@echo " [POLYML] $@"
@echo "" | $(POLYML) $(POLYMLFLAGS) \
$(foreach dep,$(3),--eval 'PolyML.loadModule "$(dep)"') \
--eval 'load "$(1)/load.sml"' \
--eval 'PolyML.export ("$@", $2)'
endef
all: smlformat
.PHONY: smlformat
smlformat: smlformat-nodoc doc
.PHONY: smlformat-nodoc
smlformat-nodoc: smlformat-bin smlformat-lib
.PHONY: smlformat-bin
smlformat-bin: $(SMLFORMAT)
.PHONY: smlformat-lib
smlformat-lib: $(SMLFORMAT_LIB)
$(SMLFORMAT) $(TEST) $(filter-out bin/overview.poly,$(EXAMPLES)): bin/%: obj/%.o
@echo " [POLYMLC] $@"
@$(POLYMLC) -o $@ $^
$(SMLFORMAT_LIB): $(SMLNJ_UTIL_LIB) $(SMLFORMAT_LIB_SRC)
@echo " [POLYML] $@"
@echo "" | $(POLYML) $(POLYMLFLAGS) \
--eval 'PolyML.loadModule "$<"' \
--eval 'PolyML.make "formatlib/main"' \
--use formatlib/main/export.sml \
--eval 'PolyML.SaveState.saveModule ("$@", SMLFormat)'
obj/smlformat.o: $(MLYACC_LIB) $(SMLFORMAT_SRC)
$(call build-module,generator/main,Main.main,$<)
obj/formatlib-test.o: $(SMLFORMAT_LIB) $(SMLUNIT_LIB) $(TEST_SRC)
$(call build-module,formatlib/test,TestMain.test,$(SMLUNIT_LIB) $(SMLFORMAT_LIB))
.PHONY: install-nodoc
install-nodoc: $(SMLFORMAT) $(SMLFORMAT_LIB)
install -D -m 755 -t $(BINDIR) $(SMLFORMAT)
install -D -m 644 -t $(LIBDIR)/smlformat-lib $(SMLFORMAT_LIB)
.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 "================================================================"
.PHONY: test
test: $(TEST)
./$<
%.lex.sml: %.lex
@echo " [MLLEX] $<"
@$(MLLEX) $<
%.grm.sml %.grm.sig %.grm.desc: %.grm
@echo " [MLYACC] $<"
@$(MLYACC) $<
%.ppg.sml: %.ppg $(SMLFORMAT)
@echo " [SMLFORMAT] $<"
@$(SMLFORMAT) $<
define build-example
@echo " [POLYML] $@"
@echo "" | $(POLYML) $(POLYMLFLAGS) \
$(foreach dep,$(2),--eval 'PolyML.loadModule "$(dep)"') \
--eval 'PolyML.loadModule "$(SMLFORMAT_LIB)"' \
--eval 'load "example/$(1)/load.sml"' \
--eval 'PolyML.export ("$@", Main.main'"'"')'
endef
obj/mlparser.o: $(MLYACC_LIB) $(SMLFORMAT_LIB) $(MLPARSER_SRC)
$(call build-example,MLParser,$<)
obj/fmt_expr_parser.o: $(MLYACC_LIB) $(SMLFORMAT_LIB) $(FORMAT_EXPR_PARSER_SRC)
$(call build-example,FormatExpressionParser,$<)
bin/overview.poly: $(SMLFORMAT_LIB) $(OVERVIEW_SRC)
@echo " [POLYML] $@"
@echo "" | $(POLYML) $(POLYMLFLAGS) \
--eval 'PolyML.loadModule "$<"' \
--eval 'PolyML.make "example/Overview"' \
--use example/Overview/export.sml \
--eval 'PolyML.SaveState.saveModule ("$@", OverviewExample)'
.PHONY: example
example: $(EXAMPLES)
.PHONY: clean
clean:
-$(RM) $(SMLFORMAT)
-$(RM) $(SMLFORMAT_LIB)
-$(RM) $(TEST)
-$(RM) $(EXAMPLES)
-$(RM) -r doc/api
-$(RM) obj/*.o
-$(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/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