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