Makefile revision e43535ace2499e7f8ef8822186047979bd58d464
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence# Makefile for the VirtualBox Linux Host Driver.
4c7d0f3c386a609d596152a6956d1fd5f1d43aa4Bob Halley# Copyright (C) 2006-2007 Sun Microsystems, Inc.
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein# This file is part of VirtualBox Open Source Edition (OSE), as
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein# available from http://www.virtualbox.org. This file is free software;
9c3531d72aeaad6c5f01efe6a1c82023e1379e4dDavid Lawrence# you can redistribute it and/or modify it under the terms of the GNU
d25afd60ee2286cb171c4960a790f3d7041b6f85Bob Halley# General Public License (GPL) as published by the Free Software
d25afd60ee2286cb171c4960a790f3d7041b6f85Bob Halley# Foundation, in version 2 as it comes in the "COPYING" file of the
b99bfa184bc9375421b5df915eea7dfac6a68a99Evan Hunt# VirtualBox OSE distribution. VirtualBox OSE is distributed in the
801dceea23d11975f5a5ae6ccbdf1dbde6b7af13David Lawrence# hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
e5242f042b968e316bb775c0dea4eb230fc4f6a4Michael Graff# The contents of this file may alternatively be used under the terms
92ef1a9b9dbd48ecb507b42ac62c15afefdaf838David Lawrence# of the Common Development and Distribution License Version 1.0
fc9e755ba340607d76c7de897ee2d985d3b24505David Lawrence# (CDDL) only, as it comes in the "COPYING.CDDL" file of the
9cd6d409b78a6f833b681c13a68fbdc7c024fe66David Lawrence# VirtualBox OSE distribution, in which case the provisions of the
b99bfa184bc9375421b5df915eea7dfac6a68a99Evan Hunt# CDDL are applicable instead of those of the GPL.
3759f10fc543747668b1ca4b4671f35b0dea8445Francis Dupont# You may elect to license modified versions of this file under the
c23f524c073bbee5cba0388f3f45bcde59bacdc5David Lawrence# terms and conditions of either the GPL or the CDDL or both.
c403d3f7d6cb17406e9be03a330ed5cf91619abcDavid Lawrence# Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
4c7d0f3c386a609d596152a6956d1fd5f1d43aa4Bob Halley# Clara, CA 95054 USA or visit http://www.sun.com if you need
440be4c866f6935ac069db79a414304507a664c2Michael Graff# additional information or have any questions.
8b78c993cb475cc94e88560941b28c37684789d9Francis Dupont# First, figure out which architecture we're targeting and the build type.
8b78c993cb475cc94e88560941b28c37684789d9Francis Dupont# (We have to support basic cross building (ARCH=i386|x86_64).)
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉# While at it, warn about BUILD_* vars found to help with user problems.
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉ifeq ($(filter-out x86_64 amd64 AMD64,$(shell uname -m)),)
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉ifneq ($(filter-out amd64 x86,$(BUILD_TARGET_ARCH)),)
8ec174ad4e570842495b2f1f3836160af90f69afBrian Wellington $(warning Ignoring unknown BUILD_TARGET_ARCH value '$(BUILD_TARGET_ARCH)'.)
c09dae9683f7fb55564d117bf7dcfcd74674b68eBob Halley ifneq ($(BUILD_TARGET_ARCH),$(BUILD_TARGET_ARCH_DEF))
c09dae9683f7fb55564d117bf7dcfcd74674b68eBob Halley $(warning Using BUILD_TARGET_ARCH='$(BUILD_TARGET_ARCH)' from the $(origin BUILD_TARGET_ARCH).)
c09dae9683f7fb55564d117bf7dcfcd74674b68eBob Halleyifneq ($(filter-out release profile debug strict,$(BUILD_TYPE)),)
92ef1a9b9dbd48ecb507b42ac62c15afefdaf838David Lawrence $(warning Ignoring unknown BUILD_TYPE value '$(BUILD_TYPE)'.)
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein $(warning Using BUILD_TYPE='$(BUILD_TYPE)' from the $(origin BUILD_TYPE).)
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein# override is required by the Debian guys
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 r0drv/linux/semeventmulti-r0drv-linux.o \
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 generic/RTLogWriteStdErr-stub-generic.o \
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 # building from this directory
b99bfa184bc9375421b5df915eea7dfac6a68a99Evan Hunt # kernel base directory
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 # build for the current kernel, version check
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 KERN_DIR := /lib/modules/$(shell uname -r)/build
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 ifneq ($(shell if test -d $(KERN_DIR); then echo yes; fi),yes)
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 ifneq ($(shell if test -d $(KERN_DIR); then echo yes; fi),yes)
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 $(error Error: unable to find the sources of your current Linux kernel. \
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 Specify KERN_DIR=<directory> and run Make again)
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 $(warning Warning: using /usr/src/linux as the source directory of your \
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 # check if versions match -- works only for later 2.6 kernels
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 VBOX_KERN_VER := $(shell $(MAKE) -sC $(KERN_DIR) --no-print-directory kernelrelease 2> /dev/null || true)
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 ifneq ($(VBOX_KERN_VER),$(shell uname -r))
8ec174ad4e570842495b2f1f3836160af90f69afBrian Wellington $(error Error: /usr/src/linux (version $(VBOX_KERN_VER)) does not match \
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 the current kernel (version $(shell uname -r)))
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 # build for a dedicated kernel, no version check
a2a072eb23b0d0167bf573625ce41a65fe135afdBob Halley ifneq ($(shell if test -d $(KERN_DIR); then echo yes; fi),yes)
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 $(error Error: KERN_DIR does not point to a directory)
5291519dba9e3b8c6e624b7c6d4b001f1d137c60Bob Halley ifneq ($(shell if test -d $(KERN_INCL); then echo yes; fi),yes)
5291519dba9e3b8c6e624b7c6d4b001f1d137c60Bob Halley $(error Error: unable to find the include directory for your current Linux \
5291519dba9e3b8c6e624b7c6d4b001f1d137c60Bob Halley kernel. Specify KERN_INCL=<directory> and run Make again)
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 # module install dir, only for current kernel
8ec174ad4e570842495b2f1f3836160af90f69afBrian Wellington ifneq ($(filter install install_rpm,$(MAKECMDGOALS)),)
8ec174ad4e570842495b2f1f3836160af90f69afBrian Wellington MODULE_DIR_TST := /lib/modules/$(shell uname -r)
de6aca419d84183a8ce15efd7104ebe6b39317f4Michael Graff ifeq ($(shell if test -d $(MODULE_DIR_TST); then echo yes; fi),yes)
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein $(error Unable to find the folder to install the support driver to)
c0c9d2b566cb40b96cb7b471450c3b47eeb0fe0cMark Andrewselse # neq($(KERNELRELEASE),)
5291519dba9e3b8c6e624b7c6d4b001f1d137c60Bob Halley # building from kbuild (make -C <kernel_directory> M=`pwd`)
60e412971ec8865ff5ab90a1a1128e86e5794299David Lawrence# debug - show guesses.
bf6d2e39124ab3d51c253f7acad9a4abef059be6Bob Halley# Compiler options
5291519dba9e3b8c6e624b7c6d4b001f1d137c60Bob Halley INCL := $(addprefix -I,$(KERN_INCL) $(EXTRA_INCL))
5291519dba9e3b8c6e624b7c6d4b001f1d137c60Bob Halley INCL += $(addprefix -I$(KBUILD_EXTMOD),/ /include /r0drv/linux)
298523461941e171ce97ea8b76892ac01bb7a49fBob HalleyKFLAGS := -D__KERNEL__ -DMODULE -DRT_OS_LINUX -DIN_RING0 -DIN_RT_R0 -DIN_SUP_R0 -DVBOX -DRT_WITH_VBOX -DVBOX_WITH_HARDENING
298523461941e171ce97ea8b76892ac01bb7a49fBob Halley# must be consistent with Config.kmk!
298523461941e171ce97ea8b76892ac01bb7a49fBob Halley # IPRT_DEBUG_SEMS indicates thread wrt sems state via the comm field.
298523461941e171ce97ea8b76892ac01bb7a49fBob Halley# 2.6 and later
8ec174ad4e570842495b2f1f3836160af90f69afBrian Wellington $(MAKE) KBUILD_VERBOSE=$(KBUILD_VERBOSE) -C $(KERN_DIR) SUBDIRS=$(CURDIR) SRCROOT=$(CURDIR) modules
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 install -m 0664 -o root -g root $(MODULE).$(MODULE_EXT) $(MODULE_DIR); \
e5242f042b968e316bb775c0dea4eb230fc4f6a4Michael Graff install -m 0664 $(MODULE).$(MODULE_EXT) $(MODULE_DIR)
e5242f042b968e316bb775c0dea4eb230fc4f6a4Michael Graff for f in . linux r0drv r0drv/generic r0drv/linux VBox common/err common/string common/log generic math/gcc; \
e5242f042b968e316bb775c0dea4eb230fc4f6a4Michael Graff do rm -f $$f/*.o $$f/.*.cmd $$f/.*.flags; done