from conan.tools.scm import Git
from conan import ConanFile, tools
from conan.tools.gnu import AutotoolsToolchain, Autotools
from conan.tools.layout import basic_layout


class rnnoiseConan(ConanFile):
    name = "rnnoise"
    package_type = "library"
    user = "aurora"

    # Optional metadata
    license = "BSD-3-Clause"
    author = "Angelica Volkova <angelica.volkova@fruct.org>"
    url = "https://gitverse.ru/auroraos/mirror_rnnoise"
    description = "Recurrent neural network for audio noise reduction."
    topics = ("noise-suppression", "neural-network", "audio")

    # Binary configuration
    settings = "os", "compiler", "build_type", "arch"
    options = {"shared": [True]}


    def source(self):
        git = Git(self)
        git.clone(url="https://github.com/desktop-app/rnnoise.git", target=".")
        branch = self.conan_data["sources"][self.version]["commit"]
        git.checkout(commit=branch)

    def layout(self):
        basic_layout(self)

    def generate(self):
        at_toolchain = AutotoolsToolchain(self)
        at_toolchain.generate()

    def build(self):
        autotools = Autotools(self)
        autotools.autoreconf()
        autotools.configure(args=['--disable-static'])
        autotools.make()

    def package(self):
        autotools = Autotools(self)
        autotools.install()

    def package_info(self):
        self.cpp_info.libs = ["rnnoise"]
