Makefile revision 38434b7b59fbfa76d67e81896d1f5b650ec8e692
235N/A#
235N/A# Makefile for the VirtualBox Linux Host Driver.
822N/A# (For 2.6.x this file must be called 'Makefile'!)
822N/A#
822N/A
235N/A#
1356N/A#
235N/A# Copyright (C) 2006-2007 innotek GmbH
235N/A#
919N/A# This file is part of VirtualBox Open Source Edition (OSE), as
919N/A# available from http://www.virtualbox.org. This file is free software;
919N/A# you can redistribute it and/or modify it under the terms of the GNU
919N/A# General Public License (GPL) as published by the Free Software
919N/A# Foundation, in version 2 as it comes in the "COPYING" file of the
919N/A# VirtualBox OSE distribution. VirtualBox OSE is distributed in the
919N/A# hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
919N/A#
919N/A# The contents of this file may alternatively be used under the terms
919N/A# of the Common Development and Distribution License Version 1.0
919N/A# (CDDL) only, as it comes in the "COPYING.CDDL" file of the
919N/A# VirtualBox OSE distribution, in which case the provisions of the
919N/A# CDDL are applicable instead of those of the GPL.
919N/A#
919N/A# You may elect to license modified versions of this file under the
919N/A# terms and conditions of either the GPL or the CDDL or both.
919N/A#
235N/A
235N/A#
235N/A# First, figure out which architecture we're targeting and the build type.
822N/A# (We have to support basic cross building (ARCH=i386|x86_64).)
235N/A# While at it, warn about BUILD_* vars found to help with user problems.
970N/A#
970N/Aifneq ($(filter-out amd64 x86,$(BUILD_TARGET_ARCH)),)
970N/A $(warning Ignoring unknown BUILD_TARGET_ARCH value '$(BUILD_TARGET_ARCH)'.)
970N/A BUILD_TARGET_ARCH :=
970N/Aendif
970N/Aifeq ($(BUILD_TARGET_ARCH),)
970N/A ifeq ($(ARCH),x86_64)
1003N/A BUILD_TARGET_ARCH := amd64
1356N/A else
970N/A ifeq ($(ARCH),i386)
235N/A BUILD_TARGET_ARCH := x86
1252N/A else
235N/A ifeq ($(filter-out x86_64 amd64 AMD64,$(shell uname -m)),)
911N/A BUILD_TARGET_ARCH := amd64
1252N/A else
1252N/A BUILD_TARGET_ARCH := x86
911N/A endif
235N/A endif
493N/A endif
493N/Aelse
235N/A $(warning Using BUILD_TARGET_ARCH='$(BUILD_TARGET_ARCH)' from the $(origin BUILD_TARGET_ARCH).)
235N/Aendif
235N/A
235N/Aifneq ($(filter-out release profile debug strict,$(BUILD_TYPE)),)
822N/A $(warning Ignoring unknown BUILD_TYPE value '$(BUILD_TYPE)'.)
235N/A BUILD_TYPE :=
1124N/Aendif
1124N/Aifeq ($(BUILD_TYPE),)
1124N/A BUILD_TYPE := release
235N/Aelse
1252N/A $(warning Using BUILD_TYPE='$(BUILD_TYPE)' from the $(origin BUILD_TYPE).)
235N/Aendif
235N/A
235N/A
1366N/A# override is required by the Debian guys
1276N/Aoverride MODULE = vboxdrv
1276N/AOBJS = \
1366N/A linux/SUPDrv-linux.o \
1276N/A SUPDRVShared.o \
1276N/A r0drv/alloc-r0drv.o \
1276N/A r0drv/initterm-r0drv.o \
1276N/A generic/RTMpCpuId-generic.o \
1347N/A r0drv/generic/RTMpOn-r0drv-generic.o \
1276N/A r0drv/linux/alloc-r0drv-linux.o \
1276N/A r0drv/linux/initterm-r0drv-linux.o \
1276N/A r0drv/linux/process-r0drv-linux.o \
1276N/A r0drv/linux/semevent-r0drv-linux.o \
1276N/A r0drv/linux/semeventmulti-r0drv-linux.o \
235N/A r0drv/linux/semfastmutex-r0drv-linux.o \
1124N/A r0drv/linux/spinlock-r0drv-linux.o \
1124N/A r0drv/linux/thread-r0drv-linux.o
1124N/Aifeq ($(BUILD_TARGET_ARCH),amd64)
970N/AOBJS += alloc/heapsimple.o
970N/Aendif
970N/Aifeq ($(BUILD_TYPE),debug)
970N/AOBJS += \
970N/A math/gcc/divdi3.o \
970N/A math/gcc/moddi3.o \
970N/A math/gcc/udivdi3.o \
947N/A math/gcc/umoddi3.o \
235N/A math/gcc/qdivrem.o \
247N/A common/log/log.o \
947N/A common/log/logcom.o \
235N/A common/log/logformat.o \
247N/A common/string/strformat.o \
947N/A common/string/strformatrt.o \
947N/A common/string/strformattype.o \
970N/A common/string/strprintf.o \
970N/A common/string/strtonum.o \
947N/A r0drv/linux/RTLogWriteDebugger-r0drv-linux.o \
947N/A generic/RTLogWriteStdErr-stub-generic.o \
947N/A generic/RTLogWriteStdOut-stub-generic.o \
947N/A generic/RTLogWriteUser-generic.o \
947N/A VBox/log-vbox.o \
947N/A VBox/strformat-vbox.o
235N/Aendif
241N/A
493N/Aifneq ($(MAKECMDGOALS),clean)
493N/A
235N/Aifeq ($(KERNELRELEASE),)
1270N/A
1270N/A #
1270N/A # building from this directory
1270N/A #
493N/A
493N/A # kernel base directory
1124N/A ifndef KERN_DIR
963N/A # build for the current kernel, version check
1124N/A KERN_DIR := /lib/modules/$(shell uname -r)/build
1124N/A ifneq ($(shell if test -d $(KERN_DIR); then echo yes; fi),yes)
1097N/A KERN_DIR := /usr/src/linux
493N/A ifneq ($(shell if test -d $(KERN_DIR); then echo yes; fi),yes)
1097N/A $(error Error: unable to find the sources of your current Linux kernel. \
1097N/A Specify KERN_DIR=<directory> and run Make again)
493N/A endif
235N/A $(warning Warning: using /usr/src/linux as the source directory of your \
1124N/A Linux kernel. If this is not correct, specify \
1124N/A KERN_DIR=<directory> and run Make again.)
1124N/A endif
1124N/A # check if versions match -- works only for later 2.6 kernels
1124N/A VBOX_KERN_VER := $(shell $(MAKE) -sC $(KERN_DIR) kernelrelease 2> /dev/null || true)
1124N/A ifneq ($(VBOX_KERN_VER),)
1124N/A ifneq ($(VBOX_KERN_VER),$(shell uname -r))
1124N/A $(error Error: /usr/src/linux (version $(VBOX_KERN_VER)) does not match \
1124N/A the current kernel (version $(shell uname -r)))
1124N/A endif
970N/A endif
970N/A else
970N/A # build for a dedicated kernel, no version check
1097N/A ifneq ($(shell if test -d $(KERN_DIR); then echo yes; fi),yes)
1097N/A $(error Error: KERN_DIR does not point to a directory)
1097N/A endif
1030N/A endif
822N/A
235N/A # includes
235N/A ifndef KERN_INCL
822N/A KERN_INCL = $(KERN_DIR)/include
822N/A endif
963N/A ifneq ($(shell if test -d $(KERN_INCL); then echo yes; fi),yes)
963N/A $(error Error: unable to find the include directory for your current Linux \
935N/A kernel. Specify KERN_INCL=<directory> and run Make again)
935N/A endif
935N/A
935N/A # module install dir, only for current kernel
935N/A ifneq ($(filter install install_rpm,$(MAKECMDGOALS)),)
1088N/A ifndef MODULE_DIR
235N/A MODULE_DIR_TST := /lib/modules/$(shell uname -r)
935N/A ifeq ($(shell if test -d $(MODULE_DIR_TST); then echo yes; fi),yes)
963N/A MODULE_DIR := $(MODULE_DIR_TST)/misc
963N/A else
935N/A $(error Unable to find the folder to install the support driver to)
963N/A endif
963N/A endif # MODULE_DIR unspecified
963N/A endif
963N/A
235N/A # guess kernel version (24 or 26)
963N/A KERN_VERSION := $(if $(wildcard $(KERN_DIR)/Rules.make),24,26)
235N/A
935N/Aelse # neq($(KERNELRELEASE),)
935N/A
963N/A #
963N/A # building from kbuild (make -C <kernel_directory> M=`pwd`)
935N/A #
963N/A
963N/A # guess kernel version (24 or 26)
1333N/A KERN_VERSION := $(if $(wildcard $(PWD)/Rules.make),24,26)
963N/A
235N/Aendif # neq($(KERNELRELEASE),)
493N/A
1252N/A# debug - show guesses.
1252N/Aifdef DEBUG
1252N/A$(warning dbg: KERN_DIR = $(KERN_DIR))
1252N/A$(warning dbg: KERN_INCL = $(KERN_INCL))
1252N/A$(warning dbg: MODULE_DIR = $(MODULE_DIR))
1252N/A$(warning dbg: KERN_VERSION = $(KERN_VERSION))
1252N/Aendif
1252N/A
1252N/A#
1252N/A# Compiler options
822N/A#
1296N/Aifndef INCL
1296N/A INCL := $(addprefix -I,$(KERN_INCL) $(EXTRA_INCL))
1296N/A ifndef KBUILD_EXTMOD
493N/A KBUILD_EXTMOD := $(shell pwd)
822N/A endif
241N/A INCL += $(addprefix -I$(KBUILD_EXTMOD),/ /include /r0drv/linux)
235N/A export INCL
1333N/Aendif
1333N/AKFLAGS := -D__KERNEL__ -DMODULE -DRT_OS_LINUX -DIN_RING0 -DIN_RT_R0 -DIN_SUP_R0 -DVBOX -DRT_WITH_VBOX
235N/Aifdef VBOX_REDHAT_KABI
493N/A KFLAGS += -DVBOX_REDHAT_KABI
235N/Aendif
606N/Aifndef CONFIG_VBOXDRV_FIXEDMAJOR
606N/A KFLAGS += -DCONFIG_VBOXDRV_AS_MISC
606N/Aendif
606N/Aifeq ($(BUILD_TARGET_ARCH),amd64)
235N/A KFLAGS += -DRT_ARCH_AMD64
922N/Aelse
235N/A KFLAGS += -DRT_ARCH_X86
599N/Aendif
1124N/Aifeq ($(BUILD_TYPE),debug)
235N/A KFLAGS += -DDEBUG -DDEBUG_$(USER)
822N/A # IPRT_DEBUG_SEMS indicates thread wrt sems state via the comm field.
1147N/A KFLAGS += -DIPRT_DEBUG_SEMS
1147N/Aendif
1124N/A
606N/A#
606N/A# Use the RTR0MemObj API - testing.
606N/A# If this makes testboxes crash/burn/leak disable it and add a comment to defect #2116.
235N/A#
1030N/AKFLAGS += -DUSE_NEW_OS_INTERFACE_FOR_MM
235N/AOBJS += r0drv/memobj-r0drv.o \
606N/A r0drv/linux/memobj-r0drv-linux.o
606N/Aifeq ($(BUILD_TARGET_ARCH),x86) # Some gcc versions ends up needing __divdi3.
1097N/AOBJS += math/gcc/qdivrem.o \
822N/A math/gcc/divdi3.o
822N/Aendif
1030N/A
963N/Aifeq ($(KERN_VERSION), 24)
235N/A# 2.4
235N/ATOPDIR = $(KERN_DIR)
247N/AMODULE_EXT := o
822N/AEXTRA_CFLAGS := -DVBOX_LINUX_2_4
1019N/A$(MODULE)-objs = $(OBJS)
1030N/Aelse
1030N/A# 2.6 and later
1030N/AMODULE_EXT := ko
1030N/A$(MODULE)-y := $(OBJS)
963N/Aendif
235N/A
963N/A# build defs
235N/AEXTRA_CFLAGS += $(INCL) $(KFLAGS) $(KDEBUG)
963N/A
235N/Aall: $(MODULE)
963N/A
247N/Aobj-m += $(MODULE).o
963N/A
963N/A$(MODULE):
822N/A $(MAKE) KBUILD_VERBOSE=1 -C $(KERN_DIR) SUBDIRS=$(CURDIR) SRCROOT=$(CURDIR) modules
963N/A
980N/Aifeq ($(KERN_VERSION), 24)
822N/A#
822N/A# 2.4 Module linking
822N/A#
822N/A$(MODULE).o: $(OBJS)
822N/A $(LD) -o $@ -r $(OBJS)
822N/A
822N/Ainclude $(KERN_DIR)/Rules.make
1124N/A
1124N/Aendif
1124N/A
822N/Ainstall: $(MODULE)
822N/A @mkdir -p $(MODULE_DIR); \
822N/A install -m 0664 -o root -g root $(MODULE).$(MODULE_EXT) $(MODULE_DIR); \
822N/A PATH="$(PATH):/bin:/sbin" depmod -ae; \
822N/A rm -f /etc/vbox/module_not_compiled
822N/A
822N/Ainstall_rpm: $(MODULE)
822N/A @mkdir -p $(MODULE_DIR); \
822N/A install -m 0664 $(MODULE).$(MODULE_EXT) $(MODULE_DIR)
1124N/A
1124N/Aendif # eq($(MAKECMDGOALS),clean)
822N/A
963N/Aclean:
1124N/A for f in . linux r0drv r0drv/linux; do rm -f $$f/*.o $$f/.*.cmd $$f/.*.flags; done
970N/A rm -rf .vboxdrv* .tmp_ver* vboxdrv.* Module.symvers Modules.symvers
970N/A