File kvm.spec of Package kvm.853

#
# spec file for package kvm
#
# Copyright (c) 2012 SUSE LINUX Products GmbH, Nuernberg, Germany.
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon. The license for this file, and modifications and additions to the
# file, is the same license as for the pristine package itself (unless the
# license for the pristine package is not an Open Source License, in which
# case the license is the MIT License). An "Open Source License" is a
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.

# Please submit bugfixes or comments via http://bugs.opensuse.org/
#
# icecream 0


%bcond_with vde

%define package_base_version 0.14.0
%define package_extra_version .0
%define bios_id seabios-0.6.2
%define pxe_rom_id gpxe-1.0.1
%define vgabios_id vgabios-0.6c

# note that this list doesn't include the gpxe roms since they get handled
# individually and not as a group
%define firmware_files {bios.bin vgabios.bin vgabios-cirrus.bin vgabios-stdvga.bin vgabios-vmware.bin vgabios-qxl.bin optionrom/extboot.bin optionrom/linuxboot.bin optionrom/multiboot.bin optionrom/vapic.bin}

ExclusiveArch:  %ix86 x86_64 ia64 s390x

%ifarch %ix86 x86_64
# choice of building all from source or using provided binary x86 blobs
%define build_fw_from_source 1
# build the Mac BIOS on x86 platforms
%define mac_bios 1
%else
%define build_fw_from_source 0
# build no Mac BIOS on others
%define mac_bios 0
%endif
%define mac_patches_ported 0

%define using_buildservice 0%{?opensuse_bs}

Name:           kvm
BuildRequires:  SDL-devel
BuildRequires:  alsa
BuildRequires:  alsa-devel
BuildRequires:  gnutls-devel
BuildRequires:  libaio-devel
BuildRequires:  libcurl-devel
BuildRequires:  libpulse-devel
BuildRequires:  ncurses-devel
BuildRequires:  pciutils-devel
BuildRequires:  perl
BuildRequires:  python
BuildRequires:  texinfo
%if 0%{?suse_version} >= 1130
BuildRequires:  brlapi-devel
%endif
%ifarch %ix86 x86_64 ia64
%if %{build_fw_from_source}
# needed for building vgabios:
BuildRequires:  bin86
%ifarch x86_64
#needed by bcc compiler which is needed for building vgabios:
BuildRequires:  glibc-32bit
%endif
%endif
%if 0%{?suse_version} > 1110
BuildRequires:  acpica
%else
BuildRequires:  pmtools
%endif
%endif
%if %{with vde}
BuildRequires:  vde2-devel
%endif
Requires:       python-curses
Requires:       virt-utils
%if 0%{?suse_version} < 1110
Requires:       kvm-kmp
%endif
Summary:        Kernel-based Virtual Machine
License:        BSD-3-Clause ; GPL-2.0 ; GPL-2.0+ ; LGPL-2.1+ ; MIT
Group:          System/Kernel
Url:            http://kvm.qumranet.com/
Version:        %{package_base_version}%{package_extra_version} 
Release:        0
Source0:        qemu-%{name}-%{package_base_version}.tar.bz2
Source1:        60-kvm.rules
Source2:        qemu-ifup
Source4:        win-virtio-drivers.iso
Source5:        win-virtio-drivers-src.tar.bz2
Source6:        %{bios_id}.tar.bz2
Source7:        %{pxe_rom_id}.tar.bz2
Source8:        bcc-0.16.17-2.i486.rpm
Source9:        %{vgabios_id}.tar.bz2
Source10:       kvm-supported.txt
Source11:       s390-zipl.rom
# common and X86 patches
Patch01:        gpxe-rom-settings.patch
Patch02:        seabios-sanitize-version.patch
Patch03:        vgabios-bcc-paths.patch

Patch05:        qemu-datadir.diff
Patch06:        kvm-qemu-default-memsize.patch
Patch07:        kvm-qemu-user-space-tool-name.patch
Patch08:        kvm-qemu-preXX-fix-rom-file-name-for-e100-nic.patch
Patch09:        kvm-qemu-no-hot-unplug-for-certain-devices.patch

