OPTIM = -Os

bridge_base = $(srctree)/drivers/gpu/mt8135/rgx_1.3_2756747/generated
RGX_TOP = $(srctree)/drivers/gpu/mt8135/rgx_1.3_2756747/
HAL_VARIANT ?= rogue
PVR_SYSTEM := rgx_mtk
RGX_BVNC = 1.31.2.0

ccflags-y += \
	-fno-strict-aliasing \
	-W -Wall \
	-Wno-missing-field-initializers \
	-Wdeclaration-after-statement \
	-Wno-format-zero-length \
	-Wmissing-prototypes \
	-Wstrict-prototypes \
	-Wno-unused-parameter \
	-Wno-sign-compare \
	-Wno-type-limits

ccflags-y += \
	-D__linux__ $(OPTIM) -g

ifeq ($(strip $(TARGET_BUILD_VARIANT)),user)
ccflags-y += \
    -include $(RGX_TOP)/include/config_kernel_user.h
else
ccflags-y += \
    -include $(RGX_TOP)/include/config_kernel_eng.h
endif

ifeq ($(MTK_FORCE_GPU_89M), true)
ccflags-y += -DMTK_FORCE_M
endif


pvrsrvkm-y += \
 services/server/env/linux/event.o \
 services/server/env/linux/lock.o \
 services/server/env/linux/mm.o \
 services/server/env/linux/mmap.o \
 services/server/env/linux/module.o \
 services/server/env/linux/mutex.o \
 services/server/env/linux/mutils.o \
 services/server/env/linux/devicemem_mmap_stub.o \
 services/server/env/linux/osfunc.o \
 services/server/env/linux/allocmem.o \
 services/server/env/linux/osconnection_server.o \
 services/server/env/linux/pdump.o \
 services/server/env/linux/physmem_osmem_linux.o \
 services/server/env/linux/pvr_debugfs.o \
 services/server/env/linux/pvr_bridge_k.o \
 services/server/env/linux/pvr_debug.o \
 services/server/env/linux/physmem_tdmetacode_linux.o \
 services/server/env/linux/physmem_tdsecbuf_linux.o \
 services/server/common/devicemem_heapcfg.o \
 services/shared/common/devicemem.o \
 services/shared/common/devicemem_utils.o \
 services/shared/common/hash.o \
 services/shared/common/ra.o \
 services/shared/common/sync.o \
 services/shared/common/dllist.o \
 services/server/common/devicemem_server.o \
 services/server/common/dc_server.o \
 services/server/common/handle.o \
 services/server/common/lists.o \
 services/server/common/mmu_common.o \
 services/server/common/connection_server.o \
 services/server/common/physheap.o \
 services/server/common/physmem.o \
 services/server/common/physmem_lma.o \
 services/server/common/pmr.o \
 services/server/common/power.o \
 services/server/common/process_stats.o \
 services/server/common/pvrsrv.o \
 services/server/common/scp.o \
 services/server/common/resman.o \
 services/server/common/srvcore.o \
 services/server/common/sync_server.o \
 services/server/common/tlintern.o \
 services/shared/common/tlclient.o \
 services/server/common/tlserver.o \
 services/server/common/tlstream.o \
 services/server/common/tutils.o
ifeq ($(PVR_RI_DEBUG),1)
pvrsrvkm-y += services/server/common/ri_server.o
endif


pvrsrvkm-y += services/server/common/handle_generic.o

ifeq ($(PVR_HANDLE_BACKEND),idr)
pvrsrvkm-y += services/server/env/linux/handle_idr.o
endif

ifeq ($(SUPPORT_GPUTRACE_EVENTS),1)
pvrsrvkm-y += services/server/env/linux/pvr_gputrace.o
endif

pvrsrvkm-$(CONFIG_X86) += services/server/env/linux/osfunc_x86.o
pvrsrvkm-$(CONFIG_ARM) += services/server/env/linux/osfunc_arm.o
pvrsrvkm-$(CONFIG_METAG) += services/server/env/linux/osfunc_metag.o
pvrsrvkm-$(CONFIG_MIPS) += services/server/env/linux/osfunc_mips.o

pvrsrvkm-$(CONFIG_EVENT_TRACING) += services/server/env/linux/trace_events.o

ifeq ($(PDUMP),1)
pvrsrvkm-y += \
 services/server/common/pdump_common.o \
 services/server/common/pdump_mmu.o \
 services/server/common/pdump_physmem.o \
 services/shared/common/devicemem_pdump.o
endif

