File libvirt.spec of Package libvirt

#
# spec file for package libvirt
#
# Copyright (c) 2014 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/
#


# For now, default to a full server + client build
%define client_only        0

# Disable all server side drivers if client only build requested
%if %{client_only}
%define server_drivers     0
%else
%define server_drivers     1
%endif

# Default build includes dlopen'd modules
%define with_driver_modules 1

# Now set the defaults for all the important features, independent
# of any particular OS

# First the daemon itself
%define with_libvirtd      0%{!?_without_libvirtd:%{server_drivers}}
%define with_avahi         0%{!?_without_avahi:%{server_drivers}}

# Then the hypervisor drivers that run in libvirtd
%define with_xen           0%{!?_without_xen:%{server_drivers}}
%define with_qemu          0%{!?_without_qemu:%{server_drivers}}
%define with_lxc           0%{!?_without_lxc:%{server_drivers}}
%define with_uml           0%{!?_without_uml:%{server_drivers}}
%define with_libxl         0%{!?_without_libxl:%{server_drivers}}
%define with_vbox          0%{!?_without_vbox:%{server_drivers}}

# Then the hypervisor drivers that run outside libvirtd, in libvirt.so
%define with_openvz        0%{!?_without_openvz:1}
%define with_vmware        0%{!?_without_vmware:1}
%define with_phyp          0%{!?_without_phyp:0}
%define with_esx           0%{!?_without_esx:1}
%define with_hyperv        0%{!?_without_hyperv:0}
%define with_xenapi        0%{!?_without_xenapi:1}
%define with_parallels     0%{!?_without_parallels:1}

# Then the secondary host drivers, which run inside libvirtd
%define with_interface     0%{!?_without_interface:%{server_drivers}}
%define with_network       0%{!?_without_network:%{server_drivers}}
%define with_storage_fs    0%{!?_without_storage_fs:%{server_drivers}}
%define with_storage_lvm   0%{!?_without_storage_lvm:%{server_drivers}}
%define with_storage_iscsi 0%{!?_without_storage_iscsi:%{server_drivers}}
%define with_storage_disk  0%{!?_without_storage_disk:%{server_drivers}}
%define with_storage_mpath 0%{!?_without_storage_mpath:%{server_drivers}}
%define with_storage_rbd   0
%define with_storage_sheepdog 0
%define with_storage_gluster  0
%define with_numactl       0%{!?_without_numactl:%{server_drivers}}
%define with_selinux       0%{!?_without_selinux:%{server_drivers}}
%define with_apparmor      0%{!?_without_apparmor:%{server_drivers}}

# Optional bits on by default
%define with_polkit        0%{!?_without_polkit:1}
%define with_udev          0%{!?_without_udev:%{server_drivers}}
%define with_audit         0%{!?_without_audit:1}
%define with_yajl          0%{!?_without_yajl:%{server_drivers}}
%define with_sanlock       0%{!?_without_sanlock:%{server_drivers}}
%define with_netcontrol    0%{!?_without_netcontrol:%{server_drivers}}

# A few optional bits off by default, we enable later
%define with_capng         0%{!?_without_capng:0}
%define with_fuse          0%{!?_without_fuse:0}
%define with_netcf         0%{!?_without_netcf:0}
%define with_nwfilter      0%{!?_without_nwfilter:0}
%define with_libpcap       0%{!?_without_libpcap:0}
%define with_macvtap       0%{!?_without_macvtap:0}
%define with_libnl         0%{!?_without_libnl:0}
%define with_dtrace        0%{!?_without_dtrace:0}
%define with_cgconfig      0%{!?_without_cgconfig:0}
%define with_systemd       0%{!?_without_systemd:0}
%define with_numad         0%{!?_without_numad:0}
%define with_firewalld     0%{!?_without_firewalld:0}
%define with_libssh2       0%{!?_without_libssh2:0}
%define with_systemd_daemon 0%{!?_without_systemd_daemon:0}

# Non-server/HV driver defaults which are always enabled
%define with_sasl          0%{!?_without_sasl:1}

# Set the OS / architecture specific special cases

# Xen is available only on x86_64
%ifnarch x86_64
%define with_xen           0
%define with_libxl         0
%endif

# libxl is only compatible with Xen >= 4.2 (i.e. suse_version > 12.2)
%if 0%{?suse_version} <= 1220
%define with_libxl         0
%endif

# numactl only on x86_64 and ia64
%ifnarch x86_64 ia64
%define with_numactl       0
%endif

# vbox is available only on i386 x86_64
%ifnarch %{ix86} x86_64
%define with_vbox          0
%endif

# Explicitly disable hypervisor drivers not supported in SLES12
%define with_openvz        0
%define with_vbox          0
%define with_uml           0
%define with_esx           0
%define with_vmware        0
%define with_xenapi        0
%define with_hyperv        0
%define with_parallels     0
%define with_xen           0

# Enable phyp driver for IBM Power systems
%ifarch ppc64
%define with_phyp          1
%endif

# LXC and selinux are not available on anything < 11.1
%if 0%{?suse_version} < 1110
%define with_lxc           0
%define with_selinux       0
%endif

# Support systemd on 12.1 and later
%if 0%{?suse_version} >= 1210
%define with_systemd       0%{!?_without_systemd:1}
%define with_systemd_daemon 1
%endif

# libcapng is used to manage capabilities in 11.3 or newer.
# It is also used by lxc and needs to be enabled if lxc is enabled.
%if 0%{?suse_version} >= 1130 || %{with_lxc}
%define with_capng         0%{!?_without_capng:1}
%endif

%if 0%{?suse_version} >= 1230
%define with_fuse          0%{!?_without_fuse:1}
%endif

# interface requires netcontrol
%if ! 0%{?with_netcontrol}
%define with_interface     0
%endif

# Support libssh2 in 12.3 and later
%if 0%{?suse_version} >= 1230
%define with_libssh2       0%{!?_without_libssh2:1}
%endif

# Disable some drivers when building without libvirt daemon.
# The logic is the same as in configure.ac
%if ! %{with_libvirtd}
%define with_interface     0
%define with_network       0
%define with_qemu          0
%define with_lxc           0
%define with_uml           0
%define with_vbox          0
%define with_udev          0
%define with_storage_fs    0
%define with_storage_lvm   0
%define with_storage_iscsi 0
%define with_storage_mpath 0
%define with_storage_rbd   0
%define with_storage_sheepdog 0
%define with_storage_gluster  0
%define with_storage_disk  0
%endif

# Enable libpcap library
%if %{with_qemu} || %{with_lxc}
%if 0%{?suse_version} >= 1140
%define with_nwfilter      0%{!?_without_nwfilter:%{server_drivers}}
%define with_libpcap       0%{!?_without_libpcap:%{server_drivers}}
%define with_macvtap       0%{!?_without_macvtap:%{server_drivers}}
# numad is used to manage the CPU and memory placement dynamically.
# It is only available on x86, and openSUSE >= 13.1
%if 0%{?suse_version} >= 1310
%ifarch i386 i586 i686 x86_64
%define with_numad         0%{!?_without_numad:%{server_drivers}}
%endif
%endif
# Force QEMU to run as qemu:qemu
%define qemu_user          qemu
%define qemu_group         qemu
%else
%define qemu_user          root
%define qemu_group         root
%endif
%endif

%if %{with_macvtap}
%define with_libnl         1
%endif

# Pull in cgroups config system
%if %{with_qemu} || %{with_lxc}
%define with_cgconfig 0%{!?_without_cgconfig:1}
%endif

%if %{with_udev}
%define with_nodedev 1
%else
%define with_nodedev 0
%endif

%if %{with_storage_fs} || %{with_storage_mpath} || %{with_storage_iscsi} || %{with_storage_lvm} || %{with_storage_disk}
%define with_storage 1
%else
%define with_storage 0
%endif

%define _fwdefdir /etc/sysconfig/SuSEfirewall2.d/services

Name:           libvirt
Url:            http://libvirt.org/
Version:        1.2.5
Release:        0
Summary:        Library providing a simple virtualization API
License:        LGPL-2.1+
Group:          Development/Libraries/C and C++

%if %{with_libvirtd}
Requires:       libvirt-daemon = %{version}-%{release}
%if %{with_network}
Requires:       libvirt-daemon-config-network = %{version}-%{release}
%endif
%if %{with_nwfilter}
Requires:       libvirt-daemon-config-nwfilter = %{version}-%{release}
%endif
%if %{with_driver_modules}
%if %{with_libxl}
Requires:       libvirt-daemon-driver-libxl = %{version}-%{release}
%endif
%if %{with_lxc}
Requires:       libvirt-daemon-driver-lxc = %{version}-%{release}
%endif
%if %{with_qemu}
Requires:       libvirt-daemon-driver-qemu = %{version}-%{release}
%endif
%if %{with_uml}
Requires:       libvirt-daemon-driver-uml = %{version}-%{release}
%endif
%if %{with_xen}
Requires:       libvirt-daemon-driver-xen = %{version}-%{release}
%endif
%if %{with_vbox}
Requires:       libvirt-daemon-driver-vbox = %{version}-%{release}
%endif
%if %{with_nwfilter}
Requires:       libvirt-daemon-driver-nwfilter = %{version}-%{release}
%endif
%if %{with_interface}
Requires:       libvirt-daemon-driver-interface = %{version}-%{release}
%endif
Requires:       libvirt-daemon-driver-network = %{version}-%{release}
Requires:       libvirt-daemon-driver-nodedev = %{version}-%{release}
Requires:       libvirt-daemon-driver-secret = %{version}-%{release}
Requires:       libvirt-daemon-driver-storage = %{version}-%{release}
%endif
%endif
Requires:       libvirt-client = %{version}-%{release}

