1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
|
# $Id: Makefile-footer.gmk $
## @file
# VirtualBox Guest Additions kernel module Makefile, common parts.
#
# See Makefile-header.gmk for details of how to use this.
#
#
# Copyright (C) 2006-2023 Oracle and/or its affiliates.
#
# This file is part of VirtualBox base platform packages, as
# available from https://www.virtualbox.org.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation, in version 3 of the
# License.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, see <https://www.gnu.org/licenses>.
#
# SPDX-License-Identifier: GPL-3.0-only
#
VBOXMOD_0_TARGET = $(VBOXMOD_NAME)
KBUILD_VERBOSE ?= 1 # Variable belongs to our kBuild, not the linux one.
VBOX_LNX_VERBOSE = $(if $(KBUILD_VERBOSE),1,)
#
# Compiler options
#
VBOXMOD_0_KFLAGS := -D__KERNEL__ -DMODULE -DRT_WITHOUT_PRAGMA_ONCE $(addprefix -D,$(VBOXMOD_DEFS))
ifeq ($(VBOX_KBUILD_TARGET_ARCH),amd64)
VBOXMOD_0_KFLAGS += -DRT_ARCH_AMD64
else
VBOXMOD_0_KFLAGS += -DRT_ARCH_X86
endif
ifeq ($(VBOX_KBUILD_TYPE),debug)
# The -Wno-array-bounds is because of a bug in gcc 4.something, see
# https://sourceware.org/bugzilla/show_bug.cgi?id=10001
VBOXMOD_0_KFLAGS += -DDEBUG -DDEBUG_$(subst $(subst _, ,_),_,$(USERNAME)) -DDEBUG_USERNAME=$(subst $(subst _, ,_),_,$(USERNAME))
ifeq ($(shell expr $(KERN_VER) : '[23]\.'),0)
VBOXMOD_0_KFLAGS += -Werror -Wall -Wno-array-bounds
# clang objects to calls to __builtin_frame_address with a non-zero argument
# on general principles in -Wall mode. The x86 linux kernel has two such calls
# in the thread_info.h / arch_within_stack_frames(), though probably safe.
ifndef ($(LLVM),) # (This is how the Linux root Makefile (since 5.7) does the test.)
VBOXMOD_0_KFLAGS += -Wno-frame-address
endif
endif
endif
ifeq ($(VBOX_KERN_GROKS_EXTMOD),)
#
# Pre 2.6.6
#
# Note: While pre 2.6.6 kernels could also do "proper" builds from kbuild, the
# make script needed to support it was somewhat different from 2.6. Since this
# script works and pre-2.6.6 is not a moving target we will not try do do things
# the "proper" way.
#
VBOXMOD_EXT := o
ifeq ($(VBOX_KBUILD_TARGET_ARCH),amd64)
VBOXMOD_0_KFLAGS += -mcmodel=kernel
endif
ifeq ($(KERN_VERSION),24)
VBOXMOD_0_KFLAGS += -DVBOX_LINUX_2_4
endif
CFLAGS := -O2 $(VBOXMOD_CFLAGS) $(addprefix -I,$(KERN_INCL) $(VBOXMOD_INCL)) $(VBOXMOD_0_KFLAGS) $(KDEBUG)
# 2.4 Module linking
$(VBOXMOD_0_TARGET).$(VBOXMOD_EXT): $(VBOXMOD_OBJS)
$(LD) -o $@ -r $(VBOXMOD_OBJS)
all: $(VBOXMOD_0_TARGET)
$(VBOXMOD_0_TARGET): $(VBOXMOD_0_TARGET).$(VBOXMOD_EXT)
install: $(VBOXMOD_0_TARGET)
@mkdir -p $(MODULE_DIR); \
install -m 0644 -o root -g root $(VBOXMOD_0_TARGET).$(VBOXMOD_EXT) $(MODULE_DIR); \
PATH="$(PATH):/bin:/sbin" depmod -a; sync
clean:
for f in $(sort $(dir $(VBOXMOD_OBJS))); do rm -f $$f/*.o $$f/.*.cmd $$f/.*.flags; done
rm -rf .$(VBOXMOD_NAME)* .tmp_ver* $(VBOXMOD_NAME).* Modules.symvers modules.order
.PHONY: all $(VBOXMOD_0_TARGET) install clean
else # VBOX_KERN_GROKS_EXTMOD
#
# 2.6.6 and later
#
VBOXMOD_EXT := ko
# build defs
EXTRA_CFLAGS += $(VBOXMOD_CFLAGS) $(addprefix -I,$(KERN_INCL) $(VBOXMOD_INCL)) $(VBOXMOD_0_KFLAGS) $(KDEBUG)
$(VBOXMOD_0_TARGET)-y := $(VBOXMOD_OBJS)
obj-m += $(VBOXMOD_0_TARGET).o
# Trigger parallel make job.
ifndef VBOX_NOJOBS
JOBS := $(shell (getconf _NPROCESSORS_ONLN || grep -Ec '^processor|^CPU[0-9]' /proc/cpuinfo) 2>/dev/null)
ifeq ($(JOBS),0)
override JOBS := 1
endif
else
JOBS :=
endif
VBOX_SUBDIR_VAR=$(if $(VBOX_KERN_GROKS_SUBDIRS),SUBDIRS,M)
# OL/UEK: CONFIG_MODULE_SIG= disables module signing for external modules.
# Ubuntu 18.04.3: CONFIG_MODULE_SIG_ALL= disables signing of all modules.
# We disable signing because we don't have any private key and want to leave
# the key handling and secure boot config to the user.
ifndef VBOX_ALLOW_MODULE_SIGNING
VBOX_DISABLE_SIGN=CONFIG_MODULE_SIG= CONFIG_MODULE_SIG_ALL=
endif
# rules:
all: $(VBOXMOD_0_TARGET)
$(VBOXMOD_0_TARGET):
$(MAKE) V=$(VBOX_LNX_VERBOSE) $(VBOX_DISABLE_SIGN) -C $(KERN_DIR) $(VBOX_SUBDIR_VAR)=$(CURDIR) SRCROOT=$(CURDIR) $(if $(JOBS),-j$(JOBS),) modules
install: $(VBOXMOD_0_TARGET)
$(MAKE) V=$(VBOX_LNX_VERBOSE) $(VBOX_DISABLE_SIGN) -C $(KERN_DIR) $(VBOX_SUBDIR_VAR)=$(CURDIR) SRCROOT=$(CURDIR) INSTALL_MOD_PATH=$(INSTALL_MOD_PATH) INSTALL_MOD_DIR=$(INSTALL_MOD_DIR) modules_install
modules_install: install
clean:
$(MAKE) V=$(VBOX_LNX_VERBOSE) $(VBOX_DISABLE_SIGN) -C $(KERN_DIR) $(VBOX_SUBDIR_VAR)=$(CURDIR) SRCROOT=$(CURDIR) clean
.PHONY: all $(VBOXMOD_0_TARGET) install modules_install clean
endif # VBOX_KERN_GROKS_EXTMOD
|