Make it possible to build in a separate directory
[libguestfs.git] / appliance / 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 EXTRA_DIST = \
19         make.sh update.sh supermin-split.sh supermin-make.sh \
20         libguestfs-supermin-helper \
21         kmod.whitelist \
22         kmod.whitelist.in \
23         packagelist.in \
24         init \
25         debian/modules/install_kernel \
26         debian/modules/y0_install-guestfsd \
27         debian/modules/z99_final-cleanups \
28         debian/debirf.conf.in
29
30 # Build the root filesystem (appliance).
31 # Currently this is arch-dependent, so it seems like putting it in
32 # $(libdir) is best.  When we build cross-architecture filesystems we
33 # should probably move them to $(datadir).
34 fsdir = $(libdir)/guestfs
35 fs_DATA = $(APPLIANCE_FILES)
36
37 # These are the resulting output files from the whole process:
38 #   VMLINUZ        kernel for the full appliance
39 #   INITRAMFSIMG   initramfs (ie. root fs) for the full appliance
40 # For details of the supermin appliance, read the README file:
41 #   SUPERMINIMG    initramfs (ie. partial root fs) for the supermin appliance
42 #   SUPERMINFILES  list of missing files (the ones we will pull out of the
43 #                    host filesystem at runtime) in the supermin appliance
44 APPLIANCE_FILES = $(INITRAMFSIMG) $(VMLINUZ)
45 if SUPERMIN
46 APPLIANCE_FILES += $(SUPERMINIMG) $(SUPERMINFILES) kmod.whitelist
47 bin_SCRIPTS = libguestfs-supermin-helper
48 endif
49
50 # Don't change these names - they must be the same as in '*.sh' scripts.
51 INITRAMFSIMG = initramfs.$(REPO).$(host_cpu).img
52 VMLINUZ = vmlinuz.$(REPO).$(host_cpu)
53 if SUPERMIN
54 SUPERMINIMG = initramfs.$(REPO).$(host_cpu).supermin.img
55 SUPERMINFILES = initramfs.$(REPO).$(host_cpu).supermin.hostfiles
56 endif
57
58 # This is for building the normal appliance:
59 $(INITRAMFSIMG) $(VMLINUZ): $(top_builddir)/initramfs/fakeroot.log
60
61 $(top_builddir)/initramfs/fakeroot.log: make.sh kmod.whitelist packagelist
62         -mv $(INITRAMFSIMG) $(INITRAMFSIMG).bak
63         -mv $(VMLINUZ) $(VMLINUZ).bak
64         if ! bash make.sh; then rm -f $@; exit 1; fi
65
66 $(INITRAMFSIMG): $(top_builddir)/initramfs/fakeroot.log $(top_builddir)/daemon/guestfsd init update.sh
67         rm -f $@
68         bash update.sh
69         touch $@
70
71 kmod.whitelist: kmod.whitelist.in
72         grep -v '^[[:space:]]*$$' < $< | grep -v '^#' > $@
73
74 packagelist: packagelist.in
75         cpp -undef -D$(DIST)=1 < $< | \
76         grep -v '^[[:space:]]*$$' | grep -v '^#' > $@
77
78 # This is for building the supermin appliance.  It has to be enabled
79 # specifically with './configure --enable-supermin'.  You really need
80 # to read the README file.
81
82 if SUPERMIN
83
84 # First we need to decide which files go in and out of the supermin
85 # appliance.  This decision is made by 'supermin-split.sh'.
86 $(SUPERMINFILES): supermin.incfiles
87 supermin.incfiles: $(top_builddir)/initramfs/fakeroot.log $(top_builddir)/daemon/guestfsd supermin-split.sh
88         rm -f supermin.incfiles $(SUPERMINFILES)
89         bash supermin-split.sh
90
91 # Second we need to create a supermin appliance with just the included
92 # files (leaving out the host files, which we'll add back at runtime).
93 $(SUPERMINIMG): supermin.incfiles supermin-make.sh
94         rm -f $@
95         bash supermin-make.sh
96
97 endif
98
99 # Extra symlinks needed by the Debian appliance.
100 debirf_symlinks = \
101         a0_prep-root \
102         z0_remove-aptitude \
103         z0_remove-locales \
104         z1_clean-root
105 noinst_DATA = $(debirf_symlinks:%=debian/modules/%)
106 $(debirf_symlinks:%=debian/modules/%): stamp-debirf-modules
107 stamp-debirf-modules:
108         mkdir -p debian/modules
109         for f in $(debirf_symlinks); do \
110           ln -sf /usr/share/debirf/modules/$$f debian/modules/$$f; \
111         done
112         touch $@
113
114 #----------------------------------------------------------------------
115 # Extra rules for testing the appliance.
116
117 # Test-boot the appliance.
118
119 test-boot: emptydisk
120         qemu-system-$(host_cpu) \
121           -m 384 \
122           -kernel $(VMLINUZ) -initrd $(INITRAMFSIMG) \
123           -hda emptydisk
124
125 emptydisk:
126         rm -f emptydisk
127         dd if=/dev/zero of=emptydisk bs=1024 count=1440
128         echo 0, | sfdisk -q -C 80 -H 2 -S 18 emptydisk > /dev/null
129
130 # This is a more realistic test boot command line which better
131 # reflects what the library does.
132
133 test-boot-realistic: emptydisk
134         qemu-system-$(host_cpu) \
135           -m 384 \
136           -kernel $(VMLINUZ) -initrd $(INITRAMFSIMG) \
137           -hda emptydisk \
138           -append "console=ttyS0 guestfs=10.0.2.4:6666 guestfs_rescue=1" \
139           -nographic \
140           -serial stdio \
141           -net channel,6666:unix:/tmp/sock,server,nowait \
142           -net user,vlan=0 \
143           -net nic,model=virtio,vlan=0
144
145 # Make clean.
146
147 CLEANFILES = $(APPLIANCE_FILES)
148
149 clean-local:
150         rm -rf $(top_builddir)/initramfs
151