1c1d0c72aSopenharmony_ci# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
2c1d0c72aSopenharmony_ci#
3c1d0c72aSopenharmony_ci# Redistribution and use in source and binary forms, with or without modification,
4c1d0c72aSopenharmony_ci# are permitted provided that the following conditions are met:
5c1d0c72aSopenharmony_ci#
6c1d0c72aSopenharmony_ci# 1. Redistributions of source code must retain the above copyright notice, this list of
7c1d0c72aSopenharmony_ci#    conditions and the following disclaimer.
8c1d0c72aSopenharmony_ci#
9c1d0c72aSopenharmony_ci# 2. Redistributions in binary form must reproduce the above copyright notice, this list
10c1d0c72aSopenharmony_ci#    of conditions and the following disclaimer in the documentation and/or other materials
11c1d0c72aSopenharmony_ci#    provided with the distribution.
12c1d0c72aSopenharmony_ci#
13c1d0c72aSopenharmony_ci# 3. Neither the name of the copyright holder nor the names of its contributors may be used
14c1d0c72aSopenharmony_ci#    to endorse or promote products derived from this software without specific prior written
15c1d0c72aSopenharmony_ci#    permission.
16c1d0c72aSopenharmony_ci#
17c1d0c72aSopenharmony_ci# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18c1d0c72aSopenharmony_ci# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
19c1d0c72aSopenharmony_ci# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20c1d0c72aSopenharmony_ci# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
21c1d0c72aSopenharmony_ci# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22c1d0c72aSopenharmony_ci# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23c1d0c72aSopenharmony_ci# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
24c1d0c72aSopenharmony_ci# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25c1d0c72aSopenharmony_ci# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
26c1d0c72aSopenharmony_ci# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
27c1d0c72aSopenharmony_ci# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28c1d0c72aSopenharmony_ci
29c1d0c72aSopenharmony_ciimport("//drivers/hdf_core/framework/tools/hc-gen/hc_gen.gni")
30c1d0c72aSopenharmony_ciimport("//kernel/liteos_a/liteos.gni")
31c1d0c72aSopenharmony_ci
32c1d0c72aSopenharmony_ciHDF_FRAMEWORKS_PATH = "//drivers/hdf_core/framework"
33c1d0c72aSopenharmony_ciHDF_PERIPHERAL_PATH = "//drivers/peripheral"
34c1d0c72aSopenharmony_ciHDF_ADAPTERS_PATH = "//drivers/hdf_core/adapter"
35c1d0c72aSopenharmony_ci
36c1d0c72aSopenharmony_citemplate("hdf_driver") {
37c1d0c72aSopenharmony_ci  if (defined(invoker.module_switch)) {
38c1d0c72aSopenharmony_ci    forward_variables_from(invoker, [ "module_switch" ])
39c1d0c72aSopenharmony_ci  } else {
40c1d0c72aSopenharmony_ci    module_switch = true
41c1d0c72aSopenharmony_ci  }
42c1d0c72aSopenharmony_ci
43c1d0c72aSopenharmony_ci  if (module_switch && defined(invoker.hcs_sources) &&
44c1d0c72aSopenharmony_ci      !defined(invoker.sources)) {
45c1d0c72aSopenharmony_ci    hc_gen_hex("${target_name}_hc_gen_hex") {
46c1d0c72aSopenharmony_ci      sources = invoker.hcs_sources
47c1d0c72aSopenharmony_ci    }
48c1d0c72aSopenharmony_ci  }
49c1d0c72aSopenharmony_ci  if (module_switch && defined(invoker.hcs_sources) &&
50c1d0c72aSopenharmony_ci      defined(invoker.sources) && defined(invoker.outputs)) {
51c1d0c72aSopenharmony_ci    hc_gen_macro("${target_name}_hc_gen_macro") {
52c1d0c72aSopenharmony_ci      sources = invoker.hcs_sources
53c1d0c72aSopenharmony_ci      outputs = invoker.outputs
54c1d0c72aSopenharmony_ci    }
55c1d0c72aSopenharmony_ci  }
56c1d0c72aSopenharmony_ci  kernel_module(target_name) {
57c1d0c72aSopenharmony_ci    forward_variables_from(invoker,
58c1d0c72aSopenharmony_ci                           "*",
59c1d0c72aSopenharmony_ci                           [
60c1d0c72aSopenharmony_ci                             "configs",
61c1d0c72aSopenharmony_ci                             "visibility",
62c1d0c72aSopenharmony_ci                           ])
63c1d0c72aSopenharmony_ci    if (defined(invoker.configs)) {
64c1d0c72aSopenharmony_ci      configs += invoker.configs
65c1d0c72aSopenharmony_ci    }
66c1d0c72aSopenharmony_ci    if (defined(invoker.visibility)) {
67c1d0c72aSopenharmony_ci      visibility += invoker.visibility
68c1d0c72aSopenharmony_ci    }
69c1d0c72aSopenharmony_ci    if (module_switch && defined(invoker.hcs_sources) &&
70c1d0c72aSopenharmony_ci        !defined(invoker.sources)) {
71c1d0c72aSopenharmony_ci      hc_gen = ":${target_name}_hc_gen_hex"
72c1d0c72aSopenharmony_ci      generated_sources = get_target_outputs(hc_gen)
73c1d0c72aSopenharmony_ci      sources_raw = generated_sources
74c1d0c72aSopenharmony_ci      sources = filter_exclude(sources_raw, [ "*.hcb" ])
75c1d0c72aSopenharmony_ci
76c1d0c72aSopenharmony_ci      if (defined(invoker.deps)) {
77c1d0c72aSopenharmony_ci        deps += [ hc_gen ]
78c1d0c72aSopenharmony_ci      } else {
79c1d0c72aSopenharmony_ci        deps = [ hc_gen ]
80c1d0c72aSopenharmony_ci      }
81c1d0c72aSopenharmony_ci    }
82c1d0c72aSopenharmony_ci    if (module_switch && defined(invoker.hcs_sources) &&
83c1d0c72aSopenharmony_ci        defined(invoker.sources)) {
84c1d0c72aSopenharmony_ci      hc_gen_macro = ":${target_name}_hc_gen_macro"
85c1d0c72aSopenharmony_ci      generated_include = get_path_info(get_target_outputs(hc_gen_macro), "dir")
86c1d0c72aSopenharmony_ci      if (defined(invoker.include_dirs)) {
87c1d0c72aSopenharmony_ci        include_dirs += generated_include
88c1d0c72aSopenharmony_ci      } else {
89c1d0c72aSopenharmony_ci        include_dirs = generated_include
90c1d0c72aSopenharmony_ci      }
91c1d0c72aSopenharmony_ci      if (defined(invoker.deps)) {
92c1d0c72aSopenharmony_ci        deps += [ hc_gen_macro ]
93c1d0c72aSopenharmony_ci      } else {
94c1d0c72aSopenharmony_ci        deps = [ hc_gen_macro ]
95c1d0c72aSopenharmony_ci      }
96c1d0c72aSopenharmony_ci    }
97c1d0c72aSopenharmony_ci  }
98c1d0c72aSopenharmony_ci}
99c1d0c72aSopenharmony_ci
100c1d0c72aSopenharmony_ciset_defaults("hdf_driver") {
101c1d0c72aSopenharmony_ci  configs = [ "$HDFTOPDIR:hdf_config" ]
102c1d0c72aSopenharmony_ci  visibility = [ "$HDFTOPDIR:*" ]
103c1d0c72aSopenharmony_ci}
104