// Build the ETC1 library
cc_library {
    name: "libETC1",
    srcs: ["ETC1/etc1.cpp"],
    host_supported: true,

    target: {
        android: {
            static: {
                enabled: false,
            },
        },
        host: {
            shared: {
                enabled: false,
            },
        },
        windows: {
            enabled: true,
        },
    },
}

// The headers modules are in frameworks/native/opengl/Android.bp.
ndk_library {
    name: "libEGL",
    symbol_file: "libEGL.map.txt",
    first_version: "9",
    unversioned_until: "current",
}

ndk_library {
    name: "libGLESv1_CM",
    symbol_file: "libGLESv1_CM.map.txt",
    first_version: "9",
    unversioned_until: "current",
}

ndk_library {
    name: "libGLESv2",
    symbol_file: "libGLESv2.map.txt",
    first_version: "9",
    unversioned_until: "current",
}

ndk_library {
    name: "libGLESv3",
    symbol_file: "libGLESv3.map.txt",
    first_version: "18",
    unversioned_until: "current",
}

cc_defaults {
    name: "gl_libs_defaults",
    cflags: [
        "-DGL_GLEXT_PROTOTYPES",
        "-DEGL_EGLEXT_PROTOTYPES",
        "-fvisibility=hidden",
    ],
    shared_libs: [
        // ***** DO NOT ADD NEW DEPENDENCIES HERE *****
        // In particular, DO NOT add libutils or anything "above" libcutils
        "libcutils",
        "liblog",
        "libdl",
    ],

    // we need to access the private Bionic header <bionic_tls.h>
    include_dirs: ["bionic/libc/private"],
}

//##############################################################################
// Build META EGL library
//
cc_defaults {
    name: "egl_libs_defaults",
    defaults: ["gl_libs_defaults"],
    cflags: [
        "-DLOG_TAG=\"libEGL\"",
    ],
    shared_libs: [
        // ***** DO NOT ADD NEW DEPENDENCIES HERE *****
        // In particular, DO NOT add libutils nor anything "above" libui
        "libui",
        "libnativewindow",
        "libbacktrace",
    ],
}

cc_library_static {
    name: "libEGL_getProcAddress",
    defaults: ["egl_libs_defaults"],
    srcs: ["EGL/getProcAddress.cpp"],
    arch: {
        arm: {
            instruction_set: "arm",
        },
    },
}

cc_library_shared {
    name: "libEGL",
    defaults: ["egl_libs_defaults"],
    srcs: [
        "EGL/egl_tls.cpp",
        "EGL/egl_cache.cpp",
        "EGL/egl_display.cpp",
        "EGL/egl_object.cpp",
        "EGL/egl.cpp",
        "EGL/eglApi.cpp",
        "EGL/Loader.cpp",
        "EGL/BlobCache.cpp",
    ],
    shared_libs: ["libvndksupport"],
    static_libs: ["libEGL_getProcAddress"],
    ldflags: ["-Wl,--exclude-libs=ALL"],
    export_include_dirs: ["EGL/include"],
}

cc_test {
    name: "libEGL_test",
    defaults: ["egl_libs_defaults"],
    srcs: [
        "EGL/BlobCache.cpp",
        "EGL/BlobCache_test.cpp",
    ],
}

cc_defaults {
    name: "gles_libs_defaults",
    defaults: ["gl_libs_defaults"],
    arch: {
        arm: {
            instruction_set: "arm",

            // TODO: This is to work around b/20093774. Remove after root cause is fixed
            ldflags: ["-Wl,--hash-style,both"],
        },
    },
    shared_libs: ["libEGL"],
}

//##############################################################################
// Build the wrapper OpenGL ES 1.x library
//
cc_library_shared {
    name: "libGLESv1_CM",
    defaults: ["gles_libs_defaults"],
    srcs: ["GLES_CM/gl.cpp"],
    cflags: ["-DLOG_TAG=\"libGLESv1\""],
}

//##############################################################################
// Build the wrapper OpenGL ES 2.x library
//
cc_library_shared {
    name: "libGLESv2",
    defaults: ["gles_libs_defaults"],
    srcs: ["GLES2/gl2.cpp"],
    cflags: ["-DLOG_TAG=\"libGLESv2\""],
}

//##############################################################################
// Build the wrapper OpenGL ES 3.x library (this is just different name for v2)
//
cc_library_shared {
    name: "libGLESv3",
    defaults: ["gles_libs_defaults"],
    srcs: ["GLES2/gl2.cpp"],
    cflags: ["-DLOG_TAG=\"libGLESv3\""],
}
