def get_global_options(lang: str,
                       comp: T.Type[Compiler],
                       for_machine: MachineChoice,
                       env: 'Environment') -> dict[OptionKey, options.AnyOptionType]:
    """Retrieve options that apply to all compilers for a given language."""
    description = f'Extra arguments passed to the {lang}'
    argkey = OptionKey(f'{lang}_args', machine=for_machine)
    largkey = OptionKey(f'{lang}_link_args', machine=for_machine)

    comp_args_from_envvar = False
    comp_options = env.coredata.optstore.get_pending_value(argkey)
    if comp_options is None:
        comp_args_from_envvar = True
        comp_options = env.env_opts.get(argkey, [])

    link_args_from_envvar = False
    link_options = env.coredata.optstore.get_pending_value(largkey)
    if link_options is None:
        link_args_from_envvar = True
        link_options = env.env_opts.get(largkey, [])

    assert isinstance(comp_options, (str, list)), 'for mypy'
    assert isinstance(link_options, (str, list)), 'for mypy'

    cargs = options.UserStringArrayOption(
        argkey.name,
        description + ' compiler',
        comp_options, split_args=True, allow_dups=True)

    largs = options.UserStringArrayOption(
        largkey.name,
        description + ' linker',
        link_options, split_args=True, allow_dups=True)

    if comp.INVOKES_LINKER and comp_args_from_envvar and link_args_from_envvar:
        # If the compiler acts as a linker driver, and we're using the
        # environment variable flags for both the compiler and linker
        # arguments, then put the compiler flags in the linker flags as well.
        # This is how autotools works, and the env vars feature is for
        # autotools compatibility.
        largs.extend_value(comp_options)

    opts: dict[OptionKey, options.AnyOptionType] = {argkey: cargs, largkey: largs}

    return opts
Retrieve options that apply to all compilers for a given language.
mesonbuild/compilers/compilers.py