10a7ce71fSopenharmony_ci# Copyright (c) 2020 Huawei Device Co., Ltd.
20a7ce71fSopenharmony_ci# Licensed under the Apache License, Version 2.0 (the "License");
30a7ce71fSopenharmony_ci# you may not use this file except in compliance with the License.
40a7ce71fSopenharmony_ci# You may obtain a copy of the License at
50a7ce71fSopenharmony_ci#
60a7ce71fSopenharmony_ci#     http://www.apache.org/licenses/LICENSE-2.0
70a7ce71fSopenharmony_ci#
80a7ce71fSopenharmony_ci# Unless required by applicable law or agreed to in writing, software
90a7ce71fSopenharmony_ci# distributed under the License is distributed on an "AS IS" BASIS,
100a7ce71fSopenharmony_ci# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
110a7ce71fSopenharmony_ci# See the License for the specific language governing permissions and
120a7ce71fSopenharmony_ci# limitations under the License.
130a7ce71fSopenharmony_ci
140a7ce71fSopenharmony_ci
150a7ce71fSopenharmony_ciifeq ($(LOCAL_HCS_ROOT),)
160a7ce71fSopenharmony_ci  LOCAL_HCS_ROOT := $(PRODUCT_PATH)
170a7ce71fSopenharmony_ciendif
180a7ce71fSopenharmony_ci
190a7ce71fSopenharmony_ciCURRENT_DIR := $(abspath $(dir $(realpath $(lastword $(MAKEFILE_LIST)))))
200a7ce71fSopenharmony_ciSOURCE_ROOT := $(abspath $(CURRENT_DIR)/../../../../)
210a7ce71fSopenharmony_ci
220a7ce71fSopenharmony_ciHC_GEN_DIR := $(abspath $(SOURCE_ROOT)/drivers/hdf_core/framework/tools/hc-gen)
230a7ce71fSopenharmony_ciifneq ($(OUT_DIR),)
240a7ce71fSopenharmony_ciHC_GEN := $(OUT_DIR)/kernel/OBJ/${KERNEL_VERSION}/drivers/hdf/khdf/hc_gen_build/hc-gen
250a7ce71fSopenharmony_cielse
260a7ce71fSopenharmony_ciHC_GEN := $(HC_GEN_DIR)/build/hc-gen
270a7ce71fSopenharmony_ciendif
280a7ce71fSopenharmony_ciLOCAL_HCS_ROOT := $(CURRENT_DIR)
290a7ce71fSopenharmony_ci
300a7ce71fSopenharmony_ciHCS_DIR := $(LOCAL_HCS_ROOT)
310a7ce71fSopenharmony_ci
320a7ce71fSopenharmony_ci$(info HCS_DIR = $(HCS_DIR))
330a7ce71fSopenharmony_ciHCB_FLAGS := -b -i -a
340a7ce71fSopenharmony_ci
350a7ce71fSopenharmony_ciHCS_OBJ := hdf_hcs_hex.o
360a7ce71fSopenharmony_ciHCS_OBJ_SRC := $(subst .o,.c,$(notdir $(HCS_OBJ)))
370a7ce71fSopenharmony_ci
380a7ce71fSopenharmony_ciCONFIG_GEN_HEX_SRC := $(addprefix $(LOCAL_HCS_ROOT)/, $(HCS_OBJ_SRC))
390a7ce71fSopenharmony_ciCONFIG_HCS_SRC := $(subst _hcs_hex.o,.hcs,$(addprefix $(HCS_DIR)/, $(HCS_OBJ)))
400a7ce71fSopenharmony_ci
410a7ce71fSopenharmony_ci$(obj)/$(HCS_OBJ): $(CONFIG_GEN_HEX_SRC)
420a7ce71fSopenharmony_ci	$(Q)$(CC) $(c_flags) -c -o $@ $<
430a7ce71fSopenharmony_ci	$(Q)rm -f $<
440a7ce71fSopenharmony_ci
450a7ce71fSopenharmony_ci$(CONFIG_GEN_HEX_SRC):  $(LOCAL_HCS_ROOT)/%_hcs_hex.c: $(HCS_DIR)/%.hcs | $(HC_GEN)
460a7ce71fSopenharmony_ci	$(Q)echo gen hdf built-in config
470a7ce71fSopenharmony_ci	$(Q)if [ ! -d $(dir $@) ]; then mkdir -p $(dir $@); fi
480a7ce71fSopenharmony_ci	$(Q)$(HC_GEN) $(HCB_FLAGS) -o $(subst _hex.c,,$(@)) $<
490a7ce71fSopenharmony_ci
500a7ce71fSopenharmony_ci$(CONFIG_GEN_SRCS): $(CONFIG_OUT_DIR)%.c: $(HCS_DIR)/%.hcs | $(HC_GEN)
510a7ce71fSopenharmony_ci	$(Q)echo gen hdf driver config
520a7ce71fSopenharmony_ci	$(Q)if [ ! -d $(dir $@) ]; then mkdir -p $(dir $@); fi
530a7ce71fSopenharmony_ci	$(Q)$(HC_GEN) -t -o $@ $<
540a7ce71fSopenharmony_ci
550a7ce71fSopenharmony_ci$(HC_GEN):
560a7ce71fSopenharmony_ci	$(HIDE)make -C $(HC_GEN_DIR) BUILD_DIR=$(dir $@)
570a7ce71fSopenharmony_ci
580a7ce71fSopenharmony_ciobj-$(CONFIG_DRIVERS_HDF) += $(HCS_OBJ)
590a7ce71fSopenharmony_ci
60