summaryrefslogtreecommitdiffstats
path: root/third_party/yasm
diff options
context:
space:
mode:
authorbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-06-12 19:35:55 +0000
committerbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-06-12 19:35:55 +0000
commit137dff6d1b1817fd06a9c77e9b1b1ac0cf3f5edc (patch)
treea91539972e02086439f91f687965c789c513e247 /third_party/yasm
parent53c4f9359cad05bc6be3051867b6dbc886a65280 (diff)
downloadchromium_src-137dff6d1b1817fd06a9c77e9b1b1ac0cf3f5edc.zip
chromium_src-137dff6d1b1817fd06a9c77e9b1b1ac0cf3f5edc.tar.gz
chromium_src-137dff6d1b1817fd06a9c77e9b1b1ac0cf3f5edc.tar.bz2
Add yasm to the GN build.
This is forked off of https://codereview.chromium.org/266613002 The code to compile yasm itself is mostly from that patch, with a few updates for the other changes. Adds a template for running compiled binaries. Compared to Albert's patch above, this assumes the binary is generated by the source tree so can have a cleaner interface (just specify the label of the tool you use). The yasm rule is new compared to Albert's patch. It uses a special wrapper script instead of the new compiled_action templates so it can properly support depfiles. This also adds convenient support for defines and include dirs. This adds some trivial ios changes to the content/public/browser. This should be a NOP now. Fixes a bug in GN depfile creation. Previously, the .d file was emitted as an output of the script, but this confuses ninja. This change just removes that. BUG= R=ajwong@chromium.org Review URL: https://codereview.chromium.org/321323004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@276772 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'third_party/yasm')
-rw-r--r--third_party/yasm/BUILD.gn402
-rw-r--r--third_party/yasm/run_yasm.py51
-rw-r--r--third_party/yasm/yasm_assemble.gni185
3 files changed, 638 insertions, 0 deletions
diff --git a/third_party/yasm/BUILD.gn b/third_party/yasm/BUILD.gn
new file mode 100644
index 0000000..7fd3065
--- /dev/null
+++ b/third_party/yasm/BUILD.gn
@@ -0,0 +1,402 @@
+# Copyright 2014 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.
+
+# The yasm build process creates a slew of small C subprograms that
+# dynamically generate files at various point in the build process. This makes
+# the build integration moderately complex.
+#
+# There are three classes of dynamically generated files:
+# 1) C source files that should be included in the build (eg., lc3bid.c)
+# 2) C source files that are #included by static C sources (eg., license.c)
+# 3) Intermediate files that are used as input by other subprograms to
+# further generate files in category #1 or #2. (eg., version.mac)
+#
+# This structure is represented with the following targets:
+# 1) yasm -- Sources, flags for the main yasm executable. Also has most of
+# of the actions and rules that invoke the subprograms.
+# 2) yasm_config -- General build configuration including setting a
+# source_prereqs listing the checked in version of files
+# generated by manually running configure. These manually
+# generated files are used by all binaries.
+# 3) yasm_utils -- Object files with memory management and hashing utilities
+# shared between yasm and the genperf subprogram.
+# 4) genmacro, genmodule, etc. -- One executable target for each subprogram.
+# 5) generate_license, generate_module, etc. -- Actions that invoke programs
+# built in #4 to generate .c files.
+# 6) compile_gperf, compile_re2c, etc. -- Actions that invoke programs that
+# turn intermediate files into .c files.
+
+if (default_toolchain == host_toolchain) {
+
+ # Various files referenced by multiple targets.
+ yasm_gen_include_dir = "$target_gen_dir/include"
+ config_makefile = "source/config/$os/Makefile"
+ version_file = "version.mac"
+
+ import("//build/compiled_action.gni")
+
+ config("yasm_config") {
+ include_dirs = [
+ "source/config/$os",
+ "source/patched-yasm",
+ ]
+ source_prereqs = [
+ config_makefile,
+ "source/config/$os/config.h",
+ "source/config/$os/libyasm-stdint.h",
+ ]
+ defines = [ "HAVE_CONFIG_H" ]
+ cflags = [ "-std=gnu99" ]
+ }
+
+ executable("genmacro") {
+ sources = [ "source/patched-yasm/tools/genmacro/genmacro.c" ]
+ configs -= [ "//build/config/compiler:chromium_code" ]
+ configs += [ ":yasm_config",
+ "//build/config/compiler:no_chromium_code" ]
+ }
+
+ executable("genmodule") {
+ sources = [ "source/patched-yasm/libyasm/genmodule.c" ]
+ configs -= [ "//build/config/compiler:chromium_code" ]
+ configs += [ ":yasm_config",
+ "//build/config/compiler:no_chromium_code" ]
+ }
+
+ executable("genperf") {
+ sources = [
+ "source/patched-yasm/tools/genperf/genperf.c",
+ "source/patched-yasm/tools/genperf/perfect.c",
+ ]
+
+ configs -= [ "//build/config/compiler:chromium_code" ]
+ configs += [ ":yasm_config",
+ "//build/config/compiler:no_chromium_code" ]
+
+ deps = [ ":yasm_utils" ]
+ }
+
+ # Used by both yasm and genperf binaries.
+ source_set("yasm_utils") {
+ sources = [
+ "source/patched-yasm/libyasm/phash.c",
+ "source/patched-yasm/libyasm/xmalloc.c",
+ "source/patched-yasm/libyasm/xstrdup.c",
+ ]
+
+ configs -= [ "//build/config/compiler:chromium_code" ]
+ configs += [ ":yasm_config",
+ "//build/config/compiler:no_chromium_code" ]
+ }
+
+ executable("genstring") {
+ sources = [ "source/patched-yasm/genstring.c", ]
+ configs -= [ "//build/config/compiler:chromium_code" ]
+ configs += [ ":yasm_config",
+ "//build/config/compiler:no_chromium_code" ]
+ }
+
+ executable("genversion") {
+ sources = [ "source/patched-yasm/modules/preprocs/nasm/genversion.c" ]
+ configs -= [ "//build/config/compiler:chromium_code" ]
+ configs += [ ":yasm_config",
+ "//build/config/compiler:no_chromium_code" ]
+ }
+
+ executable("re2c") {
+ sources = [
+ "source/patched-yasm/tools/re2c/main.c",
+ "source/patched-yasm/tools/re2c/code.c",
+ "source/patched-yasm/tools/re2c/dfa.c",
+ "source/patched-yasm/tools/re2c/parser.c",
+ "source/patched-yasm/tools/re2c/actions.c",
+ "source/patched-yasm/tools/re2c/scanner.c",
+ "source/patched-yasm/tools/re2c/mbo_getopt.c",
+ "source/patched-yasm/tools/re2c/substr.c",
+ "source/patched-yasm/tools/re2c/translate.c",
+ ]
+
+ configs -= [ "//build/config/compiler:chromium_code" ]
+ configs += [ ":yasm_config",
+ "//build/config/compiler:no_chromium_code" ]
+
+ # re2c is missing CLOSEVOP from one switch.
+ cflags = [ "-Wno-switch" ]
+ }
+
+ executable("yasm") {
+ sources = [
+ "source/patched-yasm/frontends/yasm/yasm-options.c",
+ "source/patched-yasm/frontends/yasm/yasm.c",
+ "source/patched-yasm/libyasm/assocdat.c",
+ "source/patched-yasm/libyasm/bc-align.c",
+ "source/patched-yasm/libyasm/bc-data.c",
+ "source/patched-yasm/libyasm/bc-incbin.c",
+ "source/patched-yasm/libyasm/bc-org.c",
+ "source/patched-yasm/libyasm/bc-reserve.c",
+ "source/patched-yasm/libyasm/bitvect.c",
+ "source/patched-yasm/libyasm/bytecode.c",
+ "source/patched-yasm/libyasm/errwarn.c",
+ "source/patched-yasm/libyasm/expr.c",
+ "source/patched-yasm/libyasm/file.c",
+ "source/patched-yasm/libyasm/floatnum.c",
+ "source/patched-yasm/libyasm/hamt.c",
+ "source/patched-yasm/libyasm/insn.c",
+ "source/patched-yasm/libyasm/intnum.c",
+ "source/patched-yasm/libyasm/inttree.c",
+ "source/patched-yasm/libyasm/linemap.c",
+ "source/patched-yasm/libyasm/md5.c",
+ "source/patched-yasm/libyasm/mergesort.c",
+ "source/patched-yasm/libyasm/section.c",
+ "source/patched-yasm/libyasm/strcasecmp.c",
+ "source/patched-yasm/libyasm/strsep.c",
+ "source/patched-yasm/libyasm/symrec.c",
+ "source/patched-yasm/libyasm/valparam.c",
+ "source/patched-yasm/libyasm/value.c",
+ "source/patched-yasm/modules/arch/lc3b/lc3barch.c",
+ "source/patched-yasm/modules/arch/lc3b/lc3bbc.c",
+ "source/patched-yasm/modules/arch/x86/x86arch.c",
+ "source/patched-yasm/modules/arch/x86/x86bc.c",
+ "source/patched-yasm/modules/arch/x86/x86expr.c",
+ "source/patched-yasm/modules/arch/x86/x86id.c",
+ "source/patched-yasm/modules/dbgfmts/codeview/cv-dbgfmt.c",
+ "source/patched-yasm/modules/dbgfmts/codeview/cv-symline.c",
+ "source/patched-yasm/modules/dbgfmts/codeview/cv-type.c",
+ "source/patched-yasm/modules/dbgfmts/dwarf2/dwarf2-aranges.c",
+ "source/patched-yasm/modules/dbgfmts/dwarf2/dwarf2-dbgfmt.c",
+ "source/patched-yasm/modules/dbgfmts/dwarf2/dwarf2-info.c",
+ "source/patched-yasm/modules/dbgfmts/dwarf2/dwarf2-line.c",
+ "source/patched-yasm/modules/dbgfmts/null/null-dbgfmt.c",
+ "source/patched-yasm/modules/dbgfmts/stabs/stabs-dbgfmt.c",
+ "source/patched-yasm/modules/listfmts/nasm/nasm-listfmt.c",
+ "source/patched-yasm/modules/objfmts/bin/bin-objfmt.c",
+ "source/patched-yasm/modules/objfmts/coff/coff-objfmt.c",
+ "source/patched-yasm/modules/objfmts/coff/win64-except.c",
+ "source/patched-yasm/modules/objfmts/dbg/dbg-objfmt.c",
+ "source/patched-yasm/modules/objfmts/elf/elf-objfmt.c",
+ "source/patched-yasm/modules/objfmts/elf/elf-x86-amd64.c",
+ "source/patched-yasm/modules/objfmts/elf/elf-x86-x86.c",
+ "source/patched-yasm/modules/objfmts/elf/elf.c",
+ "source/patched-yasm/modules/objfmts/macho/macho-objfmt.c",
+ "source/patched-yasm/modules/objfmts/rdf/rdf-objfmt.c",
+ "source/patched-yasm/modules/objfmts/xdf/xdf-objfmt.c",
+ "source/patched-yasm/modules/parsers/gas/gas-parse.c",
+ "source/patched-yasm/modules/parsers/gas/gas-parse-intel.c",
+ "source/patched-yasm/modules/parsers/gas/gas-parser.c",
+ "source/patched-yasm/modules/parsers/nasm/nasm-parse.c",
+ "source/patched-yasm/modules/parsers/nasm/nasm-parser.c",
+ "source/patched-yasm/modules/preprocs/cpp/cpp-preproc.c",
+ "source/patched-yasm/modules/preprocs/nasm/nasm-eval.c",
+ "source/patched-yasm/modules/preprocs/nasm/nasm-pp.c",
+ "source/patched-yasm/modules/preprocs/nasm/nasm-preproc.c",
+ "source/patched-yasm/modules/preprocs/nasm/nasmlib.c",
+ "source/patched-yasm/modules/preprocs/raw/raw-preproc.c",
+
+ # Files generated by compile_gperf
+ "$target_gen_dir/x86cpu.c",
+ "$target_gen_dir/x86regtmod.c",
+
+ # Files generated by compile_re2c
+ "$target_gen_dir/gas-token.c",
+ "$target_gen_dir/nasm-token.c",
+
+ # File generated by compile_re2c_lc3b
+ "$target_gen_dir/lc3bid.c",
+
+ # File generated by generate_module
+ "$target_gen_dir/module.c"
+ ]
+
+ configs -= [ "//build/config/compiler:chromium_code" ]
+ configs += [ ":yasm_config",
+ "//build/config/compiler:no_chromium_code" ]
+
+ # Yasm generates a bunch of .c files which its source file #include.
+ # Add the |target_gen_dir| into the include path so it can find them.
+ # Ideally, these generated .c files would be placed into a separate
+ # directory, but the gen_x86_insn.py script does not make this easy.
+ include_dirs = [ yasm_gen_include_dir ]
+
+ cflags = [ "-ansi", "-pedantic" ]
+ if (is_clang) {
+ cflags += [ "-Wno-incompatible-pointer-types" ]
+ }
+
+ # TODO(ajwong): This should take most of the generated output as
+ # source_prereqs.
+ deps = [
+ ":compile_gperf",
+ ":compile_gperf_for_include",
+ ":compile_nasm_macros",
+ ":compile_nasm_version",
+ ":compile_win64_gas",
+ ":compile_win64_nasm",
+ ":compile_re2c",
+ ":generate_license",
+ ":generate_module",
+ ":generate_version",
+ ":yasm_utils",
+ ]
+ }
+
+ compiled_action_foreach("compile_gperf") {
+ tool = ":genperf"
+ sources = [
+ "source/patched-yasm/modules/arch/x86/x86cpu.gperf",
+ "source/patched-yasm/modules/arch/x86/x86regtmod.gperf",
+ ]
+
+ outputs = [ "$target_gen_dir/{{source_name_part}}.c" ]
+ args = [
+ "{{source}}",
+ rebase_path(target_gen_dir, ".") + "/{{source_name_part}}.c",
+ ]
+ deps = [
+ ":generate_x86_insn"
+ ]
+ }
+
+ # This differs from |compile_gperf| in where it places it output files.
+ compiled_action_foreach("compile_gperf_for_include") {
+ tool = ":genperf"
+ sources = [
+ # Make sure the generated gperf files in $target_gen_dir are synced with
+ # the outputs for the related generate_*_insn actions in the
+ # generate_files target below.
+ #
+ # The output for these two are #included by
+ # source/patched-yasm/modules/arch/x86/x86id.c
+ "$yasm_gen_include_dir/x86insn_gas.gperf",
+ "$yasm_gen_include_dir/x86insn_nasm.gperf",
+ ]
+
+ outputs = [ "$yasm_gen_include_dir/{{source_name_part}}.c" ]
+ args = [
+ "{{source}}",
+ rebase_path(yasm_gen_include_dir, ".") + "/{{source_name_part}}.c",
+ ]
+ deps = [
+ ":generate_x86_insn"
+ ]
+ }
+
+ template("compile_macro") {
+ compiled_action(target_name) {
+ tool = ":genmacro"
+ # Output #included by source/patched-yasm/frontends/yasm/yasm.c.
+ sources = invoker.sources
+ outputs = invoker.outputs
+ args = [
+ rebase_path(outputs[0], root_build_dir),
+ invoker.macro_varname,
+ rebase_path(sources[0], root_build_dir),
+ ]
+ if (defined(invoker.deps)) {
+ deps = invoker.deps
+ }
+ }
+ }
+
+ compile_macro("compile_nasm_macros") {
+ # Output #included by
+ # source/patched-yasm/modules/preprocs/nasm/nasm-parser.c
+ sources = [ "source/patched-yasm/modules/parsers/nasm/nasm-std.mac" ]
+ outputs = [ "$yasm_gen_include_dir/nasm-macros.c" ]
+ macro_varname = "nasm_standard_mac"
+ }
+
+ compile_macro("compile_nasm_version") {
+ # Output #included by
+ # source/patched-yasm/modules/preprocs/nasm/nasm-preproc.c
+ sources = [ "$target_gen_dir/$version_file" ]
+ outputs = [ "$yasm_gen_include_dir/nasm-version.c" ]
+ macro_varname = "nasm_version_mac"
+ deps = [ ":generate_version" ]
+ }
+
+ compile_macro("compile_win64_gas") {
+ # Output #included by source/patched-yasm/frontends/yasm/yasm.c.
+ sources = [ "source/patched-yasm/modules/objfmts/coff/win64-gas.mac" ]
+ outputs = [ "$yasm_gen_include_dir/win64-gas.c" ]
+ macro_varname = "win64_gas_stdmac"
+ }
+
+ compile_macro("compile_win64_nasm") {
+ # Output #included by source/patched-yasm/frontends/yasm/yasm.c.
+ sources = [ "source/patched-yasm/modules/objfmts/coff/win64-nasm.mac" ]
+ outputs = [ "$yasm_gen_include_dir/win64-nasm.c" ]
+ macro_varname = "win64_nasm_stdmac"
+ }
+
+ compiled_action_foreach("compile_re2c") {
+ tool = ":re2c"
+ sources = [
+ "source/patched-yasm/modules/parsers/gas/gas-token.re",
+ "source/patched-yasm/modules/parsers/nasm/nasm-token.re",
+ ]
+ outputs = [ "$target_gen_dir/{{source_name_part}}.c" ]
+ args = [
+ "-b",
+ "-o",
+ rebase_path(target_gen_dir, ".") + "/{{source_name_part}}.c",
+ "{{source}}",
+ ]
+ }
+
+ # This call doesn't fit into the re2c template above.
+ compiled_action("compile_re2c_lc3b") {
+ tool = ":re2c"
+ sources = [ "source/patched-yasm/modules/arch/lc3b/lc3bid.re" ]
+ outputs = [ "$target_gen_dir/lc3bid.c" ]
+ args = [
+ "-s",
+ "-o",
+ rebase_path(outputs[0], root_build_dir),
+ rebase_path(sources[0], root_build_dir),
+ ]
+ }
+
+ compiled_action("generate_license") {
+ tool = ":genstring"
+ # Output #included by source/patched-yasm/frontends/yasm/yasm.c.
+ sources = [ "source/patched-yasm/COPYING" ]
+ outputs = [ "$yasm_gen_include_dir/license.c" ]
+ args = [
+ "license_msg",
+ rebase_path(outputs[0], root_build_dir),
+ rebase_path(sources[0], root_build_dir),
+ ]
+ }
+
+ compiled_action("generate_module") {
+ tool = ":genmodule"
+ sources = [ "source/patched-yasm/libyasm/module.in" ]
+ outputs = [ "$target_gen_dir/module.c" ]
+ args = [
+ rebase_path(sources[0], root_build_dir),
+ rebase_path(config_makefile, root_build_dir),
+ rebase_path(outputs[0], root_build_dir),
+ ]
+ }
+
+ compiled_action("generate_version") {
+ tool = ":genversion"
+ outputs = [ "$target_gen_dir/$version_file" ]
+ args = [
+ rebase_path(outputs[0],
+ root_build_dir)
+ ]
+ }
+
+ action("generate_x86_insn") {
+ script = "source/patched-yasm/modules/arch/x86/gen_x86_insn.py"
+ # Output eventually #included by source/patched-yasm/frontends/yasm/x86id.c
+ outputs = [
+ "$yasm_gen_include_dir/x86insns.c",
+ "$yasm_gen_include_dir/x86insn_gas.gperf",
+ "$yasm_gen_include_dir/x86insn_nasm.gperf",
+ ]
+ args = [ rebase_path(yasm_gen_include_dir, root_build_dir) ]
+ }
+}
diff --git a/third_party/yasm/run_yasm.py b/third_party/yasm/run_yasm.py
new file mode 100644
index 0000000..cbd79cc
--- /dev/null
+++ b/third_party/yasm/run_yasm.py
@@ -0,0 +1,51 @@
+# Copyright 2014 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.
+
+"""A wrapper to run yasm.
+
+Its main job is to provide a Python wrapper for GN integration, and to write
+the makefile-style output yasm generates in stdout to a .d file for dependency
+management of .inc files.
+
+Run with:
+ python run_yasm.py <yasm_binary_path> <all other yasm args>
+
+Note that <all other yasm args> must include an explicit output file (-o). This
+script will append a ".d" to this and write the dependencies there. This script
+will add "-M" to cause yasm to write the deps to stdout, so you don't need to
+specify that.
+"""
+
+import argparse
+import sys
+import subprocess
+
+# Extract the output file name from the yasm command line so we can generate a
+# .d file with the same base name.
+parser = argparse.ArgumentParser()
+parser.add_argument("-o", dest="objfile")
+options, _ = parser.parse_known_args()
+
+objfile = options.objfile
+depfile = objfile + '.d'
+
+# Assemble.
+result_code = subprocess.call(sys.argv[1:])
+if result_code != 0:
+ sys.exit(result_code)
+
+# Now generate the .d file listing the dependencies. The -M option makes yasm
+# write the Makefile-style dependencies to stdout, but it seems that inhibits
+# generating any compiled output so we need to do this in a separate pass.
+# However, outputting deps seems faster than actually assembling, and yasm is
+# so fast anyway this is not a big deal.
+#
+# This guarantees proper dependency management for assembly files. Otherwise,
+# we would have to require people to manually specify the .inc files they
+# depend on in the build file, which will surely be wrong or out-of-date in
+# some cases.
+deps = subprocess.check_output(sys.argv[1:] + ['-M'])
+with open(depfile, "wb") as f:
+ f.write(deps)
+
diff --git a/third_party/yasm/yasm_assemble.gni b/third_party/yasm/yasm_assemble.gni
new file mode 100644
index 0000000..9044efa
--- /dev/null
+++ b/third_party/yasm/yasm_assemble.gni
@@ -0,0 +1,185 @@
+# Copyright 2014 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.
+
+# This provides the yasm_assemble() template which uses YASM to assemble
+# assembly files.
+#
+# Files to be assembled with YASM should have an extension of .asm.
+#
+# Parameters
+#
+# yasm_flags (optional)
+# [list of strings] Pass additional flags into YASM. These are appended
+# to the command line. Note that the target machine type and system is
+# already set up based on the current toolchain so you don't need to
+# specify these things (see below).
+#
+# Example: yasm_flags = [ "--force-strict" ]
+#
+# include_dirs (optional)
+# [list of dir names] List of additional include dirs. Note that the
+# source root and the root generated file dir is always added, just like
+# our C++ build sets up.
+#
+# Example: include_dirs = [ "//some/other/path", target_gen_dir ]
+#
+# defines (optional)
+# [list of strings] List of defines, as with the native code defines.
+#
+# Example: defines = [ "FOO", "BAR=1" ]
+#
+# source_prereqs, deps, visibility (optional)
+# These have the same meaning as in an action.
+#
+# Example
+#
+# yasm_assemble("my_yasm_target") {
+# sources = [
+# "ultra_optimized_awesome.asm",
+# ]
+# include_dirs = [ "assembly_include" ]
+# }
+
+if (is_mac || is_ios) {
+ if (cpu_arch == "x86") {
+ _yasm_flags = [
+ "-fmacho32",
+ "-m", "x86",
+ ]
+ } else if (cpu_arch == "x64") {
+ _yasm_flags = [
+ "-fmacho64",
+ "-m", "amd64",
+ ]
+ }
+} else if (is_posix) {
+ if (cpu_arch == "x86") {
+ _yasm_flags = [
+ "-felf32",
+ "-m", "x86",
+ ]
+ } else if (cpu_arch == "x64") {
+ _yasm_flags = [
+ "-DPIC",
+ "-felf64",
+ "-m", "amd64",
+ ]
+ }
+} else if (is_win) {
+ if (cpu_arch == "x86") {
+ _yasm_flags = [
+ "-DPREFIX",
+ "-fwin32",
+ "-m", "x86",
+ ]
+ } else if (cpu_arch == "x64") {
+ _yasm_flags = [
+ "-fwin64",
+ "-m", "amd64",
+ ]
+ }
+}
+
+# Default yasm include dirs. Make it match the native build (source root and
+# root generated code directory).
+_yasm_flags += [
+ # 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),
+]
+
+if (is_win) {
+ asm_obj_extension = "obj"
+} else {
+ asm_obj_extension = "o"
+}
+
+template("yasm_assemble") {
+ # TODO(ajwong): Support use_system_yasm.
+ assert(defined(invoker.sources), "Need sources defined for $target_name")
+
+ # Only depend on YASM on x86 systems. Force compilation of .asm files for
+ # ARM to fail.
+ assert(cpu_arch == "x86" || cpu_arch == "x64")
+
+ action_name = "${target_name}_action"
+ source_set_name = target_name
+
+ action_foreach(action_name) {
+ visibility = ":$source_set_name" # Only the source set can depend on this.
+
+ script = "//third_party/yasm/run_yasm.py"
+ sources = invoker.sources
+
+ if (defined(invoker.source_prereqs)) {
+ source_prereqs = invoker.source_prereqs
+ }
+
+ # Executable (first in the args). The binary might be in the root build dir
+ # (no cross-compiling) or in a toolchain-specific subdirectory of that
+ # (when cross-compiling).
+ yasm_label = "//third_party/yasm($host_toolchain)"
+ args = [ "./" + # Force current dir.
+ rebase_path(get_label_info(yasm_label, "root_out_dir") + "/yasm",
+ root_build_dir)
+ ]
+
+ # Deps.
+ deps = [ yasm_label ]
+ if (defined(invoker.deps)) {
+ deps += invoker.deps
+ }
+
+ # Flags.
+ args += _yasm_flags
+ if (defined(invoker.yasm_flags)) {
+ args += invoker.yasm_flags
+ }
+
+ # Extra include directories.
+ if (defined(invoker.include_dirs)) {
+ foreach(include, invoker.include_dirs) {
+ args += [ "-I" + rebase_path(include, root_build_dir) ]
+ }
+ }
+
+ # Extra defines.
+ if (defined(invoker.defines)) {
+ foreach(def, invoker.defines) {
+ args += [ "-D$def" ]
+ }
+ }
+
+ # Output file.
+ #
+ # TODO(brettw) it might be nice if there was a source expansion for the
+ # path of the source file relative to the source root. Then we could
+ # exactly duplicate the naming and location of object files from the
+ # native build, which would be:
+ # "$root_out_dir/${target_name}.{{source_dir_part}}.$asm_obj_extension"
+ outputs = [ "$target_out_dir/{{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.
+ source_set(source_set_name) {
+ if (defined(invoker.visibility)) {
+ visibility = invoker.visibility
+ }
+
+ sources = get_target_outputs(":$action_name")
+ }
+}