1 | #
|
---|
2 | # Makefile for the VirtualBox Linux Host Network Filter Driver.
|
---|
3 | # (For 2.6.x this file must be called 'Makefile'!)
|
---|
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 | # Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
|
---|
19 | # Clara, CA 95054 USA or visit http://www.sun.com if you need
|
---|
20 | # additional information or have any questions.
|
---|
21 | #
|
---|
22 |
|
---|
23 | #
|
---|
24 | # First, figure out which architecture we're targeting and the build type.
|
---|
25 | # (We have to support basic cross building (ARCH=i386|x86_64).)
|
---|
26 | # While at it, warn about BUILD_* vars found to help with user problems.
|
---|
27 | #
|
---|
28 | ifeq ($(filter-out x86_64 amd64 AMD64,$(shell uname -m)),)
|
---|
29 | BUILD_TARGET_ARCH_DEF := amd64
|
---|
30 | else
|
---|
31 | BUILD_TARGET_ARCH_DEF := x86
|
---|
32 | endif
|
---|
33 | ifneq ($(filter-out amd64 x86,$(BUILD_TARGET_ARCH)),)
|
---|
34 | $(warning Ignoring unknown BUILD_TARGET_ARCH value '$(BUILD_TARGET_ARCH)'.)
|
---|
35 | BUILD_TARGET_ARCH :=
|
---|
36 | endif
|
---|
37 | ifeq ($(BUILD_TARGET_ARCH),)
|
---|
38 | ifeq ($(ARCH),x86_64)
|
---|
39 | BUILD_TARGET_ARCH := amd64
|
---|
40 | else
|
---|
41 | ifeq ($(ARCH),i386)
|
---|
42 | BUILD_TARGET_ARCH := x86
|
---|
43 | else
|
---|
44 | BUILD_TARGET_ARCH := $(BUILD_TARGET_ARCH_DEF)
|
---|
45 | endif
|
---|
46 | endif
|
---|
47 | else
|
---|
48 | ifneq ($(BUILD_TARGET_ARCH),$(BUILD_TARGET_ARCH_DEF))
|
---|
49 | $(warning Using BUILD_TARGET_ARCH='$(BUILD_TARGET_ARCH)' from the $(origin BUILD_TARGET_ARCH).)
|
---|
50 | endif
|
---|
51 | endif
|
---|
52 |
|
---|
53 | ifneq ($(filter-out release profile debug strict,$(BUILD_TYPE)),)
|
---|
54 | $(warning Ignoring unknown BUILD_TYPE value '$(BUILD_TYPE)'.)
|
---|
55 | BUILD_TYPE :=
|
---|
56 | endif
|
---|
57 | ifeq ($(BUILD_TYPE),)
|
---|
58 | BUILD_TYPE := release
|
---|
59 | else
|
---|
60 | ifneq ($(BUILD_TYPE),release)
|
---|
61 | $(warning Using BUILD_TYPE='$(BUILD_TYPE)' from the $(origin BUILD_TYPE).)
|
---|
62 | endif
|
---|
63 | endif
|
---|
64 |
|
---|
65 | # override is required by the Debian guys
|
---|
66 | override MODULE = vboxnetflt
|
---|
67 | OBJS = \
|
---|
68 | linux/VBoxNetFlt-linux.o \
|
---|
69 | VBoxNetFlt.o \
|
---|
70 | SUPR0IdcClient.o \
|
---|
71 | SUPR0IdcClientComponent.o \
|
---|
72 | SUPR0IdcClient-linux.o \
|
---|
73 |
|
---|
74 | ifeq ($(BUILD_TARGET_ARCH),x86)
|
---|
75 | OBJS += math/gcc/divdi3.o \
|
---|
76 | math/gcc/moddi3.o \
|
---|
77 | math/gcc/qdivrem.o \
|
---|
78 | math/gcc/udivdi3.o \
|
---|
79 | math/gcc/divdi3.o \
|
---|
80 | math/gcc/umoddi3.o
|
---|
81 | endif
|
---|
82 |
|
---|
83 | ifneq ($(MAKECMDGOALS),clean)
|
---|
84 |
|
---|
85 | ifeq ($(KERNELRELEASE),)
|
---|
86 |
|
---|
87 | #
|
---|
88 | # building from this directory
|
---|
89 | #
|
---|
90 |
|
---|
91 | # kernel base directory
|
---|
92 | ifndef KERN_DIR
|
---|
93 | # build for the current kernel, version check
|
---|
94 | KERN_DIR := /lib/modules/$(shell uname -r)/build
|
---|
95 | ifneq ($(shell if test -d $(KERN_DIR); then echo yes; fi),yes)
|
---|
96 | KERN_DIR := /usr/src/linux
|
---|
97 | ifneq ($(shell if test -d $(KERN_DIR); then echo yes; fi),yes)
|
---|
98 | $(error Error: unable to find the sources of your current Linux kernel. \
|
---|
99 | Specify KERN_DIR=<directory> and run Make again)
|
---|
100 | endif
|
---|
101 | $(warning Warning: using /usr/src/linux as the source directory of your \
|
---|
102 | Linux kernel. If this is not correct, specify \
|
---|
103 | KERN_DIR=<directory> and run Make again.)
|
---|
104 | endif
|
---|
105 | # check if versions match -- works only for later 2.6 kernels
|
---|
106 | VBOX_KERN_VER := $(shell $(MAKE) -sC $(KERN_DIR) --no-print-directory kernelrelease 2> /dev/null || true)
|
---|
107 | ifneq ($(VBOX_KERN_VER),)
|
---|
108 | ifneq ($(VBOX_KERN_VER),$(shell uname -r))
|
---|
109 | $(error Error: /usr/src/linux (version $(VBOX_KERN_VER)) does not match \
|
---|
110 | the current kernel (version $(shell uname -r)))
|
---|
111 | endif
|
---|
112 | endif
|
---|
113 | else
|
---|
114 | # build for a dedicated kernel, no version check
|
---|
115 | ifneq ($(shell if test -d $(KERN_DIR); then echo yes; fi),yes)
|
---|
116 | $(error Error: KERN_DIR does not point to a directory)
|
---|
117 | endif
|
---|
118 | endif
|
---|
119 |
|
---|
120 | # includes
|
---|
121 | ifndef KERN_INCL
|
---|
122 | KERN_INCL = $(KERN_DIR)/include
|
---|
123 | endif
|
---|
124 | ifneq ($(shell if test -d $(KERN_INCL); then echo yes; fi),yes)
|
---|
125 | $(error Error: unable to find the include directory for your current Linux \
|
---|
126 | kernel. Specify KERN_INCL=<directory> and run Make again)
|
---|
127 | endif
|
---|
128 |
|
---|
129 | # module install dir, only for current kernel
|
---|
130 | ifneq ($(filter install install_rpm,$(MAKECMDGOALS)),)
|
---|
131 | ifndef MODULE_DIR
|
---|
132 | MODULE_DIR_TST := /lib/modules/$(shell uname -r)
|
---|
133 | ifeq ($(shell if test -d $(MODULE_DIR_TST); then echo yes; fi),yes)
|
---|
134 | MODULE_DIR := $(MODULE_DIR_TST)/misc
|
---|
135 | else
|
---|
136 | $(error Unable to find the folder to install the support driver to)
|
---|
137 | endif
|
---|
138 | endif # MODULE_DIR unspecified
|
---|
139 | endif
|
---|
140 |
|
---|
141 | else # neq($(KERNELRELEASE),)
|
---|
142 |
|
---|
143 | #
|
---|
144 | # building from kbuild (make -C <kernel_directory> M=`pwd`)
|
---|
145 | #
|
---|
146 |
|
---|
147 | endif # neq($(KERNELRELEASE),)
|
---|
148 |
|
---|
149 | # debug - show guesses.
|
---|
150 | ifdef DEBUG
|
---|
151 | $(warning dbg: KERN_DIR = $(KERN_DIR))
|
---|
152 | $(warning dbg: KERN_INCL = $(KERN_INCL))
|
---|
153 | $(warning dbg: MODULE_DIR = $(MODULE_DIR))
|
---|
154 | endif
|
---|
155 |
|
---|
156 | KBUILD_VERBOSE ?= 1
|
---|
157 |
|
---|
158 | #
|
---|
159 | # Compiler options
|
---|
160 | #
|
---|
161 | ifndef INCL
|
---|
162 | INCL := $(addprefix -I,$(KERN_INCL) $(EXTRA_INCL))
|
---|
163 | ifndef KBUILD_EXTMOD
|
---|
164 | KBUILD_EXTMOD := $(shell pwd)
|
---|
165 | endif
|
---|
166 | INCL += $(addprefix -I$(KBUILD_EXTMOD),/ /include /r0drv/linux)
|
---|
167 | export INCL
|
---|
168 | endif
|
---|
169 | KFLAGS := -D__KERNEL__ -DMODULE -DRT_OS_LINUX -DIN_RING0 -DIN_RT_R0 -DIN_SUP_R0 -DVBOX -DRT_WITH_VBOX -DVBOX_WITH_HARDENING
|
---|
170 | ifdef VBOX_REDHAT_KABI
|
---|
171 | KFLAGS += -DVBOX_REDHAT_KABI
|
---|
172 | endif
|
---|
173 | ifeq ($(BUILD_TARGET_ARCH),amd64)
|
---|
174 | KFLAGS += -DRT_ARCH_AMD64
|
---|
175 | else
|
---|
176 | KFLAGS += -DRT_ARCH_X86
|
---|
177 | endif
|
---|
178 | # must be consistent with Config.kmk!
|
---|
179 | KFLAGS += -DVBOX_WITH_64_BITS_GUESTS
|
---|
180 | ifeq ($(BUILD_TYPE),debug)
|
---|
181 | KFLAGS += -DDEBUG -DDEBUG_$(USER) -g
|
---|
182 | # IPRT_DEBUG_SEMS indicates thread wrt sems state via the comm field.
|
---|
183 | KFLAGS += -DIPRT_DEBUG_SEMS
|
---|
184 | endif
|
---|
185 |
|
---|
186 | # By default we use remap_pfn_range() kernel API to make kernel pages
|
---|
187 | # visible for userland. Unfortuately, it leads to situation that
|
---|
188 | # during debug session all structures on that page (such as PVM pointer)
|
---|
189 | # are not accessible to the debugger (see #3214).
|
---|
190 | # This code enables experimental support
|
---|
191 | # for vm_insert_page() kernel API, allowing to export kernel pages
|
---|
192 | # to the userland in more debugger-friendly way. Due to stability
|
---|
193 | # concerns, not enabled by default yet.
|
---|
194 | ifdef VBOX_USE_INSERT_PAGE
|
---|
195 | KFLAGS += -DVBOX_USE_INSERT_PAGE
|
---|
196 | endif
|
---|
197 |
|
---|
198 | MODULE_EXT := ko
|
---|
199 | $(MODULE)-y := $(OBJS)
|
---|
200 |
|
---|
201 | # build defs
|
---|
202 | EXTRA_CFLAGS += $(INCL) $(KFLAGS) $(KDEBUG)
|
---|
203 |
|
---|
204 | all: $(MODULE)
|
---|
205 |
|
---|
206 | obj-m += $(MODULE).o
|
---|
207 |
|
---|
208 | $(MODULE):
|
---|
209 | $(MAKE) KBUILD_VERBOSE=$(KBUILD_VERBOSE) -C $(KERN_DIR) SUBDIRS=$(CURDIR) SRCROOT=$(CURDIR) modules
|
---|
210 |
|
---|
211 | install: $(MODULE)
|
---|
212 | @mkdir -p $(MODULE_DIR); \
|
---|
213 | install -m 0664 -o root -g root $(MODULE).$(MODULE_EXT) $(MODULE_DIR); \
|
---|
214 | PATH="$(PATH):/bin:/sbin" depmod -a; \
|
---|
215 | rm -f /etc/vbox/module_not_compiled
|
---|
216 |
|
---|
217 | install_rpm: $(MODULE)
|
---|
218 | @mkdir -p $(MODULE_DIR); \
|
---|
219 | install -m 0664 $(MODULE).$(MODULE_EXT) $(MODULE_DIR)
|
---|
220 |
|
---|
221 | endif # eq($(MAKECMDGOALS),clean)
|
---|
222 |
|
---|
223 | # important: Don't remove Module.symvers! DKMS does 'make clean' before building ...
|
---|
224 | clean:
|
---|
225 | for f in . linux r0drv r0drv/linux VBox common/err common/string common/log generic math/gcc; \
|
---|
226 | do rm -f $$f/*.o $$f/.*.cmd $$f/.*.flags; done
|
---|
227 | rm -rf .vboxnetflt* .tmp_ver* vboxnetflt.* Modules.symvers modules.order
|
---|