1# Copyright (c) 2021 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
14DSOFTBUS_ROOT_PATH = "./../../.."
15import("$DSOFTBUS_ROOT_PATH/core/common/dfx/dsoftbus_dfx.gni")
16import("$DSOFTBUS_ROOT_PATH/dsoftbus.gni")
17
18NSTACKX_ROOT = "$DSOFTBUS_ROOT_PATH/components/nstackx"
19cflags = [ "-DENABLE_USER_LOG" ]
20if (defined(ohos_lite)) {
21  import("//build/lite/config/component/lite_component.gni")
22  if (ohos_kernel_type == "liteos_a" || ohos_kernel_type == "liteos_m") {
23    config("nstackx_util_header") {
24      include_dirs = [
25        "interface",
26        "platform/liteos",
27      ]
28    }
29  } else if (ohos_kernel_type == "linux") {
30    config("nstackx_util_header") {
31      include_dirs = [
32        "interface",
33        "platform/unix",
34      ]
35    }
36  }
37  if (ohos_kernel_type == "liteos_m") {
38    static_library("nstackx_util.open") {
39      cflags += [
40        "-D_GNU_SOURCE",
41        "-DNSTACKX_WITH_LITEOS",
42        "-DLWIP_DONT_PROVIDE_BYTEORDER_FUNCTIONS",
43        "-DLWIP_LITEOS_A_COMPAT",
44        "-DMBEDTLS_INCLUDED",
45        "-DNSTACKX_WITH_LITEOS_M",
46        "-DENABLE_USER_LOG",
47      ]
48      if (board_toolchain_type != "iccarm") {
49        cflags += [ "-Wall" ]
50      }
51      cflags_cc = cflags
52      include_dirs = [
53        "include",
54        "interface",
55        "platform/liteos",
56        "$NSTACKX_ROOT/nstackx_core/",
57        "$hilog_lite_include_path",
58        "$utils_lite_include_path",
59      ]
60      sources = [
61        "core/nstackx_event.c",
62        "core/nstackx_log.c",
63        "core/nstackx_socket.c",
64        "core/nstackx_timer.c",
65      ]
66
67      sources += [
68        "core/nstackx_getopt.c",
69        "platform/liteos/sys_dev.c",
70        "platform/liteos/sys_epoll.c",
71        "platform/liteos/sys_event.c",
72        "platform/liteos/sys_log.c",
73        "platform/liteos/sys_socket.c",
74        "platform/liteos/sys_timer.c",
75        "platform/liteos/sys_util.c",
76      ]
77
78      public_configs = [ ":nstackx_util_header" ]
79    }
80  } else {
81    shared_library("nstackx_util.open") {
82      if (ohos_kernel_type == "liteos_a") {
83        cflags += [
84          "-Wall",
85          "-D_GNU_SOURCE",
86          "-DNSTACKX_WITH_LITEOS",
87          "-DLWIP_DONT_PROVIDE_BYTEORDER_FUNCTIONS",
88          "-DLWIP_LITEOS_A_COMPAT",
89          "-DMBEDTLS_INCLUDED",
90          "-DENABLE_USER_LOG",
91        ]
92        cflags_cc = cflags
93        include_dirs = [
94          "include",
95          "interface",
96          "platform/liteos",
97          "$NSTACKX_ROOT/nstackx_core/",
98          "$hilog_lite_include_path",
99          "$utils_lite_include_path",
100        ]
101        sources = [
102          "core/nstackx_dev.c",
103          "core/nstackx_event.c",
104          "core/nstackx_getopt.c",
105          "core/nstackx_log.c",
106          "core/nstackx_mbedtls.c",
107          "core/nstackx_socket.c",
108          "core/nstackx_timer.c",
109          "core/nstackx_util.c",
110          "platform/liteos/sys_dev.c",
111          "platform/liteos/sys_epoll.c",
112          "platform/liteos/sys_event.c",
113          "platform/liteos/sys_log.c",
114          "platform/liteos/sys_socket.c",
115          "platform/liteos/sys_timer.c",
116          "platform/liteos/sys_util.c",
117        ]
118        deps = [ "$hilog_lite_deps_path" ]
119        external_deps = [
120          "bounds_checking_function:libsec_shared",
121          "mbedtls:mbedtls_shared",
122        ]
123      } else if (ohos_kernel_type == "linux") {
124        cflags += [
125          "-Wall",
126          "-DNSTACKX_WITH_HMOS_LINUX",
127          "-DMBEDTLS_INCLUDED",
128          "-DENABLE_USER_LOG",
129        ]
130        cflags_cc = cflags
131        include_dirs = [
132          "include",
133          "interface",
134          "platform/unix",
135          "$NSTACKX_ROOT/nstackx_core/",
136          "$hilog_lite_include_path",
137          "$utils_lite_include_path",
138        ]
139        sources = [
140          "core/nstackx_dev.c",
141          "core/nstackx_event.c",
142          "core/nstackx_getopt.c",
143          "core/nstackx_log.c",
144          "core/nstackx_mbedtls.c",
145          "core/nstackx_socket.c",
146          "core/nstackx_timer.c",
147          "core/nstackx_util.c",
148          "platform/unix/sys_dev.c",
149          "platform/unix/sys_epoll.c",
150          "platform/unix/sys_event.c",
151          "platform/unix/sys_log.c",
152          "platform/unix/sys_socket.c",
153          "platform/unix/sys_timer.c",
154          "platform/unix/sys_util.c",
155        ]
156        deps = [ "$hilog_lite_deps_path" ]
157        external_deps = [
158          "bounds_checking_function:libsec_shared",
159          "mbedtls:mbedtls_shared",
160        ]
161      }
162      public_configs = [ ":nstackx_util_header" ]
163    }
164  }
165} else {
166  import("//build/ohos.gni")
167
168  config("nstackx_util_header") {
169    include_dirs = [
170      "interface",
171      "platform/unix",
172    ]
173  }
174
175  ohos_shared_library("nstackx_util.open") {
176    sanitize = {
177      ubsan = true
178      integer_overflow = true
179      boundary_sanitize = true
180      cfi = true
181      cfi_cross_dso = true
182      debug = false
183    }
184    branch_protector_ret = "pac_ret"
185
186    cflags += [
187      "-DNSTACKX_WITH_HMOS_LINUX",
188      "-DENABLE_USER_LOG",
189      "-DNSTACKX_WITH_LINUX_STANDARD",
190    ]
191    if (defined(board_toolchain_type)) {
192      if (board_toolchain_type != "iccarm") {
193        cflags += [ "-Wall" ]
194      }
195    } else {
196      cflags += [ "-Wall" ]
197    }
198    cflags_cc = cflags
199    include_dirs = [
200      "include",
201      "interface",
202      "platform/unix",
203      "$NSTACKX_ROOT/nstackx_core/",
204    ]
205    sources = [
206      "core/nstackx_dev.c",
207      "core/nstackx_event.c",
208      "core/nstackx_getopt.c",
209      "core/nstackx_log.c",
210      "core/nstackx_socket.c",
211      "core/nstackx_timer.c",
212      "core/nstackx_util.c",
213      "platform/unix/sys_dev.c",
214      "platform/unix/sys_epoll.c",
215      "platform/unix/sys_event.c",
216      "platform/unix/sys_log.c",
217      "platform/unix/sys_socket.c",
218      "platform/unix/sys_timer.c",
219      "platform/unix/sys_util.c",
220    ]
221
222    external_deps = [
223      "bounds_checking_function:libsec_shared",
224      "hilog:libhilog",
225    ]
226    if (is_standard_system) {
227      cflags += [ "-DSSL_AND_CRYPTO_INCLUDED" ]
228      sources += [ "core/nstackx_openssl.c" ]
229      external_deps += [
230        "c_utils:utils",
231        "openssl:libcrypto_shared",
232      ]
233    }
234    public_configs = [ ":nstackx_util_header" ]
235    innerapi_tags = [ "platformsdk_indirect" ]
236    part_name = "dsoftbus"
237    subsystem_name = "communication"
238  }
239}
240