528703549aea4f25fcba8ae34fdccaec7f8bf449
[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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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         .depend \
29         guestfs_c.c guestfs_c.h \
30         html/.gitignore \
31         META.in \
32         run-bindtests \
33         t/*.ml
34
35 CLEANFILES = *.cmi *.cmo *.cmx *.cma *.cmxa *.o *.a *.so
36 CLEANFILES += t/*.cmi t/*.cmo t/*.cmx t/*.o t/*.a t/*.so
37
38 AM_CPPFLAGS = -I$(top_builddir) -I$(OCAMLLIB) -I$(top_srcdir)/ocaml \
39   -I$(top_srcdir)/src -I$(top_builddir)/src \
40   $(WARN_CFLAGS) $(WERROR_CFLAGS)
41
42 if HAVE_OCAML
43
44 OCAMLCFLAGS = -g -warn-error CDEFLMPSUVYZX
45 OCAMLOPTFLAGS = $(OCAMLCFLAGS)
46
47 noinst_DATA = mlguestfs.cma mlguestfs.cmxa META
48
49 OBJS = guestfs_c.o guestfs_c_actions.o guestfs.cmo
50 XOBJS = $(OBJS:.cmo=.cmx)
51
52 mlguestfs.cma: $(OBJS)
53         $(OCAMLMKLIB) -o mlguestfs $^ -L$(top_builddir)/src/.libs -lguestfs
54
55 mlguestfs.cmxa: $(XOBJS)
56         $(OCAMLMKLIB) -o mlguestfs $^ -L$(top_builddir)/src/.libs -lguestfs
57
58 guestfs_c.o: guestfs_c.c
59         $(CC) $(AM_CPPFLAGS) $(CFLAGS) -fPIC -Wall -c $<
60
61 guestfs_c_actions.o: guestfs_c_actions.c
62         $(CC) $(AM_CPPFLAGS) $(CFLAGS) -fPIC -Wall -c $(srcdir)/$<
63
64 if HAVE_OCAMLDOC
65
66 noinst_DATA += html/index.html
67
68 html/index.html: $(srcdir)/guestfs*.mli $(srcdir)/guestfs*.ml
69         mkdir -p html
70         -$(OCAMLDOC) -d html -html $^
71 endif
72
73 TESTS_ENVIRONMENT = \
74         LD_LIBRARY_PATH=$(top_builddir)/src/.libs \
75         LIBGUESTFS_PATH=$(top_builddir)/appliance \
76         TMPDIR=$(top_builddir) \
77         $(VG)
78
79 TESTS = run-bindtests \
80         t/guestfs_005_load \
81         t/guestfs_010_basic \
82         t/guestfs_070_threads \
83         t/guestfs_080_optargs \
84         t/guestfs_400_events \
85         t/guestfs_400_progress
86 noinst_DATA += bindtests \
87         t/guestfs_005_load \
88         t/guestfs_010_basic \
89         t/guestfs_070_threads \
90         t/guestfs_080_optargs \
91         t/guestfs_400_events \
92         t/guestfs_400_progress
93
94 bindtests: bindtests.cmx mlguestfs.cmxa
95         mkdir -p t
96         $(OCAMLFIND) ocamlopt $(OCAMLOPTFLAGS) -cclib -L$(top_builddir)/src/.libs -I . -package unix -linkpkg mlguestfs.cmxa $< -o $@
97
98 t/guestfs_005_load: t/guestfs_005_load.cmx mlguestfs.cmxa
99         mkdir -p t
100         $(OCAMLFIND) ocamlopt $(OCAMLOPTFLAGS) -cclib -L$(top_builddir)/src/.libs -I . -package unix -linkpkg mlguestfs.cmxa $< -o $@
101
102 t/guestfs_010_basic: t/guestfs_010_basic.cmx mlguestfs.cmxa
103         mkdir -p t
104         $(OCAMLFIND) ocamlopt $(OCAMLOPTFLAGS) -cclib -L$(top_builddir)/src/.libs -I . -package unix -linkpkg mlguestfs.cmxa $< -o $@
105
106 t/guestfs_070_threads: t/guestfs_070_threads.cmx mlguestfs.cmxa
107         mkdir -p t
108         $(OCAMLFIND) ocamlopt $(OCAMLOPTFLAGS) -cclib -L$(top_builddir)/src/.libs -I . -package unix,threads -thread -linkpkg mlguestfs.cmxa $< -o $@
109
110 t/guestfs_080_optargs: t/guestfs_080_optargs.cmx mlguestfs.cmxa
111         mkdir -p t
112         $(OCAMLFIND) ocamlopt $(OCAMLOPTFLAGS) -cclib -L$(top_builddir)/src/.libs -I . -package unix -linkpkg mlguestfs.cmxa $< -o $@
113
114 t/guestfs_400_events: t/guestfs_400_events.cmx mlguestfs.cmxa
115         mkdir -p t
116         $(OCAMLFIND) ocamlopt $(OCAMLOPTFLAGS) -cclib -L$(top_builddir)/src/.libs -I . -package unix -linkpkg mlguestfs.cmxa $< -o $@
117
118 t/guestfs_400_progress: t/guestfs_400_progress.cmx mlguestfs.cmxa
119         mkdir -p t
120         $(OCAMLFIND) ocamlopt $(OCAMLOPTFLAGS) -cclib -L$(top_builddir)/src/.libs -I . -package unix -linkpkg mlguestfs.cmxa $< -o $@
121
122 # Need to rebuild the tests from source if the main library has
123 # changed at all, otherwise we get inconsistent assumptions.
124 t/guestfs_070_threads.cmx: t/guestfs_070_threads.ml mlguestfs.cmxa
125         $(OCAMLFIND) ocamlopt $(OCAMLOPTFLAGS) -package unix,threads -thread -linkpkg -c $< -o $@
126
127 t/%.cmx: t/%.ml mlguestfs.cmxa
128         $(OCAMLFIND) ocamlopt $(OCAMLOPTFLAGS) -package unix -linkpkg -c $< -o $(builddir)/$@
129
130 %.cmi: %.mli
131         $(OCAMLFIND) ocamlc $(OCAMLCFLAGS) -package unix -c $< -o $(builddir)/$@
132 %.cmo: %.ml
133         $(OCAMLFIND) ocamlc $(OCAMLCFLAGS) -package unix -c $< -o $(builddir)/$@
134 %.cmx: %.ml
135         $(OCAMLFIND) ocamlopt $(OCAMLOPTFLAGS) -package unix -c $< -o $(builddir)/$@
136
137 depend: .depend
138
139 .depend: $(wildcard *.mli) $(wildcard *.ml)
140         rm -f $@ $@-t
141         $(OCAMLFIND) ocamldep $^ | \
142           $(SED) 's/ *$$//' | \
143           $(SED) -e :a -e '/ *\\$$/N; s/ *\\\n */ /; ta' | \
144           sort > $@-t
145         mv $@-t $@
146
147 include .depend
148
149 SUFFIXES = .cmo .cmi .cmx .ml .mli .mll .mly
150
151 # Do the installation by hand, because we want to run ocamlfind.
152 install-data-hook:
153         mkdir -p $(DESTDIR)$(OCAMLLIB)
154         mkdir -p $(DESTDIR)$(OCAMLLIB)/stublibs
155         $(OCAMLFIND) install \
156           -ldconf ignore -destdir $(DESTDIR)$(OCAMLLIB) \
157           guestfs \
158           META *.so *.a *.cma *.cmx *.cmxa *.cmi $(srcdir)/*.mli
159
160 CLEANFILES += $(noinst_DATA)
161
162 endif
163
164 # Tell version 3.79 and up of GNU make to not build goals in this
165 # directory in parallel.  (Possible solution for RHBZ#502309).
166 .NOTPARALLEL: