1060ff233Sopenharmony_ci# Copyright (c) 2021 Huawei Device Co., Ltd.
2060ff233Sopenharmony_ci# Licensed under the Apache License, Version 2.0 (the "License");
3060ff233Sopenharmony_ci# you may not use this file except in compliance with the License.
4060ff233Sopenharmony_ci# You may obtain a copy of the License at
5060ff233Sopenharmony_ci#
6060ff233Sopenharmony_ci#     http://www.apache.org/licenses/LICENSE-2.0
7060ff233Sopenharmony_ci#
8060ff233Sopenharmony_ci# Unless required by applicable law or agreed to in writing, software
9060ff233Sopenharmony_ci# distributed under the License is distributed on an "AS IS" BASIS,
10060ff233Sopenharmony_ci# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11060ff233Sopenharmony_ci# See the License for the specific language governing permissions and
12060ff233Sopenharmony_ci# limitations under the License.
13060ff233Sopenharmony_ci
14060ff233Sopenharmony_ciDSOFTBUS_ROOT_PATH = "./../../.."
15060ff233Sopenharmony_ciimport("$DSOFTBUS_ROOT_PATH/core/common/dfx/dsoftbus_dfx.gni")
16060ff233Sopenharmony_ciimport("$DSOFTBUS_ROOT_PATH/dsoftbus.gni")
17060ff233Sopenharmony_ci
18060ff233Sopenharmony_ciNSTACKX_ROOT = "$DSOFTBUS_ROOT_PATH/components/nstackx"
19060ff233Sopenharmony_cicflags = [ "-DENABLE_USER_LOG" ]
20060ff233Sopenharmony_ciif (defined(ohos_lite)) {
21060ff233Sopenharmony_ci  import("//build/lite/config/component/lite_component.gni")
22060ff233Sopenharmony_ci  if (ohos_kernel_type == "liteos_a" || ohos_kernel_type == "liteos_m") {
23060ff233Sopenharmony_ci    config("nstackx_util_header") {
24060ff233Sopenharmony_ci      include_dirs = [
25060ff233Sopenharmony_ci        "interface",
26060ff233Sopenharmony_ci        "platform/liteos",
27060ff233Sopenharmony_ci      ]
28060ff233Sopenharmony_ci    }
29060ff233Sopenharmony_ci  } else if (ohos_kernel_type == "linux") {
30060ff233Sopenharmony_ci    config("nstackx_util_header") {
31060ff233Sopenharmony_ci      include_dirs = [
32060ff233Sopenharmony_ci        "interface",
33060ff233Sopenharmony_ci        "platform/unix",
34060ff233Sopenharmony_ci      ]
35060ff233Sopenharmony_ci    }
36060ff233Sopenharmony_ci  }
37060ff233Sopenharmony_ci  if (ohos_kernel_type == "liteos_m") {
38060ff233Sopenharmony_ci    static_library("nstackx_util.open") {
39060ff233Sopenharmony_ci      cflags += [
40060ff233Sopenharmony_ci        "-D_GNU_SOURCE",
41060ff233Sopenharmony_ci        "-DNSTACKX_WITH_LITEOS",
42060ff233Sopenharmony_ci        "-DLWIP_DONT_PROVIDE_BYTEORDER_FUNCTIONS",
43060ff233Sopenharmony_ci        "-DLWIP_LITEOS_A_COMPAT",
44060ff233Sopenharmony_ci        "-DMBEDTLS_INCLUDED",
45060ff233Sopenharmony_ci        "-DNSTACKX_WITH_LITEOS_M",
46060ff233Sopenharmony_ci        "-DENABLE_USER_LOG",
47060ff233Sopenharmony_ci      ]
48060ff233Sopenharmony_ci      if (board_toolchain_type != "iccarm") {
49060ff233Sopenharmony_ci        cflags += [ "-Wall" ]
50060ff233Sopenharmony_ci      }
51060ff233Sopenharmony_ci      cflags_cc = cflags
52060ff233Sopenharmony_ci      include_dirs = [
53060ff233Sopenharmony_ci        "include",
54060ff233Sopenharmony_ci        "interface",
55060ff233Sopenharmony_ci        "platform/liteos",
56060ff233Sopenharmony_ci        "$NSTACKX_ROOT/nstackx_core/",
57060ff233Sopenharmony_ci        "$hilog_lite_include_path",
58060ff233Sopenharmony_ci        "$utils_lite_include_path",
59060ff233Sopenharmony_ci      ]
60060ff233Sopenharmony_ci      sources = [
61060ff233Sopenharmony_ci        "core/nstackx_event.c",
62060ff233Sopenharmony_ci        "core/nstackx_log.c",
63060ff233Sopenharmony_ci        "core/nstackx_socket.c",
64060ff233Sopenharmony_ci        "core/nstackx_timer.c",
65060ff233Sopenharmony_ci      ]
66060ff233Sopenharmony_ci
67060ff233Sopenharmony_ci      sources += [
68060ff233Sopenharmony_ci        "core/nstackx_getopt.c",
69060ff233Sopenharmony_ci        "platform/liteos/sys_dev.c",
70060ff233Sopenharmony_ci        "platform/liteos/sys_epoll.c",
71060ff233Sopenharmony_ci        "platform/liteos/sys_event.c",
72060ff233Sopenharmony_ci        "platform/liteos/sys_log.c",
73060ff233Sopenharmony_ci        "platform/liteos/sys_socket.c",
74060ff233Sopenharmony_ci        "platform/liteos/sys_timer.c",
75060ff233Sopenharmony_ci        "platform/liteos/sys_util.c",
76060ff233Sopenharmony_ci      ]
77060ff233Sopenharmony_ci
78060ff233Sopenharmony_ci      public_configs = [ ":nstackx_util_header" ]
79060ff233Sopenharmony_ci    }
80060ff233Sopenharmony_ci  } else {
81060ff233Sopenharmony_ci    shared_library("nstackx_util.open") {
82060ff233Sopenharmony_ci      if (ohos_kernel_type == "liteos_a") {
83060ff233Sopenharmony_ci        cflags += [
84060ff233Sopenharmony_ci          "-Wall",
85060ff233Sopenharmony_ci          "-D_GNU_SOURCE",
86060ff233Sopenharmony_ci          "-DNSTACKX_WITH_LITEOS",
87060ff233Sopenharmony_ci          "-DLWIP_DONT_PROVIDE_BYTEORDER_FUNCTIONS",
88060ff233Sopenharmony_ci          "-DLWIP_LITEOS_A_COMPAT",
89060ff233Sopenharmony_ci          "-DMBEDTLS_INCLUDED",
90060ff233Sopenharmony_ci          "-DENABLE_USER_LOG",
91060ff233Sopenharmony_ci        ]
92060ff233Sopenharmony_ci        cflags_cc = cflags
93060ff233Sopenharmony_ci        include_dirs = [
94060ff233Sopenharmony_ci          "include",
95060ff233Sopenharmony_ci          "interface",
96060ff233Sopenharmony_ci          "platform/liteos",
97060ff233Sopenharmony_ci          "$NSTACKX_ROOT/nstackx_core/",
98060ff233Sopenharmony_ci          "$hilog_lite_include_path",
99060ff233Sopenharmony_ci          "$utils_lite_include_path",
100060ff233Sopenharmony_ci        ]
101060ff233Sopenharmony_ci        sources = [
102060ff233Sopenharmony_ci          "core/nstackx_dev.c",
103060ff233Sopenharmony_ci          "core/nstackx_event.c",
104060ff233Sopenharmony_ci          "core/nstackx_getopt.c",
105060ff233Sopenharmony_ci          "core/nstackx_log.c",
106060ff233Sopenharmony_ci          "core/nstackx_mbedtls.c",
107060ff233Sopenharmony_ci          "core/nstackx_socket.c",
108060ff233Sopenharmony_ci          "core/nstackx_timer.c",
109060ff233Sopenharmony_ci          "core/nstackx_util.c",
110060ff233Sopenharmony_ci          "platform/liteos/sys_dev.c",
111060ff233Sopenharmony_ci          "platform/liteos/sys_epoll.c",
112060ff233Sopenharmony_ci          "platform/liteos/sys_event.c",
113060ff233Sopenharmony_ci          "platform/liteos/sys_log.c",
114060ff233Sopenharmony_ci          "platform/liteos/sys_socket.c",
115060ff233Sopenharmony_ci          "platform/liteos/sys_timer.c",
116060ff233Sopenharmony_ci          "platform/liteos/sys_util.c",
117060ff233Sopenharmony_ci        ]
118060ff233Sopenharmony_ci        deps = [ "$hilog_lite_deps_path" ]
119060ff233Sopenharmony_ci        external_deps = [
120060ff233Sopenharmony_ci          "bounds_checking_function:libsec_shared",
121060ff233Sopenharmony_ci          "mbedtls:mbedtls_shared",
122060ff233Sopenharmony_ci        ]
123060ff233Sopenharmony_ci      } else if (ohos_kernel_type == "linux") {
124060ff233Sopenharmony_ci        cflags += [
125060ff233Sopenharmony_ci          "-Wall",
126060ff233Sopenharmony_ci          "-DNSTACKX_WITH_HMOS_LINUX",
127060ff233Sopenharmony_ci          "-DMBEDTLS_INCLUDED",
128060ff233Sopenharmony_ci          "-DENABLE_USER_LOG",
129060ff233Sopenharmony_ci        ]
130060ff233Sopenharmony_ci        cflags_cc = cflags
131060ff233Sopenharmony_ci        include_dirs = [
132060ff233Sopenharmony_ci          "include",
133060ff233Sopenharmony_ci          "interface",
134060ff233Sopenharmony_ci          "platform/unix",
135060ff233Sopenharmony_ci          "$NSTACKX_ROOT/nstackx_core/",
136060ff233Sopenharmony_ci          "$hilog_lite_include_path",
137060ff233Sopenharmony_ci          "$utils_lite_include_path",
138060ff233Sopenharmony_ci        ]
139060ff233Sopenharmony_ci        sources = [
140060ff233Sopenharmony_ci          "core/nstackx_dev.c",
141060ff233Sopenharmony_ci          "core/nstackx_event.c",
142060ff233Sopenharmony_ci          "core/nstackx_getopt.c",
143060ff233Sopenharmony_ci          "core/nstackx_log.c",
144060ff233Sopenharmony_ci          "core/nstackx_mbedtls.c",
145060ff233Sopenharmony_ci          "core/nstackx_socket.c",
146060ff233Sopenharmony_ci          "core/nstackx_timer.c",
147060ff233Sopenharmony_ci          "core/nstackx_util.c",
148060ff233Sopenharmony_ci          "platform/unix/sys_dev.c",
149060ff233Sopenharmony_ci          "platform/unix/sys_epoll.c",
150060ff233Sopenharmony_ci          "platform/unix/sys_event.c",
151060ff233Sopenharmony_ci          "platform/unix/sys_log.c",
152060ff233Sopenharmony_ci          "platform/unix/sys_socket.c",
153060ff233Sopenharmony_ci          "platform/unix/sys_timer.c",
154060ff233Sopenharmony_ci          "platform/unix/sys_util.c",
155060ff233Sopenharmony_ci        ]
156060ff233Sopenharmony_ci        deps = [ "$hilog_lite_deps_path" ]
157060ff233Sopenharmony_ci        external_deps = [
158060ff233Sopenharmony_ci          "bounds_checking_function:libsec_shared",
159060ff233Sopenharmony_ci          "mbedtls:mbedtls_shared",
160060ff233Sopenharmony_ci        ]
161060ff233Sopenharmony_ci      }
162060ff233Sopenharmony_ci      public_configs = [ ":nstackx_util_header" ]
163060ff233Sopenharmony_ci    }
164060ff233Sopenharmony_ci  }
165060ff233Sopenharmony_ci} else {
166060ff233Sopenharmony_ci  import("//build/ohos.gni")
167060ff233Sopenharmony_ci
168060ff233Sopenharmony_ci  config("nstackx_util_header") {
169060ff233Sopenharmony_ci    include_dirs = [
170060ff233Sopenharmony_ci      "interface",
171060ff233Sopenharmony_ci      "platform/unix",
172060ff233Sopenharmony_ci    ]
173060ff233Sopenharmony_ci  }
174060ff233Sopenharmony_ci
175060ff233Sopenharmony_ci  ohos_shared_library("nstackx_util.open") {
176060ff233Sopenharmony_ci    sanitize = {
177060ff233Sopenharmony_ci      ubsan = true
178060ff233Sopenharmony_ci      integer_overflow = true
179060ff233Sopenharmony_ci      boundary_sanitize = true
180060ff233Sopenharmony_ci      cfi = true
181060ff233Sopenharmony_ci      cfi_cross_dso = true
182060ff233Sopenharmony_ci      debug = false
183060ff233Sopenharmony_ci    }
184060ff233Sopenharmony_ci    branch_protector_ret = "pac_ret"
185060ff233Sopenharmony_ci
186060ff233Sopenharmony_ci    cflags += [
187060ff233Sopenharmony_ci      "-DNSTACKX_WITH_HMOS_LINUX",
188060ff233Sopenharmony_ci      "-DENABLE_USER_LOG",
189060ff233Sopenharmony_ci      "-DNSTACKX_WITH_LINUX_STANDARD",
190060ff233Sopenharmony_ci    ]
191060ff233Sopenharmony_ci    if (defined(board_toolchain_type)) {
192060ff233Sopenharmony_ci      if (board_toolchain_type != "iccarm") {
193060ff233Sopenharmony_ci        cflags += [ "-Wall" ]
194060ff233Sopenharmony_ci      }
195060ff233Sopenharmony_ci    } else {
196060ff233Sopenharmony_ci      cflags += [ "-Wall" ]
197060ff233Sopenharmony_ci    }
198060ff233Sopenharmony_ci    cflags_cc = cflags
199060ff233Sopenharmony_ci    include_dirs = [
200060ff233Sopenharmony_ci      "include",
201060ff233Sopenharmony_ci      "interface",
202060ff233Sopenharmony_ci      "platform/unix",
203060ff233Sopenharmony_ci      "$NSTACKX_ROOT/nstackx_core/",
204060ff233Sopenharmony_ci    ]
205060ff233Sopenharmony_ci    sources = [
206060ff233Sopenharmony_ci      "core/nstackx_dev.c",
207060ff233Sopenharmony_ci      "core/nstackx_event.c",
208060ff233Sopenharmony_ci      "core/nstackx_getopt.c",
209060ff233Sopenharmony_ci      "core/nstackx_log.c",
210060ff233Sopenharmony_ci      "core/nstackx_socket.c",
211060ff233Sopenharmony_ci      "core/nstackx_timer.c",
212060ff233Sopenharmony_ci      "core/nstackx_util.c",
213060ff233Sopenharmony_ci      "platform/unix/sys_dev.c",
214060ff233Sopenharmony_ci      "platform/unix/sys_epoll.c",
215060ff233Sopenharmony_ci      "platform/unix/sys_event.c",
216060ff233Sopenharmony_ci      "platform/unix/sys_log.c",
217060ff233Sopenharmony_ci      "platform/unix/sys_socket.c",
218060ff233Sopenharmony_ci      "platform/unix/sys_timer.c",
219060ff233Sopenharmony_ci      "platform/unix/sys_util.c",
220060ff233Sopenharmony_ci    ]
221060ff233Sopenharmony_ci
222060ff233Sopenharmony_ci    external_deps = [
223060ff233Sopenharmony_ci      "bounds_checking_function:libsec_shared",
224060ff233Sopenharmony_ci      "hilog:libhilog",
225060ff233Sopenharmony_ci    ]
226060ff233Sopenharmony_ci    if (is_standard_system) {
227060ff233Sopenharmony_ci      cflags += [ "-DSSL_AND_CRYPTO_INCLUDED" ]
228060ff233Sopenharmony_ci      sources += [ "core/nstackx_openssl.c" ]
229060ff233Sopenharmony_ci      external_deps += [
230060ff233Sopenharmony_ci        "c_utils:utils",
231060ff233Sopenharmony_ci        "openssl:libcrypto_shared",
232060ff233Sopenharmony_ci      ]
233060ff233Sopenharmony_ci    }
234060ff233Sopenharmony_ci    public_configs = [ ":nstackx_util_header" ]
235060ff233Sopenharmony_ci    innerapi_tags = [ "platformsdk_indirect" ]
236060ff233Sopenharmony_ci    part_name = "dsoftbus"
237060ff233Sopenharmony_ci    subsystem_name = "communication"
238060ff233Sopenharmony_ci  }
239060ff233Sopenharmony_ci}
240