2 # VirtualBox Guest Additions kernel module Makefile, common parts.
4 # (For 2.6.x, the main file must be called 'Makefile'!)
6 # Copyright (C) 2006-2015 Oracle Corporation
8 # This file is part of VirtualBox Open Source Edition (OSE), as
9 # available from http://www.virtualbox.org. This file is free software;
10 # you can redistribute it and/or modify it under the terms of the GNU
11 # General Public License (GPL) as published by the Free Software
12 # Foundation, in version 2 as it comes in the "COPYING" file of the
13 # VirtualBox OSE distribution. VirtualBox OSE is distributed in the
14 # hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
18 # * Building with KERN_DIR set uses the value specified and
19 # the default value for the unspecified one if any.
22 # These file should be included by the Makefiles for any kernel modules we
23 # build as part of the Guest Additions. The intended way of doing this is as
26 # # Linux kbuild sets this to our source directory if we are called from
29 # include $(obj)/Makefile.include.header
30 # MOD_NAME = <name of the module to be built, without extension>
31 # MOD_OBJS = <list of object files which should be included>
32 # MOD_DEFS = <any additional defines which this module needs>
33 # MOD_INCL = <any additional include paths which this module needs>
34 # MOD_CFLAGS = <any additional CFLAGS which this module needs>
35 # include $(obj)/Makefile.include.footer
37 # The kmk kBuild define KBUILD_TARGET_ARCH is available.
42 # First, figure out which architecture we're targeting and the build type.
43 # (We have to support basic cross building (ARCH=i386|x86_64).)
44 # While at it, warn about BUILD_* vars found to help with user problems.
46 ifeq ($(filter-out x86_64 amd64 AMD64,$(shell dpkg-architecture -qDEB_HOST_GNU_CPU)),)
47 BUILD_TARGET_ARCH_DEF := amd64
49 BUILD_TARGET_ARCH_DEF := x86
51 ifneq ($(filter-out amd64 x86,$(BUILD_TARGET_ARCH)),)
52 $(warning Ignoring unknown BUILD_TARGET_ARCH value '$(BUILD_TARGET_ARCH)'.)
55 ifeq ($(BUILD_TARGET_ARCH),)
57 BUILD_TARGET_ARCH := amd64
60 BUILD_TARGET_ARCH := x86
62 BUILD_TARGET_ARCH := $(BUILD_TARGET_ARCH_DEF)
66 ifneq ($(BUILD_TARGET_ARCH),$(BUILD_TARGET_ARCH_DEF))
67 $(warning Using BUILD_TARGET_ARCH='$(BUILD_TARGET_ARCH)' from the $(origin BUILD_TARGET_ARCH).)
71 ifneq ($(filter-out release profile debug strict,$(BUILD_TYPE)),)
72 $(warning Ignoring unknown BUILD_TYPE value '$(BUILD_TYPE)'.)
78 ifneq ($(BUILD_TYPE),release)
79 $(warning Using BUILD_TYPE='$(BUILD_TYPE)' from the $(origin BUILD_TYPE).)
86 ifeq ($(KERNELRELEASE),)
89 # building from this directory
92 # kernel base directory
93 KERN_VER ?= $(shell uname -r)
95 # guess kernel major version (24 or later)
96 ifeq ($(shell if grep '"2\.4\.' /lib/modules/$(KERN_VER)/build/include/linux/version.h > /dev/null 2>&1; then echo yes; fi),yes)
102 else # neq($(KERNELRELEASE),)
105 # building from kbuild (make -C <kernel_directory> M=`pwd`)
108 # guess kernel version (24 or 26)
109 ifeq ($(shell if echo "$(VERSION).$(PATCHLEVEL)." | grep '2\.4\.' > /dev/null; then echo yes; fi),yes)
115 KERN_VER := $(KERNELRELEASE)
117 endif # neq($(KERNELRELEASE),)
119 # Kernel build folder
120 KERN_DIR := $(srctree)
121 ifneq ($(shell if test -d $(KERN_DIR); then echo yes; fi),yes)
122 $(error Error: unable to find the headers of the Linux kernel to build against. \
123 Specify KERN_VER=<version> and run Make again)
125 # Kernel include folder
126 KERN_INCL := $(KERN_DIR)/include
127 # module install folder
128 INSTALL_MOD_DIR ?= misc
129 MODULE_DIR := $(INSTALL_MOD_PATH)/lib/modules/$(KERN_VER)/$(INSTALL_MOD_DIR)
131 # debug - show guesses.
133 $(warning dbg: INSTALL_MOD_PATH = $(INSTALL_MOD_PATH))
134 $(warning dbg: INSTALL_MOD_DIR = $(INSTALL_MOD_DIR))
135 $(warning dbg: KERN_DIR = $(KERN_DIR))
136 $(warning dbg: KERN_INCL = $(KERN_INCL))
137 $(warning dbg: KERN_VERSION = $(KERN_VERSION))
138 $(warning dbg: MODULE_DIR = $(MODULE_DIR))