# Mac OS X patches
Patch20:        kvm-qemu-lpc.patch
Patch21:        kvm-qemu-ide-ich6.patch
Patch22:        kvm-qemu-macmodel.patch
Patch23:        kvm-qemu-rtl8139-link.patch
Patch90:        kvm-bios.patch
# Post-release upstream patches
Patch100:       kvm-qemu-preXX-dictzip1.patch
Patch101:       kvm-qemu-preXX-dictzip2.patch
Patch102:       kvm-qemu-preXX-report-default-mac-used.patch
Patch103:       kvm-qemu-preXX-eepro100-pad-to-ensure-minimum-packet-size.patch
Patch104:       kvm-qemu-preXX-vnc-Fix-fatal-crash-with-vnc-reverse-mode.patch
Patch105:       kvm-qemu-preXX-hw-sd.c-Add-missing-state-change-for-SD_ST.patch
Patch106:       kvm-qemu-preXX-vnc-fix-a-memory-leak-in-threaded-vnc-serv.patch
Patch107:       kvm-qemu-preXX-device-assignment-detect-pre-fectchable-me.patch
Patch108:       kvm-qemu-preXX-qemu-kvm-Mark-VCPU-state-dirty-on-creation.patch
Patch109:       kvm-qemu-preXX-net-fix-qemu_can_send_packet-logic.patch
Patch110:       kvm-qemu-preXX-hw-pcnet.c-Fix-EPROM-contents-to-suit-AMD-.patch
Patch111:       kvm-qemu-preXX-fix-linuxboot.bin-and-multiboot.bin-to-not.patch
Patch112:       kvm-qemu-preXX-exit-if-drive-specified-is-invalid-instead.patch
Patch113:       kvm-qemu-preXX-Fix-performance-regression-in-qemu_get_ram.patch
Patch114:       kvm-qemu-preXX-kvm-Mark-VCPU-state-dirty-on-creation.patch
Patch115:       kvm-qemu-preXX-Don-t-allow-multiwrites-against-a-block-de.patch
Patch116:       kvm-qemu-preXX-virtio-pci-fix-bus-master-work-around-on-l.patch
Patch117:       kvm-qemu-preXX-virtio-serial-don-t-crash-on-invalid-input.patch
Patch118:       kvm-qemu-preXX-vhost-fix-dirty-page-handling.patch
Patch119:       kvm-qemu-preXX-e1000-multi-buffer-packet-support.patch
Patch120:       kvm-qemu-preXX-e1000-clear-EOP-for-multi-buffer-descripto.patch
Patch121:       kvm-qemu-preXX-e1000-verify-we-have-buffers-upfront.patch
Patch122:       kvm-qemu-preXX-e1000-fix-multi-descriptor-packet-checksum.patch
Patch123:       kvm-qemu-preXX-e1000-check-buffer-availability.patch
Patch124:       kvm-qemu-preXX-vnc-don-t-set-the-quality-if-lossy-encodin.patch
Patch125:       kvm-qemu-preXX-vnc-add-a-way-to-get-the-update-frequency-.patch
Patch126:       kvm-qemu-preXX-vnc-refresh-lossy-rect-after-a-given-timeo.patch
Patch127:       kvm-qemu-preXX-vnc-tight-use-the-update-frequency-to-choo.patch
Patch128:       kvm-qemu-preXX-vnc-palette-use-a-pool-to-reduce-memory-al.patch
Patch129:       kvm-qemu-preXX-vnc-palette-add-palette_init-calls.patch
Patch130:       kvm-qemu-preXX-vnc-palette-and-fill-and-color-calls.patch
Patch131:       kvm-qemu-preXX-vnc-Add-ZRLE-and-ZYWRLE-encodings.patch
Patch132:       kvm-qemu-preXX-vnc-fix-uint8_t-comparisons-with-negative-.patch
Patch133:       kvm-qemu-preXX-vnc-fix-lossy-rect-refreshing.patch
Patch134:       kvm-qemu-preXX-bitmap-add-a-generic-bitmap-and-bitops-lib.patch
Patch135:       kvm-qemu-preXX-ui-vnc-enc-tight.c-Fix-compile-failure-if-.patch
Patch136:       kvm-qemu-preXX-vnc-use-the-new-generic-bitmap-functions.patch
Patch137:       kvm-qemu-preXX-vnc-Fix-stack-corruption-and-other-bitmap-.patch
Patch138:       kvm-qemu-preXX-fix-vnc-regression.patch
Patch139:       kvm-qemu-preXX-vnc-fix-build-error-from-VNC_DIRTY_WORDS.patch
Patch140:       kvm-qemu-preXX-severe-memory-leak-caused-by-broken-palett.patch
Patch141:       kvm-qemu-preXX-virtio-blk-fail-unaligned-requests.patch
Patch142:       kvm-qemu-preXX-vnc-tight-Fix-crash-after-2GB-of-output.patch
Patch143:       kvm-qemu-preXX-virtio-guard-against-negative-vq-notifies.patch
Patch144:       kvm-qemu-preXX-validate-virtqueue.patch
Patch145:       kvm-qemu-preXX-dictzip3.patch
Patch146:       kvm-qemu-preXX-os-posix-set-groups-properly-for-runas.patch
Patch147:       kvm-qemu-preXX-e1000-check-for-overflow-whenever-issuing-PCI-dma-reads.patch
Patch148:       kvm-qemu-preXX-block-prevent-snapshot-mode-TMPDIR-symlink-attack.patch
Patch149:       kvm-qemu-preXX-console-bounds-check-whenever-changing-the-cursor-du.patch

