VirtualBox

source: vbox/trunk/src/VBox/Installer/linux/Makefile-header.gmk@ 78447

Last change on this file since 78447 was 78447, checked in by vboxsync, 6 years ago

Installers/Linux: make it possible to build our kernel modules in-tree.
This change lets our kernel module build process use kernel headers in a
kernel source tree when they are built as part of a kernel build, and is the
last known requirement for building the Additions modules in that way.

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 7.2 KB
Line 
1# $Id: Makefile-header.gmk 78447 2019-05-08 10:59:59Z 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-2019 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#
48ifeq ($(filter-out x86_64 amd64 AMD64,$(shell uname -m)),)
49 BUILD_TARGET_ARCH_DEF := amd64
50else
51 BUILD_TARGET_ARCH_DEF := x86
52endif
53ifneq ($(filter-out amd64 x86,$(BUILD_TARGET_ARCH)),)
54 $(warning Ignoring unknown BUILD_TARGET_ARCH value '$(BUILD_TARGET_ARCH)'.)
55 BUILD_TARGET_ARCH :=
56endif
57ifeq ($(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
67else
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
71endif
72
73ifneq ($(filter-out release profile debug strict,$(BUILD_TYPE)),)
74 $(warning Ignoring unknown BUILD_TYPE value '$(BUILD_TYPE)'.)
75 BUILD_TYPE :=
76endif
77ifeq ($(BUILD_TYPE),)
78 BUILD_TYPE := release
79else
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
85endif
86ifeq ($(USERNAME),)
87 USERNAME := noname
88endif
89
90ifeq ($(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 endif
142
143else # neq($(KERNELRELEASE),)
144
145 #
146 # building from kbuild (make -C <kernel_directory> M=`pwd`)
147 #
148
149 # guess kernel version (24 or 26)
150 ifeq ($(VERSION).$(PATCHLEVEL),2.4)
151 KERN_VERSION := 24
152 VBOX_KERN_GROKS_EXTMOD :=
153 else
154 KERN_VERSION := 26
155 VBOX_KERN_GROKS_EXTMOD := yes
156 ifeq ($(VERSION).$(PATCHLEVEL),2.6)
157 ifeq ($(findstring @$(SUBLEVEL)@,@0@1@2@3@4@5@),@$(SUBLEVEL)@)
158 VBOX_KERN_GROKS_EXTMOD :=
159 endif
160 endif
161 VBOX_KERN_GROKS_SUBDIRS :=
162 ifeq ($(VERSION),2)
163 VBOX_KERN_GROKS_SUBDIRS := yes
164 endif
165 ifeq ($(VERSION),3)
166 VBOX_KERN_GROKS_SUBDIRS := yes
167 endif
168 ifeq ($(VERSION),4)
169 VBOX_KERN_GROKS_SUBDIRS := yes
170 endif
171 endif
172
173 KERN_VER := $(KERNELRELEASE)
174
175 ifeq ($(KERN_DIR),)
176 ifneq ($(srctree),)
177 KERN_DIR := $(srctree)
178 else
179 KERN_DIR := /lib/modules/$(KERN_VER)/build
180 endif
181 endif
182endif # neq($(KERNELRELEASE),)
183
184# Kernel build folder
185ifneq ($(shell if test -d $(KERN_DIR); then echo yes; fi),yes)
186 $(error Error: unable to find the headers of the Linux kernel to build against (KERN_DIR=$(KERN_DIR)). \
187 Specify KERN_VER=<version> (currently $(KERN_VER)) and run Make again)
188endif
189# Kernel include folder
190KERN_INCL := $(KERN_DIR)/include
191# module install folder
192INSTALL_MOD_DIR ?= misc
193MODULE_DIR := $(INSTALL_MOD_PATH)/lib/modules/$(KERN_VER)/$(INSTALL_MOD_DIR)
194
195# For VBOX_GCC_CHECK_CC
196VBOX_CLOSEPAR := )
197VBOX_DOLLAR := $$
198## Modified VBOX_GCC_CHECK_EX_CC_CXX macro from /Config.kmk.
199# @param 1 The option to test for.
200# @param 2 The return value when supported.
201# @param 3 The return value when NOT supported.
202VBOX_GCC_CHECK_CC = $(shell \
203 > /tmp/$(VBOX_DOLLAR)$(VBOX_DOLLAR).check.c; \
204 if $(CC) $(subst -Wno-,-W,$(1)) -Werror -c -o /dev/null /tmp/$(VBOX_DOLLAR)$(VBOX_DOLLAR).check.c > /dev/null 2>&1; then \
205 case "`LC_ALL=C $(CC) $(subst -Wno-,-W,$(1)) -Werror -c -o /dev/null /tmp/$(VBOX_DOLLAR)$(VBOX_DOLLAR).check.c 2>&1`" in \
206 "error: unknown warning option"*$(VBOX_CLOSEPAR) echo "$(3)";; \
207 *$(VBOX_CLOSEPAR) echo "$(2)";; \
208 esac; \
209 else echo "$(3)"; fi; \
210 rm -f /tmp/$(VBOX_DOLLAR)$(VBOX_DOLLAR).check.c; )
211
212#
213# Guess the module directory ASSUMING that this file is located in that directory.
214# Note! The special MAKEFILE_LIST variable was introduced in GNU make 3.80.
215#
216ifdef MAKEFILE_LIST
217 VBOX_MODULE_SRC_DIR := $(dir $(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST)))
218else
219 VBOX_MODULE_SRC_DIR := $(CURDIR)/
220endif
221
222
223# debug - show guesses.
224ifdef DEBUG
225 ifndef VBOX_KERN_QUIET
226$(warning dbg: INSTALL_MOD_PATH = $(INSTALL_MOD_PATH))
227$(warning dbg: INSTALL_MOD_DIR = $(INSTALL_MOD_DIR))
228$(warning dbg: KERN_DIR = $(KERN_DIR))
229$(warning dbg: KERN_INCL = $(KERN_INCL))
230$(warning dbg: KERN_VERSION = $(KERN_VERSION))
231$(warning dbg: MODULE_DIR = $(MODULE_DIR))
232$(warning dbg: VBOX_MODULE_SRC_DIR = $(VBOX_MODULE_SRC_DIR))
233 endif
234endif
235
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