Makefile revision 37136b5ecb07042e5ba50f86849a79d1cba5d5f1
253N/A#
253N/A# VirtualBox Guest Additions Module Makefile.
253N/A#
253N/A# (For 2.6.x this file must be 'Makefile'!)
253N/A#
253N/A# Copyright (C) 2006-2007 Sun Microsystems, Inc.
253N/A#
253N/A# This file is part of VirtualBox Open Source Edition (OSE), as
253N/A# available from http://www.virtualbox.org. This file is free software;
253N/A# you can redistribute it and/or modify it under the terms of the GNU
253N/A# General Public License (GPL) as published by the Free Software
253N/A# Foundation, in version 2 as it comes in the "COPYING" file of the
253N/A# VirtualBox OSE distribution. VirtualBox OSE is distributed in the
253N/A# hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
253N/A#
253N/A# Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
253N/A# Clara, CA 95054 USA or visit http://www.sun.com if you need
253N/A# additional information or have any questions.
253N/A#
253N/A
5361N/A#
253N/A# First, figure out which architecture we're targeting and the build type.
253N/A# (We have to support basic cross building (ARCH=i386|x86_64).)
253N/A# While at it, warn about BUILD_* vars found to help with user problems.
783N/A#
253N/Aifeq ($(filter-out x86_64 amd64 AMD64,$(shell uname -m)),)
253N/A BUILD_TARGET_ARCH_DEF := amd64
253N/Aelse
253N/A BUILD_TARGET_ARCH_DEF := x86
253N/Aendif
253N/Aifneq ($(filter-out amd64 x86,$(BUILD_TARGET_ARCH)),)
844N/A $(warning Ignoring unknown BUILD_TARGET_ARCH value '$(BUILD_TARGET_ARCH)'.)
844N/A BUILD_TARGET_ARCH :=
253N/Aendif
1258N/Aifeq ($(BUILD_TARGET_ARCH),)
253N/A ifeq ($(ARCH),x86_64)
253N/A BUILD_TARGET_ARCH := amd64
844N/A else
844N/A ifeq ($(ARCH),i386)
253N/A BUILD_TARGET_ARCH := x86
253N/A else
3514N/A BUILD_TARGET_ARCH := $(BUILD_TARGET_ARCH_DEF)
2899N/A endif
3817N/A endif
3817N/Aelse
3817N/A ifneq ($(BUILD_TARGET_ARCH),$(BUILD_TARGET_ARCH_DEF))
3817N/A $(warning Using BUILD_TARGET_ARCH='$(BUILD_TARGET_ARCH)' from the $(origin BUILD_TARGET_ARCH).)
253N/A endif
253N/Aendif
253N/A
253N/Aifneq ($(filter-out release profile debug strict,$(BUILD_TYPE)),)
253N/A $(warning Ignoring unknown BUILD_TYPE value '$(BUILD_TYPE)'.)
253N/A BUILD_TYPE :=
253N/Aendif
253N/Aifeq ($(BUILD_TYPE),)
253N/A BUILD_TYPE := release
253N/Aelse
253N/A ifneq ($(BUILD_TYPE),release)
253N/A $(warning Using BUILD_TYPE='$(BUILD_TYPE)' from the $(origin BUILD_TYPE).)
253N/A endif
253N/Aendif
253N/A
253N/A
253N/A# override is required by the Debian guys
253N/Aoverride MODULE = vboxguest
253N/AOBJS = \
4044N/A VBoxGuest-linux.o \
4044N/A VBoxGuest.o \
4044N/A GenericRequest.o \
3823N/A HGCMInternal.o \
3823N/A Init.o \
3823N/A PhysHeap.o \
4044N/A SysHlp.o \
4044N/A VMMDev.o \
4044N/A r0drv/alloc-r0drv.o \
4044N/A r0drv/initterm-r0drv.o \
4044N/A r0drv/memobj-r0drv.o \
4044N/A r0drv/mpnotification-r0drv.o \
4044N/A r0drv/powernotification-r0drv.o \
4044N/A r0drv/linux/alloc-r0drv-linux.o \
4044N/A r0drv/linux/assert-r0drv-linux.o \
4044N/A r0drv/linux/initterm-r0drv-linux.o \
4044N/A r0drv/linux/memobj-r0drv-linux.o \
4044N/A r0drv/linux/mp-r0drv-linux.o \
4044N/A r0drv/linux/mpnotification-r0drv-linux.o \
3823N/A r0drv/linux/process-r0drv-linux.o \
3823N/A r0drv/linux/semevent-r0drv-linux.o \
3823N/A r0drv/linux/semeventmulti-r0drv-linux.o \
3823N/A r0drv/linux/semfastmutex-r0drv-linux.o \
3823N/A r0drv/linux/thread-r0drv-linux.o \
3823N/A RTErrConvertFromErrno.o \
3823N/A RTErrConvertToErrno.o \
3823N/A divdi3.o \
253N/A moddi3.o \
253N/A udivdi3.o \
253N/A umoddi3.o \
253N/A qdivrem.o \
253N/A logbackdoor.o \
253N/A logformat.o \
253N/A strformat.o \
253N/A strformatrt.o \
5361N/A strformattype.o \
253N/A strprintf.o \
253N/A strformat-vbox.o \
253N/A RTAssertShouldPanic-generic.o
253N/Aifeq ($(BUILD_TARGET_ARCH),amd64)
253N/AOBJS += \
253N/A alloc/heapsimple.o \
253N/A r0drv/linux/spinlock-r0drv-linux.o
253N/Aendif
253N/A
253N/Aifneq ($(MAKECMDGOALS),clean)
253N/A
253N/Aifeq ($(KERNELRELEASE),)
253N/A
253N/A #
253N/A # building from this directory
253N/A #
253N/A
253N/A # kernel base directory
253N/A ifndef KERN_DIR
253N/A KERN_DIR := /lib/modules/$(shell uname -r)/build
253N/A ifneq ($(shell if test -d $(KERN_DIR); then echo yes; fi),yes)
253N/A KERN_DIR := /usr/src/linux
253N/A ifneq ($(shell if test -d $(KERN_DIR); then echo yes; fi),yes)
253N/A $(error Error: unable to find the sources of your current Linux kernel. \
253N/A Specify KERN_DIR=<directory> and run Make again)
253N/A endif
253N/A $(warning Warning: using /usr/src/linux as the source directory of your \
253N/A Linux kernel. If this is not correct, specify \
253N/A KERN_DIR=<directory> and run Make again.)
253N/A endif
253N/A else
253N/A ifneq ($(shell if test -d $(KERN_DIR); then echo yes; fi),yes)
253N/A $(error Error: KERN_DIR does not point to a directory)
253N/A endif
253N/A endif
253N/A
253N/A # includes
253N/A ifndef KERN_INCL
253N/A KERN_INCL = $(KERN_DIR)/include
253N/A endif
253N/A ifneq ($(shell if test -d $(KERN_INCL); then echo yes; fi),yes)
253N/A $(error Error: unable to find the include directory for your current Linux \
253N/A kernel. Specify KERN_INCL=<directory> and run Make again)
2375N/A endif
2375N/A
3477N/A # module install dir, only for current kernel
3477N/A ifneq ($(filter install install_rpm,$(MAKECMDGOALS)),)
253N/A ifndef MODULE_DIR
253N/A MODULE_DIR_TST := /lib/modules/$(shell uname -r)
253N/A ifeq ($(shell if test -d $(MODULE_DIR_TST); then echo yes; fi),yes)
253N/A MODULE_DIR := $(MODULE_DIR_TST)/misc
253N/A else
253N/A $(error Unable to find the folder to install the additions driver to)
253N/A endif
253N/A endif # MODULE_DIR unspecified
253N/A endif
253N/A
253N/A # guess kernel version (24 or 26)
253N/A ifeq ($(shell if grep '"2\.4\.' $(KERN_INCL)/linux/version.h > /dev/null; then echo yes; fi),yes)
253N/A KERN_VERSION := 24
253N/A else
253N/A KERN_VERSION := 26
253N/A endif
253N/A
253N/Aelse # neq($(KERNELRELEASE),)
253N/A
253N/A #
253N/A # building from kbuild (make -C <kernel_directory> M=`pwd`)
4337N/A #
4337N/A
3817N/A # 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)
export INCL
endif
KFLAGS := -D__KERNEL__ -DMODULE -DRT_OS_LINUX -DIN_RING0 \
-DIN_RT_R0 -DIN_SUP_R0 -DVBOX -DVBGL_VBOXGUEST -DVBOX_WITH_HGCM \
-DLOG_TO_BACKDOOR -DRT_WITH_VBOX -DIN_MODULE -DIN_GUEST_R0
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
#
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 += $(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 -ae;
endif # eq($(MAKECMDGOALS),clean)
clean:
for f in . linux r0drv r0drv/linux; do rm -f $$f/*.o $$f/.*.cmd $$f/.*.flags; done
rm -rf .vboxguest* .tmp_ver* vboxguest.* Module.symvers Modules.symvers modules.order