Patch200:       qemu-img-vmdk-scsi.patch
Patch201:       kvm-studio-slirp-nooutgoing.patch
Patch202:       kvm-studio-vnc.patch
# for IA64
Source500:      ia64-fix-pagesize.pl
Patch500:       IA64-kvm-suse.patch
Patch501:       IA64-compile-fix-suse.patch
# for S390
Patch700:       S390-qemu-kvm.patch
Patch701:       S390-qemu-early-printk.patch
Patch702:       S390-0002-S390-Tell-user-why-VM-creation-failed.patch
Patch703:       S390-0003-Make-char-muxer-more-robust-wrt-small-FIFOs.patch
Patch704:       S390-0004-Always-notify-consumers-of-char-devices-if-they-re-o.patch
Patch705:       S390-0005--S390-Implement-virtio-reset.patch
Patch706:       S390-0006--S390-Add-firmware-code.patch

# For upstream patches:
BuildRoot:      %{_tmppath}/%{name}-%{version}-build
PreReq:         /usr/sbin/groupadd

%description
KVM (Kernel-based Virtual Machine) is virtualization software for
Linux. It is based on the hardware virtualization extensions provided
by Intel VT and AMD-V technologies. KVM kernel modules provide a
control interface at /dev/kvm which the qemu-kvm user-space program
uses to provide a hybrid emulated and actual hardware environment
sufficent to run various PC operating systems (guests) in unmodified
form, including Linux, Windows, and Mac OS X.

Since qemu-kvm is derived from the qemu processor emulator sources it
also is able to run guests using processor emulation mode, but with the
expected performance impact. Conversely, hardware virtualization
features outside the processor such as iommu and sr-iov are used by KVM
allowing for improved performance.

The seabios, vgabios and gpxe open source projects are also pulled from
to provide the firmware components included.

To increase performance over emulated hardware devices virtio drivers
are supported, and in the case of Windows, included.

KVM is compatible with various VM management solutions, including
libvirt, virt-manager and vm-install.


Authors:
--------
    Avi Kivity   <avi@qumranet.com>
    Yaniv Kamay  <yaniv@qumranet.com>
    Dor Laor     <dor.laor@qumranet.com>

%prep
%if %{build_fw_from_source}
mkdir bcc-bits
cd bcc-bits/
rpm2cpio %{SOURCE8} | cpio -id ./usr/bin/bcc ./usr/lib/bcc/bcc-cc1
%setup -q -T -D -n %{pxe_rom_id} -b 7
%patch01 -p1
%endif
%setup -q -n qemu-%{name}-%{package_base_version} -a 6 -a 9
%if %{build_fw_from_source}
#ensure that we only end up with the ones we built
for i in %firmware_files
do
  rm -f pc-bios/$i
