Add 'make valgrind' target to run tests under valgrind.
[libguestfs.git] / Makefile.am
1 # libguestfs
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 ACLOCAL_AMFLAGS = -I m4
19
20 SUBDIRS = src daemon fish examples images
21
22 if HAVE_OCAML
23 SUBDIRS += ocaml
24 endif
25 if HAVE_PERL
26 SUBDIRS += perl
27 endif
28 if HAVE_PYTHON
29 SUBDIRS += python
30 endif
31 if HAVE_RUBY
32 SUBDIRS += ruby
33 endif
34 if HAVE_JAVA
35 SUBDIRS += java
36 endif
37 if HAVE_INSPECTOR
38 SUBDIRS += inspector
39 endif
40
41 EXTRA_DIST = \
42         make-initramfs.sh update-initramfs.sh \
43         guestfs.pod guestfs-actions.pod guestfs-structs.pod \
44         guestfish.pod guestfish-actions.pod \
45         libguestfs.spec \
46         html/pod.css \
47         HACKING TODO \
48         tests.c \
49         libguestfs.pc libguestfs.pc.in \
50         gitlog-to-changelog \
51         recipes/LICENSE \
52         recipes/README \
53         recipes/*.html \
54         recipes/*.sh \
55         recipes/*.example \
56         html/recipes.css \
57         make-recipes.sh \
58         test-cleanup.sh
59
60 # Build the root filesystem.
61 # Currently this is arch-dependent, so it seems like putting it in
62 # $(libdir) is best.  When we build cross-architecture filesystems we
63 # should probably move them to $(datadir).
64
65 fsdir = $(libdir)/guestfs
66
67 INITRAMFSIMG = initramfs.$(REPO).$(host_cpu).img
68 VMLINUZ = vmlinuz.$(REPO).$(host_cpu)
69
70 fs_DATA =  $(INITRAMFSIMG) $(VMLINUZ)
71
72 $(INITRAMFSIMG) $(VMLINUZ): initramfs/fakeroot.log
73
74 initramfs/fakeroot.log: make-initramfs.sh.in
75         -mv $(INITRAMFSIMG) $(INITRAMFSIMG).bak
76         -mv $(VMLINUZ) $(VMLINUZ).bak
77         if ! bash $(top_builddir)/make-initramfs.sh; then rm -f $@; exit 1; fi
78
79 $(INITRAMFSIMG): initramfs/fakeroot.log daemon/guestfsd
80         rm -f $@
81         bash $(top_builddir)/update-initramfs.sh
82         touch $@
83
84 make-initramfs.sh: make-initramfs.sh.in
85         ./config.status $@
86
87 # Tests.  These are auto-generated from the test descriptions.
88
89 check_PROGRAMS = tests
90
91 tests_SOURCES = tests.c
92 tests_CFLAGS = \
93         -I$(top_builddir)/src -Wall
94 tests_LDADD = $(top_builddir)/src/libguestfs.la
95
96 TESTS = $(check_PROGRAMS)
97 TESTS_ENVIRONMENT = $(VG)
98
99 $(TESTS): $(INITRAMFS) $(VMLINUZ)
100
101 # Run the tests under valgrind.
102
103 valgrind:
104         $(MAKE) check VG="valgrind --quiet --leak-check=full"
105
106 # Manual pages.
107 # guestfs-actions.pod and guestfs-structs are autogenerated.  There is
108 # no include mechanism for POD, so we have to do it by hand.
109
110 man_MANS = guestfs.3 guestfish.1
111
112 guestfs.3: guestfs.pod guestfs-actions.pod guestfs-structs.pod
113         sed \
114           -e '/@ACTIONS@/rguestfs-actions.pod' -e 's/@ACTIONS@//' \
115           -e '/@STRUCTS@/rguestfs-structs.pod' -e 's/@STRUCTS@//' \
116           < $< | \
117         $(POD2MAN) \
118           --section 3 \
119           -c "Virtualization Support" \
120           --name "guestfs" \
121           --release "$(PACKAGE_NAME)-$(PACKAGE_VERSION)" \
122           > $@
123
124 guestfish.1: guestfish.pod guestfish-actions.pod
125         sed \
126           -e '/@ACTIONS@/rguestfish-actions.pod' -e 's/@ACTIONS@//' \
127           < $< | \
128         $(POD2MAN) \
129           --section 1 \
130           -c "Virtualization Support" \
131           --name "guestfish" \
132           --release "$(PACKAGE_NAME)-$(PACKAGE_VERSION)" \
133           > $@
134
135 noinst_DATA = html/guestfs.3.html html/guestfish.1.html
136
137 html/guestfs.3.html: guestfs.pod guestfs-actions.pod guestfs-structs.pod
138         sed \
139           -e '/@ACTIONS@/rguestfs-actions.pod' -e 's/@ACTIONS@//' \
140           -e '/@STRUCTS@/rguestfs-structs.pod' -e 's/@STRUCTS@//' \
141           < $< | \
142         pod2html \
143           --css 'pod.css' \
144           --title "libguestfs API documentation" \
145           --htmldir html \
146           --outfile $@
147
148 html/guestfish.1.html: guestfish.pod guestfish-actions.pod
149         sed \
150           -e '/@ACTIONS@/rguestfish-actions.pod' -e 's/@ACTIONS@//' \
151           < $< | \
152         pod2html \
153           --css 'pod.css' \
154           --title "guestfish, libguestfs filesystem interactive shell" \
155           --htmldir html \
156           --outfile $@
157
158 # Recipes web page.
159 html/recipes.html: $(wildcard recipes/*.sh) $(wildcard recipes/*.html) $(wildcard recipes/*.example) Makefile make-recipes.sh
160         rm -f $@ $@-t
161         sh make-recipes.sh recipes/*.sh > $@-t
162         mv $@-t $@
163
164 website: html/guestfs.3.html html/guestfish.1.html \
165         html/virt-inspector.1.html \
166         html/recipes.html
167         cp $^ html/pod.css html/recipes.css \
168           $(HOME)/d/redhat/et-website/libguestfs/
169
170 # Generate the ChangeLog automatically from the gitlog.
171
172 dist-hook:
173         ./gitlog-to-changelog > ChangeLog
174         cp ChangeLog $(distdir)/ChangeLog
175
176 # Pkgconfig.
177
178 pkgconfigdir = $(libdir)/pkgconfig
179 pkgconfig_DATA = libguestfs.pc
180
181 # Test-boot the image.
182
183 test-boot: emptydisk
184         qemu-system-$(host_cpu) \
185           -m 384 \
186           -kernel $(VMLINUZ) -initrd $(INITRAMFSIMG) \
187           -hda emptydisk
188
189 emptydisk:
190         rm -f emptydisk
191         dd if=/dev/zero of=emptydisk bs=1024 count=1440
192         echo 0, | sfdisk -q -C 80 -H 2 -S 18 emptydisk > /dev/null
193
194 # This is a more realistic test boot command line which better
195 # reflects what the library does.
196
197 test-boot-realistic: emptydisk
198         qemu-system-$(host_cpu) \
199           -m 384 \
200           -kernel $(VMLINUZ) -initrd $(INITRAMFSIMG) \
201           -hda emptydisk \
202           -append "console=ttyS0 guestfs=10.0.2.4:6666" \
203           -nographic \
204           -serial stdio \
205           -net channel,6666:unix:/tmp/sock,server,nowait \
206           -net user,vlan=0 \
207           -net nic,model=virtio,vlan=0
208
209 # Make clean.
210
211 CLEANFILES = $(fs_DATA) emptydisk pod2htm?.tmp
212
213 clean-local:
214         rm -rf initramfs