Makefile.module revision df409c2a6d13641b0586a36103d015cc8d76da53
71c8a528203c289a8585ce10ac6bafc4274058c6vboxsync# VirtualBox Guest Additions Module Makefile.
71c8a528203c289a8585ce10ac6bafc4274058c6vboxsync# (For 2.6.x this file must be 'Makefile'!)
71c8a528203c289a8585ce10ac6bafc4274058c6vboxsync# Copyright (C) 2006-2007 innotek GmbH
71c8a528203c289a8585ce10ac6bafc4274058c6vboxsync# This file is part of VirtualBox Open Source Edition (OSE), as
71c8a528203c289a8585ce10ac6bafc4274058c6vboxsync# available from http://www.virtualbox.org. This file is free software;
71c8a528203c289a8585ce10ac6bafc4274058c6vboxsync# you can redistribute it and/or modify it under the terms of the GNU
71c8a528203c289a8585ce10ac6bafc4274058c6vboxsync# General Public License (GPL) as published by the Free Software
71c8a528203c289a8585ce10ac6bafc4274058c6vboxsync# Foundation, in version 2 as it comes in the "COPYING" file of the
71c8a528203c289a8585ce10ac6bafc4274058c6vboxsync# VirtualBox OSE distribution. VirtualBox OSE is distributed in the
71c8a528203c289a8585ce10ac6bafc4274058c6vboxsync# hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
71c8a528203c289a8585ce10ac6bafc4274058c6vboxsync# override is required by the Debian guys
71c8a528203c289a8585ce10ac6bafc4274058c6vboxsyncoverride MODULE = vboxvfs
71c8a528203c289a8585ce10ac6bafc4274058c6vboxsyncEXTRA_CFLAGS = -fshort-wchar
71c8a528203c289a8585ce10ac6bafc4274058c6vboxsyncifneq ($(MAKECMDGOALS),clean)
71c8a528203c289a8585ce10ac6bafc4274058c6vboxsyncifeq ($(KERNELRELEASE),)
71c8a528203c289a8585ce10ac6bafc4274058c6vboxsync # building from this directory
71c8a528203c289a8585ce10ac6bafc4274058c6vboxsync # kernel base directory
71c8a528203c289a8585ce10ac6bafc4274058c6vboxsync ifndef KERN_DIR
71c8a528203c289a8585ce10ac6bafc4274058c6vboxsync KERN_DIR := /lib/modules/$(shell uname -r)/build
71c8a528203c289a8585ce10ac6bafc4274058c6vboxsync ifneq ($(shell if test -d $(KERN_DIR); then echo yes; fi),yes)
71c8a528203c289a8585ce10ac6bafc4274058c6vboxsync ifneq ($(shell if test -d $(KERN_DIR); then echo yes; fi),yes)
71c8a528203c289a8585ce10ac6bafc4274058c6vboxsync $(error Error: unable to find the sources of your current Linux kernel. \
71c8a528203c289a8585ce10ac6bafc4274058c6vboxsync Specify KERN_DIR=<directory> and run Make again)
71c8a528203c289a8585ce10ac6bafc4274058c6vboxsync $(warning Warning: using /usr/src/linux as the source directory of your \
71c8a528203c289a8585ce10ac6bafc4274058c6vboxsync Linux kernel. If this is not correct, specify \
71c8a528203c289a8585ce10ac6bafc4274058c6vboxsync KERN_DIR=<directory> and run Make again.)
71c8a528203c289a8585ce10ac6bafc4274058c6vboxsync ifneq ($(shell if test -d $(KERN_DIR); then echo yes; fi),yes)
71c8a528203c289a8585ce10ac6bafc4274058c6vboxsync $(error Error: KERN_DIR does not point to a directory)
71c8a528203c289a8585ce10ac6bafc4274058c6vboxsync ifndef KERN_INCL
71c8a528203c289a8585ce10ac6bafc4274058c6vboxsync KERN_INCL = $(KERN_DIR)/include
71c8a528203c289a8585ce10ac6bafc4274058c6vboxsync ifneq ($(shell if test -d $(KERN_INCL); then echo yes; fi),yes)
71c8a528203c289a8585ce10ac6bafc4274058c6vboxsync $(error Error: unable to find the include directory for your current Linux \
71c8a528203c289a8585ce10ac6bafc4274058c6vboxsync kernel. Specify KERN_INCL=<directory> and run Make again)
e214bb78026c1d64078b34ca9504d3f5abbc52efvboxsync # module install dir.
71c8a528203c289a8585ce10ac6bafc4274058c6vboxsync ifneq ($(filter install install_rpm,$(MAKECMDGOALS)),)
71c8a528203c289a8585ce10ac6bafc4274058c6vboxsync ifndef MODULE_DIR
71c8a528203c289a8585ce10ac6bafc4274058c6vboxsync MODULE_DIR_TST := /lib/modules/$(shell uname -r)
71c8a528203c289a8585ce10ac6bafc4274058c6vboxsync ifeq ($(shell if test -d $(MODULE_DIR_TST); then echo yes; fi),yes)
71c8a528203c289a8585ce10ac6bafc4274058c6vboxsync MODULE_DIR := $(MODULE_DIR_TST)/misc
71c8a528203c289a8585ce10ac6bafc4274058c6vboxsync $(error Unable to find the folder to install the shared folders driver to)
71c8a528203c289a8585ce10ac6bafc4274058c6vboxsync endif # MODULE_DIR unspecified
71c8a528203c289a8585ce10ac6bafc4274058c6vboxsync # guess kernel version (24 or 26)
71c8a528203c289a8585ce10ac6bafc4274058c6vboxsync ifeq ($(shell if grep '"2\.4\.' $(KERN_INCL)/linux/version.h > /dev/null; then echo yes; fi),yes)
71c8a528203c289a8585ce10ac6bafc4274058c6vboxsync KERN_VERSION := 24
71c8a528203c289a8585ce10ac6bafc4274058c6vboxsync KERN_VERSION := 26
71c8a528203c289a8585ce10ac6bafc4274058c6vboxsyncelse # neq($(KERNELRELEASE),)
a59528c40bbfdcee2e315756333f8c66f35b5accvboxsync # building from kbuild (make -C <kernel_directory> M=`pwd`)
71c8a528203c289a8585ce10ac6bafc4274058c6vboxsync # guess kernel version (24 or 26)
71c8a528203c289a8585ce10ac6bafc4274058c6vboxsync ifeq ($(shell if grep '"2\.4\.' $(PWD)/include/linux/version.h > /dev/null; then echo yes; fi),yes)
71c8a528203c289a8585ce10ac6bafc4274058c6vboxsync KERN_VERSION := 24
71c8a528203c289a8585ce10ac6bafc4274058c6vboxsync KERN_VERSION := 26
71c8a528203c289a8585ce10ac6bafc4274058c6vboxsyncendif # neq($(KERNELRELEASE),)
71c8a528203c289a8585ce10ac6bafc4274058c6vboxsync# debug - show guesses.
71c8a528203c289a8585ce10ac6bafc4274058c6vboxsync$(warning dbg: KERN_DIR = $(KERN_DIR))
71c8a528203c289a8585ce10ac6bafc4274058c6vboxsync$(warning dbg: KERN_INCL = $(KERN_INCL))
71c8a528203c289a8585ce10ac6bafc4274058c6vboxsync$(warning dbg: MODULE_DIR = $(MODULE_DIR))
71c8a528203c289a8585ce10ac6bafc4274058c6vboxsync$(warning dbg: KERN_VERSION = $(KERN_VERSION))
71c8a528203c289a8585ce10ac6bafc4274058c6vboxsync# Compiler options
71c8a528203c289a8585ce10ac6bafc4274058c6vboxsync INCL := $(addprefix -I,$(KERN_INCL) $(EXTRA_INCL))
71c8a528203c289a8585ce10ac6bafc4274058c6vboxsync ifndef KBUILD_EXTMOD
71c8a528203c289a8585ce10ac6bafc4274058c6vboxsync KBUILD_EXTMOD := $(shell pwd)
71c8a528203c289a8585ce10ac6bafc4274058c6vboxsync INCL += $(addprefix -I$(KBUILD_EXTMOD),/ /include /r0drv/linux)
71c8a528203c289a8585ce10ac6bafc4274058c6vboxsync export INCL
71c8a528203c289a8585ce10ac6bafc4274058c6vboxsyncKFLAGS := -D__KERNEL__ -DMODULE -DRT_OS_LINUX -DIN_RING0 -D_X86_ -DIN_RT_R0 \
71c8a528203c289a8585ce10ac6bafc4274058c6vboxsync -DIN_SUP_R0 -DVBOX -DVBOX_HGCM -DLOG_TO_BACKDOOR -DIN_MODULE \
71c8a528203c289a8585ce10ac6bafc4274058c6vboxsync -DIN_GUEST_R0
71c8a528203c289a8585ce10ac6bafc4274058c6vboxsyncifeq ($(BUILD_TYPE),debug)
71c8a528203c289a8585ce10ac6bafc4274058c6vboxsyncKFLAGS += -DDEBUG
71c8a528203c289a8585ce10ac6bafc4274058c6vboxsyncifeq ($(KERN_VERSION), 24)
71c8a528203c289a8585ce10ac6bafc4274058c6vboxsyncCFLAGS := -O2 -DVBOX_LINUX_2_4 $(INCL) $(KFLAGS) $(KDEBUG)
71c8a528203c289a8585ce10ac6bafc4274058c6vboxsyncMODULE_EXT := o
71c8a528203c289a8585ce10ac6bafc4274058c6vboxsync# 2.4 Module linking
71c8a528203c289a8585ce10ac6bafc4274058c6vboxsync$(MODULE).o: $(OBJS)
71c8a528203c289a8585ce10ac6bafc4274058c6vboxsync $(LD) -o $@ -r $(OBJS)
71c8a528203c289a8585ce10ac6bafc4274058c6vboxsync.PHONY: $(MODULE)
71c8a528203c289a8585ce10ac6bafc4274058c6vboxsyncall: $(MODULE)
71c8a528203c289a8585ce10ac6bafc4274058c6vboxsync$(MODULE): $(MODULE).o
71c8a528203c289a8585ce10ac6bafc4274058c6vboxsync# 2.6 and later
71c8a528203c289a8585ce10ac6bafc4274058c6vboxsyncMODULE_EXT := ko
71c8a528203c289a8585ce10ac6bafc4274058c6vboxsync$(MODULE)-y := $(OBJS)
71c8a528203c289a8585ce10ac6bafc4274058c6vboxsync# special hack for FC6 2.6.18 and rhel5 2.6.18
71c8a528203c289a8585ce10ac6bafc4274058c6vboxsyncifeq ($(KERNELRELEASE),)
71c8a528203c289a8585ce10ac6bafc4274058c6vboxsync KFLAGS += $(foreach inc,$(KERN_INCL),\
71c8a528203c289a8585ce10ac6bafc4274058c6vboxsync $(if $(wildcard $(inc)/linux/utsrelease.h),\
71c8a528203c289a8585ce10ac6bafc4274058c6vboxsync $(if $(shell if grep -q '"2.6.18.*fc6.*"' $(inc)/linux/utsrelease.h;\
71c8a528203c289a8585ce10ac6bafc4274058c6vboxsync then echo yes; fi),-DKERNEL_FC6,),) \
71c8a528203c289a8585ce10ac6bafc4274058c6vboxsync $(if $(wildcard $(inc)/linux/utsrelease.h),\
71c8a528203c289a8585ce10ac6bafc4274058c6vboxsync $(if $(shell if grep -q '"2.6.18.*el5.*"' $(inc)/linux/utsrelease.h;\
71c8a528203c289a8585ce10ac6bafc4274058c6vboxsync then echo yes; fi),-DKERNEL_FC6,),))
71c8a528203c289a8585ce10ac6bafc4274058c6vboxsync KFLAGS += $(filter -DKERNEL_FC6,$(patsubst 2.6.18%fc6,-DKERNEL_FC6,$(KERNELRELEASE)) \
71c8a528203c289a8585ce10ac6bafc4274058c6vboxsync $(patsubst 2.6.18%el5,-DKERNEL_FC6,$(KERNELRELEASE)))
71c8a528203c289a8585ce10ac6bafc4274058c6vboxsync# build defs
71c8a528203c289a8585ce10ac6bafc4274058c6vboxsyncEXTRA_CFLAGS += $(INCL) $(KFLAGS) $(KDEBUG)
71c8a528203c289a8585ce10ac6bafc4274058c6vboxsyncall: $(MODULE)
71c8a528203c289a8585ce10ac6bafc4274058c6vboxsyncobj-m += $(MODULE).o
71c8a528203c289a8585ce10ac6bafc4274058c6vboxsync $(MAKE) KBUILD_VERBOSE=1 -C $(KERN_DIR) SUBDIRS=$(CURDIR) SRCROOT=$(CURDIR) modules
71c8a528203c289a8585ce10ac6bafc4274058c6vboxsyncinstall: $(MODULE)
71c8a528203c289a8585ce10ac6bafc4274058c6vboxsync @mkdir -p $(MODULE_DIR); \
71c8a528203c289a8585ce10ac6bafc4274058c6vboxsync install -m 0664 -o root -g root $(MODULE).$(MODULE_EXT) $(MODULE_DIR); \
71c8a528203c289a8585ce10ac6bafc4274058c6vboxsync PATH="$(PATH):/bin:/sbin" depmod -ae;
71c8a528203c289a8585ce10ac6bafc4274058c6vboxsyncendif # eq($(MAKECMDGOALS),clean)
71c8a528203c289a8585ce10ac6bafc4274058c6vboxsync for f in . linux r0drv r0drv/linux; do rm -f $$f/*.o $$f/.*.cmd $$f/.*.flags; done
71c8a528203c289a8585ce10ac6bafc4274058c6vboxsync rm -rf .vboxvfs* .tmp_ver* vboxvfs.* Module.symvers Modules.symvers