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