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