808146d24064eab6fe34cfe1fc516cb145dc274c
[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
30 pkg_cil         = @pkg_cil@
31 pkg_extlib      = @pkg_extlib@
32
33 OCAMLCFLAGS     = -g
34 OCAMLCPACKAGES  =
35 OCAMLOPTFLAGS   =
36 OCAMLOPTPACKAGES =
37
38 OCAMLDOCFLAGS   = -html -sort
39
40 SUBDIRS         =
41 ifneq ($(pkg_cil),no)
42 ifneq ($(pkg_extlib),no)
43 SUBDIRS         += cil-tools
44 endif
45 endif
46
47 EXAMPLES        = $(patsubst %.ml,%,$(wildcard examples/*.ml))
48
49 TESTS           = $(patsubst %.ml,%,$(wildcard tests/*.ml))
50
51 BENCHMARKS      = $(patsubst %.ml,%,$(wildcard benchmarks/*.ml))
52
53 all:    bitstring.cma bitstring_persistent.cma \
54         bitstring.cmxa bitstring_persistent.cmxa \
55         pa_bitstring.cmo \
56         bitstring-objinfo
57         @for d in $(SUBDIRS); do $(MAKE) -C $$d $@; done
58
59 bitstring.cma: bitstring_types.cmo bitstring_config.cmo bitstring.cmo \
60           bitmatch.cmo
61         $(OCAMLFIND) ocamlc -a -o $@ $^
62
63 bitstring_persistent.cma: bitstring_persistent.cmo
64         $(OCAMLFIND) ocamlc -a -o $@ $^
65
66 bitstring_persistent.cmo: bitstring_persistent.ml
67         $(OCAMLFIND) ocamlc $(OCAMLCFLAGS) $(OCAMLCPACKAGES) \
68           -I +camlp4 -pp camlp4of -c $<
69
70 bitstring.cmxa: bitstring_types.cmx bitstring_config.cmx bitstring.cmx \
71           bitmatch.cmx
72         $(OCAMLFIND) ocamlopt -a -o $@ $^
73
74 bitstring_persistent.cmxa: bitstring_persistent.cmx
75         $(OCAMLFIND) ocamlopt -a -o $@ $^
76
77 bitstring_persistent.cmx: bitstring_persistent.ml
78         $(OCAMLFIND) ocamlopt $(OCAMLOPTFLAGS) $(OCAMLOPTPACKAGES) \
79           -I +camlp4 -pp camlp4of -c $<
80
81 bitstring_persistent.cmi: bitstring_persistent.mli
82         $(OCAMLFIND) ocamlc $(OCAMLCFLAGS) $(OCAMLCPACKAGES) \
83           -I +camlp4 -pp camlp4of -c $<
84
85 pa_bitstring.cmo: pa_bitstring.ml bitstring.cma bitstring_persistent.cma
86         $(OCAMLFIND) ocamlc bitstring.cma -I +camlp4 camlp4lib.cma \
87           -pp camlp4of -c $< -o $@
88
89 bitstring-objinfo: bitstring_objinfo.cmo bitstring.cma bitstring_persistent.cma
90         $(OCAMLFIND) ocamlc -I +camlp4 unix.cma camlp4lib.cma \
91           bitstring.cma bitstring_persistent.cma \
92           $< -o $@
93
94 # Tests and examples.
95
96 PP      = -pp "camlp4o bitstring.cma bitstring_persistent.cma pa_bitstring.cmo"
97
98 test: pa_bitstring.cmo bitstring.cma bitstring_persistent.cma tests/test.bmpp
99         @for f in $(TESTS); do \
100           echo Building $$f; \
101           $(OCAMLFIND) ocamlc $(OCAMLCFLAGS) $(PP) \
102             -package unix -linkpkg -I . bitstring.cma $$f.ml -o $$f; \
103           if [ $$? -ne 0 ]; then exit 1; fi; \
104           echo Running $$f; \
105           $$f; \
106           if [ $$? -ne 0 ]; then exit 1; fi; \
107         done
108         @for d in $(SUBDIRS); do $(MAKE) -C $$d $@; done
109
110 tests/test.bmpp: create_test_pattern
111         ./$< $@.new
112         mv $@.new $@
113
114 create_test_pattern: create_test_pattern.cmo
115         $(OCAMLFIND) ocamlc $(OCAMLCFLAGS) -pp camlp4of \
116           unix.cma -I +camlp4 camlp4lib.cma \
117           -I . bitstring.cma bitstring_persistent.cma $< -o $@
118
119 create_test_pattern.cmo: create_test_pattern.ml
120         $(OCAMLFIND) ocamlc $(OCAMLCFLAGS) -pp camlp4of \
121           unix.cma -I +camlp4 \
122           -I . -c $< -o $@
123
124 examples: pa_bitstring.cmo bitstring.cma bitstring_persistent.cma
125         @for f in $(EXAMPLES); do \
126           echo Building $$f; \
127           $(OCAMLFIND) ocamlc $(OCAMLCFLAGS) $(PP) \
128             -package unix -linkpkg -I . bitstring.cma $$f.ml -o $$f; \
129           if [ $$? -ne 0 ]; then exit 1; fi; \
130         done
131         @for d in $(SUBDIRS); do $(MAKE) -C $$d $@; done
132
133 print-tests: pa_bitstring.cmo bitstring_persistent.cma
134         @for f in $(TESTS); do \
135           echo Test: $$f.ml; \
136           cmd="camlp4o bitstring.cma bitstring_persistent.cma pa_bitstring.cmo \
137             -printer pr_o.cmo $$f.ml"; \
138           echo $$cmd; \
139           $$cmd; \
140         done
141
142 print-examples: pa_bitstring.cmo
143         @for f in $(EXAMPLES); do \
144           echo Example: $$f.ml; \
145           camlp4o bitstring.cma bitstring_persistent.cma pa_bitstring.cmo \
146             -printer pr_o.cmo $$f.ml; \
147           if [ $$? -ne 0 ]; then exit 1; fi; \
148         done
149
150 # Benchmarks.
151
152 ifneq ($(TIME),no)
153
154 benchmarks: pa_bitstring.cmo bitstring.cma bitstring_persistent.cma
155         @for f in $(BENCHMARKS); do \
156           $(OCAMLFIND) ocamlopt $(OCAMLOPTFLAGS) $(PP) \
157             -package unix -linkpkg -I . bitstring.cmxa $$f.ml -o $$f.opt; \
158           if [ $$? -ne 0 ]; then exit 1; fi; \
159           $(TIME) -f "$$f: %e seconds" $$f.opt; \
160           if [ $$? -ne 0 ]; then exit 1; fi; \
161         done
162 ifneq ($(GPROF),no)
163         @for f in $(BENCHMARKS); do \
164           $(OCAMLFIND) ocamlopt $(OCAMLOPTFLAGS) $(PP) -p \
165             -package unix -linkpkg -I . bitstring.cmxa $$f.ml -o $$f.opt.p; \
166           if [ $$? -ne 0 ]; then exit 1; fi; \
167           rm -f gmon.out; \
168           $$f.opt.p; \
169           if [ $$? -ne 0 ]; then exit 1; fi; \
170           gprof $$f.opt.p > $$f.profile; \
171           if [ $$? -ne 0 ]; then exit 1; fi; \
172           echo "Wrote profile of $$f"; \
173           echo "    to $$f.profile"; \
174           rm -f gmon.out; \
175         done
176 endif
177
178 endif
179
180 # Clean.
181
182 clean:
183         rm -f core *~ *.cmi *.cmo *.cmx *.cma *.cmxa *.a *.o
184         rm -f tests/*~ tests/*.cmi tests/*.cmo $(TESTS)
185         rm -f examples/*~ examples/*.cmi examples/*.cmo $(EXAMPLES)
186         rm -f benchmarks/*~ benchmarks/*.cmi benchmarks/*.cmo
187         rm -f benchmarks/*.opt benchmarks/*.opt.p benchmarks/*.profile
188         @for d in $(SUBDIRS); do $(MAKE) -C $$d $@; done
189
190 distclean: clean
191         rm -rf autom4te.cache
192         rm -f config.log config.status
193         rm -f config.h Makefile META bitstring_config.ml
194         rm -f bitstring-objinfo
195         @for d in $(SUBDIRS); do $(MAKE) -C $$d $@; done
196
197 # Documentation.
198
199 ifneq ($(OCAMLDOC),)
200 doc:
201         rm -rf html
202         mkdir html
203         $(OCAMLDOC) $(OCAMLDOCFLAGS) -d html -I +camlp4 \
204           bitstring.mli bitstring_persistent.mli bitmatch.ml
205 endif
206
207 # Install.
208
209 install:
210         ocamlfind install bitstring META *.mli *.cmx *.cma *.cmxa *.a \
211                 bitstring.cmi \
212                 bitstring_persistent.cmi \
213                 pa_bitstring.cmo
214         @for d in $(SUBDIRS); do $(MAKE) -C $$d $@; done
215
216 # Standard rules.
217
218 .mli.cmi:
219         $(OCAMLFIND) ocamlc $(OCAMLCFLAGS) $(OCAMLCPACKAGES) -c $<
220 .ml.cmo:
221         $(OCAMLFIND) ocamlc $(OCAMLCFLAGS) $(OCAMLCPACKAGES) -c $<
222 .ml.cmx:
223         $(OCAMLFIND) ocamlopt $(OCAMLOPTFLAGS) $(OCAMLOPTPACKAGES) -c $<
224
225 depend: .depend
226         @for d in $(SUBDIRS); do $(MAKE) -C $$d $@; done
227
228 .depend: bitstring.ml bitstring.mli \
229           bitstring_persistent.ml bitstring_persistent.mli \
230           bitstring_objinfo.ml \
231           create_test_pattern.ml
232         rm -f .depend
233         $(OCAMLFIND) ocamldep $(OCAMLCPACKAGES) \
234           bitstring.ml bitstring.mli \
235           bitstring_objinfo.ml >> $@
236         $(OCAMLFIND) ocamldep $(OCAMLCPACKAGES) -pp camlp4of \
237           bitstring_persistent.ml bitstring_persistent.mli \
238           create_test_pattern.ml >> $@
239
240 ifeq ($(wildcard .depend),.depend)
241 include .depend
242 endif
243
244 # Distribution.
245
246 dist:
247         $(MAKE) check-manifest
248         rm -rf $(PACKAGE)-$(VERSION)
249         mkdir $(PACKAGE)-$(VERSION)
250         tar -cf - -T MANIFEST | tar -C $(PACKAGE)-$(VERSION) -xf -
251         $(INSTALL) -m 0755 configure $(PACKAGE)-$(VERSION)/
252         $(INSTALL) -m 0644 config.h.in $(PACKAGE)-$(VERSION)/
253         svn log -v > $(PACKAGE)-$(VERSION)/CHANGES
254         tar zcf $(PACKAGE)-$(VERSION).tar.gz $(PACKAGE)-$(VERSION)
255         rm -rf $(PACKAGE)-$(VERSION)
256         ls -l $(PACKAGE)-$(VERSION).tar.gz
257
258 check-manifest:
259         svn -R list | grep -v '/$$' | sort > .check-manifest
260         sort MANIFEST > .orig-manifest; \
261         diff -u .orig-manifest .check-manifest; rv=$$?; \
262         rm -f .orig-manifest .check-manifest; \
263         exit $$rv
264
265 .PHONY: depend dist check-manifest dpkg doc \
266         print-examples print-tests examples test benchmarks
267
268 .SUFFIXES:      .cmo .cmi .cmx .ml .mli .mll