1# Copyright (C) 2022 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 14import("//build/lite/config/component/lite_component.gni") 15import("//build/ohos.gni") 16import("config.gni") 17 18config("internal") { 19 include_dirs = [ "include" ] 20 include_dirs += [ syscap_codec_config_path ] 21 if (syscap_codec_config_extern_path != "") { 22 include_dirs += [ "${root_build_dir}" ] 23 cflags = [ "-DSYSCAP_DEFINE_EXTERN_ENABLE" ] 24 } 25} 26 27sources_platform_common = [ 28 "./src/syscap_tool.c", 29 "./src/create_pcid.c", 30 "./src/endian_internal.c", 31 "./src/context_tool.c", 32 "./src/common_method.c", 33] 34 35ohos_executable("syscap_tool_bin") { 36 deps = [] 37 if (syscap_codec_config_extern_path != "") { 38 deps += [ ":gen_syscap_define_custom" ] 39 inputs = [ "${root_build_dir}/syscap_define_custom.h" ] 40 } 41 output_name = "syscap_tool" 42 install_enable = true 43 include_dirs = [ "src" ] 44 configs = [ ":internal" ] 45 defines = [] 46 47 if (is_mingw) { 48 defines += [ "_POSIX_" ] 49 } 50 if (defined(ohos_lite) && ohos_kernel_type == "liteos_m") { 51 cflags = [ "-DPATH_MAX=1024" ] 52 cflags += [ "-Wno-int-conversion" ] 53 } 54 sources = [ "./src/main.c" ] 55 sources += sources_platform_common 56 57 external_deps = [ "bounds_checking_function:libsec_static" ] 58 59 if (defined(ohos_lite)) { 60 deps += [ "//build/lite/config/component/cJSON:cjson_static" ] 61 } else { 62 external_deps += [ "cJSON:cjson_static" ] 63 } 64 65 subsystem_name = "developtools" 66 part_name = "syscap_codec" 67} 68 69config("syscap_interface_public_config") { 70 include_dirs = [ "./interfaces/inner_api/" ] 71} 72 73if (defined(ohos_lite)) { 74 if (ohos_kernel_type == "liteos_m") { 75 group("syscap_interface_shared") { 76 } 77 } else { 78 shared_library("syscap_interface_shared") { 79 deps = [] 80 if (syscap_codec_config_extern_path != "") { 81 deps += [ ":gen_syscap_define_custom" ] 82 inputs = [ "${root_build_dir}/syscap_define_custom.h" ] 83 } 84 _version_script = rebase_path("libsyscap_interface_shared.versionscript") 85 if (!defined(ldflags)) { 86 ldflags = [] 87 } 88 ldflags += [ 89 "-rdynamic", 90 "-Wl,--version-script=${_version_script}", 91 ] 92 93 include_dirs = [ "src" ] 94 configs += [ ":internal" ] 95 public_configs = [ ":syscap_interface_public_config" ] 96 sources = [ 97 "./interfaces/inner_api/syscap_interface.c", 98 "./src/context_tool.c", 99 "./src/endian_internal.c", 100 "./src/syscap_tool.c", 101 "./src/common_method.c", 102 ] 103 104 deps += [ 105 "//build/lite/config/component/cJSON:cjson_static", 106 "//third_party/bounds_checking_function:libsec_static", 107 ] 108 } 109 } 110} else { 111 ohos_shared_library("syscap_interface_shared") { 112 branch_protector_ret = "pac_ret" 113 deps = [] 114 if (syscap_codec_config_extern_path != "") { 115 deps += [ ":gen_syscap_define_custom" ] 116 inputs = [ "${root_build_dir}/syscap_define_custom.h" ] 117 } 118 version_script = "libsyscap_interface_shared.versionscript" 119 include_dirs = [ "src" ] 120 configs = [ ":internal" ] 121 public_configs = [ ":syscap_interface_public_config" ] 122 sources = [ 123 "./interfaces/inner_api/syscap_interface.c", 124 "./src/context_tool.c", 125 "./src/endian_internal.c", 126 "./src/syscap_tool.c", 127 "./src/common_method.c", 128 ] 129 external_deps = [ 130 "bounds_checking_function:libsec_static", 131 "cJSON:cjson_static", 132 ] 133 134 subsystem_name = "developtools" 135 part_name = "syscap_codec" 136 } 137} 138 139group("syscap_tool_bin_linux") { 140 deps = [ ":syscap_tool_bin(//build/toolchain/linux:clang_${host_cpu})" ] 141} 142 143build_ext_component("generate_pcid") { 144 outputs = [ "$root_out_dir/pcid.sc" ] 145 deps = [ ":syscap_tool_bin_linux" ] 146 exec_path = rebase_path(root_out_dir) 147 preload_path = rebase_path(preloader_output_dir) 148 if (defined(ohos_lite)) { 149 cmd = "${exec_path}/clang_${host_cpu}/syscap_tool" 150 } else { 151 cmd = "${exec_path}/clang_${host_cpu}/developtools/syscap_codec/syscap_tool" 152 } 153 command = "chmod 777 $cmd" 154 command += 155 " && $cmd -P -e -i ${preload_path}/system/etc/SystemCapability.json" 156 if (defined(ohos_lite)) { 157 command += " && mkdir -p $exec_path/system/etc && cp $exec_path/pcid.sc $exec_path/system/etc/pcid.sc" 158 } 159} 160 161ohos_prebuilt_etc("pcid.sc") { 162 deps = [ ":generate_pcid" ] 163 source = "$root_out_dir/pcid.sc" 164 subsystem_name = "developtools" 165 part_name = "syscap_codec" 166} 167 168if (syscap_codec_config_extern_path != "") { 169 # generate syscap_define_custom.h 170 action("gen_syscap_define_custom") { 171 script = "./tools/syscap_config_merge.py" 172 args = [ 173 "--base", 174 rebase_path("include/codec_config/syscap_define.h"), 175 "--extern", 176 rebase_path(syscap_codec_config_extern_path), 177 "--output", 178 rebase_path("${root_build_dir}/syscap_define_custom.h"), 179 ] 180 inputs = [ 181 "include/codec_config/syscap_define.h", 182 syscap_codec_config_extern_path, 183 ] 184 outputs = [ "${root_build_dir}/syscap_define_custom.h" ] 185 } 186} 187 188group("pcid_sc") { 189 deps = [ ":pcid.sc" ] 190} 191 192group("syscap_codec") { 193 deps = [ 194 ":pcid_sc", 195 ":syscap_interface_shared", 196 ] 197 if (support_jsapi && is_standard_system) { 198 deps += [ "napi:systemcapability" ] 199 } 200} 201