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 = vboxvfs
|
---|
61 | OBJS = \
|
---|
62 | vfsmod.o \
|
---|
63 | dirops.o \
|
---|
64 | regops.o \
|
---|
65 | utils.o \
|
---|
66 | GenericRequest.o \
|
---|
67 | SysHlp.o \
|
---|
68 | PhysHeap.o \
|
---|
69 | Init.o \
|
---|
70 | VMMDev.o \
|
---|
71 | HGCM.o \
|
---|
72 | VBoxCalls.o \
|
---|
73 | r0drv/alloc-r0drv.o \
|
---|
74 | r0drv/linux/alloc-r0drv-linux.o \
|
---|
75 | r0drv/linux/semevent-r0drv-linux.o \
|
---|
76 | r0drv/linux/semfastmutex-r0drv-linux.o \
|
---|
77 | divdi3.o \
|
---|
78 | moddi3.o \
|
---|
79 | udivdi3.o \
|
---|
80 | umoddi3.o \
|
---|
81 | qdivrem.o
|
---|
82 |
|
---|
83 |
|
---|
84 | EXTRA_CFLAGS = -fshort-wchar
|
---|
85 |
|
---|
86 | ifneq ($(MAKECMDGOALS),clean)
|
---|
87 |
|
---|
88 | ifeq ($(KERNELRELEASE),)
|
---|
89 |
|
---|
90 | #
|
---|
91 | # building from this directory
|
---|
92 | #
|
---|
93 |
|
---|
94 | # kernel base directory
|
---|
95 | ifndef KERN_DIR
|
---|
96 | KERN_DIR := /lib/modules/$(shell uname -r)/build
|
---|
97 | ifneq ($(shell if test -d $(KERN_DIR); then echo yes; fi),yes)
|
---|
98 | KERN_DIR := /usr/src/linux
|
---|
99 | ifneq ($(shell if test -d $(KERN_DIR); then echo yes; fi),yes)
|
---|
100 | $(error Error: unable to find the sources of your current Linux kernel. \
|
---|
101 | Specify KERN_DIR=<directory> and run Make again)
|
---|
102 | endif
|
---|
103 | $(warning Warning: using /usr/src/linux as the source directory of your \
|
---|
104 | Linux kernel. If this is not correct, specify \
|
---|
105 | KERN_DIR=<directory> and run Make again.)
|
---|
106 | endif
|
---|
107 | else
|
---|
108 | ifneq ($(shell if test -d $(KERN_DIR); then echo yes; fi),yes)
|
---|
109 | $(error Error: KERN_DIR does not point to a directory)
|
---|
110 | endif
|
---|
111 | endif
|
---|
112 |
|
---|
113 | # includes
|
---|
114 | ifndef KERN_INCL
|
---|
115 | KERN_INCL = $(KERN_DIR)/include
|
---|
116 | endif
|
---|
117 | ifneq ($(shell if test -d $(KERN_INCL); then echo yes; fi),yes)
|
---|
118 | $(error Error: unable to find the include directory for your current Linux \
|
---|
119 | kernel. Specify KERN_INCL=<directory> and run Make again)
|
---|
120 | endif
|
---|
121 |
|
---|
122 | # module install dir.
|
---|
123 | ifneq ($(filter install install_rpm,$(MAKECMDGOALS)),)
|
---|
124 | ifndef MODULE_DIR
|
---|
125 | MODULE_DIR_TST := /lib/modules/$(shell uname -r)
|
---|
126 | ifeq ($(shell if test -d $(MODULE_DIR_TST); then echo yes; fi),yes)
|
---|
127 | MODULE_DIR := $(MODULE_DIR_TST)/misc
|
---|
128 | else
|
---|
129 | $(error Unable to find the folder to install the shared folders driver to)
|
---|
130 | endif
|
---|
131 | endif # MODULE_DIR unspecified
|
---|
132 | endif
|
---|
133 |
|
---|
134 | # guess kernel version (24 or 26)
|
---|
135 | ifeq ($(shell if grep '"2\.4\.' $(KERN_INCL)/linux/version.h > /dev/null; then echo yes; fi),yes)
|
---|
136 | KERN_VERSION := 24
|
---|
137 | else
|
---|
138 | KERN_VERSION := 26
|
---|
139 | endif
|
---|
140 |
|
---|
141 | else # neq($(KERNELRELEASE),)
|
---|
142 |
|
---|
143 | #
|
---|
144 | # building from kbuild (make -C <kernel_directory> M=`pwd`)
|
---|
145 | #
|
---|
146 |
|
---|
147 | # guess kernel version (24 or 26)
|
---|
148 | ifeq ($(shell if grep '"2\.4\.' $(PWD)/include/linux/version.h > /dev/null; then echo yes; fi),yes)
|
---|
149 | KERN_VERSION := 24
|
---|
150 | else
|
---|
151 | KERN_VERSION := 26
|
---|
152 | endif
|
---|
153 |
|
---|
154 | endif # neq($(KERNELRELEASE),)
|
---|
155 |
|
---|
156 | # debug - show guesses.
|
---|
157 | ifdef DEBUG
|
---|
158 | $(warning dbg: KERN_DIR = $(KERN_DIR))
|
---|
159 | $(warning dbg: KERN_INCL = $(KERN_INCL))
|
---|
160 | $(warning dbg: MODULE_DIR = $(MODULE_DIR))
|
---|
161 | $(warning dbg: KERN_VERSION = $(KERN_VERSION))
|
---|
162 | endif
|
---|
163 |
|
---|
164 |
|
---|
165 | #
|
---|
166 | # Compiler options
|
---|
167 | #
|
---|
168 | ifndef INCL
|
---|
169 | INCL := $(addprefix -I,$(KERN_INCL) $(EXTRA_INCL))
|
---|
170 | ifndef KBUILD_EXTMOD
|
---|
171 | KBUILD_EXTMOD := $(shell pwd)
|
---|
172 | endif
|
---|
173 | INCL += $(addprefix -I$(KBUILD_EXTMOD),/ /include /r0drv/linux)
|
---|
174 | export INCL
|
---|
175 | endif
|
---|
176 | KFLAGS := -D__KERNEL__ -DMODULE -DRT_OS_LINUX -DIN_RING0 -DIN_RT_R0 \
|
---|
177 | -DIN_SUP_R0 -DVBOX -DVBOX_WITH_HGCM -DLOG_TO_BACKDOOR -DIN_MODULE \
|
---|
178 | -DIN_GUEST_R0
|
---|
179 | ifeq ($(BUILD_TARGET_ARCH),amd64)
|
---|
180 | KFLAGS += -DRT_ARCH_AMD64 -DVBOX_WITH_64_BITS_GUESTS
|
---|
181 | else
|
---|
182 | KFLAGS += -DRT_ARCH_X86
|
---|
183 | endif
|
---|
184 | ifeq ($(BUILD_TYPE),debug)
|
---|
185 | KFLAGS += -DDEBUG
|
---|
186 | endif
|
---|
187 |
|
---|
188 | ifeq ($(KERN_VERSION), 24)
|
---|
189 | #
|
---|
190 | # 2.4
|
---|
191 | #
|
---|
192 |
|
---|
193 | CFLAGS := -O2 -DVBOX_LINUX_2_4 $(INCL) $(KFLAGS) $(KDEBUG)
|
---|
194 | MODULE_EXT := o
|
---|
195 |
|
---|
196 | # 2.4 Module linking
|
---|
197 | $(MODULE).o: $(OBJS)
|
---|
198 | $(LD) -o $@ -r $(OBJS)
|
---|
199 |
|
---|
200 | .PHONY: $(MODULE)
|
---|
201 | all: $(MODULE)
|
---|
202 | $(MODULE): $(MODULE).o
|
---|
203 |
|
---|
204 | else
|
---|
205 | #
|
---|
206 | # 2.6 and later
|
---|
207 | #
|
---|
208 |
|
---|
209 | MODULE_EXT := ko
|
---|
210 |
|
---|
211 | $(MODULE)-y := $(OBJS)
|
---|
212 |
|
---|
213 | # special hack for FC6 2.6.18 and rhel5 2.6.18
|
---|
214 | ifeq ($(KERNELRELEASE),)
|
---|
215 | KFLAGS += $(foreach inc,$(KERN_INCL),\
|
---|
216 | $(if $(wildcard $(inc)/linux/utsrelease.h),\
|
---|
217 | $(if $(shell grep '"2.6.18.*fc6.*"' $(inc)/linux/utsrelease.h; \
|
---|
218 | grep '"2.6.18.*el5.*"' $(inc)/linux/utsrelease.h; \
|
---|
219 | grep '"2.6.18.*cc4.*"' $(inc)/linux/utsrelease.h),\
|
---|
220 | -DKERNEL_FC6,),))
|
---|
221 | else
|
---|
222 | KFLAGS += $(if $(shell echo "$(KERNELRELEASE)"|grep '2.6.18.*fc6.*';\
|
---|
223 | echo "$(KERNELRELEASE)"|grep '2.6.18.*el5.*';\
|
---|
224 | echo "$(KERNELRELEASE)"|grep '2.6.18.*cc4.*'),\
|
---|
225 | -DKERNEL_FC6,)
|
---|
226 | endif
|
---|
227 |
|
---|
228 | # build defs
|
---|
229 | EXTRA_CFLAGS += $(INCL) $(KFLAGS) $(KDEBUG)
|
---|
230 |
|
---|
231 | all: $(MODULE)
|
---|
232 |
|
---|
233 | obj-m += $(MODULE).o
|
---|
234 |
|
---|
235 | $(MODULE):
|
---|
236 | $(MAKE) KBUILD_VERBOSE=1 -C $(KERN_DIR) SUBDIRS=$(CURDIR) SRCROOT=$(CURDIR) modules
|
---|
237 |
|
---|
238 | endif
|
---|
239 |
|
---|
240 | install: $(MODULE)
|
---|
241 | @mkdir -p $(MODULE_DIR); \
|
---|
242 | install -m 0664 -o root -g root $(MODULE).$(MODULE_EXT) $(MODULE_DIR); \
|
---|
243 | PATH="$(PATH):/bin:/sbin" depmod -ae;
|
---|
244 |
|
---|
245 | endif # eq($(MAKECMDGOALS),clean)
|
---|
246 |
|
---|
247 | clean:
|
---|
248 | for f in . linux r0drv r0drv/linux; do rm -f $$f/*.o $$f/.*.cmd $$f/.*.flags; done
|
---|
249 | rm -rf .vboxvfs* .tmp_ver* vboxvfs.* Module.symvers Modules.symvers
|
---|