VirtualBox

Ignore:
Timestamp:
Sep 6, 2017 2:54:29 PM (7 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
117913
Message:

Drivers/Linux: make host kernel modules use make file templates.
bugref:4567: Linux kernel driver maintenance

Rework the make files from the host kernel drivers to use the
Makefile.include.header and Makefile.include.footer templates, and clean up
some obsolete scripting in the make files.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/HostDrivers/Support/linux/Makefile

    r67293 r68682  
    66#
    77#
    8 # Copyright (C) 2006-2015 Oracle Corporation
     8# Copyright (C) 2006-2017 Oracle Corporation
    99#
    1010# This file is part of VirtualBox Open Source Edition (OSE), as
     
    2626#
    2727
    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.
     28# Linux kbuild sets this to our source directory if we are called from
     29# there
     30obj ?= $(CURDIR)
     31include $(obj)/Makefile.include.header
    3132
    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 #
    37 ifeq ($(filter-out x86_64 amd64 AMD64,$(shell uname -m)),)
    38  BUILD_TARGET_ARCH_DEF := amd64
    39 else
    40  BUILD_TARGET_ARCH_DEF := x86
    41 endif
    42 ifneq ($(filter-out amd64 x86,$(BUILD_TARGET_ARCH)),)
    43  $(warning Ignoring unknown BUILD_TARGET_ARCH value '$(BUILD_TARGET_ARCH)'.)
    44  BUILD_TARGET_ARCH :=
    45 endif
    46 ifeq ($(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
    56 else
    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
    60 endif
    61 
    62 ifneq ($(filter-out release profile debug strict,$(BUILD_TYPE)),)
    63  $(warning Ignoring unknown BUILD_TYPE value '$(BUILD_TYPE)'.)
    64  BUILD_TYPE :=
    65 endif
    66 ifeq ($(BUILD_TYPE),)
    67  BUILD_TYPE := release
    68 else
    69  ifneq ($(BUILD_TYPE),release)
    70   $(warning Using BUILD_TYPE='$(BUILD_TYPE)' from the $(origin BUILD_TYPE).)
    71  endif
    72 endif
    73 
    74 # override is required by the Debian guys
    75 override MODULE = vboxdrv
    76 OBJS   = \
     33MOD_NAME = vboxdrv
     34MOD_OBJS = \
    7735        linux/SUPDrv-linux.o \
    7836        SUPDrv.o \
     
    159117        VBox/log-vbox.o
    160118ifeq ($(BUILD_TARGET_ARCH),x86)
    161 OBJS += math/gcc/divdi3.o \
     119 MOD_OBJS += math/gcc/divdi3.o \
    162120        math/gcc/moddi3.o \
    163121        math/gcc/qdivrem.o \
     
    168126endif
    169127ifeq ($(BUILD_TARGET_ARCH),amd64)
    170 OBJS += common/alloc/heapsimple.o
     128 MOD_OBJS += common/alloc/heapsimple.o
    171129endif
    172130ifdef VBOX_WITH_NATIVE_DTRACE
    173 OBJS += SUPDrvDTrace.o
     131 MOD_OBJS += SUPDrvDTrace.o
    174132endif
    175133
    176 ifneq ($(MAKECMDGOALS),clean)
    177 
    178 ifeq ($(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 
    225 else # neq($(KERNELRELEASE),)
    226 
    227  #
    228  # building from kbuild (make -C <kernel_directory> M=`pwd`)
    229  #
    230 
    231 endif # neq($(KERNELRELEASE),)
    232 
    233 # debug - show guesses.
    234 ifdef DEBUG
    235 $(warning dbg: KERN_DIR     = $(KERN_DIR))
    236 $(warning dbg: KERN_INCL    = $(KERN_INCL))
    237 $(warning dbg: MODULE_DIR   = $(MODULE_DIR))
     134MOD_INCL  = $(addprefix -I$(KBUILD_EXTMOD),/ /include /r0drv/linux)
     135ifdef VBOX_WITH_NATIVE_DTRACE
     136 MOD_INCL += -I/usr/include/linux -I/usr/include
     137endif
     138MOD_DEFS = -DRT_OS_LINUX -DIN_RING0 -DIN_RT_R0 -DIN_SUP_R0 -DVBOX \
     139        -DRT_WITH_VBOX -DVBOX_WITH_HARDENING -DSUPDRV_WITH_RELEASE_LOGGER \
     140        -DVBOX_WITH_EFLAGS_AC_SET_IN_VBOXDRV -DIPRT_WITH_EFLAGS_AC_PRESERVING \
     141    -Wno-declaration-after-statement
     142ifndef CONFIG_VBOXDRV_FIXEDMAJOR
     143 MOD_DEFS += -DCONFIG_VBOXDRV_AS_MISC
     144endif
     145ifdef VBOX_WITH_NATIVE_DTRACE
     146 MOD_DEFS += -DVBOX_WITH_NATIVE_DTRACE
     147endif
     148ifeq ($(BUILD_TARGET_ARCH),amd64)
     149 MOD_DEFS += -DRT_ARCH_AMD64
     150else
     151 MOD_DEFS += -DRT_ARCH_X86
     152endif
     153# must be consistent with Config.kmk!
     154MOD_DEFS += -DVBOX_WITH_64_BITS_GUESTS
     155ifdef VBOX_WITH_TEXT_MODMEM_HACK
     156 MOD_DEFS += -DRTMEMALLOC_EXEC_HEAP -DVBOX_WITH_TEXT_MODMEM_HACK
    238157endif
    239158
    240 KBUILD_VERBOSE ?= 1
     159# build defs
     160MOD_CFLAGS = -include $(KBUILD_EXTMOD)/include/VBox/SUPDrvMangling.h \
     161        -fno-omit-frame-pointer -fno-pie
    241162
    242 #
    243 # Compiler options
    244 #
    245 ifndef 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
    256 endif
    257 ifneq ($(wildcard $(KBUILD_EXTMOD)/vboxdrv),)
    258  MANGLING := $(KBUILD_EXTMOD)/vboxdrv/include/VBox/SUPDrvMangling.h
    259 else
    260  MANGLING := $(KBUILD_EXTMOD)/include/VBox/SUPDrvMangling.h
    261 endif
    262 KFLAGS   := -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
    266 ifdef VBOX_REDHAT_KABI
    267  KFLAGS  += -DVBOX_REDHAT_KABI
    268 endif
    269 ifndef CONFIG_VBOXDRV_FIXEDMAJOR
    270  KFLAGS  += -DCONFIG_VBOXDRV_AS_MISC
    271 endif
    272 ifdef VBOX_WITH_NATIVE_DTRACE
    273  KFLAGS  += -DVBOX_WITH_NATIVE_DTRACE
    274 endif
    275 ifeq ($(BUILD_TARGET_ARCH),amd64)
    276  KFLAGS  += -DRT_ARCH_AMD64
    277 else
    278  KFLAGS  += -DRT_ARCH_X86
    279 endif
    280 # must be consistent with Config.kmk!
    281 KFLAGS  += -DVBOX_WITH_64_BITS_GUESTS
    282 ifeq ($(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
    286 endif
    287 ifdef VBOX_WITH_TEXT_MODMEM_HACK
    288  KFLAGS += -DRTMEMALLOC_EXEC_HEAP -DVBOX_WITH_TEXT_MODMEM_HACK
    289 endif
    290 
    291 # 2.6 and later
    292 MODULE_EXT    := ko
    293 $(MODULE)-y   := $(OBJS)
    294 
    295 # build defs
    296 EXTRA_CFLAGS  += -include $(MANGLING) $(INCL) $(KFLAGS) $(KDEBUG) -fno-omit-frame-pointer -fno-pie
    297 
    298 all: $(MODULE)
    299 
    300 obj-m += $(MODULE).o
    301 
    302 JOBS := $(shell (getconf _NPROCESSORS_ONLN || grep -Ec '^processor|^CPU[0-9]' /proc/cpuinfo) 2>/dev/null)
    303 ifeq ($(JOBS),0)
    304   JOBS := 1
    305 endif
    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 
    311 install: $(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 
    317 install_rpm: $(MODULE)
    318         @mkdir -p $(MODULE_DIR); \
    319         install -m 0644 $(MODULE).$(MODULE_EXT) $(MODULE_DIR)
    320 
    321 else # 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 
    331 clean:
    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 
    337 clean:
    338         $(MAKE) KBUILD_VERBOSE=$(KBUILD_VERBOSE) SUBDIRS=$(CURDIR) SRCROOT=$(CURDIR) -C $(KERN_DIR) clean
    339 
    340  endif
    341 
    342 endif # eq($(MAKECMDGOALS),clean)
     163include $(obj)/Makefile.include.footer
    343164
    344165check: $(MODULE)
     
    349170            false; \
    350171         fi
    351 
Note: See TracChangeset for help on using the changeset viewer.

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