#!/usr/bin/make -f
##########################################################
# Copyright (C) 2006 VMware, Inc. All rights reserved.
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation version 2 and no later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
# for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
#
##########################################################

INCLUDE += -I$(SRCROOT)/include

EXTRA_CFLAGS := $(CC_OPTS) $(INCLUDE)

EXTRA_CFLAGS += $(call vm_check_build, $(AUTOCONF_DIR)/cachecreate.c, -DVMW_KMEMCR_HAS_DTOR, )
EXTRA_CFLAGS += $(call vm_check_build, $(AUTOCONF_DIR)/cachector.c,   -DVMW_KMEMCR_CTOR_HAS_3_ARGS, )
EXTRA_CFLAGS += $(call vm_check_build, $(AUTOCONF_DIR)/cachector1.c,  -DVMW_KMEMCR_CTOR_HAS_2_ARGS, )

# Note: These tests are inverted.
EXTRA_CFLAGS += $(call vm_check_build, $(AUTOCONF_DIR)/getsb1.c, ,   -DVMW_GETSB_2618)
EXTRA_CFLAGS += $(call vm_check_build, $(AUTOCONF_DIR)/statfs1.c, ,  -DVMW_STATFS_2618)
EXTRA_CFLAGS += $(call vm_check_build, $(AUTOCONF_DIR)/filldir1.c, , -DVMW_FILLDIR_2618)

obj-m += $(DRIVER).o

$(DRIVER)-y := $(subst $(SRCROOT)/, , $(patsubst %.c, %.o, $(wildcard $(SRCROOT)/linux/*.c)))

#
# In open-vm-tools, need to compile the common sources from the shared directories.
#
ifdef OVT_SOURCE_DIR
VMBLOCK_PATH        := $(shell cd $(SRCROOT) && pwd)
VMBLOCK_SHARED_PATH := $(OVT_SOURCE_DIR)/modules/shared/vmblock

VMBLOCK_SHARED      := block.o
VMBLOCK_SHARED      += stubs.o

EXTRA_CFLAGS        += -I$(VMBLOCK_PATH)/linux
EXTRA_CFLAGS        += -I$(VMBLOCK_SHARED_PATH)

$(addprefix $(VMBLOCK_PATH)/,$(VMBLOCK_SHARED)): $(VMBLOCK_PATH)/%.o: $(VMBLOCK_SHARED_PATH)/%.c
	$(Q)$(rule_cc_o_c)

$(DRIVER)-y += $(VMBLOCK_SHARED)
endif

clean:
	rm -rf $(wildcard $(DRIVER).mod.c $(DRIVER).ko .tmp_versions \
	Module.symvers Modules.symvers Module.markers modules.order \
	$(foreach dir,./ linux/,$(addprefix $(dir),.*.cmd .*.o.flags *.o)))
