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