annotate Lib/distutils/extension.py @ 54294:dba767bc3155 legacy-trunk

remove mention of old ctypes version
author Benjamin Peterson <benjamin@python.org>
date Sat, 23 May 2009 20:59:09 +0000
parents 5856fae009e8
children 98d8b8b749f4
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
12799
d81c95dd4039 Provides the Extension class, a nicer way to describe C/C++ extensions than
Greg Ward <gward@python.net>
parents:
diff changeset
1 """distutils.extension
d81c95dd4039 Provides the Extension class, a nicer way to describe C/C++ extensions than
Greg Ward <gward@python.net>
parents:
diff changeset
2
d81c95dd4039 Provides the Extension class, a nicer way to describe C/C++ extensions than
Greg Ward <gward@python.net>
parents:
diff changeset
3 Provides the Extension class, used to describe C/C++ extension
d81c95dd4039 Provides the Extension class, a nicer way to describe C/C++ extensions than
Greg Ward <gward@python.net>
parents:
diff changeset
4 modules in setup scripts."""
d81c95dd4039 Provides the Extension class, a nicer way to describe C/C++ extensions than
Greg Ward <gward@python.net>
parents:
diff changeset
5
d81c95dd4039 Provides the Extension class, a nicer way to describe C/C++ extensions than
Greg Ward <gward@python.net>
parents:
diff changeset
6 __revision__ = "$Id$"
d81c95dd4039 Provides the Extension class, a nicer way to describe C/C++ extensions than
Greg Ward <gward@python.net>
parents:
diff changeset
7
26305
32df8d5960d1 Add missing import
Andrew M. Kuchling <amk@amk.ca>
parents: 26210
diff changeset
8 import os, string, sys
12799
d81c95dd4039 Provides the Extension class, a nicer way to describe C/C++ extensions than
Greg Ward <gward@python.net>
parents:
diff changeset
9 from types import *
d81c95dd4039 Provides the Extension class, a nicer way to describe C/C++ extensions than
Greg Ward <gward@python.net>
parents:
diff changeset
10
26198
1df98f68d607 Allow unknown keyword arguments to the Extension class, and warn about them.
Andrew M. Kuchling <amk@amk.ca>
parents: 26036
diff changeset
11 try:
1df98f68d607 Allow unknown keyword arguments to the Extension class, and warn about them.
Andrew M. Kuchling <amk@amk.ca>
parents: 26036
diff changeset
12 import warnings
1df98f68d607 Allow unknown keyword arguments to the Extension class, and warn about them.
Andrew M. Kuchling <amk@amk.ca>
parents: 26036
diff changeset
13 except ImportError:
1df98f68d607 Allow unknown keyword arguments to the Extension class, and warn about them.
Andrew M. Kuchling <amk@amk.ca>
parents: 26036
diff changeset
14 warnings = None
12799
d81c95dd4039 Provides the Extension class, a nicer way to describe C/C++ extensions than
Greg Ward <gward@python.net>
parents:
diff changeset
15
d81c95dd4039 Provides the Extension class, a nicer way to describe C/C++ extensions than
Greg Ward <gward@python.net>
parents:
diff changeset
16 # This class is really only used by the "build_ext" command, so it might
d81c95dd4039 Provides the Extension class, a nicer way to describe C/C++ extensions than
Greg Ward <gward@python.net>
parents:
diff changeset
17 # make sense to put it in distutils.command.build_ext. However, that
d81c95dd4039 Provides the Extension class, a nicer way to describe C/C++ extensions than
Greg Ward <gward@python.net>
parents:
diff changeset
18 # module is already big enough, and I want to make this class a bit more
d81c95dd4039 Provides the Extension class, a nicer way to describe C/C++ extensions than
Greg Ward <gward@python.net>
parents:
diff changeset
19 # complex to simplify some common cases ("foo" module in "foo.c") and do
d81c95dd4039 Provides the Extension class, a nicer way to describe C/C++ extensions than
Greg Ward <gward@python.net>
parents:
diff changeset
20 # better error-checking ("foo.c" actually exists).
21267
7a7f557b4d54 Whitespace normalization.
Fred Drake <fdrake@acm.org>
parents: 17129
diff changeset
21 #
12799
d81c95dd4039 Provides the Extension class, a nicer way to describe C/C++ extensions than
Greg Ward <gward@python.net>
parents:
diff changeset
22 # Also, putting this in build_ext.py means every setup script would have to
d81c95dd4039 Provides the Extension class, a nicer way to describe C/C++ extensions than
Greg Ward <gward@python.net>
parents:
diff changeset
23 # import that large-ish module (indirectly, through distutils.core) in
d81c95dd4039 Provides the Extension class, a nicer way to describe C/C++ extensions than
Greg Ward <gward@python.net>
parents:
diff changeset
24 # order to do anything.
d81c95dd4039 Provides the Extension class, a nicer way to describe C/C++ extensions than
Greg Ward <gward@python.net>
parents:
diff changeset
25
d81c95dd4039 Provides the Extension class, a nicer way to describe C/C++ extensions than
Greg Ward <gward@python.net>
parents:
diff changeset
26 class Extension:
d81c95dd4039 Provides the Extension class, a nicer way to describe C/C++ extensions than
Greg Ward <gward@python.net>
parents:
diff changeset
27 """Just a collection of attributes that describes an extension
d81c95dd4039 Provides the Extension class, a nicer way to describe C/C++ extensions than
Greg Ward <gward@python.net>
parents:
diff changeset
28 module and everything needed to build it (hopefully in a portable
13948
26898a98db6e Typo fix in docstring.
Greg Ward <gward@python.net>
parents: 13800
diff changeset
29 way, but there are hooks that let you be as unportable as you need).
12799
d81c95dd4039 Provides the Extension class, a nicer way to describe C/C++ extensions than
Greg Ward <gward@python.net>
parents:
diff changeset
30
d81c95dd4039 Provides the Extension class, a nicer way to describe C/C++ extensions than
Greg Ward <gward@python.net>
parents:
diff changeset
31 Instance attributes:
d81c95dd4039 Provides the Extension class, a nicer way to describe C/C++ extensions than
Greg Ward <gward@python.net>
parents:
diff changeset
32 name : string
d81c95dd4039 Provides the Extension class, a nicer way to describe C/C++ extensions than
Greg Ward <gward@python.net>
parents:
diff changeset
33 the full name of the extension, including any packages -- ie.
d81c95dd4039 Provides the Extension class, a nicer way to describe C/C++ extensions than
Greg Ward <gward@python.net>
parents:
diff changeset
34 *not* a filename or pathname, but Python dotted name
d81c95dd4039 Provides the Extension class, a nicer way to describe C/C++ extensions than
Greg Ward <gward@python.net>
parents:
diff changeset
35 sources : [string]
12995
c910b9d9a0c0 Revised docstring so 'sources' isn't necessarily all C/C++ files (to
Greg Ward <gward@python.net>
parents: 12799
diff changeset
36 list of source filenames, relative to the distribution root
c910b9d9a0c0 Revised docstring so 'sources' isn't necessarily all C/C++ files (to
Greg Ward <gward@python.net>
parents: 12799
diff changeset
37 (where the setup script lives), in Unix form (slash-separated)
c910b9d9a0c0 Revised docstring so 'sources' isn't necessarily all C/C++ files (to
Greg Ward <gward@python.net>
parents: 12799
diff changeset
38 for portability. Source files may be C, C++, SWIG (.i),
c910b9d9a0c0 Revised docstring so 'sources' isn't necessarily all C/C++ files (to
Greg Ward <gward@python.net>
parents: 12799
diff changeset
39 platform-specific resource files, or whatever else is recognized
c910b9d9a0c0 Revised docstring so 'sources' isn't necessarily all C/C++ files (to
Greg Ward <gward@python.net>
parents: 12799
diff changeset
40 by the "build_ext" command as source for a Python extension.
12799
d81c95dd4039 Provides the Extension class, a nicer way to describe C/C++ extensions than
Greg Ward <gward@python.net>
parents:
diff changeset
41 include_dirs : [string]
d81c95dd4039 Provides the Extension class, a nicer way to describe C/C++ extensions than
Greg Ward <gward@python.net>
parents:
diff changeset
42 list of directories to search for C/C++ header files (in Unix
d81c95dd4039 Provides the Extension class, a nicer way to describe C/C++ extensions than
Greg Ward <gward@python.net>
parents:
diff changeset
43 form for portability)
d81c95dd4039 Provides the Extension class, a nicer way to describe C/C++ extensions than
Greg Ward <gward@python.net>
parents:
diff changeset
44 define_macros : [(name : string, value : string|None)]
d81c95dd4039 Provides the Extension class, a nicer way to describe C/C++ extensions than
Greg Ward <gward@python.net>
parents:
diff changeset
45 list of macros to define; each macro is defined using a 2-tuple,
d81c95dd4039 Provides the Extension class, a nicer way to describe C/C++ extensions than
Greg Ward <gward@python.net>
parents:
diff changeset
46 where 'value' is either the string to define it to or None to
d81c95dd4039 Provides the Extension class, a nicer way to describe C/C++ extensions than
Greg Ward <gward@python.net>
parents:
diff changeset
47 define it without a particular value (equivalent of "#define
d81c95dd4039 Provides the Extension class, a nicer way to describe C/C++ extensions than
Greg Ward <gward@python.net>
parents:
diff changeset
48 FOO" in source or -DFOO on Unix C compiler command line)
d81c95dd4039 Provides the Extension class, a nicer way to describe C/C++ extensions than
Greg Ward <gward@python.net>
parents:
diff changeset
49 undef_macros : [string]
d81c95dd4039 Provides the Extension class, a nicer way to describe C/C++ extensions than
Greg Ward <gward@python.net>
parents:
diff changeset
50 list of macros to undefine explicitly
d81c95dd4039 Provides the Extension class, a nicer way to describe C/C++ extensions than
Greg Ward <gward@python.net>
parents:
diff changeset
51 library_dirs : [string]
d81c95dd4039 Provides the Extension class, a nicer way to describe C/C++ extensions than
Greg Ward <gward@python.net>
parents:
diff changeset
52 list of directories to search for C/C++ libraries at link time
d81c95dd4039 Provides the Extension class, a nicer way to describe C/C++ extensions than
Greg Ward <gward@python.net>
parents:
diff changeset
53 libraries : [string]
d81c95dd4039 Provides the Extension class, a nicer way to describe C/C++ extensions than
Greg Ward <gward@python.net>
parents:
diff changeset
54 list of library names (not filenames or paths) to link against
d81c95dd4039 Provides the Extension class, a nicer way to describe C/C++ extensions than
Greg Ward <gward@python.net>
parents:
diff changeset
55 runtime_library_dirs : [string]
d81c95dd4039 Provides the Extension class, a nicer way to describe C/C++ extensions than
Greg Ward <gward@python.net>
parents:
diff changeset
56 list of directories to search for C/C++ libraries at run time
d81c95dd4039 Provides the Extension class, a nicer way to describe C/C++ extensions than
Greg Ward <gward@python.net>
parents:
diff changeset
57 (for shared extensions, this is when the extension is loaded)
d81c95dd4039 Provides the Extension class, a nicer way to describe C/C++ extensions than
Greg Ward <gward@python.net>
parents:
diff changeset
58 extra_objects : [string]
d81c95dd4039 Provides the Extension class, a nicer way to describe C/C++ extensions than
Greg Ward <gward@python.net>
parents:
diff changeset
59 list of extra files to link with (eg. object files not implied
d81c95dd4039 Provides the Extension class, a nicer way to describe C/C++ extensions than
Greg Ward <gward@python.net>
parents:
diff changeset
60 by 'sources', static library that must be explicitly specified,
d81c95dd4039 Provides the Extension class, a nicer way to describe C/C++ extensions than
Greg Ward <gward@python.net>
parents:
diff changeset
61 binary resource files, etc.)
d81c95dd4039 Provides the Extension class, a nicer way to describe C/C++ extensions than
Greg Ward <gward@python.net>
parents:
diff changeset
62 extra_compile_args : [string]
d81c95dd4039 Provides the Extension class, a nicer way to describe C/C++ extensions than
Greg Ward <gward@python.net>
parents:
diff changeset
63 any extra platform- and compiler-specific information to use
d81c95dd4039 Provides the Extension class, a nicer way to describe C/C++ extensions than
Greg Ward <gward@python.net>
parents:
diff changeset
64 when compiling the source files in 'sources'. For platforms and
d81c95dd4039 Provides the Extension class, a nicer way to describe C/C++ extensions than
Greg Ward <gward@python.net>
parents:
diff changeset
65 compilers where "command line" makes sense, this is typically a
d81c95dd4039 Provides the Extension class, a nicer way to describe C/C++ extensions than
Greg Ward <gward@python.net>
parents:
diff changeset
66 list of command-line arguments, but for other platforms it could
d81c95dd4039 Provides the Extension class, a nicer way to describe C/C++ extensions than
Greg Ward <gward@python.net>
parents:
diff changeset
67 be anything.
d81c95dd4039 Provides the Extension class, a nicer way to describe C/C++ extensions than
Greg Ward <gward@python.net>
parents:
diff changeset
68 extra_link_args : [string]
d81c95dd4039 Provides the Extension class, a nicer way to describe C/C++ extensions than
Greg Ward <gward@python.net>
parents:
diff changeset
69 any extra platform- and compiler-specific information to use
d81c95dd4039 Provides the Extension class, a nicer way to describe C/C++ extensions than
Greg Ward <gward@python.net>
parents:
diff changeset
70 when linking object files together to create the extension (or
d81c95dd4039 Provides the Extension class, a nicer way to describe C/C++ extensions than
Greg Ward <gward@python.net>
parents:
diff changeset
71 to create a new static Python interpreter). Similar
d81c95dd4039 Provides the Extension class, a nicer way to describe C/C++ extensions than
Greg Ward <gward@python.net>
parents:
diff changeset
72 interpretation as for 'extra_compile_args'.
d81c95dd4039 Provides the Extension class, a nicer way to describe C/C++ extensions than
Greg Ward <gward@python.net>
parents:
diff changeset
73 export_symbols : [string]
d81c95dd4039 Provides the Extension class, a nicer way to describe C/C++ extensions than
Greg Ward <gward@python.net>
parents:
diff changeset
74 list of symbols to be exported from a shared extension. Not
d81c95dd4039 Provides the Extension class, a nicer way to describe C/C++ extensions than
Greg Ward <gward@python.net>
parents:
diff changeset
75 used on all platforms, and not generally necessary for Python
d81c95dd4039 Provides the Extension class, a nicer way to describe C/C++ extensions than
Greg Ward <gward@python.net>
parents:
diff changeset
76 extensions, which typically export exactly one symbol: "init" +
d81c95dd4039 Provides the Extension class, a nicer way to describe C/C++ extensions than
Greg Ward <gward@python.net>
parents:
diff changeset
77 extension_name.
33759
11d01fc650dc Patch 1046644 - improved distutils support for SWIG.
Anthony Baxter <anthonybaxter@gmail.com>
parents: 27416
diff changeset
78 swig_opts : [string]
11d01fc650dc Patch 1046644 - improved distutils support for SWIG.
Anthony Baxter <anthonybaxter@gmail.com>
parents: 27416
diff changeset
79 any extra options to pass to SWIG if a source file has the .i
11d01fc650dc Patch 1046644 - improved distutils support for SWIG.
Anthony Baxter <anthonybaxter@gmail.com>
parents: 27416
diff changeset
80 extension.
23792
7dd432e1de26 Add a new definition to Extension objects: depends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 22663
diff changeset
81 depends : [string]
7dd432e1de26 Add a new definition to Extension objects: depends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 22663
diff changeset
82 list of files that the extension depends on
26036
771b6f521b95 This patch fixes the following bugs:
Gustavo Niemeyer <gustavo@niemeyer.net>
parents: 23792
diff changeset
83 language : string
771b6f521b95 This patch fixes the following bugs:
Gustavo Niemeyer <gustavo@niemeyer.net>
parents: 23792
diff changeset
84 extension language (i.e. "c", "c++", "objc"). Will be detected
771b6f521b95 This patch fixes the following bugs:
Gustavo Niemeyer <gustavo@niemeyer.net>
parents: 23792
diff changeset
85 from the source extensions if not provided.
52606
5856fae009e8 #5583 Added optional Extensions in Distutils
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 33759
diff changeset
86 optional : boolean
5856fae009e8 #5583 Added optional Extensions in Distutils
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 33759
diff changeset
87 specifies that a build failure in the extension should not abort the
5856fae009e8 #5583 Added optional Extensions in Distutils
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 33759
diff changeset
88 build process, but simply not install the failing extension.
12799
d81c95dd4039 Provides the Extension class, a nicer way to describe C/C++ extensions than
Greg Ward <gward@python.net>
parents:
diff changeset
89 """
d81c95dd4039 Provides the Extension class, a nicer way to describe C/C++ extensions than
Greg Ward <gward@python.net>
parents:
diff changeset
90
27416
20df24a13349 Remove the recently-added get_distutil_options(), and just
Andrew M. Kuchling <amk@amk.ca>
parents: 26444
diff changeset
91 # When adding arguments to this constructor, be sure to update
20df24a13349 Remove the recently-added get_distutil_options(), and just
Andrew M. Kuchling <amk@amk.ca>
parents: 26444
diff changeset
92 # setup_keywords in core.py.
12799
d81c95dd4039 Provides the Extension class, a nicer way to describe C/C++ extensions than
Greg Ward <gward@python.net>
parents:
diff changeset
93 def __init__ (self, name, sources,
d81c95dd4039 Provides the Extension class, a nicer way to describe C/C++ extensions than
Greg Ward <gward@python.net>
parents:
diff changeset
94 include_dirs=None,
d81c95dd4039 Provides the Extension class, a nicer way to describe C/C++ extensions than
Greg Ward <gward@python.net>
parents:
diff changeset
95 define_macros=None,
d81c95dd4039 Provides the Extension class, a nicer way to describe C/C++ extensions than
Greg Ward <gward@python.net>
parents:
diff changeset
96 undef_macros=None,
d81c95dd4039 Provides the Extension class, a nicer way to describe C/C++ extensions than
Greg Ward <gward@python.net>
parents:
diff changeset
97 library_dirs=None,
d81c95dd4039 Provides the Extension class, a nicer way to describe C/C++ extensions than
Greg Ward <gward@python.net>
parents:
diff changeset
98 libraries=None,
d81c95dd4039 Provides the Extension class, a nicer way to describe C/C++ extensions than
Greg Ward <gward@python.net>
parents:
diff changeset
99 runtime_library_dirs=None,
d81c95dd4039 Provides the Extension class, a nicer way to describe C/C++ extensions than
Greg Ward <gward@python.net>
parents:
diff changeset
100 extra_objects=None,
d81c95dd4039 Provides the Extension class, a nicer way to describe C/C++ extensions than
Greg Ward <gward@python.net>
parents:
diff changeset
101 extra_compile_args=None,
d81c95dd4039 Provides the Extension class, a nicer way to describe C/C++ extensions than
Greg Ward <gward@python.net>
parents:
diff changeset
102 extra_link_args=None,
d81c95dd4039 Provides the Extension class, a nicer way to describe C/C++ extensions than
Greg Ward <gward@python.net>
parents:
diff changeset
103 export_symbols=None,
33759
11d01fc650dc Patch 1046644 - improved distutils support for SWIG.
Anthony Baxter <anthonybaxter@gmail.com>
parents: 27416
diff changeset
104 swig_opts = None,
23792
7dd432e1de26 Add a new definition to Extension objects: depends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 22663
diff changeset
105 depends=None,
26036
771b6f521b95 This patch fixes the following bugs:
Gustavo Niemeyer <gustavo@niemeyer.net>
parents: 23792
diff changeset
106 language=None,
52606
5856fae009e8 #5583 Added optional Extensions in Distutils
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 33759
diff changeset
107 optional=None,
26198
1df98f68d607 Allow unknown keyword arguments to the Extension class, and warn about them.
Andrew M. Kuchling <amk@amk.ca>
parents: 26036
diff changeset
108 **kw # To catch unknown keywords
12799
d81c95dd4039 Provides the Extension class, a nicer way to describe C/C++ extensions than
Greg Ward <gward@python.net>
parents:
diff changeset
109 ):
d81c95dd4039 Provides the Extension class, a nicer way to describe C/C++ extensions than
Greg Ward <gward@python.net>
parents:
diff changeset
110 assert type(name) is StringType, "'name' must be a string"
d81c95dd4039 Provides the Extension class, a nicer way to describe C/C++ extensions than
Greg Ward <gward@python.net>
parents:
diff changeset
111 assert (type(sources) is ListType and
d81c95dd4039 Provides the Extension class, a nicer way to describe C/C++ extensions than
Greg Ward <gward@python.net>
parents:
diff changeset
112 map(type, sources) == [StringType]*len(sources)), \
14650
edda353bde12 Added 'read_setup_file()' to read old-style Setup files. Could make life
Greg Ward <gward@python.net>
parents: 13949
diff changeset
113 "'sources' must be a list of strings"
12799
d81c95dd4039 Provides the Extension class, a nicer way to describe C/C++ extensions than
Greg Ward <gward@python.net>
parents:
diff changeset
114
d81c95dd4039 Provides the Extension class, a nicer way to describe C/C++ extensions than
Greg Ward <gward@python.net>
parents:
diff changeset
115 self.name = name
d81c95dd4039 Provides the Extension class, a nicer way to describe C/C++ extensions than
Greg Ward <gward@python.net>
parents:
diff changeset
116 self.sources = sources
d81c95dd4039 Provides the Extension class, a nicer way to describe C/C++ extensions than
Greg Ward <gward@python.net>
parents:
diff changeset
117 self.include_dirs = include_dirs or []
d81c95dd4039 Provides the Extension class, a nicer way to describe C/C++ extensions than
Greg Ward <gward@python.net>
parents:
diff changeset
118 self.define_macros = define_macros or []
d81c95dd4039 Provides the Extension class, a nicer way to describe C/C++ extensions than
Greg Ward <gward@python.net>
parents:
diff changeset
119 self.undef_macros = undef_macros or []
d81c95dd4039 Provides the Extension class, a nicer way to describe C/C++ extensions than
Greg Ward <gward@python.net>
parents:
diff changeset
120 self.library_dirs = library_dirs or []
d81c95dd4039 Provides the Extension class, a nicer way to describe C/C++ extensions than
Greg Ward <gward@python.net>
parents:
diff changeset
121 self.libraries = libraries or []
d81c95dd4039 Provides the Extension class, a nicer way to describe C/C++ extensions than
Greg Ward <gward@python.net>
parents:
diff changeset
122 self.runtime_library_dirs = runtime_library_dirs or []
d81c95dd4039 Provides the Extension class, a nicer way to describe C/C++ extensions than
Greg Ward <gward@python.net>
parents:
diff changeset
123 self.extra_objects = extra_objects or []
d81c95dd4039 Provides the Extension class, a nicer way to describe C/C++ extensions than
Greg Ward <gward@python.net>
parents:
diff changeset
124 self.extra_compile_args = extra_compile_args or []
d81c95dd4039 Provides the Extension class, a nicer way to describe C/C++ extensions than
Greg Ward <gward@python.net>
parents:
diff changeset
125 self.extra_link_args = extra_link_args or []
13949
28afbc5e0770 Rene Liebscher: ext.export_symbols is now always a list (added 'or []').
Greg Ward <gward@python.net>
parents: 13948
diff changeset
126 self.export_symbols = export_symbols or []
33759
11d01fc650dc Patch 1046644 - improved distutils support for SWIG.
Anthony Baxter <anthonybaxter@gmail.com>
parents: 27416
diff changeset
127 self.swig_opts = swig_opts or []
23792
7dd432e1de26 Add a new definition to Extension objects: depends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 22663
diff changeset
128 self.depends = depends or []
26036
771b6f521b95 This patch fixes the following bugs:
Gustavo Niemeyer <gustavo@niemeyer.net>
parents: 23792
diff changeset
129 self.language = language
52606
5856fae009e8 #5583 Added optional Extensions in Distutils
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 33759
diff changeset
130 self.optional = optional
12799
d81c95dd4039 Provides the Extension class, a nicer way to describe C/C++ extensions than
Greg Ward <gward@python.net>
parents:
diff changeset
131
26198
1df98f68d607 Allow unknown keyword arguments to the Extension class, and warn about them.
Andrew M. Kuchling <amk@amk.ca>
parents: 26036
diff changeset
132 # If there are unknown keyword options, warn about them
1df98f68d607 Allow unknown keyword arguments to the Extension class, and warn about them.
Andrew M. Kuchling <amk@amk.ca>
parents: 26036
diff changeset
133 if len(kw):
1df98f68d607 Allow unknown keyword arguments to the Extension class, and warn about them.
Andrew M. Kuchling <amk@amk.ca>
parents: 26036
diff changeset
134 L = kw.keys() ; L.sort()
1df98f68d607 Allow unknown keyword arguments to the Extension class, and warn about them.
Andrew M. Kuchling <amk@amk.ca>
parents: 26036
diff changeset
135 L = map(repr, L)
1df98f68d607 Allow unknown keyword arguments to the Extension class, and warn about them.
Andrew M. Kuchling <amk@amk.ca>
parents: 26036
diff changeset
136 msg = "Unknown Extension options: " + string.join(L, ', ')
1df98f68d607 Allow unknown keyword arguments to the Extension class, and warn about them.
Andrew M. Kuchling <amk@amk.ca>
parents: 26036
diff changeset
137 if warnings is not None:
1df98f68d607 Allow unknown keyword arguments to the Extension class, and warn about them.
Andrew M. Kuchling <amk@amk.ca>
parents: 26036
diff changeset
138 warnings.warn(msg)
1df98f68d607 Allow unknown keyword arguments to the Extension class, and warn about them.
Andrew M. Kuchling <amk@amk.ca>
parents: 26036
diff changeset
139 else:
1df98f68d607 Allow unknown keyword arguments to the Extension class, and warn about them.
Andrew M. Kuchling <amk@amk.ca>
parents: 26036
diff changeset
140 sys.stderr.write(msg + '\n')
12799
d81c95dd4039 Provides the Extension class, a nicer way to describe C/C++ extensions than
Greg Ward <gward@python.net>
parents:
diff changeset
141 # class Extension
14650
edda353bde12 Added 'read_setup_file()' to read old-style Setup files. Could make life
Greg Ward <gward@python.net>
parents: 13949
diff changeset
142
edda353bde12 Added 'read_setup_file()' to read old-style Setup files. Could make life
Greg Ward <gward@python.net>
parents: 13949
diff changeset
143
edda353bde12 Added 'read_setup_file()' to read old-style Setup files. Could make life
Greg Ward <gward@python.net>
parents: 13949
diff changeset
144 def read_setup_file (filename):
edda353bde12 Added 'read_setup_file()' to read old-style Setup files. Could make life
Greg Ward <gward@python.net>
parents: 13949
diff changeset
145 from distutils.sysconfig import \
edda353bde12 Added 'read_setup_file()' to read old-style Setup files. Could make life
Greg Ward <gward@python.net>
parents: 13949
diff changeset
146 parse_makefile, expand_makefile_vars, _variable_rx
edda353bde12 Added 'read_setup_file()' to read old-style Setup files. Could make life
Greg Ward <gward@python.net>
parents: 13949
diff changeset
147 from distutils.text_file import TextFile
edda353bde12 Added 'read_setup_file()' to read old-style Setup files. Could make life
Greg Ward <gward@python.net>
parents: 13949
diff changeset
148 from distutils.util import split_quoted
edda353bde12 Added 'read_setup_file()' to read old-style Setup files. Could make life
Greg Ward <gward@python.net>
parents: 13949
diff changeset
149
edda353bde12 Added 'read_setup_file()' to read old-style Setup files. Could make life
Greg Ward <gward@python.net>
parents: 13949
diff changeset
150 # First pass over the file to gather "VAR = VALUE" assignments.
edda353bde12 Added 'read_setup_file()' to read old-style Setup files. Could make life
Greg Ward <gward@python.net>
parents: 13949
diff changeset
151 vars = parse_makefile(filename)
edda353bde12 Added 'read_setup_file()' to read old-style Setup files. Could make life
Greg Ward <gward@python.net>
parents: 13949
diff changeset
152
edda353bde12 Added 'read_setup_file()' to read old-style Setup files. Could make life
Greg Ward <gward@python.net>
parents: 13949
diff changeset
153 # Second pass to gobble up the real content: lines of the form
edda353bde12 Added 'read_setup_file()' to read old-style Setup files. Could make life
Greg Ward <gward@python.net>
parents: 13949
diff changeset
154 # <module> ... [<sourcefile> ...] [<cpparg> ...] [<library> ...]
edda353bde12 Added 'read_setup_file()' to read old-style Setup files. Could make life
Greg Ward <gward@python.net>
parents: 13949
diff changeset
155 file = TextFile(filename,
edda353bde12 Added 'read_setup_file()' to read old-style Setup files. Could make life
Greg Ward <gward@python.net>
parents: 13949
diff changeset
156 strip_comments=1, skip_blanks=1, join_lines=1,
edda353bde12 Added 'read_setup_file()' to read old-style Setup files. Could make life
Greg Ward <gward@python.net>
parents: 13949
diff changeset
157 lstrip_ws=1, rstrip_ws=1)
edda353bde12 Added 'read_setup_file()' to read old-style Setup files. Could make life
Greg Ward <gward@python.net>
parents: 13949
diff changeset
158 extensions = []
edda353bde12 Added 'read_setup_file()' to read old-style Setup files. Could make life
Greg Ward <gward@python.net>
parents: 13949
diff changeset
159
edda353bde12 Added 'read_setup_file()' to read old-style Setup files. Could make life
Greg Ward <gward@python.net>
parents: 13949
diff changeset
160 while 1:
edda353bde12 Added 'read_setup_file()' to read old-style Setup files. Could make life
Greg Ward <gward@python.net>
parents: 13949
diff changeset
161 line = file.readline()
edda353bde12 Added 'read_setup_file()' to read old-style Setup files. Could make life
Greg Ward <gward@python.net>
parents: 13949
diff changeset
162 if line is None: # eof
edda353bde12 Added 'read_setup_file()' to read old-style Setup files. Could make life
Greg Ward <gward@python.net>
parents: 13949
diff changeset
163 break
edda353bde12 Added 'read_setup_file()' to read old-style Setup files. Could make life
Greg Ward <gward@python.net>
parents: 13949
diff changeset
164 if _variable_rx.match(line): # VAR=VALUE, handled in first pass
edda353bde12 Added 'read_setup_file()' to read old-style Setup files. Could make life
Greg Ward <gward@python.net>
parents: 13949
diff changeset
165 continue
edda353bde12 Added 'read_setup_file()' to read old-style Setup files. Could make life
Greg Ward <gward@python.net>
parents: 13949
diff changeset
166
edda353bde12 Added 'read_setup_file()' to read old-style Setup files. Could make life
Greg Ward <gward@python.net>
parents: 13949
diff changeset
167 if line[0] == line[-1] == "*":
edda353bde12 Added 'read_setup_file()' to read old-style Setup files. Could make life
Greg Ward <gward@python.net>
parents: 13949
diff changeset
168 file.warn("'%s' lines not handled yet" % line)
edda353bde12 Added 'read_setup_file()' to read old-style Setup files. Could make life
Greg Ward <gward@python.net>
parents: 13949
diff changeset
169 continue
edda353bde12 Added 'read_setup_file()' to read old-style Setup files. Could make life
Greg Ward <gward@python.net>
parents: 13949
diff changeset
170
edda353bde12 Added 'read_setup_file()' to read old-style Setup files. Could make life
Greg Ward <gward@python.net>
parents: 13949
diff changeset
171 #print "original line: " + line
edda353bde12 Added 'read_setup_file()' to read old-style Setup files. Could make life
Greg Ward <gward@python.net>
parents: 13949
diff changeset
172 line = expand_makefile_vars(line, vars)
edda353bde12 Added 'read_setup_file()' to read old-style Setup files. Could make life
Greg Ward <gward@python.net>
parents: 13949
diff changeset
173 words = split_quoted(line)
edda353bde12 Added 'read_setup_file()' to read old-style Setup files. Could make life
Greg Ward <gward@python.net>
parents: 13949
diff changeset
174 #print "expanded line: " + line
edda353bde12 Added 'read_setup_file()' to read old-style Setup files. Could make life
Greg Ward <gward@python.net>
parents: 13949
diff changeset
175
edda353bde12 Added 'read_setup_file()' to read old-style Setup files. Could make life
Greg Ward <gward@python.net>
parents: 13949
diff changeset
176 # NB. this parses a slightly different syntax than the old
edda353bde12 Added 'read_setup_file()' to read old-style Setup files. Could make life
Greg Ward <gward@python.net>
parents: 13949
diff changeset
177 # makesetup script: here, there must be exactly one extension per
edda353bde12 Added 'read_setup_file()' to read old-style Setup files. Could make life
Greg Ward <gward@python.net>
parents: 13949
diff changeset
178 # line, and it must be the first word of the line. I have no idea
edda353bde12 Added 'read_setup_file()' to read old-style Setup files. Could make life
Greg Ward <gward@python.net>
parents: 13949
diff changeset
179 # why the old syntax supported multiple extensions per line, as
edda353bde12 Added 'read_setup_file()' to read old-style Setup files. Could make life
Greg Ward <gward@python.net>
parents: 13949
diff changeset
180 # they all wind up being the same.
edda353bde12 Added 'read_setup_file()' to read old-style Setup files. Could make life
Greg Ward <gward@python.net>
parents: 13949
diff changeset
181
edda353bde12 Added 'read_setup_file()' to read old-style Setup files. Could make life
Greg Ward <gward@python.net>
parents: 13949
diff changeset
182 module = words[0]
edda353bde12 Added 'read_setup_file()' to read old-style Setup files. Could make life
Greg Ward <gward@python.net>
parents: 13949
diff changeset
183 ext = Extension(module, [])
edda353bde12 Added 'read_setup_file()' to read old-style Setup files. Could make life
Greg Ward <gward@python.net>
parents: 13949
diff changeset
184 append_next_word = None
edda353bde12 Added 'read_setup_file()' to read old-style Setup files. Could make life
Greg Ward <gward@python.net>
parents: 13949
diff changeset
185
edda353bde12 Added 'read_setup_file()' to read old-style Setup files. Could make life
Greg Ward <gward@python.net>
parents: 13949
diff changeset
186 for word in words[1:]:
edda353bde12 Added 'read_setup_file()' to read old-style Setup files. Could make life
Greg Ward <gward@python.net>
parents: 13949
diff changeset
187 if append_next_word is not None:
edda353bde12 Added 'read_setup_file()' to read old-style Setup files. Could make life
Greg Ward <gward@python.net>
parents: 13949
diff changeset
188 append_next_word.append(word)
edda353bde12 Added 'read_setup_file()' to read old-style Setup files. Could make life
Greg Ward <gward@python.net>
parents: 13949
diff changeset
189 append_next_word = None
edda353bde12 Added 'read_setup_file()' to read old-style Setup files. Could make life
Greg Ward <gward@python.net>
parents: 13949
diff changeset
190 continue
edda353bde12 Added 'read_setup_file()' to read old-style Setup files. Could make life
Greg Ward <gward@python.net>
parents: 13949
diff changeset
191
edda353bde12 Added 'read_setup_file()' to read old-style Setup files. Could make life
Greg Ward <gward@python.net>
parents: 13949
diff changeset
192 suffix = os.path.splitext(word)[1]
edda353bde12 Added 'read_setup_file()' to read old-style Setup files. Could make life
Greg Ward <gward@python.net>
parents: 13949
diff changeset
193 switch = word[0:2] ; value = word[2:]
edda353bde12 Added 'read_setup_file()' to read old-style Setup files. Could make life
Greg Ward <gward@python.net>
parents: 13949
diff changeset
194
21517
324684adb483 Suggested by Pete Shinners: treat .m and .mm files as source code.
Andrew M. Kuchling <amk@amk.ca>
parents: 21267
diff changeset
195 if suffix in (".c", ".cc", ".cpp", ".cxx", ".c++", ".m", ".mm"):
14650
edda353bde12 Added 'read_setup_file()' to read old-style Setup files. Could make life
Greg Ward <gward@python.net>
parents: 13949
diff changeset
196 # hmm, should we do something about C vs. C++ sources?
edda353bde12 Added 'read_setup_file()' to read old-style Setup files. Could make life
Greg Ward <gward@python.net>
parents: 13949
diff changeset
197 # or leave it up to the CCompiler implementation to
edda353bde12 Added 'read_setup_file()' to read old-style Setup files. Could make life
Greg Ward <gward@python.net>
parents: 13949
diff changeset
198 # worry about?
edda353bde12 Added 'read_setup_file()' to read old-style Setup files. Could make life
Greg Ward <gward@python.net>
parents: 13949
diff changeset
199 ext.sources.append(word)
edda353bde12 Added 'read_setup_file()' to read old-style Setup files. Could make life
Greg Ward <gward@python.net>
parents: 13949
diff changeset
200 elif switch == "-I":
edda353bde12 Added 'read_setup_file()' to read old-style Setup files. Could make life
Greg Ward <gward@python.net>
parents: 13949
diff changeset
201 ext.include_dirs.append(value)
edda353bde12 Added 'read_setup_file()' to read old-style Setup files. Could make life
Greg Ward <gward@python.net>
parents: 13949
diff changeset
202 elif switch == "-D":
17129
32bcb4e21005 Back out conversion to string methods; the Distutils is intended to work
Andrew M. Kuchling <amk@amk.ca>
parents: 16521
diff changeset
203 equals = string.find(value, "=")
14650
edda353bde12 Added 'read_setup_file()' to read old-style Setup files. Could make life
Greg Ward <gward@python.net>
parents: 13949
diff changeset
204 if equals == -1: # bare "-DFOO" -- no value
edda353bde12 Added 'read_setup_file()' to read old-style Setup files. Could make life
Greg Ward <gward@python.net>
parents: 13949
diff changeset
205 ext.define_macros.append((value, None))
edda353bde12 Added 'read_setup_file()' to read old-style Setup files. Could make life
Greg Ward <gward@python.net>
parents: 13949
diff changeset
206 else: # "-DFOO=blah"
edda353bde12 Added 'read_setup_file()' to read old-style Setup files. Could make life
Greg Ward <gward@python.net>
parents: 13949
diff changeset
207 ext.define_macros.append((value[0:equals],
edda353bde12 Added 'read_setup_file()' to read old-style Setup files. Could make life
Greg Ward <gward@python.net>
parents: 13949
diff changeset
208 value[equals+2:]))
edda353bde12 Added 'read_setup_file()' to read old-style Setup files. Could make life
Greg Ward <gward@python.net>
parents: 13949
diff changeset
209 elif switch == "-U":
edda353bde12 Added 'read_setup_file()' to read old-style Setup files. Could make life
Greg Ward <gward@python.net>
parents: 13949
diff changeset
210 ext.undef_macros.append(value)
edda353bde12 Added 'read_setup_file()' to read old-style Setup files. Could make life
Greg Ward <gward@python.net>
parents: 13949
diff changeset
211 elif switch == "-C": # only here 'cause makesetup has it!
edda353bde12 Added 'read_setup_file()' to read old-style Setup files. Could make life
Greg Ward <gward@python.net>
parents: 13949
diff changeset
212 ext.extra_compile_args.append(word)
edda353bde12 Added 'read_setup_file()' to read old-style Setup files. Could make life
Greg Ward <gward@python.net>
parents: 13949
diff changeset
213 elif switch == "-l":
edda353bde12 Added 'read_setup_file()' to read old-style Setup files. Could make life
Greg Ward <gward@python.net>
parents: 13949
diff changeset
214 ext.libraries.append(value)
edda353bde12 Added 'read_setup_file()' to read old-style Setup files. Could make life
Greg Ward <gward@python.net>
parents: 13949
diff changeset
215 elif switch == "-L":
edda353bde12 Added 'read_setup_file()' to read old-style Setup files. Could make life
Greg Ward <gward@python.net>
parents: 13949
diff changeset
216 ext.library_dirs.append(value)
edda353bde12 Added 'read_setup_file()' to read old-style Setup files. Could make life
Greg Ward <gward@python.net>
parents: 13949
diff changeset
217 elif switch == "-R":
edda353bde12 Added 'read_setup_file()' to read old-style Setup files. Could make life
Greg Ward <gward@python.net>
parents: 13949
diff changeset
218 ext.runtime_library_dirs.append(value)
edda353bde12 Added 'read_setup_file()' to read old-style Setup files. Could make life
Greg Ward <gward@python.net>
parents: 13949
diff changeset
219 elif word == "-rpath":
edda353bde12 Added 'read_setup_file()' to read old-style Setup files. Could make life
Greg Ward <gward@python.net>
parents: 13949
diff changeset
220 append_next_word = ext.runtime_library_dirs
edda353bde12 Added 'read_setup_file()' to read old-style Setup files. Could make life
Greg Ward <gward@python.net>
parents: 13949
diff changeset
221 elif word == "-Xlinker":
edda353bde12 Added 'read_setup_file()' to read old-style Setup files. Could make life
Greg Ward <gward@python.net>
parents: 13949
diff changeset
222 append_next_word = ext.extra_link_args
22663
9d2a8f6b06b6 [Patch #536769] Add -Xcompiler flag for adding arguments and switches for
Andrew M. Kuchling <amk@amk.ca>
parents: 21517
diff changeset
223 elif word == "-Xcompiler":
9d2a8f6b06b6 [Patch #536769] Add -Xcompiler flag for adding arguments and switches for
Andrew M. Kuchling <amk@amk.ca>
parents: 21517
diff changeset
224 append_next_word = ext.extra_compile_args
14650
edda353bde12 Added 'read_setup_file()' to read old-style Setup files. Could make life
Greg Ward <gward@python.net>
parents: 13949
diff changeset
225 elif switch == "-u":
edda353bde12 Added 'read_setup_file()' to read old-style Setup files. Could make life
Greg Ward <gward@python.net>
parents: 13949
diff changeset
226 ext.extra_link_args.append(word)
edda353bde12 Added 'read_setup_file()' to read old-style Setup files. Could make life
Greg Ward <gward@python.net>
parents: 13949
diff changeset
227 if not value:
edda353bde12 Added 'read_setup_file()' to read old-style Setup files. Could make life
Greg Ward <gward@python.net>
parents: 13949
diff changeset
228 append_next_word = ext.extra_link_args
26444
4ac38f28cd10 [Part of patch #641685] Add .dylib as an extension for shared libraries
Andrew M. Kuchling <amk@amk.ca>
parents: 26305
diff changeset
229 elif suffix in (".a", ".so", ".sl", ".o", ".dylib"):
14650
edda353bde12 Added 'read_setup_file()' to read old-style Setup files. Could make life
Greg Ward <gward@python.net>
parents: 13949
diff changeset
230 # NB. a really faithful emulation of makesetup would
edda353bde12 Added 'read_setup_file()' to read old-style Setup files. Could make life
Greg Ward <gward@python.net>
parents: 13949
diff changeset
231 # append a .o file to extra_objects only if it
edda353bde12 Added 'read_setup_file()' to read old-style Setup files. Could make life
Greg Ward <gward@python.net>
parents: 13949
diff changeset
232 # had a slash in it; otherwise, it would s/.o/.c/
edda353bde12 Added 'read_setup_file()' to read old-style Setup files. Could make life
Greg Ward <gward@python.net>
parents: 13949
diff changeset
233 # and append it to sources. Hmmmm.
edda353bde12 Added 'read_setup_file()' to read old-style Setup files. Could make life
Greg Ward <gward@python.net>
parents: 13949
diff changeset
234 ext.extra_objects.append(word)
edda353bde12 Added 'read_setup_file()' to read old-style Setup files. Could make life
Greg Ward <gward@python.net>
parents: 13949
diff changeset
235 else:
edda353bde12 Added 'read_setup_file()' to read old-style Setup files. Could make life
Greg Ward <gward@python.net>
parents: 13949
diff changeset
236 file.warn("unrecognized argument '%s'" % word)
edda353bde12 Added 'read_setup_file()' to read old-style Setup files. Could make life
Greg Ward <gward@python.net>
parents: 13949
diff changeset
237
edda353bde12 Added 'read_setup_file()' to read old-style Setup files. Could make life
Greg Ward <gward@python.net>
parents: 13949
diff changeset
238 extensions.append(ext)
edda353bde12 Added 'read_setup_file()' to read old-style Setup files. Could make life
Greg Ward <gward@python.net>
parents: 13949
diff changeset
239
edda353bde12 Added 'read_setup_file()' to read old-style Setup files. Could make life
Greg Ward <gward@python.net>
parents: 13949
diff changeset
240 #print "module:", module
edda353bde12 Added 'read_setup_file()' to read old-style Setup files. Could make life
Greg Ward <gward@python.net>
parents: 13949
diff changeset
241 #print "source files:", source_files
edda353bde12 Added 'read_setup_file()' to read old-style Setup files. Could make life
Greg Ward <gward@python.net>
parents: 13949
diff changeset
242 #print "cpp args:", cpp_args
edda353bde12 Added 'read_setup_file()' to read old-style Setup files. Could make life
Greg Ward <gward@python.net>
parents: 13949
diff changeset
243 #print "lib args:", library_args
edda353bde12 Added 'read_setup_file()' to read old-style Setup files. Could make life
Greg Ward <gward@python.net>
parents: 13949
diff changeset
244
edda353bde12 Added 'read_setup_file()' to read old-style Setup files. Could make life
Greg Ward <gward@python.net>
parents: 13949
diff changeset
245 #extensions[module] = { 'sources': source_files,
edda353bde12 Added 'read_setup_file()' to read old-style Setup files. Could make life
Greg Ward <gward@python.net>
parents: 13949
diff changeset
246 # 'cpp_args': cpp_args,
edda353bde12 Added 'read_setup_file()' to read old-style Setup files. Could make life
Greg Ward <gward@python.net>
parents: 13949
diff changeset
247 # 'lib_args': library_args }
21267
7a7f557b4d54 Whitespace normalization.
Fred Drake <fdrake@acm.org>
parents: 17129
diff changeset
248
14650
edda353bde12 Added 'read_setup_file()' to read old-style Setup files. Could make life
Greg Ward <gward@python.net>
parents: 13949
diff changeset
249 return extensions
edda353bde12 Added 'read_setup_file()' to read old-style Setup files. Could make life
Greg Ward <gward@python.net>
parents: 13949
diff changeset
250
edda353bde12 Added 'read_setup_file()' to read old-style Setup files. Could make life
Greg Ward <gward@python.net>
parents: 13949
diff changeset
251 # read_setup_file ()