diff --git a/BUILD b/BUILD new file mode 100644 index 0000000..315d32e --- /dev/null +++ b/BUILD @@ -0,0 +1,73 @@ +load("@bazel_skylib//rules:expand_template.bzl", "expand_template") + +cc_library( + name = "modbus", + srcs = glob(["src/*.c"]) + [ + ":generate_config_h", + ":generate_modbus_version_h", + ], + hdrs = glob(["src/*.h"]), + copts = ["-DHAVE_CONFIG_H", "-DHAVE_NETINET_IP_H=1"], + includes = ["src"], + include_prefix = "libmodbus", + visibility = ["//visibility:public"], +) + +alias( + name = "libmodbus", + actual = ":modbus", +) + +cc_library( + name = "modbus_headers", + hdrs = [ + "src/modbus.h", + "src/modbus-rtu.h", + "src/modbus-tcp.h", + "src/modbus-version.h", + ], + includes = ["src"], + include_prefix = "libmodbus", + visibility = ["//visibility:public"], +) + +cc_shared_library( + name = "modbus_shared", + additional_linker_inputs = [ + ":modbus-versionscript.lds", + ], + user_link_flags = [ + # Linker script to hide non-modbus symbols. + "-Wl,--version-script", + "$(location modbus-versionscript.lds)", + ], + visibility = ["//visibility:public"], + deps = [ + ":modbus", + ], +) + +expand_template( + name = "generate_modbus_version_h", + out = "src/modbus-version.h", + substitutions = { + "@LIBMODBUS_VERSION_MAJOR@": "3", + "@LIBMODBUS_VERSION_MINOR@": "1", + "@LIBMODBUS_VERSION_MICRO@": "11", + "@LIBMODBUS_VERSION@": "3.1.11", + }, + template = "src/modbus-version.h.in", +) + +genrule( + name = "generate_config_h", + outs = ["src/config.h"], + cmd = """cat > $@ <