# All build-time requirements. Run-time requirements are
# listed against each sub-RPM
BuildRequires:  autoconf
BuildRequires:  automake
BuildRequires:  gettext-tools
BuildRequires:  libtool
# Needed for virkmodtest in 'make check'
BuildRequires:  modutils
%if %{with_systemd}
BuildRequires:  systemd
%endif
%if %{with_systemd_daemon}
BuildRequires:  systemd-devel
%endif
%if %{with_xen} || %{with_libxl}
BuildRequires:  xen-devel
%endif
BuildRequires:  fdupes
BuildRequires:  libattr-devel
BuildRequires:  libgcrypt-devel
BuildRequires:  libgnutls-devel
BuildRequires:  libtasn1-devel
BuildRequires:  libxml2-devel
BuildRequires:  libxslt
BuildRequires:  ncurses-devel
BuildRequires:  python
BuildRequires:  python-xml
BuildRequires:  readline-devel
BuildRequires:  xhtml-dtd
%if %{with_libvirtd}
# For pool-build probing for existing pools
BuildRequires:  libblkid-devel >= 2.17
%endif
%if %{with_udev}
BuildRequires:  libpciaccess0-devel >= 0.10.9
BuildRequires:  libudev-devel >= 145
%endif
%if %{with_yajl}
BuildRequires:  libyajl-devel
%endif
%if %{with_sanlock}
BuildRequires:  sanlock-devel >= 2.4
%endif
%if %{with_libpcap}
BuildRequires:  libpcap-devel
%endif
%if %{with_libnl}
%if 0%{?suse_version} >= 1310
BuildRequires:  libnl3-devel
%else
%if 0%{?suse_version} >= 1210
BuildRequires:  libnl-1_1-devel
%else
BuildRequires:  libnl-devel
%endif
%endif
%endif
%if %{with_avahi}
BuildRequires:  libavahi-devel
%endif
%if %{with_selinux}
BuildRequires:  libselinux-devel
%endif
%if %{with_apparmor}
BuildRequires:  libapparmor-devel
%endif
%if %{with_network}
BuildRequires:  dnsmasq >= 2.41
BuildRequires:  iptables
# TODO BuildRequires:  iptables-ipv6
BuildRequires:  radvd
%endif
%if %{with_nwfilter}
BuildRequires:  ebtables
%endif
%if %{with_sasl}
BuildRequires:  cyrus-sasl-devel
%endif
%if %{with_polkit}
%if 0%{?suse_version} > 1110
BuildRequires:  polkit-devel >= 0.9
%else
BuildRequires:  PolicyKit-devel >= 0.6
%endif
%endif
%if %{with_storage_fs}
# For mount/umount in FS driver
BuildRequires:  util-linux
%endif
%if %{with_storage_lvm}
# For LVM drivers
BuildRequires:  lvm2
%endif
%if %{with_storage_iscsi}
# For ISCSI driver
BuildRequires:  open-iscsi
%endif
%if %{with_storage_disk}
# For disk driver
BuildRequires:  parted-devel
%endif
%if %{with_storage_mpath}
# For Multipath support
BuildRequires:  device-mapper-devel
%endif
%if %{with_storage_rbd}
BuildRequires:  ceph-devel
%endif
%if %{with_numactl}
# For QEMU/LXC numa info
BuildRequires:  libnuma-devel
%endif
%if %{with_capng}
BuildRequires:  libcap-ng-devel >= 0.5.0
%endif
%if %{with_fuse}
BuildRequires:  fuse-devel >= 2.8.6
%endif
%if %{with_phyp} || %{with_libssh2}
BuildRequires:  libssh2-devel
%endif
%if %{with_netcontrol}
BuildRequires:  libnetcontrol-devel >= 0.2.0
%endif
%if %{with_esx}
BuildRequires:  libcurl-devel
%endif
%if %{with_hyperv}
BuildRequires:  libwsman-devel >= 2.2.3
%endif
%if %{with_audit}
BuildRequires:  audit-devel
%endif
%if %{with_dtrace}
# we need /usr/sbin/dtrace 
BuildRequires:  systemtap-sdt-devel
%endif
%if %{with_numad}
BuildRequires:  numad
%endif

Source0:        %{name}-%{version}.tar.bz2
Source1:        libvirtd.init
Source2:        libvirtd-relocation-server.fw
Source99:       baselibs.conf
# Upstream patches
Patch0:         d9a099a4-libxl-abi-check.patch
Patch1:         9b8d6e1e-libxl-migration.patch
Patch2:         1c7eb95c-qemu-encrypt-disk.patch
Patch3:         b73aafd6-virt-lxc-convert.patch
Patch4:         bf410bb8-libxl-iface-network.patch
Patch5:         2624dfde-libxl-iface-script.patch
Patch6:         ac63014c-libxl-domxml-from-native.patch
Patch7:         64b60266-xmconfigtest-fix.patch
Patch8:         c1bc06e2-libxl-mig-resume-fix.patch
Patch9:         48d81cef-libxl-qdisk.patch
Patch10:        1d37a4c4-libxl-detect-save-restore.patch
Patch11:        ec7b9225-libxl-pv-console.patch
Patch12:        92cd6b67-libxl-label-rename.patch
Patch13:        c4f66bb8-libxl-mig-prepare.patch
Patch14:        bab7ad4c-libxl-mig-job-fix.patch
Patch15:        72a84539-libxl-mig-crash-fix.patch
Patch16:        232cf2a4-libxl-hostdev-config.patch
Patch17:        b0d24540-libxl-iface-hostdev.patch
Patch18:        2f97ea32-libxl-hostdev-fix.patch
Patch19:        9b1e4cd5-skip-useless-apparmor-files.patch
Patch20:        9265f8ab-apparmor-lxc-rework.patch
Patch21:        dba3432b-virt-lxc-convert-fix.patch
Patch22:        a9fd30e6-storagevol-add-nocow-to-vol-xml.patch
Patch23:        7eabd550-virsh-mig-hang.patch
Patch24:        4dfc34c3-libxl-vnc-fix.patch
Patch25:        c285ffc4-virsh-mig-initdata.patch
Patch26:        0e1a1a8c-qemu-ensure-sane-umask-for-qemu-process.patch
Patch27:        e9f69374-util-don-t-shadow-global-umask-declaration.patch 
Patch28:        817206cd-libxl-lifecycle-events.patch
Patch29:        3e745e8f-CVE-2014-3633.patch
Patch30:        c7892373-libxl-remove-lock.patch
Patch31:        a9bad1a3-libvirt-guests-time-sync.patch
# pending review upstream patches
Patch100:       libxl-add-discard-support.patch
Patch101:       libxl-domxml-to-native.patch
Patch102:       lxc-keep-caps-feature.patch
Patch103:       lxc-keep-caps-feature-conversion.patch
Patch104:       lxc-keep-caps-feature-doc.patch
Patch105:       lxc-net-target-name.patch
Patch106:       lxc-net-target-name-conversion.patch
Patch107:       lxc-net-target-name-doc.patch
Patch108:       libxl-dom-reset.patch
Patch109:       libxl-hvm-kernel-boot.patch
Patch110:       libxl-support-keymap.patch
Patch111:       libxl-dev-model.patch
Patch112:       libxl-support-emulator.patch
# Need to go upstream
Patch150:       xen-pv-cdrom.patch
Patch152:       libxl-set-migration-constraints.patch
Patch153:       blockcopy-check-dst-identical-device.patch
Patch154:       libvirt-ppc64le-support.patch
Patch155:       libvirt-power8-models.patch
Patch156:       ppc64le-canonical-name.patch
# Our patches
Patch200:       libvirtd-defaults.patch
Patch201:       libvirtd-init-script.patch
Patch202:       libvirt-guests-init-script.patch
Patch203:       virtlockd-init-script.patch
Patch204:       suse-qemu-conf.patch
Patch205:       support-managed-pci-xen-driver.patch
Patch206:       systemd-service-xen.patch
# Disable failing virCgroupGetPercpuStats unit test
Patch207:       disable-virCgroupGetPercpuStats-test.patch
Patch208:       lxc-convert-fix-sle11-rootfs.patch
Patch209:       libxl-set-cach-mode.patch
Patch210:       virt-create-rootfs.patch
%if %{with_apparmor}
Patch250:       install-apparmor-profiles.patch
Patch251:       apparmor-profile-no-mount.patch
%endif
%if %{with_netcontrol}
Patch300:       libvirt-suse-netcontrol.patch
%endif
BuildRoot:      %{_tmppath}/%{name}-%{version}-build

