Greg Ward | 28a5f44 | 2000-06-06 02:57:07 +0000 | [diff] [blame] | 1 | """distutils.command.config |
| 2 | |
| 3 | Implements the Distutils 'config' command, a (mostly) empty command class |
| 4 | that exists mainly to be sub-classed by specific module distributions and |
| 5 | applications. The idea is that while every "config" command is different, |
| 6 | at least they're all named the same, and users always see "config" in the |
| 7 | list of standard commands. Also, this is a good place to put common |
| 8 | configure-like tasks: "try to compile this C code", or "figure out where |
| 9 | this header file lives". |
| 10 | """ |
| 11 | |
Greg Ward | 28a5f44 | 2000-06-06 02:57:07 +0000 | [diff] [blame] | 12 | __revision__ = "$Id$" |
| 13 | |
Tarek Ziadé | 2b66da7 | 2009-12-21 01:22:46 +0000 | [diff] [blame] | 14 | import os |
| 15 | import re |
Tarek Ziadé | e643bed | 2009-04-12 16:45:32 +0000 | [diff] [blame] | 16 | |
Greg Ward | 28a5f44 | 2000-06-06 02:57:07 +0000 | [diff] [blame] | 17 | from distutils.core import Command |
| 18 | from distutils.errors import DistutilsExecError |
Ned Deily | c47a459 | 2012-02-11 20:40:24 +0100 | [diff] [blame] | 19 | from distutils.sysconfig import customize_compiler |
Jeremy Hylton | cd8a114 | 2002-06-04 20:14:43 +0000 | [diff] [blame] | 20 | from distutils import log |
Greg Ward | 28a5f44 | 2000-06-06 02:57:07 +0000 | [diff] [blame] | 21 | |
Tarek Ziadé | 7bea344 | 2009-04-12 15:03:50 +0000 | [diff] [blame] | 22 | LANG_EXT = {'c': '.c', 'c++': '.cxx'} |
Greg Ward | 28a5f44 | 2000-06-06 02:57:07 +0000 | [diff] [blame] | 23 | |
Tarek Ziadé | 7bea344 | 2009-04-12 15:03:50 +0000 | [diff] [blame] | 24 | class config(Command): |
Greg Ward | 28a5f44 | 2000-06-06 02:57:07 +0000 | [diff] [blame] | 25 | |
| 26 | description = "prepare to build" |
| 27 | |
| 28 | user_options = [ |
| 29 | ('compiler=', None, |
| 30 | "specify the compiler type"), |
| 31 | ('cc=', None, |
| 32 | "specify the compiler executable"), |
| 33 | ('include-dirs=', 'I', |
| 34 | "list of directories to search for header files"), |
| 35 | ('define=', 'D', |
| 36 | "C preprocessor macros to define"), |
| 37 | ('undef=', 'U', |
| 38 | "C preprocessor macros to undefine"), |
| 39 | ('libraries=', 'l', |
| 40 | "external C libraries to link with"), |
| 41 | ('library-dirs=', 'L', |
| 42 | "directories to search for external C libraries"), |
Greg Ward | 59ac709 | 2000-06-21 03:00:50 +0000 | [diff] [blame] | 43 | |
| 44 | ('noisy', None, |
| 45 | "show every action (compile, link, run, ...) taken"), |
| 46 | ('dump-source', None, |
| 47 | "dump generated source files before attempting to compile them"), |
Greg Ward | 28a5f44 | 2000-06-06 02:57:07 +0000 | [diff] [blame] | 48 | ] |
| 49 | |
| 50 | |
| 51 | # The three standard command methods: since the "config" command |
| 52 | # does nothing by default, these are empty. |
| 53 | |
Tarek Ziadé | 7bea344 | 2009-04-12 15:03:50 +0000 | [diff] [blame] | 54 | def initialize_options(self): |
Greg Ward | 28a5f44 | 2000-06-06 02:57:07 +0000 | [diff] [blame] | 55 | self.compiler = None |
| 56 | self.cc = None |
| 57 | self.include_dirs = None |
Greg Ward | 28a5f44 | 2000-06-06 02:57:07 +0000 | [diff] [blame] | 58 | self.libraries = None |
| 59 | self.library_dirs = None |
| 60 | |
Greg Ward | 59ac709 | 2000-06-21 03:00:50 +0000 | [diff] [blame] | 61 | # maximal output for now |
| 62 | self.noisy = 1 |
| 63 | self.dump_source = 1 |
| 64 | |
| 65 | # list of temporary files generated along-the-way that we have |
| 66 | # to clean at some point |
| 67 | self.temp_files = [] |
| 68 | |
Tarek Ziadé | 7bea344 | 2009-04-12 15:03:50 +0000 | [diff] [blame] | 69 | def finalize_options(self): |
Greg Ward | 2e38a50 | 2000-10-14 03:40:20 +0000 | [diff] [blame] | 70 | if self.include_dirs is None: |
| 71 | self.include_dirs = self.distribution.include_dirs or [] |
Tarek Ziadé | e643bed | 2009-04-12 16:45:32 +0000 | [diff] [blame] | 72 | elif isinstance(self.include_dirs, str): |
| 73 | self.include_dirs = self.include_dirs.split(os.pathsep) |
Greg Ward | 2e38a50 | 2000-10-14 03:40:20 +0000 | [diff] [blame] | 74 | |
| 75 | if self.libraries is None: |
| 76 | self.libraries = [] |
Tarek Ziadé | e643bed | 2009-04-12 16:45:32 +0000 | [diff] [blame] | 77 | elif isinstance(self.libraries, str): |
Greg Ward | 2e38a50 | 2000-10-14 03:40:20 +0000 | [diff] [blame] | 78 | self.libraries = [self.libraries] |
| 79 | |
| 80 | if self.library_dirs is None: |
| 81 | self.library_dirs = [] |
Tarek Ziadé | e643bed | 2009-04-12 16:45:32 +0000 | [diff] [blame] | 82 | elif isinstance(self.library_dirs, str): |
| 83 | self.library_dirs = self.library_dirs.split(os.pathsep) |
Greg Ward | 28a5f44 | 2000-06-06 02:57:07 +0000 | [diff] [blame] | 84 | |
Tarek Ziadé | 3295eed | 2009-04-12 17:02:08 +0000 | [diff] [blame] | 85 | def run(self): |
Greg Ward | 28a5f44 | 2000-06-06 02:57:07 +0000 | [diff] [blame] | 86 | pass |
| 87 | |
| 88 | |
| 89 | # Utility methods for actual "config" commands. The interfaces are |
| 90 | # loosely based on Autoconf macros of similar names. Sub-classes |
| 91 | # may use these freely. |
| 92 | |
Tarek Ziadé | 7bea344 | 2009-04-12 15:03:50 +0000 | [diff] [blame] | 93 | def _check_compiler(self): |
Greg Ward | 28a5f44 | 2000-06-06 02:57:07 +0000 | [diff] [blame] | 94 | """Check that 'self.compiler' really is a CCompiler object; |
| 95 | if not, make it one. |
| 96 | """ |
| 97 | # We do this late, and only on-demand, because this is an expensive |
| 98 | # import. |
| 99 | from distutils.ccompiler import CCompiler, new_compiler |
| 100 | if not isinstance(self.compiler, CCompiler): |
Greg Ward | cb1f4c4 | 2000-09-30 18:27:54 +0000 | [diff] [blame] | 101 | self.compiler = new_compiler(compiler=self.compiler, |
Jeremy Hylton | cd8a114 | 2002-06-04 20:14:43 +0000 | [diff] [blame] | 102 | dry_run=self.dry_run, force=1) |
Andrew M. Kuchling | 679bc9f | 2003-02-18 01:28:51 +0000 | [diff] [blame] | 103 | customize_compiler(self.compiler) |
Greg Ward | 28a5f44 | 2000-06-06 02:57:07 +0000 | [diff] [blame] | 104 | if self.include_dirs: |
| 105 | self.compiler.set_include_dirs(self.include_dirs) |
| 106 | if self.libraries: |
| 107 | self.compiler.set_libraries(self.libraries) |
| 108 | if self.library_dirs: |
| 109 | self.compiler.set_library_dirs(self.library_dirs) |
| 110 | |
| 111 | |
Tarek Ziadé | 7bea344 | 2009-04-12 15:03:50 +0000 | [diff] [blame] | 112 | def _gen_temp_sourcefile(self, body, headers, lang): |
Greg Ward | 28a5f44 | 2000-06-06 02:57:07 +0000 | [diff] [blame] | 113 | filename = "_configtest" + LANG_EXT[lang] |
| 114 | file = open(filename, "w") |
Greg Ward | 59ac709 | 2000-06-21 03:00:50 +0000 | [diff] [blame] | 115 | if headers: |
| 116 | for header in headers: |
| 117 | file.write("#include <%s>\n" % header) |
| 118 | file.write("\n") |
Greg Ward | 28a5f44 | 2000-06-06 02:57:07 +0000 | [diff] [blame] | 119 | file.write(body) |
Greg Ward | 59ac709 | 2000-06-21 03:00:50 +0000 | [diff] [blame] | 120 | if body[-1] != "\n": |
| 121 | file.write("\n") |
Greg Ward | 28a5f44 | 2000-06-06 02:57:07 +0000 | [diff] [blame] | 122 | file.close() |
| 123 | return filename |
| 124 | |
Tarek Ziadé | 7bea344 | 2009-04-12 15:03:50 +0000 | [diff] [blame] | 125 | def _preprocess(self, body, headers, include_dirs, lang): |
Greg Ward | 59ac709 | 2000-06-21 03:00:50 +0000 | [diff] [blame] | 126 | src = self._gen_temp_sourcefile(body, headers, lang) |
| 127 | out = "_configtest.i" |
| 128 | self.temp_files.extend([src, out]) |
Greg Ward | 855dab9 | 2000-06-27 01:21:22 +0000 | [diff] [blame] | 129 | self.compiler.preprocess(src, out, include_dirs=include_dirs) |
Greg Ward | 59ac709 | 2000-06-21 03:00:50 +0000 | [diff] [blame] | 130 | return (src, out) |
| 131 | |
Tarek Ziadé | 7bea344 | 2009-04-12 15:03:50 +0000 | [diff] [blame] | 132 | def _compile(self, body, headers, include_dirs, lang): |
Greg Ward | 59ac709 | 2000-06-21 03:00:50 +0000 | [diff] [blame] | 133 | src = self._gen_temp_sourcefile(body, headers, lang) |
| 134 | if self.dump_source: |
| 135 | dump_file(src, "compiling '%s':" % src) |
| 136 | (obj,) = self.compiler.object_filenames([src]) |
| 137 | self.temp_files.extend([src, obj]) |
Greg Ward | 855dab9 | 2000-06-27 01:21:22 +0000 | [diff] [blame] | 138 | self.compiler.compile([src], include_dirs=include_dirs) |
Greg Ward | 28a5f44 | 2000-06-06 02:57:07 +0000 | [diff] [blame] | 139 | return (src, obj) |
| 140 | |
Tarek Ziadé | 7bea344 | 2009-04-12 15:03:50 +0000 | [diff] [blame] | 141 | def _link(self, body, headers, include_dirs, libraries, library_dirs, |
| 142 | lang): |
Greg Ward | 855dab9 | 2000-06-27 01:21:22 +0000 | [diff] [blame] | 143 | (src, obj) = self._compile(body, headers, include_dirs, lang) |
Fred Drake | 21d4535 | 2001-12-06 21:01:19 +0000 | [diff] [blame] | 144 | prog = os.path.splitext(os.path.basename(src))[0] |
Greg Ward | 59ac709 | 2000-06-21 03:00:50 +0000 | [diff] [blame] | 145 | self.compiler.link_executable([obj], prog, |
| 146 | libraries=libraries, |
Gustavo Niemeyer | 6b01685 | 2002-11-05 16:12:02 +0000 | [diff] [blame] | 147 | library_dirs=library_dirs, |
| 148 | target_lang=lang) |
Andrew M. Kuchling | b1d6029 | 2001-08-16 14:08:02 +0000 | [diff] [blame] | 149 | |
Just van Rossum | ca3fec7 | 2003-02-03 11:43:54 +0000 | [diff] [blame] | 150 | if self.compiler.exe_extension is not None: |
| 151 | prog = prog + self.compiler.exe_extension |
Andrew M. Kuchling | b1d6029 | 2001-08-16 14:08:02 +0000 | [diff] [blame] | 152 | self.temp_files.append(prog) |
| 153 | |
Greg Ward | 59ac709 | 2000-06-21 03:00:50 +0000 | [diff] [blame] | 154 | return (src, obj, prog) |
Greg Ward | 28a5f44 | 2000-06-06 02:57:07 +0000 | [diff] [blame] | 155 | |
Tarek Ziadé | 7bea344 | 2009-04-12 15:03:50 +0000 | [diff] [blame] | 156 | def _clean(self, *filenames): |
Greg Ward | 59ac709 | 2000-06-21 03:00:50 +0000 | [diff] [blame] | 157 | if not filenames: |
| 158 | filenames = self.temp_files |
| 159 | self.temp_files = [] |
Tarek Ziadé | 3295eed | 2009-04-12 17:02:08 +0000 | [diff] [blame] | 160 | log.info("removing: %s", ' '.join(filenames)) |
Greg Ward | 28a5f44 | 2000-06-06 02:57:07 +0000 | [diff] [blame] | 161 | for filename in filenames: |
| 162 | try: |
| 163 | os.remove(filename) |
| 164 | except OSError: |
| 165 | pass |
| 166 | |
| 167 | |
Greg Ward | 28a5f44 | 2000-06-06 02:57:07 +0000 | [diff] [blame] | 168 | # XXX these ignore the dry-run flag: what to do, what to do? even if |
| 169 | # you want a dry-run build, you still need some sort of configuration |
| 170 | # info. My inclination is to make it up to the real config command to |
| 171 | # consult 'dry_run', and assume a default (minimal) configuration if |
| 172 | # true. The problem with trying to do it here is that you'd have to |
| 173 | # return either true or false from all the 'try' methods, neither of |
| 174 | # which is correct. |
| 175 | |
Greg Ward | 59ac709 | 2000-06-21 03:00:50 +0000 | [diff] [blame] | 176 | # XXX need access to the header search path and maybe default macros. |
| 177 | |
Tarek Ziadé | 7bea344 | 2009-04-12 15:03:50 +0000 | [diff] [blame] | 178 | def try_cpp(self, body=None, headers=None, include_dirs=None, lang="c"): |
Greg Ward | 59ac709 | 2000-06-21 03:00:50 +0000 | [diff] [blame] | 179 | """Construct a source file from 'body' (a string containing lines |
| 180 | of C/C++ code) and 'headers' (a list of header files to include) |
| 181 | and run it through the preprocessor. Return true if the |
| 182 | preprocessor succeeded, false if there were any errors. |
| 183 | ('body' probably isn't of much use, but what the heck.) |
| 184 | """ |
| 185 | from distutils.ccompiler import CompileError |
| 186 | self._check_compiler() |
| 187 | ok = 1 |
| 188 | try: |
Andrew M. Kuchling | 6fb8d3a | 2001-08-16 13:56:40 +0000 | [diff] [blame] | 189 | self._preprocess(body, headers, include_dirs, lang) |
Greg Ward | 59ac709 | 2000-06-21 03:00:50 +0000 | [diff] [blame] | 190 | except CompileError: |
| 191 | ok = 0 |
| 192 | |
| 193 | self._clean() |
| 194 | return ok |
| 195 | |
Tarek Ziadé | 7bea344 | 2009-04-12 15:03:50 +0000 | [diff] [blame] | 196 | def search_cpp(self, pattern, body=None, headers=None, include_dirs=None, |
| 197 | lang="c"): |
Greg Ward | 59ac709 | 2000-06-21 03:00:50 +0000 | [diff] [blame] | 198 | """Construct a source file (just like 'try_cpp()'), run it through |
| 199 | the preprocessor, and return true if any line of the output matches |
| 200 | 'pattern'. 'pattern' should either be a compiled regex object or a |
| 201 | string containing a regex. If both 'body' and 'headers' are None, |
| 202 | preprocesses an empty file -- which can be useful to determine the |
| 203 | symbols the preprocessor and compiler set by default. |
| 204 | """ |
Greg Ward | 59ac709 | 2000-06-21 03:00:50 +0000 | [diff] [blame] | 205 | self._check_compiler() |
Tarek Ziadé | f6f4b30 | 2009-04-12 16:31:24 +0000 | [diff] [blame] | 206 | src, out = self._preprocess(body, headers, include_dirs, lang) |
Greg Ward | 59ac709 | 2000-06-21 03:00:50 +0000 | [diff] [blame] | 207 | |
Tarek Ziadé | f6f4b30 | 2009-04-12 16:31:24 +0000 | [diff] [blame] | 208 | if isinstance(pattern, str): |
Greg Ward | 59ac709 | 2000-06-21 03:00:50 +0000 | [diff] [blame] | 209 | pattern = re.compile(pattern) |
| 210 | |
| 211 | file = open(out) |
| 212 | match = 0 |
| 213 | while 1: |
| 214 | line = file.readline() |
| 215 | if line == '': |
| 216 | break |
Andrew M. Kuchling | 6fb8d3a | 2001-08-16 13:56:40 +0000 | [diff] [blame] | 217 | if pattern.search(line): |
Greg Ward | 59ac709 | 2000-06-21 03:00:50 +0000 | [diff] [blame] | 218 | match = 1 |
| 219 | break |
| 220 | |
| 221 | file.close() |
| 222 | self._clean() |
| 223 | return match |
| 224 | |
Tarek Ziadé | 7bea344 | 2009-04-12 15:03:50 +0000 | [diff] [blame] | 225 | def try_compile(self, body, headers=None, include_dirs=None, lang="c"): |
Greg Ward | 59ac709 | 2000-06-21 03:00:50 +0000 | [diff] [blame] | 226 | """Try to compile a source file built from 'body' and 'headers'. |
| 227 | Return true on success, false otherwise. |
Greg Ward | 28a5f44 | 2000-06-06 02:57:07 +0000 | [diff] [blame] | 228 | """ |
| 229 | from distutils.ccompiler import CompileError |
| 230 | self._check_compiler() |
| 231 | try: |
Andrew M. Kuchling | 6fb8d3a | 2001-08-16 13:56:40 +0000 | [diff] [blame] | 232 | self._compile(body, headers, include_dirs, lang) |
Greg Ward | 28a5f44 | 2000-06-06 02:57:07 +0000 | [diff] [blame] | 233 | ok = 1 |
| 234 | except CompileError: |
| 235 | ok = 0 |
| 236 | |
Jeremy Hylton | cd8a114 | 2002-06-04 20:14:43 +0000 | [diff] [blame] | 237 | log.info(ok and "success!" or "failure.") |
Greg Ward | 59ac709 | 2000-06-21 03:00:50 +0000 | [diff] [blame] | 238 | self._clean() |
Greg Ward | 28a5f44 | 2000-06-06 02:57:07 +0000 | [diff] [blame] | 239 | return ok |
| 240 | |
Tarek Ziadé | 7bea344 | 2009-04-12 15:03:50 +0000 | [diff] [blame] | 241 | def try_link(self, body, headers=None, include_dirs=None, libraries=None, |
| 242 | library_dirs=None, lang="c"): |
Greg Ward | 59ac709 | 2000-06-21 03:00:50 +0000 | [diff] [blame] | 243 | """Try to compile and link a source file, built from 'body' and |
| 244 | 'headers', to executable form. Return true on success, false |
Greg Ward | 28a5f44 | 2000-06-06 02:57:07 +0000 | [diff] [blame] | 245 | otherwise. |
| 246 | """ |
| 247 | from distutils.ccompiler import CompileError, LinkError |
| 248 | self._check_compiler() |
| 249 | try: |
Greg Ward | 855dab9 | 2000-06-27 01:21:22 +0000 | [diff] [blame] | 250 | self._link(body, headers, include_dirs, |
| 251 | libraries, library_dirs, lang) |
Greg Ward | 59ac709 | 2000-06-21 03:00:50 +0000 | [diff] [blame] | 252 | ok = 1 |
| 253 | except (CompileError, LinkError): |
| 254 | ok = 0 |
| 255 | |
Jeremy Hylton | cd8a114 | 2002-06-04 20:14:43 +0000 | [diff] [blame] | 256 | log.info(ok and "success!" or "failure.") |
Greg Ward | 59ac709 | 2000-06-21 03:00:50 +0000 | [diff] [blame] | 257 | self._clean() |
| 258 | return ok |
Fred Drake | 21d4535 | 2001-12-06 21:01:19 +0000 | [diff] [blame] | 259 | |
Tarek Ziadé | 7bea344 | 2009-04-12 15:03:50 +0000 | [diff] [blame] | 260 | def try_run(self, body, headers=None, include_dirs=None, libraries=None, |
| 261 | library_dirs=None, lang="c"): |
Greg Ward | 59ac709 | 2000-06-21 03:00:50 +0000 | [diff] [blame] | 262 | """Try to compile, link to an executable, and run a program |
| 263 | built from 'body' and 'headers'. Return true on success, false |
| 264 | otherwise. |
| 265 | """ |
| 266 | from distutils.ccompiler import CompileError, LinkError |
| 267 | self._check_compiler() |
| 268 | try: |
Andrew M. Kuchling | 246c425 | 2001-08-13 13:56:24 +0000 | [diff] [blame] | 269 | src, obj, exe = self._link(body, headers, include_dirs, |
| 270 | libraries, library_dirs, lang) |
Greg Ward | 28a5f44 | 2000-06-06 02:57:07 +0000 | [diff] [blame] | 271 | self.spawn([exe]) |
| 272 | ok = 1 |
| 273 | except (CompileError, LinkError, DistutilsExecError): |
| 274 | ok = 0 |
| 275 | |
Jeremy Hylton | cd8a114 | 2002-06-04 20:14:43 +0000 | [diff] [blame] | 276 | log.info(ok and "success!" or "failure.") |
Greg Ward | 59ac709 | 2000-06-21 03:00:50 +0000 | [diff] [blame] | 277 | self._clean() |
Greg Ward | 28a5f44 | 2000-06-06 02:57:07 +0000 | [diff] [blame] | 278 | return ok |
| 279 | |
Greg Ward | 59ac709 | 2000-06-21 03:00:50 +0000 | [diff] [blame] | 280 | |
| 281 | # -- High-level methods -------------------------------------------- |
| 282 | # (these are the ones that are actually likely to be useful |
| 283 | # when implementing a real-world config command!) |
| 284 | |
Tarek Ziadé | 7bea344 | 2009-04-12 15:03:50 +0000 | [diff] [blame] | 285 | def check_func(self, func, headers=None, include_dirs=None, |
| 286 | libraries=None, library_dirs=None, decl=0, call=0): |
Greg Ward | 59ac709 | 2000-06-21 03:00:50 +0000 | [diff] [blame] | 287 | |
| 288 | """Determine if function 'func' is available by constructing a |
| 289 | source file that refers to 'func', and compiles and links it. |
| 290 | If everything succeeds, returns true; otherwise returns false. |
| 291 | |
| 292 | The constructed source file starts out by including the header |
| 293 | files listed in 'headers'. If 'decl' is true, it then declares |
| 294 | 'func' (as "int func()"); you probably shouldn't supply 'headers' |
| 295 | and set 'decl' true in the same call, or you might get errors about |
| 296 | a conflicting declarations for 'func'. Finally, the constructed |
| 297 | 'main()' function either references 'func' or (if 'call' is true) |
| 298 | calls it. 'libraries' and 'library_dirs' are used when |
| 299 | linking. |
| 300 | """ |
| 301 | |
| 302 | self._check_compiler() |
| 303 | body = [] |
| 304 | if decl: |
| 305 | body.append("int %s ();" % func) |
| 306 | body.append("int main () {") |
| 307 | if call: |
| 308 | body.append(" %s();" % func) |
| 309 | else: |
| 310 | body.append(" %s;" % func) |
| 311 | body.append("}") |
Tarek Ziadé | 3295eed | 2009-04-12 17:02:08 +0000 | [diff] [blame] | 312 | body = "\n".join(body) + "\n" |
Greg Ward | 59ac709 | 2000-06-21 03:00:50 +0000 | [diff] [blame] | 313 | |
Greg Ward | 855dab9 | 2000-06-27 01:21:22 +0000 | [diff] [blame] | 314 | return self.try_link(body, headers, include_dirs, |
| 315 | libraries, library_dirs) |
Greg Ward | 59ac709 | 2000-06-21 03:00:50 +0000 | [diff] [blame] | 316 | |
| 317 | # check_func () |
| 318 | |
Tarek Ziadé | 7bea344 | 2009-04-12 15:03:50 +0000 | [diff] [blame] | 319 | def check_lib(self, library, library_dirs=None, headers=None, |
| 320 | include_dirs=None, other_libraries=[]): |
Greg Ward | 855dab9 | 2000-06-27 01:21:22 +0000 | [diff] [blame] | 321 | """Determine if 'library' is available to be linked against, |
| 322 | without actually checking that any particular symbols are provided |
| 323 | by it. 'headers' will be used in constructing the source file to |
| 324 | be compiled, but the only effect of this is to check if all the |
Greg Ward | 4cd6f2a | 2000-10-14 03:56:42 +0000 | [diff] [blame] | 325 | header files listed are available. Any libraries listed in |
| 326 | 'other_libraries' will be included in the link, in case 'library' |
| 327 | has symbols that depend on other libraries. |
Greg Ward | 855dab9 | 2000-06-27 01:21:22 +0000 | [diff] [blame] | 328 | """ |
| 329 | self._check_compiler() |
| 330 | return self.try_link("int main (void) { }", |
Greg Ward | 4cd6f2a | 2000-10-14 03:56:42 +0000 | [diff] [blame] | 331 | headers, include_dirs, |
| 332 | [library]+other_libraries, library_dirs) |
Greg Ward | 855dab9 | 2000-06-27 01:21:22 +0000 | [diff] [blame] | 333 | |
Tarek Ziadé | 7bea344 | 2009-04-12 15:03:50 +0000 | [diff] [blame] | 334 | def check_header(self, header, include_dirs=None, library_dirs=None, |
| 335 | lang="c"): |
Greg Ward | 59ac709 | 2000-06-21 03:00:50 +0000 | [diff] [blame] | 336 | """Determine if the system header file named by 'header_file' |
| 337 | exists and can be found by the preprocessor; return true if so, |
| 338 | false otherwise. |
| 339 | """ |
Andrew M. Kuchling | 4013cbd | 2002-09-09 12:10:00 +0000 | [diff] [blame] | 340 | return self.try_cpp(body="/* No body */", headers=[header], |
| 341 | include_dirs=include_dirs) |
Greg Ward | 59ac709 | 2000-06-21 03:00:50 +0000 | [diff] [blame] | 342 | |
| 343 | |
Tarek Ziadé | aa48798 | 2009-04-12 14:53:51 +0000 | [diff] [blame] | 344 | def dump_file(filename, head=None): |
| 345 | """Dumps a file content into log.info. |
Greg Ward | 59ac709 | 2000-06-21 03:00:50 +0000 | [diff] [blame] | 346 | |
Tarek Ziadé | aa48798 | 2009-04-12 14:53:51 +0000 | [diff] [blame] | 347 | If head is not None, will be dumped before the file content. |
| 348 | """ |
Greg Ward | 59ac709 | 2000-06-21 03:00:50 +0000 | [diff] [blame] | 349 | if head is None: |
Tarek Ziadé | aa48798 | 2009-04-12 14:53:51 +0000 | [diff] [blame] | 350 | log.info('%s' % filename) |
Greg Ward | 59ac709 | 2000-06-21 03:00:50 +0000 | [diff] [blame] | 351 | else: |
Tarek Ziadé | aa48798 | 2009-04-12 14:53:51 +0000 | [diff] [blame] | 352 | log.info(head) |
Greg Ward | 59ac709 | 2000-06-21 03:00:50 +0000 | [diff] [blame] | 353 | file = open(filename) |
Tarek Ziadé | aa48798 | 2009-04-12 14:53:51 +0000 | [diff] [blame] | 354 | try: |
| 355 | log.info(file.read()) |
| 356 | finally: |
| 357 | file.close() |