# Makefile.in COPYRIGHT FUJITSU LIMITED 2016
KDIR ?= @KDIR@
ARCH ?= @ARCH@
src = @abs_srcdir@
KMODDIR=@KMODDIR@
BINDIR=@BINDIR@
INCLUDEDIR=@INCLUDEDIR@
IHK_BASE=$(src)/../../../../ihk

obj-m += mcctrl.o

# POSTK_DEBUG_ARCH_DEP_83, arch depend translate_rva_to_rpa() move
ccflags-y := -I$(IHK_BASE)/linux/include \
             -I$(IHK_BASE)/linux/include/ihk/arch/$(ARCH) \
             -I$(IHK_BASE)/ikc/include \
             -I$(IHK_BASE)/ikc/include/ikc/arch/$(ARCH) \
             -I$(IHK_BASE)/include \
             -I$(IHK_BASE)/include/arch/$(ARCH) \
             -I$(src)/../../include \
             -I$(src)/arch/$(ARCH)/include \
             -I@abs_builddir@ \
             -I@abs_builddir@/../../../ \
             -I$(src)/../../../kernel/include \
             -DMCEXEC_PATH=\"$(BINDIR)/mcexec\"

# depending arch
include @abs_builddir@/arch/$(ARCH)/Makefile

mcctrl-y := driver.o control.o ikc.o syscall.o procfs.o binfmt_mcexec.o
mcctrl-y += sysfs.o sysfs_files.o arch/$(ARCH)/archdeps.o

KBUILD_EXTRA_SYMBOLS = @abs_builddir@/../../../../ihk/linux/core/Module.symvers

ifeq ($(ARCH), arm64)
EXTRA_CFLAGS += $(foreach i, $(shell seq 1 100), $(addprefix -DPOSTK_DEBUG_ARCH_DEP_, $(i)))
EXTRA_CFLAGS += $(foreach i, $(shell seq 1 100), $(addprefix -DPOSTK_DEBUG_TEMP_FIX_, $(i)))
endif

.PHONY: clean install modules

modules:
	$(MAKE) -C $(KDIR) M=$(PWD) SUBDIRS=$(PWD) ARCH=$(ARCH) modules

clean:
	$(RM) .*.cmd *.mod.c *.o *.ko* Module.symvers modules.order -r .tmp*

install:
	mkdir -p -m 755 $(KMODDIR)
	install -m 644 mcctrl.ko $(KMODDIR)
	mkdir -p -m 755 $(INCLUDEDIR)/mckernel
	install -m 644 $(src)/../../include/ihklib_rusage.h $(INCLUDEDIR)/mckernel/ihklib_rusage.h
