1 | # $Revision: 21337 $
|
---|
2 | ## @file
|
---|
3 | # VirtualBox Guest Additions Module Makefile.
|
---|
4 | #
|
---|
5 |
|
---|
6 | #
|
---|
7 | # Copyright (C) 2006-2009 Sun Microsystems, Inc.
|
---|
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 | # Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
|
---|
18 | # Clara, CA 95054 USA or visit http://www.sun.com if you need
|
---|
19 | # additional information or have any questions.
|
---|
20 | #
|
---|
21 |
|
---|
22 | #
|
---|
23 | # First, figure out which architecture we're targeting and the build type.
|
---|
24 | # (We have to support basic cross building (ARCH=i386|x86_64).)
|
---|
25 | # While at it, warn about BUILD_* vars found to help with user problems.
|
---|
26 | #
|
---|
27 | ifeq ($(filter-out x86_64 amd64 AMD64,$(shell uname -m)),)
|
---|
28 | BUILD_TARGET_ARCH_DEF := amd64
|
---|
29 | else
|
---|
30 | BUILD_TARGET_ARCH_DEF := x86
|
---|
31 | endif
|
---|
32 | ifneq ($(filter-out amd64 x86,$(BUILD_TARGET_ARCH)),)
|
---|
33 | $(warning Ignoring unknown BUILD_TARGET_ARCH value '$(BUILD_TARGET_ARCH)'.)
|
---|
34 | BUILD_TARGET_ARCH :=
|
---|
35 | endif
|
---|
36 | ifeq ($(BUILD_TARGET_ARCH),)
|
---|
37 | ifeq ($(ARCH),x86_64)
|
---|
38 | BUILD_TARGET_ARCH := amd64
|
---|
39 | else
|
---|
40 | ifeq ($(ARCH),i386)
|
---|
41 | BUILD_TARGET_ARCH := x86
|
---|
42 | else
|
---|
43 | BUILD_TARGET_ARCH := $(BUILD_TARGET_ARCH_DEF)
|
---|
44 | endif
|
---|
45 | endif
|
---|
46 | else
|
---|
47 | ifneq ($(BUILD_TARGET_ARCH),$(BUILD_TARGET_ARCH_DEF))
|
---|
48 | $(warning Using BUILD_TARGET_ARCH='$(BUILD_TARGET_ARCH)' from the $(origin BUILD_TARGET_ARCH).)
|
---|
49 | endif
|
---|
50 | endif
|
---|
51 |
|
---|
52 | ifneq ($(filter-out release profile debug strict,$(BUILD_TYPE)),)
|
---|
53 | $(warning Ignoring unknown BUILD_TYPE value '$(BUILD_TYPE)'.)
|
---|
54 | BUILD_TYPE :=
|
---|
55 | endif
|
---|
56 | ifeq ($(BUILD_TYPE),)
|
---|
57 | BUILD_TYPE := release
|
---|
58 | else
|
---|
59 | ifneq ($(BUILD_TYPE),release)
|
---|
60 | $(warning Using BUILD_TYPE='$(BUILD_TYPE)' from the $(origin BUILD_TYPE).)
|
---|
61 | endif
|
---|
62 | endif
|
---|
63 |
|
---|
64 |
|
---|
65 | # override is required by the Debian guys
|
---|
66 | override MODULE = vboxguest
|
---|
67 | OBJS = \
|
---|
68 | VBoxGuest-linux.o \
|
---|
69 | VBoxGuest.o \
|
---|
70 | GenericRequest.o \
|
---|
71 | HGCMInternal.o \
|
---|
72 | Init.o \
|
---|
73 | PhysHeap.o \
|
---|
74 | SysHlp.o \
|
---|
75 | VMMDev.o \
|
---|
76 | r0drv/alloc-r0drv.o \
|
---|
77 | r0drv/initterm-r0drv.o \
|
---|
78 | r0drv/memobj-r0drv.o \
|
---|
79 | r0drv/mpnotification-r0drv.o \
|
---|
80 | r0drv/powernotification-r0drv.o \
|
---|
81 | r0drv/linux/alloc-r0drv-linux.o \
|
---|
82 | r0drv/linux/assert-r0drv-linux.o \
|
---|
83 | r0drv/linux/initterm-r0drv-linux.o \
|
---|
84 | r0drv/linux/memobj-r0drv-linux.o \
|
---|
85 | r0drv/linux/memuserkernel-r0drv-linux.o \
|
---|
86 | r0drv/linux/mp-r0drv-linux.o \
|
---|
87 | r0drv/linux/mpnotification-r0drv-linux.o \
|
---|
88 | r0drv/linux/process-r0drv-linux.o \
|
---|
89 | r0drv/linux/semevent-r0drv-linux.o \
|
---|
90 | r0drv/linux/semeventmulti-r0drv-linux.o \
|
---|
91 | r0drv/linux/semfastmutex-r0drv-linux.o \
|
---|
92 | r0drv/linux/spinlock-r0drv-linux.o \
|
---|
93 | r0drv/linux/thread-r0drv-linux.o \
|
---|
94 | r0drv/linux/RTLogWriteDebugger-r0drv-linux.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/string/strformat.o \
|
---|
104 | common/string/strformatrt.o \
|
---|
105 | common/string/strformattype.o \
|
---|
106 | common/string/strprintf.o \
|
---|
107 | common/string/strtonum.o \
|
---|
108 | generic/RTAssertShouldPanic-generic.o \
|
---|
109 | generic/RTLogWriteStdErr-stub-generic.o \
|
---|
110 | generic/RTLogWriteStdOut-stub-generic.o \
|
---|
111 | VBox/log-vbox.o \
|
---|
112 | VBox/logbackdoor.o \
|
---|
113 | VBox/strformat-vbox.o
|
---|
114 | ifeq ($(BUILD_TARGET_ARCH),x86)
|
---|
115 | OBJS += \
|
---|
116 | common/math/gcc/divdi3.o \
|
---|
117 | common/math/gcc/moddi3.o \
|
---|
118 | common/math/gcc/udivdi3.o \
|
---|
119 | common/math/gcc/umoddi3.o \
|
---|
120 | common/math/gcc/qdivrem.o
|
---|
121 | endif
|
---|
122 | ifeq ($(BUILD_TARGET_ARCH),amd64)
|
---|
123 | OBJS += common/alloc/heapsimple.o
|
---|
124 | endif
|
---|
125 |
|
---|
126 | ifneq ($(MAKECMDGOALS),clean)
|
---|
127 |
|
---|
128 | ifeq ($(KERNELRELEASE),)
|
---|
129 |
|
---|
130 | #
|
---|
131 | # building from this directory
|
---|
132 | #
|
---|
133 |
|
---|
134 | # kernel base directory
|
---|
135 | ifndef KERN_DIR
|
---|
136 | KERN_DIR := /lib/modules/$(shell uname -r)/build
|
---|
137 | ifneq ($(shell if test -d $(KERN_DIR); then echo yes; fi),yes)
|
---|
138 | KERN_DIR := /usr/src/linux
|
---|
139 | ifneq ($(shell if test -d $(KERN_DIR); then echo yes; fi),yes)
|
---|
140 | $(error Error: unable to find the sources of your current Linux kernel. \
|
---|
141 | Specify KERN_DIR=<directory> and run Make again)
|
---|
142 | endif
|
---|
143 | $(warning Warning: using /usr/src/linux as the source directory of your \
|
---|
144 | Linux kernel. If this is not correct, specify \
|
---|
145 | KERN_DIR=<directory> and run Make again.)
|
---|
146 | endif
|
---|
147 | else
|
---|
148 | ifneq ($(shell if test -d $(KERN_DIR); then echo yes; fi),yes)
|
---|
149 | $(error Error: KERN_DIR does not point to a directory)
|
---|
150 | endif
|
---|
151 | endif
|
---|
152 |
|
---|
153 | # includes
|
---|
154 | ifndef KERN_INCL
|
---|
155 | KERN_INCL = $(KERN_DIR)/include
|
---|
156 | endif
|
---|
157 | ifneq ($(shell if test -d $(KERN_INCL); then echo yes; fi),yes)
|
---|
158 | $(error Error: unable to find the include directory for your current Linux \
|
---|
159 | kernel. Specify KERN_INCL=<directory> and run Make again)
|
---|
160 | endif
|
---|
161 |
|
---|
162 | # module install dir, only for current kernel
|
---|
163 | ifneq ($(filter install install_rpm,$(MAKECMDGOALS)),)
|
---|
164 | ifndef MODULE_DIR
|
---|
165 | MODULE_DIR_TST := /lib/modules/$(shell uname -r)
|
---|
166 | ifeq ($(shell if test -d $(MODULE_DIR_TST); then echo yes; fi),yes)
|
---|
167 | MODULE_DIR := $(MODULE_DIR_TST)/misc
|
---|
168 | else
|
---|
169 | $(error Unable to find the folder to install the additions driver to)
|
---|
170 | endif
|
---|
171 | endif # MODULE_DIR unspecified
|
---|
172 | endif
|
---|
173 |
|
---|
174 | # guess kernel version (24 or 26)
|
---|
175 | ifeq ($(shell if grep '"2\.4\.' $(KERN_INCL)/linux/version.h > /dev/null; then echo yes; fi),yes)
|
---|
176 | KERN_VERSION := 24
|
---|
177 | else
|
---|
178 | KERN_VERSION := 26
|
---|
179 | endif
|
---|
180 |
|
---|
181 | else # neq($(KERNELRELEASE),)
|
---|
182 |
|
---|
183 | #
|
---|
184 | # building from kbuild (make -C <kernel_directory> M=`pwd`)
|
---|
185 | #
|
---|
186 |
|
---|
187 | # guess kernel version (24 or 26)
|
---|
188 | ifeq ($(shell if echo "$(VERSION).$(PATCHLEVEL)." | grep '2\.4\.' > /dev/null; then echo yes; fi),yes)
|
---|
189 | KERN_VERSION := 24
|
---|
190 | else
|
---|
191 | KERN_VERSION := 26
|
---|
192 | endif
|
---|
193 |
|
---|
194 | endif # neq($(KERNELRELEASE),)
|
---|
195 |
|
---|
196 | # debug - show guesses.
|
---|
197 | ifdef DEBUG
|
---|
198 | $(warning dbg: KERN_DIR = $(KERN_DIR))
|
---|
199 | $(warning dbg: KERN_INCL = $(KERN_INCL))
|
---|
200 | $(warning dbg: MODULE_DIR = $(MODULE_DIR))
|
---|
201 | $(warning dbg: KERN_VERSION = $(KERN_VERSION))
|
---|
202 | endif
|
---|
203 |
|
---|
204 | KBUILD_VERBOSE ?= 1
|
---|
205 |
|
---|
206 | #
|
---|
207 | # Compiler options
|
---|
208 | #
|
---|
209 | ifndef INCL
|
---|
210 | INCL := $(addprefix -I,$(KERN_INCL) $(EXTRA_INCL))
|
---|
211 | ifndef KBUILD_EXTMOD
|
---|
212 | KBUILD_EXTMOD := $(shell pwd)
|
---|
213 | endif
|
---|
214 | INCL += $(addprefix -I$(KBUILD_EXTMOD),/ /include /r0drv/linux)
|
---|
215 | export INCL
|
---|
216 | endif
|
---|
217 | KFLAGS := -D__KERNEL__ -DMODULE \
|
---|
218 | -DVBOX -DRT_OS_LINUX -DIN_RING0 -DIN_RT_R0 -DIN_GUEST -DIN_GUEST_R0 \
|
---|
219 | -DIN_MODULE -DRT_WITH_VBOX -DVBGL_VBOXGUEST -DVBOX_WITH_HGCM
|
---|
220 | ifeq ($(BUILD_TARGET_ARCH),amd64)
|
---|
221 | KFLAGS += -DRT_ARCH_AMD64 -DVBOX_WITH_64_BITS_GUESTS
|
---|
222 | else
|
---|
223 | KFLAGS += -DRT_ARCH_X86
|
---|
224 | endif
|
---|
225 | ifeq ($(BUILD_TYPE),debug)
|
---|
226 | KFLAGS += -DDEBUG
|
---|
227 | endif
|
---|
228 |
|
---|
229 | ifeq ($(KERN_VERSION), 24)
|
---|
230 | #
|
---|
231 | # 2.4
|
---|
232 | #
|
---|
233 |
|
---|
234 | CFLAGS := -O2 -DVBOX_LINUX_2_4 -DEXPORT_SYMTAB $(INCL) $(KFLAGS) $(KDEBUG)
|
---|
235 | MODULE_EXT := o
|
---|
236 |
|
---|
237 | # 2.4 Module linking
|
---|
238 | $(MODULE).o: $(OBJS)
|
---|
239 | $(LD) -o $@ -r $(OBJS)
|
---|
240 |
|
---|
241 | .PHONY: $(MODULE)
|
---|
242 | all: $(MODULE)
|
---|
243 | $(MODULE): $(MODULE).o
|
---|
244 |
|
---|
245 | else
|
---|
246 | #
|
---|
247 | # 2.6 and later
|
---|
248 | #
|
---|
249 |
|
---|
250 | MODULE_EXT := ko
|
---|
251 |
|
---|
252 | $(MODULE)-y := $(OBJS)
|
---|
253 |
|
---|
254 | # build defs
|
---|
255 | EXTRA_CFLAGS += $(INCL) $(KFLAGS) $(KDEBUG)
|
---|
256 |
|
---|
257 | all: $(MODULE)
|
---|
258 |
|
---|
259 | obj-m += $(MODULE).o
|
---|
260 |
|
---|
261 | $(MODULE):
|
---|
262 | $(MAKE) KBUILD_VERBOSE=$(KBUILD_VERBOSE) -C $(KERN_DIR) SUBDIRS=$(CURDIR) SRCROOT=$(CURDIR) modules
|
---|
263 |
|
---|
264 | endif
|
---|
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 -ae;
|
---|
270 |
|
---|
271 | endif # eq($(MAKECMDGOALS),clean)
|
---|
272 |
|
---|
273 | clean:
|
---|
274 | for f in . linux r0drv r0drv/linux VBox common/err common/string common/log generic common/math/gcc; \
|
---|
275 | do rm -f $$f/*.o $$f/.*.cmd $$f/.*.flags; done
|
---|
276 | rm -rf .vboxguest* .tmp_ver* vboxguest.* Module.symvers Modules.symvers modules.order
|
---|