From b148d78706df88875060cb76abae9aab8a06a5fa Mon Sep 17 00:00:00 2001 From: John Moon Date: Thu, 27 Apr 2023 14:07:18 -0700 Subject: [PATCH] build: Add BUILD.bazel file Currently, the dtc project builds with Make. As some consumers of this project use Bazel, and eventually all of AOSP will need to move to Bazel anyway, add a a Bazel build definition. Bug: 251879933 Change-Id: I62ea59ee306eda58b764df2a9e5f2f33778e4b5c Signed-off-by: John Moon --- .gitignore | 2 + BUILD.bazel | 129 ++++++++++++++++++++++++++++++++++++++++++++++++++++ WORKSPACE | 0 3 files changed, 131 insertions(+) create mode 100644 BUILD.bazel create mode 100644 WORKSPACE diff --git a/.gitignore b/.gitignore index d90656b..200ac36 100644 --- a/.gitignore +++ b/.gitignore @@ -27,3 +27,5 @@ ncscope.* .eggs/ build/ dist/ + +/bazel-* diff --git a/BUILD.bazel b/BUILD.bazel new file mode 100644 index 0000000..439621d --- /dev/null +++ b/BUILD.bazel @@ -0,0 +1,129 @@ +cc_library( + name = "libfdt", + srcs = glob([ + "libfdt/*.h", + "libfdt/*.c", + ]), + copts = [ + "-Werror", + "-Wno-macro-redefined", + "-Wno-sign-compare", + ], + includes = ["libfdt"], +) + +COPTS = [ + "-Wall", + "-Werror", + "-Wno-sign-compare", + "-Wno-missing-field-initializers", + "-Wno-unused-parameter", +] + +genrule( + name = "lexer", + srcs = [ + "dtc-lexer.l", + ":parser", + ], + outs = ["dtc-lexer.lex.c"], + cmd = "lex -o$@ $(location dtc-lexer.l)", +) + +genrule( + name = "parser", + srcs = ["dtc-parser.y"], + outs = [ + "dtc-parser.c", + "dtc-parser.h", + ], + cmd = """ + bison -b dtc-parser -d $(location dtc-parser.y) + cp ./*.c $(location dtc-parser.c) + cp ./*.h $(location dtc-parser.h) + """, +) + +cc_library( + name = "dtc_gen", + srcs = [ + ":lexer", + ":parser", + ], + hdrs = glob(["*.h"]), + copts = COPTS, + deps = [":libfdt"], +) + +cc_binary( + name = "dtc", + srcs = [ + "checks.c", + "data.c", + "dtc.c", + "flattree.c", + "fstree.c", + "livetree.c", + "srcpos.c", + "treesource.c", + "util.c", + ], + copts = COPTS, + defines = ["NO_YAML"], + deps = [ + ":dtc_gen", + ":libfdt", + ], +) + +cc_binary( + name = "fdtget", + srcs = [ + "fdtget.c", + "util.c", + "util.h", + "version_non_gen.h", + ], + copts = COPTS, + defines = ["NO_YAML"], + deps = [":libfdt"], +) + +cc_binary( + name = "fdtput", + srcs = [ + "fdtput.c", + "util.c", + "util.h", + "version_non_gen.h", + ], + copts = COPTS, + defines = ["NO_YAML"], + deps = [":libfdt"], +) + +cc_binary( + name = "fdtdump", + srcs = [ + "fdtdump.c", + "util.c", + "util.h", + "version_non_gen.h", + ], + copts = COPTS, + defines = ["NO_YAML"], + deps = [":libfdt"], +) + +cc_binary( + name = "fdtoverlay", + srcs = [ + "fdtoverlay.c", + "util.c", + "util.h", + "version_non_gen.h", + ], + copts = COPTS, + defines = ["NO_YAML"], + deps = [":libfdt"], +) diff --git a/WORKSPACE b/WORKSPACE new file mode 100644 index 0000000..e69de29