Use ocaml-bisect to compute coverage of tests.
[ocaml-bitstring.git] / Makefile.in
1 # Bitstring 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 TIME            = @TIME@
28 GPROF           = @GPROF@
29 BISECT_REPORT   = @BISECT_REPORT@
30
31 BYTESWAP_H      = @BYTESWAP_H@
32
33 OCAMLLIB        = @OCAMLLIB@
34 top_srcdir      = @top_srcdir@
35
36 pkg_cil         = @pkg_cil@
37 pkg_extlib      = @pkg_extlib@
38
39 enable_coverage = @enable_coverage@
40
41 OCAMLCFLAGS     = -g
42 OCAMLCPACKAGES  =
43 OCAMLCLIBS      = -linkpkg
44 OCAMLOPTFLAGS   =
45 OCAMLOPTPACKAGES =
46 OCAMLOPTLIBS    = -linkpkg
47
48 ifneq ($(enable_coverage),no)
49 OCAMLCFLAGS     += -I +bisect -pp 'camlp4o $(OCAMLLIB)/bisect/instrument.cma'
50 OCAMLCLIBS      += -I +bisect bisect.cma
51 OCAMLOPTFLAGS   += -I +bisect -pp 'camlp4o $(OCAMLLIB)/bisect/instrument.cma'
52 OCAMLOPTLIBS    += -I +bisect bisect.cmxa
53 endif
54
55 OCAMLDOCFLAGS   = -html -sort
56
57 CC              = @CC@
58 CFLAGS          = @CFLAGS@ -Wall -Werror -fPIC -I$(top_srcdir) -I$(OCAMLLIB)
59
60 LIBRARY_PATH    = @abs_top_builddir@
61 LD_LIBRARY_PATH = @abs_top_builddir@
62 export LIBRARY_PATH
63 export LD_LIBRARY_PATH
64
65 SUBDIRS         =
66 ifneq ($(pkg_cil),no)
67 ifneq ($(pkg_extlib),no)
68 SUBDIRS         += cil-tools
69 endif
70 endif
71
72 EXAMPLES        = $(patsubst %.ml,%,$(wildcard examples/*.ml))
73
74 TESTS           = $(patsubst %.ml,%,$(wildcard tests/*.ml))
75
76 BENCHMARKS      = $(patsubst %.ml,%,$(wildcard benchmarks/*.ml))
77
78 all:    $(BYTESWAP_H) \
79         bitstring.cma bitstring_persistent.cma \
80         bitstring.cmxa bitstring_persistent.cmxa \
81         pa_bitstring.cmo \
82         bitstring-objinfo
83         @for d in $(SUBDIRS); do $(MAKE) -C $$d $@; done
84
85 bitstring.cma: bitstring_types.cmo bitstring_config.cmo \
86           bitstring_c.o bitstring.cmo bitmatch.cmo
87         $(OCAMLMKLIB) -o bitstring $^
88
89 bitstring_persistent.cma: bitstring_persistent.cmo
90         $(OCAMLFIND) ocamlc -a -o $@ $^
91
92 bitstring_persistent.cmo: bitstring_persistent.ml
93         $(OCAMLFIND) ocamlc $(OCAMLCFLAGS) $(OCAMLCPACKAGES) \
94           -I +camlp4 -pp camlp4of -c $<
95
96 bitstring.cmxa: bitstring_types.cmx bitstring_config.cmx \
97           bitstring_c.o bitstring.cmx bitmatch.cmx
98         $(OCAMLMKLIB) -o bitstring $^
99
100 bitstring_persistent.cmxa: bitstring_persistent.cmx
101         $(OCAMLFIND) ocamlopt -a -o $@ $^
102
103 bitstring_persistent.cmx: bitstring_persistent.ml
104         $(OCAMLFIND) ocamlopt $(OCAMLOPTFLAGS) $(OCAMLOPTPACKAGES) \
105           -I +camlp4 -pp camlp4of -c $<
106
107 bitstring_persistent.cmi: bitstring_persistent.mli
108         $(OCAMLFIND) ocamlc $(OCAMLCFLAGS) $(OCAMLCPACKAGES) \
109           -I +camlp4 -pp camlp4of -c $<
110
111 pa_bitstring.cmo: pa_bitstring.ml bitstring.cma bitstring_persistent.cma
112         $(OCAMLFIND) ocamlc bitstring.cma -I +camlp4 camlp4lib.cma \
113           -pp camlp4of -c $< -o $@
114
115 bitstring-objinfo: bitstring_objinfo.cmo bitstring.cma bitstring_persistent.cma
116         $(OCAMLFIND) ocamlc -I +camlp4 unix.cma camlp4lib.cma \
117           $(OCAMLCLIBS) \
118           bitstring.cma bitstring_persistent.cma \
119           $< -o $@
120
121 # Create byteswap.h if the system doesn't have this file.
122 # From gnulib, license is LGPLv2+.
123
124 byteswap.h: byteswap.in.h
125         { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
126           cat $(srcdir)/byteswap.in.h; \
127         } > $@-t
128         mv -f $@-t $@
129
130 # Tests.
131
132 ifeq ($(enable_coverage),no)
133 PP      = -pp 'camlp4o bitstring.cma bitstring_persistent.cma pa_bitstring.cmo'
134 else
135 PP      = -pp 'camlp4o $(OCAMLLIB)/bisect/bisect.cma bitstring.cma bitstring_persistent.cma pa_bitstring.cmo'
136 endif
137
138 test: pa_bitstring.cmo bitstring.cma bitstring_persistent.cma tests/test.bmpp
139         @for f in $(TESTS); do \
140           echo Building $$f; \
141           $(OCAMLFIND) ocamlopt $(OCAMLOPTFLAGS) $(PP) -package unix $(OCAMLOPTLIBS) -I . bitstring.cmxa $$f.ml -o $$f.opt; \
142           if [ $$? -ne 0 ]; then exit 1; fi; \
143           echo Running $$f; \
144           $$f.opt; \
145           if [ $$? -ne 0 ]; then exit 1; fi; \
146         done
147         @for d in $(SUBDIRS); do $(MAKE) -C $$d $@; done
148
149 tests/test.bmpp: create_test_pattern
150         ./$< $@.new
151         mv $@.new $@
152
153 create_test_pattern: create_test_pattern.cmo
154         $(OCAMLFIND) ocamlc $(OCAMLCFLAGS) -pp camlp4of \
155           unix.cma -I +camlp4 camlp4lib.cma \
156           $(OCAMLCLIBS) \
157           -I . bitstring.cma bitstring_persistent.cma $< -o $@
158
159 create_test_pattern.cmo: create_test_pattern.ml
160         $(OCAMLFIND) ocamlc $(OCAMLCFLAGS) -pp camlp4of \
161           unix.cma -I +camlp4 \
162           -I . -c $< -o $@
163
164 # Coverage of tests.
165
166 ifneq ($(BISECT_REPORT),no)
167 coverage:
168         rm -f coverage-report/*
169         rm -f bisect*.out
170         $(MAKE) test
171         $(BISECT_REPORT) -html coverage-report bisect*.out
172         rm -f bisect*.out
173         @echo Coverage report is in `pwd`/coverage-report/index.html
174 endif
175
176 # Examples.
177
178 examples: pa_bitstring.cmo bitstring.cma bitstring_persistent.cma
179         @for f in $(EXAMPLES); do \
180           echo Building $$f; \
181           $(OCAMLFIND) ocamlc $(OCAMLCFLAGS) $(PP) \
182             -package unix -linkpkg -I . bitstring.cma $$f.ml -o $$f; \
183           if [ $$? -ne 0 ]; then exit 1; fi; \
184         done
185         @for d in $(SUBDIRS); do $(MAKE) -C $$d $@; done
186
187 print-tests: pa_bitstring.cmo bitstring_persistent.cma
188         @for f in $(TESTS); do \
189           echo Test: $$f.ml; \
190           cmd="camlp4o bitstring.cma bitstring_persistent.cma pa_bitstring.cmo \
191             -printer pr_o.cmo $$f.ml"; \
192           echo $$cmd; \
193           $$cmd; \
194         done
195
196 print-examples: pa_bitstring.cmo
197         @for f in $(EXAMPLES); do \
198           echo Example: $$f.ml; \
199           camlp4o bitstring.cma bitstring_persistent.cma pa_bitstring.cmo \
200             -printer pr_o.cmo $$f.ml; \
201           if [ $$? -ne 0 ]; then exit 1; fi; \
202         done
203
204 # Benchmarks.
205
206 ifneq ($(TIME),no)
207
208 benchmarks: pa_bitstring.cmo bitstring.cma bitstring_persistent.cma
209         @for f in $(BENCHMARKS); do \
210           $(OCAMLFIND) ocamlopt $(OCAMLOPTFLAGS) $(PP) \
211             -package unix -linkpkg -I . bitstring.cmxa $$f.ml -o $$f.opt; \
212           if [ $$? -ne 0 ]; then exit 1; fi; \
213           $(TIME) -f "$$f: %e seconds" $$f.opt; \
214           if [ $$? -ne 0 ]; then exit 1; fi; \
215         done
216 ifneq ($(GPROF),no)
217         @for f in $(BENCHMARKS); do \
218           $(OCAMLFIND) ocamlopt $(OCAMLOPTFLAGS) $(PP) -p \
219             -package unix -linkpkg -I . bitstring.cmxa $$f.ml -o $$f.opt.p; \
220           if [ $$? -ne 0 ]; then exit 1; fi; \
221           rm -f gmon.out; \
222           $$f.opt.p; \
223           if [ $$? -ne 0 ]; then exit 1; fi; \
224           gprof $$f.opt.p > $$f.profile; \
225           if [ $$? -ne 0 ]; then exit 1; fi; \
226           echo "Wrote profile of $$f"; \
227           echo "    to $$f.profile"; \
228           rm -f gmon.out; \
229         done
230 endif
231
232 endif
233
234 # Clean.
235
236 clean:
237         rm -f core *~ *.cmi *.cmo *.cmx *.cma *.cmxa *.a *.o
238         rm -f tests/*~ tests/*.cmi tests/*.cmo tests/*.opt
239         rm -f examples/*~ examples/*.cmi examples/*.cmo $(EXAMPLES)
240         rm -f benchmarks/*~ benchmarks/*.cmi benchmarks/*.cmo
241         rm -f benchmarks/*.opt benchmarks/*.opt.p benchmarks/*.profile
242         @for d in $(SUBDIRS); do $(MAKE) -C $$d $@; done
243
244 distclean: clean
245         rm -rf autom4te.cache
246         rm -f config.log config.status
247         rm -f config.h Makefile META bitstring_config.ml
248         rm -f bitstring-objinfo
249         @for d in $(SUBDIRS); do $(MAKE) -C $$d $@; done
250
251 # Documentation.
252
253 ifneq ($(OCAMLDOC),)
254 doc:
255         rm -rf html
256         mkdir html
257         $(OCAMLDOC) $(OCAMLDOCFLAGS) -d html -I +camlp4 \
258           bitstring.mli bitstring_persistent.mli bitmatch.ml
259 endif
260
261 # Install.
262
263 install:
264         ocamlfind install bitstring META *.mli *.cmx *.cma *.cmxa *.a *.so \
265                 bitstring.cmi \
266                 bitstring_persistent.cmi \
267                 pa_bitstring.cmo
268         @for d in $(SUBDIRS); do $(MAKE) -C $$d $@; done
269
270 # Standard rules.
271
272 .mli.cmi:
273         $(OCAMLFIND) ocamlc $(OCAMLCFLAGS) $(OCAMLCPACKAGES) -c $<
274 .ml.cmo:
275         $(OCAMLFIND) ocamlc $(OCAMLCFLAGS) $(OCAMLCPACKAGES) -c $<
276 .ml.cmx:
277         $(OCAMLFIND) ocamlopt $(OCAMLOPTFLAGS) $(OCAMLOPTPACKAGES) -c $<
278
279 depend: .depend
280         @for d in $(SUBDIRS); do $(MAKE) -C $$d $@; done
281
282 .depend: bitstring.ml bitstring.mli \
283           bitstring_persistent.ml bitstring_persistent.mli \
284           bitstring_objinfo.ml \
285           create_test_pattern.ml
286         rm -f .depend
287         $(OCAMLFIND) ocamldep $(OCAMLCPACKAGES) \
288           bitstring.ml bitstring.mli \
289           bitstring_objinfo.ml >> $@
290         $(OCAMLFIND) ocamldep $(OCAMLCPACKAGES) -pp camlp4of \
291           bitstring_persistent.ml bitstring_persistent.mli \
292           create_test_pattern.ml >> $@
293
294 ifeq ($(wildcard .depend),.depend)
295 include .depend
296 endif
297
298 # Distribution.
299
300 dist:
301         $(MAKE) check-manifest
302         rm -rf $(PACKAGE)-$(VERSION)
303         mkdir $(PACKAGE)-$(VERSION)
304         tar -cf - -T MANIFEST | tar -C $(PACKAGE)-$(VERSION) -xf -
305         $(INSTALL) -m 0755 configure $(PACKAGE)-$(VERSION)/
306         $(INSTALL) -m 0644 config.h.in $(PACKAGE)-$(VERSION)/
307         svn log -v > $(PACKAGE)-$(VERSION)/CHANGES
308         tar zcf $(PACKAGE)-$(VERSION).tar.gz $(PACKAGE)-$(VERSION)
309         rm -rf $(PACKAGE)-$(VERSION)
310         ls -l $(PACKAGE)-$(VERSION).tar.gz
311
312 check-manifest:
313         svn -R list | grep -v '/$$' | sort > .check-manifest
314         sort MANIFEST > .orig-manifest; \
315         diff -u .orig-manifest .check-manifest; rv=$$?; \
316         rm -f .orig-manifest .check-manifest; \
317         exit $$rv
318
319 .PHONY: depend dist check-manifest dpkg doc \
320         print-examples print-tests examples test benchmarks
321
322 .SUFFIXES:      .cmo .cmi .cmx .ml .mli .mll