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