def license_destination(config, libname, filename):
    """Given the (reconstructed) library name, find appropriate destination"""
    normal = config.vendor_dir / libname
    if normal.is_dir():
        return normal / filename
    lowercase = config.vendor_dir / libname.lower()
    if lowercase.is_dir():
        return lowercase / filename
    if libname in config.library_dirnames:
        return config.vendor_dir / config.library_dirnames[libname] / filename
    return config.vendor_dir / '{}.{}'.format(libname, filename)
