File virtualbox-ose.spec of Package virtualbox-ose

#
# spec file for package virtualbox-ose (Version 3.2.6)
#
# Copyright (c) 2010 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/
#

# norootforbuild

%define _vbox_instdir  /usr/lib/virtualbox

Name:           virtualbox-ose
BuildRequires:  fdupes
%if %suse_version > 1110
BuildRequires:  acpica dmidecode
%else
BuildRequires:  pmtools
%endif
BuildRequires:  bin86 dev86 libidl-devel libqt4-devel libxslt-devel yasm
BuildRequires:  SDL-devel kernel-syms module-init-tools
BuildRequires:  e2fsprogs-devel libcap-devel libcurl-devel python-devel update-desktop-files
BuildRequires:  hal-devel pulseaudio-devel xorg-x11 xorg-x11-devel xorg-x11-server xorg-x11-server-sdk
BuildRequires:  LibVNCServer-devel gcc43-c++ kbuild pam-devel udev
%ifarch amd64 x86_64 ia32e em64t
BuildRequires:  gcc-32bit hal-32bit
BuildRequires:  xorg-x11-libX11-devel-32bit xorg-x11-libXt-devel-32bit xorg-x11-libs-32bit
BuildRequires:  libgcc-32bit xorg-x11-libXext-devel-32bit xorg-x11-libXmu-devel-32bit
BuildRequires:  gcc43-32bit libgcc-32bit libstdc++43-devel-32bit
%endif
#
ExclusiveArch:  %ix86 x86_64
Version:        3.2.6
Release:        2.<RELEASE1>
Summary:        VirtualBox OSE is an Emulator
License:        GPLv2+
Group:          System/Emulators/PC
Url:            http://www.virtualbox.org/
#
# so you don't need to repack virtualbox by hand, just add new release of VirtualBox-x.x.x-OSE.tar.bz2 and line below with 
# script virtualbox-ose-patch-source.sh will do the job :)
# WARNING: This is not a comment, but the real command to repack souce 
#%(bash %{_sourcedir}/virtualbox-ose-patch-source.sh VirtualBox-%{version}-OSE.tar.bz2)
Source0:        VirtualBox-%{version}-OSE-patched.tar.bz2
Source1:        VirtualBox-%{version}-UserManual.pdf
Source2:        %{name}-60-vboxdrv.rules
Source3:        %{name}-60-vboxguest.rules
Source4:        %{name}-default.virtualbox
Source5:        %{name}-host-kmp-files
Source6:        %{name}-guest-kmp-files
Source7:        %{name}-host-preamble
Source8:        %{name}-guest-preamble
Source9:        %{name}-wrapper.sh
# since 11.3 we need this conf instead of HAL's fdi to define vbox mouse
Source10:       %{name}-60-vboxmouse.conf
# init script to start virtual boxes during boot, to be configured via /etc/sysconfig/vbox bnc#582398
Source12:       %{name}-vboxes
Source13:       %{name}-sysconfig.vbox
Source98:       %{name}-%{version}-rpmlintrc
Source99:       %{name}-patch-source.sh
#rework init script 
Patch1:         vbox-vboxdrv-init-script.diff
Patch2:         vbox-vboxadd-init-script.diff
#disable update in vbox gui
Patch3:         vbox-disable-updates.diff
#fix return values which trigger post build checks and coused build error - should goes to upstream
Patch4:         vbox-ret-in-nonvoid-fnc.diff
#PATCH-FIX-OPENSUSE implement messagebox (VBoxPermissionMessage app), which is displayed, when user
#try to start VirtualBox and is not memeber of vboxusers group
Patch99:        vbox-permissions_warning.diff
#
BuildRoot:      %{_tmppath}/%{name}-%{version}-build
PreReq:         pwdutils permissions
Requires:       %{name}-host-kmp = %version
#

%description
VirtualBox OSE is an extremely feature rich, high performance product
for enterprise customers, it is also the only professional solution
that is freely available as Open Source Software under the terms of the
GNU Public License (GPL).
#########################
%package host-KMP

