Makefile revision 71b548af8b5b8adb865702432045250bc56ad7e5
557a0ad5156aefc96dce27978a920eadf85c9d55Mark Andrews# Makefile for the VirtualBox Linux Host Driver.
75c0816e8295e180f4bc7f10db3d0d880383bc1cMark Andrews# (For 2.6.x this file must be called 'Makefile'!)
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein# Copyright (C) 2006-2007 Sun Microsystems, Inc.
af5073d03288a53b646ec3b807ac25ced64d7879Mark Andrews# This file is part of VirtualBox Open Source Edition (OSE), as
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein# available from http://www.virtualbox.org. This file is free software;
af5073d03288a53b646ec3b807ac25ced64d7879Mark Andrews# you can redistribute it and/or modify it under the terms of the GNU
af5073d03288a53b646ec3b807ac25ced64d7879Mark Andrews# General Public License (GPL) as published by the Free Software
af5073d03288a53b646ec3b807ac25ced64d7879Mark Andrews# Foundation, in version 2 as it comes in the "COPYING" file of the
af5073d03288a53b646ec3b807ac25ced64d7879Mark Andrews# VirtualBox OSE distribution. VirtualBox OSE is distributed in the
c40265eba0c99708887d68e67901924065ba2514Brian Wellington# hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein# The contents of this file may alternatively be used under the terms
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein# of the Common Development and Distribution License Version 1.0
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein# (CDDL) only, as it comes in the "COPYING.CDDL" file of the
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein# VirtualBox OSE distribution, in which case the provisions of the
71c66a876ecca77923638d3f94cc0783152b2f03Mark Andrews# CDDL are applicable instead of those of the GPL.
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein# You may elect to license modified versions of this file under the
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews# terms and conditions of either the GPL or the CDDL or both.
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein# Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
7208386cd37a2092c70eddf80cf29519b16c4c80Mark Andrews# Clara, CA 95054 USA or visit http://www.sun.com if you need
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein# additional information or have any questions.
3b4098640dd85040270f39b9a5ee5e22de99d3d6Mark Andrews# First, figure out which architecture we're targeting and the build type.
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein# (We have to support basic cross building (ARCH=i386|x86_64).)
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein# While at it, warn about BUILD_* vars found to help with user problems.
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austeinifneq ($(filter-out amd64 x86,$(BUILD_TARGET_ARCH)),)
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein $(warning Ignoring unknown BUILD_TARGET_ARCH value '$(BUILD_TARGET_ARCH)'.)
7208386cd37a2092c70eddf80cf29519b16c4c80Mark Andrews ifeq ($(filter-out x86_64 amd64 AMD64,$(shell uname -m)),)
71c66a876ecca77923638d3f94cc0783152b2f03Mark Andrews $(warning Using BUILD_TARGET_ARCH='$(BUILD_TARGET_ARCH)' from the $(origin BUILD_TARGET_ARCH).)
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austeinifneq ($(filter-out release profile debug strict,$(BUILD_TYPE)),)
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein $(warning Ignoring unknown BUILD_TYPE value '$(BUILD_TYPE)'.)
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein $(warning Using BUILD_TYPE='$(BUILD_TYPE)' from the $(origin BUILD_TYPE).)
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein# override is required by the Debian guys
7208386cd37a2092c70eddf80cf29519b16c4c80Mark Andrews # building from this directory
7208386cd37a2092c70eddf80cf29519b16c4c80Mark Andrews # kernel base directory
7208386cd37a2092c70eddf80cf29519b16c4c80Mark Andrews # build for the current kernel, version check
7208386cd37a2092c70eddf80cf29519b16c4c80Mark Andrews KERN_DIR := /lib/modules/$(shell uname -r)/build
7208386cd37a2092c70eddf80cf29519b16c4c80Mark Andrews ifneq ($(shell if test -d $(KERN_DIR); then echo yes; fi),yes)
7208386cd37a2092c70eddf80cf29519b16c4c80Mark Andrews ifneq ($(shell if test -d $(KERN_DIR); then echo yes; fi),yes)
7208386cd37a2092c70eddf80cf29519b16c4c80Mark Andrews $(error Error: unable to find the sources of your current Linux kernel. \
7208386cd37a2092c70eddf80cf29519b16c4c80Mark Andrews Specify KERN_DIR=<directory> and run Make again)
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein $(warning Warning: using /usr/src/linux as the source directory of your \
7208386cd37a2092c70eddf80cf29519b16c4c80Mark Andrews # check if versions match -- works only for later 2.6 kernels
7208386cd37a2092c70eddf80cf29519b16c4c80Mark Andrews VBOX_KERN_VER := $(shell $(MAKE) -sC $(KERN_DIR) kernelrelease 2> /dev/null || true)
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein $(error Error: /usr/src/linux (version $(VBOX_KERN_VER)) does not match \
3a3705ef7747327df182bf8d009333d2472253d5Mark Andrews # build for a dedicated kernel, no version check
3a3705ef7747327df182bf8d009333d2472253d5Mark Andrews ifneq ($(shell if test -d $(KERN_DIR); then echo yes; fi),yes)
3a3705ef7747327df182bf8d009333d2472253d5Mark Andrews $(error Error: KERN_DIR does not point to a directory)
3b4098640dd85040270f39b9a5ee5e22de99d3d6Mark Andrews ifneq ($(shell if test -d $(KERN_INCL); then echo yes; fi),yes)
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein $(error Error: unable to find the include directory for your current Linux \
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein kernel. Specify KERN_INCL=<directory> and run Make again)
7208386cd37a2092c70eddf80cf29519b16c4c80Mark Andrews # module install dir, only for current kernel
7208386cd37a2092c70eddf80cf29519b16c4c80Mark Andrews ifneq ($(filter install install_rpm,$(MAKECMDGOALS)),)
7208386cd37a2092c70eddf80cf29519b16c4c80Mark Andrews MODULE_DIR_TST := /lib/modules/$(shell uname -r)
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein ifeq ($(shell if test -d $(MODULE_DIR_TST); then echo yes; fi),yes)
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein $(error Unable to find the folder to install the support driver to)
7208386cd37a2092c70eddf80cf29519b16c4c80Mark Andrews # guess kernel version (24 or 26)
7208386cd37a2092c70eddf80cf29519b16c4c80Mark Andrews KERN_VERSION := $(if $(wildcard $(KERN_DIR)/Rules.make),24,26)
285254345ce5ab270848f8c11f7be146793f1e00Mark Andrewselse # neq($(KERNELRELEASE),)
285254345ce5ab270848f8c11f7be146793f1e00Mark Andrews # building from kbuild (make -C <kernel_directory> M=`pwd`)
7208386cd37a2092c70eddf80cf29519b16c4c80Mark Andrews # guess kernel version (24 or 26)
7208386cd37a2092c70eddf80cf29519b16c4c80Mark Andrews KERN_VERSION := $(if $(wildcard $(PWD)/Rules.make),24,26)
3b4098640dd85040270f39b9a5ee5e22de99d3d6Mark Andrews# debug - show guesses.
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein# Compiler options
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein INCL := $(addprefix -I,$(KERN_INCL) $(EXTRA_INCL))
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein INCL += $(addprefix -I$(KBUILD_EXTMOD),/ /include /r0drv/linux)
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob AusteinKFLAGS := -D__KERNEL__ -DMODULE -DRT_OS_LINUX -DIN_RING0 -DIN_RT_R0 -DIN_SUP_R0 -DVBOX -DRT_WITH_VBOX
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein # IPRT_DEBUG_SEMS indicates thread wrt sems state via the comm field.
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein# Use the RTR0MemObj API - testing.
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein# If this makes testboxes crash/burn/leak disable it and add a comment to defect #2116.
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob AusteinKFLAGS += -DUSE_NEW_OS_INTERFACE_FOR_MM -DUSE_NEW_OS_INTERFACE_FOR_GIP
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austeinifeq ($(BUILD_TARGET_ARCH),x86) # Some gcc versions ends up needing __divdi3.
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein# 2.6 and later
$(MODULE):