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# inputs 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 30import("//build/config/compiler/compiler.gni") 31 32configs_to_delete = [] 33configs_to_add = [] 34if (is_debug) { 35 configs_to_delete += [ 36 # Build with full optimizations even on debug configurations, because some 37 # yasm build steps (highbd_sad4d_sse2.asm) can take ~33 seconds or more in 38 # debug component builds on Windows. Enabling compiler optimizations saves 39 # ~5 seconds. 40 "//build/config/compiler:default_optimization", 41 42 # Don't define _DEBUG. Modest savings, but good for consistency. 43 "//build/config:debug", 44 45 # Don't enable sanitizers for build tools. They slow down the overall build. 46 "//build/config/sanitizers:default_sanitizer_flags", 47 ] 48 49 configs_to_add += [ 50 "//build/config:release", 51 "//build/config/compiler:optimize_max", 52 ] 53 if (is_win) { 54 # This switches to using the release CRT. On debug component builds of 55 # highbd_sad4d_sse2.asm on Windows this saves about 15 s. 56 configs_to_delete += [ "//build/config/win:default_crt" ] 57 configs_to_add += [ "//build/config/win:release_crt" ] 58 59 # Without no_default_deps, an implicit dependency on libc++ is added. 60 # libc++ may have been built referencing the debug CRT, but since we're 61 # explicitly using the release CRT, this would result in undefined symbol 62 # errors when linking, so we need to remove the implicit libc++ dependency. 63 no_default_deps = true 64 } 65} 66 67if (current_toolchain == host_toolchain) { 68 # Various files referenced by multiple targets. yasm_gen_include_dir was moved 69 # from $target_gen_dir/include to avoid conflicts with x86insn_gas.c and 70 # x86insn_nasm.c. These files were previously generated during the build but 71 # are now shipped pre-generated by yasm. 72 yasm_gen_include_dir = "$target_gen_dir/gen_include" 73 config_makefile = "source/config/Makefile" 74 version_file = "version.mac" 75 76 import("//build/compiled_action.gni") 77 78 config("yasm_config") { 79 configs = [ "//build/config/sanitizers:cfi_icall_generalize_pointers" ] 80 include_dirs = [ 81 "source/config/$host_os", 82 "source/patched-yasm", 83 ] 84 defines = [ "HAVE_CONFIG_H" ] 85 if (is_posix || is_fuchsia) { 86 cflags = [ "-std=gnu99" ] 87 } 88 } 89 90 executable("genmacro") { 91 sources = [ "source/patched-yasm/tools/genmacro/genmacro.c" ] 92 configs -= [ "//build/config/compiler:chromium_code" ] 93 configs += [ 94 ":yasm_config", 95 "//build/config/compiler:no_chromium_code", 96 ] 97 deps = [ 98 # Default manifest on Windows (a no-op elsewhere). 99 "//build/win:default_exe_manifest", 100 ] 101 } 102 103 executable("genmodule") { 104 sources = [ "source/patched-yasm/libyasm/genmodule.c" ] 105 configs -= [ "//build/config/compiler:chromium_code" ] 106 configs += [ 107 ":yasm_config", 108 "//build/config/compiler:no_chromium_code", 109 ] 110 deps = [ 111 # Default manifest on Windows (a no-op elsewhere). 112 "//build/win:default_exe_manifest", 113 ] 114 } 115 116 executable("genperf") { 117 sources = [ 118 "source/patched-yasm/tools/genperf/genperf.c", 119 "source/patched-yasm/tools/genperf/perfect.c", 120 ] 121 122 configs -= [ "//build/config/compiler:chromium_code" ] 123 configs += [ 124 ":yasm_config", 125 "//build/config/compiler:no_chromium_code", 126 ] 127 128 # Must be compatible with yasm_utils/yasm 129 configs -= configs_to_delete 130 configs += configs_to_add 131 132 deps = [ 133 ":yasm_utils", 134 135 # Default manifest on Windows (a no-op elsewhere). 136 "//build/win:default_exe_manifest", 137 ] 138 } 139 140 # Used by both yasm and genperf binaries. 141 static_library("yasm_utils") { 142 sources = [ 143 "source/patched-yasm/libyasm/phash.c", 144 "source/patched-yasm/libyasm/xmalloc.c", 145 "source/patched-yasm/libyasm/xstrdup.c", 146 ] 147 148 configs -= [ "//build/config/compiler:chromium_code" ] 149 configs += [ 150 ":yasm_config", 151 "//build/config/compiler:no_chromium_code", 152 ] 153 154 # Must be compatible with yasm 155 configs -= configs_to_delete 156 configs += configs_to_add 157 } 158 159 executable("genstring") { 160 sources = [ "source/patched-yasm/genstring.c" ] 161 configs -= [ "//build/config/compiler:chromium_code" ] 162 configs += [ 163 ":yasm_config", 164 "//build/config/compiler:no_chromium_code", 165 ] 166 deps = [ 167 # Default manifest on Windows (a no-op elsewhere). 168 "//build/win:default_exe_manifest", 169 ] 170 } 171 172 executable("genversion") { 173 sources = [ "source/patched-yasm/modules/preprocs/nasm/genversion.c" ] 174 configs -= [ "//build/config/compiler:chromium_code" ] 175 configs += [ 176 ":yasm_config", 177 "//build/config/compiler:no_chromium_code", 178 ] 179 deps = [ 180 # Default manifest on Windows (a no-op elsewhere). 181 "//build/win:default_exe_manifest", 182 ] 183 } 184 185 config("re2c_warnings") { 186 # re2c is missing CLOSEVOP from one switch. 187 if (is_clang) { 188 cflags = [ 189 # re2c is missing CLOSEVOP from one switch. 190 "-Wno-switch", 191 192 # re2c contains many static functions in headers (because it's 193 # a C library predating C99.) 194 "-Wno-unused-function", 195 ] 196 } 197 } 198 199 executable("re2c") { 200 sources = [ 201 "source/patched-yasm/tools/re2c/actions.c", 202 "source/patched-yasm/tools/re2c/code.c", 203 "source/patched-yasm/tools/re2c/dfa.c", 204 "source/patched-yasm/tools/re2c/main.c", 205 "source/patched-yasm/tools/re2c/mbo_getopt.c", 206 "source/patched-yasm/tools/re2c/parser.c", 207 "source/patched-yasm/tools/re2c/scanner.c", 208 "source/patched-yasm/tools/re2c/substr.c", 209 "source/patched-yasm/tools/re2c/translate.c", 210 ] 211 212 configs -= [ "//build/config/compiler:chromium_code" ] 213 configs += [ 214 ":yasm_config", 215 "//build/config/compiler:no_chromium_code", 216 217 # Must be after no_chromium_code for warning flags to be ordered 218 # correctly. 219 ":re2c_warnings", 220 ] 221 deps = [ 222 # Default manifest on Windows (a no-op elsewhere). 223 "//build/win:default_exe_manifest", 224 ] 225 } 226 227 config("yasm_warnings") { 228 if (is_clang) { 229 cflags = [ 230 # reg3264type in x86expr.c is unused. 231 "-Wno-unused-local-typedef", 232 ] 233 } else if (is_linux) { 234 cflags = [ 235 # dosexe_objfmt_output ignores the return value of ftruncate. 236 "-Wno-unused-result", 237 ] 238 } 239 } 240 241 executable("yasm") { 242 sources = [ 243 "source/patched-yasm/frontends/yasm/yasm-options.c", 244 "source/patched-yasm/frontends/yasm/yasm.c", 245 "source/patched-yasm/libyasm/assocdat.c", 246 "source/patched-yasm/libyasm/bc-align.c", 247 "source/patched-yasm/libyasm/bc-data.c", 248 "source/patched-yasm/libyasm/bc-incbin.c", 249 "source/patched-yasm/libyasm/bc-org.c", 250 "source/patched-yasm/libyasm/bc-reserve.c", 251 "source/patched-yasm/libyasm/bitvect.c", 252 "source/patched-yasm/libyasm/bytecode.c", 253 "source/patched-yasm/libyasm/errwarn.c", 254 "source/patched-yasm/libyasm/expr.c", 255 "source/patched-yasm/libyasm/file.c", 256 "source/patched-yasm/libyasm/floatnum.c", 257 "source/patched-yasm/libyasm/hamt.c", 258 "source/patched-yasm/libyasm/insn.c", 259 "source/patched-yasm/libyasm/intnum.c", 260 "source/patched-yasm/libyasm/inttree.c", 261 "source/patched-yasm/libyasm/linemap.c", 262 "source/patched-yasm/libyasm/md5.c", 263 "source/patched-yasm/libyasm/mergesort.c", 264 "source/patched-yasm/libyasm/section.c", 265 "source/patched-yasm/libyasm/strcasecmp.c", 266 "source/patched-yasm/libyasm/strsep.c", 267 "source/patched-yasm/libyasm/symrec.c", 268 "source/patched-yasm/libyasm/valparam.c", 269 "source/patched-yasm/libyasm/value.c", 270 "source/patched-yasm/modules/arch/lc3b/lc3barch.c", 271 "source/patched-yasm/modules/arch/lc3b/lc3bbc.c", 272 "source/patched-yasm/modules/arch/x86/x86arch.c", 273 "source/patched-yasm/modules/arch/x86/x86bc.c", 274 "source/patched-yasm/modules/arch/x86/x86expr.c", 275 "source/patched-yasm/modules/arch/x86/x86id.c", 276 "source/patched-yasm/modules/dbgfmts/codeview/cv-dbgfmt.c", 277 "source/patched-yasm/modules/dbgfmts/codeview/cv-symline.c", 278 "source/patched-yasm/modules/dbgfmts/codeview/cv-type.c", 279 "source/patched-yasm/modules/dbgfmts/dwarf2/dwarf2-aranges.c", 280 "source/patched-yasm/modules/dbgfmts/dwarf2/dwarf2-dbgfmt.c", 281 "source/patched-yasm/modules/dbgfmts/dwarf2/dwarf2-info.c", 282 "source/patched-yasm/modules/dbgfmts/dwarf2/dwarf2-line.c", 283 "source/patched-yasm/modules/dbgfmts/null/null-dbgfmt.c", 284 "source/patched-yasm/modules/dbgfmts/stabs/stabs-dbgfmt.c", 285 "source/patched-yasm/modules/listfmts/nasm/nasm-listfmt.c", 286 "source/patched-yasm/modules/objfmts/bin/bin-objfmt.c", 287 "source/patched-yasm/modules/objfmts/coff/coff-objfmt.c", 288 "source/patched-yasm/modules/objfmts/coff/win64-except.c", 289 "source/patched-yasm/modules/objfmts/dbg/dbg-objfmt.c", 290 "source/patched-yasm/modules/objfmts/elf/elf-objfmt.c", 291 "source/patched-yasm/modules/objfmts/elf/elf-x86-amd64.c", 292 "source/patched-yasm/modules/objfmts/elf/elf-x86-x32.c", 293 "source/patched-yasm/modules/objfmts/elf/elf-x86-x86.c", 294 "source/patched-yasm/modules/objfmts/elf/elf.c", 295 "source/patched-yasm/modules/objfmts/macho/macho-objfmt.c", 296 "source/patched-yasm/modules/objfmts/rdf/rdf-objfmt.c", 297 "source/patched-yasm/modules/objfmts/xdf/xdf-objfmt.c", 298 "source/patched-yasm/modules/parsers/gas/gas-parse-intel.c", 299 "source/patched-yasm/modules/parsers/gas/gas-parse.c", 300 "source/patched-yasm/modules/parsers/gas/gas-parser.c", 301 "source/patched-yasm/modules/parsers/nasm/nasm-parse.c", 302 "source/patched-yasm/modules/parsers/nasm/nasm-parser.c", 303 "source/patched-yasm/modules/preprocs/cpp/cpp-preproc.c", 304 "source/patched-yasm/modules/preprocs/gas/gas-eval.c", 305 "source/patched-yasm/modules/preprocs/gas/gas-preproc.c", 306 "source/patched-yasm/modules/preprocs/nasm/nasm-eval.c", 307 "source/patched-yasm/modules/preprocs/nasm/nasm-pp.c", 308 "source/patched-yasm/modules/preprocs/nasm/nasm-preproc.c", 309 "source/patched-yasm/modules/preprocs/nasm/nasmlib.c", 310 "source/patched-yasm/modules/preprocs/raw/raw-preproc.c", 311 312 # Files generated by compile_gperf 313 "$target_gen_dir/x86cpu.c", 314 "$target_gen_dir/x86regtmod.c", 315 316 # Files generated by compile_re2c 317 "$target_gen_dir/gas-token.c", 318 "$target_gen_dir/nasm-token.c", 319 320 # File generated by compile_re2c_lc3b 321 "$target_gen_dir/lc3bid.c", 322 323 # File generated by generate_module 324 "$target_gen_dir/module.c", 325 ] 326 327 configs -= [ "//build/config/compiler:chromium_code" ] 328 configs += [ 329 ":yasm_config", 330 "//build/config/compiler:no_chromium_code", 331 "//build/config/compiler:no_incompatible_pointer_warnings", 332 333 # Must be after no_chromium_code for warning flags to be ordered 334 # correctly. 335 ":yasm_warnings", 336 ] 337 338 # Disable WPO for yasm: crbug.com/604808 339 if (is_official_build && full_wpo_on_official) { 340 configs -= [ "//build/config/compiler:default_optimization" ] 341 configs += [ "//build/config/compiler:optimize_no_wpo" ] 342 } else { 343 configs -= configs_to_delete 344 configs += configs_to_add 345 } 346 347 # Yasm generates a bunch of .c files which its source file #include. These 348 # are placed in |yasm_gen_include_dir|. 349 include_dirs = [ yasm_gen_include_dir ] 350 351 if (!is_win) { 352 cflags = [ 353 "-std=c89", 354 "-pedantic", 355 ] 356 } 357 358 # TODO(ajwong): This should take most of the generated output as 359 # inputs. 360 deps = [ 361 ":compile_gperf", 362 ":compile_gperf_for_include", 363 ":compile_nasm_macros", 364 ":compile_nasm_version", 365 ":compile_re2c", 366 ":compile_re2c_lc3b", 367 ":compile_win64_gas", 368 ":compile_win64_nasm", 369 ":generate_license", 370 ":generate_module", 371 ":generate_version", 372 ":yasm_utils", 373 374 # Default manifest on Windows (a no-op elsewhere). 375 "//build/win:default_exe_manifest", 376 ] 377 } 378 379 compiled_action_foreach("compile_gperf") { 380 tool = ":genperf" 381 sources = [ 382 "source/patched-yasm/modules/arch/x86/x86cpu.gperf", 383 "source/patched-yasm/modules/arch/x86/x86regtmod.gperf", 384 ] 385 386 outputs = [ "$target_gen_dir/{{source_name_part}}.c" ] 387 args = [ 388 "{{source}}", 389 rebase_path(target_gen_dir, root_build_dir) + "/{{source_name_part}}.c", 390 ] 391 } 392 393 # This differs from |compile_gperf| in where it places it output files. 394 compiled_action_foreach("compile_gperf_for_include") { 395 tool = ":genperf" 396 sources = [ 397 # Make sure the generated gperf files in $target_gen_dir are synced with 398 # the outputs for the related generate_*_insn actions in the 399 # generate_files target below. 400 # 401 # The output for these two are #included by 402 # source/patched-yasm/modules/arch/x86/x86id.c 403 "source/patched-yasm/x86insn_gas.gperf", 404 "source/patched-yasm/x86insn_nasm.gperf", 405 ] 406 407 outputs = [ "$yasm_gen_include_dir/{{source_name_part}}.c" ] 408 args = [ 409 "{{source}}", 410 rebase_path(yasm_gen_include_dir, root_build_dir) + 411 "/{{source_name_part}}.c", 412 ] 413 } 414 415 template("compile_macro") { 416 compiled_action(target_name) { 417 tool = ":genmacro" 418 419 # Output #included by source/patched-yasm/frontends/yasm/yasm.c. 420 inputs = invoker.sources 421 outputs = invoker.outputs 422 args = [ 423 rebase_path(outputs[0], root_build_dir), 424 invoker.macro_varname, 425 rebase_path(inputs[0], root_build_dir), 426 ] 427 if (defined(invoker.deps)) { 428 deps = invoker.deps 429 } 430 } 431 } 432 433 compile_macro("compile_nasm_macros") { 434 # Output #included by 435 # source/patched-yasm/modules/preprocs/nasm/nasm-parser.c 436 sources = [ "source/patched-yasm/modules/parsers/nasm/nasm-std.mac" ] 437 outputs = [ "$yasm_gen_include_dir/nasm-macros.c" ] 438 macro_varname = "nasm_standard_mac" 439 } 440 441 compile_macro("compile_nasm_version") { 442 # Output #included by 443 # source/patched-yasm/modules/preprocs/nasm/nasm-preproc.c 444 sources = [ "$target_gen_dir/$version_file" ] 445 outputs = [ "$yasm_gen_include_dir/nasm-version.c" ] 446 macro_varname = "nasm_version_mac" 447 deps = [ ":generate_version" ] 448 } 449 450 compile_macro("compile_win64_gas") { 451 # Output #included by source/patched-yasm/frontends/yasm/yasm.c. 452 sources = [ "source/patched-yasm/modules/objfmts/coff/win64-gas.mac" ] 453 outputs = [ "$yasm_gen_include_dir/win64-gas.c" ] 454 macro_varname = "win64_gas_stdmac" 455 } 456 457 compile_macro("compile_win64_nasm") { 458 # Output #included by source/patched-yasm/frontends/yasm/yasm.c. 459 sources = [ "source/patched-yasm/modules/objfmts/coff/win64-nasm.mac" ] 460 outputs = [ "$yasm_gen_include_dir/win64-nasm.c" ] 461 macro_varname = "win64_nasm_stdmac" 462 } 463 464 compiled_action_foreach("compile_re2c") { 465 tool = ":re2c" 466 sources = [ 467 "source/patched-yasm/modules/parsers/gas/gas-token.re", 468 "source/patched-yasm/modules/parsers/nasm/nasm-token.re", 469 ] 470 outputs = [ "$target_gen_dir/{{source_name_part}}.c" ] 471 args = [ 472 "-b", 473 "-o", 474 rebase_path(target_gen_dir, root_build_dir) + "/{{source_name_part}}.c", 475 "{{source}}", 476 ] 477 } 478 479 # This call doesn't fit into the re2c template above. 480 compiled_action("compile_re2c_lc3b") { 481 tool = ":re2c" 482 inputs = [ "source/patched-yasm/modules/arch/lc3b/lc3bid.re" ] 483 outputs = [ "$target_gen_dir/lc3bid.c" ] 484 args = [ 485 "-s", 486 "-o", 487 rebase_path(outputs[0], root_build_dir), 488 rebase_path(inputs[0], root_build_dir), 489 ] 490 } 491 492 compiled_action("generate_license") { 493 tool = ":genstring" 494 495 # Output #included by source/patched-yasm/frontends/yasm/yasm.c. 496 inputs = [ "source/patched-yasm/COPYING" ] 497 outputs = [ "$yasm_gen_include_dir/license.c" ] 498 args = [ 499 "license_msg", 500 rebase_path(outputs[0], root_build_dir), 501 rebase_path(inputs[0], root_build_dir), 502 ] 503 } 504 505 compiled_action("generate_module") { 506 tool = ":genmodule" 507 inputs = [ 508 "source/patched-yasm/libyasm/module.in", 509 config_makefile, 510 ] 511 outputs = [ "$target_gen_dir/module.c" ] 512 args = [ 513 rebase_path(inputs[0], root_build_dir), 514 rebase_path(config_makefile, root_build_dir), 515 rebase_path(outputs[0], root_build_dir), 516 ] 517 } 518 519 compiled_action("generate_version") { 520 tool = ":genversion" 521 outputs = [ "$target_gen_dir/$version_file" ] 522 args = [ rebase_path(outputs[0], root_build_dir) ] 523 } 524} 525