VirtualBox

Ignore:
Timestamp:
Sep 6, 2017 2:54:29 PM (8 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.

Location:
trunk/src/VBox/HostDrivers/VBoxNetFlt/linux
Files:
2 edited

Legend:

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

    r67293 r68682  
    11#
    22# Makefile for the VirtualBox Linux Host Network Filter Driver.
    3 # (For 2.6.x this file must be called 'Makefile'!)
    43#
    54
    65#
    76#
    8 # Copyright (C) 2006-2015 Oracle Corporation
     7# Copyright (C) 2006-2017 Oracle Corporation
    98#
    109# This file is part of VirtualBox Open Source Edition (OSE), as
     
    1716#
    1817
    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.
     18# Linux kbuild sets this to our source directory if we are called from
     19# there
     20obj ?= $(CURDIR)
     21include $(obj)/Makefile.include.header
    2222
    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 = vboxnetflt
    67 OBJS   = \
     23MOD_NAME = vboxnetflt
     24MOD_OBJS = \
    6825        linux/VBoxNetFlt-linux.o \
    6926        VBoxNetFlt.o \
     
    7330
    7431ifeq ($(BUILD_TARGET_ARCH),x86)
    75 OBJS += math/gcc/divdi3.o \
     32MOD_OBJS += math/gcc/divdi3.o \
    7633        math/gcc/moddi3.o \
    7734        math/gcc/qdivrem.o \
     
    8239endif
    8340
    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)/vboxnetflt,/ /include /r0drv/linux)
    160  export INCL
    161 endif
    162 ifneq ($(wildcard $(KBUILD_EXTMOD)/vboxnetflt),)
    163  MANGLING := $(KBUILD_EXTMOD)/vboxnetflt/include/VBox/SUPDrvMangling.h
     41MOD_INCL = $(addprefix -I$(KBUILD_EXTMOD),/ /include /r0drv/linux)
     42MOD_DEFS = -DRT_OS_LINUX -DIN_RING0 -DIN_RT_R0 \
     43        -DIN_SUP_R0 -DVBOX -DRT_WITH_VBOX -DVBOX_WITH_HARDENING \
     44        -Wno-declaration-after-statement
     45ifeq ($(BUILD_TARGET_ARCH),amd64)
     46 MOD_DEFS += -DRT_ARCH_AMD64
    16447else
    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             -Wno-declaration-after-statement
    170 ifdef VBOX_REDHAT_KABI
    171  KFLAGS  += -DVBOX_REDHAT_KABI
    172 endif
    173 ifeq ($(BUILD_TARGET_ARCH),amd64)
    174  KFLAGS  += -DRT_ARCH_AMD64
    175 else
    176  KFLAGS  += -DRT_ARCH_X86
     48 MOD_DEFS += -DRT_ARCH_X86
    17749endif
    17850# must be consistent with Config.kmk!
    179 KFLAGS  += -DVBOX_WITH_64_BITS_GUESTS
    180 ifeq ($(BUILD_TYPE),debug)
    181  KFLAGS  += -DDEBUG -DDEBUG_$(USER) -g
    182  # IPRT_DEBUG_SEMS indicates thread wrt sems state via the comm field.
    183  #KFLAGS  += -DIPRT_DEBUG_SEMS
    184 endif
     51MOD_DEFS += -DVBOX_WITH_64_BITS_GUESTS
    18552
    18653# By default we use remap_pfn_range() kernel API to make kernel pages
     
    19663endif
    19764
    198 MODULE_EXT    := ko
    199 $(MODULE)-y   := $(OBJS)
     65# build defs
     66MOD_CFLAGS = -include $(KBUILD_EXTMOD)/include/VBox/SUPDrvMangling.h -fno-pie
    20067
    201 # build defs
    202 EXTRA_CFLAGS  += -include $(MANGLING) $(INCL) $(KFLAGS) $(KDEBUG) -fno-pie
    203 
    204 all: $(MODULE)
    205 
    206 obj-m += $(MODULE).o
    207 
    208 JOBS := $(shell (getconf _NPROCESSORS_ONLN || grep -Ec '^processor|^CPU[0-9]' /proc/cpuinfo) 2>/dev/null)
    209 ifeq ($(JOBS),0)
    210   JOBS := 1
    211 endif
    212 
    213 # OL/UEK: disable module signing for external modules -- we don't have any private key
    214 $(MODULE):
    215         $(MAKE) KBUILD_VERBOSE=$(KBUILD_VERBOSE) SUBDIRS=$(CURDIR) SRCROOT=$(CURDIR) CONFIG_MODULE_SIG= -C $(KERN_DIR) -j$(JOBS) modules
    216 
    217 install: $(MODULE)
    218         @mkdir -p $(MODULE_DIR); \
    219         install -m 0644 -o root -g root $(MODULE).$(MODULE_EXT) $(MODULE_DIR); \
    220         PATH="$(PATH):/bin:/sbin" depmod -a; \
    221         rm -f /etc/vbox/module_not_compiled
    222 
    223 install_rpm: $(MODULE)
    224         @mkdir -p $(MODULE_DIR); \
    225         install -m 0644 $(MODULE).$(MODULE_EXT) $(MODULE_DIR)
    226 
    227 else # eq ($(MAKECMDGOALS),clean)
    228 
    229  ifndef KERN_DIR
    230   KERN_DIR := /lib/modules/$(shell uname -r)/build
    231   ifeq ($(wildcard $(KERN_DIR)/Makefile),)
    232    KERN_DIR := /usr/src/linux
    233   endif
    234  endif
    235  ifeq ($(wildcard $(KERN_DIR)/Makefile),)
    236 
    237 clean:
    238         find . \( -name \*.o -o -name \*.cmd \) -print0 | xargs -0 rm -f
    239         rm -rf .tmp_ver* $(MODULE).* Module.symvers Modules.symvers modules.order
    240 
    241  else
    242 
    243 clean:
    244         $(MAKE) KBUILD_VERBOSE=$(KBUILD_VERBOSE) SUBDIRS=$(CURDIR) SRCROOT=$(CURDIR) -C $(KERN_DIR) clean
    245 
    246  endif
    247 
    248 endif # eq($(MAKECMDGOALS),clean)
     68include $(obj)/Makefile.include.footer
  • trunk/src/VBox/HostDrivers/VBoxNetFlt/linux/files_vboxnetflt

    r67295 r68682  
    7474    ${PATH_ROOT}/src/VBox/HostDrivers/Support/SUPR0IdcClientInternal.h=>SUPR0IdcClientInternal.h \
    7575    ${PATH_ROOT}/src/VBox/HostDrivers/Support/linux/SUPR0IdcClient-linux.c=>linux/SUPR0IdcClient-linux.c \
     76    ${PATH_ROOT}/src/VBox/Installer/linux/Makefile.include.footer=>Makefile.include.footer \
     77    ${PATH_ROOT}/src/VBox/Installer/linux/Makefile.include.header=>Makefile.include.header \
    7678    ${PATH_ROOT}/src/VBox/Runtime/common/math/gcc/divdi3.c=>math/gcc/divdi3.c \
    7779    ${PATH_ROOT}/src/VBox/Runtime/common/math/gcc/moddi3.c=>math/gcc/moddi3.c \
Note: See TracChangeset for help on using the changeset viewer.

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