1 | #
|
---|
2 | # VirtualBox Guest Additions Module Makefile.
|
---|
3 | #
|
---|
4 | # (For 2.6.x this file must be 'Makefile'!)
|
---|
5 | #
|
---|
6 | # Copyright (C) 2006-2007 Sun Microsystems, Inc.
|
---|
7 | #
|
---|
8 | # This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
9 | # available from http://www.virtualbox.org. This file is free software;
|
---|
10 | # you can redistribute it and/or modify it under the terms of the GNU
|
---|
11 | # General Public License (GPL) as published by the Free Software
|
---|
12 | # Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
13 | # VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
14 | # hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
15 | #
|
---|
16 | # Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
|
---|
17 | # Clara, CA 95054 USA or visit http://www.sun.com if you need
|
---|
18 | # additional information or have any questions.
|
---|
19 | #
|
---|
20 |
|
---|
21 | #
|
---|
22 | # First, figure out which architecture we're targeting and the build type.
|
---|
23 | # (We have to support basic cross building (ARCH=i386|x86_64).)
|
---|
24 | # While at it, warn about BUILD_* vars found to help with user problems.
|
---|
25 | #
|
---|
26 | ifneq ($(filter-out amd64 x86,$(BUILD_TARGET_ARCH)),)
|
---|
27 | $(warning Ignoring unknown BUILD_TARGET_ARCH value '$(BUILD_TARGET_ARCH)'.)
|
---|
28 | BUILD_TARGET_ARCH :=
|
---|
29 | endif
|
---|
30 | ifeq ($(BUILD_TARGET_ARCH),)
|
---|
31 | ifeq ($(ARCH),x86_64)
|
---|
32 | BUILD_TARGET_ARCH := amd64
|
---|
33 | else
|
---|
34 | ifeq ($(ARCH),i386)
|
---|
35 | BUILD_TARGET_ARCH := x86
|
---|
36 | else
|
---|
37 | ifeq ($(filter-out x86_64 amd64 AMD64,$(shell uname -m)),)
|
---|
38 | BUILD_TARGET_ARCH := amd64
|
---|
39 | else
|
---|
40 | BUILD_TARGET_ARCH := x86
|
---|
41 | endif
|
---|
42 | endif
|
---|
43 | endif
|
---|
44 | else
|
---|
45 | $(warning Using BUILD_TARGET_ARCH='$(BUILD_TARGET_ARCH)' from the $(origin BUILD_TARGET_ARCH).)
|
---|
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 | $(warning Using BUILD_TYPE='$(BUILD_TYPE)' from the $(origin BUILD_TYPE).)
|
---|
56 | endif
|
---|
57 |
|
---|
58 |
|
---|
59 | # override is required by the Debian guys
|
---|
60 | override MODULE = vboxadd
|
---|
61 | OBJS = \
|
---|
62 | cmc.o \
|
---|
63 | vboxmod.o \
|
---|
64 | GenericRequest.o \
|
---|
65 | HGCMInternal.o \
|
---|
66 | Init.o \
|
---|
67 | PhysHeap.o \
|
---|
68 | SysHlp.o \
|
---|
69 | VMMDev.o \
|
---|
70 | r0drv/alloc-r0drv.o \
|
---|
71 | r0drv/memobj-r0drv.o \
|
---|
72 | r0drv/linux/alloc-r0drv-linux.o \
|
---|
73 | r0drv/linux/assert-r0drv-linux.o \
|
---|
74 | r0drv/linux/memobj-r0drv-linux.o \
|
---|
75 | r0drv/linux/process-r0drv-linux.o \
|
---|
76 | r0drv/linux/semevent-r0drv-linux.o \
|
---|
77 | r0drv/linux/semfastmutex-r0drv-linux.o \
|
---|
78 | RTErrConvertToErrno.o \
|
---|
79 | divdi3.o \
|
---|
80 | moddi3.o \
|
---|
81 | udivdi3.o \
|
---|
82 | umoddi3.o \
|
---|
83 | qdivrem.o \
|
---|
84 | logbackdoor.o \
|
---|
85 | logformat.o \
|
---|
86 | strformat.o \
|
---|
87 | strformatrt.o \
|
---|
88 | strformattype.o \
|
---|
89 | strprintf.o \
|
---|
90 | strformat-vbox.o \
|
---|
91 | RTAssertShouldPanic-generic.o
|
---|
92 | ifeq ($(BUILD_TARGET_ARCH),amd64)
|
---|
93 | OBJS += \
|
---|
94 | alloc/heapsimple.o \
|
---|
95 | r0drv/linux/spinlock-r0drv-linux.o
|
---|
96 | endif
|
---|
97 |
|
---|
98 | ifneq ($(MAKECMDGOALS),clean)
|
---|
99 |
|
---|
100 | ifeq ($(KERNELRELEASE),)
|
---|
101 |
|
---|
102 | #
|
---|
103 | # building from this directory
|
---|
104 | #
|
---|
105 |
|
---|
106 | # kernel base directory
|
---|
107 | ifndef KERN_DIR
|
---|
108 | KERN_DIR := /lib/modules/$(shell uname -r)/build
|
---|
109 | ifneq ($(shell if test -d $(KERN_DIR); then echo yes; fi),yes)
|
---|
110 | KERN_DIR := /usr/src/linux
|
---|
111 | ifneq ($(shell if test -d $(KERN_DIR); then echo yes; fi),yes)
|
---|
112 | $(error Error: unable to find the sources of your current Linux kernel. \
|
---|
113 | Specify KERN_DIR=<directory> and run Make again)
|
---|
114 | endif
|
---|
115 | $(warning Warning: using /usr/src/linux as the source directory of your \
|
---|
116 | Linux kernel. If this is not correct, specify \
|
---|
117 | KERN_DIR=<directory> and run Make again.)
|
---|
118 | endif
|
---|
119 | else
|
---|
120 | ifneq ($(shell if test -d $(KERN_DIR); then echo yes; fi),yes)
|
---|
121 | $(error Error: KERN_DIR does not point to a directory)
|
---|
122 | endif
|
---|
123 | endif
|
---|
124 |
|
---|
125 | # includes
|
---|
126 | ifndef KERN_INCL
|
---|
127 | KERN_INCL = $(KERN_DIR)/include
|
---|
128 | endif
|
---|
129 | ifneq ($(shell if test -d $(KERN_INCL); then echo yes; fi),yes)
|
---|
130 | $(error Error: unable to find the include directory for your current Linux \
|
---|
131 | kernel. Specify KERN_INCL=<directory> and run Make again)
|
---|
132 | endif
|
---|
133 |
|
---|
134 | # module install dir.
|
---|
135 | ifneq ($(filter install install_rpm,$(MAKECMDGOALS)),)
|
---|
136 | ifndef MODULE_DIR
|
---|
137 | MODULE_DIR_TST := /lib/modules/$(shell uname -r)
|
---|
138 | ifeq ($(shell if test -d $(MODULE_DIR_TST); then echo yes; fi),yes)
|
---|
139 | MODULE_DIR := $(MODULE_DIR_TST)/misc
|
---|
140 | else
|
---|
141 | $(error Unable to find the folder to install the additions driver to)
|
---|
142 | endif
|
---|
143 | endif # MODULE_DIR unspecified
|
---|
144 | endif
|
---|
145 |
|
---|
146 | # guess kernel version (24 or 26)
|
---|
147 | ifeq ($(shell if grep '"2\.4\.' $(KERN_INCL)/linux/version.h > /dev/null; then echo yes; fi),yes)
|
---|
148 | KERN_VERSION := 24
|
---|
149 | else
|
---|
150 | KERN_VERSION := 26
|
---|
151 | endif
|
---|
152 |
|
---|
153 | else # neq($(KERNELRELEASE),)
|
---|
154 |
|
---|
155 | #
|
---|
156 | # building from kbuild (make -C <kernel_directory> M=`pwd`)
|
---|
157 | #
|
---|
158 |
|
---|
159 | # guess kernel version (24 or 26)
|
---|
160 | ifeq ($(shell if grep '"2\.4\.' $(PWD)/include/linux/version.h > /dev/null; then echo yes; fi),yes)
|
---|
161 | KERN_VERSION := 24
|
---|
162 | else
|
---|
163 | KERN_VERSION := 26
|
---|
164 | endif
|
---|
165 |
|
---|
166 | endif # neq($(KERNELRELEASE),)
|
---|
167 |
|
---|
168 | # debug - show guesses.
|
---|
169 | ifdef DEBUG
|
---|
170 | $(warning dbg: KERN_DIR = $(KERN_DIR))
|
---|
171 | $(warning dbg: KERN_INCL = $(KERN_INCL))
|
---|
172 | $(warning dbg: MODULE_DIR = $(MODULE_DIR))
|
---|
173 | $(warning dbg: KERN_VERSION = $(KERN_VERSION))
|
---|
174 | endif
|
---|
175 |
|
---|
176 |
|
---|
177 | #
|
---|
178 | # Compiler options
|
---|
179 | #
|
---|
180 | ifndef INCL
|
---|
181 | INCL := $(addprefix -I,$(KERN_INCL) $(EXTRA_INCL))
|
---|
182 | ifndef KBUILD_EXTMOD
|
---|
183 | KBUILD_EXTMOD := $(shell pwd)
|
---|
184 | endif
|
---|
185 | INCL += $(addprefix -I$(KBUILD_EXTMOD),/ /include /r0drv/linux)
|
---|
186 | export INCL
|
---|
187 | endif
|
---|
188 | KFLAGS := -D__KERNEL__ -DMODULE -DRT_OS_LINUX -DIN_RING0 \
|
---|
189 | -DIN_RT_R0 -DIN_SUP_R0 -DVBOX -DVBGL_VBOXGUEST -DVBOX_WITH_HGCM \
|
---|
190 | -DLOG_TO_BACKDOOR -DRT_WITH_VBOX -DIN_MODULE -DIN_GUEST_R0
|
---|
191 | ifeq ($(BUILD_TARGET_ARCH),amd64)
|
---|
192 | KFLAGS += -DRT_ARCH_AMD64 -DVBOX_WITH_64_BITS_GUESTS
|
---|
193 | else
|
---|
194 | KFLAGS += -DRT_ARCH_X86
|
---|
195 | endif
|
---|
196 | ifeq ($(BUILD_TYPE),debug)
|
---|
197 | KFLAGS += -DDEBUG
|
---|
198 | endif
|
---|
199 |
|
---|
200 | ifeq ($(KERN_VERSION), 24)
|
---|
201 | #
|
---|
202 | # 2.4
|
---|
203 | #
|
---|
204 |
|
---|
205 | CFLAGS := -O2 -DVBOX_LINUX_2_4 -DEXPORT_SYMTAB $(INCL) $(KFLAGS) $(KDEBUG)
|
---|
206 | MODULE_EXT := o
|
---|
207 |
|
---|
208 | # 2.4 Module linking
|
---|
209 | $(MODULE).o: $(OBJS)
|
---|
210 | $(LD) -o $@ -r $(OBJS)
|
---|
211 |
|
---|
212 | .PHONY: $(MODULE)
|
---|
213 | all: $(MODULE)
|
---|
214 | $(MODULE): $(MODULE).o
|
---|
215 |
|
---|
216 | else
|
---|
217 | #
|
---|
218 | # 2.6 and later
|
---|
219 | #
|
---|
220 |
|
---|
221 | MODULE_EXT := ko
|
---|
222 |
|
---|
223 | $(MODULE)-y := $(OBJS)
|
---|
224 |
|
---|
225 | # build defs
|
---|
226 | EXTRA_CFLAGS += $(INCL) $(KFLAGS) $(KDEBUG)
|
---|
227 |
|
---|
228 | all: $(MODULE)
|
---|
229 |
|
---|
230 | obj-m += $(MODULE).o
|
---|
231 |
|
---|
232 | $(MODULE):
|
---|
233 | $(MAKE) KBUILD_VERBOSE=1 -C $(KERN_DIR) SUBDIRS=$(CURDIR) SRCROOT=$(CURDIR) modules
|
---|
234 |
|
---|
235 | endif
|
---|
236 |
|
---|
237 | install: $(MODULE)
|
---|
238 | @mkdir -p $(MODULE_DIR); \
|
---|
239 | install -m 0664 -o root -g root $(MODULE).$(MODULE_EXT) $(MODULE_DIR); \
|
---|
240 | PATH="$(PATH):/bin:/sbin" depmod -ae;
|
---|
241 |
|
---|
242 | endif # eq($(MAKECMDGOALS),clean)
|
---|
243 |
|
---|
244 | clean:
|
---|
245 | for f in . linux r0drv r0drv/linux; do rm -f $$f/*.o $$f/.*.cmd $$f/.*.flags; done
|
---|
246 | rm -rf .vboxadd* .tmp_ver* vboxadd.* Module.symvers Modules.symvers modules.order
|
---|