//
// Copyright (C) 2018 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

cc_defaults {
    name: "libsnapshot_defaults",
    defaults: ["fs_mgr_defaults"],
    cflags: [
        "-D_FILE_OFFSET_BITS=64",
        "-Wall",
        "-Werror",
    ],
    shared_libs: [
        "libbase",
        "liblog",
        "liblp",
    ],
    static_libs: [
        "libcutils",
        "libdm",
        "libfs_mgr",
        "libfstab",
        "liblp",
        "update_metadata-protos",
    ],
    whole_static_libs: [
        "libext2_uuid",
        "libext4_utils",
        "libfstab",
    ],
    header_libs: [
        "libfiemap_headers",
    ],
    export_static_lib_headers: [
        "update_metadata-protos",
    ],
    export_header_lib_headers: [
        "libfiemap_headers",
    ],
    export_include_dirs: ["include"],
    proto: {
        type: "lite",
        export_proto_headers: true,
        canonical_path_from_root: false,
    },
}

cc_defaults {
    name: "libsnapshot_hal_deps",
    cflags: [
        "-DLIBSNAPSHOT_USE_HAL",
    ],
    shared_libs: [
        "android.hardware.boot@1.0",
        "android.hardware.boot@1.1",
    ],
}

filegroup {
    name: "libsnapshot_sources",
    srcs: [
        "android/snapshot/snapshot.proto",
        "snapshot.cpp",
        "snapshot_metadata_updater.cpp",
        "partition_cow_creator.cpp",
        "utility.cpp",
    ],
}

cc_library_headers {
    name: "libsnapshot_headers",
    recovery_available: true,
    defaults: ["libsnapshot_defaults"],
}

cc_library_static {
    name: "libsnapshot",
    defaults: [
        "libsnapshot_defaults",
        "libsnapshot_hal_deps",
    ],
    srcs: [":libsnapshot_sources"],
    whole_static_libs: [
        "libfiemap_binder",
    ],
}

cc_library_static {
    name: "libsnapshot_init",
    defaults: ["libsnapshot_defaults"],
    srcs: [":libsnapshot_sources"],
    recovery_available: true,
    whole_static_libs: [
        "libfiemap_passthrough",
    ],
}

cc_library_static {
    name: "libsnapshot_nobinder",
    defaults: [
        "libsnapshot_defaults",
        "libsnapshot_hal_deps",
    ],
    srcs: [":libsnapshot_sources"],
    recovery_available: true,
    whole_static_libs: [
        "libfiemap_passthrough",
    ],
}

cc_test {
    name: "libsnapshot_test",
    defaults: ["libsnapshot_defaults"],
    srcs: [
        "snapshot_test.cpp",
        "partition_cow_creator_test.cpp",
        "snapshot_metadata_updater_test.cpp",
        "test_helpers.cpp",
    ],
    shared_libs: [
        "libbinder",
        "libhidlbase",
        "libprotobuf-cpp-lite",
        "libutils",
    ],
    static_libs: [
        "android.hardware.boot@1.0",
        "android.hardware.boot@1.1",
        "libcrypto_static",
        "libfs_mgr",
        "libgmock",
        "liblp",
        "libsnapshot",
        "libsparse",
        "libz",
    ],
    header_libs: [
        "libstorage_literals_headers",
    ],
}

cc_binary {
    name: "snapshotctl",
    srcs: [
        "snapshotctl.cpp",
    ],
    static_libs: [
        "libdm",
        "libext2_uuid",
        "libfiemap_binder",
        "libfstab",
        "libsnapshot",
    ],
    shared_libs: [
        "android.hardware.boot@1.0",
        "android.hardware.boot@1.1",
        "libbase",
        "libbinder",
        "libbinderthreadstate",
        "libext4_utils",
        "libfs_mgr",
        "libhidlbase",
        "liblog",
        "liblp",
        "libprotobuf-cpp-lite",
        "libutils",
    ],
    init_rc: [
        "snapshotctl.rc",
    ],
}