License:        GPLv2+
Summary:        Host kernel module for VirtualBox
Group:          System/Emulators/PC
# SUSE specify macro to define host kmp package
%suse_kernel_module_package -p %{S:7} -n %{name}-host -f %{S:5} kdump um xen xenpae
#

%description host-KMP
This package contains the kernel-module for VirtualBox OSE.
##########################
%package guest-KMP

License:        GPLv2+
Summary:        Guest kernel modules for VirtualBox
Group:          System/Emulators/PC
#SUSE specify macro to define guest kmp package
%suse_kernel_module_package -p %{S:8} -n %{name}-guest -f %{S:6} kdump um xen xenpae
#

%description guest-KMP
This package contains the kernel-module for VirtualBox OSE.
##########################################
%package -n xorg-x11-driver-virtualbox-ose
License:        GPLv2+
Summary:        VirtualBox X11 drivers for mouse and video
Group:          System/X11/Servers/XF86_4
Requires:       %{name}-guest-kmp = %version
Supplements:    modalias(pci:v000080EEd0000BEEFsv*sd*bc*sc*i*)
#

%description -n xorg-x11-driver-virtualbox-ose
VirtualBox 
This package contains X11 guest utilities and X11 guest mouse and video drivers
####################
%package guest-tools
License:        GPLv2+
Summary:        VirtualBox guest tools
Group:          System/Emulators/PC
Requires:       %{name}-guest-kmp = %version
Supplements:    modalias(pci:v000080EEd0000BEEFsv*sd*bc*sc*i*)
#

%description guest-tools
VirtualBox guest addition tools.
###########################
#%package -n python-%{name}
#Summary:    Python bindings for %{name}
#Group:      Development/Libraries
#Requires:   virtualxox-ose = %{version}

#%description -n python-%{name}
#Python XPCOM bindings to %{name}.

%prep
%setup -q -n VirtualBox-%{version}_OSE
%patch1
%patch2 
%patch3 
%patch4 -p1
%patch99 -p1
#copy user manual
%__cp %{S:1} ./UserManual.pdf

%build
# This package failed when testing with -Wl,-as-needed being default.
# So we disable it here, if you want to retest, just delete this comment and the line below.
export SUSE_ASNEEDED=0
# turn on vnc feature by hand, this line could be dropped when we could use configure script
echo VBOX_WITH_VNC=1 >> Config.kmk
#
#   --with-gcc=/usr/bin/gxx-4.3    	do configure and set proper gcc - currently vbox support only gcc<=4.4
#	--disable-kmods \  				don't build Linux kernel modules -  but use SUSE specific way see few lines under
./configure \
	--disable-kmods \
	--with-gcc=/usr/bin/gcc-4.3 \
	--with-g++=/usr/bin/g++-4.3
#
# build virtualbox-ose without kernel modules
/usr/bin/kmk \
	KBUILD_VERBOSE=2 \
	VBOX_WITH_REGISTRATION_REQUEST= VBOX_WITH_UPDATE_REQUEST= \
	TOOL_YASM_AS=yasm \
	all
#
# build kernel modules for guest and host (check novel-kmp package as example)
# host  modules : vboxdrv,vboxnetflt,vboxnetadp
# guest modules : vboxguest,vboxsf,vboxvideo
for vbox_module in out/linux.*/release/bin/src/vbox{drv,netflt,netadp} \
           out/linux.*/release/bin/additions/src/vbox{guest,sf,video}
do
    module_name=`/usr/bin/basename $vbox_module` 				#get the module name from path
    for flavor in %flavors_to_build; do 						#go trought the all flavors (desktop,default ...)
    	%__rm -rf modules_build_dir/${module_name}_${flavor}    #delete old build dir for sure
        %__mkdir -p modules_build_dir/$flavor                   #create build directory for specific flavor
		%__cp -r $vbox_module/ modules_build_dir/$flavor/       #copy sources which will be used to build vbox module in last step 
		# copy vboxdrv (for host) and vboxguest (for guest) module symbols:
     	test $module_name = "vboxnetflt"  || test $module_name = "vboxnetadp" && \
				%__cp $PWD/modules_build_dir/$flavor/vboxdrv/Module.symvers		$PWD/modules_build_dir/$flavor/$module_name
      	test $module_name = "vboxsf" && \
				%__cp $PWD/modules_build_dir/$flavor/vboxguest/Module.symvers	$PWD/modules_build_dir/$flavor/$module_name
		#and build module $module_name for $flavor flavor and %_target_cpu architecture
		%__make -C /usr/src/linux-obj/%_target_cpu/$flavor modules M=$PWD/modules_build_dir/$flavor/$module_name
	done
