VirtualBox

source: vbox/trunk/src/VBox/Additions/linux/sharedfolders/Makefile.module@ 17935

Last change on this file since 17935 was 17935, checked in by vboxsync, 16 years ago

Additions/linux: fixed kernel detection

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 6.9 KB
Line 
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#
26ifneq ($(filter-out amd64 x86,$(BUILD_TARGET_ARCH)),)
27 $(warning Ignoring unknown BUILD_TARGET_ARCH value '$(BUILD_TARGET_ARCH)'.)
28 BUILD_TARGET_ARCH :=
29endif
30ifeq ($(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
44else
45 $(warning Using BUILD_TARGET_ARCH='$(BUILD_TARGET_ARCH)' from the $(origin BUILD_TARGET_ARCH).)
46endif
47
48ifneq ($(filter-out release profile debug strict,$(BUILD_TYPE)),)
49 $(warning Ignoring unknown BUILD_TYPE value '$(BUILD_TYPE)'.)
50 BUILD_TYPE :=
51endif
52ifeq ($(BUILD_TYPE),)
53 BUILD_TYPE := release
54else
55 $(warning Using BUILD_TYPE='$(BUILD_TYPE)' from the $(origin BUILD_TYPE).)
56endif
57
58
59# override is required by the Debian guys
60override MODULE = vboxvfs
61OBJS = \
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/memobj-r0drv.o \
75 r0drv/linux/alloc-r0drv-linux.o \
76 r0drv/linux/memobj-r0drv-linux.o \
77 r0drv/linux/process-r0drv-linux.o \
78 r0drv/linux/semevent-r0drv-linux.o \
79 r0drv/linux/semfastmutex-r0drv-linux.o \
80 divdi3.o \
81 moddi3.o \
82 udivdi3.o \
83 umoddi3.o \
84 qdivrem.o
85
86
87EXTRA_CFLAGS = -fshort-wchar
88
89ifneq ($(MAKECMDGOALS),clean)
90
91ifeq ($(KERNELRELEASE),)
92
93 #
94 # building from this directory
95 #
96
97 # kernel base directory
98 ifndef KERN_DIR
99 KERN_DIR := /lib/modules/$(shell uname -r)/build
100 ifneq ($(shell if test -d $(KERN_DIR); then echo yes; fi),yes)
101 KERN_DIR := /usr/src/linux
102 ifneq ($(shell if test -d $(KERN_DIR); then echo yes; fi),yes)
103 $(error Error: unable to find the sources of your current Linux kernel. \
104 Specify KERN_DIR=<directory> and run Make again)
105 endif
106 $(warning Warning: using /usr/src/linux as the source directory of your \
107 Linux kernel. If this is not correct, specify \
108 KERN_DIR=<directory> and run Make again.)
109 endif
110 else
111 ifneq ($(shell if test -d $(KERN_DIR); then echo yes; fi),yes)
112 $(error Error: KERN_DIR does not point to a directory)
113 endif
114 endif
115
116 # includes
117 ifndef KERN_INCL
118 KERN_INCL = $(KERN_DIR)/include
119 endif
120 ifneq ($(shell if test -d $(KERN_INCL); then echo yes; fi),yes)
121 $(error Error: unable to find the include directory for your current Linux \
122 kernel. Specify KERN_INCL=<directory> and run Make again)
123 endif
124
125 # module install dir.
126 ifneq ($(filter install install_rpm,$(MAKECMDGOALS)),)
127 ifndef MODULE_DIR
128 MODULE_DIR_TST := /lib/modules/$(shell uname -r)
129 ifeq ($(shell if test -d $(MODULE_DIR_TST); then echo yes; fi),yes)
130 MODULE_DIR := $(MODULE_DIR_TST)/misc
131 else
132 $(error Unable to find the folder to install the shared folders driver to)
133 endif
134 endif # MODULE_DIR unspecified
135 endif
136
137 # guess kernel version (24 or 26)
138 ifeq ($(shell if grep '"2\.4\.' $(KERN_INCL)/linux/version.h > /dev/null; then echo yes; fi),yes)
139 KERN_VERSION := 24
140 else
141 KERN_VERSION := 26
142 endif
143
144else # neq($(KERNELRELEASE),)
145
146 #
147 # building from kbuild (make -C <kernel_directory> M=`pwd`)
148 #
149
150 # guess kernel version (24 or 26)
151 ifeq ($(shell if echo "$(VERSION).$(PATCHLEVEL)." | grep '2\.4\.' > /dev/null; then echo yes; fi),yes)
152 KERN_VERSION := 24
153 else
154 KERN_VERSION := 26
155 endif
156
157endif # neq($(KERNELRELEASE),)
158
159# debug - show guesses.
160ifdef DEBUG
161$(warning dbg: KERN_DIR = $(KERN_DIR))
162$(warning dbg: KERN_INCL = $(KERN_INCL))
163$(warning dbg: MODULE_DIR = $(MODULE_DIR))
164$(warning dbg: KERN_VERSION = $(KERN_VERSION))
165endif
166
167KBUILD_VERBOSE ?= 1
168
169#
170# Compiler options
171#
172ifndef INCL
173 INCL := $(addprefix -I,$(KERN_INCL) $(EXTRA_INCL))
174 ifndef KBUILD_EXTMOD
175 KBUILD_EXTMOD := $(shell pwd)
176 endif
177 INCL += $(addprefix -I$(KBUILD_EXTMOD),/ /include /r0drv/linux)
178 export INCL
179endif
180KFLAGS := -D__KERNEL__ -DMODULE -DRT_OS_LINUX -DIN_RING0 -DIN_RT_R0 \
181 -DIN_SUP_R0 -DVBOX -DVBOX_WITH_HGCM -DLOG_TO_BACKDOOR -DIN_MODULE \
182 -DIN_GUEST_R0
183ifeq ($(BUILD_TARGET_ARCH),amd64)
184 KFLAGS += -DRT_ARCH_AMD64 -DVBOX_WITH_64_BITS_GUESTS
185else
186 KFLAGS += -DRT_ARCH_X86
187endif
188ifeq ($(BUILD_TYPE),debug)
189KFLAGS += -DDEBUG
190endif
191
192ifeq ($(KERN_VERSION), 24)
193#
194# 2.4
195#
196
197CFLAGS := -O2 -DVBOX_LINUX_2_4 $(INCL) $(KFLAGS) $(KDEBUG)
198MODULE_EXT := o
199
200# 2.4 Module linking
201$(MODULE).o: $(OBJS)
202 $(LD) -o $@ -r $(OBJS)
203
204.PHONY: $(MODULE)
205all: $(MODULE)
206$(MODULE): $(MODULE).o
207
208else
209#
210# 2.6 and later
211#
212
213MODULE_EXT := ko
214
215$(MODULE)-y := $(OBJS)
216
217# special hack for Fedora Core 6 2.6.18 (fc6), rhel5 2.6.18 (el5),
218# ClarkConnect 4.3 (cc4) and ClarkConnect 5 (v5)
219ifeq ($(KERNELRELEASE),)
220 KFLAGS += $(foreach inc,$(KERN_INCL),\
221 $(if $(wildcard $(inc)/linux/utsrelease.h),\
222 $(if $(shell grep '"2.6.18.*fc6.*"' $(inc)/linux/utsrelease.h; \
223 grep '"2.6.18.*el5.*"' $(inc)/linux/utsrelease.h; \
224 grep '"2.6.18.*v5.*"' $(inc)/linux/utsrelease.h; \
225 grep '"2.6.18.*cc4.*"' $(inc)/linux/utsrelease.h),\
226 -DKERNEL_FC6,),))
227else
228 KFLAGS += $(if $(shell echo "$(KERNELRELEASE)"|grep '2.6.18.*fc6.*';\
229 echo "$(KERNELRELEASE)"|grep '2.6.18.*el5.*';\
230 echo "$(KERNELRELEASE)"|grep '2.6.18.*v5.*';\
231 echo "$(KERNELRELEASE)"|grep '2.6.18.*cc4.*'),\
232 -DKERNEL_FC6,)
233endif
234
235# build defs
236EXTRA_CFLAGS += $(INCL) $(KFLAGS) $(KDEBUG)
237
238all: $(MODULE)
239
240obj-m += $(MODULE).o
241
242$(MODULE):
243 $(MAKE) KBUILD_VERBOSE=$(KBUILD_VERBOSE) -C $(KERN_DIR) SUBDIRS=$(CURDIR) SRCROOT=$(CURDIR) modules
244
245endif
246
247install: $(MODULE)
248 @mkdir -p $(MODULE_DIR); \
249 install -m 0664 -o root -g root $(MODULE).$(MODULE_EXT) $(MODULE_DIR); \
250 PATH="$(PATH):/bin:/sbin" depmod -ae;
251
252endif # eq($(MAKECMDGOALS),clean)
253
254# important: Don't remove Module.symvers! DKMS does 'make clean' before building ...
255clean:
256 for f in . linux r0drv r0drv/linux; do rm -f $$f/*.o $$f/.*.cmd $$f/.*.flags; done
257 rm -rf .vboxvfs* .tmp_ver* vboxvfs.* Modules.symvers modules.order
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette