code: def gfortran_search_path(library_dirs):
      
      cmd = ("gfortran", "-print-search-dirs")
      process = subprocess.Popen(cmd, stdout=subprocess.PIPE)
      return_code = process.wait()
      # Bail out if the command failed.
      if return_code != 0:
          return library_dirs
  
      cmd_output = process.stdout.read().decode("utf-8")
      # Find single line starting with ``libraries: ``.
      search_lines = cmd_output.strip().split("\n")
      library_lines = [
          line[len(FORTRAN_LIBRARY_PREFIX) :]
          for line in search_lines
          if line.startswith(FORTRAN_LIBRARY_PREFIX)
      ]
      if len(library_lines) != 1:
          msg = GFORTRAN_MISSING_LIBS.format(cmd_output)
          print(msg, file=sys.stderr)
          return library_dirs
  
      # Go through each library in the ``libraries: = ...`` line.
      library_line = library_lines[0]
      accepted = set(library_dirs)
      for part in library_line.split(os.pathsep):
          full_path = os.path.abspath(part.strip())
          if os.path.isdir(full_path):
              accepted.add(full_path)
          else:
              # Ignore anything that isn't a directory.
              msg = GFORTRAN_BAD_PATH.format(full_path)
              print(msg, file=sys.stderr)
      return sorted(accepted)
docs: Get the library directory paths for ``gfortran``.
  
      Looks for ``libraries: =`` in the output of ``gfortran -print-search-dirs``
      and then parses the paths. If this fails for any reason, this method will
      print an error and return ``library_dirs``.
  
      Args:
          library_dirs (List[str]): Existing library directories.
  
      Returns:
          List[str]: The library directories for ``gfortran``.