VirtualBox

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

最後變更 在這個檔案從77504是 77504,由 vboxsync 提交於 6 年 前

Add/linux: Workaround for GNU make that does not sport MAKEFILE_LIST (< 3.80). bugref:9172

  • 屬性 svn:eol-style 設為 LF
  • 屬性 svn:keywords 設為 Author Date Id Revision
檔案大小: 7.0 KB
 
1# $Id: Makefile-header.gmk 77504 2019-02-28 12:37:43Z 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.alldomusa.eu.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 else
129 endif
130 endif
131
132else # neq($(KERNELRELEASE),)
133
134 #
135 # building from kbuild (make -C <kernel_directory> M=`pwd`)
136 #
137
138 # guess kernel version (24 or 26)
139 ifeq ($(VERSION).$(PATCHLEVEL),2.4)
140 KERN_VERSION := 24
141 VBOX_KERN_GROKS_EXTMOD :=
142 else
143 KERN_VERSION := 26
144 VBOX_KERN_GROKS_EXTMOD := yes
145 ifeq ($(VERSION).$(PATCHLEVEL),2.6)
146 ifeq ($(findstring @$(SUBLEVEL)@,@0@1@2@3@4@5@),@$(SUBLEVEL)@)
147 VBOX_KERN_GROKS_EXTMOD :=
148 endif
149 endif
150 endif
151
152 KERN_VER := $(KERNELRELEASE)
153
154 ifeq ($(KERN_DIR),)
155 KERN_DIR := /lib/modules/$(KERN_VER)/build
156 endif
157endif # neq($(KERNELRELEASE),)
158
159# Kernel build folder
160ifneq ($(shell if test -d $(KERN_DIR); then echo yes; fi),yes)
161 $(error Error: unable to find the headers of the Linux kernel to build against. \
162 Specify KERN_VER=<version> (currently $(KERN_VER)) and run Make again)
163endif
164# Kernel include folder
165KERN_INCL := $(KERN_DIR)/include
166# module install folder
167INSTALL_MOD_DIR ?= misc
168MODULE_DIR := $(INSTALL_MOD_PATH)/lib/modules/$(KERN_VER)/$(INSTALL_MOD_DIR)
169
170#
171# The KBUILD_EXTMOD variable is used by 2.6.6 and later when build external
172# modules (see https://lwn.net/Articles/79984/). It will be set to SUBDIRS
173# or M by the linux kernel makefile. We fake it here for older kernels.
174#
175## @todo Drop this KBUILD_EXTMOD glue once it has been removed from all our makefiles (see sharedfolders).
176ifndef CURDIR # for make < v3.79
177 CURDIR := $(shell pwd)
178endif
179ifndef KBUILD_EXTMOD
180 KBUILD_EXTMOD := $(CURDIR)
181endif
182
183
184# For VBOX_GCC_CHECK_CC
185VBOX_CLOSEPAR := )
186VBOX_DOLLAR := $$
187## Modified VBOX_GCC_CHECK_EX_CC_CXX macro from /Config.kmk.
188# @param 1 The option to test for.
189# @param 2 The return value when supported.
190# @param 3 The return value when NOT supported.
191VBOX_GCC_CHECK_CC = $(shell \
192 > /tmp/$(VBOX_DOLLAR)$(VBOX_DOLLAR).check.c; \
193 if $(CC) $(subst -Wno-,-W,$(1)) -Werror -c -o /dev/null /tmp/$(VBOX_DOLLAR)$(VBOX_DOLLAR).check.c > /dev/null 2>&1; then \
194 case "`LC_ALL=C $(CC) $(subst -Wno-,-W,$(1)) -Werror -c -o /dev/null /tmp/$(VBOX_DOLLAR)$(VBOX_DOLLAR).check.c 2>&1`" in \
195 "error: unknown warning option"*$(VBOX_CLOSEPAR) echo "$(3)";; \
196 *$(VBOX_CLOSEPAR) echo "$(2)";; \
197 esac; \
198 else echo "$(3)"; fi; \
199 rm -f /tmp/$(VBOX_DOLLAR)$(VBOX_DOLLAR).check.c; )
200
201#
202# Guess the module directory ASSUMING that this file is located in that directory.
203# Note! The special MAKEFILE_LIST variable was introduced in GNU make 3.80.
204#
205ifdef MAKEFILE_LIST
206 VBOX_MODULE_SRC_DIR := $(dir $(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST)))
207else
208 VBOX_MODULE_SRC_DIR := $(CURDIR)/
209endif
210
211
212# debug - show guesses.
213ifdef DEBUG
214 ifndef VBOX_KERN_QUIET
215$(warning dbg: INSTALL_MOD_PATH = $(INSTALL_MOD_PATH))
216$(warning dbg: INSTALL_MOD_DIR = $(INSTALL_MOD_DIR))
217$(warning dbg: KERN_DIR = $(KERN_DIR))
218$(warning dbg: KERN_INCL = $(KERN_INCL))
219$(warning dbg: KERN_VERSION = $(KERN_VERSION))
220$(warning dbg: MODULE_DIR = $(MODULE_DIR))
221$(warning dbg: KBUILD_EXTMOD = $(KBUILD_EXTMOD))
222$(warning dbg: VBOX_MODULE_SRC_DIR = $(VBOX_MODULE_SRC_DIR))
223 endif
224endif
225
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette