build: Fix inter-directory dependencies
[libguestfs.git] / ocaml / Makefile.am
1 # libguestfs OCaml bindings
2 # Copyright (C) 2009 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 include $(top_srcdir)/subdir-rules.mk
19
20 generator_built = \
21         guestfs.mli \
22         guestfs.ml \
23         guestfs_c_actions.c \
24         bindtests.ml
25
26 EXTRA_DIST = \
27         $(generator_built) \
28         guestfs_c.c guestfs_c.h \
29         guestfs_inspector.mli guestfs_inspector.ml \
30         .depend META.in \
31         run-bindtests \
32         t/*.ml
33
34 CLEANFILES = *.cmi *.cmo *.cmx *.cma *.cmxa *.o *.a *.so
35 CLEANFILES += t/*.cmi t/*.cmo t/*.cmx t/*.o t/*.a t/*.so
36
37 AM_CPPFLAGS = -I$(top_builddir) -I$(OCAMLLIB) -I$(top_srcdir)/ocaml \
38   -I$(top_srcdir)/src -I$(top_builddir)/src \
39   $(WARN_CFLAGS) $(WERROR_CFLAGS)
40
41 if HAVE_OCAML
42 if HAVE_XML_LIGHT
43
44 noinst_DATA = mlguestfs.cma mlguestfs.cmxa META
45
46 OBJS = guestfs_c.o guestfs_c_actions.o guestfs.cmo guestfs_inspector.cmo
47 XOBJS = $(OBJS:.cmo=.cmx)
48
49 mlguestfs.cma: $(OBJS)
50         $(OCAMLMKLIB) -o mlguestfs $^ -L$(top_builddir)/src/.libs -lguestfs
51
52 mlguestfs.cmxa: $(XOBJS)
53         $(OCAMLMKLIB) -o mlguestfs $^ -L$(top_builddir)/src/.libs -lguestfs
54
55 guestfs_c.o: guestfs_c.c
56         $(CC) $(AM_CPPFLAGS) $(CFLAGS) -fPIC -Wall -c $<
57
58 guestfs_c_actions.o: guestfs_c_actions.c
59         $(CC) $(AM_CPPFLAGS) $(CFLAGS) -fPIC -Wall -c $<
60
61 TESTS_ENVIRONMENT = \
62         LD_LIBRARY_PATH=$(top_builddir)/src/.libs \
63         LIBGUESTFS_PATH=$(top_builddir)/appliance \
64         $(VG)
65
66 TESTS = run-bindtests \
67         t/guestfs_005_load t/guestfs_010_launch t/guestfs_050_lvcreate \
68         t/guestfs_060_readdir t/guestfs_500_inspect
69 noinst_DATA += bindtests \
70         t/guestfs_005_load t/guestfs_010_launch t/guestfs_050_lvcreate \
71         t/guestfs_060_readdir t/guestfs_500_inspect
72
73 bindtests: bindtests.cmx mlguestfs.cmxa
74         mkdir -p t
75         $(OCAMLFIND) ocamlopt -cclib -L$(top_builddir)/src/.libs -I . -package xml-light,unix -linkpkg mlguestfs.cmxa $< -o $@
76
77 t/guestfs_005_load: t/guestfs_005_load.cmx mlguestfs.cmxa
78         mkdir -p t
79         $(OCAMLFIND) ocamlopt -cclib -L$(top_builddir)/src/.libs -I . -package xml-light,unix -linkpkg mlguestfs.cmxa $< -o $@
80
81 t/guestfs_010_launch: t/guestfs_010_launch.cmx mlguestfs.cmxa
82         mkdir -p t
83         $(OCAMLFIND) ocamlopt -cclib -L$(top_builddir)/src/.libs -I . -package xml-light,unix -linkpkg mlguestfs.cmxa $< -o $@
84
85 t/guestfs_050_lvcreate: t/guestfs_050_lvcreate.cmx mlguestfs.cmxa
86         mkdir -p t
87         $(OCAMLFIND) ocamlopt -cclib -L$(top_builddir)/src/.libs -I . -package xml-light,unix -linkpkg mlguestfs.cmxa $< -o $@
88
89 t/guestfs_060_readdir: t/guestfs_060_readdir.cmx mlguestfs.cmxa
90         mkdir -p t
91         $(OCAMLFIND) ocamlopt -cclib -L$(top_builddir)/src/.libs -I . -package xml-light,unix -linkpkg mlguestfs.cmxa $< -o $@
92
93 t/guestfs_500_inspect: t/guestfs_500_inspect.cmx mlguestfs.cmxa
94         mkdir -p t
95         $(OCAMLFIND) ocamlopt -cclib -L$(top_builddir)/src/.libs -I . -package xml-light,unix -linkpkg mlguestfs.cmxa $< -o $@
96
97 # Need to rebuild the tests from source if the main library has
98 # changed at all, otherwise we get inconsistent assumptions.
99 t/%.cmx: t/%.ml mlguestfs.cmxa
100         $(OCAMLFIND) ocamlopt -package xml-light,unix -linkpkg -c $< -o $@
101
102 .mli.cmi:
103         $(OCAMLFIND) ocamlc -package xml-light,unix -c $< -o $@
104 .ml.cmo:
105         $(OCAMLFIND) ocamlc -package xml-light,unix -c $< -o $@
106 .ml.cmx:
107         $(OCAMLFIND) ocamlopt -package xml-light,unix -c $< -o $@
108
109 depend: .depend
110
111 .depend: $(wildcard *.mli) $(wildcard *.ml)
112         rm -f $@ $@-t
113         $(OCAMLFIND) ocamldep $^ | sed 's/  *$$//' | sort > $@-t
114         mv $@-t $@
115
116 include .depend
117
118 SUFFIXES = .cmo .cmi .cmx .ml .mli .mll .mly
119
120 # Do the installation by hand, because we want to run ocamlfind.
121 install-data-hook:
122         mkdir -p $(DESTDIR)$(OCAMLLIB)
123         mkdir -p $(DESTDIR)$(OCAMLLIB)/stublibs
124         $(OCAMLFIND) install \
125           -ldconf ignore -destdir $(DESTDIR)$(OCAMLLIB) \
126           guestfs \
127           META *.so *.a *.cma *.cmx *.cmxa *.cmi *.mli
128
129 CLEANFILES += $(noinst_DATA)
130
131 endif
132 endif
133
134 # Tell version 3.79 and up of GNU make to not build goals in this
135 # directory in parallel.  (Possible solution for RHBZ#502309).
136 .NOTPARALLEL: