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 InnoTek Systemberatung GmbH
|
---|
9 | #
|
---|
10 | # This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
11 | # available from http://www.virtualbox.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 as published by the Free Software Foundation,
|
---|
14 | # in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
|
---|
15 | # distribution. VirtualBox OSE is distributed in the hope that it will
|
---|
16 | # be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
17 | #
|
---|
18 | # If you received this file as part of a commercial VirtualBox
|
---|
19 | # distribution, then only the terms of your commercial VirtualBox
|
---|
20 | # license agreement apply instead of the previous paragraph.
|
---|
21 | #
|
---|
22 |
|
---|
23 | #
|
---|
24 | # First, figure out which architecture we're targeting.
|
---|
25 | # (We have to support basic cross building (ARCH=i386|x86_64).)
|
---|
26 | #
|
---|
27 | ifneq ($(filter-out amd64 x86,$(BUILD_TARGET_ARCH)),)
|
---|
28 | $(warning Ignoring unknown BUILD_TARGET_ARCH value '$(BUILD_TARGET_ARCH)'.)
|
---|
29 | BUILD_TARGET_ARCH :=
|
---|
30 | endif
|
---|
31 | ifeq ($(BUILD_TARGET_ARCH),)
|
---|
32 | ifeq ($(ARCH),x86_64)
|
---|
33 | BUILD_TARGET_ARCH := amd64
|
---|
34 | else
|
---|
35 | ifeq ($(ARCH),i386)
|
---|
36 | BUILD_TARGET_ARCH := x86
|
---|
37 | else
|
---|
38 | ifeq ($(filter-out x86_64 amd64 AMD64,$(shell uname -m)),)
|
---|
39 | BUILD_TARGET_ARCH := amd64
|
---|
40 | else
|
---|
41 | BUILD_TARGET_ARCH := x86
|
---|
42 | endif
|
---|
43 | endif
|
---|
44 | endif
|
---|
45 | endif
|
---|
46 |
|
---|
47 |
|
---|
48 | MODULE = vboxdrv
|
---|
49 | OBJS = \
|
---|
50 | linux/SUPDrv-linux.o \
|
---|
51 | SUPDRVShared.o \
|
---|
52 | r0drv/alloc-r0drv.o \
|
---|
53 | r0drv/initterm-r0drv.o \
|
---|
54 | r0drv/linux/alloc-r0drv-linux.o \
|
---|
55 | r0drv/linux/initterm-r0drv-linux.o \
|
---|
56 | r0drv/linux/process-r0drv-linux.o \
|
---|
57 | r0drv/linux/semaphore-r0drv-linux.o \
|
---|
58 | r0drv/linux/spinlock-r0drv-linux.o \
|
---|
59 | r0drv/linux/thread-r0drv-linux.o
|
---|
60 | ifeq ($(BUILD_TARGET_ARCH),amd64)
|
---|
61 | OBJS += alloc/heapsimple.o
|
---|
62 | endif
|
---|
63 |
|
---|
64 |
|
---|
65 | ifneq ($(MAKECMDGOALS),clean)
|
---|
66 |
|
---|
67 | # kernel base directory
|
---|
68 | ifndef KERN_DIR
|
---|
69 | KERN_DIR := /lib/modules/$(shell uname -r)/build
|
---|
70 | ifneq ($(shell if test -d $(KERN_DIR); then echo yes; fi),yes)
|
---|
71 | KERN_DIR := /usr/src/linux
|
---|
72 | ifneq ($(shell if test -d $(KERN_DIR); then echo yes; fi),yes)
|
---|
73 | $(error Error: unable to find the sources of your current Linux kernel. Specify KERN_DIR=<directory> and run Make again.)
|
---|
74 | endif
|
---|
75 | $(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.)
|
---|
76 | endif
|
---|
77 | else
|
---|
78 | ifneq ($(shell if test -d $(KERN_DIR); then echo yes; fi),yes)
|
---|
79 | $(error Error: KERN_DIR does not point to a directory.)
|
---|
80 | endif
|
---|
81 | endif
|
---|
82 |
|
---|
83 | # includes
|
---|
84 | ifndef KERN_INCL
|
---|
85 | KERN_INCL = $(KERN_DIR)/include
|
---|
86 | endif
|
---|
87 | ifneq ($(shell if test -d $(KERN_INCL); then echo yes; fi),yes)
|
---|
88 | $(error Error: unable to find the include directory for your current Linux kernel. Specify $KERN_INCL=<directory> and run Make again.)
|
---|
89 | endif
|
---|
90 |
|
---|
91 | # module install dir.
|
---|
92 | ifndef MODULE_DIR
|
---|
93 | MODULE_DIR_TST := /lib/modules/$(shell uname -r)
|
---|
94 | ifeq ($(shell if test -d $(MODULE_DIR_TST); then echo yes; fi),yes)
|
---|
95 | MODULE_DIR := $(MODULE_DIR_TST)/misc
|
---|
96 | else
|
---|
97 | $(error Unable to find the folder to install the support driver to)
|
---|
98 | endif
|
---|
99 | endif # MODULE_DIR unspecified
|
---|
100 |
|
---|
101 | # guess kernel version (24 or 26)
|
---|
102 | KERN_VERSION := $(if $(wildcard $(KERN_DIR)/Rules.make),24,26)
|
---|
103 |
|
---|
104 | # debug - show guesses.
|
---|
105 | ifdef DEBUG
|
---|
106 | $(warning dbg: KERN_DIR = $(KERN_DIR))
|
---|
107 | $(warning dbg: KERN_INCL = $(KERN_INCL))
|
---|
108 | $(warning dbg: MODULE_DIR = $(MODULE_DIR))
|
---|
109 | $(warning dbg: KERN_VERSION = $(KERN_VERSION))
|
---|
110 | endif
|
---|
111 |
|
---|
112 | #
|
---|
113 | # Compiler options
|
---|
114 | #
|
---|
115 | ifndef INCL
|
---|
116 | INCL := -I$(KERN_INCL) $(addprefix -I, $(EXTRA_INCL))
|
---|
117 | ifndef KBUILD_EXTMOD
|
---|
118 | KBUILD_EXTMOD := $(shell pwd)
|
---|
119 | endif
|
---|
120 | INCL += $(addprefix -I$(KBUILD_EXTMOD),/ /include /r0drv/linux)
|
---|
121 | export INCL
|
---|
122 | endif
|
---|
123 | KFLAGS := -D__KERNEL__ -DMODULE -D__LINUX__ -DIN_RING0 -DIN_RT_R0 -DIN_SUP_R0
|
---|
124 | ifndef CONFIG_VBOXDRV_FIXEDMAJOR
|
---|
125 | KFLAGS += -DCONFIG_VBOXDRV_AS_MISC
|
---|
126 | endif
|
---|
127 | ifeq ($(BUILD_TARGET_ARCH),amd64)
|
---|
128 | KFLAGS += -D__AMD64__
|
---|
129 | else
|
---|
130 | KFLAGS += -D__X86__
|
---|
131 | endif
|
---|
132 | #ifeq ($(BUILD_TYPE),debug) - you'll have to enable this manually to get debug stuff.
|
---|
133 | #KFLAGS += -DDEBUG
|
---|
134 | #endif
|
---|
135 |
|
---|
136 | ifeq ($(KERN_VERSION), 24)
|
---|
137 | # 2.4
|
---|
138 | TOPDIR = $(KERN_DIR)
|
---|
139 | MODULE_EXT := o
|
---|
140 | EXTRA_CFLAGS := -DVBOX_LINUX_2_4
|
---|
141 | $(MODULE)-objs = $(OBJS)
|
---|
142 | else
|
---|
143 | # 2.6 and later
|
---|
144 | MODULE_EXT := ko
|
---|
145 | $(MODULE)-y := $(OBJS)
|
---|
146 | endif
|
---|
147 |
|
---|
148 | # build defs
|
---|
149 | EXTRA_CFLAGS += $(INCL) $(KFLAGS) $(KDEBUG)
|
---|
150 |
|
---|
151 | all: $(MODULE)
|
---|
152 |
|
---|
153 | obj-m += $(MODULE).o
|
---|
154 |
|
---|
155 | $(MODULE):
|
---|
156 | $(MAKE) KBUILD_VERBOSE=1 -C $(KERN_DIR) SUBDIRS=$(CURDIR) SRCROOT=$(CURDIR) modules
|
---|
157 |
|
---|
158 | ifeq ($(KERN_VERSION), 24)
|
---|
159 | #
|
---|
160 | # 2.4 Module linking
|
---|
161 | #
|
---|
162 | $(MODULE).o: $(OBJS)
|
---|
163 | $(LD) -o $@ -r $(OBJS)
|
---|
164 |
|
---|
165 | include $(KERN_DIR)/Rules.make
|
---|
166 |
|
---|
167 | endif
|
---|
168 |
|
---|
169 | install: $(MODULE)
|
---|
170 | @mkdir -p $(MODULE_DIR); \
|
---|
171 | install -m 0664 -o root -g root $(MODULE).$(MODULE_EXT) $(MODULE_DIR); \
|
---|
172 | PATH="$(PATH):/bin:/sbin" depmod -ae; \
|
---|
173 | rm -f /etc/vbox/module_not_compiled
|
---|
174 |
|
---|
175 | install_rpm: $(MODULE)
|
---|
176 | @mkdir -p $(MODULE_DIR); \
|
---|
177 | install -m 0664 $(MODULE).$(MODULE_EXT) $(MODULE_DIR)
|
---|
178 |
|
---|
179 | endif # eq($(MAKECMDGOALS),clean)
|
---|
180 |
|
---|
181 | clean:
|
---|
182 | for f in . linux r0drv r0drv/linux; do rm -f $$f/*.o $$f/.*.cmd $$f/.*.flags; done
|
---|
183 | rm -rf .vboxdrv* .tmp_ver* vboxdrv.* Module.symvers Modules.symvers
|
---|