10a7ce71fSopenharmony_ci#
20a7ce71fSopenharmony_ci# Copyright (c) 2020-2023 Huawei Device Co., Ltd.
30a7ce71fSopenharmony_ci#
40a7ce71fSopenharmony_ci# This software is licensed under the terms of the GNU General Public
50a7ce71fSopenharmony_ci# License version 2, as published by the Free Software Foundation, and
60a7ce71fSopenharmony_ci# may be copied, distributed, and modified under those terms.
70a7ce71fSopenharmony_ci#
80a7ce71fSopenharmony_ci# This program is distributed in the hope that it will be useful,
90a7ce71fSopenharmony_ci# but WITHOUT ANY WARRANTY; without even the implied warranty of
100a7ce71fSopenharmony_ci# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
110a7ce71fSopenharmony_ci# GNU General Public License for more details.
120a7ce71fSopenharmony_ci#
130a7ce71fSopenharmony_ci#
140a7ce71fSopenharmony_ci
150a7ce71fSopenharmony_ciccflags-$(CONFIG_DRIVERS_HDF_TEST) +=  -I$(srctree)/include/hdf \
160a7ce71fSopenharmony_ci    -I$(srctree)/include/hdf/osal \
170a7ce71fSopenharmony_ci    -I$(srctree)/include/hdf/utils \
180a7ce71fSopenharmony_ci    -I$(srctree)/drivers/hdf/inner_api/osal/shared \
190a7ce71fSopenharmony_ci    -I$(srctree)/drivers/hdf/inner_api/host/shared \
200a7ce71fSopenharmony_ci    -I$(srctree)/drivers/hdf/inner_api/utils \
210a7ce71fSopenharmony_ci    -I$(srctree)/drivers/hdf/inner_api/core \
220a7ce71fSopenharmony_ci    -I$(srctree)/drivers/hdf/khdf/osal/include \
230a7ce71fSopenharmony_ci    -I$(srctree)/drivers/hdf/framework/utils/include
240a7ce71fSopenharmony_ci
250a7ce71fSopenharmony_ciifeq ($(LOCAL_HCS_ROOT),)
260a7ce71fSopenharmony_ci  LOCAL_HCS_ROOT := $(PRODUCT_PATH)
270a7ce71fSopenharmony_ciendif
280a7ce71fSopenharmony_ci
290a7ce71fSopenharmony_ciCURRENT_DIR := $(abspath $(dir $(realpath $(lastword $(MAKEFILE_LIST)))))
300a7ce71fSopenharmony_ciSOURCE_ROOT := $(abspath $(CURRENT_DIR)/../../../../../../)
310a7ce71fSopenharmony_ci
320a7ce71fSopenharmony_ciHC_GEN_DIR := $(abspath $(SOURCE_ROOT)/drivers/hdf_core/framework/tools/hc-gen)
330a7ce71fSopenharmony_ciifneq ($(OUT_DIR),)
340a7ce71fSopenharmony_ciHC_GEN := $(OUT_DIR)/kernel/OBJ/${KERNEL_VERSION}/drivers/hdf/khdf/hc_gen_build/hc-gen
350a7ce71fSopenharmony_cielse
360a7ce71fSopenharmony_ciHC_GEN := $(HC_GEN_DIR)/build/hc-gen
370a7ce71fSopenharmony_ciendif
380a7ce71fSopenharmony_ciLOCAL_HCS_ROOT := $(CURRENT_DIR)
390a7ce71fSopenharmony_ci
400a7ce71fSopenharmony_ciHCS_DIR := $(LOCAL_HCS_ROOT)
410a7ce71fSopenharmony_ci
420a7ce71fSopenharmony_ciifneq ($(TARGET_BOARD_PLATFORM),)
430a7ce71fSopenharmony_ci  HCS_DIR := $(LOCAL_HCS_ROOT)/$(TARGET_BOARD_PLATFORM)
440a7ce71fSopenharmony_cielse
450a7ce71fSopenharmony_ci  ifneq ($(CONFIG_ARCH_HI3516DV300),)
460a7ce71fSopenharmony_ci    HCS_DIR := $(LOCAL_HCS_ROOT)
470a7ce71fSopenharmony_ci  endif
480a7ce71fSopenharmony_ci  ifneq ($(CONFIG_ARCH_HI3518EV300),)
490a7ce71fSopenharmony_ci    HCS_DIR := $(LOCAL_HCS_ROOT)
500a7ce71fSopenharmony_ci  endif
510a7ce71fSopenharmony_ciendif
520a7ce71fSopenharmony_ci$(info HCS_DIR = $(HCS_DIR))
530a7ce71fSopenharmony_ciHCB_FLAGS := -b -i -a
540a7ce71fSopenharmony_ci
550a7ce71fSopenharmony_ciHCS_OBJ := hdf_hcs_hex.o
560a7ce71fSopenharmony_ciHCS_OBJ_SRC := $(subst .o,.c,$(notdir $(HCS_OBJ)))
570a7ce71fSopenharmony_ci
580a7ce71fSopenharmony_ciCONFIG_GEN_HEX_SRC := $(addprefix $(LOCAL_HCS_ROOT)/, $(HCS_OBJ_SRC))
590a7ce71fSopenharmony_ciCONFIG_HCS_SRC := $(subst _hcs_hex.o,.hcs,$(addprefix $(HCS_DIR)/, $(HCS_OBJ)))
600a7ce71fSopenharmony_ci
610a7ce71fSopenharmony_ciHDF_FRAMWORK_TEST_ROOT = $(abspath $(SOURCE_ROOT)/drivers/hdf_core/framework/test/unittest/utils/hcs_parser/unittest)
620a7ce71fSopenharmony_ciHCS_MACRO_OBJ := hcs_macro_cases.o
630a7ce71fSopenharmony_ciHCS_MACRO_SRC := $(HDF_FRAMWORK_TEST_ROOT)/hcs_macro_cases.c
640a7ce71fSopenharmony_ciHCS_DEP := $(HDF_FRAMWORK_TEST_ROOT)/hdf_macro_test.h
650a7ce71fSopenharmony_ciHCS_MACRO_GEN_FILE := $(HDF_FRAMWORK_TEST_ROOT)/hdf_macro_test
660a7ce71fSopenharmony_ciHCS_FILE := $(HCS_DIR)/hdf.hcs
670a7ce71fSopenharmony_ci
680a7ce71fSopenharmony_ci$(obj)/$(HCS_OBJ): $(CONFIG_GEN_HEX_SRC)
690a7ce71fSopenharmony_ci	$(Q)$(CC) $(c_flags) -c -o $@ $<
700a7ce71fSopenharmony_ci	$(Q)rm -f $<
710a7ce71fSopenharmony_ci
720a7ce71fSopenharmony_ci$(CONFIG_GEN_HEX_SRC):  $(LOCAL_HCS_ROOT)/%_hcs_hex.c: $(HCS_DIR)/%.hcs | $(HC_GEN)
730a7ce71fSopenharmony_ci	$(Q)echo gen hdf built-in config
740a7ce71fSopenharmony_ci	$(Q)if [ ! -d $(dir $@) ]; then mkdir -p $(dir $@); fi
750a7ce71fSopenharmony_ci	$(Q)$(HC_GEN) $(HCB_FLAGS) -o $(subst _hex.c,,$(@)) $<
760a7ce71fSopenharmony_ci
770a7ce71fSopenharmony_ci$(CONFIG_GEN_SRCS): $(CONFIG_OUT_DIR)%.c: $(HCS_DIR)/%.hcs | $(HC_GEN)
780a7ce71fSopenharmony_ci	$(Q)echo gen hdf driver config
790a7ce71fSopenharmony_ci	$(Q)if [ ! -d $(dir $@) ]; then mkdir -p $(dir $@); fi
800a7ce71fSopenharmony_ci	$(Q)$(HC_GEN) -t -o $@ $<
810a7ce71fSopenharmony_ci
820a7ce71fSopenharmony_ci$(HC_GEN):
830a7ce71fSopenharmony_ci	$(HIDE)make -C $(HC_GEN_DIR) BUILD_DIR=$(dir $@)
840a7ce71fSopenharmony_ci
850a7ce71fSopenharmony_ci$(obj)/$(HCS_MACRO_OBJ): $(HCS_MACRO_SRC) $(HCS_DEP)
860a7ce71fSopenharmony_ci	$(Q)$(CC) $(c_flags) -c -o $@ $<
870a7ce71fSopenharmony_ci
880a7ce71fSopenharmony_ci$(HCS_DEP): $(HC_GEN)
890a7ce71fSopenharmony_ci	$(Q)echo gen hdf built-in config macro
900a7ce71fSopenharmony_ci	$(Q)$(HC_GEN) -m -o $(HCS_MACRO_GEN_FILE) $(HCS_FILE)
910a7ce71fSopenharmony_ci
920a7ce71fSopenharmony_ciobj-$(CONFIG_DRIVERS_HDF) += $(HCS_OBJ) \
930a7ce71fSopenharmony_ci                             $(HCS_MACRO_OBJ)
94