annotate Lib/distutils/command/config.py @ 25838:8540887bcec6 2.2

Backport of 2.183: Fix memory leak in add_subclass() found by NealN with valgrind.
author Guido van Rossum <guido@python.org>
date Fri, 18 Oct 2002 13:42:21 +0000
parents 0c44fa04f533
children
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
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
12 # created 2000/05/29, Greg Ward
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
13
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
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
20
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
21
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
22 LANG_EXT = {'c': '.c',
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
23 'c++': '.cxx'}
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
24
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
25 class config (Command):
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
26
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
27 description = "prepare to build"
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
28
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
29 user_options = [
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
30 ('compiler=', None,
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
31 "specify the compiler type"),
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
32 ('cc=', None,
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
33 "specify the compiler executable"),
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
34 ('include-dirs=', 'I',
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
35 "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
36 ('define=', 'D',
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
37 "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
38 ('undef=', 'U',
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
39 "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
40 ('libraries=', 'l',
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
41 "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
42 ('library-dirs=', 'L',
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
43 "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
44
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
45 ('noisy', None,
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
46 "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
47 ('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
48 "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
49 ]
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 # 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
53 # 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
54
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
55 def initialize_options (self):
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
56 self.compiler = None
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
57 self.cc = None
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
58 self.include_dirs = None
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
59 #self.define = None
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
60 #self.undef = None
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
61 self.libraries = None
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
62 self.library_dirs = None
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
63
12979
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
64 # 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
65 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
66 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
67
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
68 # 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
69 # 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
70 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
71
12864
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
72 def finalize_options (self):
15213
882cefe21dc3 Bastian Kleineidam: fix up any supplied command-line options.
Greg Ward <gward@python.net>
parents: 14948
diff changeset
73 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
74 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
75 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
76 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
77
882cefe21dc3 Bastian Kleineidam: fix up any supplied command-line options.
Greg Ward <gward@python.net>
parents: 14948
diff changeset
78 if self.libraries is None:
882cefe21dc3 Bastian Kleineidam: fix up any supplied command-line options.
Greg Ward <gward@python.net>
parents: 14948
diff changeset
79 self.libraries = []
882cefe21dc3 Bastian Kleineidam: fix up any supplied command-line options.
Greg Ward <gward@python.net>
parents: 14948
diff changeset
80 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
81 self.libraries = [self.libraries]
882cefe21dc3 Bastian Kleineidam: fix up any supplied command-line options.
Greg Ward <gward@python.net>
parents: 14948
diff changeset
82
882cefe21dc3 Bastian Kleineidam: fix up any supplied command-line options.
Greg Ward <gward@python.net>
parents: 14948
diff changeset
83 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
84 self.library_dirs = []
882cefe21dc3 Bastian Kleineidam: fix up any supplied command-line options.
Greg Ward <gward@python.net>
parents: 14948
diff changeset
85 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
86 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
87
12864
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
88
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
89 def run (self):
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
90 pass
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
91
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 # 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
94 # 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
95 # may use these freely.
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
96
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
97 def _check_compiler (self):
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
98 """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
99 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
100 """
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
101 # 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
102 # import.
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
103 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
104 if not isinstance(self.compiler, CCompiler):
14948
7acb8bbc215b Standardized whitespace around function calls.
Greg Ward <gward@python.net>
parents: 13029
diff changeset
105 self.compiler = new_compiler(compiler=self.compiler,
7acb8bbc215b Standardized whitespace around function calls.
Greg Ward <gward@python.net>
parents: 13029
diff changeset
106 verbose=self.noisy,
7acb8bbc215b Standardized whitespace around function calls.
Greg Ward <gward@python.net>
parents: 13029
diff changeset
107 dry_run=self.dry_run,
7acb8bbc215b Standardized whitespace around function calls.
Greg Ward <gward@python.net>
parents: 13029
diff changeset
108 force=1)
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,
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
153 library_dirs=library_dirs)
19303
cea945764db2 [Patch #444854 from twburton]
Andrew M. Kuchling <amk@amk.ca>
parents: 19302
diff changeset
154
cea945764db2 [Patch #444854 from twburton]
Andrew M. Kuchling <amk@amk.ca>
parents: 19302
diff changeset
155 prog = prog + self.compiler.exe_extension
cea945764db2 [Patch #444854 from twburton]
Andrew M. Kuchling <amk@amk.ca>
parents: 19302
diff changeset
156 self.temp_files.append(prog)
cea945764db2 [Patch #444854 from twburton]
Andrew M. Kuchling <amk@amk.ca>
parents: 19302
diff changeset
157
12979
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
158 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
159
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
160 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
161 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
162 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
163 self.temp_files = []
12864
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
164 self.announce("removing: " + string.join(filenames))
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
165 for filename in filenames:
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
166 try:
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
167 os.remove(filename)
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
168 except OSError:
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
169 pass
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
170
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
171
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
172 # 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
173 # 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
174 # 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
175 # 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
176 # 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
177 # 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
178 # which is correct.
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
179
12979
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
180 # 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
181
13029
70b16dc6137f Added 'include_dirs' parameters all over the place.
Greg Ward <gward@python.net>
parents: 12979
diff changeset
182 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
183 """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
184 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
185 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
186 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
187 ('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
188 """
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
189 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
190 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
191 ok = 1
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
192 try:
19302
ed9abab97107 [Patch #442530 from twburton]
Andrew M. Kuchling <amk@amk.ca>
parents: 19206
diff changeset
193 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
194 except CompileError:
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
195 ok = 0
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
196
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
197 self._clean()
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
198 return ok
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
199
13029
70b16dc6137f Added 'include_dirs' parameters all over the place.
Greg Ward <gward@python.net>
parents: 12979
diff changeset
200 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
201 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
202 """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
203 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
204 '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
205 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
206 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
207 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
208 """
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
209
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
210 self._check_compiler()
19302
ed9abab97107 [Patch #442530 from twburton]
Andrew M. Kuchling <amk@amk.ca>
parents: 19206
diff changeset
211 (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
212
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
213 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
214 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
215
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
216 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
217 match = 0
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
218 while 1:
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
219 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
220 if line == '':
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
221 break
19302
ed9abab97107 [Patch #442530 from twburton]
Andrew M. Kuchling <amk@amk.ca>
parents: 19206
diff changeset
222 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
223 match = 1
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
224 break
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
225
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
226 file.close()
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
227 self._clean()
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
228 return match
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
229
13029
70b16dc6137f Added 'include_dirs' parameters all over the place.
Greg Ward <gward@python.net>
parents: 12979
diff changeset
230 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
231 """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
232 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
233 """
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
234 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
235 self._check_compiler()
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
236 try:
19302
ed9abab97107 [Patch #442530 from twburton]
Andrew M. Kuchling <amk@amk.ca>
parents: 19206
diff changeset
237 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
238 ok = 1
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
239 except CompileError:
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
240 ok = 0
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
241
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
242 self.announce(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
243 self._clean()
12864
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
244 return ok
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
245
13029
70b16dc6137f Added 'include_dirs' parameters all over the place.
Greg Ward <gward@python.net>
parents: 12979
diff changeset
246 def try_link (self, body,
70b16dc6137f Added 'include_dirs' parameters all over the place.
Greg Ward <gward@python.net>
parents: 12979
diff changeset
247 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
248 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
249 lang="c"):
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
250 """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
251 '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
252 otherwise.
12864
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
253 """
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
254 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
255 self._check_compiler()
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
256 try:
13029
70b16dc6137f Added 'include_dirs' parameters all over the place.
Greg Ward <gward@python.net>
parents: 12979
diff changeset
257 self._link(body, headers, include_dirs,
70b16dc6137f Added 'include_dirs' parameters all over the place.
Greg Ward <gward@python.net>
parents: 12979
diff changeset
258 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
259 ok = 1
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
260 except (CompileError, LinkError):
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
261 ok = 0
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
262
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
263 self.announce(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
264 self._clean()
12864
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
265 return ok
21268
d296e6bb17e5 Whitespace normalization.
Fred Drake <fdrake@acm.org>
parents: 19303
diff changeset
266
13029
70b16dc6137f Added 'include_dirs' parameters all over the place.
Greg Ward <gward@python.net>
parents: 12979
diff changeset
267 def try_run (self, body,
70b16dc6137f Added 'include_dirs' parameters all over the place.
Greg Ward <gward@python.net>
parents: 12979
diff changeset
268 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
269 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
270 lang="c"):
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
271 """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
272 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
273 otherwise.
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
274 """
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
275 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
276 self._check_compiler()
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
277 try:
19206
de1c2d4d72ba Fix for NameError caught by PyChecker.
Andrew M. Kuchling <amk@amk.ca>
parents: 15215
diff changeset
278 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
279 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
280 self.spawn([exe])
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
281 ok = 1
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
282 except (CompileError, LinkError, DistutilsExecError):
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
283 ok = 0
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
284
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
285 self.announce(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
286 self._clean()
12864
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
287 return ok
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
288
12979
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
289
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
290 # -- 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
291 # (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
292 # 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
293
13029
70b16dc6137f Added 'include_dirs' parameters all over the place.
Greg Ward <gward@python.net>
parents: 12979
diff changeset
294 def check_func (self, func,
70b16dc6137f Added 'include_dirs' parameters all over the place.
Greg Ward <gward@python.net>
parents: 12979
diff changeset
295 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
296 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
297 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
298
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
299 """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
300 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
301 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
302
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
303 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
304 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
305 '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
306 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
307 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
308 '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
309 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
310 linking.
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
311 """
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
312
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
313 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
314 body = []
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
315 if decl:
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
316 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
317 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
318 if call:
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(" %s();" % func)
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
320 else:
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 body.append("}")
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
323 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
324
13029
70b16dc6137f Added 'include_dirs' parameters all over the place.
Greg Ward <gward@python.net>
parents: 12979
diff changeset
325 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
326 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
327
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
328 # check_func ()
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
329
13029
70b16dc6137f Added 'include_dirs' parameters all over the place.
Greg Ward <gward@python.net>
parents: 12979
diff changeset
330 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
331 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
332 """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
333 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
334 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
335 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
336 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
337 '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
338 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
339 """
70b16dc6137f Added 'include_dirs' parameters all over the place.
Greg Ward <gward@python.net>
parents: 12979
diff changeset
340 self._check_compiler()
70b16dc6137f Added 'include_dirs' parameters all over the place.
Greg Ward <gward@python.net>
parents: 12979
diff changeset
341 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
342 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
343 [library]+other_libraries, library_dirs)
13029
70b16dc6137f Added 'include_dirs' parameters all over the place.
Greg Ward <gward@python.net>
parents: 12979
diff changeset
344
70b16dc6137f Added 'include_dirs' parameters all over the place.
Greg Ward <gward@python.net>
parents: 12979
diff changeset
345 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
346 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
347 """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
348 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
349 false otherwise.
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
350 """
25382
0c44fa04f533 backport akuchling's checkin of
Michael W. Hudson <mwh@python.net>
parents: 21268
diff changeset
351 return self.try_cpp(body="/* No body */", headers=[header],
0c44fa04f533 backport akuchling's checkin of
Michael W. Hudson <mwh@python.net>
parents: 21268
diff changeset
352 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
353
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
354
12864
31d0988da8a9 First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff changeset
355 # 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
356
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
357
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
358 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
359 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
360 print filename + ":"
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
361 else:
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
362 print head
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
363
400382190364 Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents: 12864
diff changeset
364 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
365 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
366 file.close()