obj-y += vha/

subdir-ccflags-y += -I$(src)/include

# if building the kernel module in-tree, these config options
# should be put into a Kconfig file.
# if building out-of-tree, defining them here is as good as any.
# CONFIG_VHA:       build the VHA driver

# hardware options:
# CONFIG_VHA_DUMMY: driver runs without hardware
# CONFIG_VHA_PCI:   driver runs with generic PCI hardware
# CONFIG_VHA_EMU:   driver runs with hardware emulator
# CONFIG_VHA_APOLLO:  driver runs with IMG Apollo TCF5/TCF6 fpga hardware
# CONFIG_VHA_ORION: driver runs with IMG Orion/SFF hardware
# CONFIG_VHA_ORIONOLD: driver runs with IMG Orion/SFF hardware using old SIC
# CONFIG_VHA_ODIN: driver runs with IMG Odin TCF5/TCFVU fpga hardware
# CONFIG_VHA_DT_EXAMPLE: driver example using a device tree

# Alias for backward compatibility
#CONFIG_VHA_APOLLO := $(CONFIG_VHA_FPGA)
CONFIG_VHA_DT_EXAMPLE := y

subdir-ccflags-y += -Wall -g
# this should not be needed, but on our fpga, ubuntu kernel 4.4.0-116 does not work without it

# fail if target not specified
ifeq ($(CONFIG_VHA_PCI)$(CONFIG_VHA_EMU)$(CONFIG_VHA_APOLLO)$(CONFIG_VHA_DUMMY)$(CONFIG_VHA_ORION)$(CONFIG_VHA_ODIN)$(CONFIG_VHA_DT_EXAMPLE),)
  $(error no VHA platform specified. Try CONFIG_VHA_DUMMY=y or CONFIG_VHA_APOLLO=y or CONFIG_VHA_ODIN=y or CONFIG_VHA_ORION=y etc)KE) -C /path/to/kernel M=$(PWD)
endif

#------------------------------------
# for internal use
#------------------------------------

ifeq ($(KERNELRELEASE),)

KDIR := $(KERNEL_SRC)
PWD := $(shell pwd)

# Hardware layout
ifeq ($(CONFIG_HW_AX2)$(CONFIG_HW_AX3),)
  $(info no HW layout specified. Defaulting to Mirage: CONFIG_HW_AX2=y. To build for Aura, please specify: CONFIG_HW_AX3=y)
  export CONFIG_HW_AX2 := y
endif

ifeq ($(CONFIG_HW_AX2), y)
  $(info Building Mirage target!)
endif

ifeq ($(CONFIG_HW_AX3), y)
  # Default OS target = 0
  export CONFIG_TARGET_OSID ?= 0
  $(info Building Aura target for OS$(CONFIG_TARGET_OSID) !)
endif

# kernel warning levels: as high as possible:
# W=12 and W=123 seem to warn about linux kernel headers, so use W=1.
KWARN := W=1

ifneq (,$(shell which sparse))
# C=1: use 'sparse' for extra warnings, if it is avail.
SPARSE := C=1
endif




modules:
	make -C $(KDIR) M=$(PWD) $(SPARSE) $(KWARN) EXTRA_CFLAGS="$(EXTRA_CFLAGS)"
modules_install:
	make -C $(KDIR) M=$(PWD) $(SPARSE) $(KWARN) EXTRA_CFLAGS="$(EXTRA_CFLAGS)" modules_install
clean:
	make -C $(KDIR) M=$(PWD) clean
check:
	cd $(KDIR); scripts/checkpatch.pl -f `find $(PWD)/vha $(PWD)/include $(PWD)/img_mem -name "*\.[ch]"`

IOC := CORE_PROPS CNN_PROPS SCLR_PROPS ALLOC IMPORT FREE VHA_MAP_TO_ONCHIP VHA_MAP VHA_UNMAP BUF_STATUS
$(IOC):
	@echo '#include <stdio.h>\n#include "vha.h"\nint main() {' > /tmp/tmp.c
	@echo 'printf("%-19s= 0x%lx\\n", "VHA_IOC_$@", VHA_IOC_$@);' >> /tmp/tmp.c
	@echo "return 0;}" >> /tmp/tmp.c
	@gcc -I`pwd`/include/uapi /tmp/tmp.c
	@./a.out
	@rm -f a.out
print-ioctl-info: $(IOC)

endif # KERNELRELEASE
