1# Copyright (c) 2021-2024 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("../../core/common/dfx/dsoftbus_dfx.gni")
15import("../../dsoftbus.gni")
16import("../common/dfx/dsoftbus_dfx.gni")
17import("../connection/common/conn_common.gni")
18import("../transmission/common/trans_common.gni")
19
20dsoftbus_root_path = "../.."
21softbus_adapter_common = "${dsoftbus_root_path}/adapter/common"
22
23common_utils_src = [
24  "bitmap/softbus_bitmap.c",
25  "network/softbus_network_utils.c",
26  "json_utils/softbus_json_utils.c",
27  "message_handler/message_handler.c",
28  "queue/softbus_queue.c",
29  "security/sequence_verification/softbus_sequence_verification.c",
30  "softbus_property/softbus_feature_config.c",
31  "utils/softbus_utils.c",
32  "dfx/hisysevent_adapter/softbus_hisysevt_bus_center.c",
33  "dfx/hisysevent_adapter/softbus_hisysevt_common.c",
34  "dfx/hisysevent_adapter/softbus_hisysevt_connreporter.c",
35  "dfx/hisysevent_adapter/softbus_hisysevt_discreporter.c",
36  "dfx/hisysevent_adapter/softbus_hisysevt_transreporter.c",
37]
38external_deps = []
39
40if (defined(ohos_lite)) {
41  if (ohos_kernel_type == "liteos_m") {
42    diff_deps = [
43      "$hilog_lite_deps_path",
44      "//build/lite/config/component/cJSON:cjson_static",
45    ]
46    diff_external_deps = [ "bounds_checking_function:libsec_static" ]
47    build_type = "static_library"
48  } else {
49    diff_deps = [
50      "$hilog_lite_deps_path",
51      "//build/lite/config/component/cJSON:cjson_shared",
52    ]
53    diff_external_deps = [ "bounds_checking_function:libsec_shared" ]
54    build_type = "shared_library"
55  }
56  config("dsoftbus_utils_interface") {
57    include_dirs = [
58      "$dsoftbus_root_path/core/common/include",
59      "$dsoftbus_root_path/interfaces/kits/common",
60      "$dsoftbus_root_path/core/common/dfx/hidumper_adapter/include",
61      "$dsoftbus_root_path/core/common/dfx/hisysevent_adapter/include",
62      "$dsoftbus_root_path/core/common/dfx/interface/include",
63      "$softbus_adapter_common/include",
64      "$hilog_lite_include_path",
65      "$utils_lite_include_path",
66    ]
67    include_dirs += conn_common_inc + trans_common_inc
68    if (board_toolchain_type != "iccarm") {
69      cflags = [
70        "-ffunction-sections",
71        "-fdata-sections",
72        "-Os",
73      ]
74    } else {
75      cflags = [
76        "--diag_suppress",
77        "Pe186",
78      ]
79    }
80    cflags_cc = cflags
81  }
82
83  target(build_type, "softbus_utils") {
84    include_dirs = [
85      "$dsoftbus_root_path/interfaces/kits/common",
86      "$dsoftbus_root_path/components/nstackx/nstackx_core/dfile/interface",
87    ]
88    include_dirs += conn_common_inc + trans_common_inc
89    dfx_src = [ "dfx/hisysevent_adapter/softbus_hisysevt_nstack_virtual.c" ]
90    sources = common_utils_src
91    sources += conn_common_src + trans_common_src + dfx_src
92    if (board_toolchain_type != "iccarm") {
93      cflags = [
94        "-Wall",
95        "-fPIC",
96        "-std=c99",
97      ]
98    }
99    if (ohos_kernel_type == "liteos_m") {
100      defines += [ "SOFTBUS_LITEOS_M" ]
101      defines += [ "__STDC_FORMAT_MACROS" ]
102    } else {
103      defines += [ "DEFAULT_STORAGE_PATH=\"/storage/data\"" ]
104      defines += [ "__STDC_FORMAT_MACROS" ]
105      defines += [ "SOFTBUS_LITEOS_A" ]
106    }
107    deps = [
108      "$dsoftbus_dfx_path/anonymize:softbus_dfx_anonymizer",
109      "$dsoftbus_dfx_path/event:softbus_dfx_event",
110      "$dsoftbus_dfx_path/log:softbus_dfx_log",
111      "$dsoftbus_root_path/adapter:softbus_adapter",
112    ]
113    deps += diff_deps
114    external_deps += diff_external_deps
115    public_configs = [ ":dsoftbus_utils_interface" ]
116  }
117} else {
118  dstream_native_source_path = rebase_path("$dsoftbus_root_path")
119  dstream_dep_file = "components/nstackx_enhanced/fillp/BUILD.gn"
120  enhanced = exec_script("$dsoftbus_root_path/check_sub_module.py",
121                         [
122                           "$dstream_native_source_path",
123                           "$dstream_dep_file",
124                         ],
125                         "value")
126
127  cflags = [ "-DFILLP_LINUX" ]
128  config("dsoftbus_utils_interface_L2") {
129    include_dirs = [
130      "$dsoftbus_root_path/core/common/include",
131      "$dsoftbus_root_path/core/common/dfx/hidumper_adapter/include",
132      "$dsoftbus_root_path/core/common/dfx/hisysevent_adapter/include",
133      "$dsoftbus_root_path/core/common/dfx/interface/include",
134      "$dsoftbus_root_path/interfaces/kits/common",
135      "$softbus_adapter_common/include",
136      "$dsoftbus_root_path/components/nstackx/nstackx_core/dfile/interface",
137    ]
138    include_dirs += conn_common_inc + trans_common_inc
139  }
140  ohos_shared_library("softbus_utils") {
141    sanitize = {
142      ubsan = true
143      integer_overflow = true
144      boundary_sanitize = true
145      cfi = true
146      cfi_cross_dso = true
147      debug = false
148    }
149    branch_protector_ret = "pac_ret"
150
151    include_dirs = [
152      "$dsoftbus_root_path/interfaces/kits/common",
153      "$dsoftbus_root_path/core/bus_center/utils/include",
154      "$dsoftbus_root_path/core/common/include",
155      "$dsoftbus_root_path/components/nstackx/fillp/include",
156      "$dsoftbus_root_path/components/nstackx/nstackx_core/dfile/interface",
157      "$dsoftbus_root_path/components/nstackx/nstackx_util/interface",
158      "$dsoftbus_root_path/components/nstackx/nstackx_ctrl/interface",
159    ]
160    include_dirs += conn_common_inc + trans_common_inc
161    dfx_source = [
162      "dfx/hidumper_adapter/softbus_hidumper.c",
163      "dfx/hidumper_adapter/softbus_hidumper_bc_mgr.c",
164      "dfx/hidumper_adapter/softbus_hidumper_broadcast.c",
165      "dfx/hidumper_adapter/softbus_hidumper_disc.c",
166      "dfx/hidumper_adapter/softbus_hidumper_conn.c",
167      "dfx/hidumper_adapter/softbus_hidumper_nstack.c",
168      "dfx/hidumper_adapter/softbus_hidumper_trans.c",
169      "dfx/hidumper_adapter/softbus_hidumper_buscenter.c",
170      "dfx/hisysevent_adapter/softbus_hisysevt_nstack.c",
171    ]
172    sources = common_utils_src + conn_common_src + trans_common_src + dfx_source
173    sources += [ "$dsoftbus_root_path/core/common/utils/sqlite3_utils.c" ]
174    defines += [ "DEFAULT_STORAGE_PATH=\"/data/service/el1/public\"" ]
175    defines += [ "__STDC_FORMAT_MACROS" ]
176    if (is_asan) {
177      defines += [ "ASAN_BUILD" ]
178    }
179
180    public_configs = [ ":dsoftbus_utils_interface_L2" ]
181    public_deps = [
182      "$dsoftbus_dfx_path/anonymize:softbus_dfx_anonymizer",
183      "$dsoftbus_dfx_path/event:softbus_dfx_event",
184      "$dsoftbus_dfx_path/log:softbus_dfx_log",
185      "$dsoftbus_root_path/adapter:softbus_adapter",
186    ]
187    public_external_deps = [
188      "cJSON:cjson",
189      "sqlite:sqlite",
190    ]
191    external_deps += [
192      "bounds_checking_function:libsec_shared",
193      "cJSON:cjson",
194    ]
195    if (!enhanced) {
196      cflags += [ "-DFILLP_ENHANCED" ]
197      public_deps += [
198        "$dsoftbus_root_path/components/nstackx/fillp:FillpSo.open",
199        "$dsoftbus_root_path/components/nstackx/nstackx_core/dfile:nstackx_dfile.open",
200        "$dsoftbus_root_path/components/nstackx/nstackx_ctrl:nstackx_ctrl",
201        "$dsoftbus_root_path/components/nstackx/nstackx_util:nstackx_util.open",
202      ]
203    }
204    if (is_standard_system) {
205      external_deps += [
206        "hilog:libhilog",
207        "hisysevent:libhisysevent",
208      ]
209    }
210    innerapi_tags = [ "platformsdk_indirect" ]
211    part_name = "dsoftbus"
212    subsystem_name = "communication"
213  }
214}
215