summaryrefslogtreecommitdiff
path: root/chromium/build/linux/unbundle/yasm.gn
blob: b5b440e66faf5e6eb00bdadf5b4c6cfa3d23b2d1 (plain)
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# Copyright 2016 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

if (current_cpu == "x86") {
  _yasm_flags = [
    "-felf32",
    "-m",
    "x86",
  ]
} else if (current_cpu == "x64") {
  _yasm_flags = [
    "-DPIC",
    "-felf64",
    "-m",
    "amd64",
  ]
}

template("yasm_assemble") {
  action_name = "${target_name}_action"
  source_set_name = target_name

  action_foreach(action_name) {
    # Only the source set can depend on this.
    visibility = [ ":$source_set_name" ]

    script = "//third_party/yasm/run_yasm.py"
    sources = invoker.sources

    if (defined(invoker.inputs)) {
      inputs = invoker.inputs
    }

    deps = []
    if (defined(invoker.deps)) {
      deps += invoker.deps
    }

    args = [ "yasm" ] + _yasm_flags
    if (defined(invoker.yasm_flags)) {
      args += invoker.yasm_flags
    }

    # User defined include dirs go first.
    if (defined(invoker.include_dirs)) {
      foreach(include, invoker.include_dirs) {
        args += [ "-I" + rebase_path(include, root_build_dir) ]
      }
    }

    # Default yasm include dirs. Make it match the native build (source root and
    # root generated code directory).
    # This goes to the end of include list.
    args += [
      "-I.",

      # Using "//." will produce a relative path "../.." which looks better than
      # "../../" which will result from using "//" as the base (although both
      # work). This is because rebase_path will terminate the result in a
      # slash if the input ends in a slash.
      "-I" + rebase_path("//.", root_build_dir),
      "-I" + rebase_path(root_gen_dir, root_build_dir),
    ]

    # Extra defines.
    if (defined(invoker.defines)) {
      foreach(def, invoker.defines) {
        args += [ "-D$def" ]
      }
    }

    # Output file.
    outputs = [
      "$target_out_dir/$source_set_name/{{source_name_part}}.o",
    ]
    args += [
      "-o",
      rebase_path(outputs[0], root_build_dir),
      "{{source}}",
    ]

    # The wrapper script run_yasm will write the depfile to the same name as
    # the output but with .d appended (like gcc will).
    depfile = outputs[0] + ".d"
  }

  # Gather the .o files into a linkable thing. This doesn't actually link
  # anything (a source set just compiles files to link later), but will pass
  # the object files generated by the action up the dependency chain.
  static_library(source_set_name) {
    if (defined(invoker.visibility)) {
      visibility = invoker.visibility
    }

    sources = get_target_outputs(":$action_name")

    deps = [
      ":$action_name",
    ]
  }
}