def METHOD_NAME(gnu_dir):
    r_internals_h = join(gnu_dir, 'Rinternals.h')
    with open(r_internals_h) as f:
        lines = f.readlines()
    use_rinternals_count = 0
    with open('Rinternals.h', 'w') as f:
        for line in lines:
            if '== USE_RINTERNALS section' in line:
                f.write(use_internals_section_and_glob_var_api)
                f.write(line)
                f.write('#endif\n')
            elif 'typedef struct SEXPREC *SEXP' in line:
                f.write(line)
                f.write(sexp)
            elif '#ifdef USE_RINTERNALS' in line:
                if use_rinternals_count > 0:
                    f.write(use_internals_begin)
                else:
                    f.write(line)
                    use_rinternals_count = 1
            elif 'macro version of R_CheckStack' in line:
                f.write(use_internals_end)
                f.write(line)
            elif 'LibExtern' in line:
                var = is_internal_var(line)
                if var:
                    rewrite_var(f, var, line)
                else:
                    f.write(line)
            else:
                f.write(line)