import pathlib
import itertools


def all_fortran_paths(root_path: pathlib.Path):
    """Recursively find all Fortran files in a given directory."""
    if not root_path.exists():
        return []
    all_input_paths = []
    for extension in itertools.chain(
            *[(_, _.upper()) for _ in ('.f', '.f90', '.f03', '.f08', '.h')]):
        input_paths = root_path.glob('**/*{}'.format(extension))
        for input_path in input_paths:
            input_path = input_path.resolve()
            all_input_paths.append(input_path)
    return all_input_paths