pvrsrvkm-y += \
 services/server/devices/rgx/rgxinit.o \
 services/server/devices/rgx/rgxdebug.o \
 services/server/devices/rgx/rgxhwperf.o \
 services/server/devices/rgx/rgxmem.o \
 services/server/devices/rgx/rgxta3d.o \
 services/server/devices/rgx/rgxcompute.o \
 services/server/devices/rgx/rgxccb.o \
 services/server/devices/rgx/rgxmmuinit.o \
 services/server/devices/rgx/rgxpower.o \
 services/server/devices/rgx/rgxtransfer.o \
 services/server/devices/rgx/rgxutils.o \
 services/server/devices/rgx/rgxfwutils.o \
 services/server/devices/rgx/rgxbreakpoint.o \
 services/server/devices/rgx/debugmisc_server.o \
 services/shared/devices/rgx/rgx_compat_bvnc.o \
 services/server/devices/rgx/rgxregconfig.o

ifeq ($(SUPPORT_RAY_TRACING),1)
pvrsrvkm-y += services/server/devices/rgx/rgxray.o
endif



ifeq ($(PDUMP),1)
pvrsrvkm-y += services/server/devices/rgx/rgxpdump.o
endif

# Bridge headers and source files
ccflags-y += \
 -I$(bridge_base)/dmm_bridge \
 -I$(bridge_base)/mm_bridge \
 -I$(bridge_base)/cmm_bridge \
 -I$(bridge_base)/pdumpmm_bridge \
 -I$(bridge_base)/pdumpcmm_bridge \
 -I$(bridge_base)/pdump_bridge \
 -I$(bridge_base)/rgxtq_bridge \
 -I$(bridge_base)/rgxinit_bridge \
 -I$(bridge_base)/rgxta3d_bridge \
 -I$(bridge_base)/rgxcmp_bridge \
 -I$(bridge_base)/srvcore_bridge \
 -I$(bridge_base)/dsync_bridge \
 -I$(bridge_base)/sync_bridge \
 -I$(bridge_base)/breakpoint_bridge \
 -I$(bridge_base)/debugmisc_bridge \
 -I$(bridge_base)/rgxpdump_bridge \
 -I$(bridge_base)/pvrtl_bridge \
 -I$(bridge_base)/dpvrtl_bridge \
 -I$(bridge_base)/rgxhwperf_bridge \
 -I$(bridge_base)/regconfig_bridge

ifeq ($(PVR_RI_DEBUG),1)
ccflags-y += \
 -I$(bridge_base)/ri_bridge \
 -I$(bridge_base)/dri_bridge
endif


ifeq ($(SUPPORT_RAY_TRACING),1)
ccflags-y += -I$(bridge_base)/rgxray_bridge
endif

# Compatibility BVNC
ccflags-y += \
 -I$(RGX_TOP)/services/shared/devices/rgx

# Errata files
ccflags-y += \
 -I$(RGX_TOP)/hwdefs \
 -I$(RGX_TOP)/hwdefs/km \
 -I$(RGX_TOP)/hwdefs/km/cores



ccflags-y += \
 -I$(bridge_base)/dc_bridge


ccflags-y += -I$(bridge_base)/cachegeneric_bridge



ccflags-y += \
 -I$(bridge_base)/syncsexport_bridge \
 -I$(bridge_base)/smm_bridge

ccflags-y += \
 -I$(bridge_base)/syncexport_bridge


ifeq ($(SUPPORT_PMMIF),1)
ccflags-y += -I$(bridge_base)/pmmif_bridge
endif

ccflags-y += \
 -I$(RGX_TOP)/include \
 -I$(RGX_TOP)/services/include \
 -I$(RGX_TOP)/services/server/devices/rgx \
 -I$(RGX_TOP)/services/server/env/linux \
 -I$(RGX_TOP)/services/server/include \
 -I$(RGX_TOP)/services/shared/include \
 -I$(RGX_TOP)/services/system/include \
 -I$(RGX_TOP)/services/include/shared \
 -I$(RGX_TOP)/services/system/rgx_mtk \
 -I$(RGX_TOP)/services/server/common \
 -I$(RGX_TOP)/services/include/env/linux

ccflags-y += -I$(bridge_base)/ion_bridge



pvrsrvkm-y += \
 services/server/env/linux/pvr_sync.o