done

%install
#################################
echo "create directory structure"
#################################
%__install -d -m 755 %{buildroot}%{_bindir}
%__install -d -m 755 %{buildroot}%{_sbindir}
%__install -d -m 755 %{buildroot}/sbin
%__install -d -m 755 %{buildroot}%{_datadir}/virtualbox
%__install -d -m 755 %{buildroot}%{_datadir}/virtualbox/nls
%__install -d -m 755 %{buildroot}%{_datadir}/pixmaps
%__install -d -m 755 %{buildroot}%{_datadir}/applications
%if %suse_version >= 1130
	%__install -d -m 755 %{buildroot}%{_sysconfdir}/X11/xorg.conf.d/
%else
#since 11.3 we don't use hal to detect vbox mouse
	%__install -d -m 755 %{buildroot}%{_datadir}/hal/fdi/policy/20thirdparty
%endif
%__install -d -m 755 %{buildroot}%{_vbox_instdir}
%__install -d -m 755 %{buildroot}%{_vbox_instdir}/components
%__install -d -m 755 %{buildroot}%{_libdir}/dri
%__install -d -m 755 %{buildroot}%{_libdir}/xorg/modules/drivers
%__install -d -m 755 %{buildroot}%{_libdir}/xorg/modules/input
%__install -d -m 755 %{buildroot}%{_sysconfdir}/default
%__install -d -m 755 %{buildroot}%{_sysconfdir}/init.d
%__install -d -m 755 %{buildroot}%{_sysconfdir}/vbox
%__install -d -m 755 %{buildroot}%{_sysconfdir}/udev/rules.d
%__install -d -m 755 %{buildroot}%{_sysconfdir}/X11/xinit/xinitrc.d
%__install -d -m 755 %{buildroot}%{python_sitelib}/virtualbox

####################################################################################
echo "entering virtualbox-ose-kmp-guest and virtualbox-ose-kmp-host install section"
####################################################################################
export INSTALL_MOD_PATH=$RPM_BUILD_ROOT
export INSTALL_MOD_DIR=updates
#to install modules we use here similar steps like in build phase, go trought the all modules :
for module_name in vbox{drv,netflt,netadp,guest,sf,video} 
do
	#and trought the all flavors
	for flavor in %flavors_to_build; do
		#to install modules use Makefile from /usr/src/linux-obj/%_target_cpu/$flavor and builds from $PWD/modules_build_dir/$flavor/$module_name
    	%__make -C /usr/src/linux-obj/%_target_cpu/$flavor modules_install M=$PWD/modules_build_dir/$flavor/$module_name
    done
done

###########################################
echo "entering guest-tools install section"
###########################################
%__install -m 755 out/linux.*/release/bin/additions/VBoxControl \
									%{buildroot}%{_bindir}/VBoxControl
%__install -m 755 out/linux.*/release/bin/additions/VBoxService  \
									%{buildroot}%{_bindir}/VBoxService
%__install -m 755 out/linux.*/release/bin/additions/mount.vboxsf \
									%{buildroot}/sbin/mount.vboxsf
%__install -m 744 src/VBox/Additions/linux/installer/vboxadd.sh \
									%{buildroot}%{_sysconfdir}/init.d/vboxadd
# udev rule for guest (virtualbox-ose-guest-tools)
%__install -m 644 %{SOURCE3} 		%{buildroot}%{_sysconfdir}/udev/rules.d/60-vboxguest.rules
#
##############################################################
echo "entering xorg-x11-driver-virtualbox-ose install section"
##############################################################
pushd out/linux.*/release/bin/additions/
#VBoxClient daemon (support for clipboard,autoresize,seamless windows)
%__install -m 755 VBoxClient   		%{buildroot}%{_bindir}
# xorg drivers for mouse and videos check suse version to add propper driver
%if %suse_version >= 1130
	%__install -m 755 vboxmouse_drv_18.so \
									%{buildroot}%{_libdir}/xorg/modules/input/vboxmouse_drv.so
	%__install -m 755 vboxvideo_drv_18.so \
									%{buildroot}%{_libdir}/xorg/modules/drivers/vboxvideo_drv.so
