clang.gni 4.3 KB
Newer Older
M
mamingshuai 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
# Copyright (c) 2020 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

template("clang_toolchain") {
  toolchain(target_name) {
    assert(defined(invoker.cc), "clang toolchain must specify a \"cc\" value")
    assert(defined(invoker.cxx), "clang toolchain must specify a \"cxx\" value")
    assert(defined(invoker.ar), "clang toolchain must specify a \"ar\" value")
    assert(defined(invoker.ld), "clang toolchain must specify a \"ld\" value")

    cc = invoker.cc
    cxx = invoker.cxx
    ar = invoker.ar
    ld = invoker.ld

    need_strip = false
    if (defined(invoker.strip)) {
      strip = invoker.strip
      need_strip = true
    }

    tool("cc") {
      command = "$cc {{defines}} {{include_dirs}} {{cflags}} {{cflags_c}} -c {{source}} -o {{output}}"
      description = "clang {{output}}"
      outputs =
          [ "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o" ]
    }
    tool("cxx") {
      depfile = "{{output}}.d"
      command = "$cxx {{defines}} {{include_dirs}} {{cflags_cc}} -c {{source}} -o {{output}}"
      description = "clang++ {{output}}"
      outputs =
          [ "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o" ]
    }
    tool("asm") {
      depfile = "{{output}}.d"
      command = "$cc {{include_dirs}} {{asmflags}} -c {{source}} -o {{output}}"
      description = "ASM {{output}}"
      outputs =
          [ "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o" ]
    }
    tool("alink") {
      outfile = "{{output_dir}}/{{target_output_name}}{{output_extension}}"
      rspfile = "{{output}}.rsp"
      rspfile_content = "{{inputs}}"
      command = "$ar -cr {{output}} @\"$rspfile\""
      description = "AR {{output}}"
      outputs = [ outfile ]
      default_output_dir = "{{root_out_dir}}/libs"
      default_output_extension = ".a"
      output_prefix = "lib"
    }
    tool("solink") {
      outfile = "{{output_dir}}/{{target_output_name}}{{output_extension}}"
J
jady3356 已提交
65 66
      stripped_outfile = outfile

M
mamingshuai 已提交
67 68
      rspfile = "$outfile.rsp"
      rspfile_content = "{{inputs}}"
J
jady3356 已提交
69
      command = ""
M
mamingshuai 已提交
70
      if (need_strip) {
J
jady3356 已提交
71 72
        stripped_outfile = "{{output_dir}}/usr/lib/stripped/{{target_output_name}}{{output_extension}}"
        command += "mkdir -p {{output_dir}}/usr/lib/stripped && "
M
mamingshuai 已提交
73
      }
J
jady3356 已提交
74 75 76 77 78 79

      command += "$ld -shared {{ldflags}} {{inputs}} {{libs}} -o $outfile"
      if (need_strip) {
        command += " && $strip \"$outfile\" \"$stripped_outfile\""
      }

M
mamingshuai 已提交
80 81 82 83 84
      default_output_extension = ".so"
      description = "SOLINK $outfile"
      default_output_dir = "{{root_out_dir}}"
      output_prefix = "lib"
      outputs = [ outfile ]
J
jady3356 已提交
85 86 87
      if (stripped_outfile != outfile) {
        outputs += [ stripped_outfile ]
      }
M
mamingshuai 已提交
88 89 90
    }
    tool("link") {
      outfile = "{{output_dir}}/bin/{{target_output_name}}{{output_extension}}"
J
jady3356 已提交
91 92
      stripped_outfile = outfile

M
mamingshuai 已提交
93 94
      rspfile = "$outfile.rsp"
      custom_ld_flags = " "
J
jady3356 已提交
95 96 97 98 99 100
      command = ""
      if (need_strip) {
        stripped_outfile = "{{output_dir}}/bin/stripped/{{target_output_name}}{{output_extension}}"
        command += "mkdir -p {{output_dir}}/bin/stripped && "
      }
      command +=
M
mamingshuai 已提交
101 102
          "$cc {{ldflags}} {{inputs}} {{libs}} $custom_ld_flags -o $outfile"
      if (need_strip) {
J
jady3356 已提交
103
        command += " && $strip \"$outfile\" \"$stripped_outfile\""
M
mamingshuai 已提交
104 105 106 107 108 109
      }

      description = "LLVM LINK $outfile"
      default_output_dir = "{{root_out_dir}}"
      rspfile_content = "{{inputs}}"
      outputs = [ outfile ]
J
jady3356 已提交
110 111 112
      if (stripped_outfile != outfile) {
        outputs += [ stripped_outfile ]
      }
M
mamingshuai 已提交
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
    }
    tool("stamp") {
      if (host_os == "win") {
        command = "cmd /c type nul > \"{{output}}\""
      } else {
        command = "/usr/bin/touch {{output}}"
      }
      description = "STAMP {{output}}"
    }

    tool("copy") {
      command = "cp -afd {{source}} {{output}}"
      description = "COPY {{source}} {{output}}"
    }
  }
}