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
14import("//base/update/updater/updater_default_cfg.gni")
15import("//build/ohos.gni")
16
17updater_path = rebase_path("${updater_absolutely_path}", ".")
18updater_common_include = [
19  "include",
20  "ui/view",
21  "${updater_path}/utils/include",
22  "${updater_path}/interfaces/kits/include/",
23  "${updater_path}/services/common",
24  "${updater_path}/services/include/package",
25  "${updater_path}/services/package/pkg_manager",
26  "${updater_path}/services/package/pkg_verify",
27  "${updater_path}/services/include/log",
28  "${updater_path}/utils/json",
29  ".",
30  "./ui/include",
31  "./ui",
32  "./ui/control",
33]
34
35updater_common_deps = [
36  "${updater_path}/interfaces/kits/packages:libpackageExt",
37  "${updater_path}/services/applypatch:libapplypatch",
38  "${updater_path}/services/diffpatch/patch:libpatch",
39  "${updater_path}/services/flashd:libflashd",
40  "${updater_path}/services/fs_manager:libfsmanager",
41  "${updater_path}/services/log:libupdaterlog",
42  "${updater_path}/services/package:libupdaterpackage",
43  "${updater_path}/services/write_state:libwritestate",
44]
45
46updater_gen("updater") {
47  deps = [ "${updater_path}/services:libupdater_static" ]
48  external_deps = [ "hilog:libhilog" ]
49
50  # force link flashd library
51  ldflags = [
52    "-Wl,--whole-archive",
53    rebase_path("${target_out_dir}/flashd/libflashd.a"),
54    "-Wl,--no-whole-archive",
55  ]
56
57  part_name = "updater"
58  subsystem_name = "updater"
59}
60
61ohos_static_library("libupdater_static") {
62  defines = [ "BUILD_OHOS" ]
63  sources = [
64    "factory_reset/factory_reset.cpp",
65    "hwfault_retry/hwfault_retry.cpp",
66    "main.cpp",
67    "updater.cpp",
68    "updater_main.cpp",
69    "updater_preprocess.cpp",
70    "updater_utils.cpp",
71  ]
72
73  if (updater_ui_support) {
74    sources += [ "updater_ui.cpp" ]
75  }
76
77  include_dirs = updater_common_include
78
79  deps = updater_common_deps
80  deps += [
81    "${updater_path}/interfaces/kits/misc_info:libmiscinfo",
82    "${updater_path}/services/sdcard_update:libsdupdate",
83    "${updater_path}/services/ui:libui",
84  ]
85
86  # force link flashd library
87  ldflags = [
88    "-Wl,--whole-archive",
89    rebase_path("${target_out_dir}/flashd/libflashd.a"),
90    "-Wl,--no-whole-archive",
91  ]
92
93  if (defined(use_ptable)) {
94    include_dirs += [ "${updater_path}/services/ptable_parse" ]
95    deps += [ "${updater_path}/services/ptable_parse:libptableparse" ]
96    defines += [ "UPDATER_USE_PTABLE" ]
97  }
98
99  external_deps = [
100    "bounds_checking_function:libsec_shared",
101    "bounds_checking_function:libsec_static",
102    "bzip2:libbz2",
103    "cJSON:cjson",
104    "init:libbegetutil_static",
105    "libdrm:libdrm",
106    "openssl:libcrypto_shared",
107    "openssl:libssl_static",
108    "zlib:libz",
109  ]
110  if (updater_ui_support) {
111    external_deps += [ "drivers_peripheral_input:hdi_input_udriver" ]
112  }
113
114  if (updater_ui_support) {
115    external_deps += [ "ui_lite:libupdater_layout" ]
116  }
117
118  if (build_selinux) {
119    external_deps += [
120      "selinux:libselinux_static",
121      "selinux_adapter:librestorecon_static",
122    ]
123    cflags = [ "-DWITH_SELINUX" ]
124  }
125
126  if (build_variant == "user") {
127    defines += [ "UPDATER_BUILD_VARIANT_USER" ]
128  }
129
130  part_name = "updater"
131  subsystem_name = "updater"
132}
133
134config("libupdater_exported_headers") {
135  visibility = [ ":*" ]
136  include_dirs = [
137    "${updater_path}/services/include",
138    "${updater_path}/interfaces/kits/include",
139    "${updater_path}/services",
140  ]
141}
142
143ohos_static_library("libupdater") {
144  defines = [ "BUILD_OHOS" ]
145  sources = [
146    "factory_reset/factory_reset.cpp",
147    "hwfault_retry/hwfault_retry.cpp",
148    "updater.cpp",
149    "updater_preprocess.cpp",
150    "updater_utils.cpp",
151  ]
152
153  include_dirs = updater_common_include
154
155  deps = updater_common_deps
156
157  public_configs = [ ":libupdater_exported_headers" ]
158
159  if (defined(use_ptable)) {
160    include_dirs += [ "${updater_path}/services/ptable_parse" ]
161    deps += [ "${updater_path}/services/ptable_parse:libptableparse" ]
162    defines += [ "UPDATER_USE_PTABLE" ]
163  }
164
165  ldflags = []
166
167  # force link invisible function
168  if (defined(updater_force_link_libs)) {
169    ldflags += [ "-Wl,--whole-archive" ]
170    foreach(lib, updater_force_link_libs) {
171      ldflags += [ "${lib}" ]
172    }
173    ldflags += [ "-Wl,--no-whole-archive" ]
174  }
175
176  external_deps = [
177    "bounds_checking_function:libsec_shared",
178    "bounds_checking_function:libsec_static",
179    "bzip2:libbz2",
180    "cJSON:cjson",
181    "init:libbegetutil_static",
182    "openssl:libcrypto_shared",
183    "openssl:libssl_static",
184    "zlib:libz",
185  ]
186
187  # add updater custom library
188  if (defined(updater_custom_external_deps)) {
189    external_deps += updater_custom_external_deps
190  }
191
192  if (updater_ui_support) {
193    external_deps += [ "drivers_peripheral_input:hdi_input_udriver" ]
194  }
195
196  if (updater_ui_support) {
197    external_deps += [ "ui_lite:libupdater_layout" ]
198  }
199
200  if (build_selinux) {
201    external_deps += [
202      "selinux:libselinux_static",
203      "selinux_adapter:librestorecon_static",
204    ]
205    cflags = [ "-DWITH_SELINUX" ]
206  }
207
208  subsystem_name = "updater"
209  part_name = "updater"
210}
211