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