OLD | NEW |
(Empty) | |
| 1 # Copyright 2014 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 |
| 5 # The yasm build process creates a slew of small C subprograms that |
| 6 # dynamically generate files at various point in the build process. This makes |
| 7 # the build integration moderately complex. |
| 8 # |
| 9 # There are three classes of dynamically generated files: |
| 10 # 1) C source files that should be included in the build (eg., lc3bid.c) |
| 11 # 2) C source files that are #included by static C sources (eg., license.c) |
| 12 # 3) Intermediate files that are used as input by other subprograms to |
| 13 # further generate files in category #1 or #2. (eg., version.mac) |
| 14 # |
| 15 # This structure is represented with the following targets: |
| 16 # 1) yasm -- Sources, flags for the main yasm executable. Also has most of |
| 17 # of the actions and rules that invoke the subprograms. |
| 18 # 2) yasm_config -- General build configuration including setting a |
| 19 # source_prereqs listing the checked in version of files |
| 20 # generated by manually running configure. These manually |
| 21 # generated files are used by all binaries. |
| 22 # 3) yasm_utils -- Object files with memory management and hashing utilities |
| 23 # shared between yasm and the genperf subprogram. |
| 24 # 4) genmacro, genmodule, etc. -- One executable target for each subprogram. |
| 25 # 5) generate_license, generate_module, etc. -- Actions that invoke programs |
| 26 # built in #4 to generate .c files. |
| 27 # 6) compile_gperf, compile_re2c, etc. -- Actions that invoke programs that |
| 28 # turn intermediate files into .c files. |
| 29 |
| 30 if (default_toolchain == host_toolchain) { |
| 31 |
| 32 # Various files referenced by multiple targets. |
| 33 yasm_gen_include_dir = "$target_gen_dir/include" |
| 34 config_makefile = "source/config/$os/Makefile" |
| 35 version_file = "version.mac" |
| 36 |
| 37 import("//build/compiled_action.gni") |
| 38 |
| 39 config("yasm_config") { |
| 40 include_dirs = [ |
| 41 "source/config/$os", |
| 42 "source/patched-yasm", |
| 43 ] |
| 44 source_prereqs = [ |
| 45 config_makefile, |
| 46 "source/config/$os/config.h", |
| 47 "source/config/$os/libyasm-stdint.h", |
| 48 ] |
| 49 defines = [ "HAVE_CONFIG_H" ] |
| 50 cflags = [ "-std=gnu99" ] |
| 51 } |
| 52 |
| 53 executable("genmacro") { |
| 54 sources = [ "source/patched-yasm/tools/genmacro/genmacro.c" ] |
| 55 configs -= [ "//build/config/compiler:chromium_code" ] |
| 56 configs += [ ":yasm_config", |
| 57 "//build/config/compiler:no_chromium_code" ] |
| 58 } |
| 59 |
| 60 executable("genmodule") { |
| 61 sources = [ "source/patched-yasm/libyasm/genmodule.c" ] |
| 62 configs -= [ "//build/config/compiler:chromium_code" ] |
| 63 configs += [ ":yasm_config", |
| 64 "//build/config/compiler:no_chromium_code" ] |
| 65 } |
| 66 |
| 67 executable("genperf") { |
| 68 sources = [ |
| 69 "source/patched-yasm/tools/genperf/genperf.c", |
| 70 "source/patched-yasm/tools/genperf/perfect.c", |
| 71 ] |
| 72 |
| 73 configs -= [ "//build/config/compiler:chromium_code" ] |
| 74 configs += [ ":yasm_config", |
| 75 "//build/config/compiler:no_chromium_code" ] |
| 76 |
| 77 deps = [ ":yasm_utils" ] |
| 78 } |
| 79 |
| 80 # Used by both yasm and genperf binaries. |
| 81 source_set("yasm_utils") { |
| 82 sources = [ |
| 83 "source/patched-yasm/libyasm/phash.c", |
| 84 "source/patched-yasm/libyasm/xmalloc.c", |
| 85 "source/patched-yasm/libyasm/xstrdup.c", |
| 86 ] |
| 87 |
| 88 configs -= [ "//build/config/compiler:chromium_code" ] |
| 89 configs += [ ":yasm_config", |
| 90 "//build/config/compiler:no_chromium_code" ] |
| 91 } |
| 92 |
| 93 executable("genstring") { |
| 94 sources = [ "source/patched-yasm/genstring.c", ] |
| 95 configs -= [ "//build/config/compiler:chromium_code" ] |
| 96 configs += [ ":yasm_config", |
| 97 "//build/config/compiler:no_chromium_code" ] |
| 98 } |
| 99 |
| 100 executable("genversion") { |
| 101 sources = [ "source/patched-yasm/modules/preprocs/nasm/genversion.c" ] |
| 102 configs -= [ "//build/config/compiler:chromium_code" ] |
| 103 configs += [ ":yasm_config", |
| 104 "//build/config/compiler:no_chromium_code" ] |
| 105 } |
| 106 |
| 107 executable("re2c") { |
| 108 sources = [ |
| 109 "source/patched-yasm/tools/re2c/main.c", |
| 110 "source/patched-yasm/tools/re2c/code.c", |
| 111 "source/patched-yasm/tools/re2c/dfa.c", |
| 112 "source/patched-yasm/tools/re2c/parser.c", |
| 113 "source/patched-yasm/tools/re2c/actions.c", |
| 114 "source/patched-yasm/tools/re2c/scanner.c", |
| 115 "source/patched-yasm/tools/re2c/mbo_getopt.c", |
| 116 "source/patched-yasm/tools/re2c/substr.c", |
| 117 "source/patched-yasm/tools/re2c/translate.c", |
| 118 ] |
| 119 |
| 120 configs -= [ "//build/config/compiler:chromium_code" ] |
| 121 configs += [ ":yasm_config", |
| 122 "//build/config/compiler:no_chromium_code" ] |
| 123 |
| 124 # re2c is missing CLOSEVOP from one switch. |
| 125 cflags = [ "-Wno-switch" ] |
| 126 } |
| 127 |
| 128 executable("yasm") { |
| 129 sources = [ |
| 130 "source/patched-yasm/frontends/yasm/yasm-options.c", |
| 131 "source/patched-yasm/frontends/yasm/yasm.c", |
| 132 "source/patched-yasm/libyasm/assocdat.c", |
| 133 "source/patched-yasm/libyasm/bc-align.c", |
| 134 "source/patched-yasm/libyasm/bc-data.c", |
| 135 "source/patched-yasm/libyasm/bc-incbin.c", |
| 136 "source/patched-yasm/libyasm/bc-org.c", |
| 137 "source/patched-yasm/libyasm/bc-reserve.c", |
| 138 "source/patched-yasm/libyasm/bitvect.c", |
| 139 "source/patched-yasm/libyasm/bytecode.c", |
| 140 "source/patched-yasm/libyasm/errwarn.c", |
| 141 "source/patched-yasm/libyasm/expr.c", |
| 142 "source/patched-yasm/libyasm/file.c", |
| 143 "source/patched-yasm/libyasm/floatnum.c", |
| 144 "source/patched-yasm/libyasm/hamt.c", |
| 145 "source/patched-yasm/libyasm/insn.c", |
| 146 "source/patched-yasm/libyasm/intnum.c", |
| 147 "source/patched-yasm/libyasm/inttree.c", |
| 148 "source/patched-yasm/libyasm/linemap.c", |
| 149 "source/patched-yasm/libyasm/md5.c", |
| 150 "source/patched-yasm/libyasm/mergesort.c", |
| 151 "source/patched-yasm/libyasm/section.c", |
| 152 "source/patched-yasm/libyasm/strcasecmp.c", |
| 153 "source/patched-yasm/libyasm/strsep.c", |
| 154 "source/patched-yasm/libyasm/symrec.c", |
| 155 "source/patched-yasm/libyasm/valparam.c", |
| 156 "source/patched-yasm/libyasm/value.c", |
| 157 "source/patched-yasm/modules/arch/lc3b/lc3barch.c", |
| 158 "source/patched-yasm/modules/arch/lc3b/lc3bbc.c", |
| 159 "source/patched-yasm/modules/arch/x86/x86arch.c", |
| 160 "source/patched-yasm/modules/arch/x86/x86bc.c", |
| 161 "source/patched-yasm/modules/arch/x86/x86expr.c", |
| 162 "source/patched-yasm/modules/arch/x86/x86id.c", |
| 163 "source/patched-yasm/modules/dbgfmts/codeview/cv-dbgfmt.c", |
| 164 "source/patched-yasm/modules/dbgfmts/codeview/cv-symline.c", |
| 165 "source/patched-yasm/modules/dbgfmts/codeview/cv-type.c", |
| 166 "source/patched-yasm/modules/dbgfmts/dwarf2/dwarf2-aranges.c", |
| 167 "source/patched-yasm/modules/dbgfmts/dwarf2/dwarf2-dbgfmt.c", |
| 168 "source/patched-yasm/modules/dbgfmts/dwarf2/dwarf2-info.c", |
| 169 "source/patched-yasm/modules/dbgfmts/dwarf2/dwarf2-line.c", |
| 170 "source/patched-yasm/modules/dbgfmts/null/null-dbgfmt.c", |
| 171 "source/patched-yasm/modules/dbgfmts/stabs/stabs-dbgfmt.c", |
| 172 "source/patched-yasm/modules/listfmts/nasm/nasm-listfmt.c", |
| 173 "source/patched-yasm/modules/objfmts/bin/bin-objfmt.c", |
| 174 "source/patched-yasm/modules/objfmts/coff/coff-objfmt.c", |
| 175 "source/patched-yasm/modules/objfmts/coff/win64-except.c", |
| 176 "source/patched-yasm/modules/objfmts/dbg/dbg-objfmt.c", |
| 177 "source/patched-yasm/modules/objfmts/elf/elf-objfmt.c", |
| 178 "source/patched-yasm/modules/objfmts/elf/elf-x86-amd64.c", |
| 179 "source/patched-yasm/modules/objfmts/elf/elf-x86-x86.c", |
| 180 "source/patched-yasm/modules/objfmts/elf/elf.c", |
| 181 "source/patched-yasm/modules/objfmts/macho/macho-objfmt.c", |
| 182 "source/patched-yasm/modules/objfmts/rdf/rdf-objfmt.c", |
| 183 "source/patched-yasm/modules/objfmts/xdf/xdf-objfmt.c", |
| 184 "source/patched-yasm/modules/parsers/gas/gas-parse.c", |
| 185 "source/patched-yasm/modules/parsers/gas/gas-parse-intel.c", |
| 186 "source/patched-yasm/modules/parsers/gas/gas-parser.c", |
| 187 "source/patched-yasm/modules/parsers/nasm/nasm-parse.c", |
| 188 "source/patched-yasm/modules/parsers/nasm/nasm-parser.c", |
| 189 "source/patched-yasm/modules/preprocs/cpp/cpp-preproc.c", |
| 190 "source/patched-yasm/modules/preprocs/nasm/nasm-eval.c", |
| 191 "source/patched-yasm/modules/preprocs/nasm/nasm-pp.c", |
| 192 "source/patched-yasm/modules/preprocs/nasm/nasm-preproc.c", |
| 193 "source/patched-yasm/modules/preprocs/nasm/nasmlib.c", |
| 194 "source/patched-yasm/modules/preprocs/raw/raw-preproc.c", |
| 195 |
| 196 # Files generated by compile_gperf |
| 197 "$target_gen_dir/x86cpu.c", |
| 198 "$target_gen_dir/x86regtmod.c", |
| 199 |
| 200 # Files generated by compile_re2c |
| 201 "$target_gen_dir/gas-token.c", |
| 202 "$target_gen_dir/nasm-token.c", |
| 203 |
| 204 # File generated by compile_re2c_lc3b |
| 205 "$target_gen_dir/lc3bid.c", |
| 206 |
| 207 # File generated by generate_module |
| 208 "$target_gen_dir/module.c" |
| 209 ] |
| 210 |
| 211 configs -= [ "//build/config/compiler:chromium_code" ] |
| 212 configs += [ ":yasm_config", |
| 213 "//build/config/compiler:no_chromium_code" ] |
| 214 |
| 215 # Yasm generates a bunch of .c files which its source file #include. |
| 216 # Add the |target_gen_dir| into the include path so it can find them. |
| 217 # Ideally, these generated .c files would be placed into a separate |
| 218 # directory, but the gen_x86_insn.py script does not make this easy. |
| 219 include_dirs = [ yasm_gen_include_dir ] |
| 220 |
| 221 cflags = [ "-ansi", "-pedantic" ] |
| 222 if (is_clang) { |
| 223 cflags += [ "-Wno-incompatible-pointer-types" ] |
| 224 } |
| 225 |
| 226 # TODO(ajwong): This should take most of the generated output as |
| 227 # source_prereqs. |
| 228 deps = [ |
| 229 ":compile_gperf", |
| 230 ":compile_gperf_for_include", |
| 231 ":compile_nasm_macros", |
| 232 ":compile_nasm_version", |
| 233 ":compile_win64_gas", |
| 234 ":compile_win64_nasm", |
| 235 ":compile_re2c", |
| 236 ":generate_license", |
| 237 ":generate_module", |
| 238 ":generate_version", |
| 239 ":yasm_utils", |
| 240 ] |
| 241 } |
| 242 |
| 243 compiled_action_foreach("compile_gperf") { |
| 244 tool = ":genperf" |
| 245 sources = [ |
| 246 "source/patched-yasm/modules/arch/x86/x86cpu.gperf", |
| 247 "source/patched-yasm/modules/arch/x86/x86regtmod.gperf", |
| 248 ] |
| 249 |
| 250 outputs = [ "$target_gen_dir/{{source_name_part}}.c" ] |
| 251 args = [ |
| 252 "{{source}}", |
| 253 rebase_path(target_gen_dir, ".") + "/{{source_name_part}}.c", |
| 254 ] |
| 255 deps = [ |
| 256 ":generate_x86_insn" |
| 257 ] |
| 258 } |
| 259 |
| 260 # This differs from |compile_gperf| in where it places it output files. |
| 261 compiled_action_foreach("compile_gperf_for_include") { |
| 262 tool = ":genperf" |
| 263 sources = [ |
| 264 # Make sure the generated gperf files in $target_gen_dir are synced with |
| 265 # the outputs for the related generate_*_insn actions in the |
| 266 # generate_files target below. |
| 267 # |
| 268 # The output for these two are #included by |
| 269 # source/patched-yasm/modules/arch/x86/x86id.c |
| 270 "$yasm_gen_include_dir/x86insn_gas.gperf", |
| 271 "$yasm_gen_include_dir/x86insn_nasm.gperf", |
| 272 ] |
| 273 |
| 274 outputs = [ "$yasm_gen_include_dir/{{source_name_part}}.c" ] |
| 275 args = [ |
| 276 "{{source}}", |
| 277 rebase_path(yasm_gen_include_dir, ".") + "/{{source_name_part}}.c", |
| 278 ] |
| 279 deps = [ |
| 280 ":generate_x86_insn" |
| 281 ] |
| 282 } |
| 283 |
| 284 template("compile_macro") { |
| 285 compiled_action(target_name) { |
| 286 tool = ":genmacro" |
| 287 # Output #included by source/patched-yasm/frontends/yasm/yasm.c. |
| 288 sources = invoker.sources |
| 289 outputs = invoker.outputs |
| 290 args = [ |
| 291 rebase_path(outputs[0], root_build_dir), |
| 292 invoker.macro_varname, |
| 293 rebase_path(sources[0], root_build_dir), |
| 294 ] |
| 295 if (defined(invoker.deps)) { |
| 296 deps = invoker.deps |
| 297 } |
| 298 } |
| 299 } |
| 300 |
| 301 compile_macro("compile_nasm_macros") { |
| 302 # Output #included by |
| 303 # source/patched-yasm/modules/preprocs/nasm/nasm-parser.c |
| 304 sources = [ "source/patched-yasm/modules/parsers/nasm/nasm-std.mac" ] |
| 305 outputs = [ "$yasm_gen_include_dir/nasm-macros.c" ] |
| 306 macro_varname = "nasm_standard_mac" |
| 307 } |
| 308 |
| 309 compile_macro("compile_nasm_version") { |
| 310 # Output #included by |
| 311 # source/patched-yasm/modules/preprocs/nasm/nasm-preproc.c |
| 312 sources = [ "$target_gen_dir/$version_file" ] |
| 313 outputs = [ "$yasm_gen_include_dir/nasm-version.c" ] |
| 314 macro_varname = "nasm_version_mac" |
| 315 deps = [ ":generate_version" ] |
| 316 } |
| 317 |
| 318 compile_macro("compile_win64_gas") { |
| 319 # Output #included by source/patched-yasm/frontends/yasm/yasm.c. |
| 320 sources = [ "source/patched-yasm/modules/objfmts/coff/win64-gas.mac" ] |
| 321 outputs = [ "$yasm_gen_include_dir/win64-gas.c" ] |
| 322 macro_varname = "win64_gas_stdmac" |
| 323 } |
| 324 |
| 325 compile_macro("compile_win64_nasm") { |
| 326 # Output #included by source/patched-yasm/frontends/yasm/yasm.c. |
| 327 sources = [ "source/patched-yasm/modules/objfmts/coff/win64-nasm.mac" ] |
| 328 outputs = [ "$yasm_gen_include_dir/win64-nasm.c" ] |
| 329 macro_varname = "win64_nasm_stdmac" |
| 330 } |
| 331 |
| 332 compiled_action_foreach("compile_re2c") { |
| 333 tool = ":re2c" |
| 334 sources = [ |
| 335 "source/patched-yasm/modules/parsers/gas/gas-token.re", |
| 336 "source/patched-yasm/modules/parsers/nasm/nasm-token.re", |
| 337 ] |
| 338 outputs = [ "$target_gen_dir/{{source_name_part}}.c" ] |
| 339 args = [ |
| 340 "-b", |
| 341 "-o", |
| 342 rebase_path(target_gen_dir, ".") + "/{{source_name_part}}.c", |
| 343 "{{source}}", |
| 344 ] |
| 345 } |
| 346 |
| 347 # This call doesn't fit into the re2c template above. |
| 348 compiled_action("compile_re2c_lc3b") { |
| 349 tool = ":re2c" |
| 350 sources = [ "source/patched-yasm/modules/arch/lc3b/lc3bid.re" ] |
| 351 outputs = [ "$target_gen_dir/lc3bid.c" ] |
| 352 args = [ |
| 353 "-s", |
| 354 "-o", |
| 355 rebase_path(outputs[0], root_build_dir), |
| 356 rebase_path(sources[0], root_build_dir), |
| 357 ] |
| 358 } |
| 359 |
| 360 compiled_action("generate_license") { |
| 361 tool = ":genstring" |
| 362 # Output #included by source/patched-yasm/frontends/yasm/yasm.c. |
| 363 sources = [ "source/patched-yasm/COPYING" ] |
| 364 outputs = [ "$yasm_gen_include_dir/license.c" ] |
| 365 args = [ |
| 366 "license_msg", |
| 367 rebase_path(outputs[0], root_build_dir), |
| 368 rebase_path(sources[0], root_build_dir), |
| 369 ] |
| 370 } |
| 371 |
| 372 compiled_action("generate_module") { |
| 373 tool = ":genmodule" |
| 374 sources = [ "source/patched-yasm/libyasm/module.in" ] |
| 375 outputs = [ "$target_gen_dir/module.c" ] |
| 376 args = [ |
| 377 rebase_path(sources[0], root_build_dir), |
| 378 rebase_path(config_makefile, root_build_dir), |
| 379 rebase_path(outputs[0], root_build_dir), |
| 380 ] |
| 381 } |
| 382 |
| 383 compiled_action("generate_version") { |
| 384 tool = ":genversion" |
| 385 outputs = [ "$target_gen_dir/$version_file" ] |
| 386 args = [ |
| 387 rebase_path(outputs[0], |
| 388 root_build_dir) |
| 389 ] |
| 390 } |
| 391 |
| 392 action("generate_x86_insn") { |
| 393 script = "source/patched-yasm/modules/arch/x86/gen_x86_insn.py" |
| 394 # Output eventually #included by source/patched-yasm/frontends/yasm/x86id.c |
| 395 outputs = [ |
| 396 "$yasm_gen_include_dir/x86insns.c", |
| 397 "$yasm_gen_include_dir/x86insn_gas.gperf", |
| 398 "$yasm_gen_include_dir/x86insn_nasm.gperf", |
| 399 ] |
| 400 args = [ rebase_path(yasm_gen_include_dir, root_build_dir) ] |
| 401 } |
| 402 } |
OLD | NEW |