-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMakefile.smlnj
145 lines (103 loc) · 3.28 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
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 :=
PREFIX := /usr/local/sml
BINDIR := bin
LIBDIR := lib/smldoc.cm
DOCDIR := doc/smldoc
HEAPDIR := $(BINDIR)/.heap
SMLDOC_ARGFILE := src/smldoc.cfg
BASIS_DOCDIR := doc/SMLBasis
DEPENDS := src/main/sources.d src/test/sources.d
TEST_TARGET := $(BINDIR)/SMLDocTest.$(HEAP_SUFFIX)
SMLDOC := $(BINDIR)/smldoc
SMLDOC_IMAGE := $(HEAPDIR)/smldoc.$(HEAP_SUFFIX)
define mldepends
@echo " [GEN] $@"
@touch $@
@$(MLDEPENDS) $(MLDEPENDS_FLAGS) $(SML_BITMODE) $(SML_DULIST) -f $@ $< $(1)
@sed -i -e "s|^\([^#][^:]\+\):|\1 $@:|" $@
endef
all: smldoc
.PHONY: smldoc
smldoc: $(SMLDOC)
$(SMLDOC): $(SMLDOC_IMAGE)
sed \
-e "s|@SML@|$(SML)|" \
-e "s|@SML_FLAGS@|$(SML_BITMODE) $(SML_FLAGS)|" \
-e "s|@HEAP_IMAGE@|$<|" \
script/smldoc.in > $@
chmod +x $@
$(SMLDOC_IMAGE): src/main/sources.cm
@echo " [SMLNJ] $@"
@install -d $(dir $(SMLDOC_IMAGE))
@$(MLBUILD) $(SML_BITMODE) $(SML_DULIST) $(MLBUILD_FLAGS) $< Main.main $@
# .cm/$(CM_SUFFIX)/%.cm: %.cm
# @echo " [SMLNJ] $@"
# @echo 'CM.stabilize true "smldoc.cm";' | $(SML) $(SML_BITMODE) $(SML_DULIST)
src/main/sources.d: %.d: %.cm
$(call mldepends,$(SMLDOC_IMAGE))
src/test/sources.d: %.d: %.cm
$(call mldepends,$(dir $<).cm/$(CM_SUFFIX))
ifeq (,$(findstring clean,$(MAKECMDGOALS)))
include $(DEPENDS)
endif
.PHONY: install
install: $(SMLDOC)
install -D -m 0755 -t $(PREFIX)/$(BINDIR) $(SMLDOC)
install -D -m 0755 -t $(PREFIX)/$(HEAPDIR) $(SMLDOC_IMAGE)
# Generate the 'SMLDoc' documentation
.PHONY: smldoc-doc
smldoc-doc: $(SMLDOC) basis-doc
@echo " [SMLDoc] $(DOCDIR)"
@$(RM) -r $(DOCDIR)
@install -d $(DOCDIR)
@$(SMLDOC) -c UTF-8 -a $(SMLDOC_ARGFILE) -d "$(DOCDIR)"
# Generate the 'Basis' documentation
.PHONY: basis-doc
basis-doc: $(SMLDOC)
@echo " [SMLDoc] $(BASIS_DOCDIR)"
@$(RM) -r $(BASIS_DOCDIR)
@install -d $(BASIS_DOCDIR)
@install -d example/SMLBasis/doc/api
@cd example/SMLBasis/src && ../../../$(SMLDOC) -c UTF-8 -d "$$(realpath --relative-to=. ../../../$(BASIS_DOCDIR))" -a SMLDocOptions.txt
.PHONY: example
example: basis-doc
$(TEST_TARGET): src/test/.cm/$(CM_SUFFIX)
@install -d $(dir $@)
$(MLBUILD) $(SML_BITMODE) $(SML_DULIST) $(MLBUILD_FLAGS) $(patsubst %/.cm/$(CM_SUFFIX),%/sources.cm,$<) TestMain.main $@
.PHONY: test
test: $(TEST_TARGET)
$(SML) $(SML_BITMODE) $(SML_DULIST) $(SML_FLAGS) @SMLload=$<
.PHONY: clean
clean:
-$(RM) $(DEPENDS)
-$(RM) $(SMLDOC)
-$(RM) -r $(HEAPDIR)
-$(RM) -r $(DOCDIR)
-$(RM) -r $(BASIS_DOCDIR)
-$(RM) $(TEST_TARGET)
-$(RM) -r .cm
-$(RM) -r src/main/.cm
-$(RM) -r src/test/.cm
-$(RM) -r src/main/smlnjcm/.cm
-$(RM) -r src/main/HTML/.cm
-$(RM) src/main/ML.grm.*
-$(RM) src/main/ML.lex.sml
-$(RM) src/main/ParamPattern.grm.*
-$(RM) src/main/ParamPattern.lex.sml
-$(RM) src/main/LinkFile.grm.*
-$(RM) src/main/LinkFile.lex.sml
-$(RM) src/main/smlnjcm/CM.grm.*
-$(RM) src/main/smlnjcm/CM.lex.sml