10b966c5eSopenharmony_ci#
20b966c5eSopenharmony_ci# Copyright (c) 2020-2021 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_ciifeq ($(LOCAL_HCS_ROOT),)
160b966c5eSopenharmony_ci  LOCAL_HCS_ROOT := $(PRODUCT_PATH)
170b966c5eSopenharmony_ciendif
180b966c5eSopenharmony_ciCURRENT_DIR := $(abspath $(dir $(realpath $(lastword $(MAKEFILE_LIST)))))
190b966c5eSopenharmony_ciSOURCE_ROOT := $(abspath $(CURRENT_DIR)/../../../../../)
200b966c5eSopenharmony_ci
210b966c5eSopenharmony_ciHC_GEN_DIR := $(abspath $(SOURCE_ROOT)/drivers/hdf_core/framework/tools/hc-gen)
220b966c5eSopenharmony_ciifneq ($(OUT_DIR),)
230b966c5eSopenharmony_ciHC_GEN := $(OUT_DIR)/kernel/OBJ/${KERNEL_VERSION}/drivers/hdf/khdf/hc_gen_build/hc-gen
240b966c5eSopenharmony_cielse
250b966c5eSopenharmony_ciHC_GEN := $(HC_GEN_DIR)/build/hc-gen
260b966c5eSopenharmony_ciendif
270b966c5eSopenharmony_ciLOCAL_HCS_ROOT := $(CURRENT_DIR)
280b966c5eSopenharmony_ci
290b966c5eSopenharmony_ciHCS_DIR := $(LOCAL_HCS_ROOT)
300b966c5eSopenharmony_ci
310b966c5eSopenharmony_ciifneq ($(TARGET_BOARD_PLATFORM),)
320b966c5eSopenharmony_ci  HCS_DIR := $(LOCAL_HCS_ROOT)/$(TARGET_BOARD_PLATFORM)
330b966c5eSopenharmony_cielse
340b966c5eSopenharmony_ci  ifneq ($(CONFIG_ARCH_HI3516DV300),)
350b966c5eSopenharmony_ci    HCS_DIR := $(LOCAL_HCS_ROOT)
360b966c5eSopenharmony_ci  endif
370b966c5eSopenharmony_ci  ifneq ($(CONFIG_ARCH_HI3518EV300),)
380b966c5eSopenharmony_ci    HCS_DIR := $(LOCAL_HCS_ROOT)
390b966c5eSopenharmony_ci  endif
400b966c5eSopenharmony_ciendif
410b966c5eSopenharmony_ci$(info HCS_DIR = $(HCS_DIR))
420b966c5eSopenharmony_ciHCB_FLAGS := -b -i -a
430b966c5eSopenharmony_ci
440b966c5eSopenharmony_ciHCS_OBJ := hdf_hcs_hex.o
450b966c5eSopenharmony_ciHCS_OBJ_SRC := $(subst .o,.c,$(notdir $(HCS_OBJ)))
460b966c5eSopenharmony_ci
470b966c5eSopenharmony_ciCONFIG_GEN_HEX_SRC := $(addprefix $(LOCAL_HCS_ROOT)/, $(HCS_OBJ_SRC))
480b966c5eSopenharmony_ciCONFIG_HCS_SRC := $(subst _hcs_hex.o,.hcs,$(addprefix $(HCS_DIR)/, $(HCS_OBJ)))
490b966c5eSopenharmony_ci
500b966c5eSopenharmony_ci$(obj)/$(HCS_OBJ): $(CONFIG_GEN_HEX_SRC)
510b966c5eSopenharmony_ci	$(Q)$(CC) $(c_flags) -c -o $@ $<
520b966c5eSopenharmony_ci	$(Q)rm -f $<
530b966c5eSopenharmony_ci
540b966c5eSopenharmony_ci$(CONFIG_GEN_HEX_SRC):  $(LOCAL_HCS_ROOT)/%_hcs_hex.c: $(HCS_DIR)/%.hcs | $(HC_GEN)
550b966c5eSopenharmony_ci	$(Q)echo gen hdf built-in config
560b966c5eSopenharmony_ci	$(Q)if [ ! -d $(dir $@) ]; then mkdir -p $(dir $@); fi
570b966c5eSopenharmony_ci	$(Q)$(HC_GEN) $(HCB_FLAGS) -o $(subst _hex.c,,$(@)) $<
580b966c5eSopenharmony_ci
590b966c5eSopenharmony_ci$(CONFIG_GEN_SRCS): $(CONFIG_OUT_DIR)%.c: $(HCS_DIR)/%.hcs | $(HC_GEN)
600b966c5eSopenharmony_ci	$(Q)echo gen hdf driver config
610b966c5eSopenharmony_ci	$(Q)if [ ! -d $(dir $@) ]; then mkdir -p $(dir $@); fi
620b966c5eSopenharmony_ci	$(Q)$(HC_GEN) -t -o $@ $<
630b966c5eSopenharmony_ci
640b966c5eSopenharmony_ci$(HC_GEN):
650b966c5eSopenharmony_ci	$(HIDE)make -C $(HC_GEN_DIR) BUILD_DIR=$(dir $@)
660b966c5eSopenharmony_ci
670b966c5eSopenharmony_ciobj-$(CONFIG_DRIVERS_HDF) += $(HCS_OBJ)
68