Makefile.module revision 8b21d158f0a2cf0965e0bd696837785403231cbe
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp# VirtualBox Guest Additions Module Makefile.
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp# (For 2.6.x this file must be 'Makefile'!)
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp# Copyright (C) 2006-2007 Sun Microsystems, Inc.
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp# This file is part of VirtualBox Open Source Edition (OSE), as
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp# available from http://www.virtualbox.org. This file is free software;
8209f3939e32e0e5bde64192267fdaf9db6f4fbcTripp# you can redistribute it and/or modify it under the terms of the GNU
8209f3939e32e0e5bde64192267fdaf9db6f4fbcTripp# General Public License (GPL) as published by the Free Software
8209f3939e32e0e5bde64192267fdaf9db6f4fbcTripp# Foundation, in version 2 as it comes in the "COPYING" file of the
8209f3939e32e0e5bde64192267fdaf9db6f4fbcTripp# VirtualBox OSE distribution. VirtualBox OSE is distributed in the
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp# hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp# Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp# Clara, CA 95054 USA or visit http://www.sun.com if you need
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp# additional information or have any questions.
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp# First, figure out which architecture we're targeting and the build type.
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp# (We have to support basic cross building (ARCH=i386|x86_64).)
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp# While at it, warn about BUILD_* vars found to help with user problems.
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTrippifneq ($(filter-out amd64 x86,$(BUILD_TARGET_ARCH)),)
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp $(warning Ignoring unknown BUILD_TARGET_ARCH value '$(BUILD_TARGET_ARCH)'.)
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp BUILD_TARGET_ARCH :=
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTrippifeq ($(BUILD_TARGET_ARCH),)
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp ifeq ($(ARCH),x86_64)
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp BUILD_TARGET_ARCH := amd64
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp ifeq ($(ARCH),i386)
a00d11bb8925157bd9fcc0e0fb5fc697c53726eaTripp BUILD_TARGET_ARCH := x86
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp ifeq ($(filter-out x86_64 amd64 AMD64,$(shell uname -m)),)
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp BUILD_TARGET_ARCH := amd64
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp BUILD_TARGET_ARCH := x86
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp $(warning Using BUILD_TARGET_ARCH='$(BUILD_TARGET_ARCH)' from the $(origin BUILD_TARGET_ARCH).)
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTrippifneq ($(filter-out release profile debug strict,$(BUILD_TYPE)),)
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp $(warning Ignoring unknown BUILD_TYPE value '$(BUILD_TYPE)'.)
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp BUILD_TYPE :=
8209f3939e32e0e5bde64192267fdaf9db6f4fbcTrippifeq ($(BUILD_TYPE),)
8209f3939e32e0e5bde64192267fdaf9db6f4fbcTripp BUILD_TYPE := release
8209f3939e32e0e5bde64192267fdaf9db6f4fbcTripp $(warning Using BUILD_TYPE='$(BUILD_TYPE)' from the $(origin BUILD_TYPE).)
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp# override is required by the Debian guys
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTrippoverride MODULE = vboxvfs
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTrippEXTRA_CFLAGS = -fshort-wchar
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTrippifneq ($(MAKECMDGOALS),clean)
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTrippifeq ($(KERNELRELEASE),)
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp # building from this directory
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp # kernel base directory
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp ifndef KERN_DIR
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp KERN_DIR := /lib/modules/$(shell uname -r)/build
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp ifneq ($(shell if test -d $(KERN_DIR); then echo yes; fi),yes)
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp ifneq ($(shell if test -d $(KERN_DIR); then echo yes; fi),yes)
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp $(error Error: unable to find the sources of your current Linux kernel. \
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp Specify KERN_DIR=<directory> and run Make again)
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp $(warning Warning: using /usr/src/linux as the source directory of your \
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp Linux kernel. If this is not correct, specify \
8209f3939e32e0e5bde64192267fdaf9db6f4fbcTripp KERN_DIR=<directory> and run Make again.)
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp ifneq ($(shell if test -d $(KERN_DIR); then echo yes; fi),yes)
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp $(error Error: KERN_DIR does not point to a directory)
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp ifndef KERN_INCL
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp KERN_INCL = $(KERN_DIR)/include
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp ifneq ($(shell if test -d $(KERN_INCL); then echo yes; fi),yes)
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp $(error Error: unable to find the include directory for your current Linux \
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp kernel. Specify KERN_INCL=<directory> and run Make again)
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp # module install dir.
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp ifneq ($(filter install install_rpm,$(MAKECMDGOALS)),)
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp ifndef MODULE_DIR
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp MODULE_DIR_TST := /lib/modules/$(shell uname -r)
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp ifeq ($(shell if test -d $(MODULE_DIR_TST); then echo yes; fi),yes)
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp MODULE_DIR := $(MODULE_DIR_TST)/misc
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp $(error Unable to find the folder to install the shared folders driver to)
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp endif # MODULE_DIR unspecified
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp # guess kernel version (24 or 26)
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp ifeq ($(shell if grep '"2\.4\.' $(KERN_INCL)/linux/version.h > /dev/null; then echo yes; fi),yes)
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp KERN_VERSION := 24
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp KERN_VERSION := 26
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTrippelse # neq($(KERNELRELEASE),)
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp # building from kbuild (make -C <kernel_directory> M=`pwd`)
8209f3939e32e0e5bde64192267fdaf9db6f4fbcTripp # guess kernel version (24 or 26)
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp ifeq ($(shell if grep '"2\.4\.' $(PWD)/include/linux/version.h > /dev/null; then echo yes; fi),yes)
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp KERN_VERSION := 24
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp KERN_VERSION := 26
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTrippendif # neq($(KERNELRELEASE),)
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp# debug - show guesses.
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp$(warning dbg: KERN_DIR = $(KERN_DIR))
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp$(warning dbg: KERN_INCL = $(KERN_INCL))
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp$(warning dbg: MODULE_DIR = $(MODULE_DIR))
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp$(warning dbg: KERN_VERSION = $(KERN_VERSION))
8209f3939e32e0e5bde64192267fdaf9db6f4fbcTripp# Compiler options
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp INCL := $(addprefix -I,$(KERN_INCL) $(EXTRA_INCL))
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp ifndef KBUILD_EXTMOD
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp KBUILD_EXTMOD := $(shell pwd)
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp INCL += $(addprefix -I$(KBUILD_EXTMOD),/ /include /r0drv/linux)
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp export INCL
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTrippKFLAGS := -D__KERNEL__ -DMODULE -DRT_OS_LINUX -DIN_RING0 -DIN_RT_R0 \
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp -DIN_SUP_R0 -DVBOX -DVBOX_WITH_HGCM -DLOG_TO_BACKDOOR -DIN_MODULE \
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp -DIN_GUEST_R0
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTrippifeq ($(BUILD_TARGET_ARCH),amd64)
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp KFLAGS += -DRT_ARCH_AMD64 -DVBOX_WITH_64_BITS_GUESTS
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp KFLAGS += -DRT_ARCH_X86
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTrippifeq ($(BUILD_TYPE),debug)
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTrippKFLAGS += -DDEBUG
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTrippifeq ($(KERN_VERSION), 24)
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTrippCFLAGS := -O2 -DVBOX_LINUX_2_4 $(INCL) $(KFLAGS) $(KDEBUG)
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTrippMODULE_EXT := o
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp# 2.4 Module linking
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp$(MODULE).o: $(OBJS)
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp $(LD) -o $@ -r $(OBJS)
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp.PHONY: $(MODULE)
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTrippall: $(MODULE)
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp$(MODULE): $(MODULE).o
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp# 2.6 and later
8209f3939e32e0e5bde64192267fdaf9db6f4fbcTrippMODULE_EXT := ko
8209f3939e32e0e5bde64192267fdaf9db6f4fbcTripp$(MODULE)-y := $(OBJS)
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp# special hack for FC6 2.6.18 and rhel5 2.6.18
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTrippifeq ($(KERNELRELEASE),)
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp KFLAGS += $(foreach inc,$(KERN_INCL),\
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp $(if $(wildcard $(inc)/linux/utsrelease.h),\
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp $(if $(shell grep '"2.6.18.*fc6.*"' $(inc)/linux/utsrelease.h; \
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp grep '"2.6.18.*el5.*"' $(inc)/linux/utsrelease.h; \
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp grep '"2.6.18.*cc4.*"' $(inc)/linux/utsrelease.h),\
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp -DKERNEL_FC6,),))
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp KFLAGS += $(if $(shell echo "$(KERNELRELEASE)"|grep '2.6.18.*fc6.*';\
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp echo "$(KERNELRELEASE)"|grep '2.6.18.*el5.*';\
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp echo "$(KERNELRELEASE)"|grep '2.6.18.*cc4.*'),\
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp -DKERNEL_FC6,)
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp# build defs
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTrippEXTRA_CFLAGS += $(INCL) $(KFLAGS) $(KDEBUG)
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTrippall: $(MODULE)
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTrippobj-m += $(MODULE).o
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp $(MAKE) KBUILD_VERBOSE=1 -C $(KERN_DIR) SUBDIRS=$(CURDIR) SRCROOT=$(CURDIR) modules
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTrippinstall: $(MODULE)
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp @mkdir -p $(MODULE_DIR); \
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp install -m 0664 -o root -g root $(MODULE).$(MODULE_EXT) $(MODULE_DIR); \
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp PATH="$(PATH):/bin:/sbin" depmod -ae;
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTrippendif # eq($(MAKECMDGOALS),clean)
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp for f in . linux r0drv r0drv/linux; do rm -f $$f/*.o $$f/.*.cmd $$f/.*.flags; done
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp rm -rf .vboxvfs* .tmp_ver* vboxvfs.* Module.symvers Modules.symvers modules.order