Add 'make check' as a synonym for 'make test'.
[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         = @OCAML_PKG_cil@
37 pkg_extlib      = @OCAML_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 dynlink.cma 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 dynlink.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 check: test
139
140 test: pa_bitstring.cmo \
141         bitstring.cma bitstring_persistent.cma \
142         bitstring.cmxa bitstring_persistent.cmxa \
143         tests/test.bmpp
144         @for f in $(TESTS); do \
145           echo Building $$f; \
146           $(OCAMLFIND) ocamlopt $(OCAMLOPTFLAGS) $(PP) -package unix $(OCAMLOPTLIBS) -I . bitstring.cmxa $$f.ml -o $$f.opt; \
147           if [ $$? -ne 0 ]; then exit 1; fi; \
148           echo Running $$f; \
149           $$f.opt; \
150           if [ $$? -ne 0 ]; then exit 1; fi; \
151         done
152         @for d in $(SUBDIRS); do $(MAKE) -C $$d $@; done
153
154 tests/test.bmpp: create_test_pattern
155         ./$< $@.new
156         mv $@.new $@
157
158 create_test_pattern: create_test_pattern.cmo
159         $(OCAMLFIND) ocamlc $(OCAMLCFLAGS) -pp camlp4of \
160           unix.cma -I +camlp4 dynlink.cma camlp4lib.cma \
161           $(OCAMLCLIBS) \
162           -I . bitstring.cma bitstring_persistent.cma $< -o $@
163
164 create_test_pattern.cmo: create_test_pattern.ml
165         $(OCAMLFIND) ocamlc $(OCAMLCFLAGS) -pp camlp4of \
166           unix.cma -I +camlp4 \
167           -I . -c $< -o $@
168
169 # Coverage of tests.
170
171 ifneq ($(BISECT_REPORT),no)
172 coverage:
173         rm -f coverage-report/*
174         rm -f bisect*.out
175         $(MAKE) test
176         $(BISECT_REPORT) -html coverage-report bisect*.out
177         rm -f bisect*.out
178         @echo Coverage report is in `pwd`/coverage-report/index.html
179 endif
180
181 # Examples.
182
183 examples: pa_bitstring.cmo bitstring.cma bitstring_persistent.cma
184         @for f in $(EXAMPLES); do \
185           echo Building $$f; \
186           $(OCAMLFIND) ocamlc $(OCAMLCFLAGS) $(PP) \
187             -package unix -linkpkg -I . bitstring.cma $$f.ml -o $$f; \
188           if [ $$? -ne 0 ]; then exit 1; fi; \
189         done
190         @for d in $(SUBDIRS); do $(MAKE) -C $$d $@; done
191
192 print-tests: pa_bitstring.cmo bitstring_persistent.cma
193         @for f in $(TESTS); do \
194           echo Test: $$f.ml; \
195           cmd="camlp4o bitstring.cma bitstring_persistent.cma pa_bitstring.cmo \
196             -printer pr_o.cmo $$f.ml"; \
197           echo $$cmd; \
198           $$cmd; \
199         done
200
201 print-examples: pa_bitstring.cmo
202         @for f in $(EXAMPLES); do \
203           echo Example: $$f.ml; \
204           camlp4o bitstring.cma bitstring_persistent.cma pa_bitstring.cmo \
205             -printer pr_o.cmo $$f.ml; \
206           if [ $$? -ne 0 ]; then exit 1; fi; \
207         done
208
209 # Benchmarks.
210
211 ifneq ($(TIME),no)
212
213 benchmarks: pa_bitstring.cmo bitstring.cma bitstring_persistent.cma
214         @for f in $(BENCHMARKS); do \
215           $(OCAMLFIND) ocamlopt $(OCAMLOPTFLAGS) $(PP) \
216             -package unix -linkpkg -I . bitstring.cmxa $$f.ml -o $$f.opt; \
217           if [ $$? -ne 0 ]; then exit 1; fi; \
218           $(TIME) -f "$$f: %e seconds" $$f.opt; \
219           if [ $$? -ne 0 ]; then exit 1; fi; \
220         done
221 ifneq ($(GPROF),no)
222         @for f in $(BENCHMARKS); do \
223           $(OCAMLFIND) ocamlopt $(OCAMLOPTFLAGS) $(PP) -p \
224             -package unix -linkpkg -I . bitstring.cmxa $$f.ml -o $$f.opt.p; \
225           if [ $$? -ne 0 ]; then exit 1; fi; \
226           rm -f gmon.out; \
227           $$f.opt.p; \
228           if [ $$? -ne 0 ]; then exit 1; fi; \
229           gprof $$f.opt.p > $$f.profile; \
230           if [ $$? -ne 0 ]; then exit 1; fi; \
231           echo "Wrote profile of $$f"; \
232           echo "    to $$f.profile"; \
233           rm -f gmon.out; \
234         done
235 endif
236
237 endif
238
239 # Clean.
240
241 clean:
242         rm -f core *~ *.cmi *.cmo *.cmx *.cma *.cmxa *.cmp *.a *.o *.so
243         rm -f tests/*~ tests/*.cmi tests/*.cmo tests/*.cmx tests/*.opt
244         rm -f tests/*.o
245         rm -f examples/*~ examples/*.cmi examples/*.cmo examples/*.cmx
246         rm -f examples/*.o $(EXAMPLES)
247         rm -f benchmarks/*~ benchmarks/*.cmi benchmarks/*.cmo
248         rm -f benchmarks/*.cmx benchmarks/*.o
249         rm -f benchmarks/*.opt benchmarks/*.opt.p benchmarks/*.profile
250         rm -f create_test_pattern bitstring-objinfo
251         @for d in $(SUBDIRS); do $(MAKE) -C $$d $@; done
252
253 distclean: clean
254         rm -rf autom4te.cache
255         rm -f config.log config.status
256         rm -f config.h Makefile META bitstring_config.ml
257         rm -f bitstring-objinfo
258         @for d in $(SUBDIRS); do $(MAKE) -C $$d $@; done
259
260 # Documentation.
261
262 ifneq ($(OCAMLDOC),)
263 doc:
264         rm -rf html
265         mkdir html
266         $(OCAMLDOC) $(OCAMLDOCFLAGS) -d html -I +camlp4 \
267           bitstring.mli bitstring_persistent.mli bitmatch.ml
268 endif
269
270 # Install.
271
272 install:
273         ocamlfind install bitstring META *.mli *.cmx *.cma *.cmxa *.a *.so \
274                 bitstring.cmi \
275                 bitstring_persistent.cmi \
276                 pa_bitstring.cmo
277         @for d in $(SUBDIRS); do $(MAKE) -C $$d $@; done
278
279 uninstall: 
280         ocamlfind remove bitstring
281
282 # Standard rules.
283
284 .mli.cmi:
285         $(OCAMLFIND) ocamlc $(OCAMLCFLAGS) $(OCAMLCPACKAGES) -c $<
286 .ml.cmo:
287         $(OCAMLFIND) ocamlc $(OCAMLCFLAGS) $(OCAMLCPACKAGES) -c $<
288 .ml.cmx:
289         $(OCAMLFIND) ocamlopt $(OCAMLOPTFLAGS) $(OCAMLOPTPACKAGES) -c $<
290
291 depend: .depend
292         @for d in $(SUBDIRS); do $(MAKE) -C $$d $@; done
293
294 .depend: bitstring.ml bitstring.mli \
295           bitstring_persistent.ml bitstring_persistent.mli \
296           bitstring_objinfo.ml \
297           create_test_pattern.ml
298         rm -f .depend
299         $(OCAMLFIND) ocamldep $(OCAMLCPACKAGES) \
300           bitstring.ml bitstring.mli \
301           bitstring_objinfo.ml >> $@
302         $(OCAMLFIND) ocamldep $(OCAMLCPACKAGES) -pp camlp4of \
303           bitstring_persistent.ml bitstring_persistent.mli \
304           create_test_pattern.ml >> $@
305
306 ifeq ($(wildcard .depend),.depend)
307 include .depend
308 endif
309
310 # Distribution.
311
312 dist:
313         $(MAKE) check-manifest
314         rm -rf $(PACKAGE)-$(VERSION)
315         mkdir $(PACKAGE)-$(VERSION)
316         tar -cf - -T MANIFEST | tar -C $(PACKAGE)-$(VERSION) -xf -
317         $(INSTALL) -m 0755 configure $(PACKAGE)-$(VERSION)/
318         $(INSTALL) -m 0644 config.h.in $(PACKAGE)-$(VERSION)/
319         svn log -v > $(PACKAGE)-$(VERSION)/CHANGES
320         tar zcf $(PACKAGE)-$(VERSION).tar.gz $(PACKAGE)-$(VERSION)
321         rm -rf $(PACKAGE)-$(VERSION)
322         ls -l $(PACKAGE)-$(VERSION).tar.gz
323
324 check-manifest:
325         svn -R list | grep -v '/$$' | sort > .check-manifest
326         sort MANIFEST > .orig-manifest; \
327         diff -u .orig-manifest .check-manifest; rv=$$?; \
328         rm -f .orig-manifest .check-manifest; \
329         exit $$rv
330
331 .PHONY: depend dist check-manifest dpkg doc \
332         print-examples print-tests examples test benchmarks
333
334 .SUFFIXES:      .cmo .cmi .cmx .ml .mli .mll