docs: def get_c_extension(support_legacy=False, system_zstd=False, name='zstd',
                      warnings_as_errors=False, root=None):
      """Obtain a distutils.extension.Extension for the C extension.
  
      ``support_legacy`` controls whether to compile in legacy zstd format support.
  
      ``system_zstd`` controls whether to compile against the system zstd library.
      For this to work, the system zstd library and headers must match what
      python-zstandard is coded against exactly.
  
      ``name`` is the module name of the C extension to produce.
  
      ``warnings_as_errors`` controls whether compiler warnings are turned into
      compiler errors.
  
      ``root`` defines a root path that source should be computed as relative
      to. This should be the directory with the main ``setup.py`` that is
      being invoked. If not defined, paths will be relative to this file.
      """
      actual_root = os.path.abspath(os.path.dirname(__file__))
      root = root or actual_root
  
      sources = set([os.path.join(actual_root, p) for p in ext_sources])
      if not system_zstd:
          sources.update([os.path.join(actual_root, p) for p in zstd_sources])
          if support_legacy:
              sources.update([os.path.join(actual_root, p)
                              for p in zstd_sources_legacy])
      sources = list(sources)
  
      include_dirs = set([os.path.join(actual_root, d) for d in ext_includes])
      if not system_zstd:
          include_dirs.update([os.path.join(actual_root, d)
                               for d in zstd_includes])
          if support_legacy:
              include_dirs.update([os.path.join(actual_root, d)
                                   for d in zstd_includes_legacy])
      include_dirs = list(include_dirs)
  
      depends = [os.path.join(actual_root, p) for p in zstd_depends]
  
      compiler = distutils.ccompiler.new_compiler()
  
      # Needed for MSVC.
      if hasattr(compiler, 'initialize'):
          compiler.initialize()
  
      if compiler.compiler_type == 'unix':
          compiler_type = 'unix'
      elif compiler.compiler_type == 'msvc':
          compiler_type = 'msvc'
      elif compiler.compiler_type == 'mingw32':
          compiler_type = 'mingw32'
      else:
          raise Exception('unhandled compiler type: %s' %
                          compiler.compiler_type)
  
      extra_args = ['-DZSTD_MULTITHREAD']
  
      if not system_zstd:
          extra_args.append('-DZSTDLIB_VISIBILITY=')
          extra_args.append('-DZDICTLIB_VISIBILITY=')
          extra_args.append('-DZSTDERRORLIB_VISIBILITY=')
  
          if compiler_type == 'unix':
              extra_args.append('-fvisibility=hidden')
  
      if not system_zstd and support_legacy:
          extra_args.append('-DZSTD_LEGACY_SUPPORT=1')
  
      if warnings_as_errors:
          if compiler_type in ('unix', 'mingw32'):
              extra_args.append('-Werror')
          elif compiler_type == 'msvc':
              extra_args.append('/WX')
          else:
              assert False
  
      libraries = ['zstd'] if system_zstd else []
  
      # Python 3.7 doesn't like absolute paths. So normalize to relative.
      sources = [os.path.relpath(p, root) for p in sources]
      include_dirs = [os.path.relpath(p, root) for p in include_dirs]
      depends = [os.path.relpath(p, root) for p in depends]
  
      # TODO compile with optimizations.
      return Extension(name, sources,
                       include_dirs=include_dirs,
                       depends=depends,
                       extra_compile_args=extra_args,
                       libraries=libraries)