
include $(BUILD_DIR)/compile/$(CONFIG_CHIP)/common.inc
MONITOR_SOC_NAME=Monitor_SOC
VPATH = $(SDK_MIDDLEWARE_DIR)

INCLUDES = -I$(SDK_BOOT_DIR)/../Driver/Chip/$(CONFIG_CHIP)
INCLUDES += -I$(SDK_BOOT_DIR)/../Driver/Chip/$(CONFIG_CHIP)/regs
INCLUDES += -I$(SDK_VOS_DIR)/inc
INCLUDES += -I$(SDK_VOS_DIR)/risc/inc
INCLUDES += -I$(SDK_VOS_DIR)/freertos/FreeRTOS/Include
INCLUDES += -I$(SDK_VOS_DIR)/freertos/FreeRTOS/Source/include
INCLUDES += -I$(SDK_VOS_DIR)/freertos/FreeRTOS/Source/portable/GCC/RISC32


INCLUDES += -I$(SDK_COMMON_DIR)
INCLUDES += -I$(SDK_COMMON_DIR)/Util/HvQueue/inc
INCLUDES += -I$(SDK_COMMON_DIR)/Util/Utilities/inc
INCLUDES += -I$(SDK_COMMON_DIR)/Event
INCLUDES += -I$(SDK_COMMON_DIR)/Assert
INCLUDES += -I$(SDK_COMMON_DIR)/Timer/inc
INCLUDES += -I$(SDK_COMMON_DIR)/Database/inc
INCLUDES += -I$(SDK_COMMON_DIR)/Debug/LetterShell/inc

INCLUDES += -I$(SDK_DIR)
INCLUDES += -I$(SDK_DIR)/MiddleWare/ChannelManager/inc
INCLUDES += -I$(SDK_DIR)/MiddleWare/PowerManager/inc
INCLUDES += -I$(SDK_DIR)/MiddleWare/InputPortManager/inc
INCLUDES += -I$(SDK_DIR)/MiddleWare/InputPortManager/Ddcci/inc
INCLUDES += -I$(SDK_DIR)/MiddleWare/InputPortManager/DisplayPort/inc
INCLUDES += -I$(SDK_DIR)/MiddleWare/InputPortManager/HDCP/inc
INCLUDES += -I$(SDK_DIR)/MiddleWare/InputPortManager/HDMI/inc
INCLUDES += -I$(SDK_DIR)/MiddleWare/PanelManager/inc
INCLUDES += -I$(SDK_DIR)/MiddleWare/RunTime/SystemTask/inc
INCLUDES += -I$(USER_DIR)/$(CONFIG_VENDOR)/$(CONFIG_PROJECT)/System/EventHub/inc
INCLUDES += -I$(SDK_DIR)/MiddleWare/RunTime/OsdTask/inc
INCLUDES += -I$(SDK_DIR)/MiddleWare/RunTime/UrgentTask/inc
INCLUDES += -I$(SDK_DIR)/MiddleWare/RunTime/UsbTask/inc
INCLUDES += -I$(SDK_DIR)/MiddleWare/RunTime/AmbientLight/inc
INCLUDES += -I$(USER_DIR)/$(CONFIG_VENDOR)/$(CONFIG_PROJECT)/Pq

LINK_SCRIPT_DIR = $(BUILD_DIR)/scripts/ldscript/$(CONFIG_CHIP)
LINK_SCRIPT = $(LINK_SCRIPT_DIR)/$(CONFIG_CHIP).ld
LINK_SCRIPT_DB = $(LINK_SCRIPT_DIR)/$(CONFIG_CHIP)-db.ld
LIB_INCLUDE= -L$(LINK_SCRIPT_DIR) 
LIB_STATIC= $(addprefix $(BUILD_OUT_IMG_DIR)/,$(CONFIG_SDK_LIB)) $(addprefix $(BUILD_OUT_IMG_DIR)/,$(CONFIG_USER_LIB)) $(addprefix $(BUILD_OUT_IMG_DIR)/,$(CONFIG_SDK_PREBUILD_LIB)) $(addprefix $(BUILD_OUT_IMG_DIR)/,$(CONFIG_SDK_PREBUILD_NO_LIB))


