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