%description
Libvirt is a C toolkit to interact with the virtualization
capabilities of Linux. Virtualization of the Linux Operating System means
the ability to run multiple instances of Operating Systems concurrently
on a single hardware system where the basic resources are driven by a
Linux instance. The library aims to provide long term stable C API
to interact with Linux virtualization technologies.



Authors:
--------
    Daniel Veillard <veillard@redhat.com>
    Karel Zak <kzak@redhat.com>


%package doc
Summary:        API reference and website documentation
Group:          Development/Libraries/C and C++

%description doc
Includes the API reference for the libvirt C library, and a complete
copy of the libvirt.org website documentation.

%if %{with_libvirtd}

%package daemon
Summary:        Server side daemon and supporting files for libvirt library
Group:          Development/Libraries/C and C++

# All runtime requirements for the libvirt package (runtime requirements
# for subpackages are listed later in those subpackages)

# The client side, i.e. shared libs and virsh are in a subpackage
Requires:       %{name}-client = %{version}-%{release}

# for modprobe of pci devices
Requires:       modutils
# for /sbin/ip & /sbin/tc
Requires:       bridge-utils
Requires:       iproute
Requires:       logrotate

%if %{with_apparmor}
Requires:       apparmor-parser
%endif

%if %{with_udev}
Requires:       udev >= 145
%endif
%if %{with_polkit}
%if 0%{?suse_version} > 1110
Recommends:     polkit >= 0.93
%else
Recommends:     PolicyKit >= 0.6
%endif
%endif
%ifarch i386 i586 i686 x86_64 ia64
# For virConnectGetSysinfo
Requires:       dmidecode
%endif
%if %{with_systemd}
# For service management
%{?systemd_requires}
%endif
%if %{with_numad}
Requires:       numad
%endif

%description daemon
Server side daemon required to manage the virtualization capabilities
of recent versions of Linux. Requires a hypervisor specific sub-RPM
for specific drivers.

%if %{with_network}
%package daemon-config-network
Summary:        Default configuration files for the libvirtd daemon
Group:          Development/Libraries/C and C++

Requires:       libvirt-daemon = %{version}-%{release}
%if %{with_driver_modules}
Requires:       libvirt-daemon-driver-network = %{version}-%{release}
%endif

%description daemon-config-network
Default configuration files for setting up NAT based networking
%endif

%if %{with_nwfilter}

%package daemon-config-nwfilter
Summary:        Network filter configuration files for the libvirtd
Group:          Development/Libraries/C and C++

Requires:       libvirt-daemon = %{version}-%{release}
%if %{with_driver_modules}
Requires:       libvirt-daemon-driver-nwfilter = %{version}-%{release}
%endif

%description daemon-config-nwfilter
Network filter configuration files for the libvirt daemon, used for
cleaning guest network traffic.
%endif

%if %{with_driver_modules}
%if %{with_network}

%package daemon-driver-network
Summary:        Network driver plugin for the libvirtd daemon
Group:          Development/Libraries/C and C++
Requires:       dnsmasq >= 2.41
Requires:       iptables
# TODO Requires:       iptables-ipv6
Requires:       libvirt-daemon = %{version}-%{release}
Requires:       radvd

%description daemon-driver-network
The network driver plugin for the libvirtd daemon, providing
an implementation of the virtual network APIs using the Linux
bridge capabilities.
%endif

%if %{with_nwfilter}

%package daemon-driver-nwfilter
Summary:        A nwfilter driver plugin for the libvirtd daemon
Group:          Development/Libraries/C and C++
Requires:       ebtables
Requires:       iptables
# TODO Requires:       iptables-ipv6
Requires:       libvirt-daemon = %{version}-%{release}

%description daemon-driver-nwfilter
The nwfilter driver plugin for the libvirtd daemon, providing
an implementation of the firewall APIs using the ebtables,
iptables and ip6tables capabilities
%endif

%if %{with_nodedev}

%package daemon-driver-nodedev
Summary:        Nodedev driver plugin for the libvirtd daemon
Group:          Development/Libraries/C and C++
Requires:       libvirt-daemon = %{version}-%{release}

%description daemon-driver-nodedev
The nodedev driver plugin for the libvirtd daemon, providing
an implementation of the node device APIs using the udev
capabilities.
%endif

%if %{with_interface}

%package daemon-driver-interface
Summary:        Interface driver plugin for the libvirtd daemon
Group:          Development/Libraries/C and C++
Requires:       libvirt-daemon = %{version}-%{release}

%description daemon-driver-interface
The interface driver plugin for the libvirtd daemon, providing
an implementation of the network interface APIs using the
netcontrol library
%endif

%package daemon-driver-secret
Summary:        Secret driver plugin for the libvirtd daemon
Group:          Development/Libraries/C and C++
Requires:       libvirt-daemon = %{version}-%{release}

%description daemon-driver-secret
The secret driver plugin for the libvirtd daemon, providing
an implementation of the secret key APIs.

%if %{with_storage}

%package daemon-driver-storage
Summary:        Storage driver plugin for the libvirtd daemon
Group:          Development/Libraries/C and C++
Requires:       libvirt-daemon = %{version}-%{release}
%if %{with_storage_fs}
Requires:       nfs-utils
# For mkfs
Requires:       util-linux
%endif
%if %{with_qemu}
# From QEMU RPMs
Requires:       /usr/bin/qemu-img
%endif
%if %{with_storage_lvm}
# For LVM drivers
Requires:       lvm2
%endif
%if %{with_storage_iscsi}
# For ISCSI driver
Requires:       open-iscsi
%endif
%if %{with_storage_disk}
# For disk driver
Requires:       device-mapper
Requires:       parted
%endif
%if %{with_storage_mpath}
# For multipath support
Requires:       device-mapper
%endif

%description daemon-driver-storage
The storage driver plugin for the libvirtd daemon, providing
an implementation of the storage APIs using LVM, iSCSI,
parted and more.
%endif

%if %{with_qemu}

%package daemon-driver-qemu
Summary:        Qemu driver plugin for the libvirtd daemon
Group:          Development/Libraries/C and C++
Requires:       libvirt-daemon = %{version}-%{release}
# There really is a hard cross-driver dependency here
Requires:       /usr/bin/qemu-img
Requires:       libvirt-daemon-driver-network = %{version}-%{release}
# For image compression
Requires:       bzip2
Requires:       gzip
Requires:       xz
%if 0%{?suse_version} > 1210
Requires:       lzop
%endif
%ifarch %{ix86} x86_64 s390x
Requires:       qemu-kvm
%else
Requires:       qemu
%endif

%description daemon-driver-qemu
The qemu driver plugin for the libvirtd daemon, providing
an implementation of the hypervisor driver APIs using QEMU.
%endif

%if %{with_lxc}

%package daemon-driver-lxc
Summary:        LXC driver plugin for the libvirtd daemon
Group:          Development/Libraries/C and C++
Requires:       libvirt-daemon = %{version}-%{release}
# There really is a hard cross-driver dependency here
Requires:       SUSEConnect
Requires:       libvirt-daemon-driver-network = %{version}-%{release}

%description daemon-driver-lxc
The LXC driver plugin for the libvirtd daemon, providing
an implementation of the hypervisor driver APIs using
the Linux kernel
%endif

%if %{with_uml}

%package daemon-driver-uml
Summary:        Uml driver plugin for the libvirtd daemon
Group:          Development/Libraries/C and C++
Requires:       libvirt-daemon = %{version}-%{release}

%description daemon-driver-uml
The UML driver plugin for the libvirtd daemon, providing
an implementation of the hypervisor driver APIs using
User Mode Linux
%endif

%if %{with_xen}

%package daemon-driver-xen
Summary:        Xen driver plugin for the libvirtd daemon
Group:          Development/Libraries/C and C++
Requires:       libvirt-daemon = %{version}-%{release}

%description daemon-driver-xen
The Xen driver plugin for the libvirtd daemon, providing
an implementation of the hypervisor driver APIs using Xen.
%endif

%if %{with_vbox}

%package daemon-driver-vbox
Summary:        VirtualBox driver plugin for the libvirtd daemon
Group:          Development/Libraries/C and C++
Requires:       libvirt-daemon = %{version}-%{release}

%description daemon-driver-vbox
The vbox driver plugin for the libvirtd daemon, providing
an implementation of the hypervisor driver APIs using
VirtualBox
%endif

%if %{with_libxl}

%package daemon-driver-libxl
Summary:        Libxl driver plugin for the libvirtd daemon
Group:          Development/Libraries/C and C++
Requires:       libvirt-daemon = %{version}-%{release}

%description daemon-driver-libxl
The Libxl driver plugin for the libvirtd daemon, providing
an implementation of the hypervisor driver APIs using libxl.
%endif
%endif # with_driver_modules

%if %{with_qemu}

%package daemon-qemu
Summary:        Server side daemon & driver required to run QEMU guests
Group:          Development/Libraries/C and C++

