def has_flag(compiler, flagname):
import tempfile<EOL>with tempfile.NamedTemporaryFile('<STR_LIT:w>', suffix='<STR_LIT>') as f:<EOL><INDENT>f.write('<STR_LIT>')<EOL>try:<EOL><INDENT>compiler.compile([f.name], extra_postargs=[flagname])<EOL><DEDENT>except setuptools.distutils.errors.CompileError:<EOL><INDENT>return False<EOL><DEDENT><DEDENT>return True<EOL>
r'''
  Check if a compiler supports a certain flag. Returns ``True`` or ``False``.

  The function creates a temporary file and tries compiling with the compiler flag.

  (c) Sylvain Corlay, https://github.com/pybind/python_example