load("@rules_cc//cc:cc_binary.bzl", "cc_binary")
load("@rules_cc//cc:cc_library.bzl", "cc_library")

package(
    default_visibility = ["//visibility:public"],
)

cc_library(
    name = "liblp",
    srcs = [
        "fs_mgr/liblp/builder.cpp",
        "fs_mgr/liblp/images.cpp",
        "fs_mgr/liblp/images.h",
        "fs_mgr/liblp/partition_opener.cpp",
        "fs_mgr/liblp/property_fetcher.cpp",
        "fs_mgr/liblp/reader.cpp",
        "fs_mgr/liblp/reader.h",
        "fs_mgr/liblp/super_layout_builder.cpp",
        "fs_mgr/liblp/utility.cpp",
        "fs_mgr/liblp/utility.h",
        "fs_mgr/liblp/writer.cpp",
        "fs_mgr/liblp/writer.h",
    ],
    hdrs = [
        "fs_mgr/liblp/include/liblp/builder.h",
        "fs_mgr/liblp/include/liblp/liblp.h",
        "fs_mgr/liblp/include/liblp/metadata_format.h",
        "fs_mgr/liblp/include/liblp/partition_opener.h",
        "fs_mgr/liblp/include/liblp/property_fetcher.h",
        "fs_mgr/liblp/include/liblp/super_layout_builder.h",
    ],
    copts = [
        "-Ifs_mgr/liblp",
    ],
    includes = [
        "fs_mgr/liblp/include",
    ],
    deps = [
        ":libsparse",
        "@@//libbase",
        "@@//libext4_utils",
        "@boringssl//:crypto",
    ],
)

cc_library(
    name = "libsparse",
    srcs = [
        "libsparse/backed_block.cpp",
        "libsparse/backed_block.h",
        "libsparse/defs.h",
        "libsparse/output_file.cpp",
        "libsparse/output_file.h",
        "libsparse/sparse.cpp",
        "libsparse/sparse_crc32.cpp",
        "libsparse/sparse_crc32.h",
        "libsparse/sparse_defs.h",
        "libsparse/sparse_err.cpp",
        "libsparse/sparse_file.h",
        "libsparse/sparse_format.h",
        "libsparse/sparse_read.cpp",
    ],
    hdrs = [
        "libsparse/include/sparse/sparse.h",
    ],
    copts = [
        "-Ilibsparse",
        "-Wno-vla-cxx-extension",
        "-Wno-c99-designator",
    ],
    includes = ["libsparse/include"],
    deps = [
        "@@//libbase",
        "@zlib",
    ],
)

cc_binary(
    name = "simg2img",
    srcs = ["libsparse/simg2img.cpp"],
    deps = [":libsparse"],
)

cc_library(
    name = "libcutils",
    srcs = [
        "libcutils/android_get_control_env.h",
        "libcutils/android_get_control_file.cpp",
        "libcutils/canned_fs_config.cpp",
        "libcutils/fs_config.cpp",
        "libcutils/fs_config.h",
        "libcutils/include/cutils/android_get_control_file.h",
        "libcutils/include/cutils/sockets.h",
        "libcutils/socket_inaddr_any_server_unix.cpp",
        "libcutils/socket_local_client_unix.cpp",
        "libcutils/socket_local_server_unix.cpp",
        "libcutils/socket_local_unix.h",
        "libcutils/socket_network_client_unix.cpp",
        "libcutils/sockets.cpp",
        "libcutils/sockets_unix.cpp",
    ],
    hdrs = glob([
        "libcutils/include/**/*.h",
    ]),
    strip_include_prefix = "libcutils/include",
    deps = [
        "@//android:log_header",
        "@//libbase",
    ],
)
