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. 13import("//build/lite/ohos_var.gni") 14import("${device_path}/config.gni") 15 16if (target_os == "") { 17 target_os = "ohos" 18} 19 20if (target_cpu == "") { 21 target_cpu = board_cpu 22} 23 24target_arch_cflags = board_cflags 25if (board_arch != "") { 26 target_arch_cflags += [ "-march=$board_arch" ] 27} 28if (board_cpu != "") { 29 target_arch_cflags += [ "-mcpu=$board_cpu" ] 30} 31 32arch = "arm" 33if (ohos_kernel_type == "liteos_a") { 34 target_triple = "$arch-liteos-ohos" 35} else if (ohos_kernel_type == "linux") { 36 target_triple = "$arch-linux-ohos" 37} 38 39if (defined(board_configed_sysroot) && board_configed_sysroot != "") { 40 ohos_current_sysroot = board_configed_sysroot 41} 42 43# Only gcc available for liteos_m. 44if (ohos_kernel_type == "liteos_m" || ohos_kernel_type == "uniproton" || 45 ohos_kernel_type == "linux") { 46 use_board_toolchain = true 47} 48 49toolchain_cmd_suffix = "" 50if (host_os == "win") { 51 toolchain_cmd_suffix = ".exe" 52} 53 54# enable ccache if ccache installed. 55if (ohos_build_enable_ccache) { 56 compile_prefix = "ccache " 57} else { 58 compile_prefix = "" 59} 60 61# Load board adapter dir from board config. 62if (board_adapter_dir != "") { 63 ohos_board_adapter_dir = board_adapter_dir 64 ohos_vendor_adapter_dir = board_adapter_dir 65} 66 67# Set current toolchain with to board configuration. 68if (board_toolchain != "" && use_board_toolchain) { 69 ohos_build_compiler = board_toolchain_type 70 if (board_toolchain_path != "") { 71 compile_prefix += "${board_toolchain_path}/${board_toolchain_prefix}" 72 } else { 73 compile_prefix += "${board_toolchain_prefix}" 74 } 75 set_default_toolchain("//build/lite/toolchain:${board_toolchain}") 76 if (board_toolchain_type == "gcc") { 77 ohos_current_cc_command = "${compile_prefix}gcc$toolchain_cmd_suffix" 78 ohos_current_cxx_command = "${compile_prefix}g++$toolchain_cmd_suffix" 79 ohos_current_ar_command = "${compile_prefix}ar$toolchain_cmd_suffix" 80 ohos_current_ld_command = ohos_current_cc_command 81 ohos_current_strip_command = 82 "${compile_prefix}strip$toolchain_cmd_suffix --strip-unneeded" 83 default_target_configs = [ "//build/lite/config:gcc_opt" ] 84 } else if (board_toolchain_type == "clang") { 85 ohos_current_cc_command = "${compile_prefix}clang$toolchain_cmd_suffix" 86 ohos_current_cxx_command = "${compile_prefix}clang++$toolchain_cmd_suffix" 87 compile_prefix += "llvm-" 88 ohos_current_ar_command = "${compile_prefix}ar$toolchain_cmd_suffix" 89 ohos_current_ld_command = ohos_current_cc_command 90 ohos_current_strip_command = 91 "${compile_prefix}strip$toolchain_cmd_suffix --strip-unneeded" 92 default_target_configs = [ "//build/lite/config:clang_opt" ] 93 } else if (board_toolchain_type == "iccarm") { 94 ohos_current_cc_command = "${compile_prefix}iccarm$toolchain_cmd_suffix" 95 ohos_current_cxx_command = "${compile_prefix}iccarm$toolchain_cmd_suffix" 96 ohos_current_ar_command = "${compile_prefix}iarchive$toolchain_cmd_suffix" 97 ohos_current_as_command = "${compile_prefix}iasmarm$toolchain_cmd_suffix" 98 ohos_current_ld_command = "${compile_prefix}ilinkarm$toolchain_cmd_suffix" 99 } 100 101 # Overwrite ld cmd by customed cmd. 102 if (defined(board_customed_ld_cmd) && board_customed_ld_cmd != "") { 103 ohos_current_ld_command = board_customed_ld_cmd 104 } 105} else { 106 # OHOS default toolchain 107 ohos_build_compiler = "clang" 108 ohos_clang_toolchain_dir = rebase_path("${ohos_build_compiler_dir}/bin") 109 compile_prefix += "$ohos_clang_toolchain_dir/" 110 ohos_current_cc_command = "${compile_prefix}clang$toolchain_cmd_suffix" 111 ohos_current_cxx_command = "${compile_prefix}clang++$toolchain_cmd_suffix" 112 compile_prefix += "llvm-" 113 ohos_current_ar_command = "${compile_prefix}ar$toolchain_cmd_suffix" 114 ohos_current_ld_command = ohos_current_cxx_command 115 ohos_current_strip_command = 116 "${compile_prefix}strip$toolchain_cmd_suffix --strip-unneeded" 117 set_default_toolchain("//build/lite/toolchain:linux_x86_64_ohos_clang") 118 default_target_configs = [ "//build/lite/config:ohos_clang" ] 119 default_target_configs += [ "//build/lite/config:clang_opt" ] 120} 121 122if (board_toolchain_type != "iccarm") { 123 default_target_configs += [ 124 "//build/lite/config:board_config", 125 "//build/lite/config:cpu_arch", 126 "//build/lite/config:common", 127 "//build/lite/config:default_link_path", 128 "//build/lite/config:language_c", 129 "//build/lite/config:language_cpp", 130 "//build/lite/config:kernel_macros", 131 ] 132 if (ohos_build_type == "debug") { 133 default_target_configs += [ "//build/lite/config:debug" ] 134 } else if (ohos_build_type == "release") { 135 default_target_configs += [ "//build/lite/config:release" ] 136 } 137 138 if (ohos_kernel_type == "liteos_m") { 139 default_target_configs += [ "//build/lite/config:stack_protector" ] 140 } 141} 142 143if (ohos_kernel_type == "liteos_a") { 144 default_target_configs += 145 [ "//build/lite/config/kernel/liteos/cortex_a:default" ] 146} 147 148if (ohos_kernel_type == "liteos_a" || ohos_kernel_type == "linux") { 149 default_target_configs += [ 150 "//build/lite/config:security", 151 "//build/lite/config:exceptions", 152 ] 153} 154default_shared_library_configs = 155 default_target_configs + [ "//build/lite/config:shared_library_config" ] 156default_static_library_configs = default_target_configs 157default_executable_configs = default_static_library_configs 158if (ohos_kernel_type != "liteos_m" && ohos_kernel_type != "uniproton") { 159 default_static_library_configs += [ "//build/lite/config:static_pie_config" ] 160 default_executable_configs += [ "//build/lite/config:static_pie_config" ] 161 default_executable_configs += [ "//build/lite/config:pie_executable_config" ] 162} 163 164set_defaults("executable") { 165 configs = default_executable_configs 166 configs += [ "//build/lite/config:board_exe_ld_flags" ] 167} 168 169set_defaults("static_library") { 170 configs = default_static_library_configs 171} 172 173set_defaults("shared_library") { 174 configs = default_shared_library_configs 175} 176 177set_defaults("source_set") { 178 configs = default_target_configs 179} 180 181_target_type_list = [ 182 "executable", 183 "static_library", 184 "shared_library", 185 "source_set", 186 "action", 187 "action_foreach", 188] 189 190foreach(_target_type, _target_type_list) { 191 template(_target_type) { 192 target(_target_type, target_name) { 193 forward_variables_from(invoker, "*", [ "no_default_deps" ]) 194 if (!defined(deps)) { 195 deps = [] 196 } 197 if (!defined(invoker.no_default_deps) || !invoker.no_default_deps) { 198 deps += [ "//build/lite:prebuilts" ] 199 } 200 } 201 } 202} 203