pvrsrvkm-y += \
 generated/mm_bridge/server_mm_bridge.o \
 generated/dmm_bridge/client_mm_bridge.o \
 generated/pdumpmm_bridge/server_pdumpmm_bridge.o \
 generated/dpdumpmm_bridge/client_pdumpmm_bridge.o \
 generated/cmm_bridge/server_cmm_bridge.o \
 generated/pdumpcmm_bridge/server_pdumpcmm_bridge.o \
 generated/pdump_bridge/server_pdump_bridge.o \
 generated/rgxtq_bridge/server_rgxtq_bridge.o \
 generated/rgxinit_bridge/server_rgxinit_bridge.o \
 generated/rgxta3d_bridge/server_rgxta3d_bridge.o \
 generated/rgxcmp_bridge/server_rgxcmp_bridge.o \
 generated/srvcore_bridge/server_srvcore_bridge.o \
 generated/sync_bridge/server_sync_bridge.o \
 generated/dsync_bridge/client_sync_bridge.o \
 generated/breakpoint_bridge/server_breakpoint_bridge.o \
 generated/debugmisc_bridge/server_debugmisc_bridge.o \
 generated/rgxpdump_bridge/server_rgxpdump_bridge.o \
 generated/pvrtl_bridge/server_pvrtl_bridge.o \
 generated/dpvrtl_bridge/client_pvrtl_bridge.o \
 generated/rgxhwperf_bridge/server_rgxhwperf_bridge.o \
 generated/regconfig_bridge/server_regconfig_bridge.o
ifeq ($(PVR_RI_DEBUG),1)
pvrsrvkm-y += \
 generated/ri_bridge/server_ri_bridge.o \
 generated/dri_bridge/client_ri_bridge.o
endif


pvrsrvkm-y += \
 generated/dc_bridge/server_dc_bridge.o


ifeq ($(SUPPORT_RAY_TRACING),1)
pvrsrvkm-y += generated/rgxray_bridge/server_rgxray_bridge.o
endif


pvrsrvkm-y += \
 services/server/common/cache_generic.o \
 generated/cachegeneric_bridge/server_cachegeneric_bridge.o



pvrsrvkm-y += \
 services/server/env/linux/ossecure_export.o \
 generated/smm_bridge/server_smm_bridge.o \
 generated/syncsexport_bridge/server_syncsexport_bridge.o


pvrsrvkm-y += \
 generated/syncexport_bridge/server_syncexport_bridge.o

pvrsrvkm-y += services/system/$(PVR_SYSTEM)/sysconfig.o
pvrsrvkm-y += services/system/$(PVR_SYSTEM)/mtk_mfgsys.o
pvrsrvkm-y += services/system/$(PVR_SYSTEM)/mtk_mfgdvfs.o
pvrsrvkm-y += services/system/$(PVR_SYSTEM)/mtk_pp.o



ifeq ($(SUPPORT_PMMIF),1)
pvrsrvkm-y += \
 services/server/common/physmem_pmmif.o \
 generated/pmmif_bridge/server_pmmif_bridge.o
endif

pvrsrvkm-y += generated/ion_bridge/server_ion_bridge.o
pvrsrvkm-y += services/server/env/linux/physmem_ion.o

pvrsrvkm-y += services/system/common/env/linux/ion_support.o



ifeq ($(SUPPORT_DRM),1)
pvrsrvkm-y += \
 services/server/common/scp.o \
 services/server/env/linux/pvr_drm.o \
 services/server/env/linux/pvr_drm_display.o \
 services/server/env/linux/pvr_drm_gem.o \
 services/server/env/linux/pvr_drm_prime.o

ccflags-y += \
 -Iinclude/drm \
 -I$(RGX_TOP)/services/include/env/linux
endif # SUPPORT_DRM




ccflags-y += \
 -I$(RGX_TOP)/services/3rdparty/dc_fbdev

dc_fbdev-y := \
 services/3rdparty/dc_fbdev/dc_fbdev.o
 
ifeq ($(DEBUG),1)

ccflags-y += \
	-I$(RGX_TOP)/tools/intern/debug/dbgdriv/common \
	-I$(RGX_TOP)/tools/intern/debug/include

dbgdrv-y += \
	tools/intern/debug/dbgdriv/common/dbgdriv.o \
	tools/intern/debug/dbgdriv/common/ioctl.o \
	tools/intern/debug/dbgdriv/common/handle.o \
	tools/intern/debug/dbgdriv/common/hotkey.o \
	tools/intern/debug/dbgdriv/linux/main.o \
	tools/intern/debug/dbgdriv/linux/hostfunc.o

obj-$(CONFIG_PVR_RGX_MT8135) += dbgdrv.o
endif


obj-$(CONFIG_PVR_RGX_MT8135) += pvrsrvkm.o
obj-$(CONFIG_PVR_RGX_MT8135) += dc_fbdev.o



