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
      unstripped_outfile = outfile
J
jady3356 已提交
66

M
mamingshuai 已提交
67 68
      rspfile = "$outfile.rsp"
      rspfile_content = "{{inputs}}"
J
jady3356 已提交
69
      command = ""
M
mamingshuai 已提交
70
      if (need_strip) {
J
jady3356 已提交
71
        unstripped_outfile = "{{output_dir}}/unstripped/usr/lib/{{target_output_name}}{{output_extension}}"
M
mamingshuai 已提交
72
      }
J
jady3356 已提交
73

J
jady3356 已提交
74
      command += "$ld -shared {{ldflags}} {{inputs}} {{libs}} -o $unstripped_outfile"
J
jady3356 已提交
75
      if (need_strip) {
J
jady3356 已提交
76
        command += " && $strip \"$unstripped_outfile\" \"$outfile\""
J
jady3356 已提交
77 78
      }

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

M
mamingshuai 已提交
92 93
      rspfile = "$outfile.rsp"
      custom_ld_flags = " "
J
jady3356 已提交
94 95
      command = ""
      if (need_strip) {
J
jady3356 已提交
96
        unstripped_outfile = "{{output_dir}}/unstripped/bin/{{target_output_name}}{{output_extension}}"
J
jady3356 已提交
97 98
      }
      command +=
C
Caoruihong 已提交
99
          "$ld {{ldflags}} {{inputs}} {{libs}} $custom_ld_flags -o $unstripped_outfile"
M
mamingshuai 已提交
100
      if (need_strip) {
J
jady3356 已提交
101
        command += " && $strip \"$unstripped_outfile\" \"$outfile\""
M
mamingshuai 已提交
102 103 104 105 106 107
      }

      description = "LLVM LINK $outfile"
      default_output_dir = "{{root_out_dir}}"
      rspfile_content = "{{inputs}}"
      outputs = [ outfile ]
J
jady3356 已提交
108 109
      if (unstripped_outfile != outfile) {
        outputs += [ unstripped_outfile ]
J
jady3356 已提交
110
      }
M
mamingshuai 已提交
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
    }
    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}}"
    }
  }
}