Makefile revision 2b80aa00cbee106b9ec709660eadb6f59f4ca121
0N/A#
0N/A# Makefile for the VirtualBox Linux Host Driver.
0N/A# (For 2.6.x this file must be called 'Makefile'!)
0N/A#
911N/A
810N/A#
0N/A#
0N/A# Copyright (C) 2006 InnoTek Systemberatung GmbH
0N/A#
0N/A# This file is part of VirtualBox Open Source Edition (OSE), as
0N/A# available from http://www.virtualbox.org. This file is free software;
0N/A# you can redistribute it and/or modify it under the terms of the GNU
0N/A# General Public License as published by the Free Software Foundation,
0N/A# in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
0N/A# distribution. VirtualBox OSE is distributed in the hope that it will
0N/A# be useful, but WITHOUT ANY WARRANTY of any kind.
0N/A#
0N/A# If you received this file as part of a commercial VirtualBox
0N/A# distribution, then only the terms of your commercial VirtualBox
0N/A# license agreement apply instead of the previous paragraph.
0N/A#
0N/A
0N/A#
0N/A# First, figure out which architecture we're targeting.
0N/A# (We have to support basic cross building (ARCH=i386|x86_64).)
0N/A#
0N/Aifeq ($(filter amd64 x86,$(BUILD_TARGET_ARCH)),)
0N/A $(warning Ignoring unknown BUILD_TARGET_ARCH value '$(BUILD_TARGET_ARCH)'.)
0N/A BUILD_TARGET_ARCH :=
0N/Aendif
0N/Aifeq ($(BUILD_TARGET_ARCH),)
0N/A ifeq ($(ARCH),x86_64)
0N/A BUILD_TARGET_ARCH := amd64
0N/A else ifeq ($(ARCH),i386)
156N/A BUILD_TARGET_ARCH := x86
493N/A else ifeq ($(filter-out x86_64 amd64 AMD64,$(shell uname -m)),)
0N/A BUILD_TARGET_ARCH := amd64
0N/A else
818N/A BUILD_TARGET_ARCH := x86
0N/A endif
911N/Aendif
911N/A
911N/A
911N/AMODULE = vboxdrv
0N/AOBJS = \
493N/A linux/SUPDrv-linux.o \
493N/A SUPDRVShared.o \
156N/A r0drv/alloc-r0drv.o \
0N/A r0drv/initterm-r0drv.o \
0N/A r0drv/linux/alloc-r0drv-linux.o \
156N/A r0drv/linux/initterm-r0drv-linux.o \
156N/A r0drv/linux/semaphore-r0drv-linux.o \
0N/A r0drv/linux/spinlock-r0drv-linux.o \
0N/A r0drv/linux/thread-r0drv-linux.o
818N/Aifeq ($(BUILD_TARGET_ARCH),amd64)
818N/AOBJS += alloc/heapsimple.o
779N/Aendif
364N/A
156N/A
156N/Aifneq ($(MAKECMDGOALS),clean)
0N/A
591N/A# kernel base directory
591N/Aifndef $(KERN_DIR)
591N/A KERN_DIR := /lib/modules/$(shell uname -r)/build
591N/A ifneq ($(shell if test -d $(KERN_DIR); then echo yes; fi),yes)
591N/A KERN_DIR := /usr/src/linux
591N/A ifneq ($(shell if test -d $(KERN_DIR); then echo yes; fi),yes)
591N/A $(error Error: unable to find the sources of your current Linux kernel. Specify KERN_DIR=<directory> and run Make again.)
0N/A endif
156N/A $(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.)
493N/A endif
493N/Aelse
156N/A ifneq ($(shell if test -d $(KERN_DIR); then echo yes; fi),yes)
493N/A $(error Error: KERN_DIR does not point to a directory.)
493N/A endif
837N/Aendif
837N/A
846N/A# includes
493N/Aifndef $(KERN_INCL)
493N/A KERN_INCL = $(KERN_DIR)/include
156N/A $(info Info: using $(KERN_INCL) as the include directory of your Linux kernel. If this is not correct, specify KERN_INCL=<directory> and run Make again.)
493N/Aendif
493N/Aifneq ($(shell if test -d $(KERN_INCL); then echo yes; fi),yes)
493N/A $(error Error: unable to find the include directory for your current Linux kernel. Specify $KERN_INCL=<directory> and run Make again.)
364N/Aendif
0N/A
493N/A# module install dir.
493N/Aifndef MODULE_DIR
156N/A MODULE_DIR_TST := /lib/modules/$(shell uname -r)
493N/A ifeq ($(shell if test -d $(MODULE_DIR_TST); then echo yes; fi),yes)
493N/A MODULE_DIR := $(MODULE_DIR_TST)/misc
0N/A else
339N/A $(error Error: could not find the module directory for your current Linux kernel)
0N/A endif
0N/Aendif # MODULE_DIR unspecified
339N/A
339N/A# guess kernel version (24 or 26)
0N/AKERN_VERSION := $(if $(wildcard $(KERN_DIR)/Rules.make),24,26)
837N/A
837N/A# debug - show guesses.
838N/Aifdef DEBUG
837N/A$(warning dbg: KERN_DIR = $(KERN_DIR))
837N/A$(warning dbg: KERN_INCL = $(KERN_INCL))
591N/A$(warning dbg: MODULE_DIR = $(MODULE_DIR))
591N/A$(warning dbg: KERN_VERSION = $(KERN_VERSION))
779N/Aendif
838N/A
591N/A#
493N/A# Compiler options
493N/A#
0N/Aifndef INCL
0N/A INCL := -I$(KERN_INCL)
0N/A ifndef KBUILD_EXTMOD
0N/A KBUILD_EXTMOD := $(shell pwd)
591N/A endif
0N/A INCL += $(addprefix -I$(KBUILD_EXTMOD),/ /include /r0drv/linux)
339N/A export INCL
339N/Aendif
591N/AKFLAGS := -D__KERNEL__ -DMODULE -D__LINUX__ -DIN_RING0 -DIN_RT_R0 -DIN_SUP_R0
493N/Aifndef CONFIG_VBOXDRV_FIXEDMAJOR
837N/A KFLAGS += -DCONFIG_VBOXDRV_AS_MISC
837N/Aendif
837N/Aifeq ($(BUILD_TARGET_ARCH),amd64)
837N/A KFLAGS += -D__AMD64__
837N/Aelse
848N/A KFLAGS += -D__X86__
779N/Aendif
156N/A#ifeq ($(BUILD_TYPE),debug) - you'll have to enable this manually to get debug stuff.
156N/A#KFLAGS += -DDEBUG
810N/A#endif
591N/A
591N/Aifeq ($(KERN_VERSION), 24)
591N/A# 2.4
591N/ATOPDIR = $(KERN_DIR)
591N/AMODULE_EXT := o
848N/AEXTRA_CFLAGS := -DVBOX_LINUX_2_4
591N/A$(MODULE)-objs = $(OBJS)
591N/Aelse
591N/A# 2.6 and later
591N/AMODULE_EXT := ko
591N/A$(MODULE)-y := $(OBJS)
0N/Aendif
0N/A
# build defs
EXTRA_CFLAGS += $(INCL) $(KFLAGS) $(KDEBUG)
all: $(MODULE)
obj-m += $(MODULE).o
$(MODULE):
$(MAKE) KBUILD_VERBOSE=1 -C $(KERN_DIR) SUBDIRS=$(CURDIR) SRCROOT=$(CURDIR) modules
ifeq ($(KERN_VERSION), 24)
#
# 2.4 Module linking
#
$(MODULE).o: $(OBJS)
$(LD) -o $@ -r $(OBJS)
include $(KERN_DIR)/Rules.make
endif
install: $(MODULE)
@mkdir -p $(MODULE_DIR); \
install -m 0664 -o root -g root $(MODULE).$(MODULE_EXT) $(MODULE_DIR); \
PATH="$(PATH):/bin:/sbin" depmod -ae; \
rm -f /etc/vbox/module_not_compiled
endif # eq($(MAKECMDGOALS),clean)
clean:
for f in . linux r0drv r0drv/linux; do rm -f $$f/*.o $$f/.*.cmd $$f/.*.flags; done
rm -rf .vboxdrv* .tmp_ver* vboxdrv.* Module.symvers Modules.symvers