• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright (c) 2020 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
14# Description: Native Development Kit Template
15
16declare_args() {
17  ohos_build_ndk = false
18  ohos_build_ndk_target_host = "linux-x86_64"
19  ohos_build_ndk_version = "1.0.0"
20}
21
22ndk_out_dir = "$root_out_dir/ndk"
23
24ndk_headers_out_dir = "$ndk_out_dir/sysroot/usr/include"
25ndk_libraries_out_dir = "$ndk_out_dir/sysroot/usr/lib"
26ndk_docs_out_dir = "$ndk_out_dir/docs"
27
28windows_system = "windows-x86_64"
29linux_system = "linux-x86_64"
30
31ndk_toolchain = "gcc"
32if (ohos_build_compiler == "clang") {
33  ndk_toolchain = "llvm"
34}
35ndk_windows_specific_out_dir = "${ndk_out_dir}/$ndk_toolchain"
36ndk_linux_specific_out_dir = "${ndk_out_dir}/$ndk_toolchain"
37
38ndk_windows_toolchains_out_dir = "${ndk_windows_specific_out_dir}"
39ndk_windows_tools_out_dir = "${ndk_out_dir}/$windows_system/tools"
40
41ndk_linux_toolchains_out_dir = "${ndk_linux_specific_out_dir}"
42ndk_linux_tools_out_dir = "${ndk_out_dir}/$linux_system/tools"
43
44template("copy_files") {
45  assert(defined(invoker.src) && defined(invoker.dest_dir),
46         "sources and dest_dir are necessary")
47  if (defined(invoker.src_type)) {
48    src_type = invoker.src_type
49  } else {
50    src_type = "dir"
51  }
52  _deps = []
53  if (defined(invoker.deps)) {
54    _deps += invoker.deps
55  }
56  src = invoker.src
57  dst = invoker.dest_dir
58  action("$target_name$src") {
59    deps = _deps
60    script = "//build/lite/copy_files.py"
61    args = [
62      "--src_type",
63      src_type,
64      "--src",
65      rebase_path("$src"),
66      "--dest_dir",
67      rebase_path("$dst"),
68    ]
69    outputs = [ "$target_gen_dir/${target_name}_copy_files.log" ]
70  }
71}
72
73# Generate NDK library.
74template("ndk_lib") {
75  _deps = []
76  if (defined(invoker.deps)) {
77    _deps += invoker.deps
78  }
79
80  _head_files = []
81  if (defined(invoker.head_files)) {
82    _head_files = invoker.head_files
83  }
84  if (defined(invoker.lib_extension)) {
85    _extension = invoker.lib_extension
86  } else {
87    _extension = ".a"
88  }
89  assert(_extension != "")
90
91  group(target_name) {
92    deps = _deps
93  }
94
95  if (ohos_build_ndk) {
96    foreach(src_deps, _deps) {
97      lib_name = get_label_info(src_deps, "name")
98      copy_files("$target_name" + "_copy") {
99        deps = _deps
100        src_type = "file"
101        if (_extension == ".a") {
102          src = "$root_out_dir/libs/lib$lib_name$_extension"
103        } else {
104          src = "$root_out_dir/lib$lib_name$_extension"
105        }
106        dest_dir = "$ndk_libraries_out_dir"
107      }
108    }
109    foreach(src_dir, _head_files) {
110      copy_files(target_name) {
111        src = src_dir
112        dest_dir = "$ndk_headers_out_dir"
113      }
114    }
115  }
116}
117
118# Specify ndk toolchains
119#
120# Input variables:
121#   dest_dir: Copy destination where sources are copied to.
122#   src_dir: Copy Source directories.
123#   src_type: file or path
124#
125template("ndk_toolchains") {
126  assert(defined(invoker.src_dir) && defined(invoker.dest_dir),
127         "sources and dest_dir are necessary")
128
129  if (ohos_build_ndk) {
130    group(target_name) {
131    }
132    indexSrc = 0
133    indexDst = 0
134    foreach(src_dir, invoker.src_dir) {
135      indexDst = 0
136      foreach(dst, invoker.dest_dir) {
137        if (indexDst == indexSrc) {
138          copy_files("$src_dir") {
139            if (defined(invoker.src_type)) {
140              src_type = invoker.src_type
141            } else {
142              src_type = "dir"
143            }
144            src = src_dir
145            dest_dir = dst
146          }
147        }
148        indexDst = indexDst + 1
149      }
150      indexSrc = indexSrc + 1
151    }
152  }
153}
154