
export CONFIG_FILE = .config
export ROOT_DIR = $(shell pwd)/..
export BUILD_DIR = $(ROOT_DIR)/build
export OUT_DIR = $(ROOT_DIR)/out
export SDK_DIR=$(ROOT_DIR)/sdk
export SDK_BOOT_DIR=$(SDK_DIR)/Boot
export SDK_COMMON_DIR=$(SDK_DIR)/Common
export SDK_DRIVER_DIR=$(SDK_DIR)/Driver
export SDK_MIDDLEWARE_DIR=$(SDK_DIR)/MiddleWare
export SDK_PQ_DIR=$(SDK_DIR)/PQlib
export SDK_PM_DIR=$(SDK_DIR)/PM
export SDK_VOS_DIR=$(SDK_DIR)/Vos
export USER_DIR=$(ROOT_DIR)/user
export USER_DDCCI_DIR=$(ROOT_DIR)/user/Comm/DDCCI
export USER_DDCCI_PRODUCT_DIR=$(ROOT_DIR)/user/$(CONFIG_VENDOR)/$(CONFIG_PROJECT)/DDCCI
export USER_OSD_DIR=$(ROOT_DIR)/user/$(CONFIG_VENDOR)/$(CONFIG_PROJECT)/OSD
export USER_DATABASE_DIR=$(ROOT_DIR)/user/$(CONFIG_VENDOR)/$(CONFIG_PROJECT)/DataBase
export USER_PINSHARE_DIR=$(ROOT_DIR)/user/$(CONFIG_VENDOR)/$(CONFIG_PROJECT)/Pinshare
export USER_LED_DIR=$(ROOT_DIR)/user/$(CONFIG_VENDOR)/$(CONFIG_PROJECT)/Led
export USER_PANEL_DIR=$(ROOT_DIR)/user/$(CONFIG_VENDOR)/$(CONFIG_PROJECT)/Panel
export USER_KEYPAD_DIR=$(ROOT_DIR)/user/$(CONFIG_VENDOR)/$(CONFIG_PROJECT)/Keypad
export USER_IR_DIR=$(ROOT_DIR)/user/$(CONFIG_VENDOR)/$(CONFIG_PROJECT)/IR
export USER_EDID_DIR=$(ROOT_DIR)/user/$(CONFIG_VENDOR)/$(CONFIG_PROJECT)/EDID
export USER_PQ_DIR=$(ROOT_DIR)/user/$(CONFIG_VENDOR)/$(CONFIG_PROJECT)/PQ
export USER_PLATFORM_DIR=$(ROOT_DIR)/user/$(CONFIG_VENDOR)/$(CONFIG_PROJECT)/Platform
export TOOLS_DIR=$(ROOT_DIR)/tools
export TOOLS_FLASH_DIR=$(ROOT_DIR)/tools/flash_tool
export TOOLS_OSD_DIR=$(ROOT_DIR)/tools/osd_tool
export TOOLS_PQ_DIR=$(ROOT_DIR)/tools/pq_tool
export SDK_PREBUILD_DIR=$(ROOT_DIR)/Prebuilds

export CONFIG_SDK_LIB = libboot.a libvos.a libdriver.a libcommon.a  libmiddleware.a
export CONFIG_USER_LIB = libosd.a libddcci.a libdatabase.a libedid.a libplatform.a
export CONFIG_SDK_PREBUILD_LIB = libddr.a libpq.a libDispCtrl.a libbcon.a libAesKey.a libHdmiCal.a libDpRxCal.a libHdcpCal.a libHdcpEngine.a libDpuDcw.a
export CONFIG_SDK_PREBUILD_NO_LIB = libzero.a
all:
MULTI_DEPEND_TARGET=
MULTI_DEPEND_TARGETD=
MULTI_TARGET_CLEAN=

ifeq ($(wildcard $(ROOT_DIR)/out/$(CONFIG_FILE)),)
  $(error ".config not exist,please exe ./project_config.sh first" )
endif
include $(ROOT_DIR)/out/$(CONFIG_FILE)
include $(BUILD_DIR)/compile/$(CONFIG_CHIP)/common.inc
include $(BUILD_DIR)/compile/$(CONFIG_CHIP)/sdk_targets.inc
include $(BUILD_DIR)/compile/$(CONFIG_CHIP)/user_targets.inc
#include $(BUILD_DIR)/compile/$(CONFIG_CHIP)/prebuilds.inc

PRE_CHECK:
	@echo "Compile Begin************************"
	@mkdir -p $(BUILD_OUT_IMG_DIR)
	@mkdir -p $(BUILD_OUT_OBJ_DIR)
	@cp $(ROOT_DIR)/user/$(CONFIG_VENDOR)/$(CONFIG_PROJECT)/Prebuilds/$(CONFIG_CHIP)_pm.bin $(BUILD_OUT_IMG_DIR)/
	@cp $(ROOT_DIR)/prebuilds/*.a $(BUILD_OUT_IMG_DIR)/


define POST_CHECK
 @echo "Compile Finish************************"
 @echo "Merge Bin*****************************"
 @dd if=$(BUILD_OUT_IMG_DIR)/$(CONFIG_CHIP)_pm.bin of=$(BUILD_OUT_IMG_DIR)/tmp_pm.bin ibs=32768 conv=sync
 @cat $(BUILD_OUT_IMG_DIR)/tmp_pm.bin $(BUILD_OUT_IMG_DIR)/Monitor_SOC.bin > $(BUILD_OUT_IMG_DIR)/Monitor_SOC_PM.bin
 @rm $(BUILD_OUT_IMG_DIR)/tmp_pm.bin
 @cp $(BUILD_OUT_IMG_DIR)/Monitor_SOC_PM.bin $(OUT_DIR)/
 @cp $(BUILD_OUT_IMG_DIR)/silicon* $(OUT_DIR)/
 @cp $(BUILD_OUT_IMG_DIR)/ddr* $(OUT_DIR)/
 @cp $(BUILD_OUT_IMG_DIR)/$(CONFIG_CHIP)_pm.bin $(OUT_DIR)/pm.bin
 @echo "Merge Bin Finish**********************"
endef

all:debug

debug:PRE_CHECK  $(MULTI_DEPEND_TARGETD)
	@$(MAKE) debug COMPILE_MODE=debug -C "$(BUILD_OUT_OBJ_DIR)" -f $(BUILD_DIR)/Makefile.mk
	$(call POST_CHECK)

release:PRE_CHECK  $(MULTI_DEPEND_TARGET)
	@$(MAKE) release COMPILE_MODE=release -C "$(BUILD_OUT_OBJ_DIR)" -f $(BUILD_DIR)/Makefile.mk
	$(call POST_CHECK)
#$(MULTI_TARGET_CLEAN)
clean:
	@rm -f $(BUILD_OUT_IMG_DIR)/*
	@rm -f $(BUILD_OUT_OBJ_DIR)/*
	@rm -rf $(OUT_DIR)/*.bin
	@rm -rf $(OUT_DIR)/compressed/*
	@rm -rf $(OUT_DIR)/ddr*
	@rm -rf $(OUT_DIR)/silicon*
#IP=172.16.204.41:3333  need input
gdb:PRE_CHECK  $(MULTI_DEPEND_TARGETD)
	@$(MAKE) gdb COMPILE_MODE=debug  -C "$(BUILD_OUT_OBJ_DIR)" -f $(BUILD_DIR)/Makefile.mk