done
%patch02 -p1
%patch03 -p1
%endif
cp %{SOURCE10} .
%patch05 -p1
%patch06 -p1
%patch07 -p1
%patch08 -p1
%patch09 -p1
# Mac OS X guest
%if %{mac_bios}
%if %{mac_patches_ported}
%patch20 -p1
%endif
%patch21 -p1
%if %{mac_patches_ported}
%patch22 -p1
%patch23 -p1
%endif
cp -a roms/seabios roms/seabios-mac
%if %{mac_patches_ported}
%patch90 -p1 -b .bios-mac
%endif
%endif
# Post-release patches
%patch100 -p1
%patch101 -p1
%patch102 -p1
%patch103 -p1
%patch104 -p1
%patch105 -p1
%patch106 -p1
%patch107 -p1
%patch108 -p1
%patch109 -p1
%patch110 -p1
%patch111 -p1
%patch112 -p1
%patch113 -p1
%patch114 -p1
%patch115 -p1
%patch116 -p1
%patch117 -p1
%patch118 -p1
%patch119 -p1
%patch120 -p1
%patch121 -p1
%patch122 -p1
%patch123 -p1
%patch124 -p1
%patch125 -p1
%patch126 -p1
%patch127 -p1
%patch128 -p1
%patch129 -p1
%patch130 -p1
%patch131 -p1
%patch132 -p1
%patch133 -p1
%patch134 -p1
%patch135 -p1
%patch136 -p1
%patch137 -p1
%patch138 -p1
%patch139 -p1
%patch140 -p1
%patch141 -p1
%patch142 -p1
%patch143 -p1
%patch144 -p1
%patch145 -p1
%patch146 -p1
%patch147 -p1
%patch148 -p1
%patch149 -p1

# Studio addons
%patch200 -p1
%patch201 -p1
%patch202 -p1
# IA64 support
%ifarch ia64
%patch500 -p1
%patch501 -p1
%endif
# S390 support
%ifarch s390x
%patch700 -p1
%patch701 -p1
%patch702 -p1
%patch703 -p1
%patch704 -p1
%patch705 -p1
%patch706 -p1
%endif

cp %{SOURCE11} pc-bios/

%build
# change from devel version to actual version
echo "%{package_base_version}" > VERSION 
echo "kvm-%{version}-%{release}" > KVM_VERSION
./configure \
        --prefix=%{_prefix} \
        --sysconfdir=/etc \
        --extra-cflags="%{optflags}" \
        --disable-debug-tcg \
        --disable-sparse \
        --disable-strip \
        --enable-werror \
        --enable-sdl \
%if 0%{?suse_version} >= 1100
        --audio-drv-list="pa alsa sdl oss" \
%else
        --audio-drv-list="alsa sdl oss" \
%endif
        --audio-card-list="ac97 adlib cs4231a gus sb16 hda" \
%ifarch ia64
        --target-list="ia64-softmmu" --disable-cpu-emulation \
%else
%ifarch s390x
        --target-list="s390x-softmmu" \
%else
        --target-list="x86_64-softmmu" \
%endif
%endif
        --disable-xen \
        --enable-vnc-tls \
        --disable-vnc-sasl \
        --disable-vnc-jpeg \
        --disable-vnc-png \
        --disable-vnc-thread \
        --enable-curses \
        --enable-curl \
        --disable-fdt \
        --disable-bluez \
        --enable-kvm \
        --enable-kvm-pit \
        --enable-kvm-device-assignment \
        --disable-user \
%if !%{with vde}
        --disable-vde \
%endif
%if %{build_fw_from_source}
        --disable-blobs \
%endif
        --enable-docs \
%if 0%{?suse_version} == 1120
        --disable-linux-aio \
%else
        --enable-linux-aio \
%endif
%if 0%{?suse_version} >= 1130
        --enable-brlapi
%else
        --disable-brlapi
%endif

sed -i 's/CFLAGS  =/CFLAGS  +=/' roms/vgabios/Makefile
# userspace:
make %{?jobs:-j%jobs}

# Firmware
%ifarch %ix86 x86_64
%if %{build_fw_from_source}
make -C roms/seabios %{?jobs:-j%jobs}
cp roms/seabios/out/bios.bin pc-bios/bios.bin
%if %{mac_bios}
make -C roms/seabios-mac %{?jobs:-j%jobs}
%endif

