1 | #
|
---|
2 | # Makefile for the VirtualBox Linux Host Driver.
|
---|
3 | # (For 2.6.x this file must be called 'Makefile'!)
|
---|
4 | #
|
---|
5 |
|
---|
6 | #
|
---|
7 | #
|
---|
8 | # Copyright (C) 2006-2007 innotek GmbH
|
---|
9 | #
|
---|
10 | # This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
11 | # available from http://www.alldomusa.eu.org. This file is free software;
|
---|
12 | # you can redistribute it and/or modify it under the terms of the GNU
|
---|
13 | # General Public License (GPL) as published by the Free Software
|
---|
14 | # Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
15 | # VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
16 | # hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
17 | #
|
---|
18 | # The contents of this file may alternatively be used under the terms
|
---|
19 | # of the Common Development and Distribution License Version 1.0
|
---|
20 | # (CDDL) only, as it comes in the "COPYING.CDDL" file of the
|
---|
21 | # VirtualBox OSE distribution, in which case the provisions of the
|
---|
22 | # CDDL are applicable instead of those of the GPL.
|
---|
23 | #
|
---|
24 | # You may elect to license modified versions of this file under the
|
---|
25 | # terms and conditions of either the GPL or the CDDL or both.
|
---|
26 | #
|
---|
27 |
|
---|
28 | #
|
---|
29 | # First, figure out which architecture we're targeting.
|
---|
30 | # (We have to support basic cross building (ARCH=i386|x86_64).)
|
---|
31 | #
|
---|
32 | ifneq ($(filter-out amd64 x86,$(BUILD_TARGET_ARCH)),)
|
---|
33 | $(warning Ignoring unknown BUILD_TARGET_ARCH value '$(BUILD_TARGET_ARCH)'.)
|
---|
34 | BUILD_TARGET_ARCH :=
|
---|
35 | endif
|
---|
36 | ifeq ($(BUILD_TARGET_ARCH),)
|
---|
37 | ifeq ($(ARCH),x86_64)
|
---|
38 | BUILD_TARGET_ARCH := amd64
|
---|
39 | else
|
---|
40 | ifeq ($(ARCH),i386)
|
---|
41 | BUILD_TARGET_ARCH := x86
|
---|
42 | else
|
---|
43 | ifeq ($(filter-out x86_64 amd64 AMD64,$(shell uname -m)),)
|
---|
44 | BUILD_TARGET_ARCH := amd64
|
---|
45 | else
|
---|
46 | BUILD_TARGET_ARCH := x86
|
---|
47 | endif
|
---|
48 | endif
|
---|
49 | endif
|
---|
50 | endif
|
---|
51 |
|
---|
52 |
|
---|
53 | MODULE = vboxdrv
|
---|
54 | OBJS = \
|
---|
55 | linux/SUPDrv-linux.o \
|
---|
56 | SUPDRVShared.o \
|
---|
57 | r0drv/alloc-r0drv.o \
|
---|
58 | r0drv/initterm-r0drv.o \
|
---|
59 | r0drv/linux/alloc-r0drv-linux.o \
|
---|
60 | r0drv/linux/initterm-r0drv-linux.o \
|
---|
61 | r0drv/linux/process-r0drv-linux.o \
|
---|
62 | r0drv/linux/semevent-r0drv-linux.o \
|
---|
63 | r0drv/linux/semeventmulti-r0drv-linux.o \
|
---|
64 | r0drv/linux/semfastmutex-r0drv-linux.o \
|
---|
65 | r0drv/linux/spinlock-r0drv-linux.o \
|
---|
66 | r0drv/linux/thread-r0drv-linux.o
|
---|
67 | ifeq ($(BUILD_TARGET_ARCH),amd64)
|
---|
68 | OBJS += alloc/heapsimple.o
|
---|
69 | endif
|
---|
70 |
|
---|
71 | ifneq ($(MAKECMDGOALS),clean)
|
---|
72 |
|
---|
73 | # kernel base directory
|
---|
74 | ifndef KERN_DIR
|
---|
75 | # build for the current kernel, version check
|
---|
76 | KERN_DIR := /lib/modules/$(shell uname -r)/build
|
---|
77 | ifneq ($(shell if test -d $(KERN_DIR); then echo yes; fi),yes)
|
---|
78 | KERN_DIR := /usr/src/linux
|
---|
79 | ifneq ($(shell if test -d $(KERN_DIR); then echo yes; fi),yes)
|
---|
80 | $(error Error: unable to find the sources of your current Linux kernel. Specify KERN_DIR=<directory> and run Make again.)
|
---|
81 | endif
|
---|
82 | $(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.)
|
---|
83 | endif
|
---|
84 | # check if versions match -- works only for later 2.6 kernels
|
---|
85 | VBOX_KERN_VER := $(shell $(MAKE) -sC $(KERN_DIR) kernelrelease 2> /dev/null || true)
|
---|
86 | ifneq ($(VBOX_KERN_VER),)
|
---|
87 | ifneq ($(VBOX_KERN_VER),$(shell uname -r))
|
---|
88 | $(error Error: /usr/src/linux (version $(VBOX_KERN_VER)) does not match the current kernel (version $(shell uname -r)))
|
---|
89 | endif
|
---|
90 | endif
|
---|
91 | else
|
---|
92 | # build for a dedicated kernel, no version check
|
---|
93 | ifneq ($(shell if test -d $(KERN_DIR); then echo yes; fi),yes)
|
---|
94 | $(error Error: KERN_DIR does not point to a directory.)
|
---|
95 | endif
|
---|
96 | endif
|
---|
97 |
|
---|
98 | # includes
|
---|
99 | ifndef KERN_INCL
|
---|
100 | KERN_INCL = $(KERN_DIR)/include
|
---|
101 | endif
|
---|
102 | ifneq ($(shell if test -d $(KERN_INCL); then echo yes; fi),yes)
|
---|
103 | $(error Error: unable to find the include directory for your current Linux kernel. Specify KERN_INCL=<directory> and run Make again.)
|
---|
104 | endif
|
---|
105 |
|
---|
106 | # module install dir, only for current kernel
|
---|
107 | ifneq ($(filter install install_rpm,$(MAKECMDGOALS)),)
|
---|
108 | ifndef MODULE_DIR
|
---|
109 | MODULE_DIR_TST := /lib/modules/$(shell uname -r)
|
---|
110 | ifeq ($(shell if test -d $(MODULE_DIR_TST); then echo yes; fi),yes)
|
---|
111 | MODULE_DIR := $(MODULE_DIR_TST)/misc
|
---|
112 | else
|
---|
113 | $(error Unable to find the folder to install the support driver to)
|
---|
114 | endif
|
---|
115 | endif # MODULE_DIR unspecified
|
---|
116 | endif
|
---|
117 |
|
---|
118 | # guess kernel version (24 or 26)
|
---|
119 | KERN_VERSION := $(if $(wildcard $(KERN_DIR)/Rules.make),24,26)
|
---|
120 |
|
---|
121 | # debug - show guesses.
|
---|
122 | ifdef DEBUG
|
---|
123 | $(warning dbg: KERN_DIR = $(KERN_DIR))
|
---|
124 | $(warning dbg: KERN_INCL = $(KERN_INCL))
|
---|
125 | $(warning dbg: MODULE_DIR = $(MODULE_DIR))
|
---|
126 | $(warning dbg: KERN_VERSION = $(KERN_VERSION))
|
---|
127 | endif
|
---|
128 |
|
---|
129 | #
|
---|
130 | # Compiler options
|
---|
131 | #
|
---|
132 | ifndef INCL
|
---|
133 | INCL := -I$(KERN_INCL) $(addprefix -I, $(EXTRA_INCL))
|
---|
134 | ifndef KBUILD_EXTMOD
|
---|
135 | KBUILD_EXTMOD := $(shell pwd)
|
---|
136 | endif
|
---|
137 | INCL += $(addprefix -I$(KBUILD_EXTMOD),/ /include /r0drv/linux)
|
---|
138 | export INCL
|
---|
139 | endif
|
---|
140 | KFLAGS := -D__KERNEL__ -DMODULE -DRT_OS_LINUX -DIN_RING0 -DIN_RT_R0 -DIN_SUP_R0
|
---|
141 | ifndef CONFIG_VBOXDRV_FIXEDMAJOR
|
---|
142 | KFLAGS += -DCONFIG_VBOXDRV_AS_MISC
|
---|
143 | endif
|
---|
144 | ifeq ($(BUILD_TARGET_ARCH),amd64)
|
---|
145 | KFLAGS += -DRT_ARCH_AMD64
|
---|
146 | else
|
---|
147 | KFLAGS += -DRT_ARCH_X86
|
---|
148 | endif
|
---|
149 | #ifeq ($(BUILD_TYPE),debug) - you'll have to enable this manually to get debug stuff.
|
---|
150 | #KFLAGS += -DDEBUG
|
---|
151 | #endif
|
---|
152 |
|
---|
153 | #
|
---|
154 | # Use the RTR0MemObj API - testing.
|
---|
155 | # If this makes testboxes crash/burn/leak disable it and add a comment to defect #2116.
|
---|
156 | #
|
---|
157 | KFLAGS += -DUSE_NEW_OS_INTERFACE_FOR_MM
|
---|
158 | OBJS += r0drv/memobj-r0drv.o \
|
---|
159 | r0drv/linux/memobj-r0drv-linux.o
|
---|
160 | ifeq ($(BUILD_TARGET_ARCH),x86) # Some gcc versions ends up needing __divdi3.
|
---|
161 | OBJS += math/gcc/qdivrem.o \
|
---|
162 | math/gcc/divdi3.o
|
---|
163 | endif
|
---|
164 |
|
---|
165 | ifeq ($(KERN_VERSION), 24)
|
---|
166 | # 2.4
|
---|
167 | TOPDIR = $(KERN_DIR)
|
---|
168 | MODULE_EXT := o
|
---|
169 | EXTRA_CFLAGS := -DVBOX_LINUX_2_4
|
---|
170 | $(MODULE)-objs = $(OBJS)
|
---|
171 | else
|
---|
172 | # 2.6 and later
|
---|
173 | MODULE_EXT := ko
|
---|
174 | $(MODULE)-y := $(OBJS)
|
---|
175 | endif
|
---|
176 |
|
---|
177 | # build defs
|
---|
178 | EXTRA_CFLAGS += $(INCL) $(KFLAGS) $(KDEBUG)
|
---|
179 |
|
---|
180 | all: $(MODULE)
|
---|
181 |
|
---|
182 | obj-m += $(MODULE).o
|
---|
183 |
|
---|
184 | $(MODULE):
|
---|
185 | $(MAKE) KBUILD_VERBOSE=1 -C $(KERN_DIR) SUBDIRS=$(CURDIR) SRCROOT=$(CURDIR) modules
|
---|
186 |
|
---|
187 | ifeq ($(KERN_VERSION), 24)
|
---|
188 | #
|
---|
189 | # 2.4 Module linking
|
---|
190 | #
|
---|
191 | $(MODULE).o: $(OBJS)
|
---|
192 | $(LD) -o $@ -r $(OBJS)
|
---|
193 |
|
---|
194 | include $(KERN_DIR)/Rules.make
|
---|
195 |
|
---|
196 | endif
|
---|
197 |
|
---|
198 | install: $(MODULE)
|
---|
199 | @mkdir -p $(MODULE_DIR); \
|
---|
200 | install -m 0664 -o root -g root $(MODULE).$(MODULE_EXT) $(MODULE_DIR); \
|
---|
201 | PATH="$(PATH):/bin:/sbin" depmod -ae; \
|
---|
202 | rm -f /etc/vbox/module_not_compiled
|
---|
203 |
|
---|
204 | install_rpm: $(MODULE)
|
---|
205 | @mkdir -p $(MODULE_DIR); \
|
---|
206 | install -m 0664 $(MODULE).$(MODULE_EXT) $(MODULE_DIR)
|
---|
207 |
|
---|
208 | endif # eq($(MAKECMDGOALS),clean)
|
---|
209 |
|
---|
210 | clean:
|
---|
211 | for f in . linux r0drv r0drv/linux; do rm -f $$f/*.o $$f/.*.cmd $$f/.*.flags; done
|
---|
212 | rm -rf .vboxdrv* .tmp_ver* vboxdrv.* Module.symvers Modules.symvers
|
---|