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