1# Copyright (c) 2020 Huawei Device Co., Ltd.
2# Licensed under the Apache License, Version 2.0 (the "License");
3# you may not use this file except in compliance with the License.
4# You may obtain a copy of the License at
5#
6#     http://www.apache.org/licenses/LICENSE-2.0
7#
8# Unless required by applicable law or agreed to in writing, software
9# distributed under the License is distributed on an "AS IS" BASIS,
10# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11# See the License for the specific language governing permissions and
12# limitations under the License.
13
14
15ifeq ($(LOCAL_HCS_ROOT),)
16  LOCAL_HCS_ROOT := $(PRODUCT_PATH)
17endif
18
19CURRENT_DIR := $(abspath $(dir $(realpath $(lastword $(MAKEFILE_LIST)))))
20SOURCE_ROOT := $(abspath $(CURRENT_DIR)/../../../../)
21
22HC_GEN_DIR := $(abspath $(SOURCE_ROOT)/drivers/hdf_core/framework/tools/hc-gen)
23ifneq ($(OUT_DIR),)
24HC_GEN := $(OUT_DIR)/kernel/OBJ/${KERNEL_VERSION}/drivers/hdf/khdf/hc_gen_build/hc-gen
25else
26HC_GEN := $(HC_GEN_DIR)/build/hc-gen
27endif
28LOCAL_HCS_ROOT := $(CURRENT_DIR)
29
30HCS_DIR := $(LOCAL_HCS_ROOT)
31
32$(info HCS_DIR = $(HCS_DIR))
33HCB_FLAGS := -b -i -a
34
35HCS_OBJ := hdf_hcs_hex.o
36HCS_OBJ_SRC := $(subst .o,.c,$(notdir $(HCS_OBJ)))
37
38CONFIG_GEN_HEX_SRC := $(addprefix $(LOCAL_HCS_ROOT)/, $(HCS_OBJ_SRC))
39CONFIG_HCS_SRC := $(subst _hcs_hex.o,.hcs,$(addprefix $(HCS_DIR)/, $(HCS_OBJ)))
40
41$(obj)/$(HCS_OBJ): $(CONFIG_GEN_HEX_SRC)
42	$(Q)$(CC) $(c_flags) -c -o $@ $<
43	$(Q)rm -f $<
44
45$(CONFIG_GEN_HEX_SRC):  $(LOCAL_HCS_ROOT)/%_hcs_hex.c: $(HCS_DIR)/%.hcs | $(HC_GEN)
46	$(Q)echo gen hdf built-in config
47	$(Q)if [ ! -d $(dir $@) ]; then mkdir -p $(dir $@); fi
48	$(Q)$(HC_GEN) $(HCB_FLAGS) -o $(subst _hex.c,,$(@)) $<
49
50$(CONFIG_GEN_SRCS): $(CONFIG_OUT_DIR)%.c: $(HCS_DIR)/%.hcs | $(HC_GEN)
51	$(Q)echo gen hdf driver config
52	$(Q)if [ ! -d $(dir $@) ]; then mkdir -p $(dir $@); fi
53	$(Q)$(HC_GEN) -t -o $@ $<
54
55$(HC_GEN):
56	$(HIDE)make -C $(HC_GEN_DIR) BUILD_DIR=$(dir $@)
57
58obj-$(CONFIG_DRIVERS_HDF) += $(HCS_OBJ)
59
60