1 | # $Revision: 36274 $
|
---|
2 | ## @file
|
---|
3 | # VirtualBox Guest Additions Module Makefile.
|
---|
4 | #
|
---|
5 |
|
---|
6 | #
|
---|
7 | # Copyright (C) 2006-2010 Oracle Corporation
|
---|
8 | #
|
---|
9 | # This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | # available from http://www.virtualbox.org. This file is free software;
|
---|
11 | # you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | # General Public License (GPL) as published by the Free Software
|
---|
13 | # Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | # VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | # hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | #
|
---|
17 |
|
---|
18 | #
|
---|
19 | # First, figure out which architecture we're targeting and the build type.
|
---|
20 | # (We have to support basic cross building (ARCH=i386|x86_64).)
|
---|
21 | # While at it, warn about BUILD_* vars found to help with user problems.
|
---|
22 | #
|
---|
23 | ifeq ($(filter-out x86_64 amd64 AMD64,$(shell uname -m)),)
|
---|
24 | BUILD_TARGET_ARCH_DEF := amd64
|
---|
25 | else
|
---|
26 | BUILD_TARGET_ARCH_DEF := x86
|
---|
27 | endif
|
---|
28 | ifneq ($(filter-out amd64 x86,$(BUILD_TARGET_ARCH)),)
|
---|
29 | $(warning Ignoring unknown BUILD_TARGET_ARCH value '$(BUILD_TARGET_ARCH)'.)
|
---|
30 | BUILD_TARGET_ARCH :=
|
---|
31 | endif
|
---|
32 | ifeq ($(BUILD_TARGET_ARCH),)
|
---|
33 | ifeq ($(ARCH),x86_64)
|
---|
34 | BUILD_TARGET_ARCH := amd64
|
---|
35 | else
|
---|
36 | ifeq ($(ARCH),i386)
|
---|
37 | BUILD_TARGET_ARCH := x86
|
---|
38 | else
|
---|
39 | BUILD_TARGET_ARCH := $(BUILD_TARGET_ARCH_DEF)
|
---|
40 | endif
|
---|
41 | endif
|
---|
42 | else
|
---|
43 | ifneq ($(BUILD_TARGET_ARCH),$(BUILD_TARGET_ARCH_DEF))
|
---|
44 | $(warning Using BUILD_TARGET_ARCH='$(BUILD_TARGET_ARCH)' from the $(origin BUILD_TARGET_ARCH).)
|
---|
45 | endif
|
---|
46 | endif
|
---|
47 |
|
---|
48 | ifneq ($(filter-out release profile debug strict,$(BUILD_TYPE)),)
|
---|
49 | $(warning Ignoring unknown BUILD_TYPE value '$(BUILD_TYPE)'.)
|
---|
50 | BUILD_TYPE :=
|
---|
51 | endif
|
---|
52 | ifeq ($(BUILD_TYPE),)
|
---|
53 | BUILD_TYPE := release
|
---|
54 | else
|
---|
55 | ifneq ($(BUILD_TYPE),release)
|
---|
56 | $(warning Using BUILD_TYPE='$(BUILD_TYPE)' from the $(origin BUILD_TYPE).)
|
---|
57 | endif
|
---|
58 | endif
|
---|
59 |
|
---|
60 |
|
---|
61 | # override is required by the Debian guys
|
---|
62 | override MODULE = vboxguest
|
---|
63 | OBJS = \
|
---|
64 | VBoxGuest-linux.o \
|
---|
65 | VBoxGuest.o \
|
---|
66 | VBoxGuest2.o \
|
---|
67 | GenericRequest.o \
|
---|
68 | HGCMInternal.o \
|
---|
69 | Init.o \
|
---|
70 | PhysHeap.o \
|
---|
71 | SysHlp.o \
|
---|
72 | VMMDev.o \
|
---|
73 | r0drv/alloc-r0drv.o \
|
---|
74 | r0drv/initterm-r0drv.o \
|
---|
75 | r0drv/memobj-r0drv.o \
|
---|
76 | r0drv/mpnotification-r0drv.o \
|
---|
77 | r0drv/powernotification-r0drv.o \
|
---|
78 | r0drv/linux/alloc-r0drv-linux.o \
|
---|
79 | r0drv/linux/assert-r0drv-linux.o \
|
---|
80 | r0drv/linux/initterm-r0drv-linux.o \
|
---|
81 | r0drv/linux/memobj-r0drv-linux.o \
|
---|
82 | r0drv/linux/memuserkernel-r0drv-linux.o \
|
---|
83 | r0drv/linux/mp-r0drv-linux.o \
|
---|
84 | r0drv/linux/mpnotification-r0drv-linux.o \
|
---|
85 | r0drv/linux/process-r0drv-linux.o \
|
---|
86 | r0drv/linux/semevent-r0drv-linux.o \
|
---|
87 | r0drv/linux/semeventmulti-r0drv-linux.o \
|
---|
88 | r0drv/linux/semfastmutex-r0drv-linux.o \
|
---|
89 | r0drv/linux/spinlock-r0drv-linux.o \
|
---|
90 | r0drv/linux/thread-r0drv-linux.o \
|
---|
91 | r0drv/linux/thread2-r0drv-linux.o \
|
---|
92 | r0drv/linux/time-r0drv-linux.o \
|
---|
93 | r0drv/linux/RTLogWriteDebugger-r0drv-linux.o \
|
---|
94 | r0drv/generic/semspinmutex-r0drv-generic.o \
|
---|
95 | common/alloc/alloc.o \
|
---|
96 | common/err/RTErrConvertFromErrno.o \
|
---|
97 | common/err/RTErrConvertToErrno.o \
|
---|
98 | common/log/log.o \
|
---|
99 | common/log/logellipsis.o \
|
---|
100 | common/log/logrel.o \
|
---|
101 | common/log/logrelellipsis.o \
|
---|
102 | common/log/logcom.o \
|
---|
103 | common/log/logformat.o \
|
---|
104 | common/misc/RTAssertMsg1Weak.o \
|
---|
105 | common/misc/RTAssertMsg2.o \
|
---|
106 | common/misc/RTAssertMsg2Add.o \
|
---|
107 | common/misc/RTAssertMsg2AddWeak.o \
|
---|
108 | common/misc/RTAssertMsg2AddWeakV.o \
|
---|
109 | common/misc/RTAssertMsg2Weak.o \
|
---|
110 | common/misc/RTAssertMsg2WeakV.o \
|
---|
111 | common/misc/assert.o \
|
---|
112 | common/misc/thread.o \
|
---|
113 | common/string/RTStrCopy.o \
|
---|
114 | common/string/strformat.o \
|
---|
115 | common/string/strformatrt.o \
|
---|
116 | common/string/strformattype.o \
|
---|
117 | common/string/strprintf.o \
|
---|
118 | common/string/strtonum.o \
|
---|
119 | common/table/avlpv.o \
|
---|
120 | common/time/time.o \
|
---|
121 | generic/RTAssertShouldPanic-generic.o \
|
---|
122 | generic/RTLogWriteStdErr-stub-generic.o \
|
---|
123 | generic/RTLogWriteStdOut-stub-generic.o \
|
---|
124 | generic/RTSemEventWait-2-ex-generic.o \
|
---|
125 | generic/RTSemEventWaitNoResume-2-ex-generic.o \
|
---|
126 | generic/RTSemEventMultiWait-2-ex-generic.o \
|
---|
127 | generic/RTSemEventMultiWaitNoResume-2-ex-generic.o \
|
---|
128 | VBox/log-vbox.o \
|
---|
129 | VBox/logbackdoor.o
|
---|
130 | ifeq ($(BUILD_TARGET_ARCH),x86)
|
---|
131 | OBJS += \
|
---|
132 | common/math/gcc/divdi3.o \
|
---|
133 | common/math/gcc/moddi3.o \
|
---|
134 | common/math/gcc/udivdi3.o \
|
---|
135 | common/math/gcc/umoddi3.o \
|
---|
136 | common/math/gcc/qdivrem.o
|
---|
137 | endif
|
---|
138 | ifeq ($(BUILD_TARGET_ARCH),amd64)
|
---|
139 | OBJS += common/alloc/heapsimple.o
|
---|
140 | endif
|
---|
141 |
|
---|
142 | ifneq ($(MAKECMDGOALS),clean)
|
---|
143 |
|
---|
144 | ifeq ($(KERNELRELEASE),)
|
---|
145 |
|
---|
146 | #
|
---|
147 | # building from this directory
|
---|
148 | #
|
---|
149 |
|
---|
150 | # kernel base directory
|
---|
151 | ifndef KERN_DIR
|
---|
152 | KERN_DIR := /lib/modules/$(shell uname -r)/build
|
---|
153 | ifneq ($(shell if test -d $(KERN_DIR); then echo yes; fi),yes)
|
---|
154 | KERN_DIR := /usr/src/linux
|
---|
155 | ifneq ($(shell if test -d $(KERN_DIR); then echo yes; fi),yes)
|
---|
156 | $(error Error: unable to find the sources of your current Linux kernel. \
|
---|
157 | Specify KERN_DIR=<directory> and run Make again)
|
---|
158 | endif
|
---|
159 | $(warning Warning: using /usr/src/linux as the source directory of your \
|
---|
160 | Linux kernel. If this is not correct, specify \
|
---|
161 | KERN_DIR=<directory> and run Make again.)
|
---|
162 | endif
|
---|
163 | else
|
---|
164 | ifneq ($(shell if test -d $(KERN_DIR); then echo yes; fi),yes)
|
---|
165 | $(error Error: KERN_DIR does not point to a directory)
|
---|
166 | endif
|
---|
167 | endif
|
---|
168 |
|
---|
169 | # includes
|
---|
170 | ifndef KERN_INCL
|
---|
171 | KERN_INCL = $(KERN_DIR)/include
|
---|
172 | endif
|
---|
173 | ifneq ($(shell if test -d $(KERN_INCL); then echo yes; fi),yes)
|
---|
174 | $(error Error: unable to find the include directory for your current Linux \
|
---|
175 | kernel. Specify KERN_INCL=<directory> and run Make again)
|
---|
176 | endif
|
---|
177 |
|
---|
178 | # module install dir, only for current kernel
|
---|
179 | ifneq ($(filter install install_rpm,$(MAKECMDGOALS)),)
|
---|
180 | ifndef MODULE_DIR
|
---|
181 | MODULE_DIR_TST := /lib/modules/$(shell uname -r)
|
---|
182 | ifeq ($(shell if test -d $(MODULE_DIR_TST); then echo yes; fi),yes)
|
---|
183 | MODULE_DIR := $(MODULE_DIR_TST)/misc
|
---|
184 | else
|
---|
185 | $(error Unable to find the folder to install the additions driver to)
|
---|
186 | endif
|
---|
187 | endif # MODULE_DIR unspecified
|
---|
188 | endif
|
---|
189 |
|
---|
190 | # guess kernel version (24 or 26)
|
---|
191 | ifeq ($(shell if grep '"2\.4\.' $(KERN_INCL)/linux/version.h > /dev/null; then echo yes; fi),yes)
|
---|
192 | KERN_VERSION := 24
|
---|
193 | else
|
---|
194 | KERN_VERSION := 26
|
---|
195 | endif
|
---|
196 |
|
---|
197 | else # neq($(KERNELRELEASE),)
|
---|
198 |
|
---|
199 | #
|
---|
200 | # building from kbuild (make -C <kernel_directory> M=`pwd`)
|
---|
201 | #
|
---|
202 |
|
---|
203 | # guess kernel version (24 or 26)
|
---|
204 | ifeq ($(shell if echo "$(VERSION).$(PATCHLEVEL)." | grep '2\.4\.' > /dev/null; then echo yes; fi),yes)
|
---|
205 | KERN_VERSION := 24
|
---|
206 | else
|
---|
207 | KERN_VERSION := 26
|
---|
208 | endif
|
---|
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 | $(warning dbg: KERN_VERSION = $(KERN_VERSION))
|
---|
218 | endif
|
---|
219 |
|
---|
220 | KBUILD_VERBOSE ?= 1
|
---|
221 |
|
---|
222 | #
|
---|
223 | # Compiler options
|
---|
224 | #
|
---|
225 | ifndef INCL
|
---|
226 | INCL := $(addprefix -I,$(KERN_INCL) $(EXTRA_INCL))
|
---|
227 | ifndef KBUILD_EXTMOD
|
---|
228 | KBUILD_EXTMOD := $(shell pwd)
|
---|
229 | endif
|
---|
230 | INCL += $(addprefix -I$(KBUILD_EXTMOD),/ /include /r0drv/linux)
|
---|
231 | INCL += $(addprefix -I$(KBUILD_EXTMOD)/vboxguest,/ /include /r0drv/linux)
|
---|
232 | export INCL
|
---|
233 | endif
|
---|
234 | KFLAGS := -D__KERNEL__ -DMODULE \
|
---|
235 | -DVBOX -DRT_OS_LINUX -DIN_RING0 -DIN_RT_R0 -DIN_GUEST -DIN_GUEST_R0 \
|
---|
236 | -DIN_MODULE -DRT_WITH_VBOX -DVBGL_VBOXGUEST -DVBOX_WITH_HGCM
|
---|
237 | ifeq ($(BUILD_TARGET_ARCH),amd64)
|
---|
238 | KFLAGS += -DRT_ARCH_AMD64 -DVBOX_WITH_64_BITS_GUESTS
|
---|
239 | else
|
---|
240 | KFLAGS += -DRT_ARCH_X86
|
---|
241 | endif
|
---|
242 | ifeq ($(BUILD_TYPE),debug)
|
---|
243 | KFLAGS += -DDEBUG
|
---|
244 | endif
|
---|
245 |
|
---|
246 | ifeq ($(KERN_VERSION), 24)
|
---|
247 | #
|
---|
248 | # 2.4
|
---|
249 | #
|
---|
250 |
|
---|
251 | ifeq ($(BUILD_TARGET_ARCH),amd64)
|
---|
252 | KFLAGS += -mcmodel=kernel
|
---|
253 | endif
|
---|
254 |
|
---|
255 | CFLAGS := -O2 -DVBOX_LINUX_2_4 -DEXPORT_SYMTAB $(INCL) $(KFLAGS) $(KDEBUG)
|
---|
256 | MODULE_EXT := o
|
---|
257 |
|
---|
258 | # 2.4 Module linking
|
---|
259 | $(MODULE).o: $(OBJS)
|
---|
260 | $(LD) -o $@ -r $(OBJS)
|
---|
261 |
|
---|
262 | .PHONY: $(MODULE)
|
---|
263 | all: $(MODULE)
|
---|
264 | $(MODULE): $(MODULE).o
|
---|
265 |
|
---|
266 | else
|
---|
267 | #
|
---|
268 | # 2.6 and later
|
---|
269 | #
|
---|
270 |
|
---|
271 | MODULE_EXT := ko
|
---|
272 |
|
---|
273 | $(MODULE)-y := $(OBJS)
|
---|
274 |
|
---|
275 | # build defs
|
---|
276 | EXTRA_CFLAGS += -include $(KBUILD_EXTMOD)/include/VBox/VBoxGuestMangling.h $(INCL) $(KFLAGS) $(KDEBUG)
|
---|
277 |
|
---|
278 | all: $(MODULE)
|
---|
279 |
|
---|
280 | obj-m += $(MODULE).o
|
---|
281 |
|
---|
282 | $(MODULE):
|
---|
283 | $(MAKE) KBUILD_VERBOSE=$(KBUILD_VERBOSE) -C $(KERN_DIR) SUBDIRS=$(CURDIR) SRCROOT=$(CURDIR) modules
|
---|
284 |
|
---|
285 | endif
|
---|
286 |
|
---|
287 | install: $(MODULE)
|
---|
288 | @mkdir -p $(MODULE_DIR); \
|
---|
289 | install -m 0664 -o root -g root $(MODULE).$(MODULE_EXT) $(MODULE_DIR); \
|
---|
290 | PATH="$(PATH):/bin:/sbin" depmod -a;
|
---|
291 |
|
---|
292 | endif # eq($(MAKECMDGOALS),clean)
|
---|
293 |
|
---|
294 | check: $(MODULE)
|
---|
295 | @if ! readelf -p __ksymtab_strings vboxguest.ko | grep -E "\[.*\] *(RT|g_..*RT.*)"; then \
|
---|
296 | echo "All exported IPRT symbols are properly renamed!"; \
|
---|
297 | else \
|
---|
298 | echo "error: Some exported IPRT symbols was not properly renamed! See above." >&2; \
|
---|
299 | false; \
|
---|
300 | fi
|
---|
301 |
|
---|
302 | clean:
|
---|
303 | for f in . linux r0drv generic r0drv/linux r0drv/generic VBox \
|
---|
304 | common/alloc common/err common/log common/math/gcc common/misc common/string common/time; \
|
---|
305 | do rm -f $$f/*.o $$f/.*.cmd $$f/.*.flags; done
|
---|
306 | rm -rf .vboxguest* .tmp_ver* vboxguest.* Module.symvers Modules.symvers modules.order
|
---|