forked from ocaml/ocamlbuild
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
380 lines (306 loc) · 9.77 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
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
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
#########################################################################
# #
# OCaml #
# #
# Nicolas Pouillard, Berke Durak, projet Gallium, INRIA Rocquencourt #
# #
# Copyright 2007 Institut National de Recherche en Informatique et #
# en Automatique. All rights reserved. This file is distributed #
# under the terms of the GNU Library General Public License, with #
# the special exception on linking described in file ../LICENSE. #
# #
#########################################################################
# see 'check-if-preinstalled' target
CHECK_IF_PREINSTALLED ?= true
OCAMLBUILD_LIBDIR:=$(LIBDIR)
OCAMLBUILD_BINDIR:=$(BINDIR)
# this configuration file is generated from configure.make
include Makefile.config
ifeq ($(OCAML_NATIVE_TOOLS), true)
OCAMLC ?= ocamlc.opt
OCAMLOPT ?= ocamlopt.opt
OCAMLDEP ?= ocamldep.opt
OCAMLLEX ?= ocamllex.opt
else
OCAMLC ?= ocamlc
OCAMLOPT ?= ocamlopt
OCAMLDEP ?= ocamldep
OCAMLLEX ?= ocamllex
endif
CP ?= cp
COMPFLAGS ?= -w L -w R -w Z -I src -I +unix -safe-string
LINKFLAGS ?= -I +unix -I src
PACK_CMO= $(addprefix src/,\
const.cmo \
loc.cmo \
discard_printf.cmo \
signatures.cmi \
my_std.cmo \
my_unix.cmo \
tags.cmo \
display.cmo \
log.cmo \
shell.cmo \
bool.cmo \
glob_ast.cmo \
glob_lexer.cmo \
glob.cmo \
lexers.cmo \
param_tags.cmo \
command.cmo \
ocamlbuild_config.cmo \
ocamlbuild_where.cmo \
slurp.cmo \
options.cmo \
pathname.cmo \
configuration.cmo \
flags.cmo \
hygiene.cmo \
digest_cache.cmo \
resource.cmo \
rule.cmo \
solver.cmo \
report.cmo \
tools.cmo \
fda.cmo \
findlib.cmo \
ocaml_arch.cmo \
ocaml_utils.cmo \
ocaml_dependencies.cmo \
ocaml_compiler.cmo \
ocaml_tools.cmo \
ocaml_specific.cmo \
plugin.cmo \
exit_codes.cmo \
hooks.cmo \
main.cmo \
)
EXTRA_CMO=$(addprefix src/,\
ocamlbuild_plugin.cmo \
ocamlbuild_executor.cmo \
ocamlbuild_unix_plugin.cmo \
)
PACK_CMX=$(PACK_CMO:.cmo=.cmx)
EXTRA_CMX=$(EXTRA_CMO:.cmo=.cmx)
EXTRA_CMI=$(EXTRA_CMO:.cmo=.cmi)
INSTALL_LIB=\
ocamlbuildlib.cma \
src/ocamlbuild.cmo \
ocamlbuild_pack.cmi \
$(EXTRA_CMO:.cmo=.cmi)
INSTALL_LIB_OPT=\
ocamlbuildlib.cmxa ocamlbuildlib$(EXT_LIB) \
src/ocamlbuild.cmx src/ocamlbuild$(EXT_OBJ) \
ocamlbuild_pack.cmx \
$(EXTRA_CMO:.cmo=.cmx) $(EXTRA_CMO:.cmo=$(EXT_OBJ))
INSTALL_LIBDIR=$(DESTDIR)$(LIBDIR)
INSTALL_BINDIR=$(DESTDIR)$(BINDIR)
ifeq ($(OCAML_NATIVE), true)
all: byte native
else
all: byte
endif
byte: ocamlbuild.byte ocamlbuildlib.cma
# ocamlbuildlight.byte ocamlbuildlightlib.cma
native: ocamlbuild.native ocamlbuildlib.cmxa
allopt: byte alias # compatibility alias
# The executables
ocamlbuild.byte: ocamlbuild_pack.cmo $(EXTRA_CMO) src/ocamlbuild.cmo
$(OCAMLC) $(LINKFLAGS) -o ocamlbuild.byte \
unix.cma ocamlbuild_pack.cmo $(EXTRA_CMO) src/ocamlbuild.cmo
ocamlbuildlight.byte: ocamlbuild_pack.cmo ocamlbuildlight.cmo
$(OCAMLC) $(LINKFLAGS) -o ocamlbuildlight.byte \
ocamlbuild_pack.cmo ocamlbuildlight.cmo
ocamlbuild.native: ocamlbuild_pack.cmx $(EXTRA_CMX) src/ocamlbuild.cmx
$(OCAMLOPT) $(LINKFLAGS) -o ocamlbuild.native \
unix.cmxa ocamlbuild_pack.cmx $(EXTRA_CMX) src/ocamlbuild.cmx
# The libraries
ocamlbuildlib.cma: ocamlbuild_pack.cmo $(EXTRA_CMO)
$(OCAMLC) -a -o ocamlbuildlib.cma \
ocamlbuild_pack.cmo $(EXTRA_CMO)
ocamlbuildlightlib.cma: ocamlbuild_pack.cmo ocamlbuildlight.cmo
$(OCAMLC) -a -o ocamlbuildlightlib.cma \
ocamlbuild_pack.cmo ocamlbuildlight.cmo
ocamlbuildlib.cmxa: ocamlbuild_pack.cmx $(EXTRA_CMX)
$(OCAMLOPT) -a -o ocamlbuildlib.cmxa \
ocamlbuild_pack.cmx $(EXTRA_CMX)
# The packs
ocamlbuild_pack.cmo: $(PACK_CMO)
$(OCAMLC) -pack $(PACK_CMO) -o ocamlbuild_pack.cmo
ocamlbuild_pack.cmi: ocamlbuild_pack.cmo
ocamlbuild_pack.cmx: $(PACK_CMX)
$(OCAMLOPT) -pack $(PACK_CMX) -o ocamlbuild_pack.cmx
# The lexers
src/lexers.ml: src/lexers.mll
$(OCAMLLEX) src/lexers.mll
clean::
rm -f src/lexers.ml
beforedepend:: src/lexers.ml
src/glob_lexer.ml: src/glob_lexer.mll
$(OCAMLLEX) src/glob_lexer.mll
clean::
rm -f src/glob_lexer.ml
beforedepend:: src/glob_lexer.ml
# The config file
configure: Makefile.config src/ocamlbuild_config.ml
Makefile.config src/ocamlbuild_config.ml:
$(MAKE) -f configure.make $@
clean::
rm -f Makefile.config src/ocamlbuild_config.ml
beforedepend:: src/ocamlbuild_config.ml
# Installation
# The binaries go in BINDIR. We copy ocamlbuild.byte and
# ocamlbuild.native (if available), and also copy the best available
# binary as BINDIR/ocamlbuild.
# The library is put in LIBDIR/ocamlbuild. We copy
# - the META file (for ocamlfind)
# - src/signatures.mli (user documentation)
# - the files in INSTALL_LIB and INSTALL_LIB_OPT (if available)
# We support three installation methods:
# - standard {install,uninstall} targets
# - findlib-{install,uninstall} that uses findlib for the library install
# - producing an OPAM .install file and not actually installing anything
install-bin-byte:
mkdir -p $(INSTALL_BINDIR)
$(CP) ocamlbuild.byte $(INSTALL_BINDIR)/ocamlbuild.byte$(EXE)
ifneq ($(OCAML_NATIVE), true)
$(CP) ocamlbuild.byte $(INSTALL_BINDIR)/ocamlbuild$(EXE)
endif
install-bin-native:
mkdir -p $(INSTALL_BINDIR)
$(CP) ocamlbuild.native $(INSTALL_BINDIR)/ocamlbuild$(EXE)
$(CP) ocamlbuild.native $(INSTALL_BINDIR)/ocamlbuild.native$(EXE)
ifeq ($(OCAML_NATIVE), true)
install-bin: install-bin-byte install-bin-native
else
install-bin: install-bin-byte
endif
install-bin-opam:
echo 'bin: [' >> ocamlbuild.install
echo ' "ocamlbuild.byte" {"ocamlbuild.byte"}' >> ocamlbuild.install
ifeq ($(OCAML_NATIVE), true)
echo ' "ocamlbuild.native" {"ocamlbuild.native"}' >> ocamlbuild.install
echo ' "ocamlbuild.native" {"ocamlbuild"}' >> ocamlbuild.install
else
echo ' "ocamlbuild.byte" {"ocamlbuild"}' >> ocamlbuild.install
endif
echo ']' >> ocamlbuild.install
echo >> ocamlbuild.install
install-lib-basics:
mkdir -p $(INSTALL_LIBDIR)/ocamlbuild
$(CP) META src/signatures.mli $(INSTALL_LIBDIR)/ocamlbuild
install-lib-basics-opam:
echo ' "META"' >> ocamlbuild.install
echo ' "src/signatures.mli" {"signatures.mli"}' >> ocamlbuild.install
install-lib-byte:
mkdir -p $(INSTALL_LIBDIR)/ocamlbuild
$(CP) $(INSTALL_LIB) $(INSTALL_LIBDIR)/ocamlbuild
install-lib-byte-opam:
for lib in $(INSTALL_LIB); do \
echo " \"$$lib\" {\"$$(basename $$lib)\"}" >> ocamlbuild.install; \
done
install-lib-native:
mkdir -p $(INSTALL_LIBDIR)/ocamlbuild
$(CP) $(INSTALL_LIB_OPT) $(INSTALL_LIBDIR)/ocamlbuild
install-lib-native-opam:
for lib in $(INSTALL_LIB_OPT); do \
echo " \"$$lib\" {\"$$(basename $$lib)\"}" >> ocamlbuild.install; \
done
ifeq ($(OCAML_NATIVE), true)
install-lib: install-lib-basics install-lib-byte install-lib-native
else
install-lib: install-lib-basics install-lib-byte
endif
install-lib-findlib:
ifeq ($(OCAML_NATIVE), true)
ocamlfind install ocamlbuild \
META src/signatures.mli $(INSTALL_LIB) $(INSTALL_LIB_OPT)
else
ocamlfind install ocamlbuild \
META src/signatures.mli $(INSTALL_LIB)
endif
install-lib-opam:
echo 'lib: [' >> ocamlbuild.install
$(MAKE) install-lib-basics-opam
$(MAKE) install-lib-byte-opam
ifeq ($(OCAML_NATIVE), true)
$(MAKE) install-lib-native-opam
endif
echo ']' >> ocamlbuild.install
echo >> ocamlbuild.install
uninstall-bin:
rm $(BINDIR)/ocamlbuild
rm $(BINDIR)/ocamlbuild.byte
ifeq ($(OCAML_NATIVE), true)
rm $(BINDIR)/ocamlbuild.native
endif
uninstall-lib-basics:
rm $(LIBDIR)/ocamlbuild/META $(LIBDIR)/ocamlbuild/signatures.mli
uninstall-lib-byte:
for lib in $(INSTALL_LIB); do\
rm $(LIBDIR)/ocamlbuild/`basename $$lib`;\
done
uninstall-lib-native:
for lib in $(INSTALL_LIB_OPT); do\
rm $(LIBDIR)/ocamlbuild/`basename $$lib`;\
done
uninstall-lib:
$(MAKE) uninstall-lib-basics uninstall-lib-byte
ifeq ($(OCAML_NATIVE), true)
$(MAKE) uninstall-lib-native
endif
ls $(LIBDIR)/ocamlbuild # for easier debugging if rmdir fails
rmdir $(LIBDIR)/ocamlbuild
uninstall-lib-findlib:
ocamlfind remove ocamlbuild
install: check-if-preinstalled
$(MAKE) install-bin install-lib
uninstall: uninstall-bin uninstall-lib
findlib-install: check-if-preinstalled
$(MAKE) install-bin install-lib-findlib
findlib-uninstall: uninstall-bin uninstall-lib-findlib
opam-install: check-if-preinstalled
$(MAKE) ocamlbuild.install
ocamlbuild.install:
rm -f ocamlbuild.install
touch ocamlbuild.install
$(MAKE) install-bin-opam
$(MAKE) install-lib-opam
check-if-preinstalled:
ifeq ($(CHECK_IF_PREINSTALLED), true)
if test -d $(shell ocamlc -where)/ocamlbuild; then\
>&2 echo "ERROR: Preinstalled ocamlbuild detected at"\
"$(shell ocamlc -where)/ocamlbuild";\
>&2 echo "Installation aborted; if you want to bypass this"\
"safety check, pass CHECK_IF_PREINSTALLED=false to make";\
exit 2;\
fi
endif
# The generic rules
.SUFFIXES: .ml .mli .cmo .cmi .cmx
.ml.cmo:
$(OCAMLC) $(COMPFLAGS) -c $<
.mli.cmi:
$(OCAMLC) $(COMPFLAGS) -c $<
.ml.cmx:
$(OCAMLOPT) -for-pack Ocamlbuild_pack $(COMPFLAGS) -c $<
clean::
rm -f src/*.cm? *.cm*
ifdef EXT_OBJ
rm -f src/*$(EXT_OBJ) *$(EXT_OBJ)
endif
ifdef EXT_LIB
rm -f src/*$(EXT_LIB) *$(EXT_LIB)
endif
rm -f *.byte *.native
rm -f test/test2/vivi.ml
rm -f ocamlbuild.install
# The dependencies
depend: beforedepend
$(OCAMLDEP) -I src src/*.mli src/*.ml > .depend
$(EXTRA_CMI): ocamlbuild_pack.cmi
$(EXTRA_CMO): ocamlbuild_pack.cmo ocamlbuild_pack.cmi
$(EXTRA_CMX): ocamlbuild_pack.cmx ocamlbuild_pack.cmi
include .depend
.PHONY: all allopt clean beforedepend
.PHONY: install installopt installopt_really depend