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.alldomusa.eu.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 | # # Linux kbuild sets this to our source directory if we are called from
|
---|
23 | # # there
|
---|
24 | # obj ?= $(CURDIR)
|
---|
25 | # include $(obj)/Makefile.include.header
|
---|
26 | # MOD_NAME = <name of the module to be built, without extension>
|
---|
27 | # MOD_OBJS = <list of object files which should be included>
|
---|
28 | # MOD_DEFS = <any additional defines which this module needs>
|
---|
29 | # MOD_INCL = <any additional include paths which this module needs>
|
---|
30 | # MOD_CFLAGS = <any additional CFLAGS which this module needs>
|
---|
31 | # MOD_CLEAN = <list of directories that the clean target should look at>
|
---|
32 | # include $(obj)/Makefile.include.footer
|
---|
33 | #
|
---|
34 | # The kmk kBuild define KBUILD_TARGET_ARCH is available.
|
---|
35 | #
|
---|
36 | # @todo the shared folders module Makefile also includes the following bits.
|
---|
37 | # Integrate them if necessary.
|
---|
38 | # MOD_CFLAGS += -DEXPORT_SYMTAB -DVBGL_VBOXGUEST -DRT_WITH_VBOX
|
---|
39 | #
|
---|
40 | # # special hack for Fedora Core 6 2.6.18 (fc6), rhel5 2.6.18 (el5),
|
---|
41 | # # ClarkConnect 4.3 (cc4) and ClarkConnect 5 (v5)
|
---|
42 | # ifeq ($(KERNELRELEASE),)
|
---|
43 | # KFLAGS += $(foreach inc,$(KERN_INCL),\
|
---|
44 | # $(if $(wildcard $(inc)/linux/utsrelease.h),\
|
---|
45 | # $(if $(shell grep '"2.6.18.*fc6.*"' $(inc)/linux/utsrelease.h; \
|
---|
46 | # grep '"2.6.18.*el5.*"' $(inc)/linux/utsrelease.h; \
|
---|
47 | # grep '"2.6.18.*v5.*"' $(inc)/linux/utsrelease.h; \
|
---|
48 | # grep '"2.6.18.*cc4.*"' $(inc)/linux/utsrelease.h),\
|
---|
49 | # -DKERNEL_FC6,),))
|
---|
50 | # else
|
---|
51 | # KFLAGS += $(if $(shell echo "$(KERNELRELEASE)"|grep '2.6.18.*fc6.*';\
|
---|
52 | # echo "$(KERNELRELEASE)"|grep '2.6.18.*el5.*';\
|
---|
53 | # echo "$(KERNELRELEASE)"|grep '2.6.18.*v5.*';\
|
---|
54 | # echo "$(KERNELRELEASE)"|grep '2.6.18.*cc4.*'),\
|
---|
55 | # -DKERNEL_FC6,)
|
---|
56 | # endif
|
---|
57 | #
|
---|
58 | ## important: Don't remove Module.symvers! DKMS does 'make clean' before building ...
|
---|
59 | # rm -rf .vboxsf* .tmp_ver* vboxsf.* Modules.symvers modules.order
|
---|
60 | #
|
---|
61 |
|
---|
62 | #
|
---|
63 | # First, figure out which architecture we're targeting and the build type.
|
---|
64 | # (We have to support basic cross building (ARCH=i386|x86_64).)
|
---|
65 | # While at it, warn about BUILD_* vars found to help with user problems.
|
---|
66 | #
|
---|
67 | ifeq ($(filter-out x86_64 amd64 AMD64,$(shell uname -m)),)
|
---|
68 | BUILD_TARGET_ARCH_DEF := amd64
|
---|
69 | else
|
---|
70 | BUILD_TARGET_ARCH_DEF := x86
|
---|
71 | endif
|
---|
72 | ifneq ($(filter-out amd64 x86,$(BUILD_TARGET_ARCH)),)
|
---|
73 | $(warning Ignoring unknown BUILD_TARGET_ARCH value '$(BUILD_TARGET_ARCH)'.)
|
---|
74 | BUILD_TARGET_ARCH :=
|
---|
75 | endif
|
---|
76 | ifeq ($(BUILD_TARGET_ARCH),)
|
---|
77 | ifeq ($(ARCH),x86_64)
|
---|
78 | BUILD_TARGET_ARCH := amd64
|
---|
79 | else
|
---|
80 | ifeq ($(ARCH),i386)
|
---|
81 | BUILD_TARGET_ARCH := x86
|
---|
82 | else
|
---|
83 | BUILD_TARGET_ARCH := $(BUILD_TARGET_ARCH_DEF)
|
---|
84 | endif
|
---|
85 | endif
|
---|
86 | else
|
---|
87 | ifneq ($(BUILD_TARGET_ARCH),$(BUILD_TARGET_ARCH_DEF))
|
---|
88 | $(warning Using BUILD_TARGET_ARCH='$(BUILD_TARGET_ARCH)' from the $(origin BUILD_TARGET_ARCH).)
|
---|
89 | endif
|
---|
90 | endif
|
---|
91 |
|
---|
92 | ifneq ($(filter-out release profile debug strict,$(BUILD_TYPE)),)
|
---|
93 | $(warning Ignoring unknown BUILD_TYPE value '$(BUILD_TYPE)'.)
|
---|
94 | BUILD_TYPE :=
|
---|
95 | endif
|
---|
96 | ifeq ($(BUILD_TYPE),)
|
---|
97 | BUILD_TYPE := release
|
---|
98 | else
|
---|
99 | ifneq ($(BUILD_TYPE),release)
|
---|
100 | $(warning Using BUILD_TYPE='$(BUILD_TYPE)' from the $(origin BUILD_TYPE).)
|
---|
101 | endif
|
---|
102 | endif
|
---|
103 |
|
---|
104 | ifneq ($(MAKECMDGOALS),clean)
|
---|
105 |
|
---|
106 | ifeq ($(KERNELRELEASE),)
|
---|
107 |
|
---|
108 | #
|
---|
109 | # building from this directory
|
---|
110 | #
|
---|
111 |
|
---|
112 | # kernel base directory
|
---|
113 | ifndef KERN_DIR
|
---|
114 | KERN_DIR := /lib/modules/$(shell uname -r)/build
|
---|
115 | ifneq ($(shell if test -d $(KERN_DIR); then echo yes; fi),yes)
|
---|
116 | KERN_DIR := /usr/src/linux
|
---|
117 | ifneq ($(shell if test -d $(KERN_DIR); then echo yes; fi),yes)
|
---|
118 | $(error Error: unable to find the sources of your current Linux kernel. \
|
---|
119 | Specify KERN_DIR=<directory> and run Make again)
|
---|
120 | endif
|
---|
121 | $(warning Warning: using /usr/src/linux as the source directory of your \
|
---|
122 | Linux kernel. If this is not correct, specify \
|
---|
123 | KERN_DIR=<directory> and run Make again.)
|
---|
124 | endif
|
---|
125 | else
|
---|
126 | ifneq ($(shell if test -d $(KERN_DIR); then echo yes; fi),yes)
|
---|
127 | $(error Error: KERN_DIR does not point to a directory)
|
---|
128 | endif
|
---|
129 | endif
|
---|
130 |
|
---|
131 | # includes
|
---|
132 | ifndef KERN_INCL
|
---|
133 | KERN_INCL = $(KERN_DIR)/include
|
---|
134 | endif
|
---|
135 | ifneq ($(shell if test -d $(KERN_INCL); then echo yes; fi),yes)
|
---|
136 | $(error Error: unable to find the include directory for your current Linux \
|
---|
137 | kernel. Specify KERN_INCL=<directory> and run Make again)
|
---|
138 | endif
|
---|
139 |
|
---|
140 | # module install dir, only for current kernel
|
---|
141 | ifneq ($(filter install install_rpm,$(MAKECMDGOALS)),)
|
---|
142 | ifndef MODULE_DIR
|
---|
143 | MODULE_DIR_TST := /lib/modules/$(shell uname -r)
|
---|
144 | ifeq ($(shell if test -d $(MODULE_DIR_TST); then echo yes; fi),yes)
|
---|
145 | MODULE_DIR := $(MODULE_DIR_TST)/misc
|
---|
146 | else
|
---|
147 | $(error Unable to find the folder to install the module to)
|
---|
148 | endif
|
---|
149 | endif # MODULE_DIR unspecified
|
---|
150 | endif
|
---|
151 |
|
---|
152 | # guess kernel version (24 or 26)
|
---|
153 | ifeq ($(shell if grep '"2\.4\.' $(KERN_INCL)/linux/version.h > /dev/null; then echo yes; fi),yes)
|
---|
154 | KERN_VERSION := 24
|
---|
155 | else
|
---|
156 | KERN_VERSION := 26
|
---|
157 | endif
|
---|
158 |
|
---|
159 | else # neq($(KERNELRELEASE),)
|
---|
160 |
|
---|
161 | #
|
---|
162 | # building from kbuild (make -C <kernel_directory> M=`pwd`)
|
---|
163 | #
|
---|
164 |
|
---|
165 | # guess kernel version (24 or 26)
|
---|
166 | ifeq ($(shell if echo "$(VERSION).$(PATCHLEVEL)." | grep '2\.4\.' > /dev/null; then echo yes; fi),yes)
|
---|
167 | KERN_VERSION := 24
|
---|
168 | else
|
---|
169 | KERN_VERSION := 26
|
---|
170 | endif
|
---|
171 |
|
---|
172 | endif # neq($(KERNELRELEASE),)
|
---|
173 |
|
---|
174 | # debug - show guesses.
|
---|
175 | ifdef DEBUG
|
---|
176 | $(warning dbg: KERN_DIR = $(KERN_DIR))
|
---|
177 | $(warning dbg: KERN_INCL = $(KERN_INCL))
|
---|
178 | $(warning dbg: MODULE_DIR = $(MODULE_DIR))
|
---|
179 | $(warning dbg: KERN_VERSION = $(KERN_VERSION))
|
---|
180 | endif
|
---|
181 |
|
---|
182 | endif # eq($(MAKECMDGOALS),clean)
|
---|