1 | # $Id: Makefile-header.gmk 82968 2020-02-04 10:35:17Z vboxsync $
|
---|
2 | ## @file
|
---|
3 | # VirtualBox Guest Additions kernel module Makefile, common parts.
|
---|
4 | #
|
---|
5 | # (For 2.6.x, the main file must be called 'Makefile'!)
|
---|
6 | #
|
---|
7 |
|
---|
8 | #
|
---|
9 | # Copyright (C) 2006-2020 Oracle Corporation
|
---|
10 | #
|
---|
11 | # This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
12 | # available from http://www.virtualbox.org. This file is free software;
|
---|
13 | # you can redistribute it and/or modify it under the terms of the GNU
|
---|
14 | # General Public License (GPL) as published by the Free Software
|
---|
15 | # Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
16 | # VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
17 | # hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
18 | #
|
---|
19 |
|
---|
20 | # Testing:
|
---|
21 | # * Building with KERN_DIR set uses the value specified and
|
---|
22 | # the default value for the unspecified one if any.
|
---|
23 |
|
---|
24 | #
|
---|
25 | # These file should be included by the Makefiles for any kernel modules we
|
---|
26 | # build as part of the Guest Additions. The intended way of doing this is as
|
---|
27 | # follows:
|
---|
28 | #
|
---|
29 | # # Linux kbuild sets this to our source directory if we are called from there
|
---|
30 | # obj ?= $(CURDIR)
|
---|
31 | # include $(obj)/Makefile-header.gmk
|
---|
32 | # VBOXMOD_NAME = <name of the module to be built, without extension>
|
---|
33 | # VBOXMOD_OBJS = <list of object files which should be included>
|
---|
34 | # VBOXMOD_DEFS = <any additional defines which this module needs>
|
---|
35 | # VBOXMOD_INCL = <any additional include paths which this module needs>
|
---|
36 | # VBOXMOD_CFLAGS = <any additional CFLAGS which this module needs>
|
---|
37 | # include $(obj)/Makefile-footer.gmk
|
---|
38 | #
|
---|
39 | # The kmk kBuild define KBUILD_TARGET_ARCH is available.
|
---|
40 | #
|
---|
41 |
|
---|
42 |
|
---|
43 | #
|
---|
44 | # First, figure out which architecture we're targeting and the build type.
|
---|
45 | # (We have to support basic cross building (ARCH=i386|x86_64).)
|
---|
46 | # While at it, warn about BUILD_* vars found to help with user problems.
|
---|
47 | #
|
---|
48 | ifeq ($(filter-out x86_64 amd64 AMD64,$(shell uname -m)),)
|
---|
49 | BUILD_TARGET_ARCH_DEF := amd64
|
---|
50 | else
|
---|
51 | BUILD_TARGET_ARCH_DEF := x86
|
---|
52 | endif
|
---|
53 | ifneq ($(filter-out amd64 x86,$(BUILD_TARGET_ARCH)),)
|
---|
54 | $(warning Ignoring unknown BUILD_TARGET_ARCH value '$(BUILD_TARGET_ARCH)'.)
|
---|
55 | BUILD_TARGET_ARCH :=
|
---|
56 | endif
|
---|
57 | ifeq ($(BUILD_TARGET_ARCH),)
|
---|
58 | ifeq ($(ARCH),x86_64)
|
---|
59 | BUILD_TARGET_ARCH := amd64
|
---|
60 | else
|
---|
61 | ifeq ($(ARCH),i386)
|
---|
62 | BUILD_TARGET_ARCH := x86
|
---|
63 | else
|
---|
64 | BUILD_TARGET_ARCH := $(BUILD_TARGET_ARCH_DEF)
|
---|
65 | endif
|
---|
66 | endif
|
---|
67 | else
|
---|
68 | ifneq ($(BUILD_TARGET_ARCH),$(BUILD_TARGET_ARCH_DEF))
|
---|
69 | $(warning Using BUILD_TARGET_ARCH='$(BUILD_TARGET_ARCH)' from the $(origin BUILD_TARGET_ARCH).)
|
---|
70 | endif
|
---|
71 | endif
|
---|
72 |
|
---|
73 | ifneq ($(filter-out release profile debug strict,$(BUILD_TYPE)),)
|
---|
74 | $(warning Ignoring unknown BUILD_TYPE value '$(BUILD_TYPE)'.)
|
---|
75 | BUILD_TYPE :=
|
---|
76 | endif
|
---|
77 | ifeq ($(BUILD_TYPE),)
|
---|
78 | BUILD_TYPE := release
|
---|
79 | else
|
---|
80 | ifneq ($(BUILD_TYPE),release)
|
---|
81 | ifndef VBOX_KERN_QUIET
|
---|
82 | $(warning Using BUILD_TYPE='$(BUILD_TYPE)' from the $(origin BUILD_TYPE).)
|
---|
83 | endif
|
---|
84 | endif
|
---|
85 | endif
|
---|
86 | ifeq ($(USERNAME),)
|
---|
87 | USERNAME := noname
|
---|
88 | endif
|
---|
89 |
|
---|
90 | ifeq ($(KERNELRELEASE),)
|
---|
91 |
|
---|
92 | #
|
---|
93 | # building from this directory
|
---|
94 | #
|
---|
95 |
|
---|
96 | # kernel base directory
|
---|
97 | ifdef KERN_DIR
|
---|
98 | ifndef KERN_VER
|
---|
99 | ifeq ($(filter %/build,$(KERN_DIR)),)
|
---|
100 | $(error The variable KERN_DIR must be a kernel build folder and end with /build without a trailing slash, or KERN_VER must be set)
|
---|
101 | endif
|
---|
102 | endif
|
---|
103 | endif
|
---|
104 |
|
---|
105 | ifndef KERN_VER
|
---|
106 | ifdef KERN_DIR
|
---|
107 | KERN_VER = $(notdir $(patsubst %/build,%,$(KERN_DIR)))
|
---|
108 | ifeq ($(shell expr $(KERN_VER) : '[0-9]*\.[0-9]*.[0-9]*'),0)
|
---|
109 | $(error The kernel build folder path must end in <version>/build, or the variable KERN_VER must be set)
|
---|
110 | endif
|
---|
111 | endif
|
---|
112 | KERN_VER ?= $(shell uname -r)
|
---|
113 | endif
|
---|
114 |
|
---|
115 | ifeq ($(KERN_DIR),)
|
---|
116 | KERN_DIR := /lib/modules/$(KERN_VER)/build
|
---|
117 | endif
|
---|
118 |
|
---|
119 | # Is this 2.4 or < 2.6.6? The UTS_RELEASE "2.x.y.z" define is present in the header until 2.6.1x something.
|
---|
120 | ifeq ($(shell if grep '"2\.4\.' $(KERN_DIR)/include/linux/version.h > /dev/null 2>&1; then echo yes; fi),yes)
|
---|
121 | KERN_VERSION := 24
|
---|
122 | VBOX_KERN_GROKS_EXTMOD :=
|
---|
123 | else
|
---|
124 | KERN_VERSION := 26
|
---|
125 | VBOX_KERN_GROKS_EXTMOD := yes
|
---|
126 | ifeq ($(shell if grep '"2\.6\.[012345][."]' $(KERN_DIR)/include/linux/version.h > /dev/null 2>&1; then echo yes; fi),yes)
|
---|
127 | VBOX_KERN_GROKS_EXTMOD :=
|
---|
128 | endif
|
---|
129 | VBOX_KERN_GROKS_SUBDIRS :=
|
---|
130 | ifeq ($(shell if grep '"[432]\.' $(KERN_DIR)/include/linux/version.h > /dev/null 2>&1; then echo yes; fi),yes)
|
---|
131 | VBOX_KERN_GROKS_SUBDIRS := yes
|
---|
132 | endif
|
---|
133 | endif
|
---|
134 |
|
---|
135 | #
|
---|
136 | # Hack for Ubuntu 4.10 where we determine 2.6.8.1-3-generic-amd64 here, but the
|
---|
137 | # the next invocation (M/SUBDIR) ends up with KERNELRELEASE=2.6.8.1-3.
|
---|
138 | #
|
---|
139 | ifeq ($(shell if grep '"[2]\.' $(KERN_DIR)/include/linux/version.h > /dev/null 2>&1; then echo yes; fi),yes)
|
---|
140 | export KERN_VER KERN_DIR
|
---|
141 | else
|
---|
142 | # This makefile received some variables in the command line which should
|
---|
143 | # not be passed to the recursive make invocations (of the Linux makefile
|
---|
144 | # for building kernel modules), since they should derive KERN_DIR from the
|
---|
145 | # respective command line variables to come up with the value they expect.
|
---|
146 | unexport KERN_VER KERN_DIR
|
---|
147 | MAKEOVERRIDES := $(filter-out KERN_VER=% KERN_DIR=%,$(MAKEOVERRIDES))
|
---|
148 | endif
|
---|
149 |
|
---|
150 | else # neq($(KERNELRELEASE),)
|
---|
151 |
|
---|
152 | #
|
---|
153 | # building from kbuild (make -C <kernel_directory> M=`pwd`)
|
---|
154 | #
|
---|
155 |
|
---|
156 | # guess kernel version (24 or 26)
|
---|
157 | ifeq ($(VERSION).$(PATCHLEVEL),2.4)
|
---|
158 | KERN_VERSION := 24
|
---|
159 | VBOX_KERN_GROKS_EXTMOD :=
|
---|
160 | else
|
---|
161 | KERN_VERSION := 26
|
---|
162 | VBOX_KERN_GROKS_EXTMOD := yes
|
---|
163 | ifeq ($(VERSION).$(PATCHLEVEL),2.6)
|
---|
164 | ifeq ($(findstring @$(SUBLEVEL)@,@0@1@2@3@4@5@),@$(SUBLEVEL)@)
|
---|
165 | VBOX_KERN_GROKS_EXTMOD :=
|
---|
166 | endif
|
---|
167 | endif
|
---|
168 | VBOX_KERN_GROKS_SUBDIRS :=
|
---|
169 | ifeq ($(VERSION),2)
|
---|
170 | VBOX_KERN_GROKS_SUBDIRS := yes
|
---|
171 | endif
|
---|
172 | ifeq ($(VERSION),3)
|
---|
173 | VBOX_KERN_GROKS_SUBDIRS := yes
|
---|
174 | endif
|
---|
175 | ifeq ($(VERSION),4)
|
---|
176 | VBOX_KERN_GROKS_SUBDIRS := yes
|
---|
177 | endif
|
---|
178 | endif
|
---|
179 |
|
---|
180 | KERN_VER := $(KERNELRELEASE)
|
---|
181 |
|
---|
182 | ifeq ($(KERN_DIR),)
|
---|
183 | ifneq ($(srctree),)
|
---|
184 | KERN_DIR := $(srctree)
|
---|
185 | else
|
---|
186 | KERN_DIR := /lib/modules/$(KERN_VER)/build
|
---|
187 | endif
|
---|
188 | endif
|
---|
189 | endif # neq($(KERNELRELEASE),)
|
---|
190 |
|
---|
191 | # Kernel build folder
|
---|
192 | ifneq ($(shell if test -d $(KERN_DIR); then echo yes; fi),yes)
|
---|
193 | $(error Error: unable to find the headers of the Linux kernel to build against (KERN_DIR=$(KERN_DIR)). \
|
---|
194 | Specify KERN_VER=<version> (currently $(KERN_VER)) and run Make again)
|
---|
195 | endif
|
---|
196 | # Kernel include folder
|
---|
197 | KERN_INCL := $(KERN_DIR)/include
|
---|
198 | # module install folder
|
---|
199 | INSTALL_MOD_DIR ?= misc
|
---|
200 | MODULE_DIR := $(INSTALL_MOD_PATH)/lib/modules/$(KERN_VER)/$(INSTALL_MOD_DIR)
|
---|
201 |
|
---|
202 | # For VBOX_GCC_CHECK_CC
|
---|
203 | VBOX_CLOSEPAR := )
|
---|
204 | VBOX_DOLLAR := $$
|
---|
205 | ## Modified VBOX_GCC_CHECK_EX_CC_CXX macro from /Config.kmk.
|
---|
206 | # @param 1 The option to test for.
|
---|
207 | # @param 2 The return value when supported.
|
---|
208 | # @param 3 The return value when NOT supported.
|
---|
209 | VBOX_GCC_CHECK_CC = $(shell \
|
---|
210 | > /tmp/$(VBOX_DOLLAR)$(VBOX_DOLLAR).check.c; \
|
---|
211 | if $(CC) $(subst -Wno-,-W,$(1)) -Werror -c -o /dev/null /tmp/$(VBOX_DOLLAR)$(VBOX_DOLLAR).check.c > /dev/null 2>&1; then \
|
---|
212 | case "`LC_ALL=C $(CC) $(subst -Wno-,-W,$(1)) -Werror -c -o /dev/null /tmp/$(VBOX_DOLLAR)$(VBOX_DOLLAR).check.c 2>&1`" in \
|
---|
213 | "error: unknown warning option"*$(VBOX_CLOSEPAR) echo "$(3)";; \
|
---|
214 | *$(VBOX_CLOSEPAR) echo "$(2)";; \
|
---|
215 | esac; \
|
---|
216 | else echo "$(3)"; fi; \
|
---|
217 | rm -f /tmp/$(VBOX_DOLLAR)$(VBOX_DOLLAR).check.c; )
|
---|
218 |
|
---|
219 | #
|
---|
220 | # Guess the module directory ASSUMING that this file is located in that directory.
|
---|
221 | # Note! The special MAKEFILE_LIST variable was introduced in GNU make 3.80.
|
---|
222 | #
|
---|
223 | ifdef MAKEFILE_LIST
|
---|
224 | VBOX_MODULE_SRC_DIR := $(dir $(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST)))
|
---|
225 | else
|
---|
226 | VBOX_MODULE_SRC_DIR := $(CURDIR)/
|
---|
227 | endif
|
---|
228 |
|
---|
229 |
|
---|
230 | # debug - show guesses.
|
---|
231 | ifdef DEBUG
|
---|
232 | ifndef VBOX_KERN_QUIET
|
---|
233 | $(warning dbg: INSTALL_MOD_PATH = $(INSTALL_MOD_PATH))
|
---|
234 | $(warning dbg: INSTALL_MOD_DIR = $(INSTALL_MOD_DIR))
|
---|
235 | $(warning dbg: KERN_DIR = $(KERN_DIR))
|
---|
236 | $(warning dbg: KERN_INCL = $(KERN_INCL))
|
---|
237 | $(warning dbg: KERN_VERSION = $(KERN_VERSION))
|
---|
238 | $(warning dbg: MODULE_DIR = $(MODULE_DIR))
|
---|
239 | $(warning dbg: VBOX_MODULE_SRC_DIR = $(VBOX_MODULE_SRC_DIR))
|
---|
240 | endif
|
---|
241 | endif
|
---|
242 |
|
---|