Makefile revision b39c3fa81cadaec00ebb2e7170a8db96998b7032
2N/A# $Revision$
2N/A## @file
2N/A# VirtualBox Guest Additions Module Makefile.
2N/A#
2N/A
2N/A#
2N/A# Copyright (C) 2006-2010 Oracle Corporation
2N/A#
2N/A# This file is part of VirtualBox Open Source Edition (OSE), as
2N/A# available from http://www.virtualbox.org. This file is free software;
2N/A# you can redistribute it and/or modify it under the terms of the GNU
2N/A# General Public License (GPL) as published by the Free Software
2N/A# Foundation, in version 2 as it comes in the "COPYING" file of the
2N/A# VirtualBox OSE distribution. VirtualBox OSE is distributed in the
2N/A# hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
2N/A#
2N/A
2N/A#
2N/A# First, figure out which architecture we're targeting and the build type.
2N/A# (We have to support basic cross building (ARCH=i386|x86_64).)
2N/A# While at it, warn about BUILD_* vars found to help with user problems.
2N/A#
2N/Aifeq ($(filter-out x86_64 amd64 AMD64,$(shell uname -m)),)
2N/A BUILD_TARGET_ARCH_DEF := amd64
2N/Aelse
2N/A BUILD_TARGET_ARCH_DEF := x86
2N/Aendif
2N/Aifneq ($(filter-out amd64 x86,$(BUILD_TARGET_ARCH)),)
2N/A $(warning Ignoring unknown BUILD_TARGET_ARCH value '$(BUILD_TARGET_ARCH)'.)
2N/A BUILD_TARGET_ARCH :=
2N/Aendif
2N/Aifeq ($(BUILD_TARGET_ARCH),)
2N/A ifeq ($(ARCH),x86_64)
2N/A BUILD_TARGET_ARCH := amd64
2N/A else
2N/A ifeq ($(ARCH),i386)
2N/A BUILD_TARGET_ARCH := x86
2N/A else
2N/A BUILD_TARGET_ARCH := $(BUILD_TARGET_ARCH_DEF)
2N/A endif
2N/A endif
2N/Aelse
2N/A ifneq ($(BUILD_TARGET_ARCH),$(BUILD_TARGET_ARCH_DEF))
2N/A $(warning Using BUILD_TARGET_ARCH='$(BUILD_TARGET_ARCH)' from the $(origin BUILD_TARGET_ARCH).)
2N/A endif
2N/Aendif
2N/A
2N/Aifneq ($(filter-out release profile debug strict,$(BUILD_TYPE)),)
2N/A $(warning Ignoring unknown BUILD_TYPE value '$(BUILD_TYPE)'.)
2N/A BUILD_TYPE :=
2N/Aendif
2N/Aifeq ($(BUILD_TYPE),)
2N/A BUILD_TYPE := release
2N/Aelse
2N/A ifneq ($(BUILD_TYPE),release)
2N/A $(warning Using BUILD_TYPE='$(BUILD_TYPE)' from the $(origin BUILD_TYPE).)
2N/A endif
2N/Aendif
2N/A
2N/A
2N/A# override is required by the Debian guys
2N/Aoverride MODULE = vboxguest
2N/AOBJS = \
2N/A VBoxGuest-linux.o \
2N/A VBoxGuest.o \
2N/A VBoxGuest2.o \
2N/A GenericRequest.o \
2N/A HGCMInternal.o \
2N/A Init.o \
2N/A PhysHeap.o \
2N/A SysHlp.o \
2N/A VMMDev.o \
2N/A r0drv/alloc-r0drv.o \
2N/A r0drv/initterm-r0drv.o \
2N/A r0drv/memobj-r0drv.o \
2N/A r0drv/mpnotification-r0drv.o \
2N/A r0drv/powernotification-r0drv.o \
2N/A r0drv/linux/alloc-r0drv-linux.o \
2N/A r0drv/linux/assert-r0drv-linux.o \
2N/A r0drv/linux/initterm-r0drv-linux.o \
2N/A r0drv/linux/memobj-r0drv-linux.o \
2N/A r0drv/linux/memuserkernel-r0drv-linux.o \
2N/A r0drv/linux/mp-r0drv-linux.o \
2N/A r0drv/linux/mpnotification-r0drv-linux.o \
2N/A r0drv/linux/process-r0drv-linux.o \
2N/A r0drv/linux/semevent-r0drv-linux.o \
2N/A r0drv/linux/semeventmulti-r0drv-linux.o \
2N/A r0drv/linux/semfastmutex-r0drv-linux.o \
2N/A r0drv/linux/spinlock-r0drv-linux.o \
2N/A r0drv/linux/thread-r0drv-linux.o \
2N/A r0drv/linux/thread2-r0drv-linux.o \
2N/A r0drv/linux/time-r0drv-linux.o \
2N/A r0drv/linux/RTLogWriteDebugger-r0drv-linux.o \
2N/A r0drv/generic/semspinmutex-r0drv-generic.o \
2N/A common/alloc/alloc.o \
2N/A common/err/RTErrConvertFromErrno.o \
2N/A common/err/RTErrConvertToErrno.o \
2N/A common/log/log.o \
2N/A common/log/logellipsis.o \
2N/A common/log/logrel.o \
2N/A common/log/logrelellipsis.o \
2N/A common/log/logcom.o \
2N/A common/log/logformat.o \
2N/A common/misc/RTAssertMsg1Weak.o \
2N/A common/misc/RTAssertMsg2.o \
2N/A common/misc/RTAssertMsg2Add.o \
2N/A common/misc/RTAssertMsg2AddWeak.o \
2N/A common/misc/RTAssertMsg2AddWeakV.o \
2N/A common/misc/RTAssertMsg2Weak.o \
2N/A common/misc/RTAssertMsg2WeakV.o \
2N/A common/misc/assert.o \
2N/A common/misc/thread.o \
2N/A common/string/RTStrCopy.o \
2N/A common/string/strformat.o \
2N/A common/string/strformatrt.o \
2N/A common/string/strformattype.o \
2N/A common/string/strprintf.o \
2N/A common/string/strtonum.o \
2N/A common/table/avlpv.o \
2N/A common/time/time.o \
2N/A generic/RTAssertShouldPanic-generic.o \
2N/A generic/RTLogWriteStdErr-stub-generic.o \
2N/A generic/RTLogWriteStdOut-stub-generic.o \
2N/A generic/RTSemEventWait-2-ex-generic.o \
2N/A generic/RTSemEventWaitNoResume-2-ex-generic.o \
2N/A generic/RTSemEventMultiWait-2-ex-generic.o \
2N/A generic/RTSemEventMultiWaitNoResume-2-ex-generic.o \
2N/A VBox/log-vbox.o \
2N/A VBox/logbackdoor.o
2N/Aifeq ($(BUILD_TARGET_ARCH),x86)
2N/AOBJS += \
2N/A common/math/gcc/divdi3.o \
2N/A common/math/gcc/moddi3.o \
2N/A common/math/gcc/udivdi3.o \
2N/A common/math/gcc/umoddi3.o \
2N/A common/math/gcc/qdivrem.o
2N/Aendif
2N/Aifeq ($(BUILD_TARGET_ARCH),amd64)
2N/AOBJS += common/alloc/heapsimple.o
2N/Aendif
2N/A
2N/Aifneq ($(MAKECMDGOALS),clean)
2N/A
2N/Aifeq ($(KERNELRELEASE),)
2N/A
2N/A #
2N/A # building from this directory
2N/A #
2N/A
2N/A # kernel base directory
2N/A ifndef KERN_DIR
2N/A KERN_DIR := /lib/modules/$(shell uname -r)/build
2N/A ifneq ($(shell if test -d $(KERN_DIR); then echo yes; fi),yes)
2N/A KERN_DIR := /usr/src/linux
2N/A ifneq ($(shell if test -d $(KERN_DIR); then echo yes; fi),yes)
2N/A $(error Error: unable to find the sources of your current Linux kernel. \
2N/A Specify KERN_DIR=<directory> and run Make again)
2N/A endif
2N/A $(warning Warning: using /usr/src/linux as the source directory of your \
2N/A Linux kernel. If this is not correct, specify \
2N/A KERN_DIR=<directory> and run Make again.)
2N/A endif
2N/A else
2N/A ifneq ($(shell if test -d $(KERN_DIR); then echo yes; fi),yes)
2N/A $(error Error: KERN_DIR does not point to a directory)
2N/A endif
2N/A endif
2N/A
2N/A # includes
2N/A ifndef KERN_INCL
2N/A KERN_INCL = $(KERN_DIR)/include
2N/A endif
2N/A ifneq ($(shell if test -d $(KERN_INCL); then echo yes; fi),yes)
2N/A $(error Error: unable to find the include directory for your current Linux \
2N/A kernel. Specify KERN_INCL=<directory> and run Make again)
2N/A endif
2N/A
2N/A # module install dir, only for current kernel
2N/A ifneq ($(filter install install_rpm,$(MAKECMDGOALS)),)
2N/A ifndef MODULE_DIR
2N/A MODULE_DIR_TST := /lib/modules/$(shell uname -r)
2N/A ifeq ($(shell if test -d $(MODULE_DIR_TST); then echo yes; fi),yes)
2N/A MODULE_DIR := $(MODULE_DIR_TST)/misc
2N/A else
2N/A $(error Unable to find the folder to install the additions driver to)
2N/A endif
2N/A endif # MODULE_DIR unspecified
2N/A endif
2N/A
2N/A # guess kernel version (24 or 26)
2N/A ifeq ($(shell if grep '"2\.4\.' $(KERN_INCL)/linux/version.h > /dev/null; then echo yes; fi),yes)
2N/A KERN_VERSION := 24
2N/A else
2N/A KERN_VERSION := 26
2N/A endif
2N/A
2N/Aelse # neq($(KERNELRELEASE),)
2N/A
2N/A #
2N/A # building from kbuild (make -C <kernel_directory> M=`pwd`)
2N/A #
2N/A
2N/A # guess kernel version (24 or 26)
2N/A ifeq ($(shell if echo "$(VERSION).$(PATCHLEVEL)." | grep '2\.4\.' > /dev/null; then echo yes; fi),yes)
2N/A KERN_VERSION := 24
2N/A else
2N/A KERN_VERSION := 26
2N/A endif
2N/A
2N/Aendif # neq($(KERNELRELEASE),)
2N/A
2N/A# debug - show guesses.
2N/Aifdef DEBUG
2N/A$(warning dbg: KERN_DIR = $(KERN_DIR))
2N/A$(warning dbg: KERN_INCL = $(KERN_INCL))
2N/A$(warning dbg: MODULE_DIR = $(MODULE_DIR))
2N/A$(warning dbg: KERN_VERSION = $(KERN_VERSION))
2N/Aendif
2N/A
2N/AKBUILD_VERBOSE ?= 1
2N/A
2N/A#
2N/A# Compiler options
2N/A#
2N/Aifndef INCL
2N/A INCL := $(addprefix -I,$(KERN_INCL) $(EXTRA_INCL))
2N/A ifndef KBUILD_EXTMOD
2N/A KBUILD_EXTMOD := $(shell pwd)
2N/A endif
2N/A INCL += $(addprefix -I$(KBUILD_EXTMOD),/ /include /r0drv/linux)
2N/A INCL += $(addprefix -I$(KBUILD_EXTMOD)/vboxguest,/ /include /r0drv/linux)
2N/A export INCL
2N/Aendif
2N/Aifneq ($(wildcard $(KBUILD_EXTMOD)/vboxguest),)
2N/A MANGLING := $(KBUILD_EXTMOD)/vboxguest/include/VBox/VBoxGuestMangling.h
2N/Aelse
2N/A MANGLING := $(KBUILD_EXTMOD)/include/VBox/VBoxGuestMangling.h
2N/Aendif
2N/AKFLAGS := -D__KERNEL__ -DMODULE \
2N/A -DVBOX -DRT_OS_LINUX -DIN_RING0 -DIN_RT_R0 -DIN_GUEST -DIN_GUEST_R0 \
2N/A -DIN_MODULE -DRT_WITH_VBOX -DVBGL_VBOXGUEST -DVBOX_WITH_HGCM
2N/Aifeq ($(BUILD_TARGET_ARCH),amd64)
2N/A KFLAGS += -DRT_ARCH_AMD64 -DVBOX_WITH_64_BITS_GUESTS
2N/Aelse
2N/A KFLAGS += -DRT_ARCH_X86
2N/Aendif
2N/Aifeq ($(BUILD_TYPE),debug)
2N/AKFLAGS += -DDEBUG
2N/Aendif
2N/A
2N/Aifeq ($(KERN_VERSION), 24)
2N/A#
2N/A# 2.4
2N/A#
2N/A
2N/Aifeq ($(BUILD_TARGET_ARCH),amd64)
2N/A KFLAGS += -mcmodel=kernel
2N/Aendif
2N/A
2N/ACFLAGS := -O2 -DVBOX_LINUX_2_4 -DEXPORT_SYMTAB $(INCL) $(KFLAGS) $(KDEBUG)
2N/AMODULE_EXT := o
2N/A
2N/A# 2.4 Module linking
2N/A$(MODULE).o: $(OBJS)
2N/A $(LD) -o $@ -r $(OBJS)
2N/A
2N/A.PHONY: $(MODULE)
2N/Aall: $(MODULE)
2N/A$(MODULE): $(MODULE).o
2N/A
2N/Aelse
2N/A#
2N/A# 2.6 and later
2N/A#
2N/A
2N/AMODULE_EXT := ko
2N/A
2N/A$(MODULE)-y := $(OBJS)
2N/A
2N/A# build defs
2N/AEXTRA_CFLAGS += -include $(MANGLING) $(INCL) $(KFLAGS) $(KDEBUG)
2N/A
2N/Aall: $(MODULE)
2N/A
2N/Aobj-m += $(MODULE).o
2N/A
2N/A$(MODULE):
2N/A $(MAKE) KBUILD_VERBOSE=$(KBUILD_VERBOSE) -C $(KERN_DIR) SUBDIRS=$(CURDIR) SRCROOT=$(CURDIR) modules
2N/A
2N/Aendif
2N/A
2N/Ainstall: $(MODULE)
2N/A @mkdir -p $(MODULE_DIR); \
2N/A install -m 0664 -o root -g root $(MODULE).$(MODULE_EXT) $(MODULE_DIR); \
2N/A PATH="$(PATH):/bin:/sbin" depmod -a;
2N/A
2N/Aendif # eq($(MAKECMDGOALS),clean)
2N/A
2N/Acheck: $(MODULE)
2N/A @if ! readelf -p __ksymtab_strings vboxguest.ko | grep -E "\[.*\] *(RT|g_..*RT.*)"; then \
2N/A echo "All exported IPRT symbols are properly renamed!"; \
2N/A else \
2N/A echo "error: Some exported IPRT symbols was not properly renamed! See above." >&2; \
2N/A false; \
2N/A fi
2N/A
2N/Aclean:
2N/A for f in . linux r0drv generic r0drv/linux r0drv/generic VBox \
2N/A common/alloc common/err common/log common/math/gcc common/misc common/string common/time; \
2N/A do rm -f $$f/*.o $$f/.*.cmd $$f/.*.flags; done
2N/A rm -rf .vboxguest* .tmp_ver* vboxguest.* Module.symvers Modules.symvers modules.order
2N/A