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