This repository has been archived by the owner on Mar 10, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMakefile.rules
215 lines (178 loc) · 6.09 KB
/
Makefile.rules
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
vpath %.mll $(SOURCEDIRS)
vpath %.mly $(SOURCEDIRS)
vpath %.ml $(SOURCEDIRS) $(OBJDIR)
vpath %.mli $(SOURCEDIRS) $(OBJDIR)
vpath %.c $(SOURCEDIRS)
all:: $(TODO)
test: exe
@$(NARRATIVE) Running regression tests.
@$(BINDIR)/regression-test.sh
dist:
@$(NARRATIVE) Making distributible archive $(TARBALL)
@ln -s -f -h . c2s
@tar zcvf $(TARBALL) -X .ignores -H c2s 2> /dev/null
@rm c2s
doc: $(CMOFILES)
@$(NARRATIVE) Making API documentation
@mkdir -p $(DOCDIR)
@ocamlfind ocamldoc -html -sort -d $(DOCDIR) \
-I $(OBJDIR) -I $(INCDIR) \
$(foreach ml,$(CAML_LIB_OBJ),$(shell find $(SRC) -name $(ml).ml))
install: exe
@$(NARRATIVE) Installing $(NAME)
$(ECHO)mkdir -p $(DEST_BIN)
$(ECHO)$(INSTALL_PROGRAM) $(BINDIR)/$(CAML_EXE) $(DEST_BIN)
$(ECHO)for s in $$(find $(BINDIR) -name '*.rb'); do \
$(INSTALL_SCRIPT) $$s $(DEST_BIN) ; \
done
uninstall:
@$(NARRATIVE) Uninstalling $(NAME)
$(ECHO)rm -f $(DEST_BIN)/$(CAML_EXE)
$(ECHO)for s in $$(find $(BINDIR) -name '*.rb'); do \
rm -f $(DEST_BIN)/$$(basename $$s) ; \
done
clean: default-clean
@rm -rf *.cmi *.annot $(TODO)
@rm -rf $(OBJDIR) $(DOCDIR) $(TESTLOGS)
@rm -f $(BINDIR)/$(CAML_TPL_EXE) $(BINDIR)/$(CAML_EXE) $(TARBALL)
exe :: $(BINDIR)/$(CAML_EXE)
top :: $(BINDIR)/$(CAML_TPL_EXE)
$(BINDIR)/$(CAML_TPL_EXE): $(CAML_LIB_OBJ:%=$(OBJDIR)/%.cmo)
@$(NARRATIVE) Making top-level $@ from $(CAML_LIB_OBJ:%=%.cmo) \
$(CAML_LD_LIBS:%=%.cma)
$(AT)ocamlfind ocamlmktop $(CAML_FLAGS) $(CAML_LD_FLAGS) \
-o $@ -linkpkg \
-I $(OBJDIR) -I $(TESTDIR) \
$(CAML_LD_LIBS:%=%.cma) $(CAML_LIB_OBJ:%=%.cmo)
lib:: $(LIBDIR)/$(CAML_LIB).cma $(LIBDIR)/$(CAML_LIB).cmxa
.PHONY : all clean distclean doc test dist
.SECONDARY : $(MLLS:%.mll=$(OBJDIR)/%.ml) $(MLYS:%.mly=$(OBJDIR)/%.ml) \
$(MLYS:%.mly=$(OBJDIR)/%.mli)
ifdef NATIVECAML
$(BINDIR)/$(CAML_EXE): $(CAML_EXE_OBJ:%=$(OBJDIR)/%.cmx)
@$(NARRATIVE) Linking $@ from $(CAML_EXE_OBJ:%=%.cmx) \
$(CAML_LD_LIBS:%=%.cmxa)
$(ECHO)mkdir -p $(@D)
$(CAML_FIND) ocamlc \
$(CAMLFLAGS) $(CAML_OPT_LD_FLAGS) -o $@ -linkpkg \
$(CAML_LD_LIBS:%=%.cmxa) $(CAML_EXE_OBJ:%=%.cmx)
else
$(BINDIR)/$(CAML_EXE): $(CAML_EXE_OBJ:%=$(OBJDIR)/%.cmo)
@$(NARRATIVE) Linking $@ from $(CAML_EXE_OBJ:%=%.cmo) \
$(CAML_LD_LIBS:%=%.cma)
$(ECHO)mkdir -p $(@D)
$(AT)$(CAML_FIND) ocamlc \
$(CAMLFLAGS) $(CAML_LD_FLAGS) -o $@ -linkpkg \
$(CAML_LD_LIBS:%=%.cma) $(CAML_EXE_OBJ:%=%.cmo)
endif
$(OBJDIR)/%.ml: %.mll
$(ECHO)mkdir -p $(@D)
$(CAML_LEX) $<
$(AT)mv -f $(basename $<).ml $(OBJDIR)
$(ECHO)if test -f $(basename $<).mli; then \
$(COMMAND) cp -f $(basename $<).mli $(OBJDIR); \
cp -f $(basename $<).mli $(OBJDIR); \
fi
$(OBJDIR)/%.ml $(OBJDIR)/%.mli: %.mly
$(ECHO)mkdir -p $(@D)
$(CAML_YACC) $<
$(AT)mv -f $(basename $<).ml $(basename $<).mli $(OBJDIR)
$(OBJDIR)/%.cmi: %.mli
@$(NARRATIVE) Compiling interface $<
$(ECHO)mkdir -p $(@D)
$(AT)$(CAML_C) $(CAML_C_FLAGS) $(CAML_INCLUDES:%=-I %) -c $<
$(ECHO)if test $(OBJDIR) != $(<D); then \
$(COMMAND) mv -f $(basename $<).cmi $(OBJDIR); \
mv -f $(basename $<).cmi $(OBJDIR); \
fi
$(OBJDIR)/%.cmo: %.ml
@$(NARRATIVE) Compiling $<
$(ECHO)mkdir -p $(@D)
$(AT)$(CAML_FIND) ocamlc -linkpkg \
$(CAML_C_FLAGS) $(CAML_INCLUDES:%=-I %) -c $<
$(ECHO)if test $(OBJDIR) != $(<D); then \
for ext in $(MOVE_AFTER_CAML_C); do \
if test -f $(basename $<).$$ext; then \
$(COMMAND) mv -f $(basename $<).$$ext $(OBJDIR); \
mv -f $(basename $<).$$ext $(OBJDIR); \
fi; \
done; \
fi
$(OBJDIR)/%.cmx: %.ml
@$(NARRATIVE) Compiling $< \(to native code\)
$(ECHO)mkdir -p $(@D)
$(AT)$(CAML_FIND) $(CAML_OPT_C) -linkpkg \
$(CAML_OPT_C_FLAGS) $(CAML_INCLUDES:%=-I %) -c $< -o $@
$(ECHO)if test $(OBJDIR) != $(<D); then \
for ext in $(MOVE_AFTER_CAML_C); do \
if test -f $(basename $<).$$ext; then \
$(COMMAND) mv -f $(basename $<).$$ext $(OBJDIR); \
mv -f $(basename $<).$$ext $(OBJDIR); \
fi; \
done; \
fi
$(BINDIR)/test_suite: $(CAML_TEST_OBJ:%=$(OBJDIR)/%.cmo) \
$(CAML_LIB_OBJ:%=$(OBJDIR)/%.cmo)
@$(NARRATIVE) Building $@
$(AT)$(CAML_FIND) ocamlc \
$(CAMLFLAGS) $(CAML_LD_FLAGS) -o $@ -linkpkg \
-I $(OBJDIR) -I $(TESTDIR) \
$(CAML_LD_LIBS:%=%.cma) \
$(CAML_LIB_OBJ:%=%.cmo) \
$(CAML_TEST_OBJ:%=%.cmo)
ifdef CAML_LIB
$(LIBDIR)/$(CAML_LIB).cma: $(CAML_LIB_OBJ:%=$(OBJDIR)/%.cmo)
@$(NARRATIVE) Creating OCaml \(byte code\) library $@
$(ECHO)mkdir -p $(@D)
$(CAML_LD) $(CAML_LD_FLAGS) -a -o $@ $(CAML_LIB_OBJ:%=$(<D)/%.cmo)
$(LIBDIR)/$(CAML_LIB).cmxa $(LIBDIR)/$(CAML_LIB).a: $(CAML_LIB_OBJ:%=$(OBJDIR)/%.cmx)
@$(NARRATIVE) Creating OCaml \(native code\) library $@
$(ECHO)mkdir -p $(@D)
$(CAML_OPT_LD) $(CAML_OPT_LD_FLAGS) -a -o $@ $(CAML_LIB_OBJ:%=$(<D)/%.cmx)
endif
.PHONY: default-clean
default-clean:
@$(NARRATIVE) Cleaning
$(ECHO)-find obj \( \
-name '*.cmi' -o \
-name '*.cmo' -o \
-name '*.cmx' -o \
-name '*.cma' -o \
-name '*.cmxa' -o \
-name '*.exe' -o \
-name '*.o' -o \
-name '*.a' -o \
-name '*.ml' -o \
-name '*.mli' -o \
-name '*.annot' -o \
-name '*.obj' \
\) -exec rm {} \;
$(ECHO)-find src \( \
-name '*.annot' \) -exec rm {} \;
$(ECHO)-find src \( \
-name '*.output' \) -exec rm {} \;
$(ECHO)-find $(DEPENDDIR) \( \
-name '*.ml*.depend' \) -exec rm {} \;
$(ECHO)rm -f $(addsuffix .output, $(basename $(shell find $(SRC) -name "*.mly")))
$(ECHO)rm -f $(addsuffix .ml, $(basename $(shell find $(SRC) -name "*.mll")))
FIXDEPEND:=perl -e 'while(<>) { s%[^/\\ :]+[/\\]% %g; \
s%([-a-zA-Z0-9+-.:/\/_]+)%\$$(OBJDIR)/$$1%g; print $$_;}'
DEPINCLUDES= -I $(OBJDIR) $(SOURCEDIRS:%=-I %)
$(DEPENDDIR)/%.mli.depend: %.mli
@$(NARRATIVE) Generating dependency information for $<
$(ECHO)mkdir -p $(@D)
$(AT)$(CAML_DEP) $(DEPINCLUDES) $< | $(FIXDEPEND) > $@
$(DEPENDDIR)/%.ml.depend: %.ml
@$(NARRATIVE) Generating dependency information for $<
$(ECHO)mkdir -p $(@D)
$(AT)$(CAML_DEP) $(DEPINCLUDES) $< | $(FIXDEPEND) > $@
ifeq ($(MAKECMDGOALS),clean)
CLEANING := 1
endif
ifeq ($(MAKECMDGOALS),distclean)
CLEANING := 1
endif
ifndef CLEANING
-include $(MODULES:%=$(DEPENDDIR)/%.ml.depend)
-include $(MODULES:%=$(DEPENDDIR)/%.mli.depend)
endif