Makefile revision a0a9f39e8864357c2e1e61106958411240f5bf6b
1N/A#
1N/A# Makefile for the VirtualBox Linux Host Driver.
1N/A# (For 2.6.x this file must be called 'Makefile'!)
1N/A#
1N/A
1N/A#
1N/A#
1N/A# Copyright (C) 2006-2007 Sun Microsystems, Inc.
1N/A#
1N/A# This file is part of VirtualBox Open Source Edition (OSE), as
1N/A# available from http://www.virtualbox.org. This file is free software;
1N/A# you can redistribute it and/or modify it under the terms of the GNU
1N/A# General Public License (GPL) as published by the Free Software
1N/A# Foundation, in version 2 as it comes in the "COPYING" file of the
1N/A# VirtualBox OSE distribution. VirtualBox OSE is distributed in the
1N/A# hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
1N/A#
1N/A# The contents of this file may alternatively be used under the terms
1N/A# of the Common Development and Distribution License Version 1.0
1N/A# (CDDL) only, as it comes in the "COPYING.CDDL" file of the
1N/A# VirtualBox OSE distribution, in which case the provisions of the
1N/A# CDDL are applicable instead of those of the GPL.
1N/A#
1N/A# You may elect to license modified versions of this file under the
1N/A# terms and conditions of either the GPL or the CDDL or both.
1N/A#
1N/A# Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
1N/A# Clara, CA 95054 USA or visit http://www.sun.com if you need
1N/A# additional information or have any questions.
1N/A#
1N/A
1N/A#
1N/A# First, figure out which architecture we're targeting and the build type.
1N/A# (We have to support basic cross building (ARCH=i386|x86_64).)
1N/A# While at it, warn about BUILD_* vars found to help with user problems.
1N/A#
1N/Aifneq ($(filter-out amd64 x86,$(BUILD_TARGET_ARCH)),)
1N/A $(warning Ignoring unknown BUILD_TARGET_ARCH value '$(BUILD_TARGET_ARCH)'.)
1N/A BUILD_TARGET_ARCH :=
1N/Aendif
1N/Aifeq ($(BUILD_TARGET_ARCH),)
1N/A ifeq ($(ARCH),x86_64)
1N/A BUILD_TARGET_ARCH := amd64
1N/A else
1N/A ifeq ($(ARCH),i386)
1N/A BUILD_TARGET_ARCH := x86
1N/A else
1N/A ifeq ($(filter-out x86_64 amd64 AMD64,$(shell uname -m)),)
1N/A BUILD_TARGET_ARCH := amd64
1N/A else
1N/A BUILD_TARGET_ARCH := x86
1N/A endif
1N/A endif
1N/A endif
1N/Aelse
1N/A $(warning Using BUILD_TARGET_ARCH='$(BUILD_TARGET_ARCH)' from the $(origin BUILD_TARGET_ARCH).)
1N/Aendif
1N/A
1N/Aifneq ($(filter-out release profile debug strict,$(BUILD_TYPE)),)
1N/A $(warning Ignoring unknown BUILD_TYPE value '$(BUILD_TYPE)'.)
1N/A BUILD_TYPE :=
1N/Aendif
1N/Aifeq ($(BUILD_TYPE),)
1N/A BUILD_TYPE := release
1N/Aelse
1N/A $(warning Using BUILD_TYPE='$(BUILD_TYPE)' from the $(origin BUILD_TYPE).)
1N/Aendif
1N/A
1N/A# use vm_insert_page() API (if available) to map kernel pages to userland - better debugging
1N/A# VBOX_USE_INSERT_PAGE = 1
1N/A
1N/A# override is required by the Debian guys
1N/Aoverride MODULE = vboxdrv
1N/AOBJS = \
1N/A linux/SUPDrv-linux.o \
1N/A SUPDrv.o \
1N/A r0drv/alloc-r0drv.o \
1N/A r0drv/initterm-r0drv.o \
1N/A r0drv/memobj-r0drv.o \
1N/A r0drv/mpnotification-r0drv.o \
1N/A r0drv/powernotification-r0drv.o \
1N/A r0drv/linux/assert-r0drv-linux.o \
1N/A r0drv/linux/alloc-r0drv-linux.o \
1N/A r0drv/linux/initterm-r0drv-linux.o \
1N/A r0drv/linux/memobj-r0drv-linux.o \
1N/A r0drv/linux/mp-r0drv-linux.o \
1N/A r0drv/linux/mpnotification-r0drv-linux.o \
1N/A r0drv/linux/process-r0drv-linux.o \
1N/A r0drv/linux/semevent-r0drv-linux.o \
1N/A r0drv/linux/semeventmulti-r0drv-linux.o \
1N/A r0drv/linux/semfastmutex-r0drv-linux.o \
1N/A r0drv/linux/spinlock-r0drv-linux.o \
1N/A r0drv/linux/thread-r0drv-linux.o \
1N/A r0drv/linux/thread2-r0drv-linux.o \
1N/A r0drv/linux/time-r0drv-linux.o \
1N/A r0drv/linux/timer-r0drv-linux.o \
1N/A common/err/RTErrConvertFromErrno.o \
1N/A common/log/log.o \
1N/A common/log/logellipsis.o \
1N/A common/log/logrel.o \
1N/A common/log/logrelellipsis.o \
1N/A common/log/logcom.o \
1N/A common/log/logformat.o \
1N/A common/string/strformat.o \
1N/A common/string/strformatrt.o \
1N/A common/string/strformattype.o \
1N/A common/string/strprintf.o \
1N/A common/string/strtonum.o \
1N/A r0drv/linux/RTLogWriteDebugger-r0drv-linux.o \
1N/A generic/RTAssertShouldPanic-generic.o \
1N/A generic/RTLogWriteStdErr-stub-generic.o \
1N/A generic/RTLogWriteStdOut-stub-generic.o \
1N/A generic/RTLogWriteUser-generic.o \
1N/A VBox/log-vbox.o \
1N/A VBox/strformat-vbox.o
1N/Aifeq ($(BUILD_TARGET_ARCH),x86)
1N/AOBJS += math/gcc/divdi3.o \
1N/A math/gcc/moddi3.o \
1N/A math/gcc/qdivrem.o \
1N/A math/gcc/udivdi3.o \
1N/A math/gcc/divdi3.o \
1N/A math/gcc/umoddi3.o
1N/Aendif
1N/Aifeq ($(BUILD_TARGET_ARCH),amd64)
1N/AOBJS += alloc/heapsimple.o
1N/Aendif
1N/A
1N/Aifneq ($(MAKECMDGOALS),clean)
1N/A
1N/Aifeq ($(KERNELRELEASE),)
1N/A
1N/A #
1N/A # building from this directory
1N/A #
1N/A
1N/A # kernel base directory
1N/A ifndef KERN_DIR
1N/A # build for the current kernel, version check
1N/A KERN_DIR := /lib/modules/$(shell uname -r)/build
1N/A ifneq ($(shell if test -d $(KERN_DIR); then echo yes; fi),yes)
1N/A KERN_DIR := /usr/src/linux
1N/A ifneq ($(shell if test -d $(KERN_DIR); then echo yes; fi),yes)
1N/A $(error Error: unable to find the sources of your current Linux kernel. \
1N/A Specify KERN_DIR=<directory> and run Make again)
1N/A endif
1N/A $(warning Warning: using /usr/src/linux as the source directory of your \
1N/A Linux kernel. If this is not correct, specify \
1N/A KERN_DIR=<directory> and run Make again.)
1N/A endif
1N/A # check if versions match -- works only for later 2.6 kernels
1N/A VBOX_KERN_VER := $(shell $(MAKE) -sC $(KERN_DIR) kernelrelease 2> /dev/null || true)
1N/A ifneq ($(VBOX_KERN_VER),)
1N/A ifneq ($(VBOX_KERN_VER),$(shell uname -r))
1N/A $(error Error: /usr/src/linux (version $(VBOX_KERN_VER)) does not match \
1N/A the current kernel (version $(shell uname -r)))
1N/A endif
1N/A endif
1N/A else
1N/A # build for a dedicated kernel, no version check
1N/A ifneq ($(shell if test -d $(KERN_DIR); then echo yes; fi),yes)
1N/A $(error Error: KERN_DIR does not point to a directory)
1N/A endif
1N/A endif
1N/A
1N/A # includes
1N/A ifndef KERN_INCL
1N/A KERN_INCL = $(KERN_DIR)/include
1N/A endif
1N/A ifneq ($(shell if test -d $(KERN_INCL); then echo yes; fi),yes)
1N/A $(error Error: unable to find the include directory for your current Linux \
1N/A kernel. Specify KERN_INCL=<directory> and run Make again)
1N/A endif
1N/A
1N/A # module install dir, only for current kernel
1N/A ifneq ($(filter install install_rpm,$(MAKECMDGOALS)),)
1N/A ifndef MODULE_DIR
1N/A MODULE_DIR_TST := /lib/modules/$(shell uname -r)
1N/A ifeq ($(shell if test -d $(MODULE_DIR_TST); then echo yes; fi),yes)
1N/A MODULE_DIR := $(MODULE_DIR_TST)/misc
1N/A else
1N/A $(error Unable to find the folder to install the support driver to)
1N/A endif
1N/A endif # MODULE_DIR unspecified
1N/A endif
1N/A
1N/A # guess kernel version (24 or 26)
1N/A KERN_VERSION := $(if $(wildcard $(KERN_DIR)/Rules.make),24,26)
1N/A
1N/Aelse # neq($(KERNELRELEASE),)
1N/A
1N/A #
1N/A # building from kbuild (make -C <kernel_directory> M=`pwd`)
1N/A #
1N/A
1N/A # guess kernel version (24 or 26)
1N/A KERN_VERSION := $(if $(wildcard $(PWD)/Rules.make),24,26)
1N/A
1N/Aendif # neq($(KERNELRELEASE),)
1N/A
1N/A# debug - show guesses.
1N/Aifdef DEBUG
1N/A$(warning dbg: KERN_DIR = $(KERN_DIR))
1N/A$(warning dbg: KERN_INCL = $(KERN_INCL))
1N/A$(warning dbg: MODULE_DIR = $(MODULE_DIR))
1N/A$(warning dbg: KERN_VERSION = $(KERN_VERSION))
1N/Aendif
1N/A
1N/AKBUILD_VERBOSE ?= 1
1N/A
1N/A#
1N/A# Compiler options
1N/A#
1N/Aifndef INCL
1N/A INCL := $(addprefix -I,$(KERN_INCL) $(EXTRA_INCL))
1N/A ifndef KBUILD_EXTMOD
1N/A KBUILD_EXTMOD := $(shell pwd)
1N/A endif
1N/A INCL += $(addprefix -I$(KBUILD_EXTMOD),/ /include /r0drv/linux)
1N/A export INCL
1N/Aendif
1N/AKFLAGS := -D__KERNEL__ -DMODULE -DRT_OS_LINUX -DIN_RING0 -DIN_RT_R0 -DIN_SUP_R0 -DVBOX -DRT_WITH_VBOX -DVBOX_WITH_HARDENING
1N/Aifdef VBOX_REDHAT_KABI
1N/A KFLAGS += -DVBOX_REDHAT_KABI
1N/Aendif
1N/Aifndef CONFIG_VBOXDRV_FIXEDMAJOR
1N/A KFLAGS += -DCONFIG_VBOXDRV_AS_MISC
1N/Aendif
1N/Aifeq ($(BUILD_TARGET_ARCH),amd64)
1N/A KFLAGS += -DRT_ARCH_AMD64
1N/A # must be consistent with Config.kmk!
1N/A KFLAGS += -DVBOX_WITH_64_BITS_GUESTS
1N/Aelse
1N/A KFLAGS += -DRT_ARCH_X86
1N/Aendif
1N/Aifeq ($(BUILD_TYPE),debug)
1N/A KFLAGS += -DDEBUG -DDEBUG_$(USER) -g
1N/A # IPRT_DEBUG_SEMS indicates thread wrt sems state via the comm field.
1N/A KFLAGS += -DIPRT_DEBUG_SEMS
1N/Aendif
1N/A
1N/A# By default we use remap_pfn_range() kernel API to make kernel pages
1N/A# visible for userland. Unfortuately, it leads to situation that
1N/A# during debug session all structures on that page (such as PVM pointer)
1N/A# are not accessible to the debugger (see #3214).
1N/A# This code enables experimental support
1N/A# for vm_insert_page() kernel API, allowing to export kernel pages
1N/A# to the userland in more debugger-friendly way. Due to stability
1N/A# concerns, not enabled by default yet.
1N/Aifdef VBOX_USE_INSERT_PAGE
1N/A KFLAGS += -DVBOX_USE_INSERT_PAGE
1N/Aendif
1N/A
1N/Aifeq ($(KERN_VERSION),24)
1N/A# 2.4
1N/ATOPDIR = $(KERN_DIR)
1N/AMODULE_EXT := o
1N/AEXTRA_CFLAGS := -DVBOX_LINUX_2_4 -DEXPORT_SYMTAB
1N/A$(MODULE)-objs = $(OBJS)
1N/Aelse
1N/A# 2.6 and later
1N/AMODULE_EXT := ko
1N/A$(MODULE)-y := $(OBJS)
1N/Aendif
1N/A
1N/A# build defs
1N/AEXTRA_CFLAGS += $(INCL) $(KFLAGS) $(KDEBUG)
1N/A
1N/Aall: $(MODULE)
1N/A
1N/Aobj-m += $(MODULE).o
1N/A
1N/A$(MODULE):
1N/A $(MAKE) KBUILD_VERBOSE=$(KBUILD_VERBOSE) -C $(KERN_DIR) SUBDIRS=$(CURDIR) SRCROOT=$(CURDIR) modules
1N/A
1N/Aifeq ($(KERN_VERSION),24)
1N/A#
1N/A# 2.4 Module linking
1N/A#
1N/A$(MODULE).o: $(OBJS)
1N/A $(LD) -o $@ -r $(OBJS)
1N/A
1N/Ainclude $(KERN_DIR)/Rules.make
1N/A
1N/Aendif
1N/A
1N/Ainstall: $(MODULE)
1N/A @mkdir -p $(MODULE_DIR); \
1N/A install -m 0664 -o root -g root $(MODULE).$(MODULE_EXT) $(MODULE_DIR); \
1N/A PATH="$(PATH):/bin:/sbin" depmod -ae; \
1N/A rm -f /etc/vbox/module_not_compiled
1N/A
1N/Ainstall_rpm: $(MODULE)
1N/A @mkdir -p $(MODULE_DIR); \
1N/A install -m 0664 $(MODULE).$(MODULE_EXT) $(MODULE_DIR)
1N/A
endif # eq($(MAKECMDGOALS),clean)
clean:
for f in . linux r0drv r0drv/linux VBox common/err common/string common/log generic math/gcc; \
do rm -f $$f/*.o $$f/.*.cmd $$f/.*.flags; done
rm -rf .vboxdrv* .tmp_ver* vboxdrv.* Module.symvers Modules.symvers modules.order