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