1 | # $Id: Makefile-footer.gmk 106061 2024-09-16 14:03:52Z vboxsync $
|
---|
2 | ## @file
|
---|
3 | # VirtualBox Guest Additions kernel module Makefile, common parts.
|
---|
4 | #
|
---|
5 | # See Makefile-header.gmk for details of how to use this.
|
---|
6 | #
|
---|
7 |
|
---|
8 | #
|
---|
9 | # Copyright (C) 2006-2024 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 | VBOXMOD_0_TARGET = $(VBOXMOD_NAME)
|
---|
31 |
|
---|
32 | KBUILD_VERBOSE ?= 1 # Variable belongs to our kBuild, not the linux one.
|
---|
33 | VBOX_LNX_VERBOSE = $(if $(KBUILD_VERBOSE),1,)
|
---|
34 |
|
---|
35 | #
|
---|
36 | # Compiler options
|
---|
37 | #
|
---|
38 | VBOXMOD_0_KFLAGS := -D__KERNEL__ -DMODULE -DRT_WITHOUT_PRAGMA_ONCE $(addprefix -D,$(VBOXMOD_DEFS))
|
---|
39 | ifeq ($(VBOX_KBUILD_TARGET_ARCH),amd64)
|
---|
40 | VBOXMOD_0_KFLAGS += -DRT_ARCH_AMD64
|
---|
41 | else
|
---|
42 | ifeq ($(VBOX_KBUILD_TARGET_ARCH),x86)
|
---|
43 | VBOXMOD_0_KFLAGS += -DRT_ARCH_X86
|
---|
44 | else
|
---|
45 | ifeq ($(VBOX_KBUILD_TARGET_ARCH),arm64)
|
---|
46 | VBOXMOD_0_KFLAGS += -DRT_ARCH_ARM64
|
---|
47 | else
|
---|
48 | ifeq ($(VBOX_KBUILD_TARGET_ARCH),arm32)
|
---|
49 | VBOXMOD_0_KFLAGS += -DRT_ARCH_ARM32
|
---|
50 | else
|
---|
51 | $(error The variable VBOX_KBUILD_TARGET_ARCH doesn't contain any of the following: amd64, x86, arm64, arm32)
|
---|
52 | endif
|
---|
53 | endif
|
---|
54 | endif
|
---|
55 | endif
|
---|
56 |
|
---|
57 | ifeq ($(VBOX_KBUILD_TYPE),debug)
|
---|
58 | # The -Wno-array-bounds is because of a bug in gcc 4.something, see
|
---|
59 | # https://sourceware.org/bugzilla/show_bug.cgi?id=10001
|
---|
60 | VBOXMOD_0_KFLAGS += -DDEBUG -DDEBUG_$(subst $(subst _, ,_),_,$(USERNAME)) -DDEBUG_USERNAME=$(subst $(subst _, ,_),_,$(USERNAME))
|
---|
61 | ifeq ($(shell expr $(KERN_VER) : '[23]\.'),0)
|
---|
62 | VBOXMOD_0_KFLAGS += -Werror -Wall -Wno-array-bounds
|
---|
63 | # clang objects to calls to __builtin_frame_address with a non-zero argument
|
---|
64 | # on general principles in -Wall mode. The x86 linux kernel has two such calls
|
---|
65 | # in the thread_info.h / arch_within_stack_frames(), though probably safe.
|
---|
66 | ifndef ($(LLVM),) # (This is how the Linux root Makefile (since 5.7) does the test.)
|
---|
67 | VBOXMOD_0_KFLAGS += -Wno-frame-address
|
---|
68 | endif
|
---|
69 | endif
|
---|
70 | endif
|
---|
71 |
|
---|
72 | ifeq ($(VBOX_KERN_GROKS_EXTMOD),)
|
---|
73 | #
|
---|
74 | # Pre 2.6.6
|
---|
75 | #
|
---|
76 | # Note: While pre 2.6.6 kernels could also do "proper" builds from kbuild, the
|
---|
77 | # make script needed to support it was somewhat different from 2.6. Since this
|
---|
78 | # script works and pre-2.6.6 is not a moving target we will not try do do things
|
---|
79 | # the "proper" way.
|
---|
80 | #
|
---|
81 | VBOXMOD_EXT := o
|
---|
82 |
|
---|
83 | ifeq ($(VBOX_KBUILD_TARGET_ARCH),amd64)
|
---|
84 | VBOXMOD_0_KFLAGS += -mcmodel=kernel
|
---|
85 | endif
|
---|
86 | ifeq ($(KERN_VERSION),24)
|
---|
87 | VBOXMOD_0_KFLAGS += -DVBOX_LINUX_2_4
|
---|
88 | endif
|
---|
89 |
|
---|
90 | CFLAGS := -O2 $(VBOXMOD_CFLAGS) $(addprefix -I,$(KERN_INCL) $(VBOXMOD_INCL)) $(VBOXMOD_0_KFLAGS) $(KDEBUG)
|
---|
91 |
|
---|
92 | # 2.4 Module linking
|
---|
93 | $(VBOXMOD_0_TARGET).$(VBOXMOD_EXT): $(VBOXMOD_OBJS)
|
---|
94 | $(LD) -o $@ -r $(VBOXMOD_OBJS)
|
---|
95 |
|
---|
96 | all: $(VBOXMOD_0_TARGET)
|
---|
97 | $(VBOXMOD_0_TARGET): $(VBOXMOD_0_TARGET).$(VBOXMOD_EXT)
|
---|
98 |
|
---|
99 | install: $(VBOXMOD_0_TARGET)
|
---|
100 | @mkdir -p $(MODULE_DIR); \
|
---|
101 | install -m 0644 -o root -g root $(VBOXMOD_0_TARGET).$(VBOXMOD_EXT) $(MODULE_DIR); \
|
---|
102 | PATH="$(PATH):/bin:/sbin" depmod -a; sync
|
---|
103 |
|
---|
104 | clean:
|
---|
105 | for f in $(sort $(dir $(VBOXMOD_OBJS))); do rm -f $$f/*.o $$f/.*.cmd $$f/.*.flags; done
|
---|
106 | rm -rf .$(VBOXMOD_NAME)* .tmp_ver* $(VBOXMOD_NAME).* Modules.symvers modules.order
|
---|
107 |
|
---|
108 | .PHONY: all $(VBOXMOD_0_TARGET) install clean
|
---|
109 |
|
---|
110 | else # VBOX_KERN_GROKS_EXTMOD
|
---|
111 | #
|
---|
112 | # 2.6.6 and later
|
---|
113 | #
|
---|
114 | VBOXMOD_EXT := ko
|
---|
115 |
|
---|
116 | # build defs
|
---|
117 | EXTRA_CFLAGS += $(VBOXMOD_CFLAGS) $(addprefix -I,$(KERN_INCL) $(VBOXMOD_INCL)) $(VBOXMOD_0_KFLAGS) $(KDEBUG)
|
---|
118 | $(VBOXMOD_0_TARGET)-y := $(VBOXMOD_OBJS)
|
---|
119 | obj-m += $(VBOXMOD_0_TARGET).o
|
---|
120 |
|
---|
121 | # Trigger parallel make job.
|
---|
122 | ifndef VBOX_NOJOBS
|
---|
123 | JOBS := $(shell (getconf _NPROCESSORS_ONLN || grep -Ec '^processor|^CPU[0-9]' /proc/cpuinfo) 2>/dev/null)
|
---|
124 | ifeq ($(JOBS),0)
|
---|
125 | override JOBS := 1
|
---|
126 | endif
|
---|
127 | else
|
---|
128 | JOBS :=
|
---|
129 | endif
|
---|
130 |
|
---|
131 | VBOX_SUBDIR_VAR=$(if $(VBOX_KERN_GROKS_SUBDIRS),SUBDIRS,M)
|
---|
132 |
|
---|
133 | # OL/UEK: CONFIG_MODULE_SIG= disables module signing for external modules.
|
---|
134 | # Ubuntu 18.04.3: CONFIG_MODULE_SIG_ALL= disables signing of all modules.
|
---|
135 | # We disable signing because we don't have any private key and want to leave
|
---|
136 | # the key handling and secure boot config to the user.
|
---|
137 | ifndef VBOX_ALLOW_MODULE_SIGNING
|
---|
138 | VBOX_DISABLE_SIGN=CONFIG_MODULE_SIG= CONFIG_MODULE_SIG_ALL=
|
---|
139 | endif
|
---|
140 |
|
---|
141 | # rules:
|
---|
142 | all: $(VBOXMOD_0_TARGET)
|
---|
143 |
|
---|
144 | $(VBOXMOD_0_TARGET):
|
---|
145 | $(MAKE) V=$(VBOX_LNX_VERBOSE) $(VBOX_DISABLE_SIGN) -C $(KERN_DIR) $(VBOX_SUBDIR_VAR)=$(CURDIR) SRCROOT=$(CURDIR) $(if $(JOBS),-j$(JOBS),) modules
|
---|
146 |
|
---|
147 | install: $(VBOXMOD_0_TARGET)
|
---|
148 | $(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
|
---|
149 |
|
---|
150 | modules_install: install
|
---|
151 |
|
---|
152 | clean:
|
---|
153 | $(MAKE) V=$(VBOX_LNX_VERBOSE) $(VBOX_DISABLE_SIGN) -C $(KERN_DIR) $(VBOX_SUBDIR_VAR)=$(CURDIR) SRCROOT=$(CURDIR) clean
|
---|
154 |
|
---|
155 | .PHONY: all $(VBOXMOD_0_TARGET) install modules_install clean
|
---|
156 | endif # VBOX_KERN_GROKS_EXTMOD
|
---|
157 |
|
---|