1 | #
|
---|
2 | # VirtualBox Guest Additions Module Makefile.
|
---|
3 | #
|
---|
4 | # (For 2.6.x this file must be 'Makefile'!)
|
---|
5 | #
|
---|
6 | # Copyright (C) 2006-2010 Oracle Corporation
|
---|
7 | #
|
---|
8 | # Use only with permission
|
---|
9 | #
|
---|
10 |
|
---|
11 | #
|
---|
12 | MODULE = vboxadd_test
|
---|
13 | OBJS = test.o
|
---|
14 |
|
---|
15 | ifneq ($(MAKECMDGOALS),clean)
|
---|
16 |
|
---|
17 | # kernel base directory
|
---|
18 | ifndef KERN_DIR
|
---|
19 | KERN_DIR := /lib/modules/$(shell uname -r)/build
|
---|
20 | ifneq ($(shell if test -d $(KERN_DIR); then echo yes; fi),yes)
|
---|
21 | KERN_DIR := /usr/src/linux
|
---|
22 | ifneq ($(shell if test -d $(KERN_DIR); then echo yes; fi),yes)
|
---|
23 | $(error Error: unable to find the sources of your current Linux kernel. Specify KERN_DIR=<directory> and run Make again.)
|
---|
24 | endif
|
---|
25 | $(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.)
|
---|
26 | endif
|
---|
27 | else
|
---|
28 | ifneq ($(shell if test -d $(KERN_DIR); then echo yes; fi),yes)
|
---|
29 | $(error Error: KERN_DIR does not point to a directory.)
|
---|
30 | endif
|
---|
31 | endif
|
---|
32 |
|
---|
33 | # includes
|
---|
34 | ifndef KERN_INCL
|
---|
35 | KERN_INCL = $(KERN_DIR)/include
|
---|
36 | endif
|
---|
37 | ifneq ($(shell if test -d $(KERN_INCL); then echo yes; fi),yes)
|
---|
38 | $(error Error: unable to find the include directory for your current Linux kernel. Specify KERN_INCL=<directory> and run Make again.)
|
---|
39 | endif
|
---|
40 |
|
---|
41 | # guess kernel version (24 or 26)
|
---|
42 | ifeq ($(shell if grep '"2.4.' $(KERN_INCL)/linux/version.h > /dev/null; then echo yes; fi),yes)
|
---|
43 | KERN_VERSION := 24
|
---|
44 | else
|
---|
45 | KERN_VERSION := 26
|
---|
46 | endif
|
---|
47 | # KERN_VERSION := $(if $(wildcard $(KERN_DIR)/Rules.make),24,26)
|
---|
48 |
|
---|
49 | # debug - show guesses.
|
---|
50 | ifdef DEBUG
|
---|
51 | $(warning dbg: KERN_DIR = $(KERN_DIR))
|
---|
52 | $(warning dbg: KERN_INCL = $(KERN_INCL))
|
---|
53 | $(warning dbg: MODULE_DIR = $(MODULE_DIR))
|
---|
54 | $(warning dbg: KERN_VERSION = $(KERN_VERSION))
|
---|
55 | endif
|
---|
56 |
|
---|
57 |
|
---|
58 | #
|
---|
59 | # Compiler options
|
---|
60 | #
|
---|
61 | ifndef INCL
|
---|
62 | INCL := -I$(KERN_INCL) $(addprefix -I, $(EXTRA_INCL))
|
---|
63 | ifndef KBUILD_EXTMOD
|
---|
64 | KBUILD_EXTMOD := $(shell pwd)
|
---|
65 | endif
|
---|
66 | INCL += $(addprefix -I$(KBUILD_EXTMOD),/ /include /r0drv/linux)
|
---|
67 | export INCL
|
---|
68 | endif
|
---|
69 | KFLAGS := -D__KERNEL__ -DMODULE -DRT_OS_LINUX -DIN_RING0 -D_X86_ -DIN_RT_R0 -DIN_SUP_R0 \
|
---|
70 | -DVBGL_VBOXGUEST -DVBGL_HGCM -DVBOX_WITH_HGCM
|
---|
71 | ifeq ($(BUILD_TYPE),debug)
|
---|
72 | KFLAGS += -DDEBUG
|
---|
73 | endif
|
---|
74 |
|
---|
75 | ifeq ($(KERN_VERSION), 24)
|
---|
76 | #
|
---|
77 | # 2.4
|
---|
78 | #
|
---|
79 |
|
---|
80 | CFLAGS := -DVBOX_LINUX_2_4 $(INCL) $(KFLAGS) $(KDEBUG)
|
---|
81 | MODULE_EXT := o
|
---|
82 |
|
---|
83 | # 2.4 Module linking
|
---|
84 | $(MODULE).o: $(OBJS)
|
---|
85 | $(LD) -o $@ -r $(OBJS)
|
---|
86 |
|
---|
87 | .PHONY: $(MODULE)
|
---|
88 | all: $(MODULE)
|
---|
89 | $(MODULE): $(MODULE).o
|
---|
90 |
|
---|
91 | else
|
---|
92 | #
|
---|
93 | # 2.6 and later
|
---|
94 | #
|
---|
95 |
|
---|
96 | MODULE_EXT := ko
|
---|
97 |
|
---|
98 | $(MODULE)-y := $(OBJS)
|
---|
99 |
|
---|
100 | # build defs
|
---|
101 | EXTRA_CFLAGS += $(INCL) $(KFLAGS) $(KDEBUG)
|
---|
102 |
|
---|
103 | all: $(MODULE)
|
---|
104 |
|
---|
105 | obj-m += $(MODULE).o
|
---|
106 |
|
---|
107 | $(MODULE):
|
---|
108 | $(MAKE) KBUILD_VERBOSE=1 -C $(KERN_DIR) SUBDIRS=$(CURDIR) SRCROOT=$(CURDIR) modules
|
---|
109 |
|
---|
110 | endif
|
---|
111 |
|
---|
112 | endif # eq($(MAKECMDGOALS),clean)
|
---|
113 |
|
---|
114 | clean:
|
---|
115 | for f in . linux r0drv r0drv/linux; do rm -f $$f/*.o $$f/.*.cmd $$f/.*.flags; done
|
---|
116 | rm -rf .vboxdrv* .tmp_ver* vboxdrv.* Module.symvers Modules.symvers
|
---|