generator: Add OCaml bindings.
[hivex.git] / ocaml / Makefile.am
1 # hivex OCaml bindings
2 # Copyright (C) 2009-2010 Red Hat Inc.
3 #
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 2 of the License, or
7 # (at your option) any later version.
8 #
9 # This program 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
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 EXTRA_DIST = \
19         .depend META.in \
20         hivex.mli hivex.ml \
21         hivex_c.c \
22         t/*.ml
23
24 CLEANFILES = *.cmi *.cmo *.cmx *.cma *.cmxa *.o *.a *.so
25 CLEANFILES += t/*.cmi t/*.cmo t/*.cmx t/*.o t/*.a t/*.so
26
27 AM_CPPFLAGS = \
28   -I$(top_builddir) -I$(OCAMLLIB) -I$(top_srcdir)/ocaml \
29   -I$(top_srcdir)/lib \
30   $(WARN_CFLAGS) $(WERROR_CFLAGS)
31
32 if HAVE_OCAML
33
34 noinst_DATA = mlhivex.cma mlhivex.cmxa META
35
36 OBJS = hivex_c.o hivex.cmo
37 XOBJS = $(OBJS:.cmo=.cmx)
38
39 mlhivex.cma: $(OBJS)
40         $(OCAMLMKLIB) -o mlhivex $^ -L$(top_builddir)/lib/.libs -lhivex
41
42 mlhivex.cmxa: $(XOBJS)
43         $(OCAMLMKLIB) -o mlhivex $^ -L$(top_builddir)/lib/.libs -lhivex
44
45 hivex_c.o: hivex_c.c
46         $(CC) $(AM_CPPFLAGS) $(CFLAGS) -fPIC -Wall -c $<
47
48 TESTS_ENVIRONMENT = \
49         LD_LIBRARY_PATH=$(top_builddir)/lib/.libs \
50         $(VG)
51
52 TESTS = \
53         t/hivex_005_load \
54         t/hivex_010_open \
55         t/hivex_020_root \
56         t/hivex_100_errors \
57         t/hivex_110_gc_handle \
58         t/hivex_200_write \
59         t/hivex_300_fold
60 noinst_DATA += $(TESTS)
61
62 t/hivex_005_load: t/hivex_005_load.cmx mlhivex.cmxa
63         mkdir -p t
64         $(OCAMLFIND) ocamlopt -cclib -L$(top_builddir)/lib/.libs -I . -package unix -linkpkg mlhivex.cmxa $< -o $@
65
66 t/hivex_010_open: t/hivex_010_open.cmx mlhivex.cmxa
67         mkdir -p t
68         $(OCAMLFIND) ocamlopt -cclib -L$(top_builddir)/lib/.libs -I . -package unix -linkpkg mlhivex.cmxa $< -o $@
69
70 t/hivex_020_root: t/hivex_020_root.cmx mlhivex.cmxa
71         mkdir -p t
72         $(OCAMLFIND) ocamlopt -cclib -L$(top_builddir)/lib/.libs -I . -package unix -linkpkg mlhivex.cmxa $< -o $@
73
74 t/hivex_100_errors: t/hivex_100_errors.cmx mlhivex.cmxa
75         mkdir -p t
76         $(OCAMLFIND) ocamlopt -cclib -L$(top_builddir)/lib/.libs -I . -package unix -linkpkg mlhivex.cmxa $< -o $@
77
78 t/hivex_110_gc_handle: t/hivex_110_gc_handle.cmx mlhivex.cmxa
79         mkdir -p t
80         $(OCAMLFIND) ocamlopt -cclib -L$(top_builddir)/lib/.libs -I . -package unix -linkpkg mlhivex.cmxa $< -o $@
81
82 t/hivex_200_write: t/hivex_200_write.cmx mlhivex.cmxa
83         mkdir -p t
84         $(OCAMLFIND) ocamlopt -cclib -L$(top_builddir)/lib/.libs -I . -package unix -linkpkg mlhivex.cmxa $< -o $@
85
86 t/hivex_300_fold: t/hivex_300_fold.cmx mlhivex.cmxa
87         mkdir -p t
88         $(OCAMLFIND) ocamlopt -cclib -L$(top_builddir)/lib/.libs -I . -package unix -linkpkg mlhivex.cmxa $< -o $@
89
90 # Need to rebuild the tests from source if the main library has
91 # changed at all, otherwise we get inconsistent assumptions.
92 t/%.cmx: t/%.ml mlhivex.cmxa
93         $(OCAMLFIND) ocamlopt -package unix -linkpkg -c $< -o $@
94
95 .mli.cmi:
96         $(OCAMLFIND) ocamlc -package unix -c $< -o $@
97 .ml.cmo:
98         $(OCAMLFIND) ocamlc -package unix -c $< -o $@
99 .ml.cmx:
100         $(OCAMLFIND) ocamlopt -package unix -c $< -o $@
101
102 depend: .depend
103
104 .depend: $(wildcard *.mli) $(wildcard *.ml)
105         rm -f $@ $@-t
106         $(OCAMLFIND) ocamldep $^ | sed 's/  *$$//' | sort > $@-t
107         mv $@-t $@
108
109 include .depend
110
111 SUFFIXES = .cmo .cmi .cmx .ml .mli .mll .mly
112
113 # Do the installation by hand, because we want to run ocamlfind.
114 install-data-hook:
115         mkdir -p $(DESTDIR)$(OCAMLLIB)
116         mkdir -p $(DESTDIR)$(OCAMLLIB)/stublibs
117         $(OCAMLFIND) install \
118           -ldconf ignore -destdir $(DESTDIR)$(OCAMLLIB) \
119           hivex \
120           META *.so *.a *.cma *.cmx *.cmxa *.cmi *.mli
121
122 CLEANFILES += $(noinst_DATA)
123
124 endif
125
126 # Tell version 3.79 and up of GNU make to not build goals in this
127 # directory in parallel.  (See RHBZ#502309).
128 .NOTPARALLEL: