1# Copyright 2013 The Chromium Authors. All rights reserved. 2# Use of this source code is governed by a BSD-style license that can be 3# found in the LICENSE file. 4 5import("//build/config/clang/clang.gni") 6import("//build/config/ohos/config.gni") 7import("//build/toolchain/gcc_toolchain.gni") 8 9declare_args() { 10 # Whether unstripped binaries, i.e. compiled with debug symbols, should be 11 # considered runtime_deps rather than stripped ones. 12 ohos_unstripped_runtime_outputs = true 13 ohos_extra_cflags = "" 14 ohos_extra_cppflags = "" 15 ohos_extra_cxxflags = "" 16 ohos_extra_asmflags = "" 17 ohos_extra_ldflags = "" 18} 19 20# The ohos clang toolchains share most of the same parameters, so we have this 21# wrapper around gcc_toolchain to avoid duplication of logic. 22# 23# Parameters: 24# - toolchain_root 25# Path to cpu-specific toolchain within the ndk. 26# - sysroot 27# Sysroot for this architecture. 28# - lib_dir 29# Subdirectory inside of sysroot where libs go. 30# - binary_prefix 31# Prefix of compiler executables. 32template("ohos_clang_toolchain") { 33 gcc_toolchain(target_name) { 34 assert(defined(invoker.toolchain_args), 35 "toolchain_args must be defined for ohos_clang_toolchain()") 36 toolchain_args = invoker.toolchain_args 37 toolchain_args.current_os = "ohos" 38 39 # Output linker map files for binary size analysis. 40 enable_linker_map = true 41 42 ohos_libc_dir = 43 rebase_path(invoker.sysroot + "/" + invoker.lib_dir, root_build_dir) 44 libs_section_prefix = "${ohos_libc_dir}/Scrt1.o" 45 libs_section_prefix += " ${ohos_libc_dir}/crti.o" 46 libs_section_postfix = "${ohos_libc_dir}/crtn.o" 47 48 if (invoker.target_name == "ohos_clang_arm") { 49 abi_target = "arm-linux-ohos" 50 } else if (invoker.target_name == "ohos_clang_arm64") { 51 abi_target = "aarch64-linux-ohos" 52 } else if (invoker.target_name == "ohos_clang_x86_64") { 53 abi_target = "x86_64-linux-ohos" 54 } 55 56 clang_rt_dir = 57 rebase_path("${clang_lib_base_path}/${abi_target}", root_build_dir) 58 solink_libs_section_prefix = "${ohos_libc_dir}/crti.o" 59 solink_libs_section_prefix += " ${clang_rt_dir}/clang_rt.crtbegin.o" 60 solink_libs_section_postfix = "${ohos_libc_dir}/crtn.o" 61 solink_libs_section_postfix += " ${clang_rt_dir}/clang_rt.crtend.o" 62 63 _prefix = rebase_path("${clang_base_path}/bin", root_build_dir) 64 cc = "${_prefix}/clang" 65 cxx = "${_prefix}/clang++" 66 ar = "${_prefix}/llvm-ar" 67 ld = cxx 68 readelf = "${_prefix}/llvm-readobj" 69 nm = "${_prefix}/llvm-nm" 70 if (!is_debug) { 71 strip = rebase_path("${clang_base_path}/bin/llvm-strip", root_build_dir) 72 use_unstripped_as_runtime_outputs = ohos_unstripped_runtime_outputs 73 } 74 extra_cflags = ohos_extra_cflags 75 extra_cppflags = ohos_extra_cppflags 76 extra_cxxflags = ohos_extra_cxxflags 77 extra_asmflags = ohos_extra_asmflags 78 extra_ldflags = ohos_extra_ldflags 79 80 # Don't use .cr.so for loadable_modules since they are always loaded via 81 # absolute path. 82 loadable_module_extension = ".so" 83 } 84} 85