package {
    default_applicable_licenses: ["external_libvpx_license"],
}

// Added automatically by a large-scale-change that took the approach of
// 'apply every license found to every target'. While this makes sure we respect
// every license restriction, it may not be entirely correct.
//
// e.g. GPL in an MIT project might only apply to the contrib/ directory.
//
// Please consider splitting the single license below into multiple licenses,
// taking care not to lose any license_kind information, and overriding the
// default license using the 'licenses: [...]' property on targets as needed.
//
// For unused files, consider creating a 'fileGroup' with "//visibility:private"
// to attach the license to, and including a comment whether the files may be
// used in the current project.
// See: http://go/android-license-faq
license {
    name: "external_libvpx_license",
    visibility: [":__subpackages__"],
    license_kinds: [
        "SPDX-license-identifier-BSD",
        "SPDX-license-identifier-ISC",
        "legacy_unencumbered",
    ],
    license_text: [
        "NOTICE",
    ],
}

cc_defaults {
    name: "libvpx_defaults",

    cflags: [
        "-O3",
    ],

    min_sdk_version: "29",
    apex_available: [
        "//apex_available:platform",
        "com.android.media.swcodec",
    ],

    target: {
        darwin: {
            enabled: false,
        },
        android: {
            sanitize: {
                cfi: true,
                config: {
                    cfi_assembly_support: true,
                },
            },
        },
    },

    arch: {
        // configured to require the neon unit
        arm: {
            local_include_dirs: ["config/arm-neon"],
        },

        arm64: {
            local_include_dirs: ["config/arm64"],
        },

        riscv64: {
            local_include_dirs: ["config/generic"],
        },

        x86: {
            local_include_dirs: ["config/x86"],
        },

        x86_64: {
            local_include_dirs: ["config/x86_64"],
        },
    },
}

cc_library_static {
    name: "libvpx_neon_dotprod",
    defaults: ["libvpx_defaults"],
    host_supported: true,
    vendor_available: true,
    visibility: ["//visibility:private"],

    cflags: [
        "-Xclang -target-feature",
        // This comment prevents bpfmt from sorting the flags incorrectly.
        "-Xclang +dotprod",
    ],

    arch: {
        arm64: {
            srcs: libvpx_arm64_neon_dotprod_c_srcs,
        },
    },
}

cc_library_static {
    name: "libvpx_neon_i8mm",
    defaults: ["libvpx_defaults"],
    host_supported: true,
    vendor_available: true,
    visibility: ["//visibility:private"],

    cflags: [
        "-Xclang -target-feature",
        // This comment prevents bpfmt from sorting the flags incorrectly.
        "-Xclang +dotprod",
        // This comment prevents bpfmt from sorting the flags incorrectly.
        "-Xclang -target-feature",
        // This comment prevents bpfmt from sorting the flags incorrectly.
        "-Xclang +i8mm",
    ],

    arch: {
        arm64: {
            srcs: libvpx_arm64_neon_i8mm_c_srcs,
        },
    },
}

cc_library {
    name: "libvpx",
    defaults: [ "libvpx_defaults" ],
    vendor_available: true,
    host_supported: true,
    version_script: "exports.lds",

    arch: {
        // configured to require the neon unit
        arm: {
            // Want arm, not thumb, optimized
            instruction_set: "arm",

            srcs: libvpx_arm_neon_c_srcs + libvpx_arm_neon_asm_srcs,
        },

        arm64: {
            srcs: libvpx_arm64_c_srcs,
            whole_static_libs: [
                "libvpx_neon_dotprod",
                "libvpx_neon_i8mm",
            ],
        },

        riscv64: {
            srcs: libvpx_generic_c_srcs,
        },

        x86: {
            srcs: libvpx_x86_c_srcs + libvpx_x86_asm_srcs,
            cflags: [
                "-mssse3",
            ],
        },

        x86_64: {
            srcs: libvpx_x86_64_c_srcs + libvpx_x86_64_asm_srcs,
            cflags: [
                "-mssse3",
            ],
        },
    },

    cflags: [
        "-Wno-unused-parameter",
    ],

    export_include_dirs: ["."],

    sanitize: {
        integer_overflow: true,
        misc_undefined: ["bounds"],
        blocklist: "libvpx_blocklist.txt",
    },
}

cc_library {
    name: "libvpxrc",
    defaults: [ "libvpx_defaults" ],
    vendor_available: true,
    static_libs: [ "libvpx" ],

    arch: {
        x86_64: {
            srcs: libvpxrc_x86_64_c_srcs +
                libvpxrc_x86_64_cc_srcs +
                libvpxrc_x86_64_asm_srcs,
            cflags: [
                "-mssse3",
            ],
        },
    },

    export_include_dirs: ["."],
}

cc_library_headers {
    name: "libvpx_headers",
    vendor_available: true,
    host_supported: true,

    arch: {
        arm: {
            export_include_dirs: ["config/arm-neon"],
        },

        arm64: {
            export_include_dirs: ["config/arm64"],
        },

        riscv64: {
            export_include_dirs: ["config/generic"],
        },

        x86: {
            export_include_dirs: ["config/x86"],
        },

        x86_64: {
            export_include_dirs: ["config/x86_64"],
        },
    },

    export_include_dirs: ["."],
}

cc_fuzz {
    name: "vp9_dec_fuzzer",
    defaults: [ "libvpx_defaults" ],
    host_supported: true,
    srcs: [
        "examples/vpx_dec_fuzzer.cc",
    ],

    cflags: ["-DDECODER=vp9"],
    static_libs: [
        "libvpx",
    ],
}

cc_fuzz {
    name: "vp8_dec_fuzzer",
    defaults: [ "libvpx_defaults" ],
    host_supported: true,
    srcs: [
        "examples/vpx_dec_fuzzer.cc",
    ],

    cflags: ["-DDECODER=vp8"],
    static_libs: [
        "libvpx",
    ],
}
