from distutils.sysconfig import customize_compiler
from distutils import log
-LANG_EXT = {'c': '.c',
- 'c++': '.cxx'}
+LANG_EXT = {'c': '.c', 'c++': '.cxx'}
-class config (Command):
+class config(Command):
description = "prepare to build"
# The three standard command methods: since the "config" command
# does nothing by default, these are empty.
- def initialize_options (self):
+ def initialize_options(self):
self.compiler = None
self.cc = None
self.include_dirs = None
- #self.define = None
- #self.undef = None
self.libraries = None
self.library_dirs = None
# to clean at some point
self.temp_files = []
- def finalize_options (self):
+ def finalize_options(self):
if self.include_dirs is None:
self.include_dirs = self.distribution.include_dirs or []
elif type(self.include_dirs) is StringType:
# loosely based on Autoconf macros of similar names. Sub-classes
# may use these freely.
- def _check_compiler (self):
+ def _check_compiler(self):
"""Check that 'self.compiler' really is a CCompiler object;
if not, make it one.
"""
self.compiler.set_library_dirs(self.library_dirs)
- def _gen_temp_sourcefile (self, body, headers, lang):
+ def _gen_temp_sourcefile(self, body, headers, lang):
filename = "_configtest" + LANG_EXT[lang]
file = open(filename, "w")
if headers:
file.close()
return filename
- def _preprocess (self, body, headers, include_dirs, lang):
+ def _preprocess(self, body, headers, include_dirs, lang):
src = self._gen_temp_sourcefile(body, headers, lang)
out = "_configtest.i"
self.temp_files.extend([src, out])
self.compiler.preprocess(src, out, include_dirs=include_dirs)
return (src, out)
- def _compile (self, body, headers, include_dirs, lang):
+ def _compile(self, body, headers, include_dirs, lang):
src = self._gen_temp_sourcefile(body, headers, lang)
if self.dump_source:
dump_file(src, "compiling '%s':" % src)
self.compiler.compile([src], include_dirs=include_dirs)
return (src, obj)
- def _link (self, body,
- headers, include_dirs,
- libraries, library_dirs, lang):
+ def _link(self, body, headers, include_dirs, libraries, library_dirs,
+ lang):
(src, obj) = self._compile(body, headers, include_dirs, lang)
prog = os.path.splitext(os.path.basename(src))[0]
self.compiler.link_executable([obj], prog,
return (src, obj, prog)
- def _clean (self, *filenames):
+ def _clean(self, *filenames):
if not filenames:
filenames = self.temp_files
self.temp_files = []
# XXX need access to the header search path and maybe default macros.
- def try_cpp (self, body=None, headers=None, include_dirs=None, lang="c"):
+ def try_cpp(self, body=None, headers=None, include_dirs=None, lang="c"):
"""Construct a source file from 'body' (a string containing lines
of C/C++ code) and 'headers' (a list of header files to include)
and run it through the preprocessor. Return true if the
self._clean()
return ok
- def search_cpp (self, pattern, body=None,
- headers=None, include_dirs=None, lang="c"):
+ def search_cpp(self, pattern, body=None, headers=None, include_dirs=None,
+ lang="c"):
"""Construct a source file (just like 'try_cpp()'), run it through
the preprocessor, and return true if any line of the output matches
'pattern'. 'pattern' should either be a compiled regex object or a
self._clean()
return match
- def try_compile (self, body, headers=None, include_dirs=None, lang="c"):
+ def try_compile(self, body, headers=None, include_dirs=None, lang="c"):
"""Try to compile a source file built from 'body' and 'headers'.
Return true on success, false otherwise.
"""
self._clean()
return ok
- def try_link (self, body,
- headers=None, include_dirs=None,
- libraries=None, library_dirs=None,
- lang="c"):
+ def try_link(self, body, headers=None, include_dirs=None, libraries=None,
+ library_dirs=None, lang="c"):
"""Try to compile and link a source file, built from 'body' and
'headers', to executable form. Return true on success, false
otherwise.
self._clean()
return ok
- def try_run (self, body,
- headers=None, include_dirs=None,
- libraries=None, library_dirs=None,
- lang="c"):
+ def try_run(self, body, headers=None, include_dirs=None, libraries=None,
+ library_dirs=None, lang="c"):
"""Try to compile, link to an executable, and run a program
built from 'body' and 'headers'. Return true on success, false
otherwise.
# (these are the ones that are actually likely to be useful
# when implementing a real-world config command!)
- def check_func (self, func,
- headers=None, include_dirs=None,
- libraries=None, library_dirs=None,
- decl=0, call=0):
+ def check_func(self, func, headers=None, include_dirs=None,
+ libraries=None, library_dirs=None, decl=0, call=0):
"""Determine if function 'func' is available by constructing a
source file that refers to 'func', and compiles and links it.
# check_func ()
- def check_lib (self, library, library_dirs=None,
- headers=None, include_dirs=None, other_libraries=[]):
+ def check_lib(self, library, library_dirs=None, headers=None,
+ include_dirs=None, other_libraries=[]):
"""Determine if 'library' is available to be linked against,
without actually checking that any particular symbols are provided
by it. 'headers' will be used in constructing the source file to
headers, include_dirs,
[library]+other_libraries, library_dirs)
- def check_header (self, header, include_dirs=None,
- library_dirs=None, lang="c"):
+ def check_header(self, header, include_dirs=None, library_dirs=None,
+ lang="c"):
"""Determine if the system header file named by 'header_file'
exists and can be found by the preprocessor; return true if so,
false otherwise.
include_dirs=include_dirs)
-# class config
-
def dump_file(filename, head=None):
"""Dumps a file content into log.info.