VirtualBox

source: vbox/trunk/src/VBox/HostDrivers/Support/linux/Makefile@ 67954

Last change on this file since 67954 was 67293, checked in by vboxsync, 7 years ago

Linux host/guest kernel modules: add __udivmoddi4() to satisfy 32-bit code generated by gcc-7 or later

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 10.5 KB
Line 
1# $Id: Makefile 67293 2017-06-08 11:50:14Z vboxsync $
2## @file
3# Makefile for the VirtualBox Linux Host Driver.
4#
5
6#
7#
8# Copyright (C) 2006-2015 Oracle Corporation
9#
10# This file is part of VirtualBox Open Source Edition (OSE), as
11# available from http://www.virtualbox.org. This file is free software;
12# you can redistribute it and/or modify it under the terms of the GNU
13# General Public License (GPL) as published by the Free Software
14# Foundation, in version 2 as it comes in the "COPYING" file of the
15# VirtualBox OSE distribution. VirtualBox OSE is distributed in the
16# hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
17#
18# The contents of this file may alternatively be used under the terms
19# of the Common Development and Distribution License Version 1.0
20# (CDDL) only, as it comes in the "COPYING.CDDL" file of the
21# VirtualBox OSE distribution, in which case the provisions of the
22# CDDL are applicable instead of those of the GPL.
23#
24# You may elect to license modified versions of this file under the
25# terms and conditions of either the GPL or the CDDL or both.
26#
27
28## @todo If you make non-trivial changes to this make file, please consider
29# rewriting it to use Makefile.include.header and
30# Makefile.include.footer.
31
32#
33# First, figure out which architecture we're targeting and the build type.
34# (We have to support basic cross building (ARCH=i386|x86_64).)
35# While at it, warn about BUILD_* vars found to help with user problems.
36#
37ifeq ($(filter-out x86_64 amd64 AMD64,$(shell uname -m)),)
38 BUILD_TARGET_ARCH_DEF := amd64
39else
40 BUILD_TARGET_ARCH_DEF := x86
41endif
42ifneq ($(filter-out amd64 x86,$(BUILD_TARGET_ARCH)),)
43 $(warning Ignoring unknown BUILD_TARGET_ARCH value '$(BUILD_TARGET_ARCH)'.)
44 BUILD_TARGET_ARCH :=
45endif
46ifeq ($(BUILD_TARGET_ARCH),)
47 ifeq ($(ARCH),x86_64)
48 BUILD_TARGET_ARCH := amd64
49 else
50 ifeq ($(ARCH),i386)
51 BUILD_TARGET_ARCH := x86
52 else
53 BUILD_TARGET_ARCH := $(BUILD_TARGET_ARCH_DEF)
54 endif
55 endif
56else
57 ifneq ($(BUILD_TARGET_ARCH),$(BUILD_TARGET_ARCH_DEF))
58 $(warning Using BUILD_TARGET_ARCH='$(BUILD_TARGET_ARCH)' from the $(origin BUILD_TARGET_ARCH).)
59 endif
60endif
61
62ifneq ($(filter-out release profile debug strict,$(BUILD_TYPE)),)
63 $(warning Ignoring unknown BUILD_TYPE value '$(BUILD_TYPE)'.)
64 BUILD_TYPE :=
65endif
66ifeq ($(BUILD_TYPE),)
67 BUILD_TYPE := release
68else
69 ifneq ($(BUILD_TYPE),release)
70 $(warning Using BUILD_TYPE='$(BUILD_TYPE)' from the $(origin BUILD_TYPE).)
71 endif
72endif
73
74# override is required by the Debian guys
75override MODULE = vboxdrv
76OBJS = \
77 linux/SUPDrv-linux.o \
78 SUPDrv.o \
79 SUPDrvGip.o \
80 SUPDrvSem.o \
81 SUPDrvTracer.o \
82 SUPLibAll.o \
83 r0drv/alloc-r0drv.o \
84 r0drv/initterm-r0drv.o \
85 r0drv/memobj-r0drv.o \
86 r0drv/mpnotification-r0drv.o \
87 r0drv/powernotification-r0drv.o \
88 r0drv/linux/assert-r0drv-linux.o \
89 r0drv/linux/alloc-r0drv-linux.o \
90 r0drv/linux/initterm-r0drv-linux.o \
91 r0drv/linux/memobj-r0drv-linux.o \
92 r0drv/linux/memuserkernel-r0drv-linux.o \
93 r0drv/linux/mp-r0drv-linux.o \
94 r0drv/linux/mpnotification-r0drv-linux.o \
95 r0drv/linux/process-r0drv-linux.o \
96 r0drv/linux/rtStrFormatKernelAddress-r0drv-linux.o \
97 r0drv/linux/semevent-r0drv-linux.o \
98 r0drv/linux/semeventmulti-r0drv-linux.o \
99 r0drv/linux/semfastmutex-r0drv-linux.o \
100 r0drv/linux/semmutex-r0drv-linux.o \
101 r0drv/linux/spinlock-r0drv-linux.o \
102 r0drv/linux/thread-r0drv-linux.o \
103 r0drv/linux/thread2-r0drv-linux.o \
104 r0drv/linux/threadctxhooks-r0drv-linux.o \
105 r0drv/linux/time-r0drv-linux.o \
106 r0drv/linux/timer-r0drv-linux.o \
107 r0drv/generic/semspinmutex-r0drv-generic.o \
108 common/alloc/alloc.o \
109 common/checksum/crc32.o \
110 common/checksum/ipv4.o \
111 common/checksum/ipv6.o \
112 common/err/RTErrConvertFromErrno.o \
113 common/err/RTErrConvertToErrno.o \
114 common/log/log.o \
115 common/log/logellipsis.o \
116 common/log/logrel.o \
117 common/log/logrelellipsis.o \
118 common/log/logcom.o \
119 common/log/logformat.o \
120 common/misc/RTAssertMsg1Weak.o \
121 common/misc/RTAssertMsg2.o \
122 common/misc/RTAssertMsg2Add.o \
123 common/misc/RTAssertMsg2AddWeak.o \
124 common/misc/RTAssertMsg2AddWeakV.o \
125 common/misc/RTAssertMsg2Weak.o \
126 common/misc/RTAssertMsg2WeakV.o \
127 common/misc/assert.o \
128 common/misc/handletable.o \
129 common/misc/handletablectx.o \
130 common/misc/thread.o \
131 common/string/RTStrCopy.o \
132 common/string/RTStrCopyEx.o \
133 common/string/RTStrCopyP.o \
134 common/string/RTStrNCmp.o \
135 common/string/RTStrNLen.o \
136 common/string/stringalloc.o \
137 common/string/strformat.o \
138 common/string/strformatrt.o \
139 common/string/strformattype.o \
140 common/string/strprintf.o \
141 common/string/strtonum.o \
142 common/table/avlpv.o \
143 common/time/time.o \
144 r0drv/linux/RTLogWriteDebugger-r0drv-linux.o \
145 generic/RTAssertShouldPanic-generic.o \
146 generic/RTLogWriteStdErr-stub-generic.o \
147 generic/RTLogWriteStdOut-stub-generic.o \
148 generic/RTLogWriteUser-generic.o \
149 generic/RTMpGetArraySize-generic.o \
150 generic/RTMpGetCoreCount-generic.o \
151 generic/RTSemEventWait-2-ex-generic.o \
152 generic/RTSemEventWaitNoResume-2-ex-generic.o \
153 generic/RTSemEventMultiWait-2-ex-generic.o \
154 generic/RTSemEventMultiWaitNoResume-2-ex-generic.o \
155 generic/RTTimerCreate-generic.o \
156 generic/errvars-generic.o \
157 generic/mppresent-generic.o \
158 generic/uuid-generic.o \
159 VBox/log-vbox.o
160ifeq ($(BUILD_TARGET_ARCH),x86)
161OBJS += math/gcc/divdi3.o \
162 math/gcc/moddi3.o \
163 math/gcc/qdivrem.o \
164 math/gcc/udivdi3.o \
165 math/gcc/udivmoddi4.o \
166 math/gcc/divdi3.o \
167 math/gcc/umoddi3.o
168endif
169ifeq ($(BUILD_TARGET_ARCH),amd64)
170OBJS += common/alloc/heapsimple.o
171endif
172ifdef VBOX_WITH_NATIVE_DTRACE
173OBJS += SUPDrvDTrace.o
174endif
175
176ifneq ($(MAKECMDGOALS),clean)
177
178ifeq ($(KERNELRELEASE),)
179
180 #
181 # building from this directory
182 #
183
184 # kernel base directory
185 ifndef KERN_DIR
186 # build for the current kernel, version check
187 KERN_DIR := /lib/modules/$(shell uname -r)/build
188 ifneq ($(shell if test -d $(KERN_DIR); then echo yes; fi),yes)
189 KERN_DIR := /usr/src/linux
190 ifneq ($(shell if test -d $(KERN_DIR); then echo yes; fi),yes)
191 $(error Error: unable to find the sources of your current Linux kernel. \
192 Specify KERN_DIR=<directory> and run Make again)
193 endif
194 $(warning Warning: using /usr/src/linux as the source directory of your \
195 Linux kernel. If this is not correct, specify \
196 KERN_DIR=<directory> and run Make again.)
197 endif
198 else
199 ifneq ($(shell if test -d $(KERN_DIR); then echo yes; fi),yes)
200 $(error Error: KERN_DIR does not point to a directory)
201 endif
202 endif
203
204 # includes
205 ifndef KERN_INCL
206 KERN_INCL = $(KERN_DIR)/include
207 endif
208 ifneq ($(shell if test -d $(KERN_INCL); then echo yes; fi),yes)
209 $(error Error: unable to find the include directory for your current Linux \
210 kernel. Specify KERN_INCL=<directory> and run Make again)
211 endif
212
213 # module install dir, only for current kernel
214 ifneq ($(filter install install_rpm,$(MAKECMDGOALS)),)
215 ifndef MODULE_DIR
216 MODULE_DIR_TST := /lib/modules/$(shell uname -r)
217 ifeq ($(shell if test -d $(MODULE_DIR_TST); then echo yes; fi),yes)
218 MODULE_DIR := $(MODULE_DIR_TST)/misc
219 else
220 $(error Unable to find the folder to install the support driver to)
221 endif
222 endif # MODULE_DIR unspecified
223 endif
224
225else # neq($(KERNELRELEASE),)
226
227 #
228 # building from kbuild (make -C <kernel_directory> M=`pwd`)
229 #
230
231endif # neq($(KERNELRELEASE),)
232
233# debug - show guesses.
234ifdef DEBUG
235$(warning dbg: KERN_DIR = $(KERN_DIR))
236$(warning dbg: KERN_INCL = $(KERN_INCL))
237$(warning dbg: MODULE_DIR = $(MODULE_DIR))
238endif
239
240KBUILD_VERBOSE ?= 1
241
242#
243# Compiler options
244#
245ifndef INCL
246 INCL := $(addprefix -I,$(KERN_INCL) $(EXTRA_INCL))
247 ifndef KBUILD_EXTMOD
248 KBUILD_EXTMOD := $(shell pwd)
249 endif
250 INCL += $(addprefix -I$(KBUILD_EXTMOD),/ /include /r0drv/linux)
251 INCL += $(addprefix -I$(KBUILD_EXTMOD)/vboxdrv,/ /include /r0drv/linux)
252 ifdef VBOX_WITH_NATIVE_DTRACE
253 INCL += -I/usr/include/linux -I/usr/include
254 endif
255 export INCL
256endif
257ifneq ($(wildcard $(KBUILD_EXTMOD)/vboxdrv),)
258 MANGLING := $(KBUILD_EXTMOD)/vboxdrv/include/VBox/SUPDrvMangling.h
259else
260 MANGLING := $(KBUILD_EXTMOD)/include/VBox/SUPDrvMangling.h
261endif
262KFLAGS := -D__KERNEL__ -DMODULE -DRT_OS_LINUX -DIN_RING0 -DIN_RT_R0 \
263 -DIN_SUP_R0 -DVBOX -DRT_WITH_VBOX -DVBOX_WITH_HARDENING \
264 -DSUPDRV_WITH_RELEASE_LOGGER -DVBOX_WITH_EFLAGS_AC_SET_IN_VBOXDRV -DIPRT_WITH_EFLAGS_AC_PRESERVING \
265 -Wno-declaration-after-statement
266ifdef VBOX_REDHAT_KABI
267 KFLAGS += -DVBOX_REDHAT_KABI
268endif
269ifndef CONFIG_VBOXDRV_FIXEDMAJOR
270 KFLAGS += -DCONFIG_VBOXDRV_AS_MISC
271endif
272ifdef VBOX_WITH_NATIVE_DTRACE
273 KFLAGS += -DVBOX_WITH_NATIVE_DTRACE
274endif
275ifeq ($(BUILD_TARGET_ARCH),amd64)
276 KFLAGS += -DRT_ARCH_AMD64
277else
278 KFLAGS += -DRT_ARCH_X86
279endif
280# must be consistent with Config.kmk!
281KFLAGS += -DVBOX_WITH_64_BITS_GUESTS
282ifeq ($(BUILD_TYPE),debug)
283 KFLAGS += -DDEBUG -DDEBUG_$(USER) -g
284 # IPRT_DEBUG_SEMS indicates thread wrt sems state via the comm field.
285 #KFLAGS += -DIPRT_DEBUG_SEMS
286endif
287ifdef VBOX_WITH_TEXT_MODMEM_HACK
288 KFLAGS += -DRTMEMALLOC_EXEC_HEAP -DVBOX_WITH_TEXT_MODMEM_HACK
289endif
290
291# 2.6 and later
292MODULE_EXT := ko
293$(MODULE)-y := $(OBJS)
294
295# build defs
296EXTRA_CFLAGS += -include $(MANGLING) $(INCL) $(KFLAGS) $(KDEBUG) -fno-omit-frame-pointer -fno-pie
297
298all: $(MODULE)
299
300obj-m += $(MODULE).o
301
302JOBS := $(shell (getconf _NPROCESSORS_ONLN || grep -Ec '^processor|^CPU[0-9]' /proc/cpuinfo) 2>/dev/null)
303ifeq ($(JOBS),0)
304 JOBS := 1
305endif
306
307# OL/UEK: disable module signing for external modules -- we don't have any private key
308$(MODULE):
309 $(MAKE) KBUILD_VERBOSE=$(KBUILD_VERBOSE) SUBDIRS=$(CURDIR) SRCROOT=$(CURDIR) CONFIG_MODULE_SIG= -C $(KERN_DIR) -j$(JOBS) modules
310
311install: $(MODULE)
312 @mkdir -p $(MODULE_DIR); \
313 install -m 0644 -o root -g root $(MODULE).$(MODULE_EXT) $(MODULE_DIR); \
314 PATH="$(PATH):/bin:/sbin" depmod -a; \
315 rm -f /etc/vbox/module_not_compiled
316
317install_rpm: $(MODULE)
318 @mkdir -p $(MODULE_DIR); \
319 install -m 0644 $(MODULE).$(MODULE_EXT) $(MODULE_DIR)
320
321else # eq ($(MAKECMDGOALS),clean)
322
323 ifndef KERN_DIR
324 KERN_DIR := /lib/modules/$(shell uname -r)/build
325 ifeq ($(wildcard $(KERN_DIR)/Makefile),)
326 KERN_DIR := /usr/src/linux
327 endif
328 endif
329 ifeq ($(wildcard $(KERN_DIR)/Makefile),)
330
331clean:
332 find . \( -name \*.o -o -name \*.cmd \) -print0 | xargs -0 rm -f
333 rm -rf .tmp_ver* $(MODULE).* Module.symvers Modules.symvers modules.order
334
335 else
336
337clean:
338 $(MAKE) KBUILD_VERBOSE=$(KBUILD_VERBOSE) SUBDIRS=$(CURDIR) SRCROOT=$(CURDIR) -C $(KERN_DIR) clean
339
340 endif
341
342endif # eq($(MAKECMDGOALS),clean)
343
344check: $(MODULE)
345 @if ! readelf -p __ksymtab_strings vboxdrv.ko | grep -E "\[.*\] *(RT|g_..*RT.*)"; then \
346 echo "All exported IPRT symbols are properly renamed!"; \
347 else \
348 echo "error: Some exported IPRT symbols was not properly renamed! See above." >&2; \
349 false; \
350 fi
351
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use