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 | MODULE = vboxdrv
|
---|
24 | OBJS = \
|
---|
25 | linux/SUPDrv-linux.o \
|
---|
26 | SUPDRVShared.o \
|
---|
27 | r0drv/alloc-r0drv.o \
|
---|
28 | r0drv/linux/alloc-r0drv-linux.o \
|
---|
29 | r0drv/linux/semaphore-r0drv-linux.o \
|
---|
30 | r0drv/linux/spinlock-r0drv-linux.o \
|
---|
31 | r0drv/linux/thread-r0drv-linux.o \
|
---|
32 |
|
---|
33 | ifneq ($(MAKECMDGOALS),clean)
|
---|
34 |
|
---|
35 | # kernel base directory
|
---|
36 | ifndef $(KERN_DIR)
|
---|
37 | KERN_DIR := /lib/modules/$(shell uname -r)/build
|
---|
38 | ifneq ($(shell if test -d $(KERN_DIR); then echo yes; fi),yes)
|
---|
39 | KERN_DIR := /usr/src/linux
|
---|
40 | ifneq ($(shell if test -d $(KERN_DIR); then echo yes; fi),yes)
|
---|
41 | $(error Error: unable to find the sources of your current Linux kernel. Specify KERN_DIR=<directory> and run Make again.)
|
---|
42 | endif
|
---|
43 | $(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.)
|
---|
44 | endif
|
---|
45 | else
|
---|
46 | ifneq ($(shell if test -d $(KERN_DIR); then echo yes; fi),yes)
|
---|
47 | $(error Error: KERN_DIR does not point to a directory.)
|
---|
48 | endif
|
---|
49 | endif
|
---|
50 |
|
---|
51 | # includes
|
---|
52 | ifndef $(KERN_INCL)
|
---|
53 | KERN_INCL = $(KERN_DIR)/include
|
---|
54 | $(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.)
|
---|
55 | endif
|
---|
56 | ifneq ($(shell if test -d $(KERN_INCL); then echo yes; fi),yes)
|
---|
57 | $(error Error: unable to find the include directory for your current Linux kernel. Specify $KERN_INCL=<directory> and run Make again.)
|
---|
58 | endif
|
---|
59 |
|
---|
60 | # module install dir.
|
---|
61 | ifndef MODULE_DIR
|
---|
62 | MODULE_DIR_TST := /lib/modules/$(shell uname -r)
|
---|
63 | ifeq ($(shell if test -d $(MODULE_DIR_TST); then echo yes; fi),yes)
|
---|
64 | MODULE_DIR := $(MODULE_DIR_TST)/misc
|
---|
65 | else
|
---|
66 | $(error Error: could not find the module directory for your current Linux kernel)
|
---|
67 | endif
|
---|
68 | endif # MODULE_DIR unspecified
|
---|
69 |
|
---|
70 | # guess kernel version (24 or 26)
|
---|
71 | KERN_VERSION := $(if $(wildcard $(KERN_DIR)/Rules.make),24,26)
|
---|
72 |
|
---|
73 | # debug - show guesses.
|
---|
74 | ifdef DEBUG
|
---|
75 | $(warning dbg: KERN_DIR = $(KERN_DIR))
|
---|
76 | $(warning dbg: KERN_INCL = $(KERN_INCL))
|
---|
77 | $(warning dbg: MODULE_DIR = $(MODULE_DIR))
|
---|
78 | $(warning dbg: KERN_VERSION = $(KERN_VERSION))
|
---|
79 | endif
|
---|
80 |
|
---|
81 | #
|
---|
82 | # Compiler options
|
---|
83 | #
|
---|
84 | ifndef INCL
|
---|
85 | INCL := -I$(KERN_INCL)
|
---|
86 | ifndef KBUILD_EXTMOD
|
---|
87 | KBUILD_EXTMOD := $(shell pwd)
|
---|
88 | endif
|
---|
89 | INCL += $(addprefix -I$(KBUILD_EXTMOD),/ /include /r0drv/linux)
|
---|
90 | export INCL
|
---|
91 | endif
|
---|
92 | KFLAGS := -D__KERNEL__ -DMODULE -D__LINUX__ -DIN_RING0 -DIN_RT_R0 -DIN_SUP_R0
|
---|
93 | ifndef CONFIG_VBOXDRV_FIXEDMAJOR
|
---|
94 | KFLAGS += -DCONFIG_VBOXDRV_AS_MISC
|
---|
95 | endif
|
---|
96 | ifeq ($(filter-out x86_64 amd64 AMD64,$(shell uname -m)),)
|
---|
97 | KFLAGS += -D__AMD64__
|
---|
98 | else
|
---|
99 | KFLAGS += -D__X86__
|
---|
100 | endif
|
---|
101 | #ifeq ($(BUILD_TYPE),debug) - you'll have to enable this manually to get debug stuff.
|
---|
102 | #KFLAGS += -DDEBUG
|
---|
103 | #endif
|
---|
104 |
|
---|
105 | ifeq ($(KERN_VERSION), 24)
|
---|
106 | # 2.4
|
---|
107 | TOPDIR = $(KERN_DIR)
|
---|
108 | MODULE_EXT := o
|
---|
109 | EXTRA_CFLAGS := -DVBOX_LINUX_2_4
|
---|
110 | $(MODULE)-objs = $(OBJS)
|
---|
111 | else
|
---|
112 | # 2.6 and later
|
---|
113 | MODULE_EXT := ko
|
---|
114 | $(MODULE)-y := $(OBJS)
|
---|
115 | endif
|
---|
116 |
|
---|
117 | # build defs
|
---|
118 | EXTRA_CFLAGS += $(INCL) $(KFLAGS) $(KDEBUG)
|
---|
119 |
|
---|
120 | all: $(MODULE)
|
---|
121 |
|
---|
122 | obj-m += $(MODULE).o
|
---|
123 |
|
---|
124 | $(MODULE):
|
---|
125 | $(MAKE) KBUILD_VERBOSE=1 -C $(KERN_DIR) SUBDIRS=$(CURDIR) SRCROOT=$(CURDIR) modules
|
---|
126 |
|
---|
127 | ifeq ($(KERN_VERSION), 24)
|
---|
128 | #
|
---|
129 | # 2.4 Module linking
|
---|
130 | #
|
---|
131 | $(MODULE).o: $(OBJS)
|
---|
132 | $(LD) -o $@ -r $(OBJS)
|
---|
133 |
|
---|
134 | include $(KERN_DIR)/Rules.make
|
---|
135 |
|
---|
136 | endif
|
---|
137 |
|
---|
138 | install: $(MODULE)
|
---|
139 | @mkdir -p $(MODULE_DIR); \
|
---|
140 | install -m 0664 -o root -g root $(MODULE).$(MODULE_EXT) $(MODULE_DIR); \
|
---|
141 | PATH="$(PATH):/bin:/sbin" depmod -ae; \
|
---|
142 | rm -f /etc/vbox/module_not_compiled
|
---|
143 |
|
---|
144 | endif # eq($(MAKECMDGOALS),clean)
|
---|
145 |
|
---|
146 | clean:
|
---|
147 | for f in . linux r0drv r0drv/linux; do rm -f $$f/*.o $$f/.*.cmd $$f/.*.flags; done
|
---|
148 | rm -rf .vboxdrv* .tmp_ver* vboxdrv.* Module.symvers Modules.symvers
|
---|
149 |
|
---|