# Copyright (C) 2007-2014  VATICS Inc.
# morgan.chang@vatics.com
#
# Template of Makefile for Linux module
#


### Path to the kernel directory
KDIR =
ifeq ("$(origin O)", "command line")
override kernelsrc := $(O)
else ifneq ($(KDIR),)
kernelsrc := $(KDIR)
else ifeq ($(KERNELSRC),)
kernelsrc := /usr/src/linux-headers-$(shell uname -r)
else
kernelsrc := $(KERNELSRC)
endif

### cross compile ?
ifneq ($(CROSS_COMPILE),)
cross_compile = CROSS_COMPILE=$(CROSS_COMPILE)
endif
ifneq ($(ARCH),)
arch = ARCH=$(ARCH)
endif

clean-files = *.i modules.order

####################### 2nd stage #######################
### included by kbuild
###
ifneq ($(KERNELRELEASE),)

### the name of module
MODULE_NAME = vpl_edmc
CFILES = edmc.c
### the objects linked into the module
$(MODULE_NAME)-objs = # reset objs! set objs from the += assignment.
$(MODULE_NAME)-objs += $(CFILES:.c=.o)
ifdef CONFIG_CPU_ARM926T
#$(MODULE_NAME)-objs += proc-arm926.o
endif
ifdef CONFIG_CPU_CACHE_V7
#$(MODULE_NAME)-objs += cache-v7.o
#AFLAGS_cache-v7.o :=-Wa,-march=armv7-a
endif

obj-y += $(MODULE_NAME).o

### customized options
override EXTRA_CFLAGS += -O2

####################### 1st stage #######################
else

.PHONY: module $(MAKECMDGOALS)

MODULE := vpl_edmc.ko
	VERSION := $(shell sed -n \
			'/VPL_EDMC_VERSION/{s/.*(\(.*\)).*/\1/;s/ //g;s/,/ /g;p}' \
			vpl_edmc.h | tr ' ' '.')
	VERSION_MODULE := vpl_edmc_v$(VERSION).ko

#$(VERSION_MODULE): $(MODULE)
#	@mv -f $(MODULE) $(VERSION_MODULE)
#	@ln -fs $(VERSION_MODULE) $(MODULE)

#$(MODULE):
#	$(MAKE) $(cross_compile) $(arch) -C $(kernelsrc) M=$(CURDIR) modules

#clean:
#	@rm -rf *.o *.ko .*.cmd *.mod.c .tmp_versions *.order *symvers


endif
#########################################################
