Split out field handling from pa_bitmatch into a common library, in preparation for...
[ocaml-bitstring.git] / Makefile.in
1 # Bitmatch syntax extension.
2 # Copyright (C) 2008 Red Hat Inc., Richard W.M. Jones
3 #
4 # This library is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU Lesser General Public
6 # License as published by the Free Software Foundation; either
7 # version 2 of the License, or (at your option) any later version.
8 #
9 # This library is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 # Lesser General Public License for more details.
13 #
14 # You should have received a copy of the GNU Lesser General Public
15 # License along with this library; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
17 #
18 # $Id$
19
20 PACKAGE         = @PACKAGE_NAME@
21 VERSION         = @PACKAGE_VERSION@
22
23 OCAMLFIND       = @OCAMLFIND@
24 OCAMLMKLIB      = @OCAMLMKLIB@
25 OCAMLDOC        = @OCAMLDOC@
26 INSTALL         = @INSTALL@
27
28 OCAMLCFLAGS     = -g
29 OCAMLCPACKAGES  =
30 OCAMLOPTFLAGS   =
31 OCAMLOPTPACKAGES =
32
33 OCAMLDOCFLAGS   = -html -sort
34
35 SUBDIRS         =
36 ifneq ($(pkg_cil),no)
37 SUBDIRS         += cil-tools
38 endif
39
40 EXAMPLES        = $(patsubst %.ml,%,$(wildcard examples/*.ml))
41
42 TESTS           = $(patsubst %.ml,%,$(wildcard tests/*.ml))
43
44 all:    bitmatch.cma bitmatch_persistent.cma \
45         bitmatch.cmxa bitmatch_persistent.cmxa \
46         pa_bitmatch.cmo
47         @for d in $(SUBDIRS); do $(MAKE) -C $$d $@; done
48
49 bitmatch.cma: bitmatch_types.cmo bitmatch_config.cmo bitmatch.cmo
50         $(OCAMLFIND) ocamlc -a -o $@ $^
51
52 bitmatch_persistent.cma: bitmatch_persistent.cmo
53         $(OCAMLFIND) ocamlc -a -o $@ $^
54
55 bitmatch_persistent.cmo: bitmatch_persistent.ml
56         $(OCAMLFIND) ocamlc $(OCAMLCFLAGS) $(OCAMLCPACKAGES) \
57           -I +camlp4 -pp camlp4of -c $<
58
59 bitmatch.cmxa: bitmatch_types.cmx bitmatch_config.cmx bitmatch.cmx
60         $(OCAMLFIND) ocamlopt -a -o $@ $^
61
62 bitmatch_persistent.cmxa: bitmatch_persistent.cmx
63         $(OCAMLFIND) ocamlopt -a -o $@ $^
64
65 bitmatch_persistent.cmx: bitmatch_persistent.ml
66         $(OCAMLFIND) ocamlopt $(OCAMLOPTFLAGS) $(OCAMLOPTPACKAGES) \
67           -I +camlp4 -pp camlp4of -c $<
68
69 bitmatch_persistent.cmi: bitmatch_persistent.mli
70         $(OCAMLFIND) ocamlc $(OCAMLCFLAGS) $(OCAMLCPACKAGES) \
71           -I +camlp4 -pp camlp4of -c $<
72
73 pa_bitmatch.cmo: pa_bitmatch.ml bitmatch.cma bitmatch_persistent.cma
74         $(OCAMLFIND) ocamlc bitmatch.cma -I +camlp4 camlp4lib.cma \
75           -pp camlp4of -c $< -o $@
76
77 # Tests and examples.
78
79 PP      = -pp "camlp4o bitmatch.cma bitmatch_persistent.cma pa_bitmatch.cmo"
80
81 test: pa_bitmatch.cmo bitmatch.cma bitmatch_persistent.cma
82         @for f in $(TESTS); do \
83           echo Building $$f; \
84           $(OCAMLFIND) ocamlc $(OCAMLCFLAGS) $(PP) \
85             -package unix -linkpkg -I . bitmatch.cma $$f.ml -o $$f; \
86           if [ $$? -ne 0 ]; then exit 1; fi; \
87           echo Running $$f; \
88           $$f; \
89           if [ $$? -ne 0 ]; then exit 1; fi; \
90         done
91         @for d in $(SUBDIRS); do $(MAKE) -C $$d $@; done
92
93 examples: pa_bitmatch.cmo bitmatch.cma bitmatch_persistent.cma
94         @for f in $(EXAMPLES); do \
95           echo Building $$f; \
96           $(OCAMLFIND) ocamlc $(OCAMLFLAGS) $(PP) \
97             -package unix -linkpkg -I . bitmatch.cma $$f.ml -o $$f; \
98           if [ $$? -ne 0 ]; then exit 1; fi; \
99         done
100         @for d in $(SUBDIRS); do $(MAKE) -C $$d $@; done
101
102 print-tests: pa_bitmatch.cmo bitmatch_persistent.cma
103         @for f in $(TESTS); do \
104           echo Test: $$f.ml; \
105           cmd="camlp4o bitmatch.cma bitmatch_persistent.cma pa_bitmatch.cmo \
106             -printer pr_o.cmo $$f.ml"; \
107           echo $$cmd; \
108           $$cmd; \
109         done
110
111 print-examples: pa_bitmatch.cmo
112         @for f in $(EXAMPLES); do \
113           echo Example: $$f.ml; \
114           camlp4o bitmatch.cma bitmatch_persistent.cma pa_bitmatch.cmo \
115             -printer pr_o.cmo $$f.ml; \
116           if [ $$? -ne 0 ]; then exit 1; fi; \
117         done
118
119 # Clean.
120
121 clean:
122         rm -f core *~ *.cmi *.cmo *.cmx *.cma *.cmxa *.a *.o
123         rm -f tests/*~ tests/*.cmi tests/*.cmo $(TESTS)
124         rm -f examples/*~ examples/*.cmi examples/*.cmo $(EXAMPLES)
125         @for d in $(SUBDIRS); do $(MAKE) -C $$d $@; done
126
127 distclean: clean
128         rm -rf autom4te.cache
129         rm -f config.log config.status
130         rm -f config.h Makefile META bitmatch_config.ml
131         @for d in $(SUBDIRS); do $(MAKE) -C $$d $@; done
132
133 # Documentation.
134
135 ifneq ($(OCAMLDOC),)
136 doc:
137         rm -rf html
138         mkdir html
139         $(OCAMLDOC) $(OCAMLDOCFLAGS) -d html bitmatch.mli bitmatch.ml \
140           bitmatch_persistent.mli bitmatch_persistent.ml
141 endif
142
143 # Install.
144
145 install:
146         ocamlfind install bitmatch META *.mli *.cmx *.cma *.cmxa *.a \
147                 bitmatch.cmi \
148                 bitmatch_persistent.cmi \
149                 pa_bitmatch.cmo
150         @for d in $(SUBDIRS); do $(MAKE) -C $$d $@; done
151
152 # Standard rules.
153
154 .mli.cmi:
155         $(OCAMLFIND) ocamlc $(OCAMLCFLAGS) $(OCAMLCPACKAGES) -c $<
156 .ml.cmo:
157         $(OCAMLFIND) ocamlc $(OCAMLCFLAGS) $(OCAMLCPACKAGES) -c $<
158 .ml.cmx:
159         $(OCAMLFIND) ocamlopt $(OCAMLOPTFLAGS) $(OCAMLOPTPACKAGES) -c $<
160
161 depend: .depend
162         @for d in $(SUBDIRS); do $(MAKE) -C $$d $@; done
163
164 .depend: bitmatch.ml bitmatch.mli bitmatch_persistent.ml bitmatch_persistent.mli
165         rm -f .depend
166         $(OCAMLFIND) ocamldep $(OCAMLCPACKAGES) bitmatch.ml bitmatch.mli >> $@
167         $(OCAMLFIND) ocamldep $(OCAMLCPACKAGES) -pp camlp4of \
168           bitmatch_persistent.ml bitmatch_persistent.mli >> $@
169
170 ifeq ($(wildcard .depend),.depend)
171 include .depend
172 endif
173
174 # Distribution.
175
176 dist:
177         $(MAKE) check-manifest
178         rm -rf $(PACKAGE)-$(VERSION)
179         mkdir $(PACKAGE)-$(VERSION)
180         tar -cf - -T MANIFEST | tar -C $(PACKAGE)-$(VERSION) -xf -
181         $(INSTALL) -m 0755 configure $(PACKAGE)-$(VERSION)/
182         $(INSTALL) -m 0644 config.h.in $(PACKAGE)-$(VERSION)/
183         svn log -v > $(PACKAGE)-$(VERSION)/CHANGES
184         tar zcf $(PACKAGE)-$(VERSION).tar.gz $(PACKAGE)-$(VERSION)
185         rm -rf $(PACKAGE)-$(VERSION)
186         ls -l $(PACKAGE)-$(VERSION).tar.gz
187
188 check-manifest:
189         svn -R list | grep -v '/$$' | sort > .check-manifest
190         sort MANIFEST > .orig-manifest; \
191         diff -u .orig-manifest .check-manifest; rv=$$?; \
192         rm -f .orig-manifest .check-manifest; \
193         exit $$rv
194
195 .PHONY: depend dist check-manifest dpkg doc \
196         print-examples print-tests examples test
197
198 .SUFFIXES:      .cmo .cmi .cmx .ml .mli .mll