Makefile revision e91f2a55ed5a30342ec79ce273f3f4bad8283336
98N/A# $Revision$
98N/A## @file
98N/A# VirtualBox Guest Additions Module Makefile.
98N/A#
908N/A
733N/A#
98N/A# Copyright (C) 2006-2010 Oracle Corporation
98N/A#
98N/A# This file is part of VirtualBox Open Source Edition (OSE), as
98N/A# available from http://www.virtualbox.org. This file is free software;
98N/A# you can redistribute it and/or modify it under the terms of the GNU
98N/A# General Public License (GPL) as published by the Free Software
98N/A# Foundation, in version 2 as it comes in the "COPYING" file of the
98N/A# VirtualBox OSE distribution. VirtualBox OSE is distributed in the
98N/A# hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
98N/A#
98N/A
98N/A#
98N/A# First, figure out which architecture we're targeting and the build type.
98N/A# (We have to support basic cross building (ARCH=i386|x86_64).)
98N/A# While at it, warn about BUILD_* vars found to help with user problems.
98N/A#
98N/Aifeq ($(filter-out x86_64 amd64 AMD64,$(shell uname -m)),)
98N/A BUILD_TARGET_ARCH_DEF := amd64
98N/Aelse
98N/A BUILD_TARGET_ARCH_DEF := x86
98N/Aendif
98N/Aifneq ($(filter-out amd64 x86,$(BUILD_TARGET_ARCH)),)
98N/A $(warning Ignoring unknown BUILD_TARGET_ARCH value '$(BUILD_TARGET_ARCH)'.)
98N/A BUILD_TARGET_ARCH :=
98N/Aendif
98N/Aifeq ($(BUILD_TARGET_ARCH),)
98N/A ifeq ($(ARCH),x86_64)
98N/A BUILD_TARGET_ARCH := amd64
235N/A else
156N/A ifeq ($(ARCH),i386)
156N/A BUILD_TARGET_ARCH := x86
156N/A else
156N/A BUILD_TARGET_ARCH := $(BUILD_TARGET_ARCH_DEF)
98N/A endif
98N/A endif
98N/Aelse
98N/A ifneq ($(BUILD_TARGET_ARCH),$(BUILD_TARGET_ARCH_DEF))
493N/A $(warning Using BUILD_TARGET_ARCH='$(BUILD_TARGET_ARCH)' from the $(origin BUILD_TARGET_ARCH).)
493N/A endif
98N/Aendif
911N/A
913N/Aifneq ($(filter-out release profile debug strict,$(BUILD_TYPE)),)
913N/A $(warning Ignoring unknown BUILD_TYPE value '$(BUILD_TYPE)'.)
911N/A BUILD_TYPE :=
98N/Aendif
235N/Aifeq ($(BUILD_TYPE),)
493N/A BUILD_TYPE := release
98N/Aelse
916N/A ifneq ($(BUILD_TYPE),release)
916N/A $(warning Using BUILD_TYPE='$(BUILD_TYPE)' from the $(origin BUILD_TYPE).)
916N/A endif
916N/Aendif
98N/A
98N/A
98N/A# override is required by the Debian guys
606N/Aoverride MODULE = vboxguest
98N/AOBJS = \
98N/A VBoxGuest-linux.o \
98N/A VBoxGuest.o \
606N/A VBoxGuest2.o \
606N/A GenericRequest.o \
98N/A HGCMInternal.o \
493N/A Init.o \
493N/A PhysHeap.o \
493N/A SysHlp.o \
98N/A VMMDev.o \
98N/A r0drv/alloc-r0drv.o \
98N/A r0drv/initterm-r0drv.o \
98N/A r0drv/memobj-r0drv.o \
908N/A r0drv/mpnotification-r0drv.o \
591N/A r0drv/powernotification-r0drv.o \
493N/A r0drv/linux/alloc-r0drv-linux.o \
493N/A r0drv/linux/assert-r0drv-linux.o \
493N/A r0drv/linux/initterm-r0drv-linux.o \
493N/A r0drv/linux/memobj-r0drv-linux.o \
493N/A r0drv/linux/memuserkernel-r0drv-linux.o \
493N/A r0drv/linux/mp-r0drv-linux.o \
493N/A r0drv/linux/mpnotification-r0drv-linux.o \
493N/A r0drv/linux/process-r0drv-linux.o \
493N/A r0drv/linux/semevent-r0drv-linux.o \
705N/A r0drv/linux/semeventmulti-r0drv-linux.o \
493N/A r0drv/linux/semfastmutex-r0drv-linux.o \
557N/A r0drv/linux/spinlock-r0drv-linux.o \
557N/A r0drv/linux/thread-r0drv-linux.o \
493N/A r0drv/linux/thread2-r0drv-linux.o \
493N/A r0drv/linux/time-r0drv-linux.o \
606N/A r0drv/linux/RTLogWriteDebugger-r0drv-linux.o \
606N/A r0drv/generic/semspinmutex-r0drv-generic.o \
851N/A common/alloc/alloc.o \
851N/A common/err/RTErrConvertFromErrno.o \
851N/A common/err/RTErrConvertToErrno.o \
851N/A common/log/log.o \
851N/A common/log/logellipsis.o \
851N/A common/log/logrel.o \
851N/A common/log/logrelellipsis.o \
98N/A common/log/logcom.o \
591N/A common/log/logformat.o \
910N/A common/misc/RTAssertMsg1Weak.o \
851N/A common/misc/RTAssertMsg2.o \
591N/A common/misc/RTAssertMsg2Add.o \
910N/A common/misc/RTAssertMsg2AddWeak.o \
910N/A common/misc/RTAssertMsg2AddWeakV.o \
910N/A common/misc/RTAssertMsg2Weak.o \
910N/A common/misc/RTAssertMsg2WeakV.o \
910N/A common/misc/assert.o \
910N/A common/misc/thread.o \
98N/A common/string/RTStrCopy.o \
98N/A common/string/strformat.o \
910N/A common/string/strformatrt.o \
910N/A common/string/strformattype.o \
910N/A common/string/strprintf.o \
98N/A common/string/strtonum.o \
606N/A common/table/avlpv.o \
98N/A common/time/time.o \
606N/A generic/RTAssertShouldPanic-generic.o \
98N/A generic/RTLogWriteStdErr-stub-generic.o \
591N/A generic/RTLogWriteStdOut-stub-generic.o \
851N/A generic/RTSemEventWait-2-ex-generic.o \
111N/A generic/RTSemEventWaitNoResume-2-ex-generic.o \
111N/A generic/RTSemEventMultiWait-2-ex-generic.o \
111N/A generic/RTSemEventMultiWaitNoResume-2-ex-generic.o \
111N/A VBox/log-vbox.o \
111N/A VBox/logbackdoor.o
606N/Aifeq ($(BUILD_TARGET_ARCH),x86)
851N/AOBJS += \
851N/A common/math/gcc/divdi3.o \
851N/A common/math/gcc/moddi3.o \
606N/A common/math/gcc/udivdi3.o \
98N/A common/math/gcc/umoddi3.o \
851N/A common/math/gcc/qdivrem.o
733N/Aendif
733N/Aifeq ($(BUILD_TARGET_ARCH),amd64)
733N/AOBJS += common/alloc/heapsimple.o
733N/Aendif
733N/A
606N/Aifneq ($(MAKECMDGOALS),clean)
851N/A
606N/Aifeq ($(KERNELRELEASE),)
98N/A
851N/A #
851N/A # building from this directory
851N/A #
851N/A
851N/A # kernel base directory
851N/A ifndef KERN_DIR
851N/A KERN_DIR := /lib/modules/$(shell uname -r)/build
212N/A ifneq ($(shell if test -d $(KERN_DIR); then echo yes; fi),yes)
851N/A KERN_DIR := /usr/src/linux
606N/A ifneq ($(shell if test -d $(KERN_DIR); then echo yes; fi),yes)
606N/A $(error Error: unable to find the sources of your current Linux kernel. \
606N/A Specify KERN_DIR=<directory> and run Make again)
606N/A endif
212N/A $(warning Warning: using /usr/src/linux as the source directory of your \
98N/A Linux kernel. If this is not correct, specify \
98N/A KERN_DIR=<directory> and run Make again.)
98N/A endif
98N/A else
182N/A ifneq ($(shell if test -d $(KERN_DIR); then echo yes; fi),yes)
98N/A $(error Error: KERN_DIR does not point to a directory)
908N/A endif
908N/A endif
# includes
ifndef KERN_INCL
KERN_INCL = $(KERN_DIR)/include
endif
ifneq ($(shell if test -d $(KERN_INCL); then echo yes; fi),yes)
$(error Error: unable to find the include directory for your current Linux \
kernel. Specify KERN_INCL=<directory> and run Make again)
endif
# module install dir, only for current kernel
ifneq ($(filter install install_rpm,$(MAKECMDGOALS)),)
ifndef MODULE_DIR
MODULE_DIR_TST := /lib/modules/$(shell uname -r)
ifeq ($(shell if test -d $(MODULE_DIR_TST); then echo yes; fi),yes)
MODULE_DIR := $(MODULE_DIR_TST)/misc
else
$(error Unable to find the folder to install the additions driver to)
endif
endif # MODULE_DIR unspecified
endif
# guess kernel version (24 or 26)
ifeq ($(shell if grep '"2\.4\.' $(KERN_INCL)/linux/version.h > /dev/null; then echo yes; fi),yes)
KERN_VERSION := 24
else
KERN_VERSION := 26
endif
else # neq($(KERNELRELEASE),)
#
# building from kbuild (make -C <kernel_directory> M=`pwd`)
#
# guess kernel version (24 or 26)
ifeq ($(shell if echo "$(VERSION).$(PATCHLEVEL)." | grep '2\.4\.' > /dev/null; then echo yes; fi),yes)
KERN_VERSION := 24
else
KERN_VERSION := 26
endif
endif # neq($(KERNELRELEASE),)
# debug - show guesses.
ifdef DEBUG
$(warning dbg: KERN_DIR = $(KERN_DIR))
$(warning dbg: KERN_INCL = $(KERN_INCL))
$(warning dbg: MODULE_DIR = $(MODULE_DIR))
$(warning dbg: KERN_VERSION = $(KERN_VERSION))
endif
KBUILD_VERBOSE ?= 1
#
# Compiler options
#
ifndef INCL
INCL := $(addprefix -I,$(KERN_INCL) $(EXTRA_INCL))
ifndef KBUILD_EXTMOD
KBUILD_EXTMOD := $(shell pwd)
endif
INCL += $(addprefix -I$(KBUILD_EXTMOD),/ /include /r0drv/linux)
INCL += $(addprefix -I$(KBUILD_EXTMOD)/vboxguest,/ /include /r0drv/linux)
export INCL
endif
KFLAGS := -D__KERNEL__ -DMODULE \
-DVBOX -DRT_OS_LINUX -DIN_RING0 -DIN_RT_R0 -DIN_GUEST -DIN_GUEST_R0 \
-DIN_MODULE -DRT_WITH_VBOX -DVBGL_VBOXGUEST -DVBOX_WITH_HGCM
ifeq ($(BUILD_TARGET_ARCH),amd64)
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 $(KBUILD_EXTMOD)/include/VBox/VBoxGuestMangling.h $(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