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