make -C roms/vgabios %{?jobs:-j%jobs}
cp roms/vgabios/VGABIOS-lgpl-latest.bin pc-bios/vgabios.bin
cp roms/vgabios/VGABIOS-lgpl-latest.cirrus.bin pc-bios/vgabios-cirrus.bin
cp roms/vgabios/VGABIOS-lgpl-latest.stdvga.bin pc-bios/vgabios-stdvga.bin
cp roms/vgabios/VGABIOS-lgpl-latest.vmware.bin pc-bios/vgabios-vmware.bin
cp roms/vgabios/VGABIOS-lgpl-latest.qxl.bin pc-bios/vgabios-qxl.bin
cd ../%{pxe_rom_id}/src
make bin/8086100e.rom %{?jobs:-j%jobs}
make bin/10222000.rom %{?jobs:-j%jobs}
make bin/10500940.rom %{?jobs:-j%jobs}
make bin/10ec8139.rom %{?jobs:-j%jobs}
make bin/80861209.rom %{?jobs:-j%jobs}
make bin/1af41000.rom %{?jobs:-j%jobs}
%endif
%endif

%install
make DESTDIR=%{buildroot} install %{?jobs:-j%jobs}
%if %{mac_bios}
install -m 644 roms/seabios-mac/out/bios.bin %{buildroot}%{_datadir}/qemu-kvm/bios-mac.bin
%endif
mkdir -p %{buildroot}%{_docdir}/kvm
cp qemu-doc.html qemu-kvm.html
install -m 755 kvm/kvm_stat %{buildroot}%{_bindir}/
%if %{build_fw_from_source}
for i in %firmware_files
do
  install -m 644 pc-bios/$i %{buildroot}%{_datadir}/qemu-kvm/
done
install_rom() {
  install -m 644 $1.rom %{buildroot}%{_datadir}/qemu-kvm/$2.bin
}
cd ../%{pxe_rom_id}/src/bin/
install_rom 8086100e pxe-e1000
install_rom 10222000 pxe-pcnet
install_rom 10500940 pxe-ne2k_pci
install_rom 10ec8139 pxe-rtl8139
install_rom 80861209 pxe-i82559er
install_rom 1af41000 pxe-virtio
%endif
cd %{buildroot}
rm -r .{%_bindir/qemu-io,%_bindir/qemu-nbd,%_datadir/doc/qemu}
mv .%_bindir/qemu-img{,-kvm}
%if !%{build_fw_from_source}
rm -r .%_datadir/qemu-kvm/{openbios-sparc32,openbios-sparc64,ppc_rom.bin,openbios-ppc,video.x,bamboo.dtb,petalogix-s3adsp1800.dtb}
%endif
%ifarch ia64 s390x
rm -f .%_datadir/qemu-kvm/bios.bin
%endif
rm -r .{%_mandir/man1/qemu-img.1,%_mandir/man8/qemu-nbd.8}
mv .%_bindir/{qemu-system*,qemu-kvm}
mv .%_mandir/man1/{qemu.1,qemu-kvm.1}
chmod 644 .%_mandir/man1/*
install -D -m 644 %{SOURCE1} %{buildroot}/etc/udev/rules.d/60-kvm.rules
install -D -m 755 %{SOURCE2} %{buildroot}/usr/share/qemu-kvm/qemu-ifup
install -D -m 644 %{SOURCE4} %{buildroot}/usr/share/qemu-kvm/win-virtio-drivers.iso

%clean
cd ../
rm -rf bcc-bits
rm -rf %{pxe_rom_id}
rm -rf $RPM_BUILD_ROOT

%pre
/usr/sbin/groupadd -r kvm 2>/dev/null || :

%files
%defattr(-,root,root)
%doc qemu-kvm.html kvm-supported.txt
%attr(755,root,kvm) %{_bindir}/qemu-kvm
%attr(755,root,kvm) %{_bindir}/qemu-img-kvm
%attr(755,root,kvm) %{_bindir}/kvm_stat
%{_datadir}/qemu-kvm
%dir %attr(0700, root, kvm) %{_sysconfdir}/qemu-kvm/
%attr(644,root,kvm) %{_sysconfdir}/qemu-kvm/target-x86_64.conf
%config %{_sysconfdir}/qemu-kvm/target-x86_64.conf
%config %{_sysconfdir}/udev/rules.d/60-kvm.rules
%_mandir/man1/qemu-kvm.1.gz

%changelog