Requires:       libvirt-daemon = %{version}-%{release}
%if %{with_driver_modules}
%if %{with_interface}
Requires:       libvirt-daemon-driver-interface = %{version}-%{release}
%endif
Requires:       libvirt-daemon-driver-network = %{version}-%{release}
Requires:       libvirt-daemon-driver-nodedev = %{version}-%{release}
Requires:       libvirt-daemon-driver-nwfilter = %{version}-%{release}
Requires:       libvirt-daemon-driver-qemu = %{version}-%{release}
Requires:       libvirt-daemon-driver-secret = %{version}-%{release}
Requires:       libvirt-daemon-driver-storage = %{version}-%{release}
%endif

%description daemon-qemu
Server side daemon and driver required to manage the virtualization
capabilities of the QEMU emulators
%endif

%if %{with_lxc}

%package daemon-lxc
Summary:        Server side daemon & driver required to run LXC guests
Group:          Development/Libraries/C and C++

Requires:       libvirt-daemon = %{version}-%{release}
%if %{with_driver_modules}
%if %{with_interface}
Requires:       libvirt-daemon-driver-interface = %{version}-%{release}
%endif
Requires:       libvirt-daemon-driver-lxc = %{version}-%{release}
Requires:       libvirt-daemon-driver-network = %{version}-%{release}
Requires:       libvirt-daemon-driver-nodedev = %{version}-%{release}
Requires:       libvirt-daemon-driver-nwfilter = %{version}-%{release}
Requires:       libvirt-daemon-driver-secret = %{version}-%{release}
Requires:       libvirt-daemon-driver-storage = %{version}-%{release}
%endif

%description daemon-lxc
Server side daemon and driver required to manage the virtualization
capabilities of LXC
%endif

%if %{with_uml}

%package daemon-uml
Summary:        Server side daemon & driver required to run UML guests
Group:          Development/Libraries/C and C++

Requires:       libvirt-daemon = %{version}-%{release}
%if %{with_driver_modules}
%if %{with_interface}
Requires:       libvirt-daemon-driver-interface = %{version}-%{release}
%endif
Requires:       libvirt-daemon-driver-network = %{version}-%{release}
Requires:       libvirt-daemon-driver-nodedev = %{version}-%{release}
Requires:       libvirt-daemon-driver-nwfilter = %{version}-%{release}
Requires:       libvirt-daemon-driver-secret = %{version}-%{release}
Requires:       libvirt-daemon-driver-storage = %{version}-%{release}
Requires:       libvirt-daemon-driver-uml = %{version}-%{release}
%endif

%description daemon-uml
Server side daemon and driver required to manage the virtualization
capabilities of UML
%endif

%if %{with_xen} || %{with_libxl}

%package daemon-xen
Summary:        Server side daemon & driver required to run XEN guests
Group:          Development/Libraries/C and C++

Requires:       libvirt-daemon = %{version}-%{release}
%if %{with_driver_modules}
%if %{with_xen}
Requires:       libvirt-daemon-driver-xen = %{version}-%{release}
%endif
%if %{with_libxl}
Requires:       libvirt-daemon-driver-libxl = %{version}-%{release}
%endif
%if %{with_interface}
Requires:       libvirt-daemon-driver-interface = %{version}-%{release}
%endif
Requires:       libvirt-daemon-driver-network = %{version}-%{release}
Requires:       libvirt-daemon-driver-nodedev = %{version}-%{release}
Requires:       libvirt-daemon-driver-nwfilter = %{version}-%{release}
Requires:       libvirt-daemon-driver-secret = %{version}-%{release}
Requires:       libvirt-daemon-driver-storage = %{version}-%{release}
%endif
Requires:       xen

%description daemon-xen
Server side daemon and driver required to manage the virtualization
capabilities of XEN
%endif

%if %{with_vbox}

%package daemon-vbox
Summary:        Server side daemon & driver required to run VirtualBox guests
Group:          Development/Libraries/C and C++
Requires:       libvirt-daemon = %{version}-%{release}
%if %{with_driver_modules}
%if %{with_interface}
Requires:       libvirt-daemon-driver-interface = %{version}-%{release}
%endif
Requires:       libvirt-daemon-driver-network = %{version}-%{release}
Requires:       libvirt-daemon-driver-nodedev = %{version}-%{release}
Requires:       libvirt-daemon-driver-nwfilter = %{version}-%{release}
Requires:       libvirt-daemon-driver-secret = %{version}-%{release}
Requires:       libvirt-daemon-driver-storage = %{version}-%{release}
Requires:       libvirt-daemon-driver-vbox = %{version}-%{release}
%endif
Requires:       virtualbox

%description daemon-vbox
Server side daemon and driver required to manage the virtualization
capabilities of VirtualBox
%endif
%endif # with_libvirtd

%package client
Summary:        Client side library and utilities of the libvirt library
Group:          Development/Libraries/C and C++
Requires:       ncurses
Requires:       readline
# So remote clients can access libvirt over SSH tunnel
# (client invokes 'nc' against the UNIX socket on the server)
Requires:       netcat-openbsd
# Needed by libvirt-guests init script.
Requires:       gettext-runtime
# Needed by virt-pki-validate script.
Requires:       gnutls
%if %{with_sasl}
Requires:       cyrus-sasl
# Not technically required, but makes 'out-of-box' config
# work correctly & doesn't have onerous dependencies
Requires:       cyrus-sasl-digestmd5
%endif

%description client
Shared libraries and client binaries needed to access to the
virtualization capabilities of recent versions of Linux (and other OSes).

%package devel
Summary:        Libraries, includes, etc. to compile with the libvirt library
Group:          Development/Libraries/C and C++
Requires:       %{name}-client = %{version}-%{release}
Requires:       %{name}-doc = %{version}-%{release}
Requires:       pkg-config

%description devel
Include header files & development libraries for the libvirt C library.


%if %{with_sanlock}

%package lock-sanlock
Summary:        Sanlock lock manager plugin for QEMU driver
Group:          Development/Libraries/C and C++
Requires:       sanlock >= 2.4
# for virt-sanlock-cleanup require augeas
Requires:       %{name}-client = %{version}-%{release}
Requires:       %{name}-daemon = %{version}-%{release}
Requires:       augeas

%description lock-sanlock
Includes the Sanlock lock manager plugin for the QEMU driver
%endif

%if %{with_lxc}

%package login-shell
Summary:        Login shell for connecting users to an LXC container
Group:          Development/Libraries/C and C++
Requires:       %{name}-client = %{version}-%{release}

%description login-shell
Provides the set-uid virt-login-shell binary that is used to
connect a user to an LXC container when they login, by switching
namespaces.
%endif

%prep
%setup -q
%patch0 -p1
%patch1 -p1
%patch2 -p1
%patch3 -p1
%patch4 -p1
%patch5 -p1
%patch6 -p1
%patch7 -p1
%patch8 -p1
%patch9 -p1
%patch10 -p1
%patch11 -p1
%patch12 -p1
%patch13 -p1
%patch14 -p1
%patch15 -p1
%patch16 -p1
%patch17 -p1
%patch18 -p1
%patch19 -p1
%patch20 -p1
%patch21 -p1
%patch22 -p1
%patch23 -p1
%patch24 -p1
%patch25 -p1
%patch26 -p1
%patch27 -p1
%patch28 -p1
%patch29 -p1
%patch30 -p1
%patch31 -p1
%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
%patch150 -p1
%patch152 -p1
%patch153 -p1
%patch154 -p1
%patch155 -p1
%patch156 -p1
%patch200 -p1
%patch201 -p1
%patch202 -p1
%patch203 -p1
%patch204 -p1
%patch205 -p1
%patch206 -p1
%patch207 -p1
%patch208 -p1
%patch209 -p1
%patch210 -p1
%if %{with_apparmor}
%patch250 -p1
%patch251 -p1
%endif
%if %{with_netcontrol}
%patch300 -p1
%endif

