LOS_VFMW_DIR := $(VFMW_PATH)/vfmw_v6.2
LOS_VFMW_KEY_DIR := $(VFMW_PATH)/vfmw_key/vfmw_v6.2
LOS_DIR := $(LOS_PATH)/Huawei_LiteOS
LITEOS_TOP_DIR := $(LOS_DIR)
export $(LITEOS_TOP_DIR)
VFMW_CFLAGS :=
VFMW_SRC :=
ifeq ($(CFG_SOCT_TEE_SUPPORT), y)
VFMW_SEC_SUPPORT := y
VFMW_CFLAGS += -DVFMW_SEC_SUPPORT
endif
ifeq ($(CFG_PRODUCT_PC_SUPPORT), y)
VFMW_PC_SUPPORT := y
VFMW_CFLAGS += -DVFMW_PC_SUPPORT
endif
ifneq ($(findstring $(CFG_SOCT_CHIP_TYPE), wudangstick shaolingun),)
CHIP_VER := wudangstick
include $(LOS_VFMW_KEY_DIR)/product/wudangstick/config/vfmw_slave_mdc.mk
endif
ifneq ($(findstring $(CFG_SOCT_CHIP_TYPE), shaolinspear),)
CHIP_VER := shaolinspear
include $(LOS_VFMW_KEY_DIR)/product/shaolinspear/config/vfmw_slave_mdc.mk
endif
include $(LOS_DIR)/targets/himideer/build/config.mk
VFMW_CFLAGS += $(LITEOS_CFLAGS)
VFMW_CFLAGS += -I$(LINUX_PATH)/include/generic
VFMW_CFLAGS += -I$(VMCU_PATH)/mailbox
VFMW_CFLAGS += -I$(VMCU_PATH)/sa
VFMW_CFLAGS += -I$(LIBVA_PATH)
VFMW_OUT := $(OUT_DIR)/vfmw
VFMW_KEY_OUT := $(OUT_DIR)/vfmw_key
VFMW_LIB := $(VFMW_OUT)/libvfmw.a
MBX_OUT := $(OUT_DIR)/vmcu/mailbox
MBX_LIB := $(MBX_OUT)/libmbx.a
SA_OUT := $(OUT_DIR)/vmcu/sa
SA_LIB := $(SA_OUT)/libsa.a
LOS_OUT_DIR := $(OUT_DIR)/Huawei_LiteOS

OBJ_MKDIR = if [ ! -d $(dir $@) ]; then mkdir -p $(dir $@); fi

VFMW_OBJ := $(patsubst $(LOS_VFMW_DIR)/%.c, $(VFMW_OUT)/%.o, $(VFMW_SRC))
VFMW_LOS_BIN := los.bin

ifeq ($(CFG_SOCT_TEE_SUPPORT), y)
BIN_FILE := vmdc_tee.dat
else
BIN_FILE := vmdc_ree.dat
endif
TARGET_BIN := $(LOS_DIR)/targets/himideer/out/LiteOS_$(LITEOS_PLAT).bin

$(warning tee: $(CFG_SOCT_TEE_SUPPORT))
$(warning bin: $(BIN_FILE))
$(warning bin: $(SOCT_ROOTFS_DIR))
$(warning bin: $(OUT_DIR))
$(warning bin: $(VFMW_OUT))

all: $(VFMW_LOS_BIN)
$(VFMW_OBJ): $(VFMW_OUT)/%.o : $(LOS_VFMW_DIR)/%.c
	@$(OBJ_MKDIR)
	@$(LOS_CC) $(VFMW_CFLAGS) -c $< -o $@
$(VFMW_LIB): $(VFMW_OBJ)
	@$(AR) $(ARFLAGS) $@ $(VFMW_OBJ)
$(VFMW_LOS_BIN): $(VFMW_LIB)
	if [ ! -d $(LOS_DIR)/targets/himideer/out/lib ]; then mkdir -p $(LOS_DIR)/targets/himideer/out/lib; fi
	make -C $(VMCU_PATH)/mailbox MBX_OUT=$(MBX_OUT)
	cp -f $(MBX_LIB) $(LOS_DIR)/targets/himideer/out/lib
ifeq ($(VFMW_SEC_SUPPORT), y)
	make -C $(VMCU_PATH)/sa SA_OUT=$(SA_OUT)
	cp -f $(SA_LIB) $(LOS_DIR)/targets/himideer/out/lib
endif
	cp -f $(VFMW_LIB) $(LOS_DIR)/targets/himideer/out/lib
	make -C $(LOS_DIR)/targets/himideer LITEOS_TOP_DIR=$(LOS_DIR)

clean:
	make -C $(LOS_DIR)/targets/himideer LITEOS_TOP_DIR=$(LOS_DIR) clean
	make -C $(VMCU_PATH)/mailbox MBX_OUT=$(MBX_OUT) clean
ifeq ($(VFMW_SEC_SUPPORT), y)
	make -C $(VMCU_PATH)/sa SA_OUT=$(SA_OUT) clean
endif
	if [ -d $(VFMW_DIR)/master/client/mdc/img ]; then rm -rf $(VFMW_DIR)/master/client/mdc/img; fi
	rm -rf $(VFMW_OUT)
	rm -rf $(VFMW_KEY_OUT)
