VirtualBox

source: vbox/trunk/src/VBox/Additions/linux/installer/Makefile.include.footer@ 36462

Last change on this file since 36462 was 36462, checked in by vboxsync, 14 years ago

Additions/linux: update kernel module makefile split header and footer in preparation for using them with vboxguest.ko

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 6.3 KB
Line 
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
61override MODULE = $(MOD_NAME)
62OBJS = $(MOD_OBJS)
63
64ifneq ($(MAKECMDGOALS),clean)
65
66ifeq ($(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
119else # 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
133endif # neq($(KERNELRELEASE),)
134
135# debug - show guesses.
136ifdef 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))
141endif
142
143KBUILD_VERBOSE ?= 1
144
145#
146# Compiler options
147#
148ifndef 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
155endif
156KFLAGS := -D__KERNEL__ -DMODULE \
157 -DVBOX -DRT_OS_LINUX -DIN_RING0 -DIN_RT_R0 -DIN_MODULE \
158 -DRT_WITH_VBOX $(MOD_DEFS)
159ifeq ($(BUILD_TARGET_ARCH),amd64)
160 KFLAGS += -DRT_ARCH_AMD64 -DVBOX_WITH_64_BITS_GUESTS
161else
162 KFLAGS += -DRT_ARCH_X86
163endif
164ifeq ($(BUILD_TYPE),debug)
165KFLAGS += -DDEBUG
166endif
167
168ifeq ($(KERN_VERSION), 24)
169#
170# 2.4
171#
172
173ifeq ($(BUILD_TARGET_ARCH),amd64)
174 KFLAGS += -mcmodel=kernel
175endif
176
177CFLAGS := -O2 -DVBOX_LINUX_2_4 -DEXPORT_SYMTAB $(INCL) $(KFLAGS) $(KDEBUG) \
178 $(MOD_CFLAGS)
179MODULE_EXT := o
180
181# 2.4 Module linking
182$(MODULE).o: $(OBJS)
183 $(LD) -o $@ -r $(OBJS)
184
185.PHONY: $(MODULE)
186all: $(MODULE)
187$(MODULE): $(MODULE).o
188
189else
190#
191# 2.6 and later
192#
193
194MODULE_EXT := ko
195
196$(MODULE)-y := $(OBJS)
197
198# build defs
199EXTRA_CFLAGS += $(INCL) $(KFLAGS) $(KDEBUG) $(MOD_CFLAGS)
200
201all: $(MODULE)
202
203obj-m += $(MODULE).o
204
205$(MODULE):
206 $(MAKE) KBUILD_VERBOSE=$(KBUILD_VERBOSE) -C $(KERN_DIR) SUBDIRS=$(CURDIR) SRCROOT=$(CURDIR) modules
207
208endif
209
210install: $(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
215endif # eq($(MAKECMDGOALS),clean)
216
217clean:
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
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