1 | # $Revision: 28156 $
|
---|
2 | ## @file
|
---|
3 | # Makefile for the VirtualBox Linux Host Driver.
|
---|
4 | #
|
---|
5 |
|
---|
6 | #
|
---|
7 | #
|
---|
8 | # Copyright (C) 2006-2007 Sun Microsystems, Inc.
|
---|
9 | #
|
---|
10 | # This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
11 | # available from http://www.virtualbox.org. This file is free software;
|
---|
12 | # you can redistribute it and/or modify it under the terms of the GNU
|
---|
13 | # General Public License (GPL) as published by the Free Software
|
---|
14 | # Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
15 | # VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
16 | # hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
17 | #
|
---|
18 | # The contents of this file may alternatively be used under the terms
|
---|
19 | # of the Common Development and Distribution License Version 1.0
|
---|
20 | # (CDDL) only, as it comes in the "COPYING.CDDL" file of the
|
---|
21 | # VirtualBox OSE distribution, in which case the provisions of the
|
---|
22 | # CDDL are applicable instead of those of the GPL.
|
---|
23 | #
|
---|
24 | # You may elect to license modified versions of this file under the
|
---|
25 | # terms and conditions of either the GPL or the CDDL or both.
|
---|
26 | #
|
---|
27 | # Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
|
---|
28 | # Clara, CA 95054 USA or visit http://www.sun.com if you need
|
---|
29 | # additional information or have any questions.
|
---|
30 | #
|
---|
31 |
|
---|
32 | #
|
---|
33 | # First, figure out which architecture we're targeting and the build type.
|
---|
34 | # (We have to support basic cross building (ARCH=i386|x86_64).)
|
---|
35 | # While at it, warn about BUILD_* vars found to help with user problems.
|
---|
36 | #
|
---|
37 | ifeq ($(filter-out x86_64 amd64 AMD64,$(shell uname -m)),)
|
---|
38 | BUILD_TARGET_ARCH_DEF := amd64
|
---|
39 | else
|
---|
40 | BUILD_TARGET_ARCH_DEF := x86
|
---|
41 | endif
|
---|
42 | ifneq ($(filter-out amd64 x86,$(BUILD_TARGET_ARCH)),)
|
---|
43 | $(warning Ignoring unknown BUILD_TARGET_ARCH value '$(BUILD_TARGET_ARCH)'.)
|
---|
44 | BUILD_TARGET_ARCH :=
|
---|
45 | endif
|
---|
46 | ifeq ($(BUILD_TARGET_ARCH),)
|
---|
47 | ifeq ($(ARCH),x86_64)
|
---|
48 | BUILD_TARGET_ARCH := amd64
|
---|
49 | else
|
---|
50 | ifeq ($(ARCH),i386)
|
---|
51 | BUILD_TARGET_ARCH := x86
|
---|
52 | else
|
---|
53 | BUILD_TARGET_ARCH := $(BUILD_TARGET_ARCH_DEF)
|
---|
54 | endif
|
---|
55 | endif
|
---|
56 | else
|
---|
57 | ifneq ($(BUILD_TARGET_ARCH),$(BUILD_TARGET_ARCH_DEF))
|
---|
58 | $(warning Using BUILD_TARGET_ARCH='$(BUILD_TARGET_ARCH)' from the $(origin BUILD_TARGET_ARCH).)
|
---|
59 | endif
|
---|
60 | endif
|
---|
61 |
|
---|
62 | ifneq ($(filter-out release profile debug strict,$(BUILD_TYPE)),)
|
---|
63 | $(warning Ignoring unknown BUILD_TYPE value '$(BUILD_TYPE)'.)
|
---|
64 | BUILD_TYPE :=
|
---|
65 | endif
|
---|
66 | ifeq ($(BUILD_TYPE),)
|
---|
67 | BUILD_TYPE := release
|
---|
68 | else
|
---|
69 | ifneq ($(BUILD_TYPE),release)
|
---|
70 | $(warning Using BUILD_TYPE='$(BUILD_TYPE)' from the $(origin BUILD_TYPE).)
|
---|
71 | endif
|
---|
72 | endif
|
---|
73 |
|
---|
74 | # override is required by the Debian guys
|
---|
75 | override MODULE = vboxdrv
|
---|
76 | OBJS = \
|
---|
77 | linux/SUPDrv-linux.o \
|
---|
78 | SUPDrv.o \
|
---|
79 | SUPDrvSem.o \
|
---|
80 | r0drv/alloc-r0drv.o \
|
---|
81 | r0drv/initterm-r0drv.o \
|
---|
82 | r0drv/memobj-r0drv.o \
|
---|
83 | r0drv/mpnotification-r0drv.o \
|
---|
84 | r0drv/powernotification-r0drv.o \
|
---|
85 | r0drv/linux/assert-r0drv-linux.o \
|
---|
86 | r0drv/linux/alloc-r0drv-linux.o \
|
---|
87 | r0drv/linux/initterm-r0drv-linux.o \
|
---|
88 | r0drv/linux/memobj-r0drv-linux.o \
|
---|
89 | r0drv/linux/memuserkernel-r0drv-linux.o \
|
---|
90 | r0drv/linux/mp-r0drv-linux.o \
|
---|
91 | r0drv/linux/mpnotification-r0drv-linux.o \
|
---|
92 | r0drv/linux/process-r0drv-linux.o \
|
---|
93 | r0drv/linux/semevent-r0drv-linux.o \
|
---|
94 | r0drv/linux/semeventmulti-r0drv-linux.o \
|
---|
95 | r0drv/linux/semfastmutex-r0drv-linux.o \
|
---|
96 | r0drv/linux/spinlock-r0drv-linux.o \
|
---|
97 | r0drv/linux/thread-r0drv-linux.o \
|
---|
98 | r0drv/linux/thread2-r0drv-linux.o \
|
---|
99 | r0drv/linux/time-r0drv-linux.o \
|
---|
100 | r0drv/linux/timer-r0drv-linux.o \
|
---|
101 | r0drv/generic/semspinmutex-r0drv-generic.o \
|
---|
102 | common/checksum/ipv4.o \
|
---|
103 | common/checksum/ipv6.o \
|
---|
104 | common/err/RTErrConvertFromErrno.o \
|
---|
105 | common/err/RTErrConvertToErrno.o \
|
---|
106 | common/log/log.o \
|
---|
107 | common/log/logellipsis.o \
|
---|
108 | common/log/logrel.o \
|
---|
109 | common/log/logrelellipsis.o \
|
---|
110 | common/log/logcom.o \
|
---|
111 | common/log/logformat.o \
|
---|
112 | common/misc/RTAssertMsg1Weak.o \
|
---|
113 | common/misc/RTAssertMsg2.o \
|
---|
114 | common/misc/RTAssertMsg2Add.o \
|
---|
115 | common/misc/RTAssertMsg2AddWeak.o \
|
---|
116 | common/misc/RTAssertMsg2AddWeakV.o \
|
---|
117 | common/misc/RTAssertMsg2Weak.o \
|
---|
118 | common/misc/RTAssertMsg2WeakV.o \
|
---|
119 | common/misc/assert.o \
|
---|
120 | common/misc/handletable.o \
|
---|
121 | common/misc/handletablectx.o \
|
---|
122 | common/string/strformat.o \
|
---|
123 | common/string/strformatrt.o \
|
---|
124 | common/string/strformattype.o \
|
---|
125 | common/string/strprintf.o \
|
---|
126 | common/string/strtonum.o \
|
---|
127 | r0drv/linux/RTLogWriteDebugger-r0drv-linux.o \
|
---|
128 | generic/RTAssertShouldPanic-generic.o \
|
---|
129 | generic/RTLogWriteStdErr-stub-generic.o \
|
---|
130 | generic/RTLogWriteStdOut-stub-generic.o \
|
---|
131 | generic/RTLogWriteUser-generic.o \
|
---|
132 | generic/uuid-generic.o \
|
---|
133 | VBox/log-vbox.o
|
---|
134 | ifeq ($(BUILD_TARGET_ARCH),x86)
|
---|
135 | OBJS += math/gcc/divdi3.o \
|
---|
136 | math/gcc/moddi3.o \
|
---|
137 | math/gcc/qdivrem.o \
|
---|
138 | math/gcc/udivdi3.o \
|
---|
139 | math/gcc/divdi3.o \
|
---|
140 | math/gcc/umoddi3.o
|
---|
141 | endif
|
---|
142 | ifeq ($(BUILD_TARGET_ARCH),amd64)
|
---|
143 | OBJS += alloc/heapsimple.o
|
---|
144 | endif
|
---|
145 |
|
---|
146 | ifneq ($(MAKECMDGOALS),clean)
|
---|
147 |
|
---|
148 | ifeq ($(KERNELRELEASE),)
|
---|
149 |
|
---|
150 | #
|
---|
151 | # building from this directory
|
---|
152 | #
|
---|
153 |
|
---|
154 | # kernel base directory
|
---|
155 | ifndef KERN_DIR
|
---|
156 | # build for the current kernel, version check
|
---|
157 | KERN_DIR := /lib/modules/$(shell uname -r)/build
|
---|
158 | ifneq ($(shell if test -d $(KERN_DIR); then echo yes; fi),yes)
|
---|
159 | KERN_DIR := /usr/src/linux
|
---|
160 | ifneq ($(shell if test -d $(KERN_DIR); then echo yes; fi),yes)
|
---|
161 | $(error Error: unable to find the sources of your current Linux kernel. \
|
---|
162 | Specify KERN_DIR=<directory> and run Make again)
|
---|
163 | endif
|
---|
164 | $(warning Warning: using /usr/src/linux as the source directory of your \
|
---|
165 | Linux kernel. If this is not correct, specify \
|
---|
166 | KERN_DIR=<directory> and run Make again.)
|
---|
167 | endif
|
---|
168 | # check if versions match -- works only for later 2.6 kernels
|
---|
169 | VBOX_KERN_VER := $(shell $(MAKE) -sC $(KERN_DIR) --no-print-directory kernelrelease 2> /dev/null || true)
|
---|
170 | ifneq ($(VBOX_KERN_VER),)
|
---|
171 | ifneq ($(VBOX_KERN_VER),$(shell uname -r))
|
---|
172 | $(error Error: /usr/src/linux (version $(VBOX_KERN_VER)) does not match \
|
---|
173 | the current kernel (version $(shell uname -r)))
|
---|
174 | endif
|
---|
175 | endif
|
---|
176 | else
|
---|
177 | # build for a dedicated kernel, no version check
|
---|
178 | ifneq ($(shell if test -d $(KERN_DIR); then echo yes; fi),yes)
|
---|
179 | $(error Error: KERN_DIR does not point to a directory)
|
---|
180 | endif
|
---|
181 | endif
|
---|
182 |
|
---|
183 | # includes
|
---|
184 | ifndef KERN_INCL
|
---|
185 | KERN_INCL = $(KERN_DIR)/include
|
---|
186 | endif
|
---|
187 | ifneq ($(shell if test -d $(KERN_INCL); then echo yes; fi),yes)
|
---|
188 | $(error Error: unable to find the include directory for your current Linux \
|
---|
189 | kernel. Specify KERN_INCL=<directory> and run Make again)
|
---|
190 | endif
|
---|
191 |
|
---|
192 | # module install dir, only for current kernel
|
---|
193 | ifneq ($(filter install install_rpm,$(MAKECMDGOALS)),)
|
---|
194 | ifndef MODULE_DIR
|
---|
195 | MODULE_DIR_TST := /lib/modules/$(shell uname -r)
|
---|
196 | ifeq ($(shell if test -d $(MODULE_DIR_TST); then echo yes; fi),yes)
|
---|
197 | MODULE_DIR := $(MODULE_DIR_TST)/misc
|
---|
198 | else
|
---|
199 | $(error Unable to find the folder to install the support driver to)
|
---|
200 | endif
|
---|
201 | endif # MODULE_DIR unspecified
|
---|
202 | endif
|
---|
203 |
|
---|
204 | else # neq($(KERNELRELEASE),)
|
---|
205 |
|
---|
206 | #
|
---|
207 | # building from kbuild (make -C <kernel_directory> M=`pwd`)
|
---|
208 | #
|
---|
209 |
|
---|
210 | endif # neq($(KERNELRELEASE),)
|
---|
211 |
|
---|
212 | # debug - show guesses.
|
---|
213 | ifdef DEBUG
|
---|
214 | $(warning dbg: KERN_DIR = $(KERN_DIR))
|
---|
215 | $(warning dbg: KERN_INCL = $(KERN_INCL))
|
---|
216 | $(warning dbg: MODULE_DIR = $(MODULE_DIR))
|
---|
217 | endif
|
---|
218 |
|
---|
219 | KBUILD_VERBOSE ?= 1
|
---|
220 |
|
---|
221 | #
|
---|
222 | # Compiler options
|
---|
223 | #
|
---|
224 | ifndef INCL
|
---|
225 | INCL := $(addprefix -I,$(KERN_INCL) $(EXTRA_INCL))
|
---|
226 | ifndef KBUILD_EXTMOD
|
---|
227 | KBUILD_EXTMOD := $(shell pwd)
|
---|
228 | endif
|
---|
229 | INCL += $(addprefix -I$(KBUILD_EXTMOD),/ /include /r0drv/linux)
|
---|
230 | export INCL
|
---|
231 | endif
|
---|
232 | KFLAGS := -D__KERNEL__ -DMODULE -DRT_OS_LINUX -DIN_RING0 -DIN_RT_R0 -DIN_SUP_R0 -DVBOX -DRT_WITH_VBOX -DVBOX_WITH_HARDENING
|
---|
233 | ifdef VBOX_REDHAT_KABI
|
---|
234 | KFLAGS += -DVBOX_REDHAT_KABI
|
---|
235 | endif
|
---|
236 | ifndef CONFIG_VBOXDRV_FIXEDMAJOR
|
---|
237 | KFLAGS += -DCONFIG_VBOXDRV_AS_MISC
|
---|
238 | endif
|
---|
239 | ifeq ($(BUILD_TARGET_ARCH),amd64)
|
---|
240 | KFLAGS += -DRT_ARCH_AMD64
|
---|
241 | else
|
---|
242 | KFLAGS += -DRT_ARCH_X86
|
---|
243 | endif
|
---|
244 | # must be consistent with Config.kmk!
|
---|
245 | KFLAGS += -DVBOX_WITH_64_BITS_GUESTS
|
---|
246 | ifeq ($(BUILD_TYPE),debug)
|
---|
247 | KFLAGS += -DDEBUG -DDEBUG_$(USER) -g
|
---|
248 | # IPRT_DEBUG_SEMS indicates thread wrt sems state via the comm field.
|
---|
249 | KFLAGS += -DIPRT_DEBUG_SEMS
|
---|
250 | endif
|
---|
251 |
|
---|
252 | # 2.6 and later
|
---|
253 | MODULE_EXT := ko
|
---|
254 | $(MODULE)-y := $(OBJS)
|
---|
255 |
|
---|
256 | # build defs
|
---|
257 | EXTRA_CFLAGS += $(INCL) $(KFLAGS) $(KDEBUG)
|
---|
258 |
|
---|
259 | all: $(MODULE)
|
---|
260 |
|
---|
261 | obj-m += $(MODULE).o
|
---|
262 |
|
---|
263 | $(MODULE):
|
---|
264 | $(MAKE) KBUILD_VERBOSE=$(KBUILD_VERBOSE) -C $(KERN_DIR) SUBDIRS=$(CURDIR) SRCROOT=$(CURDIR) modules
|
---|
265 |
|
---|
266 | install: $(MODULE)
|
---|
267 | @mkdir -p $(MODULE_DIR); \
|
---|
268 | install -m 0664 -o root -g root $(MODULE).$(MODULE_EXT) $(MODULE_DIR); \
|
---|
269 | PATH="$(PATH):/bin:/sbin" depmod -a; \
|
---|
270 | rm -f /etc/vbox/module_not_compiled
|
---|
271 |
|
---|
272 | install_rpm: $(MODULE)
|
---|
273 | @mkdir -p $(MODULE_DIR); \
|
---|
274 | install -m 0664 $(MODULE).$(MODULE_EXT) $(MODULE_DIR)
|
---|
275 |
|
---|
276 | endif # eq($(MAKECMDGOALS),clean)
|
---|
277 |
|
---|
278 | clean:
|
---|
279 | for f in . linux r0drv r0drv/generic r0drv/linux VBox common/err common/string common/log generic math/gcc; \
|
---|
280 | do rm -f $$f/*.o $$f/.*.cmd $$f/.*.flags; done
|
---|
281 | rm -rf .vboxdrv* .tmp_ver* vboxdrv.* Module.symvers Modules.symvers modules.order
|
---|