1 | # $Revision: 33184 $
|
---|
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/time-r0drv-linux.o \
|
---|
92 | r0drv/linux/RTLogWriteDebugger-r0drv-linux.o \
|
---|
93 | r0drv/generic/semspinmutex-r0drv-generic.o \
|
---|
94 | common/alloc/alloc.o \
|
---|
95 | common/err/RTErrConvertFromErrno.o \
|
---|
96 | common/err/RTErrConvertToErrno.o \
|
---|
97 | common/log/log.o \
|
---|
98 | common/log/logellipsis.o \
|
---|
99 | common/log/logrel.o \
|
---|
100 | common/log/logrelellipsis.o \
|
---|
101 | common/log/logcom.o \
|
---|
102 | common/log/logformat.o \
|
---|
103 | common/misc/RTAssertMsg1Weak.o \
|
---|
104 | common/misc/RTAssertMsg2.o \
|
---|
105 | common/misc/RTAssertMsg2Add.o \
|
---|
106 | common/misc/RTAssertMsg2AddWeak.o \
|
---|
107 | common/misc/RTAssertMsg2AddWeakV.o \
|
---|
108 | common/misc/RTAssertMsg2Weak.o \
|
---|
109 | common/misc/RTAssertMsg2WeakV.o \
|
---|
110 | common/misc/assert.o \
|
---|
111 | common/string/RTStrCopy.o \
|
---|
112 | common/string/strformat.o \
|
---|
113 | common/string/strformatrt.o \
|
---|
114 | common/string/strformattype.o \
|
---|
115 | common/string/strprintf.o \
|
---|
116 | common/string/strtonum.o \
|
---|
117 | common/time/time.o \
|
---|
118 | generic/RTAssertShouldPanic-generic.o \
|
---|
119 | generic/RTLogWriteStdErr-stub-generic.o \
|
---|
120 | generic/RTLogWriteStdOut-stub-generic.o \
|
---|
121 | generic/RTSemEventWait-2-ex-generic.o \
|
---|
122 | generic/RTSemEventWaitNoResume-2-ex-generic.o \
|
---|
123 | generic/RTSemEventMultiWait-2-ex-generic.o \
|
---|
124 | generic/RTSemEventMultiWaitNoResume-2-ex-generic.o \
|
---|
125 | VBox/log-vbox.o \
|
---|
126 | VBox/logbackdoor.o
|
---|
127 | ifeq ($(BUILD_TARGET_ARCH),x86)
|
---|
128 | OBJS += \
|
---|
129 | common/math/gcc/divdi3.o \
|
---|
130 | common/math/gcc/moddi3.o \
|
---|
131 | common/math/gcc/udivdi3.o \
|
---|
132 | common/math/gcc/umoddi3.o \
|
---|
133 | common/math/gcc/qdivrem.o
|
---|
134 | endif
|
---|
135 | ifeq ($(BUILD_TARGET_ARCH),amd64)
|
---|
136 | OBJS += common/alloc/heapsimple.o
|
---|
137 | endif
|
---|
138 |
|
---|
139 | ifneq ($(MAKECMDGOALS),clean)
|
---|
140 |
|
---|
141 | ifeq ($(KERNELRELEASE),)
|
---|
142 |
|
---|
143 | #
|
---|
144 | # building from this directory
|
---|
145 | #
|
---|
146 |
|
---|
147 | # kernel base directory
|
---|
148 | ifndef KERN_DIR
|
---|
149 | KERN_DIR := /lib/modules/$(shell uname -r)/build
|
---|
150 | ifneq ($(shell if test -d $(KERN_DIR); then echo yes; fi),yes)
|
---|
151 | KERN_DIR := /usr/src/linux
|
---|
152 | ifneq ($(shell if test -d $(KERN_DIR); then echo yes; fi),yes)
|
---|
153 | $(error Error: unable to find the sources of your current Linux kernel. \
|
---|
154 | Specify KERN_DIR=<directory> and run Make again)
|
---|
155 | endif
|
---|
156 | $(warning Warning: using /usr/src/linux as the source directory of your \
|
---|
157 | Linux kernel. If this is not correct, specify \
|
---|
158 | KERN_DIR=<directory> and run Make again.)
|
---|
159 | endif
|
---|
160 | else
|
---|
161 | ifneq ($(shell if test -d $(KERN_DIR); then echo yes; fi),yes)
|
---|
162 | $(error Error: KERN_DIR does not point to a directory)
|
---|
163 | endif
|
---|
164 | endif
|
---|
165 |
|
---|
166 | # includes
|
---|
167 | ifndef KERN_INCL
|
---|
168 | KERN_INCL = $(KERN_DIR)/include
|
---|
169 | endif
|
---|
170 | ifneq ($(shell if test -d $(KERN_INCL); then echo yes; fi),yes)
|
---|
171 | $(error Error: unable to find the include directory for your current Linux \
|
---|
172 | kernel. Specify KERN_INCL=<directory> and run Make again)
|
---|
173 | endif
|
---|
174 |
|
---|
175 | # module install dir, only for current kernel
|
---|
176 | ifneq ($(filter install install_rpm,$(MAKECMDGOALS)),)
|
---|
177 | ifndef MODULE_DIR
|
---|
178 | MODULE_DIR_TST := /lib/modules/$(shell uname -r)
|
---|
179 | ifeq ($(shell if test -d $(MODULE_DIR_TST); then echo yes; fi),yes)
|
---|
180 | MODULE_DIR := $(MODULE_DIR_TST)/misc
|
---|
181 | else
|
---|
182 | $(error Unable to find the folder to install the additions driver to)
|
---|
183 | endif
|
---|
184 | endif # MODULE_DIR unspecified
|
---|
185 | endif
|
---|
186 |
|
---|
187 | # guess kernel version (24 or 26)
|
---|
188 | ifeq ($(shell if grep '"2\.4\.' $(KERN_INCL)/linux/version.h > /dev/null; then echo yes; fi),yes)
|
---|
189 | KERN_VERSION := 24
|
---|
190 | else
|
---|
191 | KERN_VERSION := 26
|
---|
192 | endif
|
---|
193 |
|
---|
194 | else # neq($(KERNELRELEASE),)
|
---|
195 |
|
---|
196 | #
|
---|
197 | # building from kbuild (make -C <kernel_directory> M=`pwd`)
|
---|
198 | #
|
---|
199 |
|
---|
200 | # guess kernel version (24 or 26)
|
---|
201 | ifeq ($(shell if echo "$(VERSION).$(PATCHLEVEL)." | grep '2\.4\.' > /dev/null; then echo yes; fi),yes)
|
---|
202 | KERN_VERSION := 24
|
---|
203 | else
|
---|
204 | KERN_VERSION := 26
|
---|
205 | endif
|
---|
206 |
|
---|
207 | endif # neq($(KERNELRELEASE),)
|
---|
208 |
|
---|
209 | # debug - show guesses.
|
---|
210 | ifdef DEBUG
|
---|
211 | $(warning dbg: KERN_DIR = $(KERN_DIR))
|
---|
212 | $(warning dbg: KERN_INCL = $(KERN_INCL))
|
---|
213 | $(warning dbg: MODULE_DIR = $(MODULE_DIR))
|
---|
214 | $(warning dbg: KERN_VERSION = $(KERN_VERSION))
|
---|
215 | endif
|
---|
216 |
|
---|
217 | KBUILD_VERBOSE ?= 1
|
---|
218 |
|
---|
219 | #
|
---|
220 | # Compiler options
|
---|
221 | #
|
---|
222 | ifndef INCL
|
---|
223 | INCL := $(addprefix -I,$(KERN_INCL) $(EXTRA_INCL))
|
---|
224 | ifndef KBUILD_EXTMOD
|
---|
225 | KBUILD_EXTMOD := $(shell pwd)
|
---|
226 | endif
|
---|
227 | INCL += $(addprefix -I$(KBUILD_EXTMOD),/ /include /r0drv/linux)
|
---|
228 | INCL += $(addprefix -I$(KBUILD_EXTMOD)/vboxguest,/ /include /r0drv/linux)
|
---|
229 | export INCL
|
---|
230 | endif
|
---|
231 | KFLAGS := -D__KERNEL__ -DMODULE \
|
---|
232 | -DVBOX -DRT_OS_LINUX -DIN_RING0 -DIN_RT_R0 -DIN_GUEST -DIN_GUEST_R0 \
|
---|
233 | -DIN_MODULE -DRT_WITH_VBOX -DVBGL_VBOXGUEST -DVBOX_WITH_HGCM
|
---|
234 | ifeq ($(BUILD_TARGET_ARCH),amd64)
|
---|
235 | KFLAGS += -DRT_ARCH_AMD64 -DVBOX_WITH_64_BITS_GUESTS
|
---|
236 | else
|
---|
237 | KFLAGS += -DRT_ARCH_X86
|
---|
238 | endif
|
---|
239 | ifeq ($(BUILD_TYPE),debug)
|
---|
240 | KFLAGS += -DDEBUG
|
---|
241 | endif
|
---|
242 |
|
---|
243 | ifeq ($(KERN_VERSION), 24)
|
---|
244 | #
|
---|
245 | # 2.4
|
---|
246 | #
|
---|
247 |
|
---|
248 | ifeq ($(BUILD_TARGET_ARCH),amd64)
|
---|
249 | KFLAGS += -mcmodel=kernel
|
---|
250 | endif
|
---|
251 |
|
---|
252 | CFLAGS := -O2 -DVBOX_LINUX_2_4 -DEXPORT_SYMTAB $(INCL) $(KFLAGS) $(KDEBUG)
|
---|
253 | MODULE_EXT := o
|
---|
254 |
|
---|
255 | # 2.4 Module linking
|
---|
256 | $(MODULE).o: $(OBJS)
|
---|
257 | $(LD) -o $@ -r $(OBJS)
|
---|
258 |
|
---|
259 | .PHONY: $(MODULE)
|
---|
260 | all: $(MODULE)
|
---|
261 | $(MODULE): $(MODULE).o
|
---|
262 |
|
---|
263 | else
|
---|
264 | #
|
---|
265 | # 2.6 and later
|
---|
266 | #
|
---|
267 |
|
---|
268 | MODULE_EXT := ko
|
---|
269 |
|
---|
270 | $(MODULE)-y := $(OBJS)
|
---|
271 |
|
---|
272 | # build defs
|
---|
273 | EXTRA_CFLAGS += $(INCL) $(KFLAGS) $(KDEBUG)
|
---|
274 |
|
---|
275 | all: $(MODULE)
|
---|
276 |
|
---|
277 | obj-m += $(MODULE).o
|
---|
278 |
|
---|
279 | $(MODULE):
|
---|
280 | $(MAKE) KBUILD_VERBOSE=$(KBUILD_VERBOSE) -C $(KERN_DIR) SUBDIRS=$(CURDIR) SRCROOT=$(CURDIR) modules
|
---|
281 |
|
---|
282 | endif
|
---|
283 |
|
---|
284 | install: $(MODULE)
|
---|
285 | @mkdir -p $(MODULE_DIR); \
|
---|
286 | install -m 0664 -o root -g root $(MODULE).$(MODULE_EXT) $(MODULE_DIR); \
|
---|
287 | PATH="$(PATH):/bin:/sbin" depmod -a;
|
---|
288 |
|
---|
289 | endif # eq($(MAKECMDGOALS),clean)
|
---|
290 |
|
---|
291 | clean:
|
---|
292 | for f in . linux r0drv generic r0drv/linux r0drv/generic VBox \
|
---|
293 | common/alloc common/err common/log common/math/gcc common/misc common/string common/time; \
|
---|
294 | do rm -f $$f/*.o $$f/.*.cmd $$f/.*.flags; done
|
---|
295 | rm -rf .vboxguest* .tmp_ver* vboxguest.* Module.symvers Modules.symvers modules.order
|
---|