##############################################################################
#
#    Copyright (c) 2021 by sietium.  All rights reserved.
#
#
##############################################################################

quiet_cmd_xxd = XXD     $@
      cmd_xxd = xxd -r $< $@

all: $(subst .hex,.o,$(wildcard *.hex))

%.o: %.o.hex
	$(call cmd,xxd)

GB_DIR_PATH = $(srctree)/$(src)
os=Kylin
osver=Kylinv10-5.4.18
gb_version=V2.0.1

ifeq ($(os),Kylin)
	OSVER=CONFIG_SKYLIN_OS_V10
else ifeq ($(os),uos)
	OSVER=CONFIG_UOS_20
else ifeq ($(os),loongnix)
	OSVER=CONFIG_LOONGSON_OS
else ifeq ($(os),CentOS)
	OSVER=CONFIG_CENTOS8
endif

ifeq ($(CONFIG_ARM64),y)
OBJ_DIR = aarch64
ccflags-y += -mcmodel=large -mfix-cortex-a53-843419
subdir-ccflags-y += -mcmodel=large -mfix-cortex-a53-843419
endif

ifeq ($(CONFIG_MIPS),y)
OBJ_DIR = mips
endif

ifeq ($(CONFIG_X86_64),y)
OBJ_DIR = x86_64
endif

# defines in build
DEFINE += $(OSVER)
DEFINE += OS_VERSION="$(osver)"
DEFINE += GB_VERSION=$(gb_version)
DEFINES = $(addprefix -D,$(DEFINE))

GB_OBJ_DIR := objs/$(OBJ_DIR)

ccflags-y += $(DEFINES)
subdir-ccflags-y += $(DEFINES)
subdir-ccflags-y += -Wno-implicit-fallthrough

ccflags-y += -I$(srctree)/include -I$(srctree)/include/linux -I$(srctree)/include/drm
ccflags-y += -I$(GB_DIR_PATH)/src/common -I$(GB_DIR_PATH)/src/kms -I$(GB_DIR_PATH)/src/gpu -I$(GB_DIR_PATH)/src/vpu/vpu_mm -I$(GB_DIR_PATH)/src/vpu/vpu_enc -I$(GB_DIR_PATH)/src/vpu/vpu_dec -I$(GB_DIR_PATH)/src/vpu/vpu_comm/ -I$(GB_DIR_PATH)/src -Iinclude/drm
subdir-ccflags-y += -Wno-implicit-fallthrough -I$(GB_DIR_PATH)/src/kms

#include $(GB_DIR_PATH)/src/common/Kbuild
#include $(GB_DIR_PATH)/src/kms/Kbuild
#include $(GB_DIR_PATH)/src/audio/Kbuild
#include $(GB_DIR_PATH)/src/mcu_peripherals/gpio/Kbuild
#include $(GB_DIR_PATH)/src/mcu_peripherals/pwm/Kbuild
#include $(GB_DIR_PATH)/src/mcu_peripherals/spi/Kbuild
#include $(GB_DIR_PATH)/src/mcu_peripherals/i2c/Kbuild
#include $(GB_DIR_PATH)/src/mcu_peripherals/pvt/Kbuild
#include $(GB_DIR_PATH)/src/gpu_test/Kbuild

audio-y += \
        src/audio/dwc-i2s.o \
        src/audio/i2s_platform.o \
        src/audio/gb02_fpga_v2vdma.o \
        src/audio/fifo.o \
        src/audio/gb_snd_codec.o

gb_common-y += \
	src/common/gb_procfs.o \
	src/common/gb_pcie_info.o \
	src/common/gb_gpuinfo.o \
	src/common/gb_irq.o

gpu_debug-y := \
	src/gpu_test/gb_easy_shell.o \
	src/gpu_test/gb_mem_tool.o

i2c-y += \
	src/mcu_peripherals/i2c/i2c-gb02-mcu.o \
	src/mcu_peripherals/i2c/ina2xx.o \
	src/mcu_peripherals/i2c/ads1015.o \
	src/mcu_peripherals/i2c/parade-ps8625.o

gpio-y += \
	src/mcu_peripherals/gpio/pinctrl-gb02-mcu.o

spi-y += \
	src/mcu_peripherals/spi/spi-gb02-mcu.o

pvt-y += \
	src/mcu_peripherals/pvt/gb02-pvt.o

pwm-y += \
	src/mcu_peripherals/pwm/pwm-gb02-mcu.o \
	src/mcu_peripherals/pwm/backlight/gb02-pwm-bl.o \
	src/mcu_peripherals/pwm/fan/gb02-pwm-fan.o

dc_kms-y += \
	src/kms/gbdc_hdmi_ddc.o \
	src/kms/gbdc_vga_bridge.o \
	src/kms/gbdc_backlight.o \
	src/kms/gbdc_connector.o \
	src/kms/gbdc_crtc.o \
	src/kms/gbdc_display.o \
	src/kms/gbdc_encoder.o \
	src/kms/gbdc_fbdev.o \
	src/kms/gbdc_mm.o \
	src/kms/gbdc_planes.o \
	src/kms/gb_kms.o \
	src/kms/gbdc_drv.o \
	src/kms/gbdc_irq.o

gb02-objs += $(gb_common-y)
gb02-objs += $(dc_kms-y)
gb02-objs += $(audio-y)
gb02-objs += $(gpio-y)
gb02-objs += $(pwm-y)
gb02-objs += $(spi-y)
gb02-objs += $(i2c-y)
gb02-objs += $(pvt-y)
gb02-objs += $(gpu_debug-y)
gb02-objs += $(GB_OBJ_DIR)/$(os)/gbgpu_$(osver).o

obj-$(CONFIG_GPU_SIETIUM_GENBU02) += gb02.o
