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