Makefile revision cf4b84bc96451ba1d379d78261dd750661e21cf0
264N/A# $Id$
264N/A## @file
264N/A# Makefile for the VirtualBox Linux Host Driver.
264N/A#
264N/A
264N/A#
264N/A#
264N/A# Copyright (C) 2006-2012 Oracle Corporation
264N/A#
264N/A# This file is part of VirtualBox Open Source Edition (OSE), as
264N/A# available from http://www.virtualbox.org. This file is free software;
264N/A# you can redistribute it and/or modify it under the terms of the GNU
264N/A# General Public License (GPL) as published by the Free Software
264N/A# Foundation, in version 2 as it comes in the "COPYING" file of the
264N/A# VirtualBox OSE distribution. VirtualBox OSE is distributed in the
264N/A# hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
264N/A#
264N/A# The contents of this file may alternatively be used under the terms
264N/A# of the Common Development and Distribution License Version 1.0
264N/A# (CDDL) only, as it comes in the "COPYING.CDDL" file of the
264N/A# VirtualBox OSE distribution, in which case the provisions of the
264N/A# CDDL are applicable instead of those of the GPL.
5396N/A#
264N/A# You may elect to license modified versions of this file under the
814N/A# terms and conditions of either the GPL or the CDDL or both.
5220N/A#
5135N/A
4431N/A#
4431N/A# First, figure out which architecture we're targeting and the build type.
5135N/A# (We have to support basic cross building (ARCH=i386|x86_64).)
3817N/A# While at it, warn about BUILD_* vars found to help with user problems.
4431N/A#
4431N/Aifeq ($(filter-out x86_64 amd64 AMD64,$(shell uname -m)),)
4431N/A BUILD_TARGET_ARCH_DEF := amd64
4431N/Aelse
4431N/A BUILD_TARGET_ARCH_DEF := x86
4431N/Aendif
3817N/Aifneq ($(filter-out amd64 x86,$(BUILD_TARGET_ARCH)),)
3817N/A $(warning Ignoring unknown BUILD_TARGET_ARCH value '$(BUILD_TARGET_ARCH)'.)
4270N/A BUILD_TARGET_ARCH :=
4270N/Aendif
4270N/Aifeq ($(BUILD_TARGET_ARCH),)
264N/A ifeq ($(ARCH),x86_64)
5396N/A BUILD_TARGET_ARCH := amd64
5396N/A else
5396N/A ifeq ($(ARCH),i386)
264N/A BUILD_TARGET_ARCH := x86
264N/A else
264N/A BUILD_TARGET_ARCH := $(BUILD_TARGET_ARCH_DEF)
5396N/A endif
1258N/A endif
264N/Aelse
3817N/A ifneq ($(BUILD_TARGET_ARCH),$(BUILD_TARGET_ARCH_DEF))
264N/A $(warning Using BUILD_TARGET_ARCH='$(BUILD_TARGET_ARCH)' from the $(origin BUILD_TARGET_ARCH).)
4431N/A endif
4431N/Aendif
4431N/A
4431N/Aifneq ($(filter-out release profile debug strict,$(BUILD_TYPE)),)
4431N/A $(warning Ignoring unknown BUILD_TYPE value '$(BUILD_TYPE)'.)
264N/A BUILD_TYPE :=
4431N/Aendif
4431N/Aifeq ($(BUILD_TYPE),)
4431N/A BUILD_TYPE := release
4431N/Aelse
5174N/A ifneq ($(BUILD_TYPE),release)
5174N/A $(warning Using BUILD_TYPE='$(BUILD_TYPE)' from the $(origin BUILD_TYPE).)
5174N/A endif
5174N/Aendif
3817N/A
264N/A# override is required by the Debian guys
4431N/Aoverride MODULE = vboxdrv
264N/AOBJS = \
4431N/A linux/SUPDrv-linux.o \
4431N/A SUPDrv.o \
264N/A SUPDrvSem.o \
4431N/A SUPDrvTracer.o \
4431N/A r0drv/alloc-r0drv.o \
5135N/A r0drv/initterm-r0drv.o \
4431N/A r0drv/memobj-r0drv.o \
5135N/A r0drv/mpnotification-r0drv.o \
4431N/A r0drv/powernotification-r0drv.o \
4431N/A r0drv/linux/assert-r0drv-linux.o \
4375N/A r0drv/linux/alloc-r0drv-linux.o \
4431N/A r0drv/linux/initterm-r0drv-linux.o \
4431N/A r0drv/linux/memobj-r0drv-linux.o \
4431N/A r0drv/linux/memuserkernel-r0drv-linux.o \
4431N/A r0drv/linux/mp-r0drv-linux.o \
4431N/A r0drv/linux/mpnotification-r0drv-linux.o \
4431N/A r0drv/linux/process-r0drv-linux.o \
4431N/A r0drv/linux/semevent-r0drv-linux.o \
4431N/A r0drv/linux/semeventmulti-r0drv-linux.o \
4431N/A r0drv/linux/semfastmutex-r0drv-linux.o \
4431N/A r0drv/linux/semmutex-r0drv-linux.o \
264N/A r0drv/linux/spinlock-r0drv-linux.o \
4431N/A r0drv/linux/thread-r0drv-linux.o \
4431N/A r0drv/linux/thread2-r0drv-linux.o \
4431N/A r0drv/linux/threadctxhooks-r0drv-linux.o \
4431N/A r0drv/linux/time-r0drv-linux.o \
4431N/A r0drv/linux/timer-r0drv-linux.o \
4431N/A r0drv/generic/semspinmutex-r0drv-generic.o \
4375N/A common/alloc/alloc.o \
4431N/A common/checksum/crc32.o \
4431N/A common/checksum/ipv4.o \
4431N/A common/checksum/ipv6.o \
264N/A common/err/RTErrConvertFromErrno.o \
4431N/A common/err/RTErrConvertToErrno.o \
4431N/A common/log/log.o \
4431N/A common/log/logellipsis.o \
4431N/A common/log/logrel.o \
4431N/A common/log/logrelellipsis.o \
3817N/A common/log/logcom.o \
4431N/A common/log/logformat.o \
4431N/A common/misc/RTAssertMsg1Weak.o \
264N/A common/misc/RTAssertMsg2.o \
4431N/A common/misc/RTAssertMsg2Add.o \
5135N/A common/misc/RTAssertMsg2AddWeak.o \
5135N/A common/misc/RTAssertMsg2AddWeakV.o \
264N/A common/misc/RTAssertMsg2Weak.o \
972N/A common/misc/RTAssertMsg2WeakV.o \
446N/A common/misc/assert.o \
446N/A common/misc/handletable.o \
4431N/A common/misc/handletablectx.o \
264N/A common/misc/thread.o \
5135N/A common/string/RTStrCopy.o \
5135N/A common/string/RTStrCopyEx.o \
5135N/A common/string/RTStrCopyP.o \
5135N/A common/string/RTStrNCmp.o \
5135N/A common/string/RTStrNLen.o \
264N/A common/string/stringalloc.o \
4431N/A common/string/strformat.o \
4431N/A common/string/strformatrt.o \
264N/A common/string/strformattype.o \
4431N/A common/string/strprintf.o \
4431N/A common/string/strtonum.o \
4431N/A common/table/avlpv.o \
4431N/A common/time/time.o \
5135N/A r0drv/linux/RTLogWriteDebugger-r0drv-linux.o \
5135N/A generic/RTAssertShouldPanic-generic.o \
795N/A generic/RTLogWriteStdErr-stub-generic.o \
5135N/A generic/RTLogWriteStdOut-stub-generic.o \
4431N/A generic/RTLogWriteUser-generic.o \
4431N/A generic/RTMpGetArraySize-generic.o \
4431N/A generic/RTMpGetCoreCount-generic.o \
4431N/A generic/RTSemEventWait-2-ex-generic.o \
795N/A generic/RTSemEventWaitNoResume-2-ex-generic.o \
795N/A generic/RTSemEventMultiWait-2-ex-generic.o \
795N/A generic/RTSemEventMultiWaitNoResume-2-ex-generic.o \
4431N/A generic/RTTimerCreate-generic.o \
4431N/A generic/errvars-generic.o \
4431N/A generic/mppresent-generic.o \
4431N/A generic/uuid-generic.o \
5135N/A VBox/log-vbox.o
5135N/Aifeq ($(BUILD_TARGET_ARCH),x86)
5135N/AOBJS += math/gcc/divdi3.o \
5135N/A math/gcc/moddi3.o \
795N/A math/gcc/qdivrem.o \
4431N/A math/gcc/udivdi3.o \
4431N/A math/gcc/divdi3.o \
4375N/A math/gcc/umoddi3.o
4431N/Aendif
4431N/Aifeq ($(BUILD_TARGET_ARCH),amd64)
4431N/AOBJS += common/alloc/heapsimple.o
4431N/Aendif
4431N/Aifdef VBOX_WITH_NATIVE_DTRACE
4431N/AOBJS += SUPDrvDTrace.o
4431N/Aendif
4431N/A
4431N/Aifneq ($(MAKECMDGOALS),clean)
4431N/A
5135N/Aifeq ($(KERNELRELEASE),)
4369N/A
4431N/A #
4431N/A # building from this directory
4431N/A #
4744N/A
4431N/A # kernel base directory
4431N/A ifndef KERN_DIR
4431N/A # build for the current kernel, version check
4431N/A KERN_DIR := /lib/modules/$(shell uname -r)/build
5135N/A ifneq ($(shell if test -d $(KERN_DIR); then echo yes; fi),yes)
5135N/A KERN_DIR := /usr/src/linux
4431N/A ifneq ($(shell if test -d $(KERN_DIR); then echo yes; fi),yes)
4431N/A $(error Error: unable to find the sources of your current Linux kernel. \
4431N/A Specify KERN_DIR=<directory> and run Make again)
4369N/A endif
4431N/A $(warning Warning: using /usr/src/linux as the source directory of your \
4431N/A Linux kernel. If this is not correct, specify \
4431N/A KERN_DIR=<directory> and run Make again.)
4431N/A endif
4431N/A else
4431N/A ifneq ($(shell if test -d $(KERN_DIR); then echo yes; fi),yes)
4431N/A $(error Error: KERN_DIR does not point to a directory)
4431N/A endif
4431N/A endif
4431N/A
4431N/A # includes
4431N/A ifndef KERN_INCL
4431N/A KERN_INCL = $(KERN_DIR)/include
4431N/A endif
4431N/A ifneq ($(shell if test -d $(KERN_INCL); then echo yes; fi),yes)
4431N/A $(error Error: unable to find the include directory for your current Linux \
4431N/A kernel. Specify KERN_INCL=<directory> and run Make again)
4431N/A endif
4431N/A
4431N/A # module install dir, only for current kernel
4431N/A ifneq ($(filter install install_rpm,$(MAKECMDGOALS)),)
4431N/A ifndef MODULE_DIR
4431N/A MODULE_DIR_TST := /lib/modules/$(shell uname -r)
4431N/A ifeq ($(shell if test -d $(MODULE_DIR_TST); then echo yes; fi),yes)
4375N/A MODULE_DIR := $(MODULE_DIR_TST)/misc
795N/A else
4431N/A $(error Unable to find the folder to install the support driver to)
5135N/A endif
5135N/A endif # MODULE_DIR unspecified
5135N/A endif
4431N/A
4431N/Aelse # neq($(KERNELRELEASE),)
5174N/A
5174N/A #
5174N/A # building from kbuild (make -C <kernel_directory> M=`pwd`)
5174N/A #
5174N/A
5174N/Aendif # neq($(KERNELRELEASE),)
5174N/A
5174N/A# debug - show guesses.
5174N/Aifdef DEBUG
4431N/A$(warning dbg: KERN_DIR = $(KERN_DIR))
4431N/A$(warning dbg: KERN_INCL = $(KERN_INCL))
4431N/A$(warning dbg: MODULE_DIR = $(MODULE_DIR))
4431N/Aendif
4369N/A
4431N/AKBUILD_VERBOSE ?= 1
4431N/A
4431N/A#
4431N/A# Compiler options
4431N/A#
264N/Aifndef INCL
4431N/A INCL := $(addprefix -I,$(KERN_INCL) $(EXTRA_INCL))
4431N/A ifndef KBUILD_EXTMOD
4431N/A KBUILD_EXTMOD := $(shell pwd)
4431N/A endif
4431N/A INCL += $(addprefix -I$(KBUILD_EXTMOD),/ /include /r0drv/linux)
4431N/A INCL += $(addprefix -I$(KBUILD_EXTMOD)/vboxdrv,/ /include /r0drv/linux)
4431N/A ifdef VBOX_WITH_NATIVE_DTRACE
4431N/A INCL += -I/usr/include/linux -I/usr/include
4431N/A endif
4375N/A export INCL
4375N/Aendif
4431N/Aifneq ($(wildcard $(KBUILD_EXTMOD)/vboxdrv),)
5135N/A MANGLING := $(KBUILD_EXTMOD)/vboxdrv/include/VBox/SUPDrvMangling.h
5135N/Aelse
5135N/A MANGLING := $(KBUILD_EXTMOD)/include/VBox/SUPDrvMangling.h
4431N/Aendif
4431N/AKFLAGS := -D__KERNEL__ -DMODULE -DRT_OS_LINUX -DIN_RING0 -DIN_RT_R0 \
4431N/A -DIN_SUP_R0 -DVBOX -DRT_WITH_VBOX -DVBOX_WITH_HARDENING \
4431N/A -Wno-declaration-after-statement
4431N/Aifdef VBOX_REDHAT_KABI
4431N/A KFLAGS += -DVBOX_REDHAT_KABI
4431N/Aendif
4431N/Aifndef CONFIG_VBOXDRV_FIXEDMAJOR
2063N/A KFLAGS += -DCONFIG_VBOXDRV_AS_MISC
4431N/Aendif
4431N/Aifdef VBOX_WITH_NATIVE_DTRACE
5135N/A KFLAGS += -DVBOX_WITH_NATIVE_DTRACE
5135N/Aendif
5135N/Aifeq ($(BUILD_TARGET_ARCH),amd64)
5135N/A KFLAGS += -DRT_ARCH_AMD64
5135N/Aelse
5135N/A KFLAGS += -DRT_ARCH_X86
5135N/Aendif
5135N/A# must be consistent with Config.kmk!
4431N/AKFLAGS += -DVBOX_WITH_64_BITS_GUESTS
5174N/Aifeq ($(BUILD_TYPE),debug)
4431N/A KFLAGS += -DDEBUG -DDEBUG_$(USER) -g
4431N/A # IPRT_DEBUG_SEMS indicates thread wrt sems state via the comm field.
5135N/A #KFLAGS += -DIPRT_DEBUG_SEMS
5135N/Aendif
5135N/Aifdef VBOX_WITH_TEXT_MODMEM_HACK
5135N/A KFLAGS += -DRTMEMALLOC_EXEC_HEAP -DVBOX_WITH_TEXT_MODMEM_HACK
264N/Aendif
264N/A
4431N/A# 2.6 and later
3477N/AMODULE_EXT := ko
4431N/A$(MODULE)-y := $(OBJS)
4375N/A
4431N/A# build defs
264N/AEXTRA_CFLAGS += -include $(MANGLING) $(INCL) $(KFLAGS) $(KDEBUG)
264N/A
264N/Aall: $(MODULE)
4337N/A
4337N/Aobj-m += $(MODULE).o
264N/A
4431N/A# OL/UEK: disable module signing for external modules -- we don't have any private key
4431N/A$(MODULE):
3817N/A $(MAKE) KBUILD_VERBOSE=$(KBUILD_VERBOSE) SUBDIRS=$(CURDIR) SRCROOT=$(CURDIR) CONFIG_MODULE_SIG= -C $(KERN_DIR) modules
4431N/A
3817N/Ainstall: $(MODULE)
3817N/A @mkdir -p $(MODULE_DIR); \
4744N/A install -m 0664 -o root -g root $(MODULE).$(MODULE_EXT) $(MODULE_DIR); \
4431N/A PATH="$(PATH):/bin:/sbin" depmod -a; \
3817N/A rm -f /etc/vbox/module_not_compiled
3817N/A
3817N/Ainstall_rpm: $(MODULE)
3817N/A @mkdir -p $(MODULE_DIR); \
3817N/A install -m 0664 $(MODULE).$(MODULE_EXT) $(MODULE_DIR)
3817N/A
5143N/Aelse # eq ($(MAKECMDGOALS),clean)
5135N/A
3817N/A ifndef KERN_DIR
3817N/A KERN_DIR := /lib/modules/$(shell uname -r)/build
ifeq ($(wildcard $(KERN_DIR)/Makefile),)
KERN_DIR := /usr/src/linux
endif
endif
ifeq ($(wildcard $(KERN_DIR)/Makefile),)
clean:
find . \( -name \*.o -o -name \*.cmd \) -print0 | xargs -0 rm -f
rm -rf .tmp_ver* $(MODULE).* Module.symvers Modules.symvers modules.order
else
clean:
$(MAKE) KBUILD_VERBOSE=$(KBUILD_VERBOSE) SUBDIRS=$(CURDIR) SRCROOT=$(CURDIR) -C $(KERN_DIR) clean
endif
endif # eq($(MAKECMDGOALS),clean)
check: $(MODULE)
@if ! readelf -p __ksymtab_strings vboxdrv.ko | grep -E "\[.*\] *(RT|g_..*RT.*)"; then \
echo "All exported IPRT symbols are properly renamed!"; \
else \
echo "error: Some exported IPRT symbols was not properly renamed! See above." >&2; \
false; \
fi