1 | #
|
---|
2 | # VirtualBox Guest Additions kernel module Makefile, common parts.
|
---|
3 | #
|
---|
4 | # (For 2.6.x, the main file must be called 'Makefile'!)
|
---|
5 | #
|
---|
6 | # Copyright (C) 2006-2015 Oracle Corporation
|
---|
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 |
|
---|
17 | # Testing:
|
---|
18 | # * Building with KERN_VER set to an installed but non-current kernel works and
|
---|
19 | # installs to the right location.
|
---|
20 | # * Building with KERN_DIR and/or MODULE_DIR set uses the value specified and
|
---|
21 | # the default value for the unspecified one if any.
|
---|
22 |
|
---|
23 | #
|
---|
24 | # These file should be included by the Makefiles for any kernel modules we
|
---|
25 | # build as part of the Guest Additions. The intended way of doing this is as
|
---|
26 | # follows:
|
---|
27 | #
|
---|
28 | # # Linux kbuild sets this to our source directory if we are called from
|
---|
29 | # # there
|
---|
30 | # obj ?= $(CURDIR)
|
---|
31 | # include $(obj)/Makefile.include.header
|
---|
32 | # MOD_NAME = <name of the module to be built, without extension>
|
---|
33 | # MOD_OBJS = <list of object files which should be included>
|
---|
34 | # MOD_DEFS = <any additional defines which this module needs>
|
---|
35 | # MOD_INCL = <any additional include paths which this module needs>
|
---|
36 | # MOD_CFLAGS = <any additional CFLAGS which this module needs>
|
---|
37 | # MOD_CLEAN = <list of directories that the clean target should look at>
|
---|
38 | # include $(obj)/Makefile.include.footer
|
---|
39 | #
|
---|
40 | # The kmk kBuild define KBUILD_TARGET_ARCH is available.
|
---|
41 | #
|
---|
42 |
|
---|
43 |
|
---|
44 | #
|
---|
45 | # First, figure out which architecture we're targeting and the build type.
|
---|
46 | # (We have to support basic cross building (ARCH=i386|x86_64).)
|
---|
47 | # While at it, warn about BUILD_* vars found to help with user problems.
|
---|
48 | #
|
---|
49 | ifeq ($(filter-out x86_64 amd64 AMD64,$(shell uname -m)),)
|
---|
50 | BUILD_TARGET_ARCH_DEF := amd64
|
---|
51 | else
|
---|
52 | BUILD_TARGET_ARCH_DEF := x86
|
---|
53 | endif
|
---|
54 | ifneq ($(filter-out amd64 x86,$(BUILD_TARGET_ARCH)),)
|
---|
55 | $(warning Ignoring unknown BUILD_TARGET_ARCH value '$(BUILD_TARGET_ARCH)'.)
|
---|
56 | BUILD_TARGET_ARCH :=
|
---|
57 | endif
|
---|
58 | ifeq ($(BUILD_TARGET_ARCH),)
|
---|
59 | ifeq ($(ARCH),x86_64)
|
---|
60 | BUILD_TARGET_ARCH := amd64
|
---|
61 | else
|
---|
62 | ifeq ($(ARCH),i386)
|
---|
63 | BUILD_TARGET_ARCH := x86
|
---|
64 | else
|
---|
65 | BUILD_TARGET_ARCH := $(BUILD_TARGET_ARCH_DEF)
|
---|
66 | endif
|
---|
67 | endif
|
---|
68 | else
|
---|
69 | ifneq ($(BUILD_TARGET_ARCH),$(BUILD_TARGET_ARCH_DEF))
|
---|
70 | $(warning Using BUILD_TARGET_ARCH='$(BUILD_TARGET_ARCH)' from the $(origin BUILD_TARGET_ARCH).)
|
---|
71 | endif
|
---|
72 | endif
|
---|
73 |
|
---|
74 | ifneq ($(filter-out release profile debug strict,$(BUILD_TYPE)),)
|
---|
75 | $(warning Ignoring unknown BUILD_TYPE value '$(BUILD_TYPE)'.)
|
---|
76 | BUILD_TYPE :=
|
---|
77 | endif
|
---|
78 | ifeq ($(BUILD_TYPE),)
|
---|
79 | BUILD_TYPE := release
|
---|
80 | else
|
---|
81 | ifneq ($(BUILD_TYPE),release)
|
---|
82 | $(warning Using BUILD_TYPE='$(BUILD_TYPE)' from the $(origin BUILD_TYPE).)
|
---|
83 | endif
|
---|
84 | endif
|
---|
85 | ifeq ($(USERNAME),)
|
---|
86 | USERNAME := noname
|
---|
87 | endif
|
---|
88 |
|
---|
89 | ifneq ($(MAKECMDGOALS),clean)
|
---|
90 |
|
---|
91 | ifeq ($(KERNELRELEASE),)
|
---|
92 |
|
---|
93 | #
|
---|
94 | # building from this directory
|
---|
95 | #
|
---|
96 |
|
---|
97 | # target kernel version
|
---|
98 | ifndef KERN_VER
|
---|
99 | KERN_VER := $(shell uname -r)
|
---|
100 | else
|
---|
101 | ifneq ($(shell if test -d /lib/modules/$(KERN_VER)/build; then echo yes; fi),yes)
|
---|
102 | KERN_VER := $(shell uname -r)
|
---|
103 | endif
|
---|
104 | endif
|
---|
105 |
|
---|
106 | # kernel base directory
|
---|
107 | ifndef KERN_DIR
|
---|
108 | KERN_DIR := /lib/modules/$(KERN_VER)/build
|
---|
109 | ifneq ($(shell if test -d $(KERN_DIR); then echo yes; fi),yes)
|
---|
110 | KERN_DIR := /usr/src/linux
|
---|
111 | ifneq ($(shell if test -d $(KERN_DIR); then echo yes; fi),yes)
|
---|
112 | $(error Error: unable to find the sources of your current Linux kernel. \
|
---|
113 | Specify KERN_DIR=<directory> and run Make again)
|
---|
114 | endif
|
---|
115 | $(warning Warning: using /usr/src/linux as the source directory of your \
|
---|
116 | Linux kernel. If this is not correct, specify \
|
---|
117 | KERN_DIR=<directory> and run Make again.)
|
---|
118 | endif
|
---|
119 | else
|
---|
120 | ifneq ($(shell if test -d $(KERN_DIR); then echo yes; fi),yes)
|
---|
121 | $(error Error: KERN_DIR does not point to a directory)
|
---|
122 | endif
|
---|
123 | endif
|
---|
124 |
|
---|
125 | # includes
|
---|
126 | ifndef KERN_INCL
|
---|
127 | KERN_INCL = $(KERN_DIR)/include
|
---|
128 | endif
|
---|
129 | ifneq ($(shell if test -d $(KERN_INCL); then echo yes; fi),yes)
|
---|
130 | $(error Error: unable to find the include directory for your current Linux \
|
---|
131 | kernel. Specify KERN_INCL=<directory> and run Make again)
|
---|
132 | endif
|
---|
133 |
|
---|
134 | # module install dir, only for current kernel
|
---|
135 | ifneq ($(filter install install_rpm,$(MAKECMDGOALS)),)
|
---|
136 | ifndef MODULE_DIR
|
---|
137 | MODULE_DIR_TST := /lib/modules/$(KERN_VER)
|
---|
138 | ifeq ($(shell if test -d $(MODULE_DIR_TST); then echo yes; fi),yes)
|
---|
139 | MODULE_DIR := $(MODULE_DIR_TST)/misc
|
---|
140 | else
|
---|
141 | $(error Unable to find the folder to install the module to)
|
---|
142 | endif
|
---|
143 | endif # MODULE_DIR unspecified
|
---|
144 | endif
|
---|
145 |
|
---|
146 | # guess kernel version (24 or 26)
|
---|
147 | ifeq ($(shell if grep '"2\.4\.' $(KERN_INCL)/linux/version.h > /dev/null; then echo yes; fi),yes)
|
---|
148 | KERN_VERSION := 24
|
---|
149 | else
|
---|
150 | KERN_VERSION := 26
|
---|
151 | endif
|
---|
152 |
|
---|
153 | else # neq($(KERNELRELEASE),)
|
---|
154 |
|
---|
155 | #
|
---|
156 | # building from kbuild (make -C <kernel_directory> M=`pwd`)
|
---|
157 | #
|
---|
158 |
|
---|
159 | # guess kernel version (24 or 26)
|
---|
160 | ifeq ($(shell if echo "$(VERSION).$(PATCHLEVEL)." | grep '2\.4\.' > /dev/null; then echo yes; fi),yes)
|
---|
161 | KERN_VERSION := 24
|
---|
162 | else
|
---|
163 | KERN_VERSION := 26
|
---|
164 | endif
|
---|
165 |
|
---|
166 | endif # neq($(KERNELRELEASE),)
|
---|
167 |
|
---|
168 | # debug - show guesses.
|
---|
169 | ifdef DEBUG
|
---|
170 | $(warning dbg: KERN_DIR = $(KERN_DIR))
|
---|
171 | $(warning dbg: KERN_INCL = $(KERN_INCL))
|
---|
172 | $(warning dbg: MODULE_DIR = $(MODULE_DIR))
|
---|
173 | $(warning dbg: KERN_VERSION = $(KERN_VERSION))
|
---|
174 | endif
|
---|
175 |
|
---|
176 | endif # eq($(MAKECMDGOALS),clean)
|
---|