%else 
%if %suse_version == 1120
	%__install -m 755 vboxmouse_drv_16.so \
									%{buildroot}%{_libdir}/xorg/modules/input/vboxmouse_drv.so
	%__install -m 755 vboxvideo_drv_16.so \
									%{buildroot}%{_libdir}/xorg/modules/drivers/vboxvideo_drv.so
%else
	%__install -m 755 vboxmouse_drv_15.so \
									%{buildroot}%{_libdir}/xorg/modules/input/vboxmouse_drv.so
	%__install -m 755 vboxvideo_drv_15.so \
									%{buildroot}%{_libdir}/xorg/modules/drivers/vboxvideo_drv.so
%endif
%endif
popd
# VBoxOGL* libs for xorg-x11-driver-virtualbox-ose
%__install -m 644 out/linux.*/release/bin/additions/VBoxOGL*.so \
									%{buildroot}%{_libdir}
# make link for dri lib
%__ln_s %{_libdir}/VBoxOGL.so 		%{buildroot}%{_libdir}/dri/vboxvideo_dri.so
# install init script which start VBoxClient daemon (support for clipboard,autoresize,seamless windows)
%__install -m 755 src/VBox/Additions/x11/Installer/98vboxadd-xclient \
									%{buildroot}%{_sysconfdir}/X11/xinit/xinitrc.d/vboxadd-xclient.sh
%if %suse_version >= 1130
    # add xorg config snipet to vbox mouse integration recognize
	%__install -m 644 %{SOURCE10} 	%{buildroot}%{_sysconfdir}/X11/xorg.conf.d/60-vboxmouse.conf
%else
	# hal policy file to autodetect the virtualbox mouse
	%__install -m 644 src/VBox/Additions/linux/installer/90-vboxguest.fdi \
									%{buildroot}%{_datadir}/hal/fdi/policy/20thirdparty/90-vboxguest.fdi
%endif

##############################################
echo "entering virtualbox-ose install section"
##############################################
# copy the main files to %{_vbox_instdir}
pushd out/linux.*/release/bin
%__install -m 755 VBoxManage 		%{buildroot}%{_vbox_instdir}
%__install -m 755 VBoxHeadless 		%{buildroot}%{_vbox_instdir}
%__install -m 755 VBoxSDL 			%{buildroot}%{_vbox_instdir}
%__install -m 755 VBoxTunctl 		%{buildroot}%{_vbox_instdir}
# create links to vbox tools in PATH - they could be usefull for controlling vbox from command line
%__ln_s %{_vbox_instdir}/VBoxManage %{buildroot}%{_bindir}/VBoxManage
%__ln_s %{_vbox_instdir}/VBoxHeadless \
									%{buildroot}%{_bindir}/VBoxHeadless 
%__ln_s %{_vbox_instdir}/VBoxSDL    %{buildroot}%{_bindir}/VBoxSDL
%__ln_s %{_vbox_instdir}/VBoxTunctl %{buildroot}%{_bindir}/VBoxTunctl
%__install -m 755 VBoxSVC 			%{buildroot}%{_vbox_instdir} 
%__install -m 755 VBoxXPCOMIPCD 	%{buildroot}%{_vbox_instdir}
%__install -m 755 VBoxTestOGL 		%{buildroot}%{_vbox_instdir}
%__install -m 755 VBoxPermissionMessage	\
									%{buildroot}%{_vbox_instdir}
