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