# SPDX-License-Identifier: GPL-2.0-only
# Copyright (c) 2026 MetaX Integrated Circuits (Shanghai) Co., Ltd. All rights reserved.
#
# This program is free software; you can redistribute it and/or modify it under the terms of the
# GNU General Public License, version 2, as published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
# even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License, version 2, for more details.
#
# You should have received a copy of the GNU General Public License, version 2, along with this
# program; if not, see <https://www.gnu.org/licenses/>

FULL_MX_PATH=$(src)/..

LINUXINCLUDE += -I$(FULL_MX_PATH)/kernel
LINUXINCLUDE += -I$(FULL_MX_PATH)/mxcd
LINUXINCLUDE += -I$(FULL_MX_PATH)/interface/metax

COMMON_PATH := ../common
include $(FULL_MX_PATH)/common/Makefile
metax-y += $(COMMON_FILES)

metax-y += ../mxcd/mxcd_init.o \
	../mxcd/mxcd_cdev.o \
	../mxcd/mxcd_log.o \
	../mxcd/mxcd_task_mmap.o \
	../mxcd/mxcd_peer_mem.o \
	../mxcd/mxcd_mgpu.o

metax-y += metax_atu.o \
	metax_device.o \
	metax_dma_buf.o \
	metax_driver.o \
	metax_xtt_domain.o \
	metax_hag.o \
	metax_io.o \
	metax_p2p.o \
	metax_kms.o \
	metax_log.o \
	metax_object.o \
	metax_pci.o \
	metax_trace.o \
	metax_ttm.o \
	metax_platform.o \
	metax_fw_pm.o \
	metax_vram_domain.o \
	metax_shmem_domain.o \
	metax_mxme_domain.o \
	metax_umh.o \
	metax_mon.o

metax-y += metax_pro.o
metax-y += metax_model.o metax_sgpu.o metax_native.o

metax-y += eth/mxeth_main.o \
	eth/mxeth_tools.o \
	eth/metax_eth.o

metax-y += ../kernel/kernel_inf.o
metax-y += ../kernel/kernel_trace.o

ifneq ($(MX_BUILD_MODE),gcc)
include $(FULL_MX_PATH)/metaxobj/metaxobj.mk
else
metax-y += ../metaxobj/out/metax_obj.o
METAX_OBJ_BINARY := $(FULL_MX_PATH)/metaxobj/out/metax_obj.o_binary
METAX_OBJ_BINARY_O := $(FULL_MX_PATH)/metaxobj/out/metax_obj.o
quiet_cmd_symlink = SYMLINK $@
cmd_symlink = ln -sf $(notdir $<) $@

$(METAX_OBJ_BINARY_O): $(METAX_OBJ_BINARY)
	$(call if_changed,symlink)
endif

ifneq ($(MX_DEBUG_CFLAGS),)
CFLAGS_../mxcd/mxcd_events.o += -O1 -fno-omit-frame-pointer
endif

obj-m += metax.o
