from __future__ import absolute_import, print_function

__copyright__ = """
Copyright (C) 2009-15 Andreas Kloeckner
Copyright (C) 2013 Marko Bencun
Copyright (C) 2014 Yuyi Chao
"""

__license__ = """
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
"""


from cffi import FFI

ffi = FFI()


with open("cl_types.h", "rt") as f:
    ffi.cdef(f.read())

if {CL_ENABLE_GL}:
    with open("cl_gl_types.h") as f:
        ffi.cdef(f.read())

with open("src/c_wrapper/wrap_cl_core.h", "rt") as f:
    ffi.cdef(f.read())

if {CL_ENABLE_GL}:
    with open("src/c_wrapper/wrap_cl_gl_core.h") as f:
        ffi.cdef(f.read())

ffi.set_source("pyopencl._cffi",
        """
        #include "wrap_cl.h"
        """,
        define_macros=list({EXTRA_DEFINES}.items()),
        include_dirs=(
            {CL_INC_DIR} + ["src/c_wrapper/"]),
        library_dirs={CL_LIB_DIR},
        libraries={CL_LIBNAME},
        extra_compile_args=({CXXFLAGS}),
        extra_link_args={LDFLAGS},
        source_extension=".cpp",
        sources=[
            "src/c_wrapper/wrap_cl.cpp",
            "src/c_wrapper/wrap_constants.cpp",
            "src/c_wrapper/bitlog.cpp",
            "src/c_wrapper/pyhelper.cpp",
            "src/c_wrapper/platform.cpp",
            "src/c_wrapper/device.cpp",
            "src/c_wrapper/context.cpp",
            "src/c_wrapper/command_queue.cpp",
            "src/c_wrapper/event.cpp",
            "src/c_wrapper/memory_object.cpp",
            "src/c_wrapper/svm.cpp",
            "src/c_wrapper/image.cpp",
            "src/c_wrapper/gl_obj.cpp",
            "src/c_wrapper/memory_map.cpp",
            "src/c_wrapper/buffer.cpp",
            "src/c_wrapper/sampler.cpp",
            "src/c_wrapper/program.cpp",
            "src/c_wrapper/kernel.cpp",
            "src/c_wrapper/debug.cpp",
            ]
        )


if __name__ == "__main__":
    ffi.compile()
