VirtualBox

source: vbox/trunk/src/VBox/Additions/linux/drm/Makefile.module@ 18703

Last change on this file since 18703 was 17935, checked in by vboxsync, 16 years ago

Additions/linux: fixed kernel detection

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.5 KB
Line 
1#
2# VirtualBox Guest Additions Module Makefile.
3#
4# (For 2.6.x this file must be 'Makefile'!)
5#
6# Copyright (C) 2006-2007 Sun Microsystems, Inc.
7#
8# This file is part of VirtualBox Open Source Edition (OSE), as
9# available from http://www.virtualbox.org. This file is free software;
10# you can redistribute it and/or modify it under the terms of the GNU
11# General Public License (GPL) as published by the Free Software
12# Foundation, in version 2 as it comes in the "COPYING" file of the
13# VirtualBox OSE distribution. VirtualBox OSE is distributed in the
14# hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
15#
16# Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
17# Clara, CA 95054 USA or visit http://www.sun.com if you need
18# additional information or have any questions.
19#
20
21## @todo We must make this into a common template *soon*.
22
23#
24# First, figure out which architecture we're targeting and the build type.
25# (We have to support basic cross building (ARCH=i386|x86_64).)
26# While at it, warn about BUILD_* vars found to help with user problems.
27#
28ifneq ($(filter-out amd64 x86,$(BUILD_TARGET_ARCH)),)
29 $(warning Ignoring unknown BUILD_TARGET_ARCH value '$(BUILD_TARGET_ARCH)'.)
30 BUILD_TARGET_ARCH :=
31endif
32ifeq ($(BUILD_TARGET_ARCH),)
33 ifeq ($(ARCH),x86_64)
34 BUILD_TARGET_ARCH := amd64
35 else
36 ifeq ($(ARCH),i386)
37 BUILD_TARGET_ARCH := x86
38 else
39 ifeq ($(filter-out x86_64 amd64 AMD64,$(shell uname -m)),)
40 BUILD_TARGET_ARCH := amd64
41 else
42 BUILD_TARGET_ARCH := x86
43 endif
44 endif
45 endif
46else
47 $(warning Using BUILD_TARGET_ARCH='$(BUILD_TARGET_ARCH)' from the $(origin BUILD_TARGET_ARCH).)
48endif
49
50ifneq ($(filter-out release profile debug strict,$(BUILD_TYPE)),)
51 $(warning Ignoring unknown BUILD_TYPE value '$(BUILD_TYPE)'.)
52 BUILD_TYPE :=
53endif
54ifeq ($(BUILD_TYPE),)
55 BUILD_TYPE := release
56else
57 $(warning Using BUILD_TYPE='$(BUILD_TYPE)' from the $(origin BUILD_TYPE).)
58endif
59
60EXTRA_CFLAGS = -fshort-wchar
61
62ifneq ($(MAKECMDGOALS),clean)
63
64ifeq ($(KERNELRELEASE),)
65
66 #
67 # building from this directory
68 #
69
70 # kernel base directory
71 ifndef KERN_DIR
72 KERN_DIR := /lib/modules/$(shell uname -r)/build
73 ifneq ($(shell if test -d $(KERN_DIR); then echo yes; fi),yes)
74 KERN_DIR := /usr/src/linux
75 ifneq ($(shell if test -d $(KERN_DIR); then echo yes; fi),yes)
76 $(error Error: unable to find the sources of your current Linux kernel. \
77 Specify KERN_DIR=<directory> and run Make again)
78 endif
79 $(warning Warning: using /usr/src/linux as the source directory of your \
80 Linux kernel. If this is not correct, specify \
81 KERN_DIR=<directory> and run Make again.)
82 endif
83 else
84 ifneq ($(shell if test -d $(KERN_DIR); then echo yes; fi),yes)
85 $(error Error: KERN_DIR does not point to a directory)
86 endif
87 endif
88
89 # includes
90 ifndef KERN_INCL
91 KERN_INCL = $(KERN_DIR)/include
92 endif
93 ifneq ($(shell if test -d $(KERN_INCL); then echo yes; fi),yes)
94 $(error Error: unable to find the include directory for your current Linux \
95 kernel. Specify KERN_INCL=<directory> and run Make again)
96 endif
97
98 # module install dir.
99 ifneq ($(filter install install_rpm,$(MAKECMDGOALS)),)
100 ifndef MODULE_DIR
101 MODULE_DIR_TST := /lib/modules/$(shell uname -r)
102 ifeq ($(shell if test -d $(MODULE_DIR_TST); then echo yes; fi),yes)
103 MODULE_DIR := $(MODULE_DIR_TST)/misc
104 else
105 $(error Unable to find the folder to install the DRM driver to)
106 endif
107 endif # MODULE_DIR unspecified
108 endif
109
110 # guess kernel version (24 or 26)
111 ifeq ($(shell if grep '"2\.4\.' $(KERN_INCL)/linux/version.h > /dev/null; then echo yes; fi),yes)
112 KERN_VERSION := 24
113 else
114 KERN_VERSION := 26
115 endif
116
117else # neq($(KERNELRELEASE),)
118
119 #
120 # building from kbuild (make -C <kernel_directory> M=`pwd`)
121 #
122
123 # guess kernel version (24 or 26)
124 ifeq ($(shell if echo "$(VERSION).$(PATCHLEVEL)." | grep '2\.4\.' > /dev/null; then echo yes; fi),yes)
125 KERN_VERSION := 24
126 else
127 KERN_VERSION := 26
128 endif
129
130endif # neq($(KERNELRELEASE),)
131
132# debug - show guesses.
133ifdef DEBUG
134$(warning dbg: KERN_DIR = $(KERN_DIR))
135$(warning dbg: KERN_INCL = $(KERN_INCL))
136$(warning dbg: MODULE_DIR = $(MODULE_DIR))
137$(warning dbg: KERN_VERSION = $(KERN_VERSION))
138endif
139
140KBUILD_VERBOSE ?= 1
141
142#
143# Compiler options
144#
145ifndef INCL
146 INCL := $(addprefix -I,$(KERN_INCL) $(EXTRA_INCL))
147 ifndef KBUILD_EXTMOD
148 KBUILD_EXTMOD := $(shell pwd)
149 endif
150 INCL += $(addprefix -I$(KBUILD_EXTMOD),/ /include /r0drv/linux)
151 export INCL
152endif
153KFLAGS := -D__KERNEL__ -DMODULE -DRT_OS_LINUX -DIN_RING0 -DIN_RT_R0 \
154 -DIN_SUP_R0 -DVBOX -DVBOX_WITH_HGCM -DLOG_TO_BACKDOOR -DIN_MODULE \
155 -DIN_GUEST_R0
156ifeq ($(BUILD_TARGET_ARCH),amd64)
157 KFLAGS += -DRT_ARCH_AMD64 -DVBOX_WITH_64_BITS_GUESTS
158else
159 KFLAGS += -DRT_ARCH_X86
160endif
161ifeq ($(BUILD_TYPE),debug)
162KFLAGS += -DDEBUG
163endif
164
165# override is required by the Debian guys
166override MODULE = vboxvideo
167OBJS = vboxvideo_drm.o
168
169ifeq ($(KERN_VERSION), 24)
170#
171# 2.4
172#
173
174CFLAGS := -O2 -DVBOX_LINUX_2_4 $(INCL) $(KFLAGS) $(KDEBUG)
175MODULE_EXT := o
176
177# 2.4 Module linking
178$(MODULE).o: $(OBJS)
179 $(LD) -o $@ -r $(OBJS)
180
181.PHONY: $(MODULE)
182all: $(MODULE)
183$(MODULE): $(MODULE).o
184
185else
186#
187# 2.6 and later
188#
189
190MODULE_EXT := ko
191
192$(MODULE)-y := $(OBJS)
193
194# special hack for Fedora Core 6 2.6.18 (fc6), rhel5 2.6.18 (el5),
195# ClarkConnect 4.3 (cc4) and ClarkConnect 5 (v5)
196ifeq ($(KERNELRELEASE),)
197 KFLAGS += $(foreach inc,$(KERN_INCL),\
198 $(if $(wildcard $(inc)/linux/utsrelease.h),\
199 $(if $(shell grep '"2.6.18.*fc6.*"' $(inc)/linux/utsrelease.h; \
200 grep '"2.6.18.*el5.*"' $(inc)/linux/utsrelease.h; \
201 grep '"2.6.18.*v5.*"' $(inc)/linux/utsrelease.h; \
202 grep '"2.6.18.*cc4.*"' $(inc)/linux/utsrelease.h),\
203 -DKERNEL_FC6,),))
204else
205 KFLAGS += $(if $(shell echo "$(KERNELRELEASE)"|grep '2.6.18.*fc6.*';\
206 echo "$(KERNELRELEASE)"|grep '2.6.18.*el5.*';\
207 echo "$(KERNELRELEASE)"|grep '2.6.18.*v5.*';\
208 echo "$(KERNELRELEASE)"|grep '2.6.18.*cc4.*'),\
209 -DKERNEL_FC6,)
210endif
211
212# build defs
213EXTRA_CFLAGS += $(INCL) $(KFLAGS) $(KDEBUG)
214
215all: $(MODULE)
216
217obj-m += $(MODULE).o
218
219$(MODULE):
220 $(MAKE) KBUILD_VERBOSE=$(KBUILD_VERBOSE) -C $(KERN_DIR) SUBDIRS=$(CURDIR) SRCROOT=$(CURDIR) modules
221
222endif
223
224install: $(MODULE)
225 @mkdir -p $(MODULE_DIR); \
226 install -m 0664 -o root -g root $(MODULE).$(MODULE_EXT) $(MODULE_DIR); \
227 PATH="$(PATH):/bin:/sbin" depmod -ae;
228
229endif # eq($(MAKECMDGOALS),clean)
230
231# important: Don't remove Module.symvers! DKMS does 'make clean' before building ...
232clean:
233 for f in . linux r0drv r0drv/linux; do rm -f $$f/*.o $$f/.*.cmd $$f/.*.flags; done
234 rm -rf .vboxvideo* .tmp_ver* vboxvideo.* Modules.symvers modules.order
235
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette