1c1d0c72aSopenharmony_ci# Copyright (c) 2023 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/uniproton/uniproton.gni")
31c1d0c72aSopenharmony_ci
32c1d0c72aSopenharmony_ciHDF_FRAMEWORKS_PATH = "//drivers/hdf_core/framework"
33c1d0c72aSopenharmony_ciHDF_PERIPHERAL_PATH = "//drivers/peripheral"
34c1d0c72aSopenharmony_ciHDF_ADAPTER_PLATFORM_PATH =
35c1d0c72aSopenharmony_ci    "//device/soc/st/stm32f407zg/uniproton/board/hdf_platform"
36c1d0c72aSopenharmony_ci
37c1d0c72aSopenharmony_citemplate("hdf_driver") {
38c1d0c72aSopenharmony_ci  if (defined(invoker.module_switch)) {
39c1d0c72aSopenharmony_ci    forward_variables_from(invoker, [ "module_switch" ])
40c1d0c72aSopenharmony_ci  } else {
41c1d0c72aSopenharmony_ci    module_switch = true
42c1d0c72aSopenharmony_ci  }
43c1d0c72aSopenharmony_ci
44c1d0c72aSopenharmony_ci  if (defined(invoker.macro_switch)) {
45c1d0c72aSopenharmony_ci    macro_switch = invoker.macro_switch
46c1d0c72aSopenharmony_ci  } else {
47c1d0c72aSopenharmony_ci    macro_switch = false
48c1d0c72aSopenharmony_ci  }
49c1d0c72aSopenharmony_ci
50c1d0c72aSopenharmony_ci  if (!macro_switch && module_switch && defined(invoker.hcs_sources)) {
51c1d0c72aSopenharmony_ci    hc_gen_hex("${target_name}_hc_gen_hex") {
52c1d0c72aSopenharmony_ci      sources = invoker.hcs_sources
53c1d0c72aSopenharmony_ci    }
54c1d0c72aSopenharmony_ci  }
55c1d0c72aSopenharmony_ci
56c1d0c72aSopenharmony_ci  if (macro_switch && module_switch && defined(invoker.hcs_sources)) {
57c1d0c72aSopenharmony_ci    hc_gen_macro("${target_name}_hc_gen_macro") {
58c1d0c72aSopenharmony_ci      sources = invoker.hcs_sources
59c1d0c72aSopenharmony_ci      outputs = [ "$target_gen_dir/hdf_config_macro.h" ]
60c1d0c72aSopenharmony_ci    }
61c1d0c72aSopenharmony_ci  }
62c1d0c72aSopenharmony_ci
63c1d0c72aSopenharmony_ci  kernel_module(target_name) {
64c1d0c72aSopenharmony_ci    if (defined(invoker.special_visibility)) {
65c1d0c72aSopenharmony_ci      visibility += invoker.special_visibility
66c1d0c72aSopenharmony_ci    }
67c1d0c72aSopenharmony_ci
68c1d0c72aSopenharmony_ci    forward_variables_from(invoker,
69c1d0c72aSopenharmony_ci                           "*",
70c1d0c72aSopenharmony_ci                           [
71c1d0c72aSopenharmony_ci                             "configs",
72c1d0c72aSopenharmony_ci                             "visibility",
73c1d0c72aSopenharmony_ci                           ])
74c1d0c72aSopenharmony_ci    if (defined(invoker.configs)) {
75c1d0c72aSopenharmony_ci      configs += invoker.configs
76c1d0c72aSopenharmony_ci    }
77c1d0c72aSopenharmony_ci    if (defined(invoker.visibility)) {
78c1d0c72aSopenharmony_ci      visibility += invoker.visibility
79c1d0c72aSopenharmony_ci    }
80c1d0c72aSopenharmony_ci
81c1d0c72aSopenharmony_ci    if (module_switch && !macro_switch && defined(invoker.hcs_sources)) {
82c1d0c72aSopenharmony_ci      hc_gen = ":${target_name}_hc_gen_hex"
83c1d0c72aSopenharmony_ci      generated_sources = get_target_outputs(hc_gen)
84c1d0c72aSopenharmony_ci      set_sources_assignment_filter([ "*.hcb" ])
85c1d0c72aSopenharmony_ci      if (defined(invoker.sources)) {
86c1d0c72aSopenharmony_ci        sources += generated_sources
87c1d0c72aSopenharmony_ci      } else {
88c1d0c72aSopenharmony_ci        sources = generated_sources
89c1d0c72aSopenharmony_ci      }
90c1d0c72aSopenharmony_ci
91c1d0c72aSopenharmony_ci      if (defined(invoker.deps)) {
92c1d0c72aSopenharmony_ci        deps += [ hc_gen ]
93c1d0c72aSopenharmony_ci      } else {
94c1d0c72aSopenharmony_ci        deps = [ hc_gen ]
95c1d0c72aSopenharmony_ci      }
96c1d0c72aSopenharmony_ci    }
97c1d0c72aSopenharmony_ci
98c1d0c72aSopenharmony_ci    if (module_switch && macro_switch && defined(invoker.hcs_sources)) {
99c1d0c72aSopenharmony_ci      hc_gen_macro = ":${target_name}_hc_gen_macro"
100c1d0c72aSopenharmony_ci      if (defined(invoker.deps)) {
101c1d0c72aSopenharmony_ci        deps += [ hc_gen_macro ]
102c1d0c72aSopenharmony_ci      } else {
103c1d0c72aSopenharmony_ci        deps = [ hc_gen_macro ]
104c1d0c72aSopenharmony_ci      }
105c1d0c72aSopenharmony_ci    }
106c1d0c72aSopenharmony_ci  }
107c1d0c72aSopenharmony_ci}
108c1d0c72aSopenharmony_ci
109c1d0c72aSopenharmony_ciset_defaults("hdf_driver") {
110c1d0c72aSopenharmony_ci  configs = [ "$HDFTOPDIR:hdf_config" ]
111c1d0c72aSopenharmony_ci  visibility = [ "$HDFTOPDIR:*" ]
112c1d0c72aSopenharmony_ci  visibility += [ "//drivers/hdf_core/adapter/*" ]
113c1d0c72aSopenharmony_ci  visibility += [ "//drivers/hdf_core/interfaces/*" ]
114c1d0c72aSopenharmony_ci}
115