Summary: Kernel-based Virtual Machine
Summary(ja): カーネルベースの仮想マシン
Name: kvm
Version: 83
Release: 1%{?_dist_release}
License: GPLv2+ and LGPLv2+
Group: Development/Tools
URL: http://kvm.qumranet.com/kvmwiki
Source0: %{name}-%{version}.tar.gz
Source1: %{name}.modules
Patch2: %{name}-62-block-rw-range-check.patch
# patches from upstream qemu

BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
BuildRequires: SDL-devel
# to build the bios
BuildRequires: dev86
BuildRequires: iasl
BuildRequires: %{_includedir}/gnu/stubs-32.h
BuildRequires: zlib-devel
# TLS / x509 auth in VNC server
BuildRequires: gnutls-devel
# for the docs
BuildRequires: texi2html
BuildRequires: rsync
# kvm kernel side is only x86/x86_64 as that's where the hardware is
ExclusiveArch: %{ix86} x86_64

%description
KVM (for Kernel-based Virtual Machine) is a full virtualization solution
for Linux on x86 hardware.

Using KVM, one can run multiple virtual machines running unmodified Linux
or Windows images. Each virtual machine has private virtualized hardware:
a network card, disk, graphics adapter, etc.

%prep
%setup -q
%patch2 -p1

# "configure --kerneldir" looks for this
# FIXME: kvm-84 or later shouldn't need this anymore, see:
# http://git.kernel.org/?p=linux/kernel/git/marcelo/kvm-userspace.git;a=commit;h=4f45aa2db
echo "%{name}-%{version}" > $(pwd)/kernel/.kernelrelease

# we must not use any of the binaries from the qemu/pc-bios/ directory,
# as they don't have the corresponding sources shipped with them
rm -f qemu/pc-bios/*.{bin,x,dtb} qemu/pc-bios/openbios-*
find qemu/pc-bios -exec file {} \; | grep '\(data\|BIOS\|executable\)' && \
    echo "Found some binary blobs in qemu/pc-bios!" && exit 1

%build
# systems like rhel build system does not have a recent enough linker so 
# --build-id works. this option is used fedora 8 onwards for giving info
# to the debug packages.

build_id_available() {
	echo "int main () { return 0; }" | gcc -x c -Wl,--build-id - 2>/dev/null
}

if build_id_available; then
	qemuldflags="-Wl,--build-id";
else
	qemuldflags="";
fi


# we need to install the data bits in a different path
sed -i 's/datasuffix=\"\/share\/qemu\"/datasuffix=\"\/share\/kvm\"/' qemu/configure
./configure \
   --with-patched-kernel \
   --kerneldir=$(pwd)/kernel \
   --prefix=%{_prefix} \
   --qemu-ldflags=$qemuldflags \
   --disable-blobs \
   --audio-drv-list=sdl,alsa,oss

# build the bios, and fix it's makefile
sed -i 's/gcc -m32/gcc/' bios/Makefile
make bios

make vgabios

# we can't use RPM_OPT_FLAGS for the same reasons as qemu (#208026) for the
# qemu bits.  so let's set it for the other pieces.  this requires some
# manual keeping up of what is in the kvm tree.
sed -i 's/CFLAGS =/CFLAGS +=/' user/Makefile
echo "CFLAGS=$RPM_OPT_FLAGS" >> user/config.mak
make %{?_smp_mflags}


%install
rm -rf $RPM_BUILD_ROOT
make DESTDIR=$RPM_BUILD_ROOT install

# we have to have our own copies of the bios/keymaps due to incompat with
# qemu 0.9.  include the man page
mv $RPM_BUILD_ROOT/%{_mandir}/man1/qemu.1* $RPM_BUILD_ROOT/%{_mandir}/man1/qemu-kvm.1
rm -rf $RPM_BUILD_ROOT/%{_mandir}/man*/qemu-img* $RPM_BUILD_ROOT/%{_docdir}
rm -f $RPM_BUILD_ROOT/%{_bindir}/qemu-img
# no shared lib, static libs
rm -fr $RPM_BUILD_ROOT/%{_includedir} $RPM_BUILD_ROOT/%{_libdir}

# make install gives it bogus execute permissiions
chmod -x $RPM_BUILD_ROOT/%{_mandir}/man1/qemu-kvm.1*

install -d $RPM_BUILD_ROOT/%{_datadir}/%{name}
for i in bios.bin extboot.bin vgabios.bin vgabios-cirrus.bin
do
  install -m 0644 qemu/pc-bios/$i $RPM_BUILD_ROOT/%{_datadir}/%{name}/$i
done

mv $RPM_BUILD_ROOT/%{_bindir}/qemu-system-x86_64 $RPM_BUILD_ROOT/%{_bindir}/qemu-kvm

mkdir -p $RPM_BUILD_ROOT/%{_sysconfdir}/sysconfig/modules
install -m 0755 %{SOURCE1} $RPM_BUILD_ROOT/%{_sysconfdir}/sysconfig/modules/kvm.modules
install -m 0755 user/kvmtrace %{buildroot}/%{_bindir}/
install -m 0755 user/kvmtrace_format %{buildroot}/%{_bindir}/

# the pxe etherboot images will be symlinks to the images on
# /usr/share/etherboot, as KVM doesn't know how to look
# for other paths, yet.
pxe_link() {
  ln -s ../etherboot/$2.rom %{buildroot}/usr/share/kvm/pxe-$1.bin
}

