VirtualBox

source: vbox/trunk/src/VBox/HostDrivers/linux/Makefile@ 104448

Last change on this file since 104448 was 98103, checked in by vboxsync, 2 years ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 7.2 KB
Line 
1#
2# Makefile for the VirtualBox Linux Host Drivers.
3#
4
5#
6# Copyright (C) 2008-2023 Oracle and/or its affiliates.
7#
8# This file is part of VirtualBox base platform packages, as
9# available from https://www.virtualbox.org.
10#
11# This program is free software; you can redistribute it and/or
12# modify it under the terms of the GNU General Public License
13# as published by the Free Software Foundation, in version 3 of the
14# License.
15#
16# This program is distributed in the hope that it will be useful, but
17# WITHOUT ANY WARRANTY; without even the implied warranty of
18# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19# General Public License for more details.
20#
21# You should have received a copy of the GNU General Public License
22# along with this program; if not, see <https://www.gnu.org/licenses>.
23#
24# The contents of this file may alternatively be used under the terms
25# of the Common Development and Distribution License Version 1.0
26# (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
27# in the VirtualBox distribution, in which case the provisions of the
28# CDDL are applicable instead of those of the GPL.
29#
30# You may elect to license modified versions of this file under the
31# terms and conditions of either the GPL or the CDDL or both.
32#
33# SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
34#
35
36ifneq ($(KERNELRELEASE),)
37
38# Building from kBuild (make -C <kernel_directory> M=`pwd`),
39# or inside a kernel source tree.
40
41obj-m = vboxdrv/
42 ifneq ($(wildcard $(CURDIR)/vboxnetflt/Makefile),)
43obj-m += vboxnetflt/
44 endif
45 ifneq ($(wildcard $(CURDIR)/vboxnetadp/Makefile),)
46obj-m += vboxnetadp/
47 endif
48 ifneq ($(wildcard $(CURDIR)/vboxpci/Makefile),)
49obj-m += vboxpci/
50 endif
51
52else # ! KERNELRELEASE
53
54# convenience Makefile without KERNELRELEASE
55
56ifndef SUDO
57 ifneq ($(shell id -u),0)
58SUDO := $(firstword $(wildcard /usr/bin/sudo /bin/sudo /usr/sbin/sudo))
59 else
60SUDO :=
61 endif
62endif
63
64KBUILD_VERBOSE ?=
65.PHONY: all install clean check unload load \
66 vboxdrv vboxnetflt vboxnetadp vboxpci \
67 install-vboxdrv install-vboxnetflt install-vboxnetadp install-vboxpci \
68 clean-vboxdrv clean-vboxnetflt clean-vboxnetadp clean-vboxpci
69
70all: vboxdrv vboxnetflt vboxnetadp vboxpci
71
72# We want to build on Linux 2.6.18 and later kernels.
73KERN_VER ?= $(shell uname -r)
74 ifneq ($(filter-out 1.% 2.0.% 2.1.% 2.2.% 2.3.% 2.4.% 2.5.%,$(KERN_VER)),)
75
76vboxdrv:
77 @echo "=== Building 'vboxdrv' module ==="
78 +@$(MAKE) KBUILD_VERBOSE=$(KBUILD_VERBOSE) -C vboxdrv
79 @cp vboxdrv/vboxdrv.ko .
80 @echo
81
82vboxnetflt: vboxdrv
83 +@if [ -d vboxnetflt ]; then \
84 if [ -f vboxdrv/Module.symvers ]; then \
85 cp vboxdrv/Module.symvers vboxnetflt; \
86 fi; \
87 echo "=== Building 'vboxnetflt' module ==="; \
88 $(MAKE) KBUILD_VERBOSE=$(KBUILD_VERBOSE) KBUILD_EXTRA_SYMBOLS=$(abspath vboxnetflt/Module.symvers) -C vboxnetflt || exit 1; \
89 cp vboxnetflt/vboxnetflt.ko .; \
90 echo; \
91 fi
92
93vboxnetadp: vboxdrv
94 +@if [ -d vboxnetadp ]; then \
95 if [ -f vboxdrv/Module.symvers ]; then \
96 cp vboxdrv/Module.symvers vboxnetadp; \
97 fi; \
98 echo "=== Building 'vboxnetadp' module ==="; \
99 $(MAKE) KBUILD_VERBOSE=$(KBUILD_VERBOSE) KBUILD_EXTRA_SYMBOLS=$(abspath vboxnetadp/Module.symvers) -C vboxnetadp || exit 1; \
100 cp vboxnetadp/vboxnetadp.ko .; \
101 echo; \
102 fi
103
104vboxpci: vboxdrv
105 +@if [ -d vboxpci ]; then \
106 if [ -f vboxdrv/Module.symvers ]; then \
107 cp vboxdrv/Module.symvers vboxpci; \
108 fi; \
109 echo "=== Building 'vboxpci' module ==="; \
110 $(MAKE) KBUILD_VERBOSE=$(KBUILD_VERBOSE) KBUILD_EXTRA_SYMBOLS=$(abspath vboxpci/Module.symvers) -C vboxpci || exit 1; \
111 cp vboxpci/vboxpci.ko .; \
112 echo; \
113 fi
114
115install-vboxdrv:
116 +@$(MAKE) KBUILD_VERBOSE=$(KBUILD_VERBOSE) -C vboxdrv install
117
118install-vboxnetflt:
119 +@if [ -d vboxnetflt ]; then \
120 $(MAKE) KBUILD_VERBOSE=$(KBUILD_VERBOSE) -C vboxnetflt install; \
121 fi
122
123install-vboxnetadp:
124 +@if [ -d vboxnetadp ]; then \
125 $(MAKE) KBUILD_VERBOSE=$(KBUILD_VERBOSE) -C vboxnetadp install; \
126 fi
127
128install-vboxpci:
129 +@if [ -d vboxpci ]; then \
130 $(MAKE) KBUILD_VERBOSE=$(KBUILD_VERBOSE) -C vboxpci install; \
131 fi
132
133install: install-vboxdrv install-vboxnetflt install-vboxnetadp install-vboxpci
134
135# Look for wrapper modules, sorting them so vmmr0 is first.
136VBOX_WRAPPER_DIRS := $(notdir $(wildcard $(CURDIR)/vbox_*))
137 ifneq ($(VBOX_WRAPPER_DIRS),)
138VBOX_WRAPPER_DIRS := $(filter vbox_vmmr0,$(VBOX_WRAPPER_DIRS)) $(sort $(filter-out vbox_vmmr0,$(VBOX_WRAPPER_DIRS)))
139 endif
140 define wrapper_template
141$(wrapper): $(subst $(wrapper),,vbox_vmmr0)
142 +$$(MAKE) KBUILD_VERBOSE=$$(KBUILD_VERBOSE) -C $(wrapper)/
143
144load-$(wrapper): $(subst load-$(wrapper),,load-vbox_vmmr0)
145 @if ! grep -q "^$(wrapper) " /proc/modules; then \
146 echo "Loading $(wrapper)..."; \
147 $(SUDO) /sbin/insmod $(wrapper)/$(wrapper).ko; \
148 else \
149 echo "Skipping loading $(wrapper) module (already loaded)."; \
150 fi
151
152unload-$(wrapper):
153 @if grep -q "^$(wrapper) " /proc/modules; then \
154 echo "Unloading $(wrapper)..."; \
155 $(SUDO) /sbin/rmmod $(wrapper)/$(wrapper).ko; \
156 fi
157 endef
158$(foreach wrapper,$(VBOX_WRAPPER_DIRS), $(eval $(wrapper_template)))
159
160wrappers: $(VBOX_WRAPPER_DIRS)
161wrappers-load: $(addprefix load-,$(VBOX_WRAPPER_DIRS))
162wrappers-unload:
163 @for module in $(filter-out vbox_vmmr0,$(VBOX_WRAPPER_DIRS)) $(filter vbox_vmmr0,$(VBOX_WRAPPER_DIRS)); \
164 do \
165 if grep -q "^$${module} " /proc/modules; then \
166 echo "Unloading $${module}..."; \
167 $(SUDO) /sbin/rmmod "$${module}"; \
168 fi \
169 done
170wrappers-reload: wrappers-unload
171 +$(MAKE) -f $(lastword $(MAKEFILE_LIST)) --no-print-directory wrappers-load
172
173buildid:
174 @for module in $(foreach module,vboxdrv vboxnetflt vboxnetadp $(VBOX_WRAPPER_DIRS),$(module)/$(module).ko); \
175 do \
176 buildid=`readelf -n $${module} | sed -ne 's/^.*Build ID: *\([[:xdigit:]][[:xdigit:]]\)\(.*\)$$/\1\/\2/p' `; \
177 if [ -n "$${buildid}" ]; then \
178 mkdir -p ~/.debug/.build-id/`dirname $${buildid}`; \
179 ln -sfn -- "$(CURDIR)/$${module}" ~/.debug/.build-id/$${buildid}; \
180 else \
181 echo "warning: No build ID for $${module}"; \
182 fi \
183 done
184
185.PHONY: wrappers wrappers-load wrappers-unload buildid $(VBOX_WRAPPER_DIRS) \
186 $(addprefix load-,$(VBOX_WRAPPER_DIRS)) $(addprefix unload-,$(VBOX_WRAPPER_DIRS))
187
188 else # Too old:
189
190VBOX_WRAPPER_DIRS :=
191
192vboxdrv:
193vboxnetflt:
194vboxnetadp:
195vboxpci:
196install:
197wrappers:
198wrappers-load:
199wrappers-unload:
200buildid:
201
202 endif
203
204clean-vboxdrv:
205 +@$(MAKE) -C vboxdrv clean
206 rm -rf vboxdrv.ko
207
208clean-vboxnetflt:
209 +@if [ -d vboxnetflt ]; then \
210 $(MAKE) -C vboxnetflt clean; \
211 fi
212 rm -rf vboxnetflt.ko
213
214clean-vboxnetadp:
215 +@if [ -d vboxnetadp ]; then \
216 $(MAKE) -C vboxnetadp clean; \
217 fi
218 rm -rf vboxnetadp.ko
219
220clean-vboxpci:
221 +@if [ -d vboxpci ]; then \
222 $(MAKE) -C vboxpci clean; \
223 fi
224 rm -f vboxpci.ko
225
226clean: clean-vboxdrv clean-vboxnetflt clean-vboxnetadp clean-vboxpci
227
228check:
229 +@$(MAKE) KBUILD_VERBOSE=$(KBUILD_VERBOSE) -C vboxdrv check
230
231unload:
232 @for module in vboxpci vboxnetadp vboxnetflt vboxdrv; do \
233 if grep "^$$module " /proc/modules >/dev/null; then \
234 echo "Removing previously installed $$module module"; \
235 $(SUDO) /sbin/rmmod $$module; \
236 fi; \
237 done
238
239load: unload
240 @for module in vboxdrv vboxnetflt vboxnetadp vboxpci; do \
241 if test -f $$module.ko; then \
242 echo "Installing $$module module"; \
243 $(SUDO) /sbin/insmod $$module.ko; \
244 fi; \
245 done
246
247endif # ! KERNELRELEASE
248
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