[37798] | 1 | #
|
---|
| 2 | # Makefile for the VirtualBox Linux Host PCI Driver.
|
---|
| 3 | # (For 2.6.x this file must be called 'Makefile'!)
|
---|
| 4 | #
|
---|
| 5 |
|
---|
| 6 | #
|
---|
| 7 | #
|
---|
[56293] | 8 | # Copyright (C) 2011-2015 Oracle Corporation
|
---|
[37798] | 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 |
|
---|
[67063] | 19 | ## @todo If you make non-trivial changes to this make file, please consider
|
---|
| 20 | # rewriting it to use Makefile.include.header and
|
---|
| 21 | # Makefile.include.footer.
|
---|
| 22 |
|
---|
[37798] | 23 | #
|
---|
| 24 | # First, figure out which architecture we're targeting and the build type.
|
---|
| 25 | # (We have to support basic cross building (ARCH=i386|x86_64).)
|
---|
| 26 | # While at it, warn about BUILD_* vars found to help with user problems.
|
---|
| 27 | #
|
---|
| 28 | ifeq ($(filter-out x86_64 amd64 AMD64,$(shell uname -m)),)
|
---|
| 29 | BUILD_TARGET_ARCH_DEF := amd64
|
---|
| 30 | else
|
---|
| 31 | BUILD_TARGET_ARCH_DEF := x86
|
---|
| 32 | endif
|
---|
| 33 | ifneq ($(filter-out amd64 x86,$(BUILD_TARGET_ARCH)),)
|
---|
| 34 | $(warning Ignoring unknown BUILD_TARGET_ARCH value '$(BUILD_TARGET_ARCH)'.)
|
---|
| 35 | BUILD_TARGET_ARCH :=
|
---|
| 36 | endif
|
---|
| 37 | ifeq ($(BUILD_TARGET_ARCH),)
|
---|
| 38 | ifeq ($(ARCH),x86_64)
|
---|
| 39 | BUILD_TARGET_ARCH := amd64
|
---|
| 40 | else
|
---|
| 41 | ifeq ($(ARCH),i386)
|
---|
| 42 | BUILD_TARGET_ARCH := x86
|
---|
| 43 | else
|
---|
| 44 | BUILD_TARGET_ARCH := $(BUILD_TARGET_ARCH_DEF)
|
---|
| 45 | endif
|
---|
| 46 | endif
|
---|
| 47 | else
|
---|
| 48 | ifneq ($(BUILD_TARGET_ARCH),$(BUILD_TARGET_ARCH_DEF))
|
---|
| 49 | $(warning Using BUILD_TARGET_ARCH='$(BUILD_TARGET_ARCH)' from the $(origin BUILD_TARGET_ARCH).)
|
---|
| 50 | endif
|
---|
| 51 | endif
|
---|
| 52 |
|
---|
| 53 | ifneq ($(filter-out release profile debug strict,$(BUILD_TYPE)),)
|
---|
| 54 | $(warning Ignoring unknown BUILD_TYPE value '$(BUILD_TYPE)'.)
|
---|
| 55 | BUILD_TYPE :=
|
---|
| 56 | endif
|
---|
| 57 | ifeq ($(BUILD_TYPE),)
|
---|
| 58 | BUILD_TYPE := release
|
---|
| 59 | else
|
---|
| 60 | ifneq ($(BUILD_TYPE),release)
|
---|
| 61 | $(warning Using BUILD_TYPE='$(BUILD_TYPE)' from the $(origin BUILD_TYPE).)
|
---|
| 62 | endif
|
---|
| 63 | endif
|
---|
| 64 |
|
---|
| 65 | # override is required by the Debian guys
|
---|
| 66 | override MODULE = vboxpci
|
---|
| 67 | OBJS = \
|
---|
| 68 | linux/VBoxPci-linux.o \
|
---|
| 69 | VBoxPci.o \
|
---|
| 70 | SUPR0IdcClient.o \
|
---|
| 71 | SUPR0IdcClientComponent.o \
|
---|
| 72 | linux/SUPR0IdcClient-linux.o
|
---|
| 73 |
|
---|
| 74 | ifeq ($(BUILD_TARGET_ARCH),x86)
|
---|
| 75 | OBJS += math/gcc/divdi3.o \
|
---|
| 76 | math/gcc/moddi3.o \
|
---|
| 77 | math/gcc/qdivrem.o \
|
---|
| 78 | math/gcc/udivdi3.o \
|
---|
[67293] | 79 | math/gcc/udivmoddi4.o \
|
---|
[37798] | 80 | math/gcc/divdi3.o \
|
---|
| 81 | math/gcc/umoddi3.o
|
---|
| 82 | endif
|
---|
| 83 |
|
---|
| 84 | ifneq ($(MAKECMDGOALS),clean)
|
---|
| 85 |
|
---|
| 86 | ifeq ($(KERNELRELEASE),)
|
---|
| 87 |
|
---|
| 88 | #
|
---|
| 89 | # building from this directory
|
---|
| 90 | #
|
---|
| 91 |
|
---|
| 92 | # kernel base directory
|
---|
| 93 | ifndef KERN_DIR
|
---|
| 94 | # build for the current kernel, version check
|
---|
| 95 | KERN_DIR := /lib/modules/$(shell uname -r)/build
|
---|
| 96 | ifneq ($(shell if test -d $(KERN_DIR); then echo yes; fi),yes)
|
---|
| 97 | KERN_DIR := /usr/src/linux
|
---|
| 98 | ifneq ($(shell if test -d $(KERN_DIR); then echo yes; fi),yes)
|
---|
| 99 | $(error Error: unable to find the sources of your current Linux kernel. \
|
---|
| 100 | Specify KERN_DIR=<directory> and run Make again)
|
---|
| 101 | endif
|
---|
| 102 | $(warning Warning: using /usr/src/linux as the source directory of your \
|
---|
| 103 | Linux kernel. If this is not correct, specify \
|
---|
| 104 | KERN_DIR=<directory> and run Make again.)
|
---|
| 105 | endif
|
---|
| 106 | else
|
---|
| 107 | ifneq ($(shell if test -d $(KERN_DIR); then echo yes; fi),yes)
|
---|
| 108 | $(error Error: KERN_DIR does not point to a directory)
|
---|
| 109 | endif
|
---|
| 110 | endif
|
---|
| 111 |
|
---|
| 112 | # includes
|
---|
| 113 | ifndef KERN_INCL
|
---|
| 114 | KERN_INCL = $(KERN_DIR)/include
|
---|
| 115 | endif
|
---|
| 116 | ifneq ($(shell if test -d $(KERN_INCL); then echo yes; fi),yes)
|
---|
| 117 | $(error Error: unable to find the include directory for your current Linux \
|
---|
| 118 | kernel. Specify KERN_INCL=<directory> and run Make again)
|
---|
| 119 | endif
|
---|
| 120 |
|
---|
| 121 | # module install dir, only for current kernel
|
---|
| 122 | ifneq ($(filter install install_rpm,$(MAKECMDGOALS)),)
|
---|
| 123 | ifndef MODULE_DIR
|
---|
| 124 | MODULE_DIR_TST := /lib/modules/$(shell uname -r)
|
---|
| 125 | ifeq ($(shell if test -d $(MODULE_DIR_TST); then echo yes; fi),yes)
|
---|
| 126 | MODULE_DIR := $(MODULE_DIR_TST)/misc
|
---|
| 127 | else
|
---|
| 128 | $(error Unable to find the folder to install the support driver to)
|
---|
| 129 | endif
|
---|
| 130 | endif # MODULE_DIR unspecified
|
---|
| 131 | endif
|
---|
| 132 |
|
---|
| 133 | else # neq($(KERNELRELEASE),)
|
---|
| 134 |
|
---|
| 135 | #
|
---|
| 136 | # building from kbuild (make -C <kernel_directory> M=`pwd`)
|
---|
| 137 | #
|
---|
| 138 |
|
---|
| 139 | endif # neq($(KERNELRELEASE),)
|
---|
| 140 |
|
---|
| 141 | # debug - show guesses.
|
---|
| 142 | ifdef DEBUG
|
---|
| 143 | $(warning dbg: KERN_DIR = $(KERN_DIR))
|
---|
| 144 | $(warning dbg: KERN_INCL = $(KERN_INCL))
|
---|
| 145 | $(warning dbg: MODULE_DIR = $(MODULE_DIR))
|
---|
| 146 | endif
|
---|
| 147 |
|
---|
| 148 | KBUILD_VERBOSE ?= 1
|
---|
| 149 |
|
---|
| 150 | #
|
---|
| 151 | # Compiler options
|
---|
| 152 | #
|
---|
| 153 | ifndef INCL
|
---|
| 154 | INCL := $(addprefix -I,$(KERN_INCL) $(EXTRA_INCL))
|
---|
| 155 | ifndef KBUILD_EXTMOD
|
---|
| 156 | KBUILD_EXTMOD := $(shell pwd)
|
---|
| 157 | endif
|
---|
| 158 | INCL += $(addprefix -I$(KBUILD_EXTMOD),/ /include /r0drv/linux)
|
---|
| 159 | INCL += $(addprefix -I$(KBUILD_EXTMOD)/vboxpci,/ /include /r0drv/linux)
|
---|
| 160 | export INCL
|
---|
| 161 | endif
|
---|
| 162 | ifneq ($(wildcard $(KBUILD_EXTMOD)/vboxpci),)
|
---|
| 163 | MANGLING := $(KBUILD_EXTMOD)/vboxpci/include/VBox/SUPDrvMangling.h
|
---|
| 164 | else
|
---|
| 165 | MANGLING := $(KBUILD_EXTMOD)/include/VBox/SUPDrvMangling.h
|
---|
| 166 | endif
|
---|
| 167 | KFLAGS := -D__KERNEL__ -DMODULE -DRT_OS_LINUX -DIN_RING0 -DIN_RT_R0 \
|
---|
| 168 | -DIN_SUP_R0 -DVBOX -DRT_WITH_VBOX -DVBOX_WITH_HARDENING
|
---|
| 169 | ifdef VBOX_REDHAT_KABI
|
---|
| 170 | KFLAGS += -DVBOX_REDHAT_KABI
|
---|
| 171 | endif
|
---|
| 172 | ifeq ($(BUILD_TARGET_ARCH),amd64)
|
---|
| 173 | KFLAGS += -DRT_ARCH_AMD64
|
---|
| 174 | else
|
---|
| 175 | KFLAGS += -DRT_ARCH_X86
|
---|
| 176 | endif
|
---|
| 177 | # must be consistent with Config.kmk!
|
---|
| 178 | KFLAGS += -DVBOX_WITH_64_BITS_GUESTS
|
---|
| 179 | ifeq ($(BUILD_TYPE),debug)
|
---|
| 180 | KFLAGS += -DDEBUG -DDEBUG_$(USER) -g
|
---|
| 181 | # IPRT_DEBUG_SEMS indicates thread wrt sems state via the comm field.
|
---|
| 182 | #KFLAGS += -DIPRT_DEBUG_SEMS
|
---|
| 183 | endif
|
---|
| 184 |
|
---|
| 185 | # By default we use remap_pfn_range() kernel API to make kernel pages
|
---|
| 186 | # visible for userland. Unfortunately, it leads to situation that
|
---|
| 187 | # during debug session all structures on that page (such as PVM pointer)
|
---|
| 188 | # are not accessible to the debugger (see #3214).
|
---|
| 189 | # This code enables experimental support
|
---|
| 190 | # for vm_insert_page() kernel API, allowing to export kernel pages
|
---|
| 191 | # to the userland in more debugger-friendly way. Due to stability
|
---|
| 192 | # concerns, not enabled by default yet.
|
---|
| 193 | ifdef VBOX_USE_INSERT_PAGE
|
---|
| 194 | KFLAGS += -DVBOX_USE_INSERT_PAGE
|
---|
| 195 | endif
|
---|
| 196 |
|
---|
| 197 | MODULE_EXT := ko
|
---|
| 198 | $(MODULE)-y := $(OBJS)
|
---|
| 199 |
|
---|
| 200 | # build defs
|
---|
[61081] | 201 | EXTRA_CFLAGS += -include $(MANGLING) $(INCL) $(KFLAGS) $(KDEBUG) -fno-pie
|
---|
[37798] | 202 |
|
---|
| 203 | all: $(MODULE)
|
---|
| 204 |
|
---|
| 205 | obj-m += $(MODULE).o
|
---|
| 206 |
|
---|
[61411] | 207 | JOBS := $(shell (getconf _NPROCESSORS_ONLN || grep -Ec '^processor|^CPU[0-9]' /proc/cpuinfo) 2>/dev/null)
|
---|
| 208 | ifeq ($(JOBS),0)
|
---|
| 209 | JOBS := 1
|
---|
| 210 | endif
|
---|
| 211 |
|
---|
[39400] | 212 | # OL/UEK: disable module signing for external modules -- we don't have any private key
|
---|
[37798] | 213 | $(MODULE):
|
---|
[61411] | 214 | $(MAKE) KBUILD_VERBOSE=$(KBUILD_VERBOSE) SUBDIRS=$(CURDIR) SRCROOT=$(CURDIR) CONFIG_MODULE_SIG= -C $(KERN_DIR) -j$(JOBS) modules
|
---|
[37798] | 215 |
|
---|
| 216 | install: $(MODULE)
|
---|
| 217 | @mkdir -p $(MODULE_DIR); \
|
---|
[59453] | 218 | install -m 0644 -o root -g root $(MODULE).$(MODULE_EXT) $(MODULE_DIR); \
|
---|
[37798] | 219 | PATH="$(PATH):/bin:/sbin" depmod -a;
|
---|
| 220 |
|
---|
| 221 | install_rpm: $(MODULE)
|
---|
| 222 | @mkdir -p $(MODULE_DIR); \
|
---|
[59453] | 223 | install -m 0644 $(MODULE).$(MODULE_EXT) $(MODULE_DIR)
|
---|
[37798] | 224 |
|
---|
| 225 | else # eq ($(MAKECMDGOALS),clean)
|
---|
| 226 |
|
---|
| 227 | ifndef KERN_DIR
|
---|
| 228 | KERN_DIR := /lib/modules/$(shell uname -r)/build
|
---|
| 229 | ifeq ($(wildcard $(KERN_DIR)/Makefile),)
|
---|
| 230 | KERN_DIR := /usr/src/linux
|
---|
| 231 | endif
|
---|
| 232 | endif
|
---|
| 233 | ifeq ($(wildcard $(KERN_DIR)/Makefile),)
|
---|
| 234 |
|
---|
| 235 | clean:
|
---|
| 236 | find . \( -name \*.o -o -name \*.cmd \) -print0 | xargs -0 rm -f
|
---|
| 237 | rm -rf .tmp_ver* $(MODULE).* Module.symvers Modules.symvers modules.order
|
---|
| 238 |
|
---|
| 239 | else
|
---|
| 240 |
|
---|
| 241 | clean:
|
---|
| 242 | $(MAKE) KBUILD_VERBOSE=$(KBUILD_VERBOSE) SUBDIRS=$(CURDIR) SRCROOT=$(CURDIR) -C $(KERN_DIR) clean
|
---|
| 243 |
|
---|
| 244 | endif
|
---|
| 245 |
|
---|
| 246 | endif # eq($(MAKECMDGOALS),clean)
|
---|