| # Copyright 2019 The Chromium OS Authors. All rights reserved. |
| # Use of this source code is governed by a BSD-style license that can be |
| # found in the LICENSE file. |
| |
| # GN template to generate static library for the given yacc files. |
| # How to use: |
| # [platform2/pkg/BUILD.gn] |
| # generate_bison_parser("foo_bison_parser") { |
| # out_dir = "${platform2_root}" |
| # sources = [ |
| # "foo.yy", |
| # "bar.yy", |
| # ] |
| # } |
| # |
| # Then this generates the binding source code and headers |
| # under ${root_gen_dir}/${out_dir},. E.g. ${root_gen_dir}/${out_dir}/foo.cc, |
| # ${root_gen_dir}/${out_dir}/foo.hh, ${root_gen_dir}/${out_dir}/bar.cc, |
| # ${root_gen_dir}/${out_dir}/bar.hh etc. |
| # |
| # Parameters: |
| # out_dir |
| # The output source code and headers' path. |
| # sources |
| # The .yy / .y file paths. |
| # |
| |
| template("generate_bison_parser") { |
| h_dir = "${root_gen_dir}/" + invoker.out_dir |
| |
| action_foreach(target_name) { |
| sources = invoker.sources |
| script = "//common-mk/file_generator_wrapper.py" |
| outputs = [ |
| "${h_dir}/{{source_name_part}}.cc", |
| "${h_dir}/{{source_name_part}}.hh", |
| ] |
| args = [ |
| "bison", |
| "-d", |
| "-o", |
| "${h_dir}/{{source_name_part}}.cc", |
| "{{source}}", |
| ] |
| } |
| } |