cc_library_static {
    name: "libmpeg2dec",
    vendor_available: true,
    shared_libs: ["liblog", "libcutils"],

    cflags: [
        "-D_LIB",
        "-DMULTICORE",
        "-fPIC",

        "-O3",
        "-DANDROID",
        "-Werror",
    ],

    export_include_dirs: [
        "decoder",
        "common",
    ],

    srcs: [
        "common/impeg2_buf_mgr.c",
        "common/impeg2_disp_mgr.c",
        "common/impeg2_format_conv.c",
        "common/impeg2_globals.c",
        "common/impeg2_idct.c",
        "common/impeg2_inter_pred.c",
        "common/impeg2_job_queue.c",
        "common/impeg2_mem_func.c",
        "common/ithread.c",
        "decoder/impeg2d_api_main.c",
        "decoder/impeg2d_bitstream.c",
        "decoder/impeg2d_debug.c",
        "decoder/impeg2d_dec_hdr.c",
        "decoder/impeg2d_decoder.c",
        "decoder/impeg2d_d_pic.c",
        "decoder/impeg2d_function_selector_generic.c",
        "decoder/impeg2d_globals.c",
        "decoder/impeg2d_i_pic.c",
        "decoder/impeg2d_mc.c",
        "decoder/impeg2d_mv_dec.c",
        "decoder/impeg2d_pic_proc.c",
        "decoder/impeg2d_pnb_pic.c",
        "decoder/impeg2d_vld.c",
        "decoder/impeg2d_vld_tables.c",
        "decoder/impeg2d_deinterlace.c",
        "common/icv_sad.c",
        "common/icv_variance.c",
        "common/ideint.c",
        "common/ideint_cac.c",
        "common/ideint_debug.c",
        "common/ideint_function_selector_generic.c",
        "common/ideint_utils.c",
    ],

    arch: {
        arm: {
            local_include_dirs: [
                "decoder/arm",
                "common/arm",
            ],

            srcs: [
                "decoder/arm/impeg2d_function_selector.c",
                "common/arm/ideint_function_selector.c",
            ],

            neon: {
                srcs: [
                    "decoder/arm/impeg2d_function_selector_a9q.c",
                    "common/arm/ideint_function_selector_a9.c",
                    "common/arm/icv_sad_a9.s",
                    "common/arm/icv_variance_a9.s",
                    "common/arm/ideint_spatial_filter_a9.s",
                    "common/arm/ideint_cac_a9.s",
                    "common/arm/impeg2_format_conv.s",
                    "common/arm/impeg2_idct.s",
                    "common/arm/impeg2_inter_pred.s",
                    "common/arm/impeg2_mem_func.s",
                ],
                cflags: [
                    "-UDISABLE_NEON",
                    "-UDEFAULT_ARCH",
                    "-DDEFAULT_ARCH=D_ARCH_ARM_A9Q",
                ],
            },

            cflags: [
                "-DDISABLE_NEONINTR",
                "-DARM",
                "-DARMGCC",

                // These are overriden by armv7_a_neon
                "-DDISABLE_NEON",
                "-DDEFAULT_ARCH=D_ARCH_ARM_NONEON",
            ],
            instruction_set: "arm",
        },

        arm64: {
            cflags: [
                "-DARMV8",
                "-DDISABLE_NEONINTR",
                "-DARM",
                "-DARMGCC",

                "-DDEFAULT_ARCH=D_ARCH_ARMV8_GENERIC",
            ],
            local_include_dirs: [
                "decoder/arm",
                "common/armv8",
            ],

            srcs: [
                "decoder/arm/impeg2d_function_selector.c",
                "decoder/arm/impeg2d_function_selector_av8.c",
                "common/arm/ideint_function_selector.c",
                "common/arm/ideint_function_selector_av8.c",
                "common/armv8/icv_sad_av8.s",
                "common/armv8/icv_variance_av8.s",
                "common/armv8/ideint_spatial_filter_av8.s",
                "common/armv8/ideint_cac_av8.s",
                "common/armv8/impeg2_neon_macros.s",
                "common/armv8/impeg2_format_conv.s",
                "common/armv8/impeg2_idct.s",
                "common/armv8/impeg2_inter_pred.s",
                "common/armv8/impeg2_mem_func.s",
            ],
        },

        mips: {
            local_include_dirs: ["common/mips"],

            srcs: [
                "decoder/mips/impeg2d_function_selector.c",
                "common/mips/ideint_function_selector.c",
            ],
        },

        mips64: {
            local_include_dirs: ["common/mips"],

            srcs: [
                "decoder/mips/impeg2d_function_selector.c",
                "common/mips/ideint_function_selector.c",
            ],
        },

        x86: {
            cflags: [
                "-DX86",
                "-DDISABLE_AVX2",
                "-msse4.2",
                "-mno-avx",
                "-DDEFAULT_ARCH=D_ARCH_X86_SSE42",
            ],

            local_include_dirs: [
                "decoder/x86",
                "common/x86",
            ],

            srcs: [
                "decoder/x86/impeg2d_function_selector.c",
                "decoder/x86/impeg2d_function_selector_avx2.c",
                "decoder/x86/impeg2d_function_selector_ssse3.c",
                "decoder/x86/impeg2d_function_selector_sse42.c",
                "common/x86/ideint_function_selector.c",
                "common/x86/ideint_function_selector_ssse3.c",
                "common/x86/ideint_function_selector_sse42.c",
                "common/x86/icv_variance_ssse3.c",
                "common/x86/icv_sad_ssse3.c",
                "common/x86/ideint_cac_ssse3.c",
                "common/x86/ideint_spatial_filter_ssse3.c",
                "common/x86/impeg2_idct_recon_sse42_intr.c",
                "common/x86/impeg2_inter_pred_sse42_intr.c",
                "common/x86/impeg2_mem_func_sse42_intr.c",
            ],
        },

        x86_64: {
            cflags: [
                "-DX86",
                "-DDISABLE_AVX2",
                "-msse4.2",
                "-mno-avx",
                "-DDEFAULT_ARCH=D_ARCH_X86_SSE42",
            ],

            local_include_dirs: [
                "decoder/x86",
                "common/x86",
            ],

            srcs: [
                "decoder/x86/impeg2d_function_selector.c",
                "decoder/x86/impeg2d_function_selector_avx2.c",
                "decoder/x86/impeg2d_function_selector_ssse3.c",
                "decoder/x86/impeg2d_function_selector_sse42.c",
                "common/x86/ideint_function_selector.c",
                "common/x86/ideint_function_selector_ssse3.c",
                "common/x86/ideint_function_selector_sse42.c",
                "common/x86/icv_variance_ssse3.c",
                "common/x86/icv_sad_ssse3.c",
                "common/x86/ideint_cac_ssse3.c",
                "common/x86/ideint_spatial_filter_ssse3.c",
                "common/x86/impeg2_idct_recon_sse42_intr.c",
                "common/x86/impeg2_inter_pred_sse42_intr.c",
                "common/x86/impeg2_mem_func_sse42_intr.c",
            ],
        },
    },
    sanitize: {
        integer_overflow: true,
        misc_undefined: ["bounds"],
        // Enable CFI if this becomes a shared library.
        // cfi: true,
        blacklist: "libmpeg2dec_blacklist.txt",
    },
}

subdirs = ["test"]