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 22 # get all hcs file by sources 23 hcs_inputs = 24 exec_script("//drivers/hdf_core/framework/tools/hc-gen/hcs_build_info.py", 25 rebase_path(invoker.sources), 26 "list lines") 27 28 target(target_type, target_name) { 29 deps = [ "//drivers/hdf_core/framework/tools/hc-gen:build_hc_gen" ] 30 script = "/usr/bin/env" 31 if (defined(ohos_lite)) { 32 script = "//build/lite/run_shell_cmd.py" 33 } 34 inputs = hcs_inputs 35 sources = invoker.sources 36 if (defined(invoker.hc_gen_hex) && invoker.hc_gen_hex) { 37 hc_flags = [ 38 "-b", 39 "-i", 40 "-a", 41 ] 42 output_suffix = "_hex.c" 43 output_suffix2 = ".hcb" 44 } else if (defined(invoker.hc_gen_c) && invoker.hc_gen_c) { 45 hc_flags = [ "-t" ] 46 output_suffix = ".c" 47 output_suffix2 = ".h" 48 } else if (defined(invoker.hc_gen_macro) && invoker.hc_gen_macro) { 49 hc_flags = [ "-m" ] 50 output_suffix = ".h" 51 } else if (defined(invoker.hc_gen_start_cfg) && invoker.hc_gen_start_cfg) { 52 hc_flags = [ "-s" ] 53 output_suffix = ".cfg" 54 } else { 55 hc_flags = [] 56 output_suffix = ".hcb" 57 } 58 59 if (defined(invoker.outputs)) { 60 outputs = invoker.outputs 61 } else { 62 outputs = [ "$target_gen_dir/{{source_name_part}}$output_suffix" ] 63 } 64 if (defined(output_suffix2)) { 65 outputs += [ string_replace(outputs[0], output_suffix, output_suffix2) ] 66 } 67 if (target_type == "action") { 68 src = rebase_path(sources[0], root_build_dir) 69 } else { 70 src = "{{source}}" 71 } 72 73 args = [ rebase_path( 74 get_path_info("//drivers/hdf_core/framework/tools/hc-gen/", 75 "out_dir") + "/hc-gen") ] 76 args += hc_flags 77 args += [ 78 "-o", 79 rebase_path(string_replace(outputs[0], output_suffix, "")), 80 src, 81 ] 82 } 83} 84 85template("hc_gen_c") { 86 hc_gen_c = true 87 hc_gen(target_name) { 88 forward_variables_from(invoker, "*") 89 } 90} 91 92template("hc_gen_hex") { 93 hc_gen_hex = true 94 hc_gen(target_name) { 95 forward_variables_from(invoker, "*") 96 } 97} 98 99template("hc_gen_macro") { 100 hc_gen_macro = true 101 hc_gen(target_name) { 102 forward_variables_from(invoker, "*") 103 } 104} 105 106template("hc_gen_start_cfg") { 107 hc_gen_start_cfg = true 108 hc_gen(target_name) { 109 forward_variables_from(invoker, "*") 110 } 111} 112