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") { 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 # copy C/C++ runtime libraries to lib out dir 71 if (ohos_build_compiler == "clang") { 72 runtime_libs = [ 73 "libc++.so", 74 "libc.so", 75 ] 76 compiler_cmd = "$ohos_current_cxx_command --target=$target_triple --sysroot=$sysroot_path $arch_cflags" 77 } else { 78 runtime_libs = [ 79 "libstdc++.so.6", 80 "libc.so", 81 "libgcc_s.so.1", 82 ] 83 compiler_cmd = 84 "$ohos_current_cxx_command --sysroot=$sysroot_path $arch_cflags" 85 } 86 87 libs = [] 88 outputs = [] 89 foreach(lib, runtime_libs) { 90 libs += [ "\$($compiler_cmd -print-file-name=$lib)" ] 91 outputs += [ "$root_out_dir/unstripped/usr/lib/$lib" ] 92 } 93 94 lib_out_dir = rebase_path("$root_out_dir/unstripped/usr/lib", exec_path) 95 command += " && mkdir -p $lib_out_dir && sh -c \"cp -f " + 96 string_join(" ", libs) + " $lib_out_dir\"" 97} 98 99action_foreach("strip") { 100 no_default_deps = true 101 deps = [ ":build_sysroot" ] 102 script = "//build/lite/run_shell_cmd.py" 103 set_sources_assignment_filter([ "*.txt" ]) 104 sources = get_target_outputs(deps[0]) 105 outputs = [ "$root_out_dir/libs/{{source_file_part}}" ] 106 args = [ 107 "$ohos_current_strip_command", 108 "{{source}}", 109 "-o", 110 rebase_path("$root_out_dir/libs/{{source_file_part}}", root_build_dir), 111 ] 112} 113 114config("sysroot_flags") { 115 if (ohos_build_compiler == "clang") { 116 cflags = [ 117 "--target=$target_triple", 118 "--sysroot=$sysroot_path", 119 ] 120 } else { 121 cflags = [ 122 "--sysroot=$sysroot_path", 123 "-specs=musl-gcc.specs", 124 ] 125 } 126 cflags_cc = cflags 127 ldflags = cflags 128 asmflags = cflags 129} 130 131group("build") { 132 all_dependent_configs = [ ":sysroot_flags" ] 133 deps = [ 134 ":build_sysroot", 135 ":strip", 136 ] 137} 138