Makefile revision 228952e4dd4c991e27dbd718bc2f3a48bd547df8
9b2bd54c98edb185a3985410367754ab33217362bnicholes#
9b2bd54c98edb185a3985410367754ab33217362bnicholes# Makefile for the VirtualBox Linux Host Driver.
9b2bd54c98edb185a3985410367754ab33217362bnicholes# (For 2.6.x this file must be called 'Makefile'!)
9b2bd54c98edb185a3985410367754ab33217362bnicholes#
9b2bd54c98edb185a3985410367754ab33217362bnicholes
9b2bd54c98edb185a3985410367754ab33217362bnicholes#
9b2bd54c98edb185a3985410367754ab33217362bnicholes#
9b2bd54c98edb185a3985410367754ab33217362bnicholes# Copyright (C) 2006 innotek GmbH
9b2bd54c98edb185a3985410367754ab33217362bnicholes#
9b2bd54c98edb185a3985410367754ab33217362bnicholes# This file is part of VirtualBox Open Source Edition (OSE), as
9b2bd54c98edb185a3985410367754ab33217362bnicholes# available from http://www.virtualbox.org. This file is free software;
9b2bd54c98edb185a3985410367754ab33217362bnicholes# you can redistribute it and/or modify it under the terms of the GNU
9b2bd54c98edb185a3985410367754ab33217362bnicholes# General Public License as published by the Free Software Foundation,
9b2bd54c98edb185a3985410367754ab33217362bnicholes# in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
9b2bd54c98edb185a3985410367754ab33217362bnicholes# distribution. VirtualBox OSE is distributed in the hope that it will
9b2bd54c98edb185a3985410367754ab33217362bnicholes# be useful, but WITHOUT ANY WARRANTY of any kind.
9b2bd54c98edb185a3985410367754ab33217362bnicholes
9b2bd54c98edb185a3985410367754ab33217362bnicholes#
9b2bd54c98edb185a3985410367754ab33217362bnicholes# First, figure out which architecture we're targeting.
9b2bd54c98edb185a3985410367754ab33217362bnicholes# (We have to support basic cross building (ARCH=i386|x86_64).)
9b2bd54c98edb185a3985410367754ab33217362bnicholes#
9b2bd54c98edb185a3985410367754ab33217362bnicholesifneq ($(filter-out amd64 x86,$(BUILD_TARGET_ARCH)),)
70953fb44a7140fe206c3a5f011e24209c8c5c6abnicholes $(warning Ignoring unknown BUILD_TARGET_ARCH value '$(BUILD_TARGET_ARCH)'.)
70953fb44a7140fe206c3a5f011e24209c8c5c6abnicholes BUILD_TARGET_ARCH :=
70953fb44a7140fe206c3a5f011e24209c8c5c6abnicholesendif
9b2bd54c98edb185a3985410367754ab33217362bnicholesifeq ($(BUILD_TARGET_ARCH),)
9b2bd54c98edb185a3985410367754ab33217362bnicholes ifeq ($(ARCH),x86_64)
9b2bd54c98edb185a3985410367754ab33217362bnicholes BUILD_TARGET_ARCH := amd64
9b2bd54c98edb185a3985410367754ab33217362bnicholes else
9b2bd54c98edb185a3985410367754ab33217362bnicholes ifeq ($(ARCH),i386)
9b2bd54c98edb185a3985410367754ab33217362bnicholes BUILD_TARGET_ARCH := x86
be06f010941d039a422f1bbd7e321a1a0e92e291bnicholes else
9b2bd54c98edb185a3985410367754ab33217362bnicholes ifeq ($(filter-out x86_64 amd64 AMD64,$(shell uname -m)),)
9b2bd54c98edb185a3985410367754ab33217362bnicholes BUILD_TARGET_ARCH := amd64
9b2bd54c98edb185a3985410367754ab33217362bnicholes else
9b2bd54c98edb185a3985410367754ab33217362bnicholes BUILD_TARGET_ARCH := x86
9b2bd54c98edb185a3985410367754ab33217362bnicholes endif
9b2bd54c98edb185a3985410367754ab33217362bnicholes endif
9b2bd54c98edb185a3985410367754ab33217362bnicholes endif
9b2bd54c98edb185a3985410367754ab33217362bnicholesendif
9b2bd54c98edb185a3985410367754ab33217362bnicholes
9b2bd54c98edb185a3985410367754ab33217362bnicholes
9b2bd54c98edb185a3985410367754ab33217362bnicholesMODULE = vboxdrv
9b2bd54c98edb185a3985410367754ab33217362bnicholesOBJS = \
9b2bd54c98edb185a3985410367754ab33217362bnicholes linux/SUPDrv-linux.o \
9b2bd54c98edb185a3985410367754ab33217362bnicholes SUPDRVShared.o \
9b2bd54c98edb185a3985410367754ab33217362bnicholes r0drv/alloc-r0drv.o \
9b2bd54c98edb185a3985410367754ab33217362bnicholes r0drv/initterm-r0drv.o \
9b2bd54c98edb185a3985410367754ab33217362bnicholes r0drv/linux/alloc-r0drv-linux.o \
9b2bd54c98edb185a3985410367754ab33217362bnicholes r0drv/linux/initterm-r0drv-linux.o \
9b2bd54c98edb185a3985410367754ab33217362bnicholes r0drv/linux/process-r0drv-linux.o \
9b2bd54c98edb185a3985410367754ab33217362bnicholes r0drv/linux/semaphore-r0drv-linux.o \
9b2bd54c98edb185a3985410367754ab33217362bnicholes r0drv/linux/spinlock-r0drv-linux.o \
9b2bd54c98edb185a3985410367754ab33217362bnicholes r0drv/linux/thread-r0drv-linux.o
be06f010941d039a422f1bbd7e321a1a0e92e291bnicholesifeq ($(BUILD_TARGET_ARCH),amd64)
9b2bd54c98edb185a3985410367754ab33217362bnicholesOBJS += alloc/heapsimple.o
9b2bd54c98edb185a3985410367754ab33217362bnicholesendif
9b2bd54c98edb185a3985410367754ab33217362bnicholes
9b2bd54c98edb185a3985410367754ab33217362bnicholesifneq ($(MAKECMDGOALS),clean)
9b2bd54c98edb185a3985410367754ab33217362bnicholes
9b2bd54c98edb185a3985410367754ab33217362bnicholes# kernel base directory
be06f010941d039a422f1bbd7e321a1a0e92e291bnicholesifndef KERN_DIR
9b2bd54c98edb185a3985410367754ab33217362bnicholes KERN_DIR := /lib/modules/$(shell uname -r)/build
9b2bd54c98edb185a3985410367754ab33217362bnicholes ifneq ($(shell if test -d $(KERN_DIR); then echo yes; fi),yes)
9b2bd54c98edb185a3985410367754ab33217362bnicholes KERN_DIR := /usr/src/linux
9b2bd54c98edb185a3985410367754ab33217362bnicholes ifneq ($(shell if test -d $(KERN_DIR); then echo yes; fi),yes)
9b2bd54c98edb185a3985410367754ab33217362bnicholes $(error Error: unable to find the sources of your current Linux kernel. Specify KERN_DIR=<directory> and run Make again.)
9b2bd54c98edb185a3985410367754ab33217362bnicholes endif
be06f010941d039a422f1bbd7e321a1a0e92e291bnicholes $(warning Warning: using /usr/src/linux as the source directory of your Linux kernel. If this is not correct, specify KERN_DIR=<directory> and run Make again.)
9b2bd54c98edb185a3985410367754ab33217362bnicholes endif
9b2bd54c98edb185a3985410367754ab33217362bnicholeselse
9b2bd54c98edb185a3985410367754ab33217362bnicholes ifneq ($(shell if test -d $(KERN_DIR); then echo yes; fi),yes)
9b2bd54c98edb185a3985410367754ab33217362bnicholes $(error Error: KERN_DIR does not point to a directory.)
9b2bd54c98edb185a3985410367754ab33217362bnicholes endif
9b2bd54c98edb185a3985410367754ab33217362bnicholesendif
be06f010941d039a422f1bbd7e321a1a0e92e291bnicholes
9b2bd54c98edb185a3985410367754ab33217362bnicholes# includes
9b2bd54c98edb185a3985410367754ab33217362bnicholesifndef KERN_INCL
9b2bd54c98edb185a3985410367754ab33217362bnicholes KERN_INCL = $(KERN_DIR)/include
9b2bd54c98edb185a3985410367754ab33217362bnicholesendif
9b2bd54c98edb185a3985410367754ab33217362bnicholesifneq ($(shell if test -d $(KERN_INCL); then echo yes; fi),yes)
9b2bd54c98edb185a3985410367754ab33217362bnicholes $(error Error: unable to find the include directory for your current Linux kernel. Specify KERN_INCL=<directory> and run Make again.)
9b2bd54c98edb185a3985410367754ab33217362bnicholesendif
9b2bd54c98edb185a3985410367754ab33217362bnicholes
9b2bd54c98edb185a3985410367754ab33217362bnicholes# module install dir.
9b2bd54c98edb185a3985410367754ab33217362bnicholesifneq ($(filter install install_rpm,$(MAKECMDGOALS)),)
9b2bd54c98edb185a3985410367754ab33217362bnicholes ifndef MODULE_DIR
9b2bd54c98edb185a3985410367754ab33217362bnicholes MODULE_DIR_TST := /lib/modules/$(shell uname -r)
9b2bd54c98edb185a3985410367754ab33217362bnicholes ifeq ($(shell if test -d $(MODULE_DIR_TST); then echo yes; fi),yes)
9b2bd54c98edb185a3985410367754ab33217362bnicholes MODULE_DIR := $(MODULE_DIR_TST)/misc
9b2bd54c98edb185a3985410367754ab33217362bnicholes else
9b2bd54c98edb185a3985410367754ab33217362bnicholes $(error Unable to find the folder to install the support driver to)
9b2bd54c98edb185a3985410367754ab33217362bnicholes endif
9b2bd54c98edb185a3985410367754ab33217362bnicholes endif # MODULE_DIR unspecified
9b2bd54c98edb185a3985410367754ab33217362bnicholesendif
9b2bd54c98edb185a3985410367754ab33217362bnicholes
9b2bd54c98edb185a3985410367754ab33217362bnicholes# guess kernel version (24 or 26)
9b2bd54c98edb185a3985410367754ab33217362bnicholesKERN_VERSION := $(if $(wildcard $(KERN_DIR)/Rules.make),24,26)
9b2bd54c98edb185a3985410367754ab33217362bnicholes
9b2bd54c98edb185a3985410367754ab33217362bnicholes# debug - show guesses.
9b2bd54c98edb185a3985410367754ab33217362bnicholesifdef DEBUG
9b2bd54c98edb185a3985410367754ab33217362bnicholes$(warning dbg: KERN_DIR = $(KERN_DIR))
9b2bd54c98edb185a3985410367754ab33217362bnicholes$(warning dbg: KERN_INCL = $(KERN_INCL))
9b2bd54c98edb185a3985410367754ab33217362bnicholes$(warning dbg: MODULE_DIR = $(MODULE_DIR))
9b2bd54c98edb185a3985410367754ab33217362bnicholes$(warning dbg: KERN_VERSION = $(KERN_VERSION))
9b2bd54c98edb185a3985410367754ab33217362bnicholesendif
9b2bd54c98edb185a3985410367754ab33217362bnicholes
9b2bd54c98edb185a3985410367754ab33217362bnicholes#
9b2bd54c98edb185a3985410367754ab33217362bnicholes# Compiler options
9b2bd54c98edb185a3985410367754ab33217362bnicholes#
9b2bd54c98edb185a3985410367754ab33217362bnicholesifndef INCL
9b2bd54c98edb185a3985410367754ab33217362bnicholes INCL := -I$(KERN_INCL) $(addprefix -I, $(EXTRA_INCL))
9b2bd54c98edb185a3985410367754ab33217362bnicholes ifndef KBUILD_EXTMOD
9b2bd54c98edb185a3985410367754ab33217362bnicholes KBUILD_EXTMOD := $(shell pwd)
9b2bd54c98edb185a3985410367754ab33217362bnicholes endif
be06f010941d039a422f1bbd7e321a1a0e92e291bnicholes INCL += $(addprefix -I$(KBUILD_EXTMOD),/ /include /r0drv/linux)
9b2bd54c98edb185a3985410367754ab33217362bnicholes export INCL
9b2bd54c98edb185a3985410367754ab33217362bnicholesendif
9b2bd54c98edb185a3985410367754ab33217362bnicholesKFLAGS := -D__KERNEL__ -DMODULE -DRT_OS_LINUX -DIN_RING0 -DIN_RT_R0 -DIN_SUP_R0
9b2bd54c98edb185a3985410367754ab33217362bnicholesifndef CONFIG_VBOXDRV_FIXEDMAJOR
9b2bd54c98edb185a3985410367754ab33217362bnicholes KFLAGS += -DCONFIG_VBOXDRV_AS_MISC
9b2bd54c98edb185a3985410367754ab33217362bnicholesendif
9b2bd54c98edb185a3985410367754ab33217362bnicholesifeq ($(BUILD_TARGET_ARCH),amd64)
9b2bd54c98edb185a3985410367754ab33217362bnicholes KFLAGS += -DRT_ARCH_AMD64
9b2bd54c98edb185a3985410367754ab33217362bnicholeselse
9b2bd54c98edb185a3985410367754ab33217362bnicholes KFLAGS += -DRT_ARCH_X86
9b2bd54c98edb185a3985410367754ab33217362bnicholesendif
9b2bd54c98edb185a3985410367754ab33217362bnicholes#ifeq ($(BUILD_TYPE),debug) - you'll have to enable this manually to get debug stuff.
9b2bd54c98edb185a3985410367754ab33217362bnicholes#KFLAGS += -DDEBUG
9b2bd54c98edb185a3985410367754ab33217362bnicholes#endif
9b2bd54c98edb185a3985410367754ab33217362bnicholes
9b2bd54c98edb185a3985410367754ab33217362bnicholes#
9b2bd54c98edb185a3985410367754ab33217362bnicholes# Use the RTR0MemObj API - testing.
9b2bd54c98edb185a3985410367754ab33217362bnicholes# If this makes testboxes crash/burn/leak disable it and add a comment to defect #2116.
9b2bd54c98edb185a3985410367754ab33217362bnicholes#
9b2bd54c98edb185a3985410367754ab33217362bnicholesKFLAGS += -DUSE_NEW_OS_INTERFACE_FOR_MM
9b2bd54c98edb185a3985410367754ab33217362bnicholesOBJS += r0drv/memobj-r0drv.o \
9b2bd54c98edb185a3985410367754ab33217362bnicholes r0drv/linux/memobj-r0drv-linux.o
9b2bd54c98edb185a3985410367754ab33217362bnicholes
9b2bd54c98edb185a3985410367754ab33217362bnicholesifeq ($(KERN_VERSION), 24)
9b2bd54c98edb185a3985410367754ab33217362bnicholes# 2.4
be06f010941d039a422f1bbd7e321a1a0e92e291bnicholesTOPDIR = $(KERN_DIR)
9b2bd54c98edb185a3985410367754ab33217362bnicholesMODULE_EXT := o
9b2bd54c98edb185a3985410367754ab33217362bnicholesEXTRA_CFLAGS := -DVBOX_LINUX_2_4
9b2bd54c98edb185a3985410367754ab33217362bnicholes$(MODULE)-objs = $(OBJS)
9b2bd54c98edb185a3985410367754ab33217362bnicholeselse
9b2bd54c98edb185a3985410367754ab33217362bnicholes# 2.6 and later
9b2bd54c98edb185a3985410367754ab33217362bnicholesMODULE_EXT := ko
be06f010941d039a422f1bbd7e321a1a0e92e291bnicholes$(MODULE)-y := $(OBJS)
9b2bd54c98edb185a3985410367754ab33217362bnicholesendif
9b2bd54c98edb185a3985410367754ab33217362bnicholes
9b2bd54c98edb185a3985410367754ab33217362bnicholes# build defs
9b2bd54c98edb185a3985410367754ab33217362bnicholesEXTRA_CFLAGS += $(INCL) $(KFLAGS) $(KDEBUG)
9b2bd54c98edb185a3985410367754ab33217362bnicholes
9b2bd54c98edb185a3985410367754ab33217362bnicholesall: $(MODULE)
9b2bd54c98edb185a3985410367754ab33217362bnicholes
9b2bd54c98edb185a3985410367754ab33217362bnicholesobj-m += $(MODULE).o
9b2bd54c98edb185a3985410367754ab33217362bnicholes
9b2bd54c98edb185a3985410367754ab33217362bnicholes$(MODULE):
9b2bd54c98edb185a3985410367754ab33217362bnicholes $(MAKE) KBUILD_VERBOSE=1 -C $(KERN_DIR) SUBDIRS=$(CURDIR) SRCROOT=$(CURDIR) modules
9b2bd54c98edb185a3985410367754ab33217362bnicholes
9b2bd54c98edb185a3985410367754ab33217362bnicholesifeq ($(KERN_VERSION), 24)
9b2bd54c98edb185a3985410367754ab33217362bnicholes#
9b2bd54c98edb185a3985410367754ab33217362bnicholes# 2.4 Module linking
9b2bd54c98edb185a3985410367754ab33217362bnicholes#
9b2bd54c98edb185a3985410367754ab33217362bnicholes$(MODULE).o: $(OBJS)
9b2bd54c98edb185a3985410367754ab33217362bnicholes $(LD) -o $@ -r $(OBJS)
9b2bd54c98edb185a3985410367754ab33217362bnicholes
9b2bd54c98edb185a3985410367754ab33217362bnicholesinclude $(KERN_DIR)/Rules.make
9b2bd54c98edb185a3985410367754ab33217362bnicholes
f628b5980b3f4ae688b70ae449a1f50aea687384bnicholesendif
f628b5980b3f4ae688b70ae449a1f50aea687384bnicholes
f628b5980b3f4ae688b70ae449a1f50aea687384bnicholesinstall: $(MODULE)
9b2bd54c98edb185a3985410367754ab33217362bnicholes @mkdir -p $(MODULE_DIR); \
9b2bd54c98edb185a3985410367754ab33217362bnicholes install -m 0664 -o root -g root $(MODULE).$(MODULE_EXT) $(MODULE_DIR); \
9b2bd54c98edb185a3985410367754ab33217362bnicholes PATH="$(PATH):/bin:/sbin" depmod -ae; \
9b2bd54c98edb185a3985410367754ab33217362bnicholes rm -f /etc/vbox/module_not_compiled
9b2bd54c98edb185a3985410367754ab33217362bnicholes
9b2bd54c98edb185a3985410367754ab33217362bnicholesinstall_rpm: $(MODULE)
9b2bd54c98edb185a3985410367754ab33217362bnicholes @mkdir -p $(MODULE_DIR); \
9b2bd54c98edb185a3985410367754ab33217362bnicholes install -m 0664 $(MODULE).$(MODULE_EXT) $(MODULE_DIR)
be06f010941d039a422f1bbd7e321a1a0e92e291bnicholes
9b2bd54c98edb185a3985410367754ab33217362bnicholesendif # eq($(MAKECMDGOALS),clean)
9b2bd54c98edb185a3985410367754ab33217362bnicholes
9b2bd54c98edb185a3985410367754ab33217362bnicholesclean:
9b2bd54c98edb185a3985410367754ab33217362bnicholes for f in . linux r0drv r0drv/linux; do rm -f $$f/*.o $$f/.*.cmd $$f/.*.flags; done
9b2bd54c98edb185a3985410367754ab33217362bnicholes rm -rf .vboxdrv* .tmp_ver* vboxdrv.* Module.symvers Modules.symvers
9b2bd54c98edb185a3985410367754ab33217362bnicholes