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