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