1 | #
|
---|
2 | # VirtualBox Guest Additions Module Makefile.
|
---|
3 | #
|
---|
4 | # (For 2.6.x this file must be 'Makefile'!)
|
---|
5 | #
|
---|
6 | # Copyright (C) 2006-2010 Oracle Corporation
|
---|
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 |
|
---|
17 | #
|
---|
18 | # First, figure out which architecture we're targeting and the build type.
|
---|
19 | # (We have to support basic cross building (ARCH=i386|x86_64).)
|
---|
20 | # While at it, warn about BUILD_* vars found to help with user problems.
|
---|
21 | #
|
---|
22 | ifeq ($(filter-out x86_64 amd64 AMD64,$(shell uname -m)),)
|
---|
23 | BUILD_TARGET_ARCH_DEF := amd64
|
---|
24 | else
|
---|
25 | BUILD_TARGET_ARCH_DEF := x86
|
---|
26 | endif
|
---|
27 | ifneq ($(filter-out amd64 x86,$(BUILD_TARGET_ARCH)),)
|
---|
28 | $(warning Ignoring unknown BUILD_TARGET_ARCH value '$(BUILD_TARGET_ARCH)'.)
|
---|
29 | BUILD_TARGET_ARCH :=
|
---|
30 | endif
|
---|
31 | ifeq ($(BUILD_TARGET_ARCH),)
|
---|
32 | ifeq ($(ARCH),x86_64)
|
---|
33 | BUILD_TARGET_ARCH := amd64
|
---|
34 | else
|
---|
35 | ifeq ($(ARCH),i386)
|
---|
36 | BUILD_TARGET_ARCH := x86
|
---|
37 | else
|
---|
38 | BUILD_TARGET_ARCH := $(BUILD_TARGET_ARCH_DEF)
|
---|
39 | endif
|
---|
40 | endif
|
---|
41 | else
|
---|
42 | ifneq ($(BUILD_TARGET_ARCH),$(BUILD_TARGET_ARCH_DEF))
|
---|
43 | $(warning Using BUILD_TARGET_ARCH='$(BUILD_TARGET_ARCH)' from the $(origin BUILD_TARGET_ARCH).)
|
---|
44 | endif
|
---|
45 | endif
|
---|
46 |
|
---|
47 | ifneq ($(filter-out release profile debug strict,$(BUILD_TYPE)),)
|
---|
48 | $(warning Ignoring unknown BUILD_TYPE value '$(BUILD_TYPE)'.)
|
---|
49 | BUILD_TYPE :=
|
---|
50 | endif
|
---|
51 | ifeq ($(BUILD_TYPE),)
|
---|
52 | BUILD_TYPE := release
|
---|
53 | else
|
---|
54 | ifneq ($(BUILD_TYPE),release)
|
---|
55 | $(warning Using BUILD_TYPE='$(BUILD_TYPE)' from the $(origin BUILD_TYPE).)
|
---|
56 | endif
|
---|
57 | endif
|
---|
58 |
|
---|
59 |
|
---|
60 | # override is required by the Debian guys
|
---|
61 | override MODULE = vboxsf
|
---|
62 | OBJS = \
|
---|
63 | vfsmod.o \
|
---|
64 | dirops.o \
|
---|
65 | lnkops.o \
|
---|
66 | regops.o \
|
---|
67 | utils.o \
|
---|
68 | GenericRequest.o \
|
---|
69 | SysHlp.o \
|
---|
70 | PhysHeap.o \
|
---|
71 | Init.o \
|
---|
72 | VMMDev.o \
|
---|
73 | HGCM.o \
|
---|
74 | VBoxGuestR0LibSharedFolders.o \
|
---|
75 | VbglR0CanUsePhysPageList.o
|
---|
76 | ifeq ($(BUILD_TARGET_ARCH),x86)
|
---|
77 | OBJS += \
|
---|
78 | divdi3.o \
|
---|
79 | moddi3.o \
|
---|
80 | udivdi3.o \
|
---|
81 | umoddi3.o \
|
---|
82 | qdivrem.o
|
---|
83 | endif
|
---|
84 |
|
---|
85 | EXTRA_CFLAGS = -fshort-wchar
|
---|
86 |
|
---|
87 | ifneq ($(MAKECMDGOALS),clean)
|
---|
88 |
|
---|
89 | ifeq ($(KERNELRELEASE),)
|
---|
90 |
|
---|
91 | #
|
---|
92 | # building from this directory
|
---|
93 | #
|
---|
94 |
|
---|
95 | # kernel base directory
|
---|
96 | ifndef KERN_DIR
|
---|
97 | KERN_DIR := /lib/modules/$(shell uname -r)/build
|
---|
98 | ifneq ($(shell if test -d $(KERN_DIR); then echo yes; fi),yes)
|
---|
99 | KERN_DIR := /usr/src/linux
|
---|
100 | ifneq ($(shell if test -d $(KERN_DIR); then echo yes; fi),yes)
|
---|
101 | $(error Error: unable to find the sources of your current Linux kernel. \
|
---|
102 | Specify KERN_DIR=<directory> and run Make again)
|
---|
103 | endif
|
---|
104 | $(warning Warning: using /usr/src/linux as the source directory of your \
|
---|
105 | Linux kernel. If this is not correct, specify \
|
---|
106 | KERN_DIR=<directory> and run Make again.)
|
---|
107 | endif
|
---|
108 | else
|
---|
109 | ifneq ($(shell if test -d $(KERN_DIR); then echo yes; fi),yes)
|
---|
110 | $(error Error: KERN_DIR does not point to a directory)
|
---|
111 | endif
|
---|
112 | endif
|
---|
113 |
|
---|
114 | # includes
|
---|
115 | ifndef KERN_INCL
|
---|
116 | KERN_INCL = $(KERN_DIR)/include
|
---|
117 | endif
|
---|
118 | ifneq ($(shell if test -d $(KERN_INCL); then echo yes; fi),yes)
|
---|
119 | $(error Error: unable to find the include directory for your current Linux \
|
---|
120 | kernel. Specify KERN_INCL=<directory> and run Make again)
|
---|
121 | endif
|
---|
122 |
|
---|
123 | # module install dir.
|
---|
124 | ifneq ($(filter install install_rpm,$(MAKECMDGOALS)),)
|
---|
125 | ifndef MODULE_DIR
|
---|
126 | MODULE_DIR_TST := /lib/modules/$(shell uname -r)
|
---|
127 | ifeq ($(shell if test -d $(MODULE_DIR_TST); then echo yes; fi),yes)
|
---|
128 | MODULE_DIR := $(MODULE_DIR_TST)/misc
|
---|
129 | else
|
---|
130 | $(error Unable to find the folder to install the shared folders driver to)
|
---|
131 | endif
|
---|
132 | endif # MODULE_DIR unspecified
|
---|
133 | endif
|
---|
134 |
|
---|
135 | # guess kernel version (24 or 26)
|
---|
136 | ifeq ($(shell if grep '"2\.4\.' $(KERN_INCL)/linux/version.h > /dev/null; then echo yes; fi),yes)
|
---|
137 | KERN_VERSION := 24
|
---|
138 | else
|
---|
139 | KERN_VERSION := 26
|
---|
140 | endif
|
---|
141 |
|
---|
142 | else # neq($(KERNELRELEASE),)
|
---|
143 |
|
---|
144 | #
|
---|
145 | # building from kbuild (make -C <kernel_directory> M=`pwd`)
|
---|
146 | #
|
---|
147 |
|
---|
148 | # guess kernel version (24 or 26)
|
---|
149 | ifeq ($(shell if echo "$(VERSION).$(PATCHLEVEL)." | grep '2\.4\.' > /dev/null; then echo yes; fi),yes)
|
---|
150 | KERN_VERSION := 24
|
---|
151 | else
|
---|
152 | KERN_VERSION := 26
|
---|
153 | endif
|
---|
154 |
|
---|
155 | endif # neq($(KERNELRELEASE),)
|
---|
156 |
|
---|
157 | # debug - show guesses.
|
---|
158 | ifdef DEBUG
|
---|
159 | $(warning dbg: KERN_DIR = $(KERN_DIR))
|
---|
160 | $(warning dbg: KERN_INCL = $(KERN_INCL))
|
---|
161 | $(warning dbg: MODULE_DIR = $(MODULE_DIR))
|
---|
162 | $(warning dbg: KERN_VERSION = $(KERN_VERSION))
|
---|
163 | endif
|
---|
164 |
|
---|
165 | KBUILD_VERBOSE ?= 1
|
---|
166 |
|
---|
167 | #
|
---|
168 | # Compiler options
|
---|
169 | #
|
---|
170 | ifndef INCL
|
---|
171 | INCL := $(addprefix -I,$(KERN_INCL) $(EXTRA_INCL))
|
---|
172 | ifndef KBUILD_EXTMOD
|
---|
173 | KBUILD_EXTMOD := $(shell pwd)
|
---|
174 | endif
|
---|
175 | INCL += $(addprefix -I$(KBUILD_EXTMOD),/ /include /r0drv/linux)
|
---|
176 | INCL += $(addprefix -I$(KBUILD_EXTMOD)/vboxsf,/ /include /r0drv/linux)
|
---|
177 | export INCL
|
---|
178 | endif
|
---|
179 | KFLAGS := -D__KERNEL__ -DMODULE -DRT_OS_LINUX -DIN_RING0 -DIN_RT_R0 \
|
---|
180 | -DIN_SUP_R0 -DVBOX -DVBOX_WITH_HGCM -DIN_MODULE -DIN_GUEST_R0
|
---|
181 | # our module does not export any symbol
|
---|
182 | KFLAGS += -DRT_NO_EXPORT_SYMBOL
|
---|
183 | ifeq ($(BUILD_TARGET_ARCH),amd64)
|
---|
184 | KFLAGS += -DRT_ARCH_AMD64 -DVBOX_WITH_64_BITS_GUESTS
|
---|
185 | else
|
---|
186 | KFLAGS += -DRT_ARCH_X86
|
---|
187 | endif
|
---|
188 | ifeq ($(BUILD_TYPE),debug)
|
---|
189 | KFLAGS += -DDEBUG
|
---|
190 | endif
|
---|
191 |
|
---|
192 | ifeq ($(KERN_VERSION), 24)
|
---|
193 | #
|
---|
194 | # 2.4
|
---|
195 | #
|
---|
196 |
|
---|
197 | ifeq ($(BUILD_TARGET_ARCH),amd64)
|
---|
198 | KFLAGS += -mcmodel=kernel
|
---|
199 | endif
|
---|
200 |
|
---|
201 | CFLAGS := -O2 -DVBOX_LINUX_2_4 $(INCL) $(KFLAGS) $(KDEBUG)
|
---|
202 | MODULE_EXT := o
|
---|
203 |
|
---|
204 | # 2.4 Module linking
|
---|
205 | $(MODULE).o: $(OBJS)
|
---|
206 | $(LD) -o $@ -r $(OBJS)
|
---|
207 |
|
---|
208 | .PHONY: $(MODULE)
|
---|
209 | all: $(MODULE)
|
---|
210 | $(MODULE): $(MODULE).o
|
---|
211 |
|
---|
212 | else
|
---|
213 | #
|
---|
214 | # 2.6 and later
|
---|
215 | #
|
---|
216 |
|
---|
217 | MODULE_EXT := ko
|
---|
218 |
|
---|
219 | $(MODULE)-y := $(OBJS)
|
---|
220 |
|
---|
221 | # special hack for Fedora Core 6 2.6.18 (fc6), rhel5 2.6.18 (el5),
|
---|
222 | # ClarkConnect 4.3 (cc4) and ClarkConnect 5 (v5)
|
---|
223 | ifeq ($(KERNELRELEASE),)
|
---|
224 | KFLAGS += $(foreach inc,$(KERN_INCL),\
|
---|
225 | $(if $(wildcard $(inc)/linux/utsrelease.h),\
|
---|
226 | $(if $(shell grep '"2.6.18.*fc6.*"' $(inc)/linux/utsrelease.h; \
|
---|
227 | grep '"2.6.18.*el5.*"' $(inc)/linux/utsrelease.h; \
|
---|
228 | grep '"2.6.18.*v5.*"' $(inc)/linux/utsrelease.h; \
|
---|
229 | grep '"2.6.18.*cc4.*"' $(inc)/linux/utsrelease.h),\
|
---|
230 | -DKERNEL_FC6,),))
|
---|
231 | else
|
---|
232 | KFLAGS += $(if $(shell echo "$(KERNELRELEASE)"|grep '2.6.18.*fc6.*';\
|
---|
233 | echo "$(KERNELRELEASE)"|grep '2.6.18.*el5.*';\
|
---|
234 | echo "$(KERNELRELEASE)"|grep '2.6.18.*v5.*';\
|
---|
235 | echo "$(KERNELRELEASE)"|grep '2.6.18.*cc4.*'),\
|
---|
236 | -DKERNEL_FC6,)
|
---|
237 | endif
|
---|
238 |
|
---|
239 | # build defs
|
---|
240 | EXTRA_CFLAGS += $(INCL) $(KFLAGS) $(KDEBUG)
|
---|
241 |
|
---|
242 | all: $(MODULE)
|
---|
243 |
|
---|
244 | obj-m += $(MODULE).o
|
---|
245 |
|
---|
246 | $(MODULE):
|
---|
247 | $(MAKE) KBUILD_VERBOSE=$(KBUILD_VERBOSE) -C $(KERN_DIR) SUBDIRS=$(CURDIR) SRCROOT=$(CURDIR) modules
|
---|
248 |
|
---|
249 | endif
|
---|
250 |
|
---|
251 | install: $(MODULE)
|
---|
252 | @mkdir -p $(MODULE_DIR); \
|
---|
253 | install -m 0664 -o root -g root $(MODULE).$(MODULE_EXT) $(MODULE_DIR); \
|
---|
254 | PATH="$(PATH):/bin:/sbin" depmod -a;
|
---|
255 |
|
---|
256 | endif # eq($(MAKECMDGOALS),clean)
|
---|
257 |
|
---|
258 | # important: Don't remove Module.symvers! DKMS does 'make clean' before building ...
|
---|
259 | clean:
|
---|
260 | for f in . linux r0drv r0drv/linux; do rm -f $$f/*.o $$f/.*.cmd $$f/.*.flags; done
|
---|
261 | rm -rf .vboxsf* .tmp_ver* vboxsf.* Modules.symvers modules.order
|
---|