def hs_library_pattern(name, mode = "static", profiling = False):
    """Convert hs-libraries entry to glob patterns.

    Args:
        name: The library name. E.g. HSrts or Cffi.
        mode: The linking mode. Either "static" or "dynamic".
        profiling: Look for profiling mode libraries.

    Returns:
        List of globbing patterns for the library file.

    """
    # The RTS configuration suffix.
    # See https://gitlab.haskell.org/ghc/ghc/wikis/commentary/rts/config#rts-configurations
    configs = ["_p"] if profiling else [""]
    # Special case HSrts or Cffi - include both libXYZ and libXYZ_thr.
    if name == "HSrts" or name == "Cffi":
        configs = [
            prefix + config
            for config in configs
            for prefix in ["", "_thr"]
        ]
    # Special case libCffi - dynamic lib has no configs and is called libffi.
    if name == "Cffi" and mode == "dynamic":
        libname = "ffi"
        configs = [""]
    else:
        libname = name
    libnames = [libname + config for config in configs]
    # Special case libCffi - dynamic lib has no version suffix.
    if mode == "dynamic" and name != "Cffi":
        libnames = [libname + "-ghc*" for libname in libnames]
    if mode == "dynamic":
        exts = ["so", "so.*", "dylib", "dll"]
    else:
        exts = ["a"]
    return [
        "lib{}.{}".format(libname, ext)
        for libname in libnames
        for ext in exts
    ]