%__install -m 755 VBoxNetDHCP 		%{buildroot}%{_vbox_instdir}
%__install -m 755 VBoxNetAdpCtl 	%{buildroot}%{_vbox_instdir}
%__install -m 755 VBoxBFE 			%{buildroot}%{_vbox_instdir}
%__install -m 755 VirtualBox 		%{buildroot}%{_vbox_instdir}
%__install -m 755 VBoxEFI*.fd		%{buildroot}%{_vbox_instdir}
%__install -m 755 VBoxSysInfo.sh 	%{buildroot}%{_vbox_instdir}
%__install -m 755 *.so		 		%{buildroot}%{_vbox_instdir}
%__install -m 644 V*.gc 			%{buildroot}%{_vbox_instdir}
%__install -m 644 *.r0 				%{buildroot}%{_vbox_instdir}
%__install -m 644 components/* 		%{buildroot}%{_vbox_instdir}/components/
# install languages
%__install -m 644 nls/*  			%{buildroot}%{_datadir}/virtualbox/nls/
popd
# install desktop file
%__install -m 644 src/VBox/Installer/linux/virtualbox.desktop \
									%{buildroot}%{_datadir}/applications/%{name}.desktop
# create a menu entry
%__install -m 644 out/linux.*/release/bin/VBox.png \
									%{buildroot}%{_datadir}/pixmaps/
# install udev rule for host (virtualbox-ose)
%__install -m 644 %{SOURCE2} 		%{buildroot}%{_sysconfdir}/udev/rules.d/60-vboxdrv.rules
# install config with session shutdown defs
%__install -m 644 %{SOURCE4} 		%{buildroot}%{_sysconfdir}/default/virtualbox
# copy the init scripts
%__install -m 744 src/VBox/Installer/linux/vboxdrv.sh.in \
									%{buildroot}%{_sysconfdir}/init.d/vboxdrv
#install wrapper script
%__install -m 644 %{S:9} 			%{buildroot}%{_bindir}/VirtualBox

# Init script to start virtual boxes during boot
%__install -m 755 %{S:12} %{buildroot}%{_sysconfdir}/init.d/vboxes
%__ln_s %{_sysconfdir}/init.d/vboxes %{buildroot}%{_sbindir}/rcvboxes
%__install -d -m 755 %buildroot%_var/adm/fillup-templates
install -m 700 %{S:13} %buildroot%_var/adm/fillup-templates/sysconfig.vbox

%suse_update_desktop_file -i %{name} System Emulator

#run fdupes because we lost link for virtualbox/components directory
%fdupes %{buildroot}/%{_vbox_instdir}
#also some translation files are duplicated
%fdupes %{buildroot}/%{_datadir}/virtualbox/nls

######################################################
#echo "entrering python-virtualbox-ose install section"
######################################################
#%__cp -rp obj/bin/sdk/. %{buildroot}%{_datadir}/virtualbox/sdk
#%__mv %{buildroot}%{_datadir}/virtualbox/sdk/bindings/xpcom/python/xpcom \
#    %{buildroot}%{python_sitelib}/virtualbox
#%__ln -sf ../../../../../../..%{python_sitelib}/virtualbox/xpcom \
#	%{buildroot}%{_datadir}/virtualbox/sdk/bindings/xpcom/python/xpcom

%pre
echo "creating group vboxusers..."
groupadd -r vboxusers 2>/dev/null || :

%post
/sbin/ldconfig
%fillup_and_insserv -f -y vboxdrv
%fillup_only -an vboxes
%run_permissions

%post guest-tools
%fillup_and_insserv -f -y vboxadd

%preun
%stop_on_removal vboxdrv
exit 0

%preun guest-tools
%stop_on_removal vboxadd 
exit 0

%postun
/sbin/ldconfig
%restart_on_update vboxdrv
%insserv_cleanup

%postun guest-tools
%restart_on_update vboxadd
%insserv_cleanup
%verifyscript
%if %suse_version > 1110
%verify_permissions -e %{_vbox_instdir}/VBoxBFE -e %{_vbox_instdir}/VBoxHeadless -e %{_vbox_instdir}/VBoxSDL -e %{_vbox_instdir}/VirtualBox -e %{_vbox_instdir}/VBoxNetAdpCtl
%else
%verify_permissions -e %{_vbox_instdir}/VBoxBFE -e %{_vbox_instdir}/VBoxHeadless -e %{_vbox_instdir}/VBoxSDL -e %{_vbox_instdir}/VirtualBox
%endif
#-e %{_vbox_instdir}/VBoxNetDHCP 