pxe_link e1000 e1000-82542
pxe_link ne2k_pci ne
pxe_link pcnet pcnet32
pxe_link rtl8139 rtl8139
pxe_link virtio virtio-net


%post
# load kvm modules now, so we can make sure no reboot is needed.
# If there's already a kvm module installed, we don't mess with it
sh /%{_sysconfdir}/sysconfig/modules/kvm.modules


%clean
rm -rf $RPM_BUILD_ROOT


%files
%defattr(-,root,root,-)
%{_bindir}/*
%{_mandir}/*
%{_datadir}/%{name}
%{_sysconfdir}/sysconfig/modules/%{name}.modules

%changelog
* Mon Jan 19 2009 Daisuke SUZUKI <daisuke@linux.or.jp> 83-1
- new upstream release
- build with gnutls-1.6.3

* Mon Jul 07 2008 Daisuke SUZUKI <daisuke@linux.or.jp> 70-1
- new upstream release
- import patches from fedora

* Thu Nov 01 2007 Daisuke SUZUKI <daisuke@linux.or.jp> 48-0vl1
- initial build for Vine Linux
- update to kvm-48

* Mon Oct 15 2007 Daniel P. Berrange <berrange@redhat.com> - 36-7.fc8
- Fixed PXE boot when KVM is enabled (rhbz #331191)

* Wed Sep 26 2007 Daniel P. Berrange <berrange@redhat.com> - 36-6.fc8
- Fixed rtl8139 checksum calculation for Vista (rhbz #308201)

* Mon Sep 24 2007 Jeremy Katz <katzj@redhat.com> - 36-5
- fix build on x86_64

* Mon Sep 24 2007 Jeremy Katz <katzj@redhat.com> - 36-3
- add support for selecting boot device at runtime

* Tue Sep  4 2007 Jeremy Katz <katzj@redhat.com> - 36-2
- rebase vnc auth patch

* Tue Sep  4 2007 Jeremy Katz <katzj@redhat.com> - 36-1
- update to kvm-36

* Mon Aug 27 2007 Daniel P. Berrange <berrange@redhat.com> - 35-3.fc8
- Added patch for VNC password auth and TLS+x509 cert auth

* Mon Aug 20 2007 Jeremy Katz <katzj@redhat.com> - 35-2
- add fix for ATAPI from upstream qemu

* Mon Aug 20 2007 Jeremy Katz <katzj@redhat.com> - 35-1
- update to kvm-35
- patch to use -Wl,--build-id so that we get debuginfo

* Thu Jul 19 2007 Jeremy Katz <katzj@redhat.com> - 31-1
- update to kvm-31

* Mon Jul 16 2007 Jeremy Katz <katzj@redhat.com> - 28-2
- add patch from danpb to fix mac addrs of multiple 8139 nics (#247641)

* Wed Jun 13 2007 Jeremy Katz <katzj@redhat.com> - 28-1
- update to kvm-28

* Sat Jun  9 2007 Jeremy Katz <katzj@redhat.com> - 27-1
- update to kvm-27

* Tue May 29 2007 Jeremy Katz <katzj@redhat.com> - 26-1
- update to kvm-26

* Wed May 16 2007 Jeremy Katz <katzj@redhat.com> - 24-1
- update to kvm-24

* Wed Apr 25 2007 Jeremy Katz <katzj@redhat.com> - 19-2
- fix kernel and ramdisk being specified on the command line (#237879)

* Tue Apr 17 2007 Jeremy Katz <katzj@redhat.com> - 19-1
- update to kvm-19
- use rtl8139 as the default nic emulation instead of ne2k_pci (#236790)

* Mon Mar 26 2007 Jeremy Katz <katzj@redhat.com> - 15-2
- add file so that kvm modules get loaded on boot

* Wed Mar  7 2007 Jeremy Katz <katzj@redhat.com> - 15-1
- update to kvm-15

* Mon Feb 26 2007 Jeremy Katz <katzj@redhat.com> - 14-2
- use default optflags for non-qemu pieces (#230012)

* Fri Feb 23 2007 Jeremy Katz <katzj@redhat.com> - 14-1
- update to kvm-14
- note: this requires a kernel that's 2.6.21-rc1 or newer

* Mon Feb 19 2007 Jeremy Katz <katzj@redhat.com> - 12-3
- add the buildrequires for the docs to build

* Mon Feb 19 2007 Jeremy Katz <katzj@redhat.com> - 12-2
- include bios and keymaps in the kvm package since we need a slightly 
  different version for kvm now
- include man page

* Fri Jan 26 2007 Jeremy Katz <katzj@redhat.com> - 12-1
- update to kvm-12
- add qemu patch for better ATAPI DMA support (which works with ata_piix)

* Fri Jan 19 2007 Jeremy Katz <katzj@redhat.com> - 11-1
- update to kvm-11

* Fri Jan  5 2007 Jeremy Katz <katzj@redhat.com> - 9-1
- update to kvm-9

* Wed Jan  3 2007 Jeremy Katz <katzj@redhat.com> - 7-4
- actually build without -devel...

* Wed Dec 20 2006 Jeremy Katz <katzj@redhat.com> - 7-3
- remove the -devel subpackage since there's no shared lib upstream yet
- direct download link for source 

* Tue Dec 19 2006 Jeremy Katz <katzj@redhat.com> - 7-2
- BR e2fsprogs-devel

* Tue Dec 19 2006 Jeremy Katz <katzj@redhat.com> - 7-1
- Initial build