summaryrefslogtreecommitdiffstats
path: root/Lib/distutils/ccompiler.py
diff options
context:
space:
mode:
authorSkip Montanaro <skip@pobox.com>2003-04-24 19:49:23 (GMT)
committerSkip Montanaro <skip@pobox.com>2003-04-24 19:49:23 (GMT)
commitfa012610c443338da52080e9f05c839543e9b798 (patch)
tree38665ebcd9b9e786c9595dbfbc37a7799a3fcd21 /Lib/distutils/ccompiler.py
parent8ed06da754209a68ff775856509dd2d5a144c14c (diff)
downloadcpython-fa012610c443338da52080e9f05c839543e9b798.zip
cpython-fa012610c443338da52080e9f05c839543e9b798.tar.gz
cpython-fa012610c443338da52080e9f05c839543e9b798.tar.bz2
new method: has_function() - returns a boolean indicating whether the
argument function is available on the current platform
Diffstat (limited to 'Lib/distutils/ccompiler.py')
-rw-r--r--Lib/distutils/ccompiler.py45
1 files changed, 45 insertions, 0 deletions
diff --git a/Lib/distutils/ccompiler.py b/Lib/distutils/ccompiler.py
index 46fb743..751ec06 100644
--- a/Lib/distutils/ccompiler.py
+++ b/Lib/distutils/ccompiler.py
@@ -883,6 +883,51 @@ class CCompiler:
"""
raise NotImplementedError
+ def has_function(self, funcname,
+ includes=None,
+ include_dirs=None,
+ libraries=None,
+ library_dirs=None):
+ """Return a boolean indicating whether funcname is supported on
+ the current platform. The optional arguments can be used to
+ augment the compilation environment.
+ """
+
+ # this can't be included at module scope because it tries to
+ # import math which might not be available at that point - maybe
+ # the necessary logic should just be inlined?
+ import tempfile
+ if includes is None:
+ includes = []
+ if include_dirs is None:
+ include_dirs = []
+ if libraries is None:
+ libraries = []
+ if library_dirs is None:
+ library_dirs = []
+ fd, fname = tempfile.mkstemp(".c", funcname, text=True)
+ f = os.fdopen(fd, "w")
+ for incl in includes:
+ f.write("""#include "%s"\n""" % incl)
+ f.write("""\
+main (int argc, char **argv) {
+ %s();
+}
+""" % funcname)
+ f.close()
+ try:
+ objects = self.compile([fname], include_dirs=include_dirs)
+ except CompileError:
+ return False
+
+ try:
+ self.link_executable(objects, "a.out",
+ libraries=libraries,
+ library_dirs=library_dirs)
+ except (LinkError, TypeError):
+ return False
+ return True
+
def find_library_file (self, dirs, lib, debug=0):
"""Search the specified list of directories for a static or shared
library file 'lib' and return the full path to that file. If