2
##########################################################
3
# Copyright (C) 1998 VMware, Inc. All rights reserved.
5
# This program is free software; you can redistribute it and/or modify it
6
# under the terms of the GNU General Public License as published by the
7
# Free Software Foundation version 2 and no later version.
9
# This program is distributed in the hope that it will be useful, but
10
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14
# You should have received a copy of the GNU General Public License along
15
# with this program; if not, write to the Free Software Foundation, Inc.,
16
# 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
##########################################################
21
#### VMware kernel module Makefile to be distributed externally
25
#### SRCROOT _must_ be a relative path.
30
# open-vm-tools doesn't replicate shared source files for different modules;
31
# instead, files are kept in shared locations. So define a few useful macros
32
# to be able to handle both cases cleanly.
36
AUTOCONF_DIR := $(OVT_SOURCE_DIR)/modules/linux/shared/autoconf
37
VMLIB_PATH = $(OVT_SOURCE_DIR)/lib/$(1)
38
INCLUDE += -I$(OVT_SOURCE_DIR)/modules/linux/shared
39
INCLUDE += -I$(OVT_SOURCE_DIR)/lib/include
41
AUTOCONF_DIR := $(SRCROOT)/shared/autoconf
42
INCLUDE += -I$(SRCROOT)/shared
46
VM_UNAME = $(shell uname -r)
48
# Header directory for the running kernel
50
HEADER_DIR = $(LINUXINCLUDE)
52
HEADER_DIR = /lib/modules/$(VM_UNAME)/build/include
55
BUILD_DIR = $(HEADER_DIR)/..
58
PRODUCT := tools-source
63
vm_check_gcc = $(shell if $(CC) $(1) -S -o /dev/null -xc /dev/null \
64
> /dev/null 2>&1; then echo "$(1)"; else echo "$(2)"; fi)
65
vm_check_file = $(shell if test -f $(1); then echo "yes"; else echo "no"; fi)
69
ifeq ($(call vm_check_file,$(BUILD_DIR)/Makefile), yes)
70
ifneq ($(call vm_check_file,$(BUILD_DIR)/Rules.make), yes)
77
ifndef VM_KBUILD_SHOWN
78
ifeq ($(VM_KBUILD), no)
79
VM_DUMMY := $(shell echo >&2 "Using standalone build system.")
81
ifeq ($(VM_KBUILD), 24)
82
VM_DUMMY := $(shell echo >&2 "Using 2.4.x kernel build system.")
84
VM_DUMMY := $(shell echo >&2 "Using 2.6.x kernel build system.")
87
VM_KBUILD_SHOWN := yes
88
export VM_KBUILD_SHOWN
91
ifneq ($(VM_KBUILD), no)
93
VMCCVER := $(shell $(CC) -dumpversion)
95
# If there is no version defined, we are in toplevel pass, not yet in kernel makefiles...
98
ifeq ($(VM_KBUILD), 24)
99
DRIVER_KO := $(DRIVER).o
101
DRIVER_KO := $(DRIVER).ko
106
auto-build: $(DRIVER_KO)
107
cp -f $< $(SRCROOT)/../$(DRIVER).o
109
# $(DRIVER_KO) is a phony target, so compare file times explicitly
110
$(DRIVER): $(DRIVER_KO)
111
if [ $< -nt $@ ] || [ ! -e $@ ] ; then cp -f $< $@; fi
113
# Pass gcc version down the chain, so we can detect if kernel attempts to use unapproved compiler
114
VM_CCVER := $(VMCCVER)
119
MAKEOVERRIDES := $(filter-out CC=%,$(MAKEOVERRIDES))
122
# Define a setup target that gets built before the actual driver.
123
# This target may not be used at all, but if it is then it will be defined
129
$(DRIVER_KO): prebuild
130
$(MAKE) -C $(BUILD_DIR) SUBDIRS=$$PWD SRCROOT=$$PWD/$(SRCROOT) \
131
MODULEBUILDDIR=$(MODULEBUILDDIR) modules
132
$(MAKE) -C $$PWD SRCROOT=$$PWD/$(SRCROOT) \
133
MODULEBUILDDIR=$(MODULEBUILDDIR) postbuild
136
vm_check_build = $(shell if $(CC) $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) \
137
$(CPPFLAGS) $(CFLAGS) $(CFLAGS_KERNEL) $(LINUXINCLUDE) \
138
$(EXTRA_CFLAGS) -Iinclude2/asm/mach-default \
139
-DKBUILD_BASENAME=\"$(DRIVER)\" \
140
-Werror -S -o /dev/null -xc $(1) \
141
> /dev/null 2>&1; then echo "$(2)"; else echo "$(3)"; fi)
143
CC_WARNINGS := -Wall -Wstrict-prototypes
144
CC_OPTS := $(GLOBAL_DEFS) $(CC_WARNINGS) -DVMW_USING_KBUILD
146
CC_OPTS += -DVMX86_DEVEL
149
CC_OPTS += -DVMX86_DEBUG
152
include $(SRCROOT)/Makefile.kernel
155
ifeq ($(VM_KBUILD), 24)
157
O_TARGET := $(DRIVER).o
159
obj-y := $($(DRIVER)-y)
161
include $(TOPDIR)/Rules.make
167
include $(SRCROOT)/Makefile.normal