Makefile revision 0513cf94a5a1eeca5bac1778cbb9bb64e84f396f
aa1d397c4736cd86540555193d71e55fa3b37b2aMark Andrews# Makefile for the VirtualBox Linux Host Driver.
04428429c4e689333e3ef8d19a2debeb20d4d15dMark Andrews# (For 2.6.x this file must be called 'Makefile'!)
a3b428812703d22a605a9f882e71ed65f0ffdc65Mark Andrews# Copyright (C) 2006-2007 Sun Microsystems, Inc.
9e3a7b0faf417a10f5f689edf288807b2d5eedc5Brian Wellington# This file is part of VirtualBox Open Source Edition (OSE), as
ac4e70ff8955669341f435bc0a734a17c01af124Mark Andrews# available from http://www.virtualbox.org. This file is free software;
068a66979695c77359e7a9181bb3f831c965b21cMark Andrews# you can redistribute it and/or modify it under the terms of the GNU
9e3a7b0faf417a10f5f689edf288807b2d5eedc5Brian Wellington# General Public License (GPL) as published by the Free Software
d56e188030368b835122d759ebbf8d9613c166f4Mark Andrews# Foundation, in version 2 as it comes in the "COPYING" file of the
c718d15a9a95054ee3c71540c02335426071fc6dMark Andrews# VirtualBox OSE distribution. VirtualBox OSE is distributed in the
a9789e288ee11ae4315e27235c33bae5405bd7c4Mark Andrews# hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
c718d15a9a95054ee3c71540c02335426071fc6dMark Andrews# The contents of this file may alternatively be used under the terms
4b2cb1422c7c600fbc13b1cb06a8b4693bc11af8Mark Andrews# of the Common Development and Distribution License Version 1.0
c651f15b30f1dae5cc2f00878fb5da5b3a35a468Mark Andrews# (CDDL) only, as it comes in the "COPYING.CDDL" file of the
c651f15b30f1dae5cc2f00878fb5da5b3a35a468Mark Andrews# VirtualBox OSE distribution, in which case the provisions of the
c718d15a9a95054ee3c71540c02335426071fc6dMark Andrews# CDDL are applicable instead of those of the GPL.
c651f15b30f1dae5cc2f00878fb5da5b3a35a468Mark Andrews# You may elect to license modified versions of this file under the
efb0e886f18894a1d2489f1ad74ad14b579e11c7Mark Andrews# terms and conditions of either the GPL or the CDDL or both.
aa1d397c4736cd86540555193d71e55fa3b37b2aMark Andrews# Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
91216cff91b34c9ff6e846dc23f248219cafe660Andreas Gustafsson# Clara, CA 95054 USA or visit http://www.sun.com if you need
aa1d397c4736cd86540555193d71e55fa3b37b2aMark Andrews# additional information or have any questions.
9e3a7b0faf417a10f5f689edf288807b2d5eedc5Brian Wellington# First, figure out which architecture we're targeting and the build type.
a3b428812703d22a605a9f882e71ed65f0ffdc65Mark Andrews# (We have to support basic cross building (ARCH=i386|x86_64).)
c651f15b30f1dae5cc2f00878fb5da5b3a35a468Mark Andrews# While at it, warn about BUILD_* vars found to help with user problems.
4b2cb1422c7c600fbc13b1cb06a8b4693bc11af8Mark Andrewsifneq ($(filter-out amd64 x86,$(BUILD_TARGET_ARCH)),)
c651f15b30f1dae5cc2f00878fb5da5b3a35a468Mark Andrews $(warning Ignoring unknown BUILD_TARGET_ARCH value '$(BUILD_TARGET_ARCH)'.)
c651f15b30f1dae5cc2f00878fb5da5b3a35a468Mark Andrews ifeq ($(filter-out x86_64 amd64 AMD64,$(shell uname -m)),)
aa1d397c4736cd86540555193d71e55fa3b37b2aMark Andrews $(warning Using BUILD_TARGET_ARCH='$(BUILD_TARGET_ARCH)' from the $(origin BUILD_TARGET_ARCH).)
aa1d397c4736cd86540555193d71e55fa3b37b2aMark Andrewsifneq ($(filter-out release profile debug strict,$(BUILD_TYPE)),)
9e3a7b0faf417a10f5f689edf288807b2d5eedc5Brian Wellington $(warning Ignoring unknown BUILD_TYPE value '$(BUILD_TYPE)'.)
c651f15b30f1dae5cc2f00878fb5da5b3a35a468Mark Andrews $(warning Using BUILD_TYPE='$(BUILD_TYPE)' from the $(origin BUILD_TYPE).)
a9789e288ee11ae4315e27235c33bae5405bd7c4Mark Andrews# override is required by the Debian guys
4b2cb1422c7c600fbc13b1cb06a8b4693bc11af8Mark Andrews # building from this directory
46e873c835bf7d9ec3e1097e0aceb8db5b1ae93aMark Andrews # kernel base directory
c651f15b30f1dae5cc2f00878fb5da5b3a35a468Mark Andrews # build for the current kernel, version check
4b2cb1422c7c600fbc13b1cb06a8b4693bc11af8Mark Andrews KERN_DIR := /lib/modules/$(shell uname -r)/build
c651f15b30f1dae5cc2f00878fb5da5b3a35a468Mark Andrews ifneq ($(shell if test -d $(KERN_DIR); then echo yes; fi),yes)
c651f15b30f1dae5cc2f00878fb5da5b3a35a468Mark Andrews ifneq ($(shell if test -d $(KERN_DIR); then echo yes; fi),yes)
0d3490f93bb980fde704055e74c1b508987a5fe4Mark Andrews $(error Error: unable to find the sources of your current Linux kernel. \
5147281cb8e25c599d759dfa65fdb6f9125efefbMark Andrews Specify KERN_DIR=<directory> and run Make again)
6b5c57e52ac8c3e0af1547be3140ebbfb41a85b3Mark Andrews $(warning Warning: using /usr/src/linux as the source directory of your \
6b5c57e52ac8c3e0af1547be3140ebbfb41a85b3Mark Andrews Linux kernel. If this is not correct, specify \
068a66979695c77359e7a9181bb3f831c965b21cMark Andrews # check if versions match -- works only for later 2.6 kernels
a9789e288ee11ae4315e27235c33bae5405bd7c4Mark Andrews VBOX_KERN_VER := $(shell $(MAKE) -sC $(KERN_DIR) kernelrelease 2> /dev/null || true)
068a66979695c77359e7a9181bb3f831c965b21cMark Andrews $(error Error: /usr/src/linux (version $(VBOX_KERN_VER)) does not match \
75216e007570b8ea36b3ac9cca096bf70c0ca6f6Mark Andrews the current kernel (version $(shell uname -r)))
45eca3a5d46ed15aee14d81f6cb6c9fb6f365344Mark Andrews # build for a dedicated kernel, no version check
ca12f7f4cf72e2368ee946f3eb4915ab73576cdcMark Andrews ifneq ($(shell if test -d $(KERN_DIR); then echo yes; fi),yes)
7e1a8f402e3881388db37152f71c698cb1f1c426Mark Andrews $(error Error: KERN_DIR does not point to a directory)
aa1d397c4736cd86540555193d71e55fa3b37b2aMark Andrews ifneq ($(shell if test -d $(KERN_INCL); then echo yes; fi),yes)
91216cff91b34c9ff6e846dc23f248219cafe660Andreas Gustafsson $(error Error: unable to find the include directory for your current Linux \
aa1d397c4736cd86540555193d71e55fa3b37b2aMark Andrews kernel. Specify KERN_INCL=<directory> and run Make again)
a9789e288ee11ae4315e27235c33bae5405bd7c4Mark Andrews # module install dir, only for current kernel
c651f15b30f1dae5cc2f00878fb5da5b3a35a468Mark Andrews ifneq ($(filter install install_rpm,$(MAKECMDGOALS)),)
4b2cb1422c7c600fbc13b1cb06a8b4693bc11af8Mark Andrews MODULE_DIR_TST := /lib/modules/$(shell uname -r)
c651f15b30f1dae5cc2f00878fb5da5b3a35a468Mark Andrews ifeq ($(shell if test -d $(MODULE_DIR_TST); then echo yes; fi),yes)
068a66979695c77359e7a9181bb3f831c965b21cMark Andrews $(error Unable to find the folder to install the support driver to)
c651f15b30f1dae5cc2f00878fb5da5b3a35a468Mark Andrews # guess kernel version (24 or 26)
e076d0c88be69de7c190ab924d095e69d2e11f7aAndreas Gustafsson KERN_VERSION := $(if $(wildcard $(KERN_DIR)/Rules.make),24,26)
a9789e288ee11ae4315e27235c33bae5405bd7c4Mark Andrewselse # neq($(KERNELRELEASE),)
aa1d397c4736cd86540555193d71e55fa3b37b2aMark Andrews # building from kbuild (make -C <kernel_directory> M=`pwd`)
068a66979695c77359e7a9181bb3f831c965b21cMark Andrews # guess kernel version (24 or 26)
aa1d397c4736cd86540555193d71e55fa3b37b2aMark Andrews KERN_VERSION := $(if $(wildcard $(PWD)/Rules.make),24,26)
efb0e886f18894a1d2489f1ad74ad14b579e11c7Mark Andrews# debug - show guesses.
a9789e288ee11ae4315e27235c33bae5405bd7c4Mark Andrews# Compiler options
9e3a7b0faf417a10f5f689edf288807b2d5eedc5Brian Wellington INCL := $(addprefix -I,$(KERN_INCL) $(EXTRA_INCL))
9e3a7b0faf417a10f5f689edf288807b2d5eedc5Brian Wellington INCL += $(addprefix -I$(KBUILD_EXTMOD),/ /include /r0drv/linux)
9e3a7b0faf417a10f5f689edf288807b2d5eedc5Brian WellingtonKFLAGS := -D__KERNEL__ -DMODULE -DRT_OS_LINUX -DIN_RING0 -DIN_RT_R0 -DIN_SUP_R0 -DVBOX -DRT_WITH_VBOX
9e3a7b0faf417a10f5f689edf288807b2d5eedc5Brian Wellington # IPRT_DEBUG_SEMS indicates thread wrt sems state via the comm field.
9e3a7b0faf417a10f5f689edf288807b2d5eedc5Brian WellingtonEXTRA_CFLAGS := -DVBOX_LINUX_2_4 -DEXPORT_SYMTAB
9e3a7b0faf417a10f5f689edf288807b2d5eedc5Brian Wellington# 2.6 and later
9e3a7b0faf417a10f5f689edf288807b2d5eedc5Brian Wellington $(MAKE) KBUILD_VERBOSE=1 -C $(KERN_DIR) SUBDIRS=$(CURDIR) SRCROOT=$(CURDIR) modules
9e3a7b0faf417a10f5f689edf288807b2d5eedc5Brian Wellington# 2.4 Module linking
aa1d397c4736cd86540555193d71e55fa3b37b2aMark Andrews install -m 0664 -o root -g root $(MODULE).$(MODULE_EXT) $(MODULE_DIR); \
9e3a7b0faf417a10f5f689edf288807b2d5eedc5Brian Wellington install -m 0664 $(MODULE).$(MODULE_EXT) $(MODULE_DIR)
9e3a7b0faf417a10f5f689edf288807b2d5eedc5Brian Wellington for f in . linux r0drv r0drv/linux VBox common/string common/log generic math/gcc; \
9e3a7b0faf417a10f5f689edf288807b2d5eedc5Brian Wellington do rm -f $$f/*.o $$f/.*.cmd $$f/.*.flags; done