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      cfi = true
178      cfi_cross_dso = true
179      debug = false
180    }
181    branch_protector_ret = "pac_ret"
182
183    cflags += [
184      "-DNSTACKX_WITH_HMOS_LINUX",
185      "-DENABLE_USER_LOG",
186    ]
187    if (defined(board_toolchain_type)) {
188      if (board_toolchain_type != "iccarm") {
189        cflags += [ "-Wall" ]
190      }
191    } else {
192      cflags += [ "-Wall" ]
193    }
194    cflags_cc = cflags
195    include_dirs = [
196      "include",
197      "interface",
198      "platform/unix",
199      "$NSTACKX_ROOT/nstackx_core/",
200    ]
201    sources = [
202      "core/nstackx_dev.c",
203      "core/nstackx_event.c",
204      "core/nstackx_getopt.c",
205      "core/nstackx_log.c",
206      "core/nstackx_socket.c",
207      "core/nstackx_timer.c",
208      "core/nstackx_util.c",
209      "platform/unix/sys_dev.c",
210      "platform/unix/sys_epoll.c",
211      "platform/unix/sys_event.c",
212      "platform/unix/sys_log.c",
213      "platform/unix/sys_socket.c",
214      "platform/unix/sys_timer.c",
215      "platform/unix/sys_util.c",
216    ]
217
218    external_deps = [
219      "bounds_checking_function:libsec_shared",
220      "hilog:libhilog",
221    ]
222    if (is_standard_system) {
223      cflags += [ "-DSSL_AND_CRYPTO_INCLUDED" ]
224      sources += [ "core/nstackx_openssl.c" ]
225      external_deps += [
226        "c_utils:utils",
227        "openssl:libcrypto_shared",
228      ]
229    }
230    public_configs = [ ":nstackx_util_header" ]
231    innerapi_tags = [ "platformsdk_indirect" ]
232    part_name = "dsoftbus"
233    subsystem_name = "communication"
234  }
235}
236