%build
%if ! %{with_xen}
%define _without_xen --without-xen
%endif
%if ! %{with_qemu}
%define _without_qemu --without-qemu
%endif
%if ! %{with_openvz}
%define _without_openvz --without-openvz
%endif
%if ! %{with_lxc}
%define _without_lxc --without-lxc
%endif
%if ! %{with_vbox}
%define _without_vbox --without-vbox
%endif
%if ! %{with_xenapi}
%define _without_xenapi --without-xenapi
%endif
%if ! %{with_uml}
%define _without_uml --without-uml
%endif
%if ! %{with_phyp}
%define _without_phyp --without-phyp
%endif
%if ! %{with_esx}
%define _without_esx --without-esx
%endif
%if ! %{with_vmware}
%define _without_vmware --without-vmware
%endif
%if ! %{with_hyperv}
%define _without_hyperv --without-hyperv
%endif
%if ! %{with_parallels}
%define _without_parallels --without-parallels
%endif
%if ! %{with_libxl}
%define _without_libxl --without-libxl
%endif
%if ! %{with_libvirtd}
%define _without_libvirtd --without-libvirtd
%endif
%if ! %{with_storage_fs}
%define _without_storage_fs --without-storage-fs
%endif
%if ! %{with_storage_lvm}
%define _without_storage_lvm --without-storage-lvm
%endif
%if ! %{with_storage_iscsi}
%define _without_storage_iscsi --without-storage-iscsi
%endif
%if ! %{with_storage_disk}
%define _without_storage_disk --without-storage-disk
%endif
%if ! %{with_storage_mpath}
%define _without_storage_mpath --without-storage-mpath
%endif
%if ! %{with_storage_rbd}
%define _without_storage_rbd --without-storage-rbd
%endif
%if ! %{with_storage_sheepdog}
%define _without_storage_sheepdog --without-storage-sheepdog
%endif
%if ! %{with_storage_gluster}
%define _without_storage_gluster --without-storage-gluster
%endif
%if ! %{with_numactl}
%define _without_numactl --without-numactl
%endif
%if ! %{with_numad}
%define _without_numad --without-numad
%endif
%if ! %{with_selinux}
%define _without_selinux --without-selinux
%endif
%if ! %{with_apparmor}
%define _without_apparmor --without-apparmor
%else
%define _with_apparmor_profiles --with-apparmor-profiles
%endif
%if ! %{with_capng}
%define _without_capng --without-capng
%endif
%if ! %{with_fuse}
%define _without_fuse --without-fuse
%endif
%if ! %{with_netcf}
%define _without_netcf --without-netcf
%endif
%if ! %{with_netcontrol}
%define _without_netcontrol --without-netcontrol
%endif
%if ! %{with_udev}
%define _without_udev --without-udev
%endif
%if ! %{with_yajl}
%define _without_yajl --without-yajl
%endif
%if ! %{with_macvtap}
%define _without_macvtap --without-macvtap
%endif
%if ! %{with_polkit}
%define _without_polkit --without-polkit
%endif
%if ! %{with_audit}
%define _without_audit --without-audit
%endif
%if ! %{with_dtrace}
%define _without_dtrace --without-dtrace
%endif
%if ! %{with_interface}
%define _without_interface --without-interface
%endif
%if ! %{with_network}
%define _without_network --without-network
%endif
%if ! %{with_sasl}
%define _without_sasl --without-sasl
%endif
%if ! %{with_avahi}
%define _without_avahi --without-avahi
%endif
%if ! %{with_libpcap}
%define _without_libpcap --without-libpcap
%endif
%if ! %{with_sanlock}
%define _without_sanlock --without-sanlock
%endif
%if %{with_systemd}
%define init_scripts --with-init_script=systemd+redhat
%else
%define init_scripts --with-init_script=redhat
%endif
%if ! %{with_driver_modules}
%define _without_driver_modules --without-driver-modules
%endif
%if %{with_firewalld}
%define _with_firewalld --with-firewalld
%endif
%if ! %{with_systemd_daemon}
%define _without_systemd_daemon --without-systemd-daemon
%endif

%if %{with_selinux}
%define with_selinux_mount --with-selinux-mount="/sys/fs/selinux"
%endif

autoreconf -f -i
export CFLAGS="$RPM_OPT_FLAGS"
rm -f po/stamp-po
%configure --disable-static --with-pic \
           %{?_without_xen} \
           %{?_without_qemu} \
           %{?_without_openvz} \
           %{?_without_lxc} \
           %{?_without_vbox} \
           %{?_without_libxl} \
           %{?_without_xenapi} \
           %{?_without_sasl} \
           %{?_without_avahi} \
           %{?_without_polkit} \
           %{?_without_libvirtd} \
           %{?_without_uml} \
           %{?_without_phyp} \
           %{?_without_esx} \
           %{?_without_hyperv} \
           %{?_without_vmware} \
           %{?_without_parallels} \
           %{?_without_interface} \
           %{?_without_network} \
           %{?_without_storage_fs} \
           %{?_without_storage_lvm} \
           %{?_without_storage_iscsi} \
           %{?_without_storage_disk} \
           %{?_without_storage_mpath} \
           %{?_without_storage_rbd} \
           %{?_without_storage_sheepdog} \
           %{?_without_storage_gluster} \
           %{?_without_numactl} \
           %{?_without_numad} \
           %{?_without_capng} \
           %{?_without_fuse} \
           %{?_without_netcf} \
           %{?_without_netcontrol} \
           %{?_without_selinux} \
           %{?_with_selinux_mount} \
           %{?_without_apparmor} \
           %{?_with_apparmor_profiles} \
           %{?_without_udev} \
           %{?_without_yajl} \
           %{?_without_sanlock} \
           %{?_without_libpcap} \
           %{?_without_macvtap} \
           %{?_without_audit} \
           %{?_without_dtrace} \
           %{?_without_driver_modules} \
           %{?_with_firewalld} \
           %{?_without_systemd_daemon} \
           --libexecdir=%{_libdir}/%{name} \
           --with-qemu-user=%{qemu_user} \
           --with-qemu-group=%{qemu_group} \
           --without-pm-utils \
           %{init_scripts} \
           ac_cv_path_MODPROBE=/sbin/modprobe \
           ac_cv_path_UDEVADM=/sbin/udevadm \
           ac_cv_path_SHOWMOUNT=/usr/sbin/showmount
make V=1 %{?jobs:-j%jobs} DOCS_DIR=%{_docdir}/%{name}-python EXAMPLE_DIR=%{_docdir}/%{name}-python/examples HTML_DIR=%{_docdir}/%{name}
gzip -9 ChangeLog

%install
%makeinstall SYSTEMD_UNIT_DIR=%{_unitdir} DOCS_DIR=%{_docdir}/%{name}-python EXAMPLE_DIR=%{_docdir}/%{name}-python/examples HTML_DIR=%{_docdir}/%{name}
for i in object-events dominfo domsuspend hellolibvirt openauth xml/nwfilter systemtap
do
  (cd examples/$i ; make clean ; rm -rf .deps .libs Makefile Makefile.in)
