appliance: Set $PATH instead of hard-coding paths to binaries everywhere.
[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 include $(top_srcdir)/subdir-rules.mk
19
20 EXTRA_DIST = \
21         kmod.whitelist.in \
22         packagelist.in \
23         init \
24         debian/modules/install_kernel \
25         debian/modules/y0_install-guestfsd \
26         debian/modules/z99_final-cleanups \
27         debian/debirf.conf.in \
28         make.sh.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_PROGRAMS = libguestfs-supermin-helper
48 libguestfs_supermin_helper_SOURCES = \
49         libguestfs-supermin-helper.c ../gnulib/lib/xalloc-die.c
50 libguestfs_supermin_helper_CFLAGS = \
51         -I$(srcdir)/../gnulib/lib -I../gnulib/lib \
52         $(WARN_CFLAGS) $(WERROR_CFLAGS)
53 libguestfs_supermin_helper_LDADD = \
54         ../gnulib/lib/libgnu.la
55 endif
56
57 # Don't change these names - they must be the same as in '*.sh' scripts.
58 INITRAMFSIMG = initramfs.$(REPO).$(host_cpu).img
59 VMLINUZ = vmlinuz.$(REPO).$(host_cpu)
60 if SUPERMIN
61 SUPERMINIMG = initramfs.$(REPO).$(host_cpu).supermin.img
62 SUPERMINFILES = initramfs.$(REPO).$(host_cpu).supermin.hostfiles
63 endif
64
65 # This is for building the normal appliance:
66 $(INITRAMFSIMG) $(VMLINUZ): $(top_builddir)/initramfs/fakeroot.log
67
68 $(top_builddir)/initramfs/fakeroot.log: make.sh kmod.whitelist packagelist $(top_builddir)/daemon/guestfsd
69         mv $(INITRAMFSIMG) $(INITRAMFSIMG).bak 2>/dev/null; :
70         mv $(VMLINUZ) $(VMLINUZ).bak 2>/dev/null; :
71         if ! bash make.sh; then rm -f $@; exit 1; fi
72
73 # This used to be a configure-generated file (as is update.sh still).
74 # However config.status always touches the destination file, which
75 # means the appliance got rebuilt too often.
76 make.sh: make.sh.in
77         cd $(top_builddir) && \
78           ./config.status --file=appliance/$@-t:appliance/$<
79         chmod +x $@-t
80         mv $@-t $@
81
82 $(INITRAMFSIMG): $(top_builddir)/initramfs/fakeroot.log $(top_builddir)/daemon/guestfsd init update.sh
83         rm -f $@
84         bash update.sh
85         touch $@
86
87 kmod.whitelist: kmod.whitelist.in
88         grep -v '^[[:space:]]*$$' < $< | grep -v '^#' > $@
89
90 packagelist: packagelist.in
91         cpp -undef -D$(DIST)=1 < $< | \
92         grep -v '^[[:space:]]*$$' | grep -v '^#' > $@
93
94 # This is for building the supermin appliance.  It has to be enabled
95 # specifically with './configure --enable-supermin'.  You really need
96 # to read the README file.
97
98 if SUPERMIN
99
100 # First we need to decide which files go in and out of the supermin
101 # appliance.  This decision is made by 'supermin-split.sh'.
102 $(SUPERMINFILES): supermin.incfiles
103 supermin.incfiles: $(top_builddir)/initramfs/fakeroot.log $(top_builddir)/daemon/guestfsd supermin-split.sh
104         rm -f supermin.incfiles $(SUPERMINFILES)
105         bash supermin-split.sh
106
107 # Second we need to create a supermin appliance with just the included
108 # files (leaving out the host files, which we'll add back at runtime).
109 $(SUPERMINIMG): supermin.incfiles supermin-make.sh
110         rm -f $@
111         bash supermin-make.sh
112
113 endif
114
115 # Extra symlinks needed by the Debian appliance.
116 debirf_symlinks = \
117         a0_prep-root \
118         z0_remove-aptitude \
119         z0_remove-locales \
120         z1_clean-root
121 noinst_DATA = $(debirf_symlinks:%=debian/modules/%)
122 $(debirf_symlinks:%=debian/modules/%): stamp-debirf-modules
123 stamp-debirf-modules:
124         mkdir -p debian/modules
125         for f in $(debirf_symlinks); do \
126           ln -sf /usr/share/debirf/modules/$$f debian/modules/$$f; \
127         done
128         touch $@
129
130 #----------------------------------------------------------------------
131 # Extra rules for testing the appliance.
132
133 # Test-boot the appliance.
134
135 test-boot: emptydisk
136         qemu-system-$(host_cpu) \
137           -m 384 \
138           -kernel $(VMLINUZ) -initrd $(INITRAMFSIMG) \
139           -hda emptydisk
140
141 emptydisk:
142         rm -f emptydisk
143         dd if=/dev/zero of=emptydisk bs=1024 count=1440
144         echo 0, | sfdisk -q -C 80 -H 2 -S 18 emptydisk > /dev/null
145
146 # This is a more realistic test boot command line which better
147 # reflects what the library does.
148
149 test-boot-realistic: emptydisk
150         qemu-system-$(host_cpu) \
151           -m 384 \
152           -kernel $(VMLINUZ) -initrd $(INITRAMFSIMG) \
153           -hda emptydisk \
154           -append "console=ttyS0 guestfs=10.0.2.4:6666 guestfs_rescue=1" \
155           -nographic \
156           -serial stdio \
157           -net channel,6666:unix:/tmp/sock,server,nowait \
158           -net user,vlan=0 \
159           -net nic,model=virtio,vlan=0
160
161 # Make clean.
162
163 CLEANFILES = $(APPLIANCE_FILES) packagelist kmod.whitelist supermin.incfiles
164
165 clean-local:
166         rm -rf $(top_builddir)/initramfs