annotate Lib/distutils/command/config.py @ 58925:eecf1bef052d 2.6

Merged revisions 78207 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r78207 | ezio.melotti | 2010-02-17 01:26:09 +0200 (Wed, 17 Feb 2010) | 1 line #7930: fix stripid ........
author Ezio Melotti <ezio.melotti@gmail.com>
date Tue, 16 Feb 2010 23:29:44 +0000
parents 893d46576737
children 4cdf21a0dbbc a5229237eb50
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
12864
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
1 """distutils.command.config
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
2
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
3 Implements the Distutils 'config' command, a (mostly) empty command class
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
4 that exists mainly to be sub-classed by specific module distributions and
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
5 applications. The idea is that while every "config" command is different,
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
6 at least they're all named the same, and users always see "config" in the
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
7 list of standard commands. Also, this is a good place to put common
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
8 configure-like tasks: "try to compile this C code", or "figure out where
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
9 this header file lives".
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
10 """
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
11
33965
893d46576737 Update compatibility comments to 2.1, corresponding to PEP 291 1.13.
Martin v. Löwis <martin@v.loewis.de>
parents: 27928
diff changeset
12 # This module should be kept compatible with Python 2.1.
26285
42bfc98d295b Add comment to Distutil files about requiring 1.5.2 compatibility, as
Andrew M. Kuchling <amk@amk.ca>
parents: 26210
diff changeset
13
12864
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
14 __revision__ = "$Id$"
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
15
12979
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
16 import sys, os, string, re
15213
882cefe21dc3 Bastian Kleineidam: fix up any supplied command-line options.
Greg Ward <gward@python.net>
parents: 14948
diff changeset
17 from types import *
12864
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
18 from distutils.core import Command
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
19 from distutils.errors import DistutilsExecError
27928
e31b39930a31 [Patch #681504] Call customize_compiler in config command
Andrew M. Kuchling <amk@amk.ca>
parents: 27628
diff changeset
20 from distutils.sysconfig import customize_compiler
23668
ca87119255eb Make setup.py less chatty by default.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 21268
diff changeset
21 from distutils import log
12864
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
22
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
23 LANG_EXT = {'c': '.c',
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
24 'c++': '.cxx'}
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
25
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
26 class config (Command):
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
27
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
28 description = "prepare to build"
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
29
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
30 user_options = [
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
31 ('compiler=', None,
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
32 "specify the compiler type"),
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
33 ('cc=', None,
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
34 "specify the compiler executable"),
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
35 ('include-dirs=', 'I',
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
36 "list of directories to search for header files"),
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
37 ('define=', 'D',
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
38 "C preprocessor macros to define"),
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
39 ('undef=', 'U',
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
40 "C preprocessor macros to undefine"),
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
41 ('libraries=', 'l',
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
42 "external C libraries to link with"),
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
43 ('library-dirs=', 'L',
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
44 "directories to search for external C libraries"),
12979
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
45
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
46 ('noisy', None,
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
47 "show every action (compile, link, run, ...) taken"),
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
48 ('dump-source', None,
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
49 "dump generated source files before attempting to compile them"),
12864
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
50 ]
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
51
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
52
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
53 # The three standard command methods: since the "config" command
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
54 # does nothing by default, these are empty.
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
55
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
56 def initialize_options (self):
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
57 self.compiler = None
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
58 self.cc = None
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
59 self.include_dirs = None
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
60 #self.define = None
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
61 #self.undef = None
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
62 self.libraries = None
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
63 self.library_dirs = None
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
64
12979
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
65 # maximal output for now
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
66 self.noisy = 1
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
67 self.dump_source = 1
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
68
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
69 # list of temporary files generated along-the-way that we have
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
70 # to clean at some point
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
71 self.temp_files = []
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
72
12864
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
73 def finalize_options (self):
15213
882cefe21dc3 Bastian Kleineidam: fix up any supplied command-line options.
Greg Ward <gward@python.net>
parents: 14948
diff changeset
74 if self.include_dirs is None:
882cefe21dc3 Bastian Kleineidam: fix up any supplied command-line options.
Greg Ward <gward@python.net>
parents: 14948
diff changeset
75 self.include_dirs = self.distribution.include_dirs or []
882cefe21dc3 Bastian Kleineidam: fix up any supplied command-line options.
Greg Ward <gward@python.net>
parents: 14948
diff changeset
76 elif type(self.include_dirs) is StringType:
882cefe21dc3 Bastian Kleineidam: fix up any supplied command-line options.
Greg Ward <gward@python.net>
parents: 14948
diff changeset
77 self.include_dirs = string.split(self.include_dirs, os.pathsep)
882cefe21dc3 Bastian Kleineidam: fix up any supplied command-line options.
Greg Ward <gward@python.net>
parents: 14948
diff changeset
78
882cefe21dc3 Bastian Kleineidam: fix up any supplied command-line options.
Greg Ward <gward@python.net>
parents: 14948
diff changeset
79 if self.libraries is None:
882cefe21dc3 Bastian Kleineidam: fix up any supplied command-line options.
Greg Ward <gward@python.net>
parents: 14948
diff changeset
80 self.libraries = []
882cefe21dc3 Bastian Kleineidam: fix up any supplied command-line options.
Greg Ward <gward@python.net>
parents: 14948
diff changeset
81 elif type(self.libraries) is StringType:
882cefe21dc3 Bastian Kleineidam: fix up any supplied command-line options.
Greg Ward <gward@python.net>
parents: 14948
diff changeset
82 self.libraries = [self.libraries]
882cefe21dc3 Bastian Kleineidam: fix up any supplied command-line options.
Greg Ward <gward@python.net>
parents: 14948
diff changeset
83
882cefe21dc3 Bastian Kleineidam: fix up any supplied command-line options.
Greg Ward <gward@python.net>
parents: 14948
diff changeset
84 if self.library_dirs is None:
882cefe21dc3 Bastian Kleineidam: fix up any supplied command-line options.
Greg Ward <gward@python.net>
parents: 14948
diff changeset
85 self.library_dirs = []
882cefe21dc3 Bastian Kleineidam: fix up any supplied command-line options.
Greg Ward <gward@python.net>
parents: 14948
diff changeset
86 elif type(self.library_dirs) is StringType:
882cefe21dc3 Bastian Kleineidam: fix up any supplied command-line options.
Greg Ward <gward@python.net>
parents: 14948
diff changeset
87 self.library_dirs = string.split(self.library_dirs, os.pathsep)
882cefe21dc3 Bastian Kleineidam: fix up any supplied command-line options.
Greg Ward <gward@python.net>
parents: 14948
diff changeset
88
12864
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
89
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
90 def run (self):
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
91 pass
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
92
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
93
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
94 # Utility methods for actual "config" commands. The interfaces are
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
95 # loosely based on Autoconf macros of similar names. Sub-classes
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
96 # may use these freely.
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
97
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
98 def _check_compiler (self):
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
99 """Check that 'self.compiler' really is a CCompiler object;
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
100 if not, make it one.
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
101 """
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
102 # We do this late, and only on-demand, because this is an expensive
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
103 # import.
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
104 from distutils.ccompiler import CCompiler, new_compiler
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
105 if not isinstance(self.compiler, CCompiler):
14948
7acb8bbc215b Standardized whitespace around function calls.
Greg Ward <gward@python.net>
parents: 13029
diff changeset
106 self.compiler = new_compiler(compiler=self.compiler,
23668
ca87119255eb Make setup.py less chatty by default.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 21268
diff changeset
107 dry_run=self.dry_run, force=1)
27928
e31b39930a31 [Patch #681504] Call customize_compiler in config command
Andrew M. Kuchling <amk@amk.ca>
parents: 27628
diff changeset
108 customize_compiler(self.compiler)
12864
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
109 if self.include_dirs:
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
110 self.compiler.set_include_dirs(self.include_dirs)
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
111 if self.libraries:
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
112 self.compiler.set_libraries(self.libraries)
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
113 if self.library_dirs:
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
114 self.compiler.set_library_dirs(self.library_dirs)
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
115
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
116
12979
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
117 def _gen_temp_sourcefile (self, body, headers, lang):
12864
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
118 filename = "_configtest" + LANG_EXT[lang]
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
119 file = open(filename, "w")
12979
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
120 if headers:
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
121 for header in headers:
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
122 file.write("#include <%s>\n" % header)
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
123 file.write("\n")
12864
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
124 file.write(body)
12979
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
125 if body[-1] != "\n":
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
126 file.write("\n")
12864
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
127 file.close()
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
128 return filename
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
129
13029
70b16dc6137f Added 'include_dirs' parameters all over the place.
Greg Ward <gward@python.net>
parents: 12979
diff changeset
130 def _preprocess (self, body, headers, include_dirs, lang):
12979
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
131 src = self._gen_temp_sourcefile(body, headers, lang)
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
132 out = "_configtest.i"
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
133 self.temp_files.extend([src, out])
13029
70b16dc6137f Added 'include_dirs' parameters all over the place.
Greg Ward <gward@python.net>
parents: 12979
diff changeset
134 self.compiler.preprocess(src, out, include_dirs=include_dirs)
12979
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
135 return (src, out)
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
136
13029
70b16dc6137f Added 'include_dirs' parameters all over the place.
Greg Ward <gward@python.net>
parents: 12979
diff changeset
137 def _compile (self, body, headers, include_dirs, lang):
12979
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
138 src = self._gen_temp_sourcefile(body, headers, lang)
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
139 if self.dump_source:
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
140 dump_file(src, "compiling '%s':" % src)
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
141 (obj,) = self.compiler.object_filenames([src])
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
142 self.temp_files.extend([src, obj])
13029
70b16dc6137f Added 'include_dirs' parameters all over the place.
Greg Ward <gward@python.net>
parents: 12979
diff changeset
143 self.compiler.compile([src], include_dirs=include_dirs)
12864
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
144 return (src, obj)
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
145
13029
70b16dc6137f Added 'include_dirs' parameters all over the place.
Greg Ward <gward@python.net>
parents: 12979
diff changeset
146 def _link (self, body,
70b16dc6137f Added 'include_dirs' parameters all over the place.
Greg Ward <gward@python.net>
parents: 12979
diff changeset
147 headers, include_dirs,
70b16dc6137f Added 'include_dirs' parameters all over the place.
Greg Ward <gward@python.net>
parents: 12979
diff changeset
148 libraries, library_dirs, lang):
70b16dc6137f Added 'include_dirs' parameters all over the place.
Greg Ward <gward@python.net>
parents: 12979
diff changeset
149 (src, obj) = self._compile(body, headers, include_dirs, lang)
21268
d296e6bb17e5 Whitespace normalization.
Fred Drake <fdrake@acm.org>
parents: 19303
diff changeset
150 prog = os.path.splitext(os.path.basename(src))[0]
12979
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
151 self.compiler.link_executable([obj], prog,
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
152 libraries=libraries,
26036
771b6f521b95 This patch fixes the following bugs:
Gustavo Niemeyer <gustavo@niemeyer.net>
parents: 25174
diff changeset
153 library_dirs=library_dirs,
771b6f521b95 This patch fixes the following bugs:
Gustavo Niemeyer <gustavo@niemeyer.net>
parents: 25174
diff changeset
154 target_lang=lang)
19303
cea945764db2 [Patch #444854 from twburton]
Andrew M. Kuchling <amk@amk.ca>
parents: 19302
diff changeset
155
27628
afc9a095a2d5 patch #664131, fix config command on OSX and Linux
Just van Rossum <just@letterror.com>
parents: 26285
diff changeset
156 if self.compiler.exe_extension is not None:
afc9a095a2d5 patch #664131, fix config command on OSX and Linux
Just van Rossum <just@letterror.com>
parents: 26285
diff changeset
157 prog = prog + self.compiler.exe_extension
19303
cea945764db2 [Patch #444854 from twburton]
Andrew M. Kuchling <amk@amk.ca>
parents: 19302
diff changeset
158 self.temp_files.append(prog)
cea945764db2 [Patch #444854 from twburton]
Andrew M. Kuchling <amk@amk.ca>
parents: 19302
diff changeset
159
12979
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
160 return (src, obj, prog)
12864
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
161
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
162 def _clean (self, *filenames):
12979
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
163 if not filenames:
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
164 filenames = self.temp_files
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
165 self.temp_files = []
23668
ca87119255eb Make setup.py less chatty by default.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 21268
diff changeset
166 log.info("removing: %s", string.join(filenames))
12864
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
167 for filename in filenames:
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
168 try:
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
169 os.remove(filename)
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
170 except OSError:
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
171 pass
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
172
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
173
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
174 # XXX these ignore the dry-run flag: what to do, what to do? even if
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
175 # you want a dry-run build, you still need some sort of configuration
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
176 # info. My inclination is to make it up to the real config command to
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
177 # consult 'dry_run', and assume a default (minimal) configuration if
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
178 # true. The problem with trying to do it here is that you'd have to
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
179 # return either true or false from all the 'try' methods, neither of
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
180 # which is correct.
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
181
12979
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
182 # XXX need access to the header search path and maybe default macros.
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
183
13029
70b16dc6137f Added 'include_dirs' parameters all over the place.
Greg Ward <gward@python.net>
parents: 12979
diff changeset
184 def try_cpp (self, body=None, headers=None, include_dirs=None, lang="c"):
12979
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
185 """Construct a source file from 'body' (a string containing lines
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
186 of C/C++ code) and 'headers' (a list of header files to include)
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
187 and run it through the preprocessor. Return true if the
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
188 preprocessor succeeded, false if there were any errors.
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
189 ('body' probably isn't of much use, but what the heck.)
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
190 """
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
191 from distutils.ccompiler import CompileError
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
192 self._check_compiler()
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
193 ok = 1
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
194 try:
19302
ed9abab97107 [Patch #442530 from twburton]
Andrew M. Kuchling <amk@amk.ca>
parents: 19206
diff changeset
195 self._preprocess(body, headers, include_dirs, lang)
12979
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
196 except CompileError:
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
197 ok = 0
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
198
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
199 self._clean()
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
200 return ok
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
201
13029
70b16dc6137f Added 'include_dirs' parameters all over the place.
Greg Ward <gward@python.net>
parents: 12979
diff changeset
202 def search_cpp (self, pattern, body=None,
70b16dc6137f Added 'include_dirs' parameters all over the place.
Greg Ward <gward@python.net>
parents: 12979
diff changeset
203 headers=None, include_dirs=None, lang="c"):
12979
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
204 """Construct a source file (just like 'try_cpp()'), run it through
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
205 the preprocessor, and return true if any line of the output matches
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
206 'pattern'. 'pattern' should either be a compiled regex object or a
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
207 string containing a regex. If both 'body' and 'headers' are None,
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
208 preprocesses an empty file -- which can be useful to determine the
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
209 symbols the preprocessor and compiler set by default.
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
210 """
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
211
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
212 self._check_compiler()
19302
ed9abab97107 [Patch #442530 from twburton]
Andrew M. Kuchling <amk@amk.ca>
parents: 19206
diff changeset
213 (src, out) = self._preprocess(body, headers, include_dirs, lang)
12979
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
214
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
215 if type(pattern) is StringType:
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
216 pattern = re.compile(pattern)
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
217
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
218 file = open(out)
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
219 match = 0
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
220 while 1:
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
221 line = file.readline()
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
222 if line == '':
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
223 break
19302
ed9abab97107 [Patch #442530 from twburton]
Andrew M. Kuchling <amk@amk.ca>
parents: 19206
diff changeset
224 if pattern.search(line):
12979
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
225 match = 1
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
226 break
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
227
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
228 file.close()
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
229 self._clean()
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
230 return match
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
231
13029
70b16dc6137f Added 'include_dirs' parameters all over the place.
Greg Ward <gward@python.net>
parents: 12979
diff changeset
232 def try_compile (self, body, headers=None, include_dirs=None, lang="c"):
12979
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
233 """Try to compile a source file built from 'body' and 'headers'.
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
234 Return true on success, false otherwise.
12864
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
235 """
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
236 from distutils.ccompiler import CompileError
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
237 self._check_compiler()
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
238 try:
19302
ed9abab97107 [Patch #442530 from twburton]
Andrew M. Kuchling <amk@amk.ca>
parents: 19206
diff changeset
239 self._compile(body, headers, include_dirs, lang)
12864
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
240 ok = 1
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
241 except CompileError:
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
242 ok = 0
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
243
23668
ca87119255eb Make setup.py less chatty by default.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 21268
diff changeset
244 log.info(ok and "success!" or "failure.")
12979
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
245 self._clean()
12864
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
246 return ok
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
247
13029
70b16dc6137f Added 'include_dirs' parameters all over the place.
Greg Ward <gward@python.net>
parents: 12979
diff changeset
248 def try_link (self, body,
70b16dc6137f Added 'include_dirs' parameters all over the place.
Greg Ward <gward@python.net>
parents: 12979
diff changeset
249 headers=None, include_dirs=None,
12979
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
250 libraries=None, library_dirs=None,
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
251 lang="c"):
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
252 """Try to compile and link a source file, built from 'body' and
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
253 'headers', to executable form. Return true on success, false
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
254 otherwise.
12864
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
255 """
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
256 from distutils.ccompiler import CompileError, LinkError
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
257 self._check_compiler()
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
258 try:
13029
70b16dc6137f Added 'include_dirs' parameters all over the place.
Greg Ward <gward@python.net>
parents: 12979
diff changeset
259 self._link(body, headers, include_dirs,
70b16dc6137f Added 'include_dirs' parameters all over the place.
Greg Ward <gward@python.net>
parents: 12979
diff changeset
260 libraries, library_dirs, lang)
12864
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
261 ok = 1
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
262 except (CompileError, LinkError):
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
263 ok = 0
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
264
23668
ca87119255eb Make setup.py less chatty by default.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 21268
diff changeset
265 log.info(ok and "success!" or "failure.")
12979
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
266 self._clean()
12864
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
267 return ok
21268
d296e6bb17e5 Whitespace normalization.
Fred Drake <fdrake@acm.org>
parents: 19303
diff changeset
268
13029
70b16dc6137f Added 'include_dirs' parameters all over the place.
Greg Ward <gward@python.net>
parents: 12979
diff changeset
269 def try_run (self, body,
70b16dc6137f Added 'include_dirs' parameters all over the place.
Greg Ward <gward@python.net>
parents: 12979
diff changeset
270 headers=None, include_dirs=None,
12979
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
271 libraries=None, library_dirs=None,
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
272 lang="c"):
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
273 """Try to compile, link to an executable, and run a program
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
274 built from 'body' and 'headers'. Return true on success, false
12864
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
275 otherwise.
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
276 """
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
277 from distutils.ccompiler import CompileError, LinkError
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
278 self._check_compiler()
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
279 try:
19206
de1c2d4d72ba Fix for NameError caught by PyChecker.
Andrew M. Kuchling <amk@amk.ca>
parents: 15215
diff changeset
280 src, obj, exe = self._link(body, headers, include_dirs,
de1c2d4d72ba Fix for NameError caught by PyChecker.
Andrew M. Kuchling <amk@amk.ca>
parents: 15215
diff changeset
281 libraries, library_dirs, lang)
12864
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
282 self.spawn([exe])
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
283 ok = 1
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
284 except (CompileError, LinkError, DistutilsExecError):
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
285 ok = 0
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
286
23668
ca87119255eb Make setup.py less chatty by default.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 21268
diff changeset
287 log.info(ok and "success!" or "failure.")
12979
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
288 self._clean()
12864
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
289 return ok
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
290
12979
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
291
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
292 # -- High-level methods --------------------------------------------
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
293 # (these are the ones that are actually likely to be useful
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
294 # when implementing a real-world config command!)
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
295
13029
70b16dc6137f Added 'include_dirs' parameters all over the place.
Greg Ward <gward@python.net>
parents: 12979
diff changeset
296 def check_func (self, func,
70b16dc6137f Added 'include_dirs' parameters all over the place.
Greg Ward <gward@python.net>
parents: 12979
diff changeset
297 headers=None, include_dirs=None,
12979
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
298 libraries=None, library_dirs=None,
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
299 decl=0, call=0):
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
300
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
301 """Determine if function 'func' is available by constructing a
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
302 source file that refers to 'func', and compiles and links it.
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
303 If everything succeeds, returns true; otherwise returns false.
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
304
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
305 The constructed source file starts out by including the header
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
306 files listed in 'headers'. If 'decl' is true, it then declares
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
307 'func' (as "int func()"); you probably shouldn't supply 'headers'
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
308 and set 'decl' true in the same call, or you might get errors about
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
309 a conflicting declarations for 'func'. Finally, the constructed
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
310 'main()' function either references 'func' or (if 'call' is true)
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
311 calls it. 'libraries' and 'library_dirs' are used when
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
312 linking.
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
313 """
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
314
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
315 self._check_compiler()
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
316 body = []
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
317 if decl:
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
318 body.append("int %s ();" % func)
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
319 body.append("int main () {")
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
320 if call:
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
321 body.append(" %s();" % func)
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
322 else:
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
323 body.append(" %s;" % func)
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
324 body.append("}")
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
325 body = string.join(body, "\n") + "\n"
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
326
13029
70b16dc6137f Added 'include_dirs' parameters all over the place.
Greg Ward <gward@python.net>
parents: 12979
diff changeset
327 return self.try_link(body, headers, include_dirs,
70b16dc6137f Added 'include_dirs' parameters all over the place.
Greg Ward <gward@python.net>
parents: 12979
diff changeset
328 libraries, library_dirs)
12979
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
329
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
330 # check_func ()
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
331
13029
70b16dc6137f Added 'include_dirs' parameters all over the place.
Greg Ward <gward@python.net>
parents: 12979
diff changeset
332 def check_lib (self, library, library_dirs=None,
15215
9598650f2bc9 Bastian Kleineidam: make 'check_lib()' more like AC_CHECK_LIB by adding
Greg Ward <gward@python.net>
parents: 15213
diff changeset
333 headers=None, include_dirs=None, other_libraries=[]):
13029
70b16dc6137f Added 'include_dirs' parameters all over the place.
Greg Ward <gward@python.net>
parents: 12979
diff changeset
334 """Determine if 'library' is available to be linked against,
70b16dc6137f Added 'include_dirs' parameters all over the place.
Greg Ward <gward@python.net>
parents: 12979
diff changeset
335 without actually checking that any particular symbols are provided
70b16dc6137f Added 'include_dirs' parameters all over the place.
Greg Ward <gward@python.net>
parents: 12979
diff changeset
336 by it. 'headers' will be used in constructing the source file to
70b16dc6137f Added 'include_dirs' parameters all over the place.
Greg Ward <gward@python.net>
parents: 12979
diff changeset
337 be compiled, but the only effect of this is to check if all the
15215
9598650f2bc9 Bastian Kleineidam: make 'check_lib()' more like AC_CHECK_LIB by adding
Greg Ward <gward@python.net>
parents: 15213
diff changeset
338 header files listed are available. Any libraries listed in
9598650f2bc9 Bastian Kleineidam: make 'check_lib()' more like AC_CHECK_LIB by adding
Greg Ward <gward@python.net>
parents: 15213
diff changeset
339 'other_libraries' will be included in the link, in case 'library'
9598650f2bc9 Bastian Kleineidam: make 'check_lib()' more like AC_CHECK_LIB by adding
Greg Ward <gward@python.net>
parents: 15213
diff changeset
340 has symbols that depend on other libraries.
13029
70b16dc6137f Added 'include_dirs' parameters all over the place.
Greg Ward <gward@python.net>
parents: 12979
diff changeset
341 """
70b16dc6137f Added 'include_dirs' parameters all over the place.
Greg Ward <gward@python.net>
parents: 12979
diff changeset
342 self._check_compiler()
70b16dc6137f Added 'include_dirs' parameters all over the place.
Greg Ward <gward@python.net>
parents: 12979
diff changeset
343 return self.try_link("int main (void) { }",
15215
9598650f2bc9 Bastian Kleineidam: make 'check_lib()' more like AC_CHECK_LIB by adding
Greg Ward <gward@python.net>
parents: 15213
diff changeset
344 headers, include_dirs,
9598650f2bc9 Bastian Kleineidam: make 'check_lib()' more like AC_CHECK_LIB by adding
Greg Ward <gward@python.net>
parents: 15213
diff changeset
345 [library]+other_libraries, library_dirs)
13029
70b16dc6137f Added 'include_dirs' parameters all over the place.
Greg Ward <gward@python.net>
parents: 12979
diff changeset
346
70b16dc6137f Added 'include_dirs' parameters all over the place.
Greg Ward <gward@python.net>
parents: 12979
diff changeset
347 def check_header (self, header, include_dirs=None,
70b16dc6137f Added 'include_dirs' parameters all over the place.
Greg Ward <gward@python.net>
parents: 12979
diff changeset
348 library_dirs=None, lang="c"):
12979
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
349 """Determine if the system header file named by 'header_file'
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
350 exists and can be found by the preprocessor; return true if so,
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
351 false otherwise.
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
352 """
25174
29efc2d83ade Include an empty body when checking for a header file
Andrew M. Kuchling <amk@amk.ca>
parents: 23668
diff changeset
353 return self.try_cpp(body="/* No body */", headers=[header],
29efc2d83ade Include an empty body when checking for a header file
Andrew M. Kuchling <amk@amk.ca>
parents: 23668
diff changeset
354 include_dirs=include_dirs)
12979
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
355
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
356
12864
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
357 # class config
12979
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
358
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
359
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
360 def dump_file (filename, head=None):
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
361 if head is None:
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
362 print filename + ":"
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
363 else:
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
364 print head
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
365
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
366 file = open(filename)
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
367 sys.stdout.write(file.read())
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
368 file.close()