def make_cygpath_function(mounts):
    """Creates a make function that can be used in place of cygpath.

    Args:
        mounts: A list of tuples decribing filesystem mounts.

    Returns:
        The body of a function implementing cygpath in make as a string.
    """
    # We're building a bunch of nested patsubst calls. Once we've written each
    # of the calls, we pass the function input to the inner most call.
    if len(mounts) == 0:
        return '$1'

    cyg_path, win_path = mounts[0]
    if not cyg_path.endswith('/'):
        cyg_path += '/'
    if not win_path.endswith('/'):
        win_path += '/'

    other_mounts = mounts[1:]
    return '$(patsubst {}%,{}%,\n{})'.format(
        cyg_path, win_path, make_cygpath_function(other_mounts))