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