Fix rebuild of virt-p2v script, because default perms are 0555.
[virt-p2v.git] / Makefile.in
1 # Makefile for virt-p2v
2 # @configure_input@
3 #
4 # Copyright (C) 2007-2008 Red Hat Inc.
5 # Written by Richard W.M. Jones <rjones@redhat.com>
6 #
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
11 #
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20
21 #----------------------------------------------------------------------
22 # General configuration
23
24 PACKAGE         := @PACKAGE_NAME@
25 VERSION         := @PACKAGE_VERSION@
26
27 INSTALL         := @INSTALL@
28
29 HAVE_PERLDOC    := @HAVE_PERLDOC@
30 HAVE_QEMU       := @HAVE_QEMU@
31 HAVE_QEMU_KVM   := @HAVE_QEMU_KVM@
32 HAVE_LIVECD_CREATOR := @HAVE_LIVECD_CREATOR@
33 HAVE_LIVECD_ISO_TO_PXEBOOT := @HAVE_LIVECD_ISO_TO_PXEBOOT@
34
35 LABEL           := $(PACKAGE)-$(VERSION)
36 ISO             := $(LABEL).iso
37 PXE_TAR         := $(PACKAGE)-$(VERSION)-pxeboot.tar
38 VIRTP2V_RPM     := $(PACKAGE)-$(VERSION)-1.noarch.rpm
39
40 #----------------------------------------------------------------------
41
42 all:
43         @echo "make rpm       Build the virt-p2v RPM"
44         @echo "make build     Build the live CD ISO"
45         @echo "make boot [HDA=hda.img] [HDB=hdb.img] [ISO=livecd.iso]"
46         @echo "                 Boot built/named ISO (uses qemu)"
47         @echo "make update    Update an existing live CD ISO with new"
48         @echo "                 virt-p2v script, without doing full rebuild"
49         @echo "make pxe       Build a PXE image (in tftpboot/ subdirectory)"
50         @echo "make man       Make man pages (needs POD)"
51
52 # Build live CD.
53
54 ifeq ($(HAVE_LIVECD_CREATOR),livecd-creator)
55
56 build:  checkroot checkrpm checkscript
57         rm -f $(ISO)
58         livecd-creator --config=p2v.ks --fslabel=$(LABEL)
59         ls -lhtr *.iso
60
61 endif
62
63 # Build RPM of virt-p2v.
64
65 rpm:    checknotroot p2vrepo/$(VIRTP2V_RPM)
66
67 RPM_FLAGS := --define "_topdir       %(pwd)/rpmbuild" \
68              --define "_builddir     %{_topdir}/BUILD" \
69              --define "_rpmdir       %{_topdir}/RPMS" \
70              --define "_srcrpmdir    %{_topdir}/SRPMS" \
71              --define "_specdir      %{_topdir}/SPECS" \
72              --define "_sourcedir    %(pwd)"
73
74 p2vrepo/$(VIRTP2V_RPM): \
75                 virt-p2v.spec \
76                 virt-p2v virt-p2v-update-wrapper iso-attach \
77                 inittab
78         $(MAKE) dist
79         rm -rf rpmbuild
80         mkdir rpmbuild rpmbuild/{RPMS,BUILD,SRPMS,SPECS} rpmbuild/RPMS/noarch
81         rpmbuild $(RPM_FLAGS) -ba $<
82         mkdir -p p2vrepo
83         cp rpmbuild/RPMS/noarch/$(VIRTP2V_RPM) p2vrepo
84         createrepo p2vrepo
85
86 # Make the final script.
87
88 virt-p2v: virt-p2v.ml0 virt-p2v.ml
89         rm -f $@
90         cat $^ > $@
91         chmod 0555 $@
92
93 # Run live CD under qemu.
94
95 ifeq ($(HAVE_QEMU_KVM),qemu-kvm)
96 QEMU    := qemu-kvm
97 else
98 ifeq ($(HAVE_QEMU),qemu)
99 QEMU    := qemu
100 endif
101 endif
102
103 ifneq ($(QEMU),)
104 HDA     :=
105 HDB     :=
106
107 QEMU_ARGS := -m 512 -cdrom $(ISO) -boot d
108 ifneq ($(HDA),)
109 QEMU_ARGS += -hda $(HDA)
110 endif
111 ifneq ($(HDB),)
112 QEMU_ARGS += -hdb $(HDB)
113 endif
114
115 boot:
116         $(QEMU) $(QEMU_ARGS)
117 endif
118
119 # Update an existing ISO.
120
121 update: checkroot checkscript
122         -./iso-attach delete $(ISO) 2>/dev/null
123         ./iso-attach add $(ISO) virt-p2v
124
125 # PXE boot.
126
127 ifeq ($(HAVE_LIVECD_ISO_TO_PXEBOOT),livecd-iso-to-pxeboot)
128
129 pxe: checkroot checkscript
130         livecd-iso-to-pxeboot $(ISO)
131
132 endif
133
134 # Check that we are root.
135
136 checkroot:
137         @if [ `id -u` -ne 0 ]; then \
138           echo "You must be root to perform this operation."; \
139           exit 1; \
140         fi
141
142 # Check that we are not root.
143
144 checknotroot:
145         @if [ `id -u` -eq 0 ]; then \
146           echo "You must not perform this step as root."; \
147           exit 1; \
148         fi
149
150 # Check that the script compiles.
151
152 checkscript:
153         test -x virt-p2v
154         ./virt-p2v --test
155
156 # Check that the RPM has been built.
157
158 checkrpm:
159         test -f p2vrepo/$(VIRTP2V_RPM)
160
161 # Clean.
162
163 clean:
164         rm -f *~ core virt-p2v pod2htm*
165
166 distclean: clean
167         rm -rf autom4te.cache config.log config.status configure \
168           p2v.ks Makefile po/Makefile virt-p2v.spec
169
170 reallyreallyclean: distclean
171         rm -f virt-p2v-*.tar.gz virt-p2v-*.iso
172
173 # Manifest.
174
175 dist:
176         $(MAKE) check-manifest
177         rm -rf $(PACKAGE)-$(VERSION)
178         mkdir $(PACKAGE)-$(VERSION)
179         tar -cf - -T MANIFEST | tar -C $(PACKAGE)-$(VERSION) -xf -
180         $(INSTALL) -m 0755 configure $(PACKAGE)-$(VERSION)/
181         tar zcf $(PACKAGE)-$(VERSION).tar.gz $(PACKAGE)-$(VERSION)
182         rm -rf $(PACKAGE)-$(VERSION)
183         ls -l $(PACKAGE)-$(VERSION).tar.gz
184
185 check-manifest:
186         @hg manifest | sort > .check-manifest; \
187         sort MANIFEST > .orig-manifest; \
188         diff -u .orig-manifest .check-manifest; rv=$$?; \
189         rm -f .orig-manifest .check-manifest; \
190         exit $$rv
191
192 # Manual page.
193
194 ifeq ($(HAVE_PERLDOC),perldoc)
195
196 MAN_SECTION := Virtualization Support
197
198 man: virt-p2v.1 virt-p2v.1.txt virt-p2v.1.html
199
200 virt-p2v.1: virt-p2v.pod
201         pod2man -c "$(MAN_SECTION)" --release "$(PACKAGE)-$(VERSION)" $< > $@
202
203 virt-p2v.1.txt: virt-p2v.pod
204         pod2text $< > $@
205
206 virt-p2v.1.html: virt-p2v.pod
207         pod2html -css virt-p2v.1.css $< > $@
208
209 endif
210
211 # Website.
212
213 WEBSITE_DIR := ../redhat/et-website/virt-p2v
214
215 website: man dist
216         cp virt-p2v.1.html $(WEBSITE_DIR)
217         cp virt-p2v.1.css $(WEBSITE_DIR)
218         cp $(PACKAGE)-$(VERSION).tar.gz $(WEBSITE_DIR)
219
220 # Upload everything.
221
222 upload: upload_iso upload_pxe
223
224 # Upload ISO.
225
226 upload_iso:
227         scp -l 300 $(ISO) et.redhat.com:public_html/tmp/
228
229 # Upload PXE image.
230
231 upload_pxe:
232         tar cf $(PXE_TAR) tftpboot
233         scp -l 300 $(PXE_TAR) et.redhat.com:public_html/tmp/
234 #       rm $(PXE_TAR)
235
236 .PHONY: build boot checkroot