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

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

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),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$(GB_DIR_PATH)/kms -I$(GB_DIR_PATH)/gpu/core -I$(GB_DIR_PATH) -Iinclude/drm
subdir-ccflags-y += -Wno-implicit-fallthrough -I$(GB_DIR_PATH)/kms

include $(GB_DIR_PATH)/gpu/core/Kbuild
include $(GB_DIR_PATH)/common/Kbuild
include $(GB_DIR_PATH)/kms/Kbuild

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

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

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

obj-$(CONFIG_GPU_SIETIUM_GENBU01) += gb.o
gb-objs := $(gpu_core-y)
gb-objs += $(gb_common-y)
gb-objs += $(dc_kms-y)
gb-objs += $(GB_OBJ_DIR)/$(os)/gbgpu_$(osver).o
