| 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 | # override is required by the Debian guys
|
|---|
| 22 | override MODULE = vboxvfs
|
|---|
| 23 | OBJS = \
|
|---|
| 24 | vfsmod.o \
|
|---|
| 25 | dirops.o \
|
|---|
| 26 | regops.o \
|
|---|
| 27 | utils.o \
|
|---|
| 28 | GenericRequest.o \
|
|---|
| 29 | SysHlp.o \
|
|---|
| 30 | PhysHeap.o \
|
|---|
| 31 | Init.o \
|
|---|
| 32 | VMMDev.o \
|
|---|
| 33 | HGCM.o \
|
|---|
| 34 | VBoxCalls.o \
|
|---|
| 35 | r0drv/alloc-r0drv.o \
|
|---|
| 36 | r0drv/linux/alloc-r0drv-linux.o \
|
|---|
| 37 | r0drv/linux/semevent-r0drv-linux.o \
|
|---|
| 38 | r0drv/linux/semfastmutex-r0drv-linux.o \
|
|---|
| 39 | divdi3.o \
|
|---|
| 40 | moddi3.o \
|
|---|
| 41 | udivdi3.o \
|
|---|
| 42 | umoddi3.o \
|
|---|
| 43 | qdivrem.o
|
|---|
| 44 |
|
|---|
| 45 |
|
|---|
| 46 | EXTRA_CFLAGS = -fshort-wchar
|
|---|
| 47 |
|
|---|
| 48 | ifneq ($(MAKECMDGOALS),clean)
|
|---|
| 49 |
|
|---|
| 50 | ifeq ($(KERNELRELEASE),)
|
|---|
| 51 |
|
|---|
| 52 | #
|
|---|
| 53 | # building from this directory
|
|---|
| 54 | #
|
|---|
| 55 |
|
|---|
| 56 | # kernel base directory
|
|---|
| 57 | ifndef KERN_DIR
|
|---|
| 58 | KERN_DIR := /lib/modules/$(shell uname -r)/build
|
|---|
| 59 | ifneq ($(shell if test -d $(KERN_DIR); then echo yes; fi),yes)
|
|---|
| 60 | KERN_DIR := /usr/src/linux
|
|---|
| 61 | ifneq ($(shell if test -d $(KERN_DIR); then echo yes; fi),yes)
|
|---|
| 62 | $(error Error: unable to find the sources of your current Linux kernel. \
|
|---|
| 63 | Specify KERN_DIR=<directory> and run Make again)
|
|---|
| 64 | endif
|
|---|
| 65 | $(warning Warning: using /usr/src/linux as the source directory of your \
|
|---|
| 66 | Linux kernel. If this is not correct, specify \
|
|---|
| 67 | KERN_DIR=<directory> and run Make again.)
|
|---|
| 68 | endif
|
|---|
| 69 | else
|
|---|
| 70 | ifneq ($(shell if test -d $(KERN_DIR); then echo yes; fi),yes)
|
|---|
| 71 | $(error Error: KERN_DIR does not point to a directory)
|
|---|
| 72 | endif
|
|---|
| 73 | endif
|
|---|
| 74 |
|
|---|
| 75 | # includes
|
|---|
| 76 | ifndef KERN_INCL
|
|---|
| 77 | KERN_INCL = $(KERN_DIR)/include
|
|---|
| 78 | endif
|
|---|
| 79 | ifneq ($(shell if test -d $(KERN_INCL); then echo yes; fi),yes)
|
|---|
| 80 | $(error Error: unable to find the include directory for your current Linux \
|
|---|
| 81 | kernel. Specify KERN_INCL=<directory> and run Make again)
|
|---|
| 82 | endif
|
|---|
| 83 |
|
|---|
| 84 | # module install dir.
|
|---|
| 85 | ifneq ($(filter install install_rpm,$(MAKECMDGOALS)),)
|
|---|
| 86 | ifndef MODULE_DIR
|
|---|
| 87 | MODULE_DIR_TST := /lib/modules/$(shell uname -r)
|
|---|
| 88 | ifeq ($(shell if test -d $(MODULE_DIR_TST); then echo yes; fi),yes)
|
|---|
| 89 | MODULE_DIR := $(MODULE_DIR_TST)/misc
|
|---|
| 90 | else
|
|---|
| 91 | $(error Unable to find the folder to install the shared folders driver to)
|
|---|
| 92 | endif
|
|---|
| 93 | endif # MODULE_DIR unspecified
|
|---|
| 94 | endif
|
|---|
| 95 |
|
|---|
| 96 | # guess kernel version (24 or 26)
|
|---|
| 97 | ifeq ($(shell if grep '"2\.4\.' $(KERN_INCL)/linux/version.h > /dev/null; then echo yes; fi),yes)
|
|---|
| 98 | KERN_VERSION := 24
|
|---|
| 99 | else
|
|---|
| 100 | KERN_VERSION := 26
|
|---|
| 101 | endif
|
|---|
| 102 |
|
|---|
| 103 | else # neq($(KERNELRELEASE),)
|
|---|
| 104 |
|
|---|
| 105 | #
|
|---|
| 106 | # building from kbuild (make -C <kernel_directory> M=`pwd`)
|
|---|
| 107 | #
|
|---|
| 108 |
|
|---|
| 109 | # guess kernel version (24 or 26)
|
|---|
| 110 | ifeq ($(shell if grep '"2\.4\.' $(PWD)/include/linux/version.h > /dev/null; then echo yes; fi),yes)
|
|---|
| 111 | KERN_VERSION := 24
|
|---|
| 112 | else
|
|---|
| 113 | KERN_VERSION := 26
|
|---|
| 114 | endif
|
|---|
| 115 |
|
|---|
| 116 | endif # neq($(KERNELRELEASE),)
|
|---|
| 117 |
|
|---|
| 118 | # debug - show guesses.
|
|---|
| 119 | ifdef DEBUG
|
|---|
| 120 | $(warning dbg: KERN_DIR = $(KERN_DIR))
|
|---|
| 121 | $(warning dbg: KERN_INCL = $(KERN_INCL))
|
|---|
| 122 | $(warning dbg: MODULE_DIR = $(MODULE_DIR))
|
|---|
| 123 | $(warning dbg: KERN_VERSION = $(KERN_VERSION))
|
|---|
| 124 | endif
|
|---|
| 125 |
|
|---|
| 126 |
|
|---|
| 127 | #
|
|---|
| 128 | # Compiler options
|
|---|
| 129 | #
|
|---|
| 130 | ifndef INCL
|
|---|
| 131 | INCL := $(addprefix -I,$(KERN_INCL) $(EXTRA_INCL))
|
|---|
| 132 | ifndef KBUILD_EXTMOD
|
|---|
| 133 | KBUILD_EXTMOD := $(shell pwd)
|
|---|
| 134 | endif
|
|---|
| 135 | INCL += $(addprefix -I$(KBUILD_EXTMOD),/ /include /r0drv/linux)
|
|---|
| 136 | export INCL
|
|---|
| 137 | endif
|
|---|
| 138 | KFLAGS := -D__KERNEL__ -DMODULE -DRT_OS_LINUX -DIN_RING0 -D_X86_ -DIN_RT_R0 \
|
|---|
| 139 | -DIN_SUP_R0 -DVBOX -DVBOX_HGCM -DLOG_TO_BACKDOOR -DIN_MODULE \
|
|---|
| 140 | -DIN_GUEST_R0
|
|---|
| 141 | ifeq ($(BUILD_TYPE),debug)
|
|---|
| 142 | KFLAGS += -DDEBUG
|
|---|
| 143 | endif
|
|---|
| 144 |
|
|---|
| 145 | ifeq ($(KERN_VERSION), 24)
|
|---|
| 146 | #
|
|---|
| 147 | # 2.4
|
|---|
| 148 | #
|
|---|
| 149 |
|
|---|
| 150 | CFLAGS := -O2 -DVBOX_LINUX_2_4 $(INCL) $(KFLAGS) $(KDEBUG)
|
|---|
| 151 | MODULE_EXT := o
|
|---|
| 152 |
|
|---|
| 153 | # 2.4 Module linking
|
|---|
| 154 | $(MODULE).o: $(OBJS)
|
|---|
| 155 | $(LD) -o $@ -r $(OBJS)
|
|---|
| 156 |
|
|---|
| 157 | .PHONY: $(MODULE)
|
|---|
| 158 | all: $(MODULE)
|
|---|
| 159 | $(MODULE): $(MODULE).o
|
|---|
| 160 |
|
|---|
| 161 | else
|
|---|
| 162 | #
|
|---|
| 163 | # 2.6 and later
|
|---|
| 164 | #
|
|---|
| 165 |
|
|---|
| 166 | MODULE_EXT := ko
|
|---|
| 167 |
|
|---|
| 168 | $(MODULE)-y := $(OBJS)
|
|---|
| 169 |
|
|---|
| 170 | # special hack for FC6 2.6.18 and rhel5 2.6.18
|
|---|
| 171 | ifeq ($(KERNELRELEASE),)
|
|---|
| 172 | KFLAGS += $(foreach inc,$(KERN_INCL),\
|
|---|
| 173 | $(if $(wildcard $(inc)/linux/utsrelease.h),\
|
|---|
| 174 | $(if $(shell if grep -q '"2.6.18.*fc6.*"' $(inc)/linux/utsrelease.h;\
|
|---|
| 175 | then echo yes; fi),-DKERNEL_FC6,),) \
|
|---|
| 176 | $(if $(wildcard $(inc)/linux/utsrelease.h),\
|
|---|
| 177 | $(if $(shell if grep -q '"2.6.18.*el5.*"' $(inc)/linux/utsrelease.h;\
|
|---|
| 178 | then echo yes; fi),-DKERNEL_FC6,),) \
|
|---|
| 179 | $(if $(wildcard $(inc)/linux/utsrelease.h),\
|
|---|
| 180 | $(if $(shell if grep -q '"2.6.18.*cc4.*"' $(inc)/linux/utsrelease.h;\
|
|---|
| 181 | then echo yes; fi),-DKERNEL_FC6,),))
|
|---|
| 182 | else
|
|---|
| 183 | KFLAGS += $(if $(shell if echo "$(KERNELRELEASE)"|grep -q '2.6.18.*fc6.*';\
|
|---|
| 184 | then echo yes; fi),-DKERNEL_FC6,) \
|
|---|
| 185 | $(if $(shell if echo "$(KERNELRELEASE)"|grep -q '2.6.18.*el5.*';\
|
|---|
| 186 | then echo yes; fi),-DKERNEL_FC6,) \
|
|---|
| 187 | $(if $(shell if echo "$(KERNELRELEASE)"|grep -q '2.6.18.*cc4.*';\
|
|---|
| 188 | then echo yes; fi),-DKERNEL_FC6,)
|
|---|
| 189 | endif
|
|---|
| 190 |
|
|---|
| 191 | # build defs
|
|---|
| 192 | EXTRA_CFLAGS += $(INCL) $(KFLAGS) $(KDEBUG)
|
|---|
| 193 |
|
|---|
| 194 | all: $(MODULE)
|
|---|
| 195 |
|
|---|
| 196 | obj-m += $(MODULE).o
|
|---|
| 197 |
|
|---|
| 198 | $(MODULE):
|
|---|
| 199 | $(MAKE) KBUILD_VERBOSE=1 -C $(KERN_DIR) SUBDIRS=$(CURDIR) SRCROOT=$(CURDIR) modules
|
|---|
| 200 |
|
|---|
| 201 | endif
|
|---|
| 202 |
|
|---|
| 203 | install: $(MODULE)
|
|---|
| 204 | @mkdir -p $(MODULE_DIR); \
|
|---|
| 205 | install -m 0664 -o root -g root $(MODULE).$(MODULE_EXT) $(MODULE_DIR); \
|
|---|
| 206 | PATH="$(PATH):/bin:/sbin" depmod -ae;
|
|---|
| 207 |
|
|---|
| 208 | endif # eq($(MAKECMDGOALS),clean)
|
|---|
| 209 |
|
|---|
| 210 | clean:
|
|---|
| 211 | for f in . linux r0drv r0drv/linux; do rm -f $$f/*.o $$f/.*.cmd $$f/.*.flags; done
|
|---|
| 212 | rm -rf .vboxvfs* .tmp_ver* vboxvfs.* Module.symvers Modules.symvers
|
|---|