VirtualBox

source: vbox/trunk/src/VBox/Installer/linux/Makefile-header.gmk@ 100191

Last change on this file since 100191 was 100191, checked in by vboxsync, 18 months ago

*: Some of the easy build fixes for linux.arm64 not warranting their own commit, bugref:10457

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 9.9 KB
Line 
1# $Id: Makefile-header.gmk 100191 2023-06-16 08:04:11Z 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-2023 Oracle and/or its affiliates.
10#
11# This file is part of VirtualBox base platform packages, as
12# available from https://www.virtualbox.org.
13#
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#
29
30# Testing:
31# * Building with KERN_DIR set uses the value specified and
32# the default value for the unspecified one if any.
33
34#
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#
39# # Linux kbuild sets this to our source directory if we are called from there
40# obj ?= $(CURDIR)
41# include $(obj)/Makefile-header.gmk
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>
47# include $(obj)/Makefile-footer.gmk
48#
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.
53#
54
55
56#
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).)
59# While at it, warn about *BUILD_* vars found to help with user problems.
60#
61
62# VBOX_KBUILD_TARGET_ARCH = amd64|x86|arm64|arm32
63ifeq ($(filter-out x86_64 amd64 AMD64,$(shell uname -m)),)
64 VBOX_KBUILD_TARGET_ARCH_DEFAULT := amd64
65else ifeq ($(filter-out aarch64,$(shell uname -m)),)
66 VBOX_KBUILD_TARGET_ARCH_DEFAULT := arm64
67else ifeq ($(filter-out armv7,$(shell uname -m)),)
68 VBOX_KBUILD_TARGET_ARCH_DEFAULT := arm32
69else
70 VBOX_KBUILD_TARGET_ARCH_DEFAULT := x86
71endif
72ifdef VBOX_KBUILD_TARGET_ARCH
73 ifneq ($(filter-out amd64 x86 arm64,$(VBOX_KBUILD_TARGET_ARCH)),)
74 $(warning Ignoring unknown VBOX_KBUILD_TARGET_ARCH value '$(VBOX_KBUILD_TARGET_ARCH)'.)
75 VBOX_KBUILD_TARGET_ARCH :=
76 endif
77else
78 ifdef KBUILD_TARGET_ARCH
79 ifneq ($(filter-out amd64 x86 arm64,$(KBUILD_TARGET_ARCH)),)
80 $(warning Ignoring unknown KBUILD_TARGET_ARCH value '$(KBUILD_TARGET_ARCH)'.)
81 VBOX_KBUILD_TARGET_ARCH :=
82 endif
83 else
84 ifdef BUILD_TARGET_ARCH
85 $(warning BUILD_TARGET_ARCH is deprecated, use VBOX_KBUILD_TARGET_ARCH instead.)
86 ifneq ($(filter-out amd64 x86 arm64,$(BUILD_TARGET_ARCH)),)
87 $(warning Ignoring unknown BUILD_TARGET_ARCH value '$(BUILD_TARGET_ARCH)'.)
88 VBOX_KBUILD_TARGET_ARCH :=
89 endif
90 endif
91 endif
92endif
93ifeq ($(VBOX_KBUILD_TARGET_ARCH),)
94 ifeq ($(ARCH),x86_64)
95 VBOX_KBUILD_TARGET_ARCH := amd64
96 else
97 ifeq ($(ARCH),i386)
98 VBOX_KBUILD_TARGET_ARCH := x86
99 else
100 VBOX_KBUILD_TARGET_ARCH := $(VBOX_KBUILD_TARGET_ARCH_DEFAULT)
101 endif
102 endif
103else
104 ifneq ($(VBOX_KBUILD_TARGET_ARCH),$(VBOX_KBUILD_TARGET_ARCH_DEFAULT))
105 $(warning Using VBOX_KBUILD_TARGET_ARCH='$(VBOX_KBUILD_TARGET_ARCH)' from the $(origin VBOX_KBUILD_TARGET_ARCH).)
106 endif
107endif
108
109# VBOX_KBUILD_TYPE = release|debug|profile|strict|asan
110ifdef VBOX_KBUILD_TYPE
111 VBOX_KBUILD_TYPE_VAR := VBOX_KBUILD_TYPE
112 ifneq ($(filter-out release profile debug strict asan,$(VBOX_KBUILD_TYPE)),)
113 $(warning Ignoring unknown VBOX_KBUILD_TYPE value '$(VBOX_KBUILD_TYPE)'.)
114 VBOX_KBUILD_TYPE :=
115 endif
116else
117 ifdef KBUILD_TYPE
118 VBOX_KBUILD_TYPE_VAR := KBUILD_TYPE
119 VBOX_KBUILD_TYPE := $(KBUILD_TYPE)
120 ifneq ($(filter-out release profile debug strict asan,$(KBUILD_TYPE)),)
121 $(warning Ignoring unknown KBUILD_TYPE value '$(KBUILD_TYPE)'.)
122 VBOX_KBUILD_TYPE :=
123 endif
124 else
125 ifdef BUILD_TYPE
126 $(warning BUILD_TYPE is deprecated, use VBOX_KBUILD_TYPE instead.)
127 VBOX_KBUILD_TYPE_VAR := BUILD_TYPE
128 VBOX_KBUILD_TYPE := $(BUILD_TYPE)
129 ifneq ($(filter-out release profile debug strict asan,$(BUILD_TYPE)),)
130 $(warning Ignoring unknown BUILD_TYPE value '$(BUILD_TYPE)'.)
131 VBOX_KBUILD_TYPE :=
132 endif
133 endif
134 endif
135endif
136ifeq ($(VBOX_KBUILD_TYPE),)
137 VBOX_KBUILD_TYPE_VAR = VBOX_KBUILD_TYPE
138 VBOX_KBUILD_TYPE := release
139else
140 ifneq ($(VBOX_KBUILD_TYPE),release)
141 ifndef VBOX_KERN_QUIET
142 $(warning Using VBOX_KBUILD_TYPE='$(VBOX_KBUILD_TYPE)' from the $(origin $(VBOX_KBUILD_TYPE_VAR)) ($(VBOX_KBUILD_TYPE_VAR)).)
143 endif
144 endif
145endif
146
147ifeq ($(USERNAME),)
148 USERNAME := noname
149endif
150
151ifeq ($(KERNELRELEASE),)
152
153 #
154 # building from this directory
155 #
156
157 # kernel base directory
158 ifdef KERN_DIR
159 ifndef KERN_VER
160 ifeq ($(filter %/build,$(KERN_DIR)),)
161 $(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)
162 endif
163 endif
164 endif
165
166 ifndef KERN_VER
167 ifdef KERN_DIR
168 KERN_VER = $(notdir $(patsubst %/build,%,$(KERN_DIR)))
169 ifeq ($(shell expr $(KERN_VER) : '[0-9]*\.[0-9]*.[0-9]*'),0)
170 $(error The kernel build folder path must end in <version>/build, or the variable KERN_VER must be set)
171 endif
172 endif
173 KERN_VER ?= $(shell uname -r)
174 endif
175
176 ifeq ($(KERN_DIR),)
177 KERN_DIR := /lib/modules/$(KERN_VER)/build
178 endif
179
180 # 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.
181 ifeq ($(shell if grep '"2\.4\.' $(KERN_DIR)/include/linux/version.h > /dev/null 2>&1; then echo yes; fi),yes)
182 KERN_VERSION := 24
183 VBOX_KERN_GROKS_EXTMOD :=
184 else
185 KERN_VERSION := 26
186 VBOX_KERN_GROKS_EXTMOD := yes
187 ifeq ($(shell if grep '"2\.6\.[012345][."]' $(KERN_DIR)/include/linux/version.h > /dev/null 2>&1; then echo yes; fi),yes)
188 VBOX_KERN_GROKS_EXTMOD :=
189 endif
190 VBOX_KERN_GROKS_SUBDIRS :=
191 ifeq ($(shell if grep '"[432]\.' $(KERN_DIR)/include/linux/version.h > /dev/null 2>&1; then echo yes; fi),yes)
192 VBOX_KERN_GROKS_SUBDIRS := yes
193 endif
194 endif
195
196 #
197 # Hack for Ubuntu 4.10 where we determine 2.6.8.1-3-generic-amd64 here, but the
198 # the next invocation (M/SUBDIR) ends up with KERNELRELEASE=2.6.8.1-3.
199 #
200 ifeq ($(shell if grep '"[2]\.' $(KERN_DIR)/include/linux/version.h > /dev/null 2>&1; then echo yes; fi),yes)
201 export KERN_VER KERN_DIR
202 else
203 # This makefile received some variables in the command line which should
204 # not be passed to the recursive make invocations (of the Linux makefile
205 # for building kernel modules), since they should derive KERN_DIR from the
206 # respective command line variables to come up with the value they expect.
207 unexport KERN_VER KERN_DIR
208 MAKEOVERRIDES := $(filter-out KERN_VER=% KERN_DIR=%,$(MAKEOVERRIDES))
209 endif
210
211else # neq($(KERNELRELEASE),)
212
213 #
214 # building from kbuild (make -C <kernel_directory> M=`pwd`)
215 #
216
217 # guess kernel version (24 or 26)
218 ifeq ($(VERSION).$(PATCHLEVEL),2.4)
219 KERN_VERSION := 24
220 VBOX_KERN_GROKS_EXTMOD :=
221 else
222 KERN_VERSION := 26
223 VBOX_KERN_GROKS_EXTMOD := yes
224 ifeq ($(VERSION).$(PATCHLEVEL),2.6)
225 ifeq ($(findstring @$(SUBLEVEL)@,@0@1@2@3@4@5@),@$(SUBLEVEL)@)
226 VBOX_KERN_GROKS_EXTMOD :=
227 endif
228 endif
229 VBOX_KERN_GROKS_SUBDIRS :=
230 ifeq ($(VERSION),2)
231 VBOX_KERN_GROKS_SUBDIRS := yes
232 endif
233 ifeq ($(VERSION),3)
234 VBOX_KERN_GROKS_SUBDIRS := yes
235 endif
236 ifeq ($(VERSION),4)
237 VBOX_KERN_GROKS_SUBDIRS := yes
238 endif
239 endif
240
241 KERN_VER := $(KERNELRELEASE)
242
243 ifeq ($(KERN_DIR),)
244 ifneq ($(srctree),)
245 KERN_DIR := $(srctree)
246 else
247 KERN_DIR := /lib/modules/$(KERN_VER)/build
248 endif
249 endif
250endif # neq($(KERNELRELEASE),)
251
252# Kernel build folder
253ifneq ($(shell if test -d $(KERN_DIR); then echo yes; fi),yes)
254 $(error Error: unable to find the headers of the Linux kernel to build against (KERN_DIR=$(KERN_DIR)). \
255 Specify KERN_VER=<version> (currently $(KERN_VER)) and run Make again)
256endif
257# Kernel include folder
258KERN_INCL := $(KERN_DIR)/include
259# module install folder
260INSTALL_MOD_DIR ?= misc
261MODULE_DIR := $(INSTALL_MOD_PATH)/lib/modules/$(KERN_VER)/$(INSTALL_MOD_DIR)
262
263# For VBOX_GCC_CHECK_CC
264VBOX_CLOSEPAR := )
265VBOX_DOLLAR := $$
266## Modified VBOX_GCC_CHECK_EX_CC_CXX macro from /Config.kmk.
267# @param 1 The option to test for.
268# @param 2 The return value when supported.
269# @param 3 The return value when NOT supported.
270VBOX_GCC_CHECK_CC = $(shell \
271 > /tmp/$(VBOX_DOLLAR)$(VBOX_DOLLAR).check.c; \
272 if $(CC) $(subst -Wno-,-W,$(1)) -Werror -c -o /dev/null /tmp/$(VBOX_DOLLAR)$(VBOX_DOLLAR).check.c > /dev/null 2>&1; then \
273 case "`LC_ALL=C $(CC) $(subst -Wno-,-W,$(1)) -Werror -c -o /dev/null /tmp/$(VBOX_DOLLAR)$(VBOX_DOLLAR).check.c 2>&1`" in \
274 "error: unknown warning option"*$(VBOX_CLOSEPAR) echo "$(3)";; \
275 *$(VBOX_CLOSEPAR) echo "$(2)";; \
276 esac; \
277 else echo "$(3)"; fi; \
278 rm -f /tmp/$(VBOX_DOLLAR)$(VBOX_DOLLAR).check.c; )
279
280#
281# Guess the module directory ASSUMING that this file is located in that directory.
282# Note! The special MAKEFILE_LIST variable was introduced in GNU make 3.80.
283#
284ifndef VBOX_MODULE_SRC_DIR
285 ifdef MAKEFILE_LIST
286 VBOX_MODULE_SRC_DIR := $(dir $(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST)))
287 else
288 VBOX_MODULE_SRC_DIR := $(CURDIR)/
289 endif
290endif
291
292
293# debug - show guesses.
294ifdef DEBUG
295 ifndef VBOX_KERN_QUIET
296$(warning dbg: INSTALL_MOD_PATH = $(INSTALL_MOD_PATH))
297$(warning dbg: INSTALL_MOD_DIR = $(INSTALL_MOD_DIR))
298$(warning dbg: KERN_DIR = $(KERN_DIR))
299$(warning dbg: KERN_INCL = $(KERN_INCL))
300$(warning dbg: KERN_VERSION = $(KERN_VERSION))
301$(warning dbg: MODULE_DIR = $(MODULE_DIR))
302$(warning dbg: VBOX_MODULE_SRC_DIR = $(VBOX_MODULE_SRC_DIR))
303 endif
304endif
305
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette