Makefile revision f1630a6818621238c9c2338394b44995e318e108
75c0816e8295e180f4bc7f10db3d0d880383bc1cMark Andrews# VirtualBox Guest Additions Module Makefile.
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein# Copyright (C) 2006-2009 Sun Microsystems, Inc.
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein# This file is part of VirtualBox Open Source Edition (OSE), as
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein# available from http://www.virtualbox.org. This file is free software;
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein# you can redistribute it and/or modify it under the terms of the GNU
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein# General Public License (GPL) as published by the Free Software
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein# Foundation, in version 2 as it comes in the "COPYING" file of the
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein# VirtualBox OSE distribution. VirtualBox OSE is distributed in the
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein# hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
a1b05dea35aa30b152a47115e18bbe679d3fcf19Mark Andrews# Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein# Clara, CA 95054 USA or visit http://www.sun.com if you need
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein# additional information or have any questions.
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein# First, figure out which architecture we're targeting and the build type.
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein# (We have to support basic cross building (ARCH=i386|x86_64).)
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein# While at it, warn about BUILD_* vars found to help with user problems.
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austeinifeq ($(filter-out x86_64 amd64 AMD64,$(shell uname -m)),)
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austeinifneq ($(filter-out amd64 x86,$(BUILD_TARGET_ARCH)),)
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein $(warning Ignoring unknown BUILD_TARGET_ARCH value '$(BUILD_TARGET_ARCH)'.)
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein ifneq ($(BUILD_TARGET_ARCH),$(BUILD_TARGET_ARCH_DEF))
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein $(warning Using BUILD_TARGET_ARCH='$(BUILD_TARGET_ARCH)' from the $(origin BUILD_TARGET_ARCH).)
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austeinifneq ($(filter-out release profile debug strict,$(BUILD_TYPE)),)
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein $(warning Ignoring unknown BUILD_TYPE value '$(BUILD_TYPE)'.)
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein $(warning Using BUILD_TYPE='$(BUILD_TYPE)' from the $(origin BUILD_TYPE).)
a1b05dea35aa30b152a47115e18bbe679d3fcf19Mark Andrews# override is required by the Debian guys
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein # building from this directory
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein # kernel base directory
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein KERN_DIR := /lib/modules/$(shell uname -r)/build
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein ifneq ($(shell if test -d $(KERN_DIR); then echo yes; fi),yes)
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein ifneq ($(shell if test -d $(KERN_DIR); then echo yes; fi),yes)
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein $(error Error: unable to find the sources of your current Linux kernel. \
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein Specify KERN_DIR=<directory> and run Make again)
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein $(warning Warning: using /usr/src/linux as the source directory of your \
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein ifneq ($(shell if test -d $(KERN_DIR); then echo yes; fi),yes)
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein $(error Error: KERN_DIR does not point to a directory)
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein ifneq ($(shell if test -d $(KERN_INCL); then echo yes; fi),yes)
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews $(error Error: unable to find the include directory for your current Linux \
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews kernel. Specify KERN_INCL=<directory> and run Make again)
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews # module install dir, only for current kernel
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews ifneq ($(filter install install_rpm,$(MAKECMDGOALS)),)
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews MODULE_DIR_TST := /lib/modules/$(shell uname -r)
b05bdb520d83f7ecaad708fe305268c3420be01dMark Andrews ifeq ($(shell if test -d $(MODULE_DIR_TST); then echo yes; fi),yes)
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews $(error Unable to find the folder to install the additions driver to)
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein # guess kernel version (24 or 26)
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein ifeq ($(shell if grep '"2\.4\.' $(KERN_INCL)/linux/version.h > /dev/null; then echo yes; fi),yes)
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austeinelse # neq($(KERNELRELEASE),)
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein # building from kbuild (make -C <kernel_directory> M=`pwd`)
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein # guess kernel version (24 or 26)
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein ifeq ($(shell if echo "$(VERSION).$(PATCHLEVEL)." | grep '2\.4\.' > /dev/null; then echo yes; fi),yes)
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein# debug - show guesses.
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein# Compiler options
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein INCL := $(addprefix -I,$(KERN_INCL) $(EXTRA_INCL))
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein INCL += $(addprefix -I$(KBUILD_EXTMOD),/ /include /r0drv/linux)
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein -DVBOX -DRT_OS_LINUX -DIN_RING0 -DIN_RT_R0 -DIN_GUEST -DIN_GUEST_R0 \
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein -DIN_MODULE -DRT_WITH_VBOX -DVBGL_VBOXGUEST -DVBOX_WITH_HGCM
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein KFLAGS += -DRT_ARCH_AMD64 -DVBOX_WITH_64_BITS_GUESTS
ceeb18e6907a10547859faa340ecad83bedae90cMark AndrewsCFLAGS := -O2 -DVBOX_LINUX_2_4 -DEXPORT_SYMTAB $(INCL) $(KFLAGS) $(KDEBUG)
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein# 2.4 Module linking
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein# 2.6 and later
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein $(MAKE) KBUILD_VERBOSE=$(KBUILD_VERBOSE) -C $(KERN_DIR) SUBDIRS=$(CURDIR) SRCROOT=$(CURDIR) modules
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein install -m 0664 -o root -g root $(MODULE).$(MODULE_EXT) $(MODULE_DIR); \
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein for f in . linux r0drv r0drv/linux r0drv/generic VBox common/err common/string common/log generic common/math/gcc; \