done
cp examples/lxcconvert/virt-lxc-convert $RPM_BUILD_ROOT%{_bindir}
rm -f $RPM_BUILD_ROOT%{_libdir}/*.la
rm -f $RPM_BUILD_ROOT%{_libdir}/*.a
rm -f $RPM_BUILD_ROOT%{_libdir}/%{name}/lock-driver/*.la
rm -f $RPM_BUILD_ROOT%{_libdir}/%{name}/lock-driver/*.a
%if %{with_driver_modules}
rm -f $RPM_BUILD_ROOT%{_libdir}/%{name}/connection-driver/*.la
rm -f $RPM_BUILD_ROOT%{_libdir}/%{name}/connection-driver/*.a
%endif
# remove currently unsupported locale(s)
rm -rf $RPM_BUILD_ROOT/usr/share/locale/sr@latin
%if 0%{?suse_version} < 1130
rm -rf $RPM_BUILD_ROOT/usr/share/locale/vi_VN
%endif
# temporarily remove polkit ACL policiy configuration - bnc#827644
rm -f $RPM_BUILD_ROOT/%{_datadir}/polkit-1/actions/org.libvirt.api.policy
mkdir -p $RPM_BUILD_ROOT/%{_localstatedir}/lib/libvirt
mkdir -p $RPM_BUILD_ROOT/%{_sysconfdir}/libvirt/hooks
%find_lang %{name}
# Add a README to the libvirt package with a note about the empty
# file list
cat > $RPM_BUILD_ROOT%{_docdir}/libvirt/libvirt.README << 'EOF'
The libvirt package no longer contains any files.  It exists now
only to fulfill its 'Provides' contract.
EOF
%if %{with_network}
install -d -m 0755 $RPM_BUILD_ROOT%{_localstatedir}/lib/libvirt/dnsmasq/
install -d -m 0755 $RPM_BUILD_ROOT%{_datadir}/libvirt/networks/
cp $RPM_BUILD_ROOT%{_sysconfdir}/libvirt/qemu/networks/default.xml \
   $RPM_BUILD_ROOT%{_datadir}/libvirt/networks/default.xml
rm -f $RPM_BUILD_ROOT%{_sysconfdir}/libvirt/qemu/networks/default.xml
rm -f $RPM_BUILD_ROOT%{_sysconfdir}/libvirt/qemu/networks/autostart/default.xml
# Strip auto-generated UUID - we need it generated per-install
sed -i -e "/<uuid>/d" $RPM_BUILD_ROOT%{_datadir}/libvirt/networks/default.xml
%else
rm -f $RPM_BUILD_ROOT%{_sysconfdir}/libvirt/qemu/networks/default.xml
rm -f $RPM_BUILD_ROOT%{_sysconfdir}/libvirt/qemu/networks/autostart/default.xml
%endif
%if ! %{with_nwfilter}
rm -rf $RPM_BUILD_ROOT%{_sysconfdir}/libvirt/nwfilter
rm -rf $RPM_BUILD_ROOT%{_libdir}/%{name}/connection-driver/libvirt_driver_nwfilter.so
%endif
%if %{with_lxc}
cat > $RPM_BUILD_ROOT%{_docdir}/libvirt/libvirt-daemon-lxc.README << 'EOF'
Any empty package encapsulating requirements for a libvirtd capable
of managing LXC.
EOF
%else
rm -rf $RPM_BUILD_ROOT%{_sysconfdir}/libvirt/lxc.conf
rm -f $RPM_BUILD_ROOT%{_datadir}/augeas/lenses/libvirtd_lxc.aug
rm -f $RPM_BUILD_ROOT%{_datadir}/augeas/lenses/tests/test_libvirtd_lxc.aug
rm -rf $RPM_BUILD_ROOT%{_sysconfdir}/logrotate.d/libvirtd.lxc
%endif
%if %{with_qemu}
cat > $RPM_BUILD_ROOT%{_docdir}/libvirt/libvirt-daemon-qemu.README << 'EOF'
Any empty package encapsulating requirements for a libvirtd capable
of managing QEMU/KVM.
EOF
%else
rm -rf $RPM_BUILD_ROOT%{_sysconfdir}/libvirt/qemu.conf
rm -f $RPM_BUILD_ROOT%{_datadir}/augeas/lenses/libvirtd_qemu.aug
rm -f $RPM_BUILD_ROOT%{_datadir}/augeas/lenses/tests/test_libvirtd_qemu.aug
rm -rf $RPM_BUILD_ROOT%{_sysconfdir}/logrotate.d/libvirtd.qemu
%endif
%if %{with_uml}
cat > $RPM_BUILD_ROOT%{_docdir}/libvirt/libvirt-daemon-uml.README << 'EOF'
Any empty package encapsulating requirements for a libvirtd capable
of managing UML.
EOF
%else
rm -rf $RPM_BUILD_ROOT%{_sysconfdir}/logrotate.d/libvirtd.uml
%endif
%if %{with_vbox}
cat > $RPM_BUILD_ROOT%{_docdir}/libvirt/libvirt-daemon-vbox.README << 'EOF'
Any empty package encapsulating requirements for a libvirtd capable
of managing VirtualBox.
EOF
%endif
%if %{with_xen} || %{with_libxl}
cat > $RPM_BUILD_ROOT%{_docdir}/libvirt/libvirt-daemon-xen.README << 'EOF'
Any empty package encapsulating requirements for a libvirtd capable
of managing Xen.
EOF
%endif
%if ! %{with_sanlock}
rm -f $RPM_BUILD_ROOT%{_datadir}/augeas/lenses/libvirt_sanlock.aug
rm -f $RPM_BUILD_ROOT%{_datadir}/augeas/lenses/tests/test_libvirt_sanlock.aug
%endif

# init scripts
mkdir -p $RPM_BUILD_ROOT%{_sysconfdir}/init.d
mkdir -p $RPM_BUILD_ROOT%{_localstatedir}/adm/fillup-templates
%if %{with_libvirtd}
# Currently using our own libvirtd init script
rm -f $RPM_BUILD_ROOT%{_sysconfdir}/rc.d/init.d/libvirtd
%if %{with_systemd}
ln -s %{_sbindir}/service $RPM_BUILD_ROOT%{_sbindir}/rclibvirtd
%else
install %SOURCE1 $RPM_BUILD_ROOT%{_sysconfdir}/init.d/libvirtd
ln -s /etc/init.d/libvirtd $RPM_BUILD_ROOT%{_sbindir}/rclibvirtd
%endif
mv $RPM_BUILD_ROOT%{_sysconfdir}/sysconfig/libvirtd $RPM_BUILD_ROOT%{_localstatedir}/adm/fillup-templates/sysconfig.libvirtd
rm -f $RPM_BUILD_ROOT/usr/lib/sysctl.d/libvirtd.conf
# For other services, use the in-tree scripts
%if %{with_systemd}
rm -f $RPM_BUILD_ROOT%{_sysconfdir}/rc.d/init.d/virtlockd
ln -s %{_sbindir}/service $RPM_BUILD_ROOT%{_sbindir}/rcvirtlockd
%else
mv $RPM_BUILD_ROOT%{_sysconfdir}/rc.d/init.d/virtlockd $RPM_BUILD_ROOT%{_sysconfdir}/init.d/virtlockd
ln -s /etc/init.d/virtlockd $RPM_BUILD_ROOT%{_sbindir}/rcvirtlockd
%endif
mv $RPM_BUILD_ROOT%{_sysconfdir}/sysconfig/virtlockd $RPM_BUILD_ROOT%{_localstatedir}/adm/fillup-templates/sysconfig.virtlockd
#install firewall definitions format is described here:
#/usr/share/SuSEfirewall2/services/TEMPLATE
mkdir -p $RPM_BUILD_ROOT/%{_fwdefdir}
install -m 644 %{S:2} $RPM_BUILD_ROOT/%{_fwdefdir}/libvirtd-relocation-server
%endif
%if %{with_systemd}
rm -f $RPM_BUILD_ROOT%{_sysconfdir}/rc.d/init.d/libvirt-guests
ln -s %{_sbindir}/service $RPM_BUILD_ROOT%{_sbindir}/rclibvirt-guests
%else
mv $RPM_BUILD_ROOT%{_sysconfdir}/rc.d/init.d/libvirt-guests $RPM_BUILD_ROOT%{_sysconfdir}/init.d/libvirt-guests
mkdir -p $RPM_BUILD_ROOT%{_sbindir}
ln -s %{_sysconfdir}/init.d/libvirt-guests $RPM_BUILD_ROOT%{_sbindir}/rclibvirt-guests
%endif
mv $RPM_BUILD_ROOT%{_sysconfdir}/sysconfig/libvirt-guests $RPM_BUILD_ROOT%{_localstatedir}/adm/fillup-templates/sysconfig.libvirt-guests
%fdupes -s $RPM_BUILD_ROOT

%clean
rm -rf $RPM_BUILD_ROOT

# Ignore 'make check' on older code base
%if 0%{?suse_version} >= 1210

%check
cd tests
make
# These tests don't current work in a mock build root
# virnetsockettest: fails on NETLINK (missing under qemu-user emulation)
for i in nodeinfotest seclabeltest virnetsockettest
do
  rm -f $i
  printf 'int main(void) { return 0; }' > $i.c
  printf '#!/bin/sh\nexit 0\n' > $i
  chmod +x $i
done
if ! make check VIR_TEST_DEBUG=1
then
  cat test-suite.log || true
  exit 1
fi
%endif

%if %{with_libvirtd}

%pre daemon
%if %{with_systemd}
%service_add_pre libvirtd.service
%service_add_pre virtlockd.service virtlockd.socket
%endif
%{_bindir}/getent group libvirt >/dev/null || \
  %{_sbindir}/groupadd -r libvirt 2>/dev/null

%post daemon
/sbin/ldconfig
%if %{with_systemd}
%service_add_post libvirtd.service
%service_add_post virtlockd.service virtlockd.socket
%endif
%{fillup_only -n libvirtd}
%{fillup_only -n virtlockd}

%preun daemon
%if %{with_systemd}
%service_del_preun libvirtd.service
%service_del_preun virtlockd.service virtlockd.socket
%else
%stop_on_removal libvirtd
%stop_on_removal virtlockd
%endif

%postun daemon
/sbin/ldconfig
%if %{with_systemd}
%service_del_postun libvirtd.service
%service_del_postun virtlockd.service virtlockd.socket
%else
%restart_on_update libvirtd
%restart_on_update virtlockd
%endif
%insserv_cleanup

%if %{with_network}
%post daemon-config-network
# Install the default network if one doesn't exist
if test $1 -eq 1 && test ! -f %{_sysconfdir}/libvirt/qemu/networks/default.xml ; then
    UUID=`/usr/bin/uuidgen`
    sed -e "s,</name>,</name>\n  <uuid>$UUID</uuid>," \
         < %{_datadir}/libvirt/networks/default.xml \
         > %{_sysconfdir}/libvirt/qemu/networks/default.xml
fi
%endif
%endif # with_libvirtd

%post client
/sbin/ldconfig
%if %{with_systemd}
%service_add_post libvirt-guests.service
%endif
%{fillup_only -n libvirt-guests}

%preun client
%if %{with_systemd}
%service_del_preun libvirt-guests.service
%else
%stop_on_removal libvirt-guests
%endif
if [ $1 = 0 ]; then
    rm -f /var/lib/libvirt/libvirt-guests
fi

%postun client
/sbin/ldconfig
%if %{with_systemd}
%service_del_postun libvirt-guests.service
%endif
%insserv_cleanup

%files
%defattr(-, root, root)
%doc %{_docdir}/%{name}/libvirt.README

%if %{with_libvirtd}

%files daemon
%defattr(-, root, root)
%{_sbindir}/libvirtd
%{_sbindir}/virtlockd
%dir %{_libdir}/%{name}
%dir %attr(0700, root, root) %{_sysconfdir}/libvirt/
%dir %attr(0700, root, root) %{_sysconfdir}/libvirt/hooks
%{_localstatedir}/adm/fillup-templates/sysconfig.libvirtd
%{_localstatedir}/adm/fillup-templates/sysconfig.virtlockd
%if %{with_systemd}
%{_unitdir}/libvirtd.service
%{_unitdir}/virtlockd.service
%{_unitdir}/virtlockd.socket
%else
%config /etc/init.d/libvirtd
%config /etc/init.d/virtlockd
%endif
%{_sbindir}/rclibvirtd
%{_sbindir}/rcvirtlockd
%config(noreplace) %{_sysconfdir}/libvirt/libvirtd.conf
%config(noreplace) %{_sysconfdir}/logrotate.d/libvirtd
%config(noreplace) %{_sysconfdir}/libvirt/virtlockd.conf
%dir %{_datadir}/augeas/
%dir %{_datadir}/augeas/lenses
%dir %{_datadir}/augeas/lenses/tests
%{_datadir}/augeas/lenses/libvirtd.aug
%{_datadir}/augeas/lenses/tests/test_libvirtd.aug
%{_datadir}/augeas/lenses/virtlockd.aug
%{_datadir}/augeas/lenses/tests/test_virtlockd.aug
%{_datadir}/augeas/lenses/libvirt_lockd.aug
%{_datadir}/augeas/lenses/tests/test_libvirt_lockd.aug
%if %{with_dtrace}
%{_datadir}/systemtap/tapset/libvirt_probes.stp
%{_datadir}/systemtap/tapset/libvirt_functions.stp
%endif
%dir %{_localstatedir}/lib/libvirt/
%dir %attr(0711, root, root) %{_localstatedir}/lib/libvirt/images/
%dir %attr(0711, root, root) %{_localstatedir}/lib/libvirt/filesystems/
%dir %attr(0711, root, root) %{_localstatedir}/lib/libvirt/boot/
%dir %attr(0711, root, root) %{_localstatedir}/cache/libvirt/
%dir %attr(0700, root, root) %{_localstatedir}/log/libvirt/
%dir %attr(0755, root, root) %{_libdir}/%{name}/lock-driver
%attr(0755, root, root) %{_libdir}/%{name}/lock-driver/lockd.so
%if %{with_polkit}
%if 0%{?suse_version} > 1110
%{_datadir}/polkit-1/actions/org.libvirt.unix.policy
%else
%{_datadir}/PolicyKit/policy/org.libvirt.unix.policy
%endif
%endif
%attr(0755, root, root) %{_libdir}/%{name}/libvirt_iohelper
%doc %{_mandir}/man8/libvirtd.8*
%{_mandir}/man8/virtlockd.8*
%if %{with_apparmor}
%dir %{_sysconfdir}/apparmor.d
%dir %{_sysconfdir}/apparmor.d/abstractions
%dir %{_sysconfdir}/apparmor.d/libvirt
%config(noreplace) %{_sysconfdir}/apparmor.d/usr.sbin.libvirtd
%config(noreplace) %{_sysconfdir}/apparmor.d/usr.lib.libvirt.virt-aa-helper
%config(noreplace) %{_sysconfdir}/apparmor.d/abstractions/libvirt-qemu
%config(noreplace) %{_sysconfdir}/apparmor.d/abstractions/libvirt-lxc
%config(noreplace) %{_sysconfdir}/apparmor.d/libvirt/TEMPLATE.lxc
%config(noreplace) %{_sysconfdir}/apparmor.d/libvirt/TEMPLATE.qemu
%{_libdir}/%{name}/virt-aa-helper
%endif
%config %{_fwdefdir}/libvirtd-relocation-server

%if ! %{with_driver_modules}
%if %{with_network} || %{with_qemu}
%dir %attr(0700, root, root) %{_sysconfdir}/libvirt/qemu/
%endif
%if %{with_network}
%dir %attr(0700, root, root) %{_sysconfdir}/libvirt/qemu/networks/
%dir %attr(0700, root, root) %{_sysconfdir}/libvirt/qemu/networks/autostart
%dir %attr(0700, root, root) %{_localstatedir}/lib/libvirt/network/
%dir %attr(0755, root, root) %{_localstatedir}/lib/libvirt/dnsmasq/
%dir %{_datadir}/libvirt/networks/
%{_datadir}/libvirt/networks/default.xml
%endif
%if %{with_nwfilter}
%dir %attr(0700, root, root) %{_sysconfdir}/libvirt/nwfilter/
%endif
%if %{with_qemu}
%config(noreplace) %{_sysconfdir}/libvirt/qemu.conf
%config(noreplace) %{_sysconfdir}/libvirt/qemu-lockd.conf
%config(noreplace) %{_sysconfdir}/logrotate.d/libvirtd.qemu
%dir %attr(0750, %{qemu_user}, %{qemu_group}) %{_localstatedir}/lib/libvirt/qemu/
%dir %attr(0750, %{qemu_user}, %{qemu_group}) %{_localstatedir}/cache/libvirt/qemu/
%dir %attr(0750, %{qemu_user}, %{qemu_group}) %{_localstatedir}/lib/libvirt/qemu/channel/
%dir %attr(0750, %{qemu_user}, %{qemu_group}) %{_localstatedir}/lib/libvirt/qemu/channel/target/
%dir %attr(0700, root, root) %{_localstatedir}/log/libvirt/qemu/
%{_datadir}/augeas/lenses/libvirtd_qemu.aug
%{_datadir}/augeas/lenses/tests/test_libvirtd_qemu.aug
%endif
%if %{with_lxc}
%config(noreplace) %{_sysconfdir}/libvirt/lxc.conf
%config(noreplace) %{_sysconfdir}/logrotate.d/libvirtd.lxc
%dir %attr(0700, root, root) %{_localstatedir}/lib/libvirt/lxc/
%dir %attr(0700, root, root) %{_localstatedir}/log/libvirt/lxc/
%attr(0755, root, root) %{_libdir}/%{name}/libvirt_lxc
%{_datadir}/augeas/lenses/libvirtd_lxc.aug
%{_datadir}/augeas/lenses/tests/test_libvirtd_lxc.aug
%endif
%if %{with_uml}
%config(noreplace) %{_sysconfdir}/logrotate.d/libvirtd.uml
%dir %attr(0700, root, root) %{_localstatedir}/lib/libvirt/uml/
%dir %attr(0700, root, root) %{_localstatedir}/log/libvirt/uml/
%endif
%if %{with_libxl}
%dir %attr(0700, root, root) %{_localstatedir}/lib/libvirt/libxl/
%dir %attr(0700, root, root) %{_localstatedir}/log/libvirt/libxl/
%endif
%if %{with_storage_disk}
%attr(0755, root, root) %{_libdir}/%{name}/libvirt_parthelper
%endif
%endif # ! %{with_driver_modules}

%if %{with_network}
%files daemon-config-network
%defattr(-, root, root)
%dir %{_datadir}/libvirt/networks/
%{_datadir}/libvirt/networks/default.xml
%endif

%if %{with_nwfilter}

%files daemon-config-nwfilter
%defattr(-, root, root)
%dir %attr(0700, root, root) %{_sysconfdir}/libvirt/nwfilter/
%{_sysconfdir}/libvirt/nwfilter/*.xml
%endif

%if %{with_driver_modules}
%if %{with_interface}

%files daemon-driver-interface
%defattr(-, root, root)
%dir %{_libdir}/%{name}/connection-driver
%{_libdir}/%{name}/connection-driver/libvirt_driver_interface.so
%endif

%if %{with_network}

%files daemon-driver-network
%defattr(-, root, root)
%dir %attr(0700, root, root) %{_sysconfdir}/libvirt/qemu/
%dir %attr(0700, root, root) %{_sysconfdir}/libvirt/qemu/networks/
%dir %attr(0700, root, root) %{_sysconfdir}/libvirt/qemu/networks/autostart
%dir %attr(0700, root, root) %{_localstatedir}/lib/libvirt/network/
%dir %attr(0755, root, root) %{_localstatedir}/lib/libvirt/dnsmasq/
%dir %{_libdir}/%{name}/connection-driver
%{_libdir}/%{name}/connection-driver/libvirt_driver_network.so
%endif

%if %{with_nodedev}

%files daemon-driver-nodedev
%defattr(-, root, root)
%dir %{_libdir}/%{name}/connection-driver
%{_libdir}/%{name}/connection-driver/libvirt_driver_nodedev.so
%endif

%if %{with_nwfilter}

%files daemon-driver-nwfilter
%defattr(-, root, root)
%dir %attr(0700, root, root) %{_sysconfdir}/libvirt/nwfilter/
%dir %{_libdir}/%{name}/connection-driver
%{_libdir}/%{name}/connection-driver/libvirt_driver_nwfilter.so
%endif

%files daemon-driver-secret
%defattr(-, root, root)
%dir %{_libdir}/%{name}/connection-driver
%{_libdir}/%{name}/connection-driver/libvirt_driver_secret.so

%if %{with_storage}

%files daemon-driver-storage
%defattr(-, root, root)
%if %{with_storage_disk}
%attr(0755, root, root) %{_libdir}/%{name}/libvirt_parthelper
%endif
%dir %{_libdir}/%{name}/connection-driver
%{_libdir}/%{name}/connection-driver/libvirt_driver_storage.so
%endif

%if %{with_qemu}

%files daemon-driver-qemu
%defattr(-, root, root)
%dir %attr(0700, root, root) %{_sysconfdir}/libvirt/qemu/
%config(noreplace) %{_sysconfdir}/libvirt/qemu.conf
%config(noreplace) %{_sysconfdir}/libvirt/qemu-lockd.conf
%config(noreplace) %{_sysconfdir}/logrotate.d/libvirtd.qemu
%dir %attr(0750, %{qemu_user}, %{qemu_group}) %{_localstatedir}/lib/libvirt/qemu/
%dir %attr(0750, %{qemu_user}, %{qemu_group}) %{_localstatedir}/cache/libvirt/qemu/
%dir %attr(0750, %{qemu_user}, %{qemu_group}) %{_localstatedir}/lib/libvirt/qemu/channel/
%dir %attr(0750, %{qemu_user}, %{qemu_group}) %{_localstatedir}/lib/libvirt/qemu/channel/target/
%dir %attr(0700, root, root) %{_localstatedir}/log/libvirt/qemu/
%{_datadir}/augeas/lenses/libvirtd_qemu.aug
%{_datadir}/augeas/lenses/tests/test_libvirtd_qemu.aug
%dir %{_libdir}/%{name}/connection-driver
%{_libdir}/%{name}/connection-driver/libvirt_driver_qemu.so
%endif

%if %{with_lxc}

%files daemon-driver-lxc
%defattr(-, root, root)
%config(noreplace) %{_sysconfdir}/libvirt/lxc.conf
%config(noreplace) %{_sysconfdir}/logrotate.d/libvirtd.lxc
%dir %attr(0700, root, root) %{_localstatedir}/lib/libvirt/lxc/
%dir %attr(0700, root, root) %{_localstatedir}/log/libvirt/lxc/
%attr(0755, root, root) %{_libdir}/%{name}/libvirt_lxc
%{_datadir}/augeas/lenses/libvirtd_lxc.aug
%{_datadir}/augeas/lenses/tests/test_libvirtd_lxc.aug
%dir %{_libdir}/%{name}/connection-driver
%{_libdir}/%{name}/connection-driver/libvirt_driver_lxc.so
%attr(0755, root, root) %{_bindir}/virt-lxc-convert
%{_bindir}/virt-create-rootfs
%doc %{_mandir}/man1/virt-create-rootfs.1*
%endif

%if %{with_uml}

%files daemon-driver-uml
%defattr(-, root, root)
%config(noreplace) %{_sysconfdir}/logrotate.d/libvirtd.uml
%dir %attr(0700, root, root) %{_localstatedir}/lib/libvirt/uml/
%dir %attr(0700, root, root) %{_localstatedir}/log/libvirt/uml/
%dir %{_libdir}/%{name}/connection-driver
%{_libdir}/%{name}/connection-driver/libvirt_driver_uml.so
%endif

%if %{with_xen}

%files daemon-driver-xen
%defattr(-, root, root)
%dir %{_libdir}/%{name}/connection-driver
%{_libdir}/%{name}/connection-driver/libvirt_driver_xen.so
%endif

%if %{with_libxl}

%files daemon-driver-libxl
%defattr(-, root, root)
%dir %attr(0700, root, root) %{_localstatedir}/lib/libvirt/libxl/
%dir %attr(0700, root, root) %{_localstatedir}/log/libvirt/libxl/
%dir %{_libdir}/%{name}/connection-driver
%{_libdir}/%{name}/connection-driver/libvirt_driver_libxl.so
%endif

%if %{with_vbox}

%files daemon-driver-vbox
%defattr(-, root, root)
%{_libdir}/%{name}/connection-driver/libvirt_driver_vbox.so
%endif
%endif # with_driver_modules

%if %{with_qemu}

%files daemon-qemu
%defattr(-, root, root)
%doc %{_docdir}/%{name}/libvirt-daemon-qemu.README
%endif

%if %{with_lxc}

%files daemon-lxc
%defattr(-, root, root)
%doc %{_docdir}/%{name}/libvirt-daemon-lxc.README
%endif

%if %{with_uml}

%files daemon-uml
%defattr(-, root, root)
%doc %{_docdir}/%{name}/libvirt-daemon-uml.README
%endif

%if %{with_xen} || %{with_libxl}

%files daemon-xen
%defattr(-, root, root)
%doc %{_docdir}/%{name}/libvirt-daemon-xen.README
%endif

%if %{with_vbox}

%files daemon-vbox
%defattr(-, root, root)
%doc %{_docdir}/%{name}/libvirt-daemon-vbox.README
%endif
%endif # with_libvirtd

%files client -f %{name}.lang
%defattr(-, root, root)
%doc AUTHORS ChangeLog.gz NEWS README COPYING COPYING.LESSER TODO
%doc %{_mandir}/man1/virsh.1*
%doc %{_mandir}/man1/virt-xml-validate.1*
%doc %{_mandir}/man1/virt-pki-validate.1*
%doc %{_mandir}/man1/virt-host-validate.1*
%config(noreplace) %{_sysconfdir}/%{name}/libvirt.conf
%{_bindir}/virsh
%{_bindir}/virt-xml-validate
%{_bindir}/virt-pki-validate
%{_bindir}/virt-host-validate
%dir %{_libdir}/%{name}
%{_libdir}/lib*.so.*
%attr(0755, root, root) %{_libdir}/%{name}/libvirt-guests.sh
%{_localstatedir}/adm/fillup-templates/sysconfig.libvirt-guests
%if %{with_systemd}
%{_unitdir}/libvirt-guests.service
%else
%config /etc/init.d/libvirt-guests
%endif
%{_sbindir}/rclibvirt-guests

%dir %{_datadir}/libvirt/
%dir %{_datadir}/libvirt/schemas/

%{_datadir}/libvirt/schemas/basictypes.rng
%{_datadir}/libvirt/schemas/capability.rng
%{_datadir}/libvirt/schemas/domain.rng
%{_datadir}/libvirt/schemas/domaincommon.rng
%{_datadir}/libvirt/schemas/domainsnapshot.rng
%{_datadir}/libvirt/schemas/interface.rng
%{_datadir}/libvirt/schemas/network.rng
%{_datadir}/libvirt/schemas/networkcommon.rng
%{_datadir}/libvirt/schemas/nodedev.rng
%{_datadir}/libvirt/schemas/nwfilter.rng
%{_datadir}/libvirt/schemas/secret.rng
%{_datadir}/libvirt/schemas/storagecommon.rng
%{_datadir}/libvirt/schemas/storagepool.rng
%{_datadir}/libvirt/schemas/storagevol.rng
%{_datadir}/libvirt/cpu_map.xml
%{_datadir}/libvirt/libvirtLogo.png
%if %{with_sasl}
%dir %{_sysconfdir}/sasl2/
%config(noreplace) %{_sysconfdir}/sasl2/libvirt.conf
%endif

%files devel
%defattr(-, root, root)
%{_includedir}/libvirt
%{_libdir}/*.so
%{_libdir}/pkgconfig/libvirt.pc
%dir %{_datadir}/libvirt/api/
%{_datadir}/libvirt/api/libvirt-api.xml
%{_datadir}/libvirt/api/libvirt-qemu-api.xml
%{_datadir}/libvirt/api/libvirt-lxc-api.xml

%files doc
%defattr(-, root, root)
# Website
%dir %{_docdir}/libvirt
%doc %{_docdir}/%{name}/*.png
%doc %{_docdir}/%{name}/*.html
%doc %{_docdir}/%{name}/*.gif
%doc %{_docdir}/%{name}/*.css
%doc %{_docdir}/%{name}/html
%doc %{_docdir}/%{name}/internals

# API docs
%dir %{_datadir}/gtk-doc/html/libvirt/
%doc %{_datadir}/gtk-doc/html/libvirt/*

%if %{with_sanlock}

%files lock-sanlock
%defattr(-, root, root)
%doc %{_mandir}/man8/virt-sanlock-cleanup.8*
%if %{with_qemu}
%config(noreplace) %{_sysconfdir}/%{name}/qemu-sanlock.conf
%endif
%dir %{_libdir}/%{name}/lock-driver/
%attr(0755, root, root) %{_libdir}/%{name}/lock-driver/sanlock.so
%dir %{_datadir}/augeas/
%dir %{_datadir}/augeas/lenses
%dir %{_datadir}/augeas/lenses/tests
%{_datadir}/augeas/lenses/libvirt_sanlock.aug
%{_datadir}/augeas/lenses/tests/test_libvirt_sanlock.aug
%dir %attr(0700, root, root) %{_localstatedir}/lib/%{name}/sanlock
%{_sbindir}/virt-sanlock-cleanup
%attr(0755, root, root) %{_libdir}/%{name}/libvirt_sanlock_helper
%endif

%if %{with_lxc}

%files login-shell
%defattr(-, root, root)
%config(noreplace) %{_sysconfdir}/libvirt/virt-login-shell.conf
%doc %{_mandir}/man1/virt-login-shell.1*
# setuid binary that needs security audit - bnc#837609
# In the meantime, don't install setuid
#%attr(4755, root, root) %{_bindir}/virt-login-shell
%{_bindir}/virt-login-shell
%endif

%changelog