1 | #
|
---|
2 | # VirtualBox Guest Additions kernel module Makefile, common parts.
|
---|
3 | #
|
---|
4 | # (For 2.6.x, the main file must be called '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 | # These file should be included by the Makefiles for any kernel modules we
|
---|
23 | # build as part of the Guest Additions. The intended way of doing this is as
|
---|
24 | # follows:
|
---|
25 | #
|
---|
26 | # include Makefile.include
|
---|
27 | # MOD_NAME = <name of the module to be built, without extension>
|
---|
28 | # MOD_OBJS = <list of object files which should be included>
|
---|
29 | # MOD_FLAGS = <any additional CFLAGS which this module needs>
|
---|
30 | #
|
---|
31 | # The kmk kBuild define KBUILD_TARGET_ARCH is available.
|
---|
32 | #
|
---|
33 | # @todo the shared folders module Makefile also includes the following bits.
|
---|
34 | # Integrate them if necessary.
|
---|
35 | # MOD_FLAGS += -DEXPORT_SYMTAB -DVBGL_VBOXGUEST -DRT_WITH_VBOX
|
---|
36 | #
|
---|
37 | # # special hack for Fedora Core 6 2.6.18 (fc6), rhel5 2.6.18 (el5),
|
---|
38 | # # ClarkConnect 4.3 (cc4) and ClarkConnect 5 (v5)
|
---|
39 | # ifeq ($(KERNELRELEASE),)
|
---|
40 | # KFLAGS += $(foreach inc,$(KERN_INCL),\
|
---|
41 | # $(if $(wildcard $(inc)/linux/utsrelease.h),\
|
---|
42 | # $(if $(shell grep '"2.6.18.*fc6.*"' $(inc)/linux/utsrelease.h; \
|
---|
43 | # grep '"2.6.18.*el5.*"' $(inc)/linux/utsrelease.h; \
|
---|
44 | # grep '"2.6.18.*v5.*"' $(inc)/linux/utsrelease.h; \
|
---|
45 | # grep '"2.6.18.*cc4.*"' $(inc)/linux/utsrelease.h),\
|
---|
46 | # -DKERNEL_FC6,),))
|
---|
47 | # else
|
---|
48 | # KFLAGS += $(if $(shell echo "$(KERNELRELEASE)"|grep '2.6.18.*fc6.*';\
|
---|
49 | # echo "$(KERNELRELEASE)"|grep '2.6.18.*el5.*';\
|
---|
50 | # echo "$(KERNELRELEASE)"|grep '2.6.18.*v5.*';\
|
---|
51 | # echo "$(KERNELRELEASE)"|grep '2.6.18.*cc4.*'),\
|
---|
52 | # -DKERNEL_FC6,)
|
---|
53 | # endif
|
---|
54 | #
|
---|
55 | ## important: Don't remove Module.symvers! DKMS does 'make clean' before building ...
|
---|
56 | # rm -rf .vboxvfs* .tmp_ver* vboxvfs.* Modules.symvers modules.order
|
---|
57 | #
|
---|
58 |
|
---|
59 |
|
---|
60 |
|
---|
61 | # override is required by the Debian guys
|
---|
62 | override MODULE = $(MOD_NAME)
|
---|
63 | OBJS = $(MOD_OBJS)
|
---|
64 |
|
---|
65 | ifneq ($(MAKECMDGOALS),clean)
|
---|
66 |
|
---|
67 | ifeq ($(KERNELRELEASE),)
|
---|
68 |
|
---|
69 | #
|
---|
70 | # building from this directory
|
---|
71 | #
|
---|
72 |
|
---|
73 | # kernel base directory
|
---|
74 | ifndef KERN_DIR
|
---|
75 | KERN_DIR := /lib/modules/$(shell uname -r)/build
|
---|
76 | ifneq ($(shell if test -d $(KERN_DIR); then echo yes; fi),yes)
|
---|
77 | KERN_DIR := /usr/src/linux
|
---|
78 | ifneq ($(shell if test -d $(KERN_DIR); then echo yes; fi),yes)
|
---|
79 | $(error Error: unable to find the sources of your current Linux kernel. \
|
---|
80 | Specify KERN_DIR=<directory> and run Make again)
|
---|
81 | endif
|
---|
82 | $(warning Warning: using /usr/src/linux as the source directory of your \
|
---|
83 | Linux kernel. If this is not correct, specify \
|
---|
84 | KERN_DIR=<directory> and run Make again.)
|
---|
85 | endif
|
---|
86 | else
|
---|
87 | ifneq ($(shell if test -d $(KERN_DIR); then echo yes; fi),yes)
|
---|
88 | $(error Error: KERN_DIR does not point to a directory)
|
---|
89 | endif
|
---|
90 | endif
|
---|
91 |
|
---|
92 | # includes
|
---|
93 | ifndef KERN_INCL
|
---|
94 | KERN_INCL = $(KERN_DIR)/include
|
---|
95 | endif
|
---|
96 | ifneq ($(shell if test -d $(KERN_INCL); then echo yes; fi),yes)
|
---|
97 | $(error Error: unable to find the include directory for your current Linux \
|
---|
98 | kernel. Specify KERN_INCL=<directory> and run Make again)
|
---|
99 | endif
|
---|
100 |
|
---|
101 | # module install dir, only for current kernel
|
---|
102 | ifneq ($(filter install install_rpm,$(MAKECMDGOALS)),)
|
---|
103 | ifndef MODULE_DIR
|
---|
104 | MODULE_DIR_TST := /lib/modules/$(shell uname -r)
|
---|
105 | ifeq ($(shell if test -d $(MODULE_DIR_TST); then echo yes; fi),yes)
|
---|
106 | MODULE_DIR := $(MODULE_DIR_TST)/misc
|
---|
107 | else
|
---|
108 | $(error Unable to find the folder to install the driver ($(MOD_NAME)) to)
|
---|
109 | endif
|
---|
110 | endif # MODULE_DIR unspecified
|
---|
111 | endif
|
---|
112 |
|
---|
113 | # guess kernel version (24 or 26)
|
---|
114 | ifeq ($(shell if grep '"2\.4\.' $(KERN_INCL)/linux/version.h > /dev/null; then echo yes; fi),yes)
|
---|
115 | KERN_VERSION := 24
|
---|
116 | else
|
---|
117 | KERN_VERSION := 26
|
---|
118 | endif
|
---|
119 |
|
---|
120 | else # neq($(KERNELRELEASE),)
|
---|
121 |
|
---|
122 | #
|
---|
123 | # building from kbuild (make -C <kernel_directory> M=`pwd`)
|
---|
124 | #
|
---|
125 |
|
---|
126 | # guess kernel version (24 or 26)
|
---|
127 | ifeq ($(shell if echo "$(VERSION).$(PATCHLEVEL)." | grep '2\.4\.' > /dev/null; then echo yes; fi),yes)
|
---|
128 | KERN_VERSION := 24
|
---|
129 | else
|
---|
130 | KERN_VERSION := 26
|
---|
131 | endif
|
---|
132 |
|
---|
133 | endif # neq($(KERNELRELEASE),)
|
---|
134 |
|
---|
135 | # debug - show guesses.
|
---|
136 | ifdef DEBUG
|
---|
137 | $(warning dbg: KERN_DIR = $(KERN_DIR))
|
---|
138 | $(warning dbg: KERN_INCL = $(KERN_INCL))
|
---|
139 | $(warning dbg: MODULE_DIR = $(MODULE_DIR))
|
---|
140 | $(warning dbg: KERN_VERSION = $(KERN_VERSION))
|
---|
141 | endif
|
---|
142 |
|
---|
143 | KBUILD_VERBOSE ?= 1
|
---|
144 |
|
---|
145 | #
|
---|
146 | # Compiler options
|
---|
147 | #
|
---|
148 | ifndef INCL
|
---|
149 | INCL := $(addprefix -I,$(KERN_INCL) $(EXTRA_INCL))
|
---|
150 | ifndef KBUILD_EXTMOD
|
---|
151 | KBUILD_EXTMOD := $(shell pwd)
|
---|
152 | endif
|
---|
153 | INCL += $(addprefix -I$(KBUILD_EXTMOD),/ /include /r0drv/linux)
|
---|
154 | export INCL
|
---|
155 | endif
|
---|
156 | KFLAGS := -D__KERNEL__ -DMODULE -DRT_OS_LINUX -DIN_RING0 \
|
---|
157 | -DIN_RT_R0 -DIN_SUP_R0 -DVBOX -DVBGL_VBOXGUEST -DVBOX_WITH_HGCM \
|
---|
158 | -DLOG_TO_BACKDOOR -DRT_WITH_VBOX -DIN_MODULE -DIN_GUEST_R0
|
---|
159 | ifeq ($(BUILD_TARGET_ARCH),amd64)
|
---|
160 | KFLAGS += -DRT_ARCH_AMD64 -DVBOX_WITH_64_BITS_GUESTS
|
---|
161 | else
|
---|
162 | KFLAGS += -DRT_ARCH_X86
|
---|
163 | endif
|
---|
164 | ifeq ($(BUILD_TYPE),debug)
|
---|
165 | KFLAGS += -DDEBUG
|
---|
166 | endif
|
---|
167 |
|
---|
168 | ifeq ($(KERN_VERSION), 24)
|
---|
169 | #
|
---|
170 | # 2.4
|
---|
171 | #
|
---|
172 |
|
---|
173 | CFLAGS := -O2 -DVBOX_LINUX_2_4 -DEXPORT_SYMTAB $(INCL) $(KFLAGS) $(KDEBUG)
|
---|
174 | MODULE_EXT := o
|
---|
175 |
|
---|
176 | # 2.4 Module linking
|
---|
177 | $(MODULE).o: $(OBJS)
|
---|
178 | $(LD) -o $@ -r $(OBJS)
|
---|
179 |
|
---|
180 | .PHONY: $(MODULE)
|
---|
181 | all: $(MODULE)
|
---|
182 | $(MODULE): $(MODULE).o
|
---|
183 |
|
---|
184 | else
|
---|
185 | #
|
---|
186 | # 2.6 and later
|
---|
187 | #
|
---|
188 |
|
---|
189 | MODULE_EXT := ko
|
---|
190 |
|
---|
191 | $(MODULE)-y := $(OBJS)
|
---|
192 |
|
---|
193 | # build defs
|
---|
194 | EXTRA_CFLAGS += $(INCL) $(KFLAGS) $(KDEBUG)
|
---|
195 |
|
---|
196 | all: $(MODULE)
|
---|
197 |
|
---|
198 | obj-m += $(MODULE).o
|
---|
199 |
|
---|
200 | $(MODULE):
|
---|
201 | $(MAKE) KBUILD_VERBOSE=$(KBUILD_VERBOSE) -C $(KERN_DIR) SUBDIRS=$(CURDIR) SRCROOT=$(CURDIR) modules
|
---|
202 |
|
---|
203 | endif
|
---|
204 |
|
---|
205 | install: $(MODULE)
|
---|
206 | @mkdir -p $(MODULE_DIR); \
|
---|
207 | install -m 0664 -o root -g root $(MODULE).$(MODULE_EXT) $(MODULE_DIR); \
|
---|
208 | PATH="$(PATH):/bin:/sbin" depmod -ae;
|
---|
209 |
|
---|
210 | endif # eq($(MAKECMDGOALS),clean)
|
---|
211 |
|
---|
212 | clean:
|
---|
213 | for f in . linux r0drv r0drv/linux; do rm -f $$f/*.o $$f/.*.cmd $$f/.*.flags; done
|
---|
214 | rm -rf .$(MOD_NAME)* .tmp_ver* $(MOD_NAME).* Module.symvers Modules.symvers modules.order
|
---|