• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright (c) 2021 Huawei Device Co., Ltd.
2#
3# HDF is dual licensed: you can use it either under the terms of
4# the GPL, or the BSD license, at your option.
5# See the LICENSE file in the root of this repository for complete details.
6
7template("hc_gen") {
8  assert(defined(invoker.sources), "sources are must")
9  if (defined(invoker.outputs)) {
10    foreach(o, invoker.outputs) {
11      if (o == string_replace(o, "{{", "")) {
12        specified_output_name = true
13      }
14    }
15  }
16  if (defined(specified_output_name) && specified_output_name) {
17    target_type = "action"
18  } else {
19    target_type = "action_foreach"
20  }
21  target(target_type, target_name) {
22    deps = [ "//drivers/hdf_core/framework/tools/hc-gen:build_hc_gen" ]
23    script = "/usr/bin/env"
24    if (defined(ohos_lite)) {
25      script = "//build/lite/run_shell_cmd.py"
26    }
27    sources = invoker.sources
28    if (defined(invoker.hc_gen_hex) && invoker.hc_gen_hex) {
29      hc_flags = [
30        "-b",
31        "-i",
32        "-a",
33      ]
34      output_suffix = "_hex.c"
35      output_suffix2 = ".hcb"
36    } else if (defined(invoker.hc_gen_c) && invoker.hc_gen_c) {
37      hc_flags = [ "-t" ]
38      output_suffix = ".c"
39      output_suffix2 = ".h"
40    } else if (defined(invoker.hc_gen_macro) && invoker.hc_gen_macro) {
41      hc_flags = [ "-m" ]
42      output_suffix = ".h"
43    } else if (defined(invoker.hc_gen_start_cfg) && invoker.hc_gen_start_cfg) {
44      hc_flags = [ "-s" ]
45      output_suffix = ".cfg"
46    } else {
47      hc_flags = []
48      output_suffix = ".hcb"
49    }
50
51    if (defined(invoker.outputs)) {
52      outputs = invoker.outputs
53    } else {
54      outputs = [ "$target_gen_dir/{{source_name_part}}$output_suffix" ]
55    }
56    if (defined(output_suffix2)) {
57      outputs += [ string_replace(outputs[0], output_suffix, output_suffix2) ]
58    }
59    if (target_type == "action") {
60      src = rebase_path(sources[0], root_build_dir)
61    } else {
62      src = "{{source}}"
63    }
64
65    args = [ rebase_path(
66            get_path_info("//drivers/hdf_core/framework/tools/hc-gen/",
67                          "out_dir") + "/hc-gen") ]
68    args += hc_flags
69    args += [
70      "-o",
71      rebase_path(string_replace(outputs[0], output_suffix, "")),
72      src,
73    ]
74  }
75}
76
77template("hc_gen_c") {
78  hc_gen_c = true
79  hc_gen(target_name) {
80    forward_variables_from(invoker, "*")
81  }
82}
83
84template("hc_gen_hex") {
85  hc_gen_hex = true
86  hc_gen(target_name) {
87    forward_variables_from(invoker, "*")
88  }
89}
90
91template("hc_gen_macro") {
92  hc_gen_macro = true
93  hc_gen(target_name) {
94    forward_variables_from(invoker, "*")
95  }
96}
97
98template("hc_gen_start_cfg") {
99  hc_gen_start_cfg = true
100  hc_gen(target_name) {
101    forward_variables_from(invoker, "*")
102  }
103}
104