#!/usr/bin/make -f
#
# Copyright (C) 2006-2008 Sun Microsystems, Inc.
#
# This file is part of VirtualBox Open Source Edition (OSE), as
# available from http://www.virtualbox.org. This file is free software;
# you can redistribute it and/or modify it under the terms of the GNU
# General Public License as published by the Free Software Foundation,
# in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
# distribution. VirtualBox OSE is distributed in the hope that it will
# be useful, but WITHOUT ANY WARRANTY of any kind.
#
#export DH_VERBOSE=1
export DH_COMPAT=4
# possible overrides:
# OSE=1 force VBOX_OSE
# NOPARALLEL=1 compile with -j1
# LINUX=
compile vboxdrv against Linux found in
# VERBOSE=1 verbose build
# DEBUG=1 debug build
# NOSUBVER=1 disable generation of the sub-version field (which is
# either the subversion rev [if available] or the build date)
# NODOCS=1 don't build docs, use precompiled UserManual.pdf and
# VirtualBox.chm from $HOME
# NOMODS=1 don't build any module
# NOQT=1 don't build the Qt GUI
# HEADLESS=1 build the headless version
# STAGEDISO= don't build the VBoxAdditions, use the precompiled .iso
package := virtualbox
verpkg := virtualbox-ose
current := $(shell pwd)
vboxroot := $(shell pwd)
builddir := $(current)/debian/builddir
moddir := $(current)/debian/modules
prefix := $(current)/debian/$(verpkg)
arch := $(shell dpkg --print-architecture)
verfile := $(builddir)/version-generated.mk
ose := 1
NOMODS ?= $(ose)
NOQT ?= $(HEADLESS)
ifneq ($(wildcard $(verfile)),)
include $(verfile)
ver := $(VBOX_VERSION_STRING)
archdir := $(prefix)/opt/VirtualBox-$(ver)
endif
ifneq ($(STAGEDISO),)
ifeq ($(wildcard $(STAGEDISO)/VBoxGuestAdditions.iso),)
$(error STAGEDISO='$(STAGEDISO)/VBoxGuestAdditions.iso' not found)
endif
endif
# Hack: Xandros is actually Debian/sarge ... :(
ifneq ($(wildcard /etc/xandros-desktop-version),)
debrel := _xandros4.1
else
ifneq ($(wildcard /etc/univention),)
debrel := _ucs1.3
else
debrel := $(if $(shell which lsb_release),_$(shell lsb_release -si)_$(shell lsb_release -sc),unknown)
endif
endif
gccver := $(subst ., ,$(shell gcc -dumpversion))
gccvmaj := $(word 1,$(gccver))
gccvmin := $(word 2,$(gccver))
debcfgs := VBOX_PATH_PACKAGE_DOCS="\"/usr/share/doc/$(verpkg)\""
# Ubuntu dapper: gcc-4.0 does not work with recompiler, use gcc-3.4 instead
configure: debian/configure-stamp
debian/configure-stamp:
dh_testdir
cd $(vboxroot) && ./configure --odir=$(current)/debian --disable-qt3 $(if \
$(NOQT),--disable-qt,) $(if \
$(ose),--ose,) $(if $(LINUX),--with-linux=$(LINUX),) $(if \
$(filter _Ubuntu_dapper,$(debrel)),--with-gcc=gcc-3.4 --with-g++=g++-3.4,) $(if \
$(shell test $(gccvmaj) -eq 4 -a $(gccvmin) -gt 2 -o $(gccvmaj) -gt 4 && echo "yes"),--with-gcc=gcc-4.2 --with-g++=g++-4.2,) $(if \
$(filter _xandros4.1 _ucs1.3,$(debrel)),--disable-sdl-ttf,) $(if \
$(HEADLESS),--build-headless,) $(if $(DEBUG),--build-debug,)
touch debian/configure-stamp
build: debian/configure-stamp debian/build-stamp
debian/build-stamp $(verfile):
dh_testdir
. debian/env.sh && kmk -C $(vboxroot) $(if \
$(VERBOSE),--print-directory,--no-print-directory) $(if \
$(NOPARALLEL),-j1,) $(if \
$(VERBOSE),KBUILD_VERBOSE=2,) $(if \
$(NODOCS),VBOX_WITH_DOCS= ,)\
$(if $(STAGEDISO),VBOX_WITHOUT_ADDITIONS=1,) \
AUTOCFG=$(current)/debian/AutoConfig.kmk \
LOCALCFG=$(current)/debian/LocalConfig.kmk \
PATH_OUT=$(current)/debian/builddir \
VBOX_DO_STRIP= VBOX_DO_STRIP_MODULES= \
$(debcfgs) \
all
$(if $(NODOCS),cp $(vboxroot)/prebuild/UserManual.pdf $(builddir)/bin,)
$(if $(NODOCS),cp $(vboxroot)/prebuild/VirtualBox.chm $(builddir)/bin,)
mkdir -p $(builddir)/bin/additions
$(if $(STAGEDISO),cp $(STAGEDISO)/VBoxGuestAdditions.iso $(builddir)/bin/additions,)
. debian/env.sh && kmk -C $(vboxroot) $(if \
$(VERBOSE),--print-directory,--no-print-directory) $(if \
$(VERBOSE),KBUILD_VERBOSE=2,) $(if \
$(STAGEDISO),VBOX_WITHOUT_ADDITIONS=1,) \
AUTOCFG=$(current)/debian/AutoConfig.kmk \
LOCALCFG=$(current)/debian/LocalConfig.kmk \
PATH_OUT=$(current)/debian/builddir \
VBOX_DO_STRIP= VBOX_DO_STRIP_MODULES= \
VBOX_NO_LINUX_RUN_INSTALLER=1 \
$(debcfgs) \
packing
touch debian/build-stamp
# Build modules for every kernel we find in /lib/modules/*
modules: debian/build-stamp debian/modules-stamp
debian/modules-stamp: debian/build-stamp
rm -rf $(moddir)
mkdir $(moddir)
make -C $(builddir)/bin/src/vboxdrv clean
for d in $(wildcard /lib/modules/*); do \
if [ -L $$d/build ]; then \
make -C $(builddir)/bin/src/vboxdrv KERN_DIR=$$d/build MODULE_DIR=$$d clean && \
make -C $(builddir)/bin/src/vboxdrv KBUILD_VERBOSE= KERN_DIR=$$d/build MODULE_DIR=$$d all && \
install -D -m 0644 -g 0 -o 0 \
$(builddir)/bin/src/vboxdrv/vboxdrv.ko $(moddir)/$$(basename $$d)/vboxdrv.ko && \
make -C $(builddir)/bin/src/vboxnetflt KERN_DIR=$$d/build MODULE_DIR=$$d clean && \
(cp $(builddir)/bin/src/vboxdrv/Module.symvers $(builddir)/bin/src/vboxnetflt || true) && \
make -C $(builddir)/bin/src/vboxnetflt KBUILD_VERBOSE= KERN_DIR=$$d/build MODULE_DIR=$$d all && \
install -D -m 0644 -g 0 -o 0 \
$(builddir)/bin/src/vboxnetflt/vboxnetflt.ko $(moddir)/$$(basename $$d)/vboxnetflt.ko; \
fi; \
done
make -C $(builddir)/bin/src/vboxdrv clean
make -C $(builddir)/bin/src/vboxnetflt clean
touch debian/modules-stamp
clean:
dh_testdir
dh_testroot
rm -f debian/$(package).init debian/vboxdrv.init
rm -f debian/AutoConfig.kmk debian/configure.log debian/env.sh debian/preinst
rm -f debian/modules-stamp debian/build-stamp debian/configure-stamp
rm -rf $(builddir) $(moddir)
dh_clean
ifeq ($(VBOX_VERSION_MAJOR),)
binary binary-arch binary-indep: build $(verfile)
$(MAKE) -f debian/rules binary
else
# Build architecture-dependent files here.
binary binary-arch binary-indep: build $(if $(NOMODS),,modules)
dh_testdir
dh_testroot
dh_clean -k
dh_installdirs
tar -xjC $(prefix)/opt -f $(builddir)/bin/VirtualBox.tar.bz2
install -d -g 0 -o 0 $(prefix)/usr/share/applications
install -d -g 0 -o 0 $(prefix)/usr/lib
install -d -g 0 -o 0 $(prefix)/usr/bin
install -d -g 0 -o 0 $(prefix)/usr/lib/$(package)
install -d -g 0 -o 0 $(prefix)/usr/share/$(package)
install -d -g 0 -o 0 $(prefix)/usr/share/doc/$(verpkg)
$(if $(NOQT),,mv $(archdir)/VirtualBox.desktop \
$(prefix)/usr/share/applications/VirtualBox.desktop)
install -d -g 0 -o 0 $(prefix)/usr/share/pixmaps
install -D -g 0 -o 0 -m 644 debian/lintian-override \
$(prefix)/usr/share/lintian/overrides/$(package)
mv $(archdir)/VBox.png \
$(prefix)/usr/share/pixmaps/VBox.png
mv $(archdir)/*.gc $(prefix)/usr/lib/$(package)
mv $(archdir)/*.r0 $(prefix)/usr/lib/$(package)
$(if $(filter amd64,$(arch)),\
mv $(archdir)/VBoxREM2.rel $(prefix)/usr/lib/$(package),)
mv $(archdir)/VBoxXPCOMIPCD $(prefix)/usr/lib/$(package)
mv $(archdir)/components $(prefix)/usr/lib/$(package)/components
mv $(archdir)/*.so $(prefix)/usr/lib/$(package)
mv $(archdir)/*.so.4 $(prefix)/usr/lib/$(package) || true
$(if $(NOQT),,mv $(archdir)/nls $(prefix)/usr/share/$(package))
mv $(archdir)/src $(prefix)/usr/share/$(package)
rm $(archdir)/VBox.sh
install -D -g 0 -o 0 -m 644 debian/VBox.sh $(prefix)/usr/bin/VBox
mv $(archdir)/VBoxSysInfo.sh $(prefix)/usr/share/$(package)
for i in VBoxManage VBoxSVC $(if $(HEADLESS),,VBoxSDL) \
$(if $(NOQT),,VirtualBox) $(if $(ose),,VBoxVRDP) \
VBoxHeadless; do \
mv $(archdir)/$$i $(prefix)/usr/lib/$(package); done
mv $(archdir)/VBoxTunctl $(prefix)/usr/bin
$(if $(NOMODS),,for d in $(moddir)/*; do \
install -D -g 0 -o 0 -m 0644 \
$$d/vboxdrv.ko $(prefix)/lib/modules/$$(basename $$d)/misc/vboxdrv.ko; \
install -D -g 0 -o 0 -m 0644 \
$$d/vboxnetflt.ko $(prefix)/lib/modules/$$(basename $$d)/misc/vboxnetflt.ko; \
done)
ifeq ($(ose),)
$(if $(NOQT),,mv $(archdir)/kchmviewer $(prefix)/usr/lib/$(package))
dh_installdocs \
$(archdir)/UserManual*.pdf $(archdir)/VirtualBox*.chm \
LICENSE
rm $(addprefix $(archdir)/,UserManual*.pdf VirtualBox*.chm LICENSE)
for i in rdesktop-vrdp.tar.gz additions/VBoxGuestAdditions.iso; do \
mv $(archdir)/$$i $(prefix)/usr/share/$(package); done
rmdir $(archdir)/additions
if [ -d $(archdir)/accessible ]; then mv $(archdir)/accessible $(prefix)/usr/lib/virtualbox; fi
else
dh_installdocs
endif
rmdir $(archdir)
rmdir $(prefix)/opt
dh_link \
$(if $(NOQT),,usr/bin/VBox usr/bin/VirtualBox) \
usr/bin/VBox usr/bin/VBoxManage \
$(if $(HEADLESS),,usr/bin/VBox usr/bin/VBoxSDL) \
$(if $(ose),,usr/bin/VBox usr/bin/VBoxVRDP) \
usr/bin/VBox usr/bin/VBoxHeadless \
usr/share/virtualbox/src/vboxdrv usr/src/vboxdrv-$(ver) \
usr/share/virtualbox/src/vboxnetflt usr/src/vboxnetflt-$(ver)
dh_desktop
dh_installmenu
$(if $(NOMODS),,dh_installmodules)
sed \
-e 's|%NOLSB%|$(if $(filter _Debian_sarge ucs1.3,$(debrel)),yes,)|g' \
-e 's|%PACKAGE%|virtualbox|g' \
src/VBox/Installer/linux/vboxdrv.sh.in > debian/vboxdrv.init
dh_installinit --name=vboxdrv
cat debian/preinst.in | sed -e 's|%VER%|$(ver)|g' > debian/preinst
if [ "$(debrel)" = "_Ubuntu_dapper" -o "$(debrel)" = "_Debian_sarge" ]; then \
cat debian/postrm.dapper > debian/postrm; fi
dh_installdebconf
dh_installchangelogs
dh_link
dh_strip --keep-debug --exclude=libVBoxQtCore.so.4 --exclude=libVBoxQtGui.so.4 --exclude=libVBoxQtNetwork.so.4 --exclude=libqtaccessiblewidgets.so
# manually strip our R0/GC modules, dh_strip cannot handle them
for f in \
$(prefix)/usr/lib/$(package)/*.r0 $(prefix)/usr/lib/$(package)/*.gc; do \
objcopy --only-keep-debug \
$$f \
$(prefix)/usr/lib/debug/usr/lib/$(package)/`basename $$f`; \
strip -S --remove-section=.comment $$f; \
objcopy --add-gnu-debuglink=$(prefix)/usr/lib/debug/usr/lib/$(package)/`basename $$f` $$f; \
done
mkdir -p $(current)/debian/$(verpkg)-dbg/usr/lib
mv $(current)/debian/$(verpkg)/usr/lib/debug $(current)/debian/$(verpkg)-dbg/usr/lib
dh_compress -X.pdf -X.chm -X LICENSE
dh_fixperms
dh_makeshlibs
dh_installdeb
dh_perl
dh_shlibdeps
dh_gencontrol -- \
-Valsa=$(if $(HEADLESS),,libasound2) \
-Vpulse=$(if $(HEADLESS),,libpulse0) \
-Vsdlttf=$(if $(HEADLESS),,libsdl-ttf2.0-0) \
-Vdkms=$(if $(filter _Ubuntu_gutsy _Ubuntu_hardy _Ubuntu_intrepid,$(debrel)),dkms,)
dh_md5sums
dh_builddeb
endif
.PHONY: binary modules binary-arch binary-indep clean checkroot