]> matita.cs.unibo.it Git - helm.git/blob - Makefile.common.in
cefbf646d19ab6053937eb26d931752086ef51a8
[helm.git] / Makefile.common.in
1 # This Makefile must be included by another one defining:
2 #  $PACKAGE
3 #  $REQUIRES
4 #  $PREDICATES
5 #  $INTERFACE_FILES
6 #  $IMPLEMENTATION_FILES
7 #  $EXTRA_OBJECTS_TO_INSTALL
8 #  $EXTRA_OBJECTS_TO_CLEAN
9 # and put in a directory where there is a .depend file.
10
11 OCAMLFIND_DEST_DIR = @OCAMLFIND_DEST_DIR@
12
13 PREPROCOPTIONS = -pp camlp4o
14 PREREQ =
15 OCAMLOPTIONS = -package "$(REQUIRES)" -predicates "$(PREDICATES)"
16 OCAMLDEBUGOPTIONS = -g
17 OCAMLFIND = ocamlfind
18 OCAMLC = $(OCAMLFIND) ocamlc $(OCAMLDEBUGOPTIONS) $(OCAMLOPTIONS) $(PREPROCOPTIONS)
19 OCAMLOPT = $(OCAMLFIND) opt $(OCAMLOPTIONS) $(PREPROCOPTIONS)
20 OCAMLDEP = $(OCAMLFIND) ocamldep $(PREPROCOPTIONS)
21 OCAMLLEX = ocamllex
22 OCAMLYACC = ocamlyacc
23
24 LIBRARIES = $(shell ocamlfind query -recursive -predicates "byte $(PREDICATES)" -format "%d/%a" $(REQUIRES))
25 LIBRARIES_OPT = $(shell ocamlfind query -recursive -predicates "native $(PREDICATES)" -format "%d/%a" $(REQUIRES))
26
27
28 ARCHIVE = $(PACKAGE).cma
29 ARCHIVE_OPT = $(PACKAGE).cmxa
30 OBJECTS_TO_INSTALL = $(ARCHIVE) $(ARCHIVE_OPT) $(ARCHIVE_OPT:%.cmxa=%.a) \
31                      $(INTERFACE_FILES) $(INTERFACE_FILES:%.mli=%.cmi) \
32                      $(EXTRA_OBJECTS_TO_INSTALL)
33 DEPEND_FILES = $(INTERFACE_FILES) $(IMPLEMENTATION_FILES)
34
35 $(ARCHIVE): $(IMPLEMENTATION_FILES:%.ml=%.cmo) $(LIBRARIES)
36         $(OCAMLC) -a -linkall -o $@ $(IMPLEMENTATION_FILES:%.ml=%.cmo)
37
38 $(ARCHIVE_OPT): $(IMPLEMENTATION_FILES:%.ml=%.cmx) $(LIBRARIES_OPT)
39         $(OCAMLOPT) -a -linkall -o $@ $(IMPLEMENTATION_FILES:%.ml=%.cmx)
40
41 prereq: $(PREREQ)
42 all: prereq $(IMPLEMENTATION_FILES:%.ml=%.cmo) $(ARCHIVE)
43 opt: prereq $(IMPLEMENTATION_FILES:%.ml=%.cmx) $(ARCHIVE_OPT)
44 world: all opt
45
46 depend: $(DEPEND_FILES)
47         $(OCAMLDEP) $(INTERFACE_FILES) $(IMPLEMENTATION_FILES) > .depend
48
49 $(PACKAGE).ps: .dep.dot
50         dot -Tps -o $@ $<
51
52 .dep.dot: .depend
53         ocamldot < .depend > $@
54
55 %.cmi: %.mli
56         $(OCAMLC) -c $<
57 %.cmo %.cmi: %.ml
58         $(OCAMLC) -c $<
59 %.cmx: %.ml
60         $(OCAMLOPT) -c $<
61 %.ml %.mli: %.mly
62         $(OCAMLYACC) $<
63 %.ml: %.mll
64         $(OCAMLLEX) $<
65
66 $(IMPLEMENTATION_FILES:%.ml=%.cmo): $(LIBRARIES)
67 $(IMPLEMENTATION_FILES:%.ml=%.cmx): $(LIBRARIES_OPT)
68
69 clean:
70         rm -f *.cm[ioax] *.cmxa *.o *.a $(EXTRA_OBJECTS_TO_CLEAN)
71
72 install:
73         mkdir $(OCAMLFIND_DEST_DIR)/$(PACKAGE)
74         cp $(OBJECTS_TO_INSTALL) $(OCAMLFIND_DEST_DIR)/$(PACKAGE)
75
76 uninstall:
77         cd $(OCAMLFIND_DEST_DIR)/$(PACKAGE) && rm -f $(OBJECTS_TO_INSTALL)
78         rmdir $(OCAMLFIND_DEST_DIR)/$(PACKAGE)
79
80 backup:
81         cd ..; tar cvzf $(PACKAGE)_$(shell date +%s).tar.gz $(PACKAGE)
82
83 .PHONY: all opt world backup depend install uninstall clean
84
85 ifneq ($(MAKECMDGOALS), depend)
86    include .depend   
87 endif
88
89 ifeq ($(MAKECMDGOALS), all)
90    $(IMPLEMENTATION_FILES:%.ml=%.cmi): $(LIBRARIES)
91 endif
92
93 ifeq ($(MAKECMDGOALS), opt)
94    $(IMPLEMENTATION_FILES:%.ml=%.cmi): $(LIBRARIES_OPT)
95 endif
96
97 ifeq ($(MAKECMDGOALS),)
98    $(IMPLEMENTATION_FILES:%.ml=%.cmi): $(LIBRARIES)
99 endif