%clean
[ -d "%{buildroot}" -a "%{buildroot}" != "" ] && %__rm -rf "%{buildroot}"

%files
%defattr(-, root, root)
%doc UserManual.pdf
%{_bindir}/VBoxManage
%{_bindir}/VBoxHeadless 
%{_bindir}/VBoxSDL
%{_bindir}/VBoxTunctl
#wrapper script is in bindir
%attr(0755,root,root) %{_bindir}/VirtualBox
%dir %{_vbox_instdir}
%{_vbox_instdir}/VBoxSysInfo.sh
%{_vbox_instdir}/VBox*.so
%{_vbox_instdir}/VBox*.gc
%{_vbox_instdir}/VBox*.r0
%{_vbox_instdir}/VMMGC.gc
%{_vbox_instdir}/VMMR0.r0
%{_vbox_instdir}/VBoxEFI*.fd
%{_vbox_instdir}/VirtualBox*.so
%{_vbox_instdir}/VBoxManage
%{_vbox_instdir}/VBoxSVC
%{_vbox_instdir}/VBoxTunctl
%{_vbox_instdir}/VBoxXPCOMIPCD
%{_vbox_instdir}/VBoxTestOGL
%{_vbox_instdir}/VBoxPermissionMessage
%dir %{_vbox_instdir}/components
%{_vbox_instdir}/components/*.so
%{_vbox_instdir}/components/*.xpt
%{_datadir}/pixmaps/VBox.png
%{_datadir}/applications/%{name}.desktop
%dir %{_datadir}/virtualbox
%{_datadir}/virtualbox/nls
%config %{_sysconfdir}/default/virtualbox
%config %{_sysconfdir}/udev/rules.d/60-vboxdrv.rules
%config %{_sysconfdir}/init.d/vboxdrv
%{_sysconfdir}/init.d/vboxes
%{_var}/adm/fillup-templates/sysconfig.vbox
%{_sbindir}/rcvboxes
#check setuid bit
%if %suse_version > 1110
%verify(not mode) %attr(0755,root,vboxusers) %{_vbox_instdir}/VBoxNetAdpCtl
%else
%{_vbox_instdir}/VBoxNetAdpCtl
%endif
%verify(not mode) %attr(0755,root,vboxusers) %{_vbox_instdir}/VBoxBFE
%verify(not mode) %attr(0755,root,vboxusers) %{_vbox_instdir}/VBoxHeadless
%verify(not mode) %attr(0755,root,vboxusers) %{_vbox_instdir}/VBoxSDL
%verify(not mode) %attr(0755,root,vboxusers) %{_vbox_instdir}/VirtualBox
#%verify(not mode) %attr(0755,root,vboxusers) %{_vbox_instdir}/VBoxNetDHCP
%{_vbox_instdir}/VBoxNetDHCP
#

%files -n xorg-x11-driver-virtualbox-ose
%defattr(-, root, root)
%dir %{_libdir}/xorg/modules/drivers
%dir %{_libdir}/xorg/modules/input
%dir %{_libdir}/dri/
%{_bindir}/VBoxClient
%{_libdir}/VBoxOGL*.so
%{_libdir}/xorg/modules/drivers/vboxvideo_drv.so
%{_libdir}/xorg/modules/input/vboxmouse_drv.so
%{_libdir}/dri/vboxvideo_dri.so
%{_sysconfdir}/X11/xinit/xinitrc.d/vboxadd-xclient.sh
%if %suse_version >= 1130
%{_sysconfdir}/X11/xorg.conf.d/60-vboxmouse.conf
%else
%{_datadir}/hal/fdi/policy/20thirdparty/90-vboxguest.fdi
%endif
#

%files guest-tools
%defattr(-, root, root)
%{_bindir}/VBoxControl
%{_bindir}/VBoxService
/sbin/mount.vboxsf
%config %{_sysconfdir}/udev/rules.d/60-vboxguest.rules
%config %{_sysconfdir}/init.d/vboxadd

#%files -n python-virtualbox-ose
#%defattr(-,root, root)
#%{python_sitelib}/virtualbox

%changelog