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