// Copyright 2017 The Android Open Source Project

// Library used to export files from this directory to other programs in this
// project.
package {
    // See: http://go/android-license-faq
    // A large-scale-change added 'default_applicable_licenses' to import
    // all of the 'license_kinds' from "external_e2fsprogs_license"
    // to get the below license kinds:
    //   SPDX-license-identifier-GPL
    //   SPDX-license-identifier-LGPL
    //   SPDX-license-identifier-LGPL-2.1
    //   SPDX-license-identifier-LGPL-3.0
    default_applicable_licenses: ["external_e2fsprogs_license"],
}

cc_library {
    name: "libext2_misc",
    host_supported: true,
    recovery_available: true,
    defaults: ["e2fsprogs-defaults"],

    target: {
        windows: {
            enabled: true,
        },
    },

    srcs: [
        "create_inode.c",
    ],
    shared_libs: [
        "libext2fs",
        "libext2_com_err",
        "libext2_quota",
    ],
    export_include_dirs: ["."],
}

//########################################################################
// Build mke2fs

cc_defaults {
    name: "mke2fs_defaults",
    recovery_available: true,
    defaults: ["e2fsprogs-defaults"],

    srcs: [
        "mke2fs.c",
        "util.c",
        "mk_hugefiles.c",
        "default_profile.c",
    ],
    stl: "libc++_static",
    include_dirs: ["external/e2fsprogs/e2fsck"],
}

cc_binary {
    name: "mke2fs",
    host_supported: true,
    defaults: ["mke2fs_defaults"],
    target: {
        host: {
            static_libs: [
                "libext2_blkid",
                "libext2_misc",
                "libext2_uuid",
                "libext2_quota",
                "libext2_com_err",
                "libext2_e2p",
                "libext2fs",
                "libsparse",
                "libbase",
                "libz",
            ],
        },
        not_windows: {
            required: [
                "mke2fs.conf",
            ],
        },
        windows: {
            ldflags: ["-static"],
            enabled: true,
        },
        android: {
            required: [
                "mke2fs.conf",
            ],
            shared_libs: [
                "libext2fs",
                "libext2_blkid",
                "libext2_misc",
                "libext2_uuid",
                "libext2_quota",
                "libext2_com_err",
                "libext2_e2p",
            ],
            symlinks: [
                "mkfs.ext2",
                "mkfs.ext3",
                "mkfs.ext4",
            ],
        },
    },
}

cc_binary {
    name: "mke2fs.microdroid",
    defaults: ["mke2fs_defaults"],
    bootstrap: true,
    target: {
        android: {
            required: [
                "mke2fs.conf",
            ],
            shared_libs: [
                "libext2fs",
                "libext2_blkid",
                "libext2_misc",
                "libext2_uuid",
                "libext2_quota",
                "libext2_com_err",
                "libext2_e2p",
            ],
            symlinks: ["mkfs.ext4.microdroid"],
        },
    },
    installable: false,
    stem: "mke2fs",
    visibility: ["//packages/modules/Virtualization/microdroid"],
}

//##########################################################################
// Build tune2fs

cc_defaults {
    name: "tune2fs-defaults",
    defaults: ["e2fsprogs-defaults"],
    srcs: [
        "tune2fs.c",
        "util.c",
    ],
    cflags: ["-DNO_RECOVERY"],
    include_dirs: ["external/e2fsprogs/e2fsck"],
}

tune2fs_libs = [
    "libext2_blkid",
    "libext2_com_err",
    "libext2_quota",
    "libext2_uuid",
    "libext2_e2p",
    "libext2fs",
]

cc_binary {
    name: "tune2fs",
    host_supported: true,
    vendor_ramdisk_available: true,
    defaults: ["tune2fs-defaults"],

    shared_libs: tune2fs_libs,
}

cc_binary {
    name: "tune2fs_static",
    static_executable: true,
    defaults: ["tune2fs-defaults"],

    static_libs: tune2fs_libs,
}

cc_binary {
    name: "tune2fs_ramdisk",
    stem: "tune2fs",
    static_executable: true,
    ramdisk: true,
    defaults: ["tune2fs-defaults"],
    static_libs: tune2fs_libs,
}

cc_library_static {
    name: "libtune2fs",
    defaults: ["tune2fs-defaults"],

    cflags: ["-DBUILD_AS_LIB"],
    static_libs: tune2fs_libs,
}

//########################################################################
// Build badblocks

cc_binary {
    name: "badblocks",
    host_supported: true,
    defaults: ["e2fsprogs-defaults"],

    srcs: ["badblocks.c"],
    shared_libs: [
        "libext2fs",
        "libext2_com_err",
        "libext2_uuid",
        "libext2_blkid",
        "libext2_e2p",
    ],
}

//########################################################################
// Build chattr

cc_binary {
    name: "chattr-e2fsprogs",
    host_supported: true,
    defaults: ["e2fsprogs-defaults"],

    srcs: ["chattr.c"],
    shared_libs: [
        "libext2_com_err",
        "libext2_e2p",
    ],
}

//########################################################################
// Build lsattr

cc_defaults {
    name: "lsattr-defaults",
    srcs: ["lsattr.c"],
    defaults: ["e2fsprogs-defaults"],
}

lsattr_libs = [
    "libext2_com_err",
    "libext2_e2p",
]

cc_binary {
    name: "lsattr-e2fsprogs",
    host_supported: true,
    defaults: ["lsattr-defaults"],

    shared_libs: lsattr_libs,
}

cc_binary {
    name: "lsattr_static",
    static_executable: true,
    defaults: ["lsattr-defaults"],

    static_libs: lsattr_libs,
}

//########################################################################
// Build blkid

cc_binary {
    name: "blkid",
    host_supported: true,
    defaults: ["e2fsprogs-defaults"],

    srcs: ["blkid.c"],
    shared_libs: [
        "libext2fs",
        "libext2_blkid",
        "libext2_com_err",
        "libext2_e2p",
    ],
}

cc_binary {
    name: "blkid_static",
    host_supported: true,
    static_executable: true,
    defaults: ["e2fsprogs-defaults"],

    srcs: ["blkid.c"],
    static_libs: [
        "libext2fs",
        "libext2_blkid",
        "libext2_com_err",
        "libext2_e2p",
        "libext2_uuid",
    ],
}

//########################################################################
// Build e4crypt

cc_binary {
    name: "e4crypt",
    host_supported: true,
    defaults: ["e2fsprogs-defaults"],

    srcs: ["e4crypt.c"],
    shared_libs: [
        "libext2fs",
        "libext2_uuid",
    ],

    target: {
        darwin: {
            enabled: false,
        },
    },
}

//##########################################################################
// Build e2image

cc_binary {
    name: "e2image",
    host_supported: true,
    defaults: ["e2fsprogs-defaults"],

    srcs: ["e2image.c"],
    shared_libs: [
        "libext2fs",
        "libext2_blkid",
        "libext2_com_err",
        "libext2_quota",
    ],
}

//##########################################################################
// Build filefrag

cc_binary {
    name: "filefrag",
    host_supported: true,
    defaults: ["e2fsprogs-defaults"],

    srcs: ["filefrag.c"],
    shared_libs: [
        "libext2fs",
    ],
}

//##########################################################################
// Build e2freefrag

cc_binary {
    name: "e2freefrag",
    host_supported: true,
    defaults: ["e2fsprogs-defaults"],

    srcs: [
        "e2freefrag.c",
    ],
    header_libs: ["libext2-headers"],
    shared_libs: [
        "libext2fs",
        "libext2_com_err",
    ],
}
