import argparse
import os
import platform


def _print_exists(filename):
    """Prints the names of missing files.

    Return False if anything is missing else return True.
    """
    if os.path.exists(filename):
        print(f"FOUND: {filename}")
        return True
    else:
        print(f"ERROR: {filename} is MISSING!")
        return False


def libraries_exist(major, minor, patch):
    """Check that the AVIF library is installed for given version.

    Return False if anything is missing else return True.

    NOTE: libavif release number does not match the shared library version.
    """
    exists = True

    filename = os.path.join(os.environ['PREFIX'], 'lib', 'libavif')

    if platform.system() == 'Darwin':
        for library in [
                f'{filename}.dylib',
                f'{filename}.{major}.dylib',
                f'{filename}.{major}.{minor}.{patch}.dylib',
        ]:
            exists = exists and _print_exists(library)
    elif platform.system() == 'Windows':
        exists = exists and _print_exists(
            os.path.join(os.environ['PREFIX'], 'lib', 'avif.lib'))
        exists = exists and _print_exists(
            os.path.join(os.environ['PREFIX'], 'bin', 'avif.dll'))
    else:  # Linux
        for library in [
                f'{filename}.so',
                f'{filename}.so.{major}',
                f'{filename}.so.{major}.{minor}.{patch}',
        ]:
            exists = exists and _print_exists(library)

    return exists


def cmake_config_exist():
    """Checks that CMAKE config and pkgconfig files were installed.

    Return False if anything is missing else return True.
    """
    exists = True

    exists = exists and _print_exists(
        os.path.join(os.environ['PREFIX'], 'lib', 'pkgconfig', 'libavif.pc'))

    for middle in [
            '',
            '-release',
            '-version',
    ]:
        exists = exists and _print_exists(
            os.path.join(os.environ['PREFIX'], 'lib', 'cmake', 'libavif',
                         f'libavif-config{middle}.cmake'))

    return exists


def headers_exist():
    return _print_exists(
        os.path.join(os.environ['PREFIX'], 'include', 'avif', 'avif.h'))


if __name__ == '__main__':
    parser = argparse.ArgumentParser(
        description='Check whether libavif has all components installed.')
    parser.add_argument('MAJOR', type=int, help='Major library version')
    parser.add_argument('MINOR', type=int, help='Minor library version')
    parser.add_argument('PATCH', type=int, help='Patch library version')
    args = parser.parse_args()
    assert (libraries_exist(args.MAJOR, args.MINOR, args.PATCH)
            and headers_exist()
            and cmake_config_exist()), "There are libavif files missing!"

@@ -365,16 +365,24 @@
 s_exist(
+prefix, 
 major, m
@@ -653,36 +653,22 @@
 th.join(
-os.environ%5B'PREFIX'%5D
+prefix
 , 'lib',
@@ -1061,36 +1061,22 @@
 th.join(
-os.environ%5B'PREFIX'%5D
+prefix
 , 'lib',
@@ -1157,36 +1157,22 @@
 th.join(
-os.environ%5B'PREFIX'%5D
+prefix
 , 'bin',
@@ -1690,36 +1690,22 @@
 th.join(
-os.environ%5B'PREFIX'%5D
+prefix
 , 'lib',
@@ -1893,36 +1893,22 @@
 th.join(
-os.environ%5B'PREFIX'%5D
+prefix
 , 'lib',
@@ -2022,24 +2022,30 @@
 aders_exist(
+prefix
 ):%0A    retur
@@ -2056,33 +2056,24 @@
 rint_exists(
-%0A        
 os.path.join
@@ -2077,28 +2077,14 @@
 oin(
-os.environ%5B'PREFIX'%5D
+prefix
 , 'i
@@ -2503,16 +2503,149 @@
 _args()%0A
+    if platform.system() == 'Windows':%0A        prefix = os.environ%5B'LIBRARY_PREFIX'%5D%0A    else:%0A        prefix = os.environ%5B'PREFIX'%5D%0A
     asse
@@ -2664,16 +2664,24 @@
 s_exist(
+prefix, 
 args.MAJ
@@ -2738,16 +2738,22 @@
 s_exist(
+prefix
 )%0A      
@@ -2781,16 +2781,22 @@
 g_exist(
+prefix
 )), %22The

Modify check-exists to check new Windows prefix