VirtualBox

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

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

linux/Makefile-header.gmk: Ubuntu 4.10 fix. bugref:9172

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 7.7 KB
Line 
1# $Id: Makefile-header.gmk 77740 2019-03-17 03:03:50Z 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 KERN_DIR := /lib/modules/$(KERN_VER)/build
177 endif
178endif # neq($(KERNELRELEASE),)
179
180# Kernel build folder
181ifneq ($(shell if test -d $(KERN_DIR); then echo yes; fi),yes)
182 $(error Error: unable to find the headers of the Linux kernel to build against (KERN_DIR=$(KERN_DIR)). \
183 Specify KERN_VER=<version> (currently $(KERN_VER)) and run Make again)
184endif
185# Kernel include folder
186KERN_INCL := $(KERN_DIR)/include
187# module install folder
188INSTALL_MOD_DIR ?= misc
189MODULE_DIR := $(INSTALL_MOD_PATH)/lib/modules/$(KERN_VER)/$(INSTALL_MOD_DIR)
190
191#
192# The KBUILD_EXTMOD variable is used by 2.6.6 and later when build external
193# modules (see https://lwn.net/Articles/79984/). It will be set to SUBDIRS
194# or M by the linux kernel makefile. We fake it here for older kernels.
195#
196## @todo Drop this KBUILD_EXTMOD glue once it has been removed from all our makefiles (see sharedfolders).
197ifndef CURDIR # for make < v3.79
198 CURDIR := $(shell pwd)
199endif
200ifndef KBUILD_EXTMOD
201 KBUILD_EXTMOD := $(CURDIR)
202endif
203
204
205# For VBOX_GCC_CHECK_CC
206VBOX_CLOSEPAR := )
207VBOX_DOLLAR := $$
208## Modified VBOX_GCC_CHECK_EX_CC_CXX macro from /Config.kmk.
209# @param 1 The option to test for.
210# @param 2 The return value when supported.
211# @param 3 The return value when NOT supported.
212VBOX_GCC_CHECK_CC = $(shell \
213 > /tmp/$(VBOX_DOLLAR)$(VBOX_DOLLAR).check.c; \
214 if $(CC) $(subst -Wno-,-W,$(1)) -Werror -c -o /dev/null /tmp/$(VBOX_DOLLAR)$(VBOX_DOLLAR).check.c > /dev/null 2>&1; then \
215 case "`LC_ALL=C $(CC) $(subst -Wno-,-W,$(1)) -Werror -c -o /dev/null /tmp/$(VBOX_DOLLAR)$(VBOX_DOLLAR).check.c 2>&1`" in \
216 "error: unknown warning option"*$(VBOX_CLOSEPAR) echo "$(3)";; \
217 *$(VBOX_CLOSEPAR) echo "$(2)";; \
218 esac; \
219 else echo "$(3)"; fi; \
220 rm -f /tmp/$(VBOX_DOLLAR)$(VBOX_DOLLAR).check.c; )
221
222#
223# Guess the module directory ASSUMING that this file is located in that directory.
224# Note! The special MAKEFILE_LIST variable was introduced in GNU make 3.80.
225#
226ifdef MAKEFILE_LIST
227 VBOX_MODULE_SRC_DIR := $(dir $(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST)))
228else
229 VBOX_MODULE_SRC_DIR := $(CURDIR)/
230endif
231
232
233# debug - show guesses.
234ifdef DEBUG
235 ifndef VBOX_KERN_QUIET
236$(warning dbg: INSTALL_MOD_PATH = $(INSTALL_MOD_PATH))
237$(warning dbg: INSTALL_MOD_DIR = $(INSTALL_MOD_DIR))
238$(warning dbg: KERN_DIR = $(KERN_DIR))
239$(warning dbg: KERN_INCL = $(KERN_INCL))
240$(warning dbg: KERN_VERSION = $(KERN_VERSION))
241$(warning dbg: MODULE_DIR = $(MODULE_DIR))
242$(warning dbg: KBUILD_EXTMOD = $(KBUILD_EXTMOD))
243$(warning dbg: VBOX_MODULE_SRC_DIR = $(VBOX_MODULE_SRC_DIR))
244 endif
245endif
246
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