1060ff233Sopenharmony_ci# Copyright (c) 2021-2023 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/dsoftbus.gni")
16060ff233Sopenharmony_ci
17060ff233Sopenharmony_ci# basic compilation options
18060ff233Sopenharmony_cicflags = [
19060ff233Sopenharmony_ci  "-DENABLE_USER_LOG",
20060ff233Sopenharmony_ci  "-DNSTACKX_EXTEND_BUSINESSDATA",
21060ff233Sopenharmony_ci  "-DDFINDER_SAVE_DEVICE_LIST",
22060ff233Sopenharmony_ci  "-DDFINDER_SUPPORT_SET_SCREEN_STATUS",
23060ff233Sopenharmony_ci  "-DDFINDER_DISTINGUISH_ACTIVE_PASSIVE_DISCOVERY",
24060ff233Sopenharmony_ci]
25060ff233Sopenharmony_ci
26060ff233Sopenharmony_ci# configure cflags based on build toolchain type
27060ff233Sopenharmony_ciif (defined(board_toolchain_type)) {
28060ff233Sopenharmony_ci  if (board_toolchain_type != "iccarm") {
29060ff233Sopenharmony_ci    cflags += [ "-Wall" ]
30060ff233Sopenharmony_ci  }
31060ff233Sopenharmony_ci} else {
32060ff233Sopenharmony_ci  cflags += [ "-Wall" ]
33060ff233Sopenharmony_ci}
34060ff233Sopenharmony_ci
35060ff233Sopenharmony_cibase_src = [
36060ff233Sopenharmony_ci  "core/json_payload.c",
37060ff233Sopenharmony_ci  "core/nstackx_common.c",
38060ff233Sopenharmony_ci  "core/nstackx_device.c",
39060ff233Sopenharmony_ci  "core/nstackx_device_local.c",
40060ff233Sopenharmony_ci  "core/nstackx_device_remote.c",
41060ff233Sopenharmony_ci  "core/nstackx_dfinder_log.c",
42060ff233Sopenharmony_ci]
43060ff233Sopenharmony_ci
44060ff233Sopenharmony_cibase_include_dirs = [
45060ff233Sopenharmony_ci  "interface",
46060ff233Sopenharmony_ci  "include",
47060ff233Sopenharmony_ci  "../nstackx_util/interface",
48060ff233Sopenharmony_ci]
49060ff233Sopenharmony_ci
50060ff233Sopenharmony_ci# mini platform
51060ff233Sopenharmony_ciif (defined(ohos_lite) && ohos_kernel_type == "liteos_m") {
52060ff233Sopenharmony_ci  mini_diff_src = [
53060ff233Sopenharmony_ci    "core/mini_discover/coap_adapter.c",
54060ff233Sopenharmony_ci    "core/mini_discover/coap_app.c",
55060ff233Sopenharmony_ci    "core/mini_discover/coap_discover.c",
56060ff233Sopenharmony_ci    "core/nstackx_statistics.c",
57060ff233Sopenharmony_ci    "core/nstackx_dfinder_hievent.c",
58060ff233Sopenharmony_ci  ]
59060ff233Sopenharmony_ci  mini_diff_include_dirs = [
60060ff233Sopenharmony_ci    "include/mini_discover",
61060ff233Sopenharmony_ci    "../nstackx_util/platform/liteos",
62060ff233Sopenharmony_ci  ]
63060ff233Sopenharmony_ci  cflags += [
64060ff233Sopenharmony_ci    "-DNSTACKX_WITH_LITEOS",
65060ff233Sopenharmony_ci    "-DNSTACKX_WITH_LITEOS_M",
66060ff233Sopenharmony_ci    "-DLWIP_LITEOS_A_COMPAT",
67060ff233Sopenharmony_ci    "-D_GNU_SOURCE",
68060ff233Sopenharmony_ci    "-DDFINDER_USE_MINI_NSTACKX",
69060ff233Sopenharmony_ci  ]
70060ff233Sopenharmony_ci}
71060ff233Sopenharmony_ci
72060ff233Sopenharmony_ci# standard and small platform
73060ff233Sopenharmony_ciif (!defined(ohos_lite) ||
74060ff233Sopenharmony_ci    (defined(ohos_lite) && ohos_kernel_type != "liteos_m")) {
75060ff233Sopenharmony_ci  standard_small_diff_src = [
76060ff233Sopenharmony_ci    "core/coap_discover/coap_app.c",
77060ff233Sopenharmony_ci    "core/coap_discover/coap_client.c",
78060ff233Sopenharmony_ci    "core/coap_discover/coap_discover.c",
79060ff233Sopenharmony_ci    "core/nstackx_dfinder_hidump.c",
80060ff233Sopenharmony_ci    "core/nstackx_dfinder_mgt_msg_log.c",
81060ff233Sopenharmony_ci    "core/nstackx_dfinder_hievent.c",
82060ff233Sopenharmony_ci    "core/nstackx_statistics.c",
83060ff233Sopenharmony_ci    "core/nstackx_smartgenius.c",
84060ff233Sopenharmony_ci  ]
85060ff233Sopenharmony_ci  standard_small_diff_include_dirs = [ "include/coap_discover" ]
86060ff233Sopenharmony_ci  cflags += [
87060ff233Sopenharmony_ci    "-DDFINDER_MGT_MSG_LOG",
88060ff233Sopenharmony_ci    "-DNSTACKX_DFINDER_HIDUMP",
89060ff233Sopenharmony_ci  ]
90060ff233Sopenharmony_ci}
91060ff233Sopenharmony_ci
92060ff233Sopenharmony_ciconfig("nstackx_ctrl_interface") {
93060ff233Sopenharmony_ci  include_dirs = [ "interface" ]
94060ff233Sopenharmony_ci}
95060ff233Sopenharmony_ci
96060ff233Sopenharmony_ciif (defined(ohos_lite)) {
97060ff233Sopenharmony_ci  if (ohos_kernel_type == "liteos_m") {
98060ff233Sopenharmony_ci    import("//build/lite/config/component/lite_component.gni")
99060ff233Sopenharmony_ci    static_library("nstackx_ctrl") {
100060ff233Sopenharmony_ci      sources = base_src
101060ff233Sopenharmony_ci      sources += mini_diff_src
102060ff233Sopenharmony_ci      include_dirs = base_include_dirs
103060ff233Sopenharmony_ci      include_dirs += mini_diff_include_dirs
104060ff233Sopenharmony_ci      include_dirs += [ "//third_party/cJSON" ]
105060ff233Sopenharmony_ci      public_configs = [ ":nstackx_ctrl_interface" ]
106060ff233Sopenharmony_ci      deps = [ "../nstackx_util:nstackx_util.open" ]
107060ff233Sopenharmony_ci      if (board_toolchain_type != "iccarm") {
108060ff233Sopenharmony_ci        cflags += [ "-std=c99" ]
109060ff233Sopenharmony_ci        cflags_cc = cflags
110060ff233Sopenharmony_ci      } else {
111060ff233Sopenharmony_ci        cflags += [
112060ff233Sopenharmony_ci          "--diag_suppress",
113060ff233Sopenharmony_ci          "Pa181",
114060ff233Sopenharmony_ci        ]
115060ff233Sopenharmony_ci        include_dirs += [
116060ff233Sopenharmony_ci          "//kernel/liteos_m/components/net/lwip-2.1/porting/include",
117060ff233Sopenharmony_ci          "//third_party/lwip/src/include",
118060ff233Sopenharmony_ci        ]
119060ff233Sopenharmony_ci      }
120060ff233Sopenharmony_ci    }
121060ff233Sopenharmony_ci  } else {
122060ff233Sopenharmony_ci    import("//build/lite/config/component/lite_component.gni")
123060ff233Sopenharmony_ci    shared_library("nstackx_ctrl") {
124060ff233Sopenharmony_ci      sources = base_src
125060ff233Sopenharmony_ci      sources += standard_small_diff_src
126060ff233Sopenharmony_ci      include_dirs = base_include_dirs
127060ff233Sopenharmony_ci      include_dirs += standard_small_diff_include_dirs
128060ff233Sopenharmony_ci      public_configs = [ ":nstackx_ctrl_interface" ]
129060ff233Sopenharmony_ci      deps = [
130060ff233Sopenharmony_ci        "../nstackx_util:nstackx_util.open",
131060ff233Sopenharmony_ci        "//build/lite/config/component/cJSON:cjson_shared",
132060ff233Sopenharmony_ci      ]
133060ff233Sopenharmony_ci      external_deps = [
134060ff233Sopenharmony_ci        "bounds_checking_function:libsec_shared",
135060ff233Sopenharmony_ci        "libcoap:libcoap",
136060ff233Sopenharmony_ci      ]
137060ff233Sopenharmony_ci      if (ohos_kernel_type == "liteos_a") {
138060ff233Sopenharmony_ci        cflags += [
139060ff233Sopenharmony_ci          "-DNSTACKX_WITH_LITEOS",
140060ff233Sopenharmony_ci          "-DLWIP_LITEOS_A_COMPAT",
141060ff233Sopenharmony_ci        ]
142060ff233Sopenharmony_ci      }
143060ff233Sopenharmony_ci      cflags += [
144060ff233Sopenharmony_ci        "-fPIC",
145060ff233Sopenharmony_ci        "-std=c99",
146060ff233Sopenharmony_ci        "-DNSTACKX_DFINDER_HIDUMP",
147060ff233Sopenharmony_ci      ]
148060ff233Sopenharmony_ci      cflags_cc = cflags
149060ff233Sopenharmony_ci      ldflags = [
150060ff233Sopenharmony_ci        "-Wl,-z,relro,-z,now",
151060ff233Sopenharmony_ci        "-s",
152060ff233Sopenharmony_ci        "-fPIC",
153060ff233Sopenharmony_ci      ]
154060ff233Sopenharmony_ci    }
155060ff233Sopenharmony_ci  }
156060ff233Sopenharmony_ci} else {
157060ff233Sopenharmony_ci  import("//build/ohos.gni")
158060ff233Sopenharmony_ci  ohos_shared_library("nstackx_ctrl") {
159060ff233Sopenharmony_ci    sanitize = {
160060ff233Sopenharmony_ci      ubsan = true
161060ff233Sopenharmony_ci      integer_overflow = true
162060ff233Sopenharmony_ci      boundary_sanitize = true
163060ff233Sopenharmony_ci      cfi = true
164060ff233Sopenharmony_ci      cfi_cross_dso = true
165060ff233Sopenharmony_ci      debug = false
166060ff233Sopenharmony_ci    }
167060ff233Sopenharmony_ci    branch_protector_ret = "pac_ret"
168060ff233Sopenharmony_ci
169060ff233Sopenharmony_ci    cflags += [
170060ff233Sopenharmony_ci      "-DDFINDER_MGT_MSG_LOG",
171060ff233Sopenharmony_ci      "-DNSTACKX_DFINDER_HIDUMP",
172060ff233Sopenharmony_ci    ]
173060ff233Sopenharmony_ci    cflags_cc = cflags
174060ff233Sopenharmony_ci    sources = base_src
175060ff233Sopenharmony_ci    sources += standard_small_diff_src
176060ff233Sopenharmony_ci    include_dirs = base_include_dirs
177060ff233Sopenharmony_ci    include_dirs += standard_small_diff_include_dirs
178060ff233Sopenharmony_ci    include_dirs += [ "../nstackx_util/platform/unix" ]
179060ff233Sopenharmony_ci    public_configs = [ ":nstackx_ctrl_interface" ]
180060ff233Sopenharmony_ci    deps = [ "../nstackx_util:nstackx_util.open" ]
181060ff233Sopenharmony_ci    external_deps = [
182060ff233Sopenharmony_ci      "bounds_checking_function:libsec_shared",
183060ff233Sopenharmony_ci      "cJSON:cjson",
184060ff233Sopenharmony_ci      "libcoap:libcoap",
185060ff233Sopenharmony_ci    ]
186060ff233Sopenharmony_ci    subsystem_name = "communication"
187060ff233Sopenharmony_ci    innerapi_tags = [ "platformsdk_indirect" ]
188060ff233Sopenharmony_ci    part_name = "dsoftbus"
189060ff233Sopenharmony_ci  }
190060ff233Sopenharmony_ci}
191