code: def generic_pre_build_hook(
      cmd,
      ext,
      fcompiler_flags,
      patch_source_func=None,
      source_fnpart=None,
  ):
      """
      Pre-build hook for adding compiler flags and patching sources.
  
      Parameters
      ----------
      cmd : distutils.core.Command
          Hook input. Current distutils command (build_clib or build_ext).
      ext : dict or numpy.distutils.extension.Extension
          Hook input. Configuration information for library (dict, build_clib)
          or extension (numpy.distutils.extension.Extension, build_ext).
      fcompiler_flags : dict
          Dictionary of ``{'compiler_name': ['-flag1', ...]}`` containing
          compiler flags to set.
      patch_source_func : callable, optional
          Function patching sources, see `_generic_patch_sources` below.
      source_fnpart : str, optional
          String to append to the modified file basename before extension.
  
      """
      is_clib = isinstance(ext, dict)
  
      if is_clib:
          build_info = ext
          del ext
  
          # build_clib doesn't have separate f77/f90 compilers
          f77 = cmd._f_compiler
          f90 = cmd._f_compiler
      else:
          f77 = cmd._f77_compiler
          f90 = cmd._f90_compiler
  
      # Add compiler flags
      if is_clib:
          f77_args = build_info.setdefault("extra_f77_compile_args", [])
          f90_args = build_info.setdefault("extra_f90_compile_args", [])
          compilers = [(f77, f77_args), (f90, f90_args)]
      else:
          compilers = [
              (f77, ext.extra_f77_compile_args),
              (f90, ext.extra_f90_compile_args),
          ]
  
      for compiler, args in compilers:
          if compiler is None:
              continue
  
          try:
              flags = fcompiler_flags[compiler.compiler_type]
          except KeyError as e:
              raise RuntimeError(
                  "Compiler {!r} is not supported in this "
                  "configuration.".format(compiler.compiler_type)
              ) from e
  
          args.extend(flag for flag in flags if flag not in args)
  
      # Mangle sources
      if patch_source_func is not None:
          if is_clib:
              build_info.setdefault("depends", []).extend(
                  build_info["sources"]
              )
              new_sources = _generic_patch_sources(
                  build_info["sources"],
                  patch_source_func,
                  source_fnpart,
              )
              build_info["sources"][:] = new_sources
          else:
              ext.depends.extend(ext.sources)
              new_sources = _generic_patch_sources(
                  ext.sources, patch_source_func, source_fnpart
              )
              ext.sources[:] = new_sources
  
imports: import re
  import os
  import sys
  from distutils.util import get_platform
  import numpy
  from .system_info import combine_dict
label_desc: Use image node_id 12 for calling a global function with example usage: generic_pre_build_hook(cmd, ext, fcompiler_flags, patch_source_func, source_fnpart) without return types