1 | #
|
---|
2 | # VirtualBox Guest Additions kernel module Makefile, common parts.
|
---|
3 | #
|
---|
4 | # (For 2.6.x, the main file must be called 'Makefile'!)
|
---|
5 | #
|
---|
6 | # Copyright (C) 2006-2015 Oracle Corporation
|
---|
7 | #
|
---|
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.
|
---|
15 | #
|
---|
16 |
|
---|
17 | # Testing:
|
---|
18 | # * Building with KERN_DIR set uses the value specified and
|
---|
19 | # the default value for the unspecified one if any.
|
---|
20 |
|
---|
21 | #
|
---|
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
|
---|
24 | # follows:
|
---|
25 | #
|
---|
26 | # # Linux kbuild sets this to our source directory if we are called from
|
---|
27 | # # there
|
---|
28 | # obj ?= $(CURDIR)
|
---|
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
|
---|
36 | #
|
---|
37 | # The kmk kBuild define KBUILD_TARGET_ARCH is available.
|
---|
38 | #
|
---|
39 |
|
---|
40 |
|
---|
41 | #
|
---|
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.
|
---|
45 | #
|
---|
46 | ifeq ($(filter-out x86_64 amd64 AMD64,$(shell uname -m)),)
|
---|
47 | BUILD_TARGET_ARCH_DEF := amd64
|
---|
48 | else
|
---|
49 | BUILD_TARGET_ARCH_DEF := x86
|
---|
50 | endif
|
---|
51 | ifneq ($(filter-out amd64 x86,$(BUILD_TARGET_ARCH)),)
|
---|
52 | $(warning Ignoring unknown BUILD_TARGET_ARCH value '$(BUILD_TARGET_ARCH)'.)
|
---|
53 | BUILD_TARGET_ARCH :=
|
---|
54 | endif
|
---|
55 | ifeq ($(BUILD_TARGET_ARCH),)
|
---|
56 | ifeq ($(ARCH),x86_64)
|
---|
57 | BUILD_TARGET_ARCH := amd64
|
---|
58 | else
|
---|
59 | ifeq ($(ARCH),i386)
|
---|
60 | BUILD_TARGET_ARCH := x86
|
---|
61 | else
|
---|
62 | BUILD_TARGET_ARCH := $(BUILD_TARGET_ARCH_DEF)
|
---|
63 | endif
|
---|
64 | endif
|
---|
65 | else
|
---|
66 | ifneq ($(BUILD_TARGET_ARCH),$(BUILD_TARGET_ARCH_DEF))
|
---|
67 | $(warning Using BUILD_TARGET_ARCH='$(BUILD_TARGET_ARCH)' from the $(origin BUILD_TARGET_ARCH).)
|
---|
68 | endif
|
---|
69 | endif
|
---|
70 |
|
---|
71 | ifneq ($(filter-out release profile debug strict,$(BUILD_TYPE)),)
|
---|
72 | $(warning Ignoring unknown BUILD_TYPE value '$(BUILD_TYPE)'.)
|
---|
73 | BUILD_TYPE :=
|
---|
74 | endif
|
---|
75 | ifeq ($(BUILD_TYPE),)
|
---|
76 | BUILD_TYPE := release
|
---|
77 | else
|
---|
78 | ifneq ($(BUILD_TYPE),release)
|
---|
79 | $(warning Using BUILD_TYPE='$(BUILD_TYPE)' from the $(origin BUILD_TYPE).)
|
---|
80 | endif
|
---|
81 | endif
|
---|
82 | ifeq ($(USERNAME),)
|
---|
83 | USERNAME := noname
|
---|
84 | endif
|
---|
85 |
|
---|
86 | ifeq ($(KERNELRELEASE),)
|
---|
87 |
|
---|
88 | #
|
---|
89 | # building from this directory
|
---|
90 | #
|
---|
91 |
|
---|
92 | # kernel base directory
|
---|
93 | ifndef KERN_DIR
|
---|
94 | KERN_DIR := /lib/modules/$(shell uname -r)/build
|
---|
95 | ifneq ($(shell if test -d $(KERN_DIR); then echo yes; fi),yes)
|
---|
96 | $(error Error: unable to find the sources of your current Linux kernel. \
|
---|
97 | Specify KERN_DIR=<directory> and run Make again)
|
---|
98 | endif
|
---|
99 | else
|
---|
100 | ifneq ($(shell if test -d $(KERN_DIR); then echo yes; fi),yes)
|
---|
101 | $(error Error: KERN_DIR does not point to a directory)
|
---|
102 | endif
|
---|
103 | endif
|
---|
104 |
|
---|
105 | # includes
|
---|
106 | ifndef KERN_INCL
|
---|
107 | KERN_INCL := $(KERN_DIR)/include
|
---|
108 | endif
|
---|
109 | ifneq ($(shell if test -d $(KERN_INCL); then echo yes; fi),yes)
|
---|
110 | $(error Error: unable to find the include directory for your current Linux \
|
---|
111 | kernel. Specify KERN_INCL=<directory> and run Make again)
|
---|
112 | endif
|
---|
113 |
|
---|
114 | # module install dir
|
---|
115 | INSTALL_MOD_DIR ?= misc
|
---|
116 |
|
---|
117 | # guess kernel major version (24 or later)
|
---|
118 | ifeq ($(shell if grep '"2\.4\.' $(KERN_INCL)/linux/version.h > /dev/null 2>&1; then echo yes; fi),yes)
|
---|
119 | KERN_VERSION := 24
|
---|
120 | else
|
---|
121 | KERN_VERSION := 26
|
---|
122 | endif
|
---|
123 |
|
---|
124 | else # neq($(KERNELRELEASE),)
|
---|
125 |
|
---|
126 | #
|
---|
127 | # building from kbuild (make -C <kernel_directory> M=`pwd`)
|
---|
128 | #
|
---|
129 |
|
---|
130 | # guess kernel version (24 or 26)
|
---|
131 | ifeq ($(shell if echo "$(VERSION).$(PATCHLEVEL)." | grep '2\.4\.' > /dev/null; then echo yes; fi),yes)
|
---|
132 | KERN_VERSION := 24
|
---|
133 | else
|
---|
134 | KERN_VERSION := 26
|
---|
135 | endif
|
---|
136 |
|
---|
137 | KERN_DIR := /lib/modules/$(KERNELRELEASE)/build
|
---|
138 | KERN_INCL := $(KERN_DIR)/include
|
---|
139 |
|
---|
140 | endif # neq($(KERNELRELEASE),)
|
---|
141 |
|
---|
142 | # debug - show guesses.
|
---|
143 | ifdef DEBUG
|
---|
144 | $(warning dbg: KERN_DIR = $(KERN_DIR))
|
---|
145 | $(warning dbg: KERN_INCL = $(KERN_INCL))
|
---|
146 | $(warning dbg: INSTALL_MOD_PATH = $(INSTALL_MOD_PATH))
|
---|
147 | $(warning dbg: INSTALL_MOD_DIR = $(INSTALL_MOD_DIR))
|
---|
148 | $(warning dbg: KERN_VERSION = $(KERN_VERSION))
|
---|
149 | endif
|
---|