OBJ_MONITOR_SOC_APP_C = $(wildcard $(SDK_MIDDLEWARE_DIR)/*.c)
OBJ_MONITOR_SOC_APP_C_NODIR = $(notdir $(OBJ_MONITOR_SOC_APP_C))
OBJ_MONITOR_SOC_APP_O = $(OBJ_MONITOR_SOC_APP_C_NODIR:%.c=%.o)

MONITOR_SOC_APP_C_NODIR_O = $(OBJ_MONITOR_SOC_APP_O)
MONITOR_SOC_APP_C_WITH_DIR_O= $(addprefix $(BUILD_OUT_OBJ_DIR)/,$(MONITOR_SOC_APP_C_NODIR_O))

MONITOR_SOC_APP = $(BUILD_OUT_IMG_DIR)/$(MONITOR_SOC_NAME).bin

debug:$(MONITOR_SOC_APP)
release:$(MONITOR_SOC_APP)

gdb:$(MONITOR_SOC_APP)
	$(HEADER)$(GDB) $(BUILD_OUT_IMG_DIR)/$(MONITOR_SOC_NAME).elf -x "$(BUILD_DIR)/scripts/risc.gdbinit" -ex target\ remote\ $(IP) -ex set\ endian\ little -ex mon\ halt


define PRINT_SECTION_INFO
 $(HEADER)$(OBJDUMP) -hww $1
endef 

$(MONITOR_SOC_APP):$(MONITOR_SOC_APP_C_NODIR_O) $(LIB_STATIC)
	$(HEADER)$(CC) $(LIB_INCLUDE) -T$(LINK_SCRIPT) $(LD_FLAG) $(MONITOR_SOC_APP_C_WITH_DIR_O)  -o $(BUILD_OUT_IMG_DIR)/$(MONITOR_SOC_NAME).elf -Wl,-Map=$(BUILD_OUT_IMG_DIR)/$(MONITOR_SOC_NAME).map -Wl,-start-group $(LIB_STATIC) -lc -lm -lgcc -Wl,-end-group
	$(HEADER)$(OBJCOPY) -O binary $(BUILD_OUT_IMG_DIR)/$(MONITOR_SOC_NAME).elf $@
	$(HEADER)$(OBJCOPY) -O binary $(BUILD_OUT_IMG_DIR)/$(MONITOR_SOC_NAME).elf --only-section=.boot_text --only-section=.boot_rodata --only-section=.boot_data --only-section=.boot_vector $(BUILD_OUT_IMG_DIR)/ram-$(MONITOR_SOC_NAME).bin
	$(HEADER)$(OBJCOPY) -O binary $(BUILD_OUT_IMG_DIR)/$(MONITOR_SOC_NAME).elf --only-section=.text  --only-section=.rodata --only-section=.data $(BUILD_OUT_IMG_DIR)/ddr-$(MONITOR_SOC_NAME).bin
	$(HEADER)$(OBJCOPY) -O binary $(BUILD_OUT_IMG_DIR)/$(MONITOR_SOC_NAME).elf --only-section=.boot_rom_text --only-section=.boot_text --only-section=.boot_rodata --only-section=.boot_data --only-section=.boot_vector $(BUILD_OUT_IMG_DIR)/silicon_boot.bin
#	$(HEADER)$(OBJDUMP) -D -S $(BUILD_OUT_IMG_DIR)/$(MONITOR_SOC_NAME).elf > $(BUILD_OUT_IMG_DIR)/$(MONITOR_SOC_NAME).S
	$(call PRINT_SECTION_INFO,$(BUILD_OUT_IMG_DIR)/$(MONITOR_SOC_NAME).elf)
	$(HEADER)$(CC) $(LIB_INCLUDE) -T$(LINK_SCRIPT_DB) $(LD_FLAG) $(MONITOR_SOC_APP_C_WITH_DIR_O)  -o $(BUILD_OUT_IMG_DIR)/$(MONITOR_SOC_NAME).elf-DB -Wl,-Map=$(BUILD_OUT_IMG_DIR)/$(MONITOR_SOC_NAME).map-DB -Wl,-start-group $(LIB_STATIC) -lc -lm -lgcc -Wl,-end-group
	$(HEADER)$(OBJCOPY) -O binary $(BUILD_OUT_IMG_DIR)/$(MONITOR_SOC_NAME).elf-DB $@-DB
	$(HEADER)$(OBJCOPY) -O binary $(BUILD_OUT_IMG_DIR)/$(MONITOR_SOC_NAME).elf-DB --only-section=.boot_text --only-section=.boot_rodata --only-section=.boot_data --only-section=.boot_vector $(BUILD_OUT_IMG_DIR)/ram-$(MONITOR_SOC_NAME).bin-DB
	$(HEADER)$(OBJCOPY) -O binary $(BUILD_OUT_IMG_DIR)/$(MONITOR_SOC_NAME).elf-DB --only-section=.text  --only-section=.rodata --only-section=.data $(BUILD_OUT_IMG_DIR)/ddr-$(MONITOR_SOC_NAME).bin-DB
	$(HEADER)$(OBJCOPY) -O binary $(BUILD_OUT_IMG_DIR)/$(MONITOR_SOC_NAME).elf-DB --only-section=.boot_rom_text --only-section=.boot_text --only-section=.boot_rodata --only-section=.boot_data --only-section=.boot_vector $(BUILD_OUT_IMG_DIR)/silicon_boot.bin-DB
#	$(HEADER)$(OBJDUMP) -D -S $(BUILD_OUT_IMG_DIR)/$(MONITOR_SOC_NAME).elf-DB > $(BUILD_OUT_IMG_DIR)/$(MONITOR_SOC_NAME)-DB.S
	$(call PRINT_SECTION_INFO,$(BUILD_OUT_IMG_DIR)/$(MONITOR_SOC_NAME).elf-DB)


