1 | # $Id: Makefile-header.gmk 84947 2020-06-25 11:52:07Z vboxsync $
|
---|
2 | ## @file
|
---|
3 | # VirtualBox Guest Additions kernel module Makefile, common parts.
|
---|
4 | #
|
---|
5 | # (For 2.6.x, the main file must be called 'Makefile'!)
|
---|
6 | #
|
---|
7 |
|
---|
8 | #
|
---|
9 | # Copyright (C) 2006-2020 Oracle Corporation
|
---|
10 | #
|
---|
11 | # This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
12 | # available from http://www.virtualbox.org. This file is free software;
|
---|
13 | # you can redistribute it and/or modify it under the terms of the GNU
|
---|
14 | # General Public License (GPL) as published by the Free Software
|
---|
15 | # Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
16 | # VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
17 | # hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
18 | #
|
---|
19 |
|
---|
20 | # Testing:
|
---|
21 | # * Building with KERN_DIR set uses the value specified and
|
---|
22 | # the default value for the unspecified one if any.
|
---|
23 |
|
---|
24 | #
|
---|
25 | # These file should be included by the Makefiles for any kernel modules we
|
---|
26 | # build as part of the Guest Additions. The intended way of doing this is as
|
---|
27 | # follows:
|
---|
28 | #
|
---|
29 | # # Linux kbuild sets this to our source directory if we are called from there
|
---|
30 | # obj ?= $(CURDIR)
|
---|
31 | # include $(obj)/Makefile-header.gmk
|
---|
32 | # VBOXMOD_NAME = <name of the module to be built, without extension>
|
---|
33 | # VBOXMOD_OBJS = <list of object files which should be included>
|
---|
34 | # VBOXMOD_DEFS = <any additional defines which this module needs>
|
---|
35 | # VBOXMOD_INCL = <any additional include paths which this module needs>
|
---|
36 | # VBOXMOD_CFLAGS = <any additional CFLAGS which this module needs>
|
---|
37 | # include $(obj)/Makefile-footer.gmk
|
---|
38 | #
|
---|
39 | # To avoid potential confusion between kmk/kBuild and linux/kbuild,
|
---|
40 | # we use VBOX_KBUILD_TARGET_ARCH instead of KBUILD_TARGET_ARCH and
|
---|
41 | # VBOX_KBUILD_TYPE instead of KBUILD_TYPE. The VBOX_KBUILD_ variable
|
---|
42 | # variant takes percedence over the kmk/kBuild ones.
|
---|
43 | #
|
---|
44 |
|
---|
45 |
|
---|
46 | #
|
---|
47 | # First, figure out which architecture we're targeting and the build type.
|
---|
48 | # (We have to support basic cross building (ARCH=i386|x86_64).)
|
---|
49 | # While at it, warn about *BUILD_* vars found to help with user problems.
|
---|
50 | #
|
---|
51 |
|
---|
52 | # VBOX_KBUILD_TARGET_ARCH = amd64|x86
|
---|
53 | ifeq ($(filter-out x86_64 amd64 AMD64,$(shell uname -m)),)
|
---|
54 | VBOX_KBUILD_TARGET_ARCH_DEFAULT := amd64
|
---|
55 | else
|
---|
56 | VBOX_KBUILD_TARGET_ARCH_DEFAULT := x86
|
---|
57 | endif
|
---|
58 | ifdef VBOX_KBUILD_TARGET_ARCH
|
---|
59 | ifneq ($(filter-out amd64 x86,$(VBOX_KBUILD_TARGET_ARCH)),)
|
---|
60 | $(warning Ignoring unknown VBOX_KBUILD_TARGET_ARCH value '$(VBOX_KBUILD_TARGET_ARCH)'.)
|
---|
61 | VBOX_KBUILD_TARGET_ARCH :=
|
---|
62 | endif
|
---|
63 | else
|
---|
64 | ifdef KBUILD_TARGET_ARCH
|
---|
65 | ifneq ($(filter-out amd64 x86,$(KBUILD_TARGET_ARCH)),)
|
---|
66 | $(warning Ignoring unknown KBUILD_TARGET_ARCH value '$(KBUILD_TARGET_ARCH)'.)
|
---|
67 | VBOX_KBUILD_TARGET_ARCH :=
|
---|
68 | endif
|
---|
69 | else
|
---|
70 | ifdef BUILD_TARGET_ARCH
|
---|
71 | $(warning BUILD_TARGET_ARCH is deprecated, use VBOX_KBUILD_TARGET_ARCH instead.)
|
---|
72 | ifneq ($(filter-out amd64 x86,$(BUILD_TARGET_ARCH)),)
|
---|
73 | $(warning Ignoring unknown BUILD_TARGET_ARCH value '$(BUILD_TARGET_ARCH)'.)
|
---|
74 | VBOX_KBUILD_TARGET_ARCH :=
|
---|
75 | endif
|
---|
76 | endif
|
---|
77 | endif
|
---|
78 | endif
|
---|
79 | ifeq ($(VBOX_KBUILD_TARGET_ARCH),)
|
---|
80 | ifeq ($(ARCH),x86_64)
|
---|
81 | VBOX_KBUILD_TARGET_ARCH := amd64
|
---|
82 | else
|
---|
83 | ifeq ($(ARCH),i386)
|
---|
84 | VBOX_KBUILD_TARGET_ARCH := x86
|
---|
85 | else
|
---|
86 | VBOX_KBUILD_TARGET_ARCH := $(VBOX_KBUILD_TARGET_ARCH_DEFAULT)
|
---|
87 | endif
|
---|
88 | endif
|
---|
89 | else
|
---|
90 | ifneq ($(VBOX_KBUILD_TARGET_ARCH),$(VBOX_KBUILD_TARGET_ARCH_DEFAULT))
|
---|
91 | $(warning Using VBOX_KBUILD_TARGET_ARCH='$(VBOX_KBUILD_TARGET_ARCH)' from the $(origin VBOX_KBUILD_TARGET_ARCH).)
|
---|
92 | endif
|
---|
93 | endif
|
---|
94 |
|
---|
95 | # VBOX_KBUILD_TYPE = release|debug|profile|strict
|
---|
96 | ifdef VBOX_KBUILD_TYPE
|
---|
97 | VBOX_KBUILD_TYPE_VAR := VBOX_KBUILD_TYPE
|
---|
98 | ifneq ($(filter-out release profile debug strict,$(VBOX_KBUILD_TYPE)),)
|
---|
99 | $(warning Ignoring unknown VBOX_KBUILD_TYPE value '$(VBOX_KBUILD_TYPE)'.)
|
---|
100 | VBOX_KBUILD_TYPE :=
|
---|
101 | endif
|
---|
102 | else
|
---|
103 | ifdef KBUILD_TYPE
|
---|
104 | VBOX_KBUILD_TYPE_VAR := KBUILD_TYPE
|
---|
105 | VBOX_KBUILD_TYPE := $(KBUILD_TYPE)
|
---|
106 | ifneq ($(filter-out release profile debug strict,$(KBUILD_TYPE)),)
|
---|
107 | $(warning Ignoring unknown KBUILD_TYPE value '$(KBUILD_TYPE)'.)
|
---|
108 | VBOX_KBUILD_TYPE :=
|
---|
109 | endif
|
---|
110 | else
|
---|
111 | ifdef BUILD_TYPE
|
---|
112 | $(warning BUILD_TYPE is deprecated, use VBOX_KBUILD_TYPE instead.)
|
---|
113 | VBOX_KBUILD_TYPE_VAR := BUILD_TYPE
|
---|
114 | VBOX_KBUILD_TYPE := $(BUILD_TYPE)
|
---|
115 | ifneq ($(filter-out release profile debug strict,$(BUILD_TYPE)),)
|
---|
116 | $(warning Ignoring unknown BUILD_TYPE value '$(BUILD_TYPE)'.)
|
---|
117 | VBOX_KBUILD_TYPE :=
|
---|
118 | endif
|
---|
119 | endif
|
---|
120 | endif
|
---|
121 | endif
|
---|
122 | ifeq ($(VBOX_KBUILD_TYPE),)
|
---|
123 | VBOX_KBUILD_TYPE_VAR = VBOX_KBUILD_TYPE
|
---|
124 | VBOX_KBUILD_TYPE := release
|
---|
125 | else
|
---|
126 | ifneq ($(VBOX_KBUILD_TYPE),release)
|
---|
127 | ifndef VBOX_KERN_QUIET
|
---|
128 | $(warning Using VBOX_KBUILD_TYPE='$(VBOX_KBUILD_TYPE)' from the $(origin $(VBOX_KBUILD_TYPE_VAR)) ($(VBOX_KBUILD_TYPE_VAR)).)
|
---|
129 | endif
|
---|
130 | endif
|
---|
131 | endif
|
---|
132 |
|
---|
133 | ifeq ($(USERNAME),)
|
---|
134 | USERNAME := noname
|
---|
135 | endif
|
---|
136 |
|
---|
137 | ifeq ($(KERNELRELEASE),)
|
---|
138 |
|
---|
139 | #
|
---|
140 | # building from this directory
|
---|
141 | #
|
---|
142 |
|
---|
143 | # kernel base directory
|
---|
144 | ifdef KERN_DIR
|
---|
145 | ifndef KERN_VER
|
---|
146 | ifeq ($(filter %/build,$(KERN_DIR)),)
|
---|
147 | $(error The variable KERN_DIR must be a kernel build folder and end with /build without a trailing slash, or KERN_VER must be set)
|
---|
148 | endif
|
---|
149 | endif
|
---|
150 | endif
|
---|
151 |
|
---|
152 | ifndef KERN_VER
|
---|
153 | ifdef KERN_DIR
|
---|
154 | KERN_VER = $(notdir $(patsubst %/build,%,$(KERN_DIR)))
|
---|
155 | ifeq ($(shell expr $(KERN_VER) : '[0-9]*\.[0-9]*.[0-9]*'),0)
|
---|
156 | $(error The kernel build folder path must end in <version>/build, or the variable KERN_VER must be set)
|
---|
157 | endif
|
---|
158 | endif
|
---|
159 | KERN_VER ?= $(shell uname -r)
|
---|
160 | endif
|
---|
161 |
|
---|
162 | ifeq ($(KERN_DIR),)
|
---|
163 | KERN_DIR := /lib/modules/$(KERN_VER)/build
|
---|
164 | endif
|
---|
165 |
|
---|
166 | # Is this 2.4 or < 2.6.6? The UTS_RELEASE "2.x.y.z" define is present in the header until 2.6.1x something.
|
---|
167 | ifeq ($(shell if grep '"2\.4\.' $(KERN_DIR)/include/linux/version.h > /dev/null 2>&1; then echo yes; fi),yes)
|
---|
168 | KERN_VERSION := 24
|
---|
169 | VBOX_KERN_GROKS_EXTMOD :=
|
---|
170 | else
|
---|
171 | KERN_VERSION := 26
|
---|
172 | VBOX_KERN_GROKS_EXTMOD := yes
|
---|
173 | ifeq ($(shell if grep '"2\.6\.[012345][."]' $(KERN_DIR)/include/linux/version.h > /dev/null 2>&1; then echo yes; fi),yes)
|
---|
174 | VBOX_KERN_GROKS_EXTMOD :=
|
---|
175 | endif
|
---|
176 | VBOX_KERN_GROKS_SUBDIRS :=
|
---|
177 | ifeq ($(shell if grep '"[432]\.' $(KERN_DIR)/include/linux/version.h > /dev/null 2>&1; then echo yes; fi),yes)
|
---|
178 | VBOX_KERN_GROKS_SUBDIRS := yes
|
---|
179 | endif
|
---|
180 | endif
|
---|
181 |
|
---|
182 | #
|
---|
183 | # Hack for Ubuntu 4.10 where we determine 2.6.8.1-3-generic-amd64 here, but the
|
---|
184 | # the next invocation (M/SUBDIR) ends up with KERNELRELEASE=2.6.8.1-3.
|
---|
185 | #
|
---|
186 | ifeq ($(shell if grep '"[2]\.' $(KERN_DIR)/include/linux/version.h > /dev/null 2>&1; then echo yes; fi),yes)
|
---|
187 | export KERN_VER KERN_DIR
|
---|
188 | else
|
---|
189 | # This makefile received some variables in the command line which should
|
---|
190 | # not be passed to the recursive make invocations (of the Linux makefile
|
---|
191 | # for building kernel modules), since they should derive KERN_DIR from the
|
---|
192 | # respective command line variables to come up with the value they expect.
|
---|
193 | unexport KERN_VER KERN_DIR
|
---|
194 | MAKEOVERRIDES := $(filter-out KERN_VER=% KERN_DIR=%,$(MAKEOVERRIDES))
|
---|
195 | endif
|
---|
196 |
|
---|
197 | else # neq($(KERNELRELEASE),)
|
---|
198 |
|
---|
199 | #
|
---|
200 | # building from kbuild (make -C <kernel_directory> M=`pwd`)
|
---|
201 | #
|
---|
202 |
|
---|
203 | # guess kernel version (24 or 26)
|
---|
204 | ifeq ($(VERSION).$(PATCHLEVEL),2.4)
|
---|
205 | KERN_VERSION := 24
|
---|
206 | VBOX_KERN_GROKS_EXTMOD :=
|
---|
207 | else
|
---|
208 | KERN_VERSION := 26
|
---|
209 | VBOX_KERN_GROKS_EXTMOD := yes
|
---|
210 | ifeq ($(VERSION).$(PATCHLEVEL),2.6)
|
---|
211 | ifeq ($(findstring @$(SUBLEVEL)@,@0@1@2@3@4@5@),@$(SUBLEVEL)@)
|
---|
212 | VBOX_KERN_GROKS_EXTMOD :=
|
---|
213 | endif
|
---|
214 | endif
|
---|
215 | VBOX_KERN_GROKS_SUBDIRS :=
|
---|
216 | ifeq ($(VERSION),2)
|
---|
217 | VBOX_KERN_GROKS_SUBDIRS := yes
|
---|
218 | endif
|
---|
219 | ifeq ($(VERSION),3)
|
---|
220 | VBOX_KERN_GROKS_SUBDIRS := yes
|
---|
221 | endif
|
---|
222 | ifeq ($(VERSION),4)
|
---|
223 | VBOX_KERN_GROKS_SUBDIRS := yes
|
---|
224 | endif
|
---|
225 | endif
|
---|
226 |
|
---|
227 | KERN_VER := $(KERNELRELEASE)
|
---|
228 |
|
---|
229 | ifeq ($(KERN_DIR),)
|
---|
230 | ifneq ($(srctree),)
|
---|
231 | KERN_DIR := $(srctree)
|
---|
232 | else
|
---|
233 | KERN_DIR := /lib/modules/$(KERN_VER)/build
|
---|
234 | endif
|
---|
235 | endif
|
---|
236 | endif # neq($(KERNELRELEASE),)
|
---|
237 |
|
---|
238 | # Kernel build folder
|
---|
239 | ifneq ($(shell if test -d $(KERN_DIR); then echo yes; fi),yes)
|
---|
240 | $(error Error: unable to find the headers of the Linux kernel to build against (KERN_DIR=$(KERN_DIR)). \
|
---|
241 | Specify KERN_VER=<version> (currently $(KERN_VER)) and run Make again)
|
---|
242 | endif
|
---|
243 | # Kernel include folder
|
---|
244 | KERN_INCL := $(KERN_DIR)/include
|
---|
245 | # module install folder
|
---|
246 | INSTALL_MOD_DIR ?= misc
|
---|
247 | MODULE_DIR := $(INSTALL_MOD_PATH)/lib/modules/$(KERN_VER)/$(INSTALL_MOD_DIR)
|
---|
248 |
|
---|
249 | # For VBOX_GCC_CHECK_CC
|
---|
250 | VBOX_CLOSEPAR := )
|
---|
251 | VBOX_DOLLAR := $$
|
---|
252 | ## Modified VBOX_GCC_CHECK_EX_CC_CXX macro from /Config.kmk.
|
---|
253 | # @param 1 The option to test for.
|
---|
254 | # @param 2 The return value when supported.
|
---|
255 | # @param 3 The return value when NOT supported.
|
---|
256 | VBOX_GCC_CHECK_CC = $(shell \
|
---|
257 | > /tmp/$(VBOX_DOLLAR)$(VBOX_DOLLAR).check.c; \
|
---|
258 | if $(CC) $(subst -Wno-,-W,$(1)) -Werror -c -o /dev/null /tmp/$(VBOX_DOLLAR)$(VBOX_DOLLAR).check.c > /dev/null 2>&1; then \
|
---|
259 | case "`LC_ALL=C $(CC) $(subst -Wno-,-W,$(1)) -Werror -c -o /dev/null /tmp/$(VBOX_DOLLAR)$(VBOX_DOLLAR).check.c 2>&1`" in \
|
---|
260 | "error: unknown warning option"*$(VBOX_CLOSEPAR) echo "$(3)";; \
|
---|
261 | *$(VBOX_CLOSEPAR) echo "$(2)";; \
|
---|
262 | esac; \
|
---|
263 | else echo "$(3)"; fi; \
|
---|
264 | rm -f /tmp/$(VBOX_DOLLAR)$(VBOX_DOLLAR).check.c; )
|
---|
265 |
|
---|
266 | #
|
---|
267 | # Guess the module directory ASSUMING that this file is located in that directory.
|
---|
268 | # Note! The special MAKEFILE_LIST variable was introduced in GNU make 3.80.
|
---|
269 | #
|
---|
270 | ifdef MAKEFILE_LIST
|
---|
271 | VBOX_MODULE_SRC_DIR := $(dir $(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST)))
|
---|
272 | else
|
---|
273 | VBOX_MODULE_SRC_DIR := $(CURDIR)/
|
---|
274 | endif
|
---|
275 |
|
---|
276 |
|
---|
277 | # debug - show guesses.
|
---|
278 | ifdef DEBUG
|
---|
279 | ifndef VBOX_KERN_QUIET
|
---|
280 | $(warning dbg: INSTALL_MOD_PATH = $(INSTALL_MOD_PATH))
|
---|
281 | $(warning dbg: INSTALL_MOD_DIR = $(INSTALL_MOD_DIR))
|
---|
282 | $(warning dbg: KERN_DIR = $(KERN_DIR))
|
---|
283 | $(warning dbg: KERN_INCL = $(KERN_INCL))
|
---|
284 | $(warning dbg: KERN_VERSION = $(KERN_VERSION))
|
---|
285 | $(warning dbg: MODULE_DIR = $(MODULE_DIR))
|
---|
286 | $(warning dbg: VBOX_MODULE_SRC_DIR = $(VBOX_MODULE_SRC_DIR))
|
---|
287 | endif
|
---|
288 | endif
|
---|
289 |
|
---|