1# Copyright (c) 2021-2023 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/dsoftbus.gni")
16
17# basic compilation options
18cflags = [
19  "-DENABLE_USER_LOG",
20  "-DNSTACKX_DFINDER_HIDUMP",
21  "-DNSTACKX_EXTEND_BUSINESSDATA",
22  "-DDFINDER_SAVE_DEVICE_LIST",
23  "-DDFINDER_SUPPORT_SET_SCREEN_STATUS",
24  "-DDFINDER_DISTINGUISH_ACTIVE_PASSIVE_DISCOVERY",
25]
26
27# configure cflags based on build toolchain type
28if (defined(board_toolchain_type)) {
29  if (board_toolchain_type != "iccarm") {
30    cflags += [ "-Wall" ]
31  }
32} else {
33  cflags += [ "-Wall" ]
34}
35
36base_src = [
37  "core/json_payload.c",
38  "core/nstackx_common.c",
39  "core/nstackx_device.c",
40  "core/nstackx_device_local.c",
41  "core/nstackx_device_remote.c",
42  "core/nstackx_dfinder_log.c",
43]
44
45base_include_dirs = [
46  "interface",
47  "include",
48  "../nstackx_util/interface",
49]
50
51# mini platform
52if (defined(ohos_lite) && ohos_kernel_type == "liteos_m") {
53  mini_diff_src = [
54    "core/mini_discover/coap_adapter.c",
55    "core/mini_discover/coap_app.c",
56    "core/mini_discover/coap_discover.c",
57  ]
58  mini_diff_include_dirs = [
59    "include/mini_discover",
60    "../nstackx_util/platform/liteos",
61  ]
62  cflags += [
63    "-DNSTACKX_WITH_LITEOS",
64    "-DNSTACKX_WITH_LITEOS_M",
65    "-DLWIP_LITEOS_A_COMPAT",
66    "-D_GNU_SOURCE",
67    "-DDFINDER_USE_MINI_NSTACKX",
68  ]
69}
70
71# standard and small platform
72if (!defined(ohos_lite) ||
73    (defined(ohos_lite) && ohos_kernel_type != "liteos_m")) {
74  standard_small_diff_src = [
75    "core/coap_discover/coap_app.c",
76    "core/coap_discover/coap_client.c",
77    "core/coap_discover/coap_discover.c",
78    "core/nstackx_dfinder_hidump.c",
79    "core/nstackx_dfinder_mgt_msg_log.c",
80    "core/nstackx_dfinder_hievent.c",
81    "core/nstackx_statistics.c",
82    "core/nstackx_smartgenius.c",
83  ]
84  standard_small_diff_include_dirs = [ "include/coap_discover" ]
85  cflags += [ "-DDFINDER_MGT_MSG_LOG" ]
86}
87
88config("nstackx_ctrl_interface") {
89  include_dirs = [ "interface" ]
90}
91
92if (defined(ohos_lite)) {
93  if (ohos_kernel_type == "liteos_m") {
94    import("//build/lite/config/component/lite_component.gni")
95    static_library("nstackx_ctrl") {
96      sources = base_src
97      sources += mini_diff_src
98      include_dirs = base_include_dirs
99      include_dirs += mini_diff_include_dirs
100      include_dirs += [ "//third_party/cJSON" ]
101      public_configs = [ ":nstackx_ctrl_interface" ]
102      deps = [ "../nstackx_util:nstackx_util.open" ]
103      if (board_toolchain_type != "iccarm") {
104        cflags += [ "-std=c99" ]
105        cflags_cc = cflags
106      } else {
107        cflags += [
108          "--diag_suppress",
109          "Pa181",
110        ]
111        include_dirs += [
112          "//kernel/liteos_m/components/net/lwip-2.1/porting/include",
113          "//third_party/lwip/src/include",
114        ]
115      }
116    }
117  } else {
118    import("//build/lite/config/component/lite_component.gni")
119    shared_library("nstackx_ctrl") {
120      sources = base_src
121      sources += standard_small_diff_src
122      include_dirs = base_include_dirs
123      include_dirs += standard_small_diff_include_dirs
124      public_configs = [ ":nstackx_ctrl_interface" ]
125      deps = [
126        "../nstackx_util:nstackx_util.open",
127        "//build/lite/config/component/cJSON:cjson_shared",
128      ]
129      external_deps = [
130        "bounds_checking_function:libsec_shared",
131        "libcoap:libcoap",
132      ]
133      if (ohos_kernel_type == "liteos_a") {
134        cflags += [
135          "-DNSTACKX_WITH_LITEOS",
136          "-DLWIP_LITEOS_A_COMPAT",
137        ]
138      }
139      cflags += [
140        "-fPIC",
141        "-std=c99",
142      ]
143      cflags_cc = cflags
144      ldflags = [
145        "-Wl,-z,relro,-z,now",
146        "-s",
147        "-fPIC",
148      ]
149    }
150  }
151} else {
152  import("//build/ohos.gni")
153  ohos_shared_library("nstackx_ctrl") {
154    sanitize = {
155      cfi = true
156      cfi_cross_dso = true
157      debug = false
158    }
159    branch_protector_ret = "pac_ret"
160
161    cflags += [ "-DDFINDER_MGT_MSG_LOG" ]
162    cflags_cc = cflags
163    sources = base_src
164    sources += standard_small_diff_src
165    include_dirs = base_include_dirs
166    include_dirs += standard_small_diff_include_dirs
167    include_dirs += [ "../nstackx_util/platform/unix" ]
168    public_configs = [ ":nstackx_ctrl_interface" ]
169    deps = [ "../nstackx_util:nstackx_util.open" ]
170    external_deps = [
171      "bounds_checking_function:libsec_shared",
172      "cJSON:cjson",
173      "libcoap:libcoap",
174    ]
175    subsystem_name = "communication"
176    innerapi_tags = [ "platformsdk_indirect" ]
177    part_name = "dsoftbus"
178  }
179}
180