• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
2# Copyright (c) 2020-2022 Huawei Device Co., Ltd. All rights reserved.
3#
4# Redistribution and use in source and binary forms, with or without modification,
5# are permitted provided that the following conditions are met:
6#
7# 1. Redistributions of source code must retain the above copyright notice, this list of
8#    conditions and the following disclaimer.
9#
10# 2. Redistributions in binary form must reproduce the above copyright notice, this list
11#    of conditions and the following disclaimer in the documentation and/or other materials
12#    provided with the distribution.
13#
14# 3. Neither the name of the copyright holder nor the names of its contributors may be used
15#    to endorse or promote products derived from this software without specific prior written
16#    permission.
17#
18# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
20# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
22# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
30import("//build/lite/config/component/lite_component.gni")
31
32targets = ""
33if (ohos_kernel_type == "liteos_a") {
34  targets = "liteos_a_user"
35} else if (ohos_kernel_type == "linux") {
36  targets = "linux_user"
37}
38
39assert(targets != "", "Unsupported ohos_kernel_type: $ohos_kernel_type")
40
41sysroot_path = rebase_path(ohos_current_sysroot)
42arch_cflags = string_join(" ", target_arch_cflags)
43
44build_ext_component("build_sysroot") {
45  no_default_deps = true
46  deps = []
47  exec_path = rebase_path(target_out_dir)
48  if (!defined(board_configed_sysroot) || board_configed_sysroot == "") {
49    makefile = rebase_path("Makefile", exec_path)
50    command = "make TOPDIR=$ohos_root_path SYSROOTDIR=$sysroot_path TARGETS=$targets -f $makefile"
51    command += " ARCH=$arch ARCH_CFLAGS=\"$arch_cflags\""
52    if (ohos_build_compiler == "clang") {
53      command += " CLANG=\"$ohos_current_cc_command\" TARGET=$target_triple"
54    } else {
55      command += " GCC=\"$ohos_current_cc_command\""
56    }
57    if (ohos_build_type == "debug" && !is_llvm_build) {
58      command += " BUILD_DEBUG=true"
59    }
60    if (ohos_kernel_type == "linux") {
61      deps += [ "//kernel/linux/build:linux_kernel" ]
62      command += " LINUXDIR=" + rebase_path("$root_out_dir/kernel/linux-4.19")
63      command += " PREBUILTLINUXHDRDIR=" + rebase_path(
64                     "//kernel/linux/patches/linux-4.19/prebuilts/usr/include")
65    }
66  } else {
67    command = "true"
68  }
69
70  if (!is_llvm_build) {
71    # copy C/C++ runtime libraries to lib out dir
72    if (ohos_build_compiler == "clang") {
73      runtime_libs = [
74        "libc++.so",
75        "libc.so",
76      ]
77      compiler_cmd = "$ohos_current_cxx_command --target=$target_triple --sysroot=$sysroot_path $arch_cflags"
78    } else {
79      runtime_libs = [
80        "libstdc++.so.6",
81        "libc.so",
82        "libgcc_s.so.1",
83      ]
84      compiler_cmd =
85          "$ohos_current_cxx_command --sysroot=$sysroot_path $arch_cflags"
86    }
87
88    libs = []
89    outputs = []
90    foreach(lib, runtime_libs) {
91      libs += [ "\$($compiler_cmd -print-file-name=$lib)" ]
92      outputs += [ "$root_out_dir/unstripped/usr/lib/$lib" ]
93    }
94
95    lib_out_dir = rebase_path("$root_out_dir/unstripped/usr/lib", exec_path)
96    command += " && mkdir -p $lib_out_dir && sh -c \"cp -f " +
97               string_join(" ", libs) + " $lib_out_dir\""
98  }
99}
100
101build_ext_component("build_sysroot_header") {
102  no_default_deps = true
103  deps = []
104  exec_path = rebase_path(target_out_dir)
105  if (!defined(board_configed_sysroot) || board_configed_sysroot == "") {
106    makefile = rebase_path("Makefile", exec_path)
107    command = "make musl_header_install_for_liteos_a_user TOPDIR=$ohos_root_path SYSROOTDIR=$sysroot_path TARGETS=$targets -f $makefile"
108    command += " ARCH=$arch ARCH_CFLAGS=\"$arch_cflags\""
109    if (ohos_build_compiler == "clang") {
110      command += " CLANG=\"$ohos_current_cc_command\" TARGET=$target_triple"
111    } else {
112      command += " GCC=\"$ohos_current_cc_command\""
113    }
114    if (ohos_build_type == "debug" && !is_llvm_build) {
115      command += " BUILD_DEBUG=true"
116    }
117    if (ohos_kernel_type == "linux") {
118      deps += [ "//kernel/linux/build:linux_kernel" ]
119      command += " LINUXDIR=" + rebase_path("$root_out_dir/kernel/linux-4.19")
120      command += " PREBUILTLINUXHDRDIR=" + rebase_path(
121                     "//kernel/linux/patches/linux-4.19/prebuilts/usr/include")
122    }
123  } else {
124    command = "true"
125  }
126}
127
128if (!is_llvm_build) {
129  action_foreach("strip") {
130    no_default_deps = true
131    deps = [ ":build_sysroot" ]
132    script = "//build/lite/run_shell_cmd.py"
133    sources_raw = get_target_outputs(deps[0])
134    sources = filter_exclude(sources_raw, [ "*.txt" ])
135    outputs = [ "$root_out_dir/libs/{{source_file_part}}" ]
136    args = [
137      "$ohos_current_strip_command",
138      "{{source}}",
139      "-o",
140      rebase_path("$root_out_dir/libs/{{source_file_part}}", root_build_dir),
141    ]
142  }
143}
144
145config("sysroot_flags") {
146  if (ohos_build_compiler == "clang") {
147    cflags = [
148      "--target=$target_triple",
149      "--sysroot=$sysroot_path",
150    ]
151  } else {
152    cflags = [
153      "--sysroot=$sysroot_path",
154      "-specs=musl-gcc.specs",
155    ]
156  }
157  cflags_cc = cflags
158  ldflags = cflags
159  asmflags = cflags
160}
161
162group("build") {
163  all_dependent_configs = [ ":sysroot_flags" ]
164  deps = [ ":build_sysroot" ]
165  if (!is_llvm_build) {
166    deps += [ ":strip" ]
167  }
168}
169