Makefile.module revision 8b21d158f0a2cf0965e0bd696837785403231cbe
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync# VirtualBox Guest Additions Module Makefile.
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync# (For 2.6.x this file must be 'Makefile'!)
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync# Copyright (C) 2006-2007 Sun Microsystems, Inc.
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync# This file is part of VirtualBox Open Source Edition (OSE), as
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync# available from http://www.virtualbox.org. This file is free software;
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync# you can redistribute it and/or modify it under the terms of the GNU
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync# General Public License (GPL) as published by the Free Software
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync# Foundation, in version 2 as it comes in the "COPYING" file of the
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync# VirtualBox OSE distribution. VirtualBox OSE is distributed in the
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync# hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
1c94c0a63ba68be1a7b2c640e70d7a06464e4fcavboxsync# Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
1c94c0a63ba68be1a7b2c640e70d7a06464e4fcavboxsync# Clara, CA 95054 USA or visit http://www.sun.com if you need
1c94c0a63ba68be1a7b2c640e70d7a06464e4fcavboxsync# additional information or have any questions.
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync# First, figure out which architecture we're targeting and the build type.
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync# (We have to support basic cross building (ARCH=i386|x86_64).)
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync# While at it, warn about BUILD_* vars found to help with user problems.
b0dfb334954c0552bb583967a3077ec88fd00471vboxsyncifneq ($(filter-out amd64 x86,$(BUILD_TARGET_ARCH)),)
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync $(warning Ignoring unknown BUILD_TARGET_ARCH value '$(BUILD_TARGET_ARCH)'.)
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsync BUILD_TARGET_ARCH :=
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsyncifeq ($(BUILD_TARGET_ARCH),)
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync ifeq ($(ARCH),x86_64)
c312e1b81dffe42e0fb766020fb8defaeade05d6vboxsync BUILD_TARGET_ARCH := amd64
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync ifeq ($(ARCH),i386)
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync BUILD_TARGET_ARCH := x86
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync ifeq ($(filter-out x86_64 amd64 AMD64,$(shell uname -m)),)
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync BUILD_TARGET_ARCH := amd64
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync BUILD_TARGET_ARCH := x86
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync $(warning Using BUILD_TARGET_ARCH='$(BUILD_TARGET_ARCH)' from the $(origin BUILD_TARGET_ARCH).)
b0dfb334954c0552bb583967a3077ec88fd00471vboxsyncifneq ($(filter-out release profile debug strict,$(BUILD_TYPE)),)
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync $(warning Ignoring unknown BUILD_TYPE value '$(BUILD_TYPE)'.)
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync BUILD_TYPE :=
b0dfb334954c0552bb583967a3077ec88fd00471vboxsyncifeq ($(BUILD_TYPE),)
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync BUILD_TYPE := release
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync $(warning Using BUILD_TYPE='$(BUILD_TYPE)' from the $(origin BUILD_TYPE).)
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync# override is required by the Debian guys
b0dfb334954c0552bb583967a3077ec88fd00471vboxsyncoverride MODULE = vboxadd
50f0e2e83362e100d306a411980d555d46aa00a8vboxsyncifeq ($(BUILD_TARGET_ARCH),amd64)
b0dfb334954c0552bb583967a3077ec88fd00471vboxsyncifneq ($(MAKECMDGOALS),clean)
b0dfb334954c0552bb583967a3077ec88fd00471vboxsyncifeq ($(KERNELRELEASE),)
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync # building from this directory
80523be8dba75b5eb32569fd72ddf54f3b009025vboxsync # kernel base directory
80523be8dba75b5eb32569fd72ddf54f3b009025vboxsync ifndef KERN_DIR
80523be8dba75b5eb32569fd72ddf54f3b009025vboxsync KERN_DIR := /lib/modules/$(shell uname -r)/build
80523be8dba75b5eb32569fd72ddf54f3b009025vboxsync ifneq ($(shell if test -d $(KERN_DIR); then echo yes; fi),yes)
80523be8dba75b5eb32569fd72ddf54f3b009025vboxsync ifneq ($(shell if test -d $(KERN_DIR); then echo yes; fi),yes)
80523be8dba75b5eb32569fd72ddf54f3b009025vboxsync $(error Error: unable to find the sources of your current Linux kernel. \
80523be8dba75b5eb32569fd72ddf54f3b009025vboxsync Specify KERN_DIR=<directory> and run Make again)
80523be8dba75b5eb32569fd72ddf54f3b009025vboxsync $(warning Warning: using /usr/src/linux as the source directory of your \
80523be8dba75b5eb32569fd72ddf54f3b009025vboxsync Linux kernel. If this is not correct, specify \
80523be8dba75b5eb32569fd72ddf54f3b009025vboxsync KERN_DIR=<directory> and run Make again.)
80523be8dba75b5eb32569fd72ddf54f3b009025vboxsync ifneq ($(shell if test -d $(KERN_DIR); then echo yes; fi),yes)
80523be8dba75b5eb32569fd72ddf54f3b009025vboxsync $(error Error: KERN_DIR does not point to a directory)
8d29e9dc0d280b7b26834132b9ce14a3a845a7fdvboxsync ifndef KERN_INCL
8d29e9dc0d280b7b26834132b9ce14a3a845a7fdvboxsync KERN_INCL = $(KERN_DIR)/include
8d29e9dc0d280b7b26834132b9ce14a3a845a7fdvboxsync ifneq ($(shell if test -d $(KERN_INCL); then echo yes; fi),yes)
5d05aa26ae1949e6f0bbc149d8b8e39495710ac7vboxsync $(error Error: unable to find the include directory for your current Linux \
5d05aa26ae1949e6f0bbc149d8b8e39495710ac7vboxsync kernel. Specify KERN_INCL=<directory> and run Make again)
8d29e9dc0d280b7b26834132b9ce14a3a845a7fdvboxsync # module install dir.
5d05aa26ae1949e6f0bbc149d8b8e39495710ac7vboxsync ifneq ($(filter install install_rpm,$(MAKECMDGOALS)),)
5d05aa26ae1949e6f0bbc149d8b8e39495710ac7vboxsync ifndef MODULE_DIR
5d05aa26ae1949e6f0bbc149d8b8e39495710ac7vboxsync MODULE_DIR_TST := /lib/modules/$(shell uname -r)
5d05aa26ae1949e6f0bbc149d8b8e39495710ac7vboxsync ifeq ($(shell if test -d $(MODULE_DIR_TST); then echo yes; fi),yes)
5d05aa26ae1949e6f0bbc149d8b8e39495710ac7vboxsync MODULE_DIR := $(MODULE_DIR_TST)/misc
5d05aa26ae1949e6f0bbc149d8b8e39495710ac7vboxsync $(error Unable to find the folder to install the additions driver to)
5d05aa26ae1949e6f0bbc149d8b8e39495710ac7vboxsync endif # MODULE_DIR unspecified
b60e4b0625949fd68ed97f1353e2174c5b3192e5vboxsync # guess kernel version (24 or 26)
b60e4b0625949fd68ed97f1353e2174c5b3192e5vboxsync ifeq ($(shell if grep '"2\.4\.' $(KERN_INCL)/linux/version.h > /dev/null; then echo yes; fi),yes)
8d29e9dc0d280b7b26834132b9ce14a3a845a7fdvboxsync KERN_VERSION := 24
8d29e9dc0d280b7b26834132b9ce14a3a845a7fdvboxsync KERN_VERSION := 26
8d29e9dc0d280b7b26834132b9ce14a3a845a7fdvboxsyncelse # neq($(KERNELRELEASE),)
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsync # building from kbuild (make -C <kernel_directory> M=`pwd`)
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsync # guess kernel version (24 or 26)
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsync ifeq ($(shell if grep '"2\.4\.' $(PWD)/include/linux/version.h > /dev/null; then echo yes; fi),yes)
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsync KERN_VERSION := 24
052deaa01d8fcd5cec4dff857833538940b751c3vboxsync KERN_VERSION := 26
052deaa01d8fcd5cec4dff857833538940b751c3vboxsyncendif # neq($(KERNELRELEASE),)
052deaa01d8fcd5cec4dff857833538940b751c3vboxsync# debug - show guesses.
052deaa01d8fcd5cec4dff857833538940b751c3vboxsync$(warning dbg: KERN_DIR = $(KERN_DIR))
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsync$(warning dbg: KERN_INCL = $(KERN_INCL))
755f4438e1e3a66f23230126b7df46d51006ac24vboxsync$(warning dbg: MODULE_DIR = $(MODULE_DIR))
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsync$(warning dbg: KERN_VERSION = $(KERN_VERSION))
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsync# Compiler options
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsync INCL := $(addprefix -I,$(KERN_INCL) $(EXTRA_INCL))
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsync ifndef KBUILD_EXTMOD
755f4438e1e3a66f23230126b7df46d51006ac24vboxsync KBUILD_EXTMOD := $(shell pwd)
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsync INCL += $(addprefix -I$(KBUILD_EXTMOD),/ /include /r0drv/linux)
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsync export INCL
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsyncKFLAGS := -D__KERNEL__ -DMODULE -DRT_OS_LINUX -DIN_RING0 \
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsync -DIN_RT_R0 -DIN_SUP_R0 -DVBOX -DVBGL_VBOXGUEST -DVBOX_WITH_HGCM \
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsync -DLOG_TO_BACKDOOR -DRT_WITH_VBOX -DIN_MODULE -DIN_GUEST_R0
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsyncifeq ($(BUILD_TARGET_ARCH),amd64)
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsync KFLAGS += -DRT_ARCH_AMD64 -DVBOX_WITH_64_BITS_GUESTS
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsync KFLAGS += -DRT_ARCH_X86
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsyncifeq ($(BUILD_TYPE),debug)
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsyncKFLAGS += -DDEBUG
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsyncifeq ($(KERN_VERSION), 24)
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsyncCFLAGS := -O2 -DVBOX_LINUX_2_4 -DEXPORT_SYMTAB $(INCL) $(KFLAGS) $(KDEBUG)
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsyncMODULE_EXT := o
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsync# 2.4 Module linking
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsync$(MODULE).o: $(OBJS)
1e2bc03fd1fc133bd3a066b1557471e157df78f6vboxsync $(LD) -o $@ -r $(OBJS)
1e2bc03fd1fc133bd3a066b1557471e157df78f6vboxsync.PHONY: $(MODULE)
1e2bc03fd1fc133bd3a066b1557471e157df78f6vboxsyncall: $(MODULE)
1e2bc03fd1fc133bd3a066b1557471e157df78f6vboxsync$(MODULE): $(MODULE).o
1e2bc03fd1fc133bd3a066b1557471e157df78f6vboxsync# 2.6 and later
39a628c9e979cb2355caa57eb099b13cb922783cvboxsyncMODULE_EXT := ko
26bef2fb65df80a28b9972e0a43a92be367417d9vboxsync$(MODULE)-y := $(OBJS)
1e2bc03fd1fc133bd3a066b1557471e157df78f6vboxsync# build defs
1e2bc03fd1fc133bd3a066b1557471e157df78f6vboxsyncEXTRA_CFLAGS += $(INCL) $(KFLAGS) $(KDEBUG)
1e2bc03fd1fc133bd3a066b1557471e157df78f6vboxsyncall: $(MODULE)
39a628c9e979cb2355caa57eb099b13cb922783cvboxsyncobj-m += $(MODULE).o
d308e8fdb9e4d827ed10d26d1581d265602f6f46vboxsync $(MAKE) KBUILD_VERBOSE=1 -C $(KERN_DIR) SUBDIRS=$(CURDIR) SRCROOT=$(CURDIR) modules
5bcfdf9ef0306239498361e5021d008ad77bf539vboxsyncinstall: $(MODULE)
5bcfdf9ef0306239498361e5021d008ad77bf539vboxsync @mkdir -p $(MODULE_DIR); \
7dbde0174637fbfd00c50b383f654e46878eaa8evboxsync install -m 0664 -o root -g root $(MODULE).$(MODULE_EXT) $(MODULE_DIR); \
5bcfdf9ef0306239498361e5021d008ad77bf539vboxsync PATH="$(PATH):/bin:/sbin" depmod -ae;
5bcfdf9ef0306239498361e5021d008ad77bf539vboxsyncendif # eq($(MAKECMDGOALS),clean)
5bcfdf9ef0306239498361e5021d008ad77bf539vboxsync for f in . linux r0drv r0drv/linux; do rm -f $$f/*.o $$f/.*.cmd $$f/.*.flags; done
7dbde0174637fbfd00c50b383f654e46878eaa8evboxsync rm -rf .vboxadd* .tmp_ver* vboxadd.* Module.symvers Modules.symvers modules.order