VirtualBox

source: vbox/trunk/src/VBox/HostDrivers/Support/linux/Makefile@ 6571

最後變更 在這個檔案從6571是 6571,由 vboxsync 提交於 17 年 前

Linux kernel modules: allow to build from kBuild (KERNELRELEASE set), cosmetical fixes

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Author Date Id Revision
檔案大小: 7.5 KB
 
1#
2# Makefile for the VirtualBox Linux Host Driver.
3# (For 2.6.x this file must be called 'Makefile'!)
4#
5
6#
7#
8# Copyright (C) 2006-2007 innotek GmbH
9#
10# This file is part of VirtualBox Open Source Edition (OSE), as
11# available from http://www.alldomusa.eu.org. This file is free software;
12# you can redistribute it and/or modify it under the terms of the GNU
13# General Public License (GPL) as published by the Free Software
14# Foundation, in version 2 as it comes in the "COPYING" file of the
15# VirtualBox OSE distribution. VirtualBox OSE is distributed in the
16# hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
17#
18# The contents of this file may alternatively be used under the terms
19# of the Common Development and Distribution License Version 1.0
20# (CDDL) only, as it comes in the "COPYING.CDDL" file of the
21# VirtualBox OSE distribution, in which case the provisions of the
22# CDDL are applicable instead of those of the GPL.
23#
24# You may elect to license modified versions of this file under the
25# terms and conditions of either the GPL or the CDDL or both.
26#
27
28#
29# First, figure out which architecture we're targeting and the build type.
30# (We have to support basic cross building (ARCH=i386|x86_64).)
31# While at it, warn about BUILD_* vars found to help with user problems.
32#
33ifneq ($(filter-out amd64 x86,$(BUILD_TARGET_ARCH)),)
34 $(warning Ignoring unknown BUILD_TARGET_ARCH value '$(BUILD_TARGET_ARCH)'.)
35 BUILD_TARGET_ARCH :=
36endif
37ifeq ($(BUILD_TARGET_ARCH),)
38 ifeq ($(ARCH),x86_64)
39 BUILD_TARGET_ARCH := amd64
40 else
41 ifeq ($(ARCH),i386)
42 BUILD_TARGET_ARCH := x86
43 else
44 ifeq ($(filter-out x86_64 amd64 AMD64,$(shell uname -m)),)
45 BUILD_TARGET_ARCH := amd64
46 else
47 BUILD_TARGET_ARCH := x86
48 endif
49 endif
50 endif
51else
52 $(warning Using BUILD_TARGET_ARCH='$(BUILD_TARGET_ARCH)' from the $(origin BUILD_TARGET_ARCH).)
53endif
54
55ifneq ($(filter-out release profile debug strict,$(BUILD_TYPE)),)
56 $(warning Ignoring unknown BUILD_TYPE value '$(BUILD_TYPE)'.)
57 BUILD_TYPE :=
58endif
59ifeq ($(BUILD_TYPE),)
60 BUILD_TYPE := release
61else
62 $(warning Using BUILD_TYPE='$(BUILD_TYPE)' from the $(origin BUILD_TYPE).)
63endif
64
65
66MODULE = vboxdrv
67OBJS = \
68 linux/SUPDrv-linux.o \
69 SUPDRVShared.o \
70 r0drv/alloc-r0drv.o \
71 r0drv/initterm-r0drv.o \
72 r0drv/linux/alloc-r0drv-linux.o \
73 r0drv/linux/initterm-r0drv-linux.o \
74 r0drv/linux/process-r0drv-linux.o \
75 r0drv/linux/semevent-r0drv-linux.o \
76 r0drv/linux/semeventmulti-r0drv-linux.o \
77 r0drv/linux/semfastmutex-r0drv-linux.o \
78 r0drv/linux/spinlock-r0drv-linux.o \
79 r0drv/linux/thread-r0drv-linux.o
80ifeq ($(BUILD_TARGET_ARCH),amd64)
81OBJS += alloc/heapsimple.o
82endif
83ifeq ($(BUILD_TYPE),debug)
84OBJS += \
85 math/gcc/divdi3.o \
86 math/gcc/moddi3.o \
87 math/gcc/udivdi3.o \
88 math/gcc/umoddi3.o \
89 math/gcc/qdivrem.o \
90 common/log/log.o \
91 common/log/logcom.o \
92 common/log/logformat.o \
93 common/string/strformat.o \
94 common/string/strformatrt.o \
95 common/string/strprintf.o \
96 common/string/strtonum.o \
97 r0drv/linux/RTLogWriteDebugger-r0drv-linux.o \
98 generic/RTLogWriteStdErr-stub-generic.o \
99 generic/RTLogWriteStdOut-stub-generic.o \
100 generic/RTLogWriteUser-generic.o \
101 VBox/log-vbox.o \
102 VBox/strformat-vbox.o
103endif
104
105ifneq ($(MAKECMDGOALS),clean)
106
107ifeq ($(KERNELRELEASE),)
108
109 #
110 # building from this directory
111 #
112
113 # kernel base directory
114 ifndef KERN_DIR
115 # build for the current kernel, version check
116 KERN_DIR := /lib/modules/$(shell uname -r)/build
117 ifneq ($(shell if test -d $(KERN_DIR); then echo yes; fi),yes)
118 KERN_DIR := /usr/src/linux
119 ifneq ($(shell if test -d $(KERN_DIR); then echo yes; fi),yes)
120 $(error Error: unable to find the sources of your current Linux kernel. \
121 Specify KERN_DIR=<directory> and run Make again)
122 endif
123 $(warning Warning: using /usr/src/linux as the source directory of your \
124 Linux kernel. If this is not correct, specify \
125 KERN_DIR=<directory> and run Make again.)
126 endif
127 # check if versions match -- works only for later 2.6 kernels
128 VBOX_KERN_VER := $(shell $(MAKE) -sC $(KERN_DIR) kernelrelease 2> /dev/null || true)
129 ifneq ($(VBOX_KERN_VER),)
130 ifneq ($(VBOX_KERN_VER),$(shell uname -r))
131 $(error Error: /usr/src/linux (version $(VBOX_KERN_VER)) does not match \
132 the current kernel (version $(shell uname -r)))
133 endif
134 endif
135 else
136 # build for a dedicated kernel, no version check
137 ifneq ($(shell if test -d $(KERN_DIR); then echo yes; fi),yes)
138 $(error Error: KERN_DIR does not point to a directory)
139 endif
140 endif
141
142 # includes
143 ifndef KERN_INCL
144 KERN_INCL = $(KERN_DIR)/include
145 endif
146 ifneq ($(shell if test -d $(KERN_INCL); then echo yes; fi),yes)
147 $(error Error: unable to find the include directory for your current Linux \
148 kernel. Specify KERN_INCL=<directory> and run Make again)
149 endif
150
151 # module install dir, only for current kernel
152 ifneq ($(filter install install_rpm,$(MAKECMDGOALS)),)
153 ifndef MODULE_DIR
154 MODULE_DIR_TST := /lib/modules/$(shell uname -r)
155 ifeq ($(shell if test -d $(MODULE_DIR_TST); then echo yes; fi),yes)
156 MODULE_DIR := $(MODULE_DIR_TST)/misc
157 else
158 $(error Unable to find the folder to install the support driver to)
159 endif
160 endif # MODULE_DIR unspecified
161 endif
162
163 # guess kernel version (24 or 26)
164 KERN_VERSION := $(if $(wildcard $(KERN_DIR)/Rules.make),24,26)
165
166else # neq($(KERNELRELEASE),)
167
168 #
169 # building from Linux-2.6-kbuild (make -C <kernel_directory> M=`pwd`)
170 #
171
172 KERN_VERSION := 26
173
174endif # neq($(KERNELRELEASE),)
175
176# debug - show guesses.
177ifdef DEBUG
178$(warning dbg: KERN_DIR = $(KERN_DIR))
179$(warning dbg: KERN_INCL = $(KERN_INCL))
180$(warning dbg: MODULE_DIR = $(MODULE_DIR))
181$(warning dbg: KERN_VERSION = $(KERN_VERSION))
182endif
183
184#
185# Compiler options
186#
187ifndef INCL
188 INCL := $(addprefix -I,$(KERN_INCL) $(EXTRA_INCL))
189 ifndef KBUILD_EXTMOD
190 KBUILD_EXTMOD := $(shell pwd)
191 endif
192 INCL += $(addprefix -I$(KBUILD_EXTMOD),/ /include /r0drv/linux)
193 export INCL
194endif
195KFLAGS := -D__KERNEL__ -DMODULE -DRT_OS_LINUX -DIN_RING0 -DIN_RT_R0 -DIN_SUP_R0 -DVBOX -DRT_WITH_VBOX
196ifndef CONFIG_VBOXDRV_FIXEDMAJOR
197 KFLAGS += -DCONFIG_VBOXDRV_AS_MISC
198endif
199ifeq ($(BUILD_TARGET_ARCH),amd64)
200 KFLAGS += -DRT_ARCH_AMD64
201else
202 KFLAGS += -DRT_ARCH_X86
203endif
204ifeq ($(BUILD_TYPE),debug)
205 KFLAGS += -DDEBUG -DDEBUG_$(USER)
206endif
207
208#
209# Use the RTR0MemObj API - testing.
210# If this makes testboxes crash/burn/leak disable it and add a comment to defect #2116.
211#
212KFLAGS += -DUSE_NEW_OS_INTERFACE_FOR_MM
213OBJS += r0drv/memobj-r0drv.o \
214 r0drv/linux/memobj-r0drv-linux.o
215ifeq ($(BUILD_TARGET_ARCH),x86) # Some gcc versions ends up needing __divdi3.
216OBJS += math/gcc/qdivrem.o \
217 math/gcc/divdi3.o
218endif
219
220ifeq ($(KERN_VERSION), 24)
221# 2.4
222TOPDIR = $(KERN_DIR)
223MODULE_EXT := o
224EXTRA_CFLAGS := -DVBOX_LINUX_2_4
225$(MODULE)-objs = $(OBJS)
226else
227# 2.6 and later
228MODULE_EXT := ko
229$(MODULE)-y := $(OBJS)
230endif
231
232# build defs
233EXTRA_CFLAGS += $(INCL) $(KFLAGS) $(KDEBUG)
234
235all: $(MODULE)
236
237obj-m += $(MODULE).o
238
239$(MODULE):
240 $(MAKE) KBUILD_VERBOSE=1 -C $(KERN_DIR) SUBDIRS=$(CURDIR) SRCROOT=$(CURDIR) modules
241
242ifeq ($(KERN_VERSION), 24)
243#
244# 2.4 Module linking
245#
246$(MODULE).o: $(OBJS)
247 $(LD) -o $@ -r $(OBJS)
248
249include $(KERN_DIR)/Rules.make
250
251endif
252
253install: $(MODULE)
254 @mkdir -p $(MODULE_DIR); \
255 install -m 0664 -o root -g root $(MODULE).$(MODULE_EXT) $(MODULE_DIR); \
256 PATH="$(PATH):/bin:/sbin" depmod -ae; \
257 rm -f /etc/vbox/module_not_compiled
258
259install_rpm: $(MODULE)
260 @mkdir -p $(MODULE_DIR); \
261 install -m 0664 $(MODULE).$(MODULE_EXT) $(MODULE_DIR)
262
263endif # eq($(MAKECMDGOALS),clean)
264
265clean:
266 for f in . linux r0drv r0drv/linux; do rm -f $$f/*.o $$f/.*.cmd $$f/.*.flags; done
267 rm -rf .vboxdrv* .tmp_ver* vboxdrv.* Module.symvers Modules.symvers
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

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