from waflib import TaskGen

def build(bld):
    if bld.env.STATIC:
        obj = bld(features='cxx cxxstlib')
    else:
        obj = bld(features='cxx cxxshlib')

    obj.name = 'libsub%s' % bld.env.API_VERSION
    obj.target = 'sub%s' % bld.env.API_VERSION
    obj.uselib = 'CXML DCP BOOST_FILESYSTEM BOOST_LOCALE BOOST_REGEX ASDCPLIB_CTH'
    obj.use = 'libkumu-libsub%s libasdcp-libsub%s' % (bld.env.API_VERSION, bld.env.API_VERSION)
    obj.export_includes = ['.']
    obj.source = """
                 colour.cc
                 dcp_reader.cc
                 effect.cc
                 exceptions.cc
                 font_size.cc
                 horizontal_position.cc
                 iso6937.cc
                 iso6937_tables.cc
                 locale_convert.cc
                 rational.cc
                 raw_convert.cc
                 raw_subtitle.cc
                 reader.cc
                 reader_factory.cc
                 ssa_reader.cc
                 stl_binary_reader.cc
                 stl_binary_tables.cc
                 stl_binary_writer.cc
                 stl_text_reader.cc
                 stl_util.cc
                 sub_time.cc
                 subrip_reader.cc
                 subtitle.cc
                 util.cc
                 vertical_reference.cc
                 vertical_position.cc
                 """

    headers = """
              collect.h
              colour.h
              dcp_reader.h
              effect.h
              exceptions.h
              font_size.h
              horizontal_position.h
              horizontal_reference.h
              rational.h
              raw_subtitle.h
              reader.h
              reader_factory.h
              ssa_reader.h
              stl_binary_tables.h
              stl_binary_reader.h
              stl_binary_writer.h
              stl_text_reader.h
              sub_time.h
              subrip_reader.h
              subtitle.h
              vertical_position.h
              vertical_reference.h
              """

    bld.install_files('${PREFIX}/include/libsub%s/sub' % bld.env.API_VERSION, headers)
    if bld.env.STATIC:
        bld.install_files('${PREFIX}/lib', 'libsub%s.a' % bld.env.API_VERSION)
