blob: 9d2a6fa15cc747b0c1eada59d61b95dd85210ce7 [file] [log] [blame]
Greg Ward3ca54bc2000-05-31 01:05:35 +00001"""distutils.extension
2
3Provides the Extension class, used to describe C/C++ extension
4modules in setup scripts."""
5
6# created 2000/05/30, Greg Ward
7
8__revision__ = "$Id$"
9
10from types import *
11
12
13# This class is really only used by the "build_ext" command, so it might
14# make sense to put it in distutils.command.build_ext. However, that
15# module is already big enough, and I want to make this class a bit more
16# complex to simplify some common cases ("foo" module in "foo.c") and do
17# better error-checking ("foo.c" actually exists).
18#
19# Also, putting this in build_ext.py means every setup script would have to
20# import that large-ish module (indirectly, through distutils.core) in
21# order to do anything.
22
23class Extension:
24 """Just a collection of attributes that describes an extension
25 module and everything needed to build it (hopefully in a portable
26 way, but there are hooks that let you can be as unportable as you
27 need).
28
29 Instance attributes:
30 name : string
31 the full name of the extension, including any packages -- ie.
32 *not* a filename or pathname, but Python dotted name
33 sources : [string]
34 list of C/C++ source filenames, relative to the distribution
35 root (where the setup script lives), in Unix form
36 (slash-separated) for portability
37 include_dirs : [string]
38 list of directories to search for C/C++ header files (in Unix
39 form for portability)
40 define_macros : [(name : string, value : string|None)]
41 list of macros to define; each macro is defined using a 2-tuple,
42 where 'value' is either the string to define it to or None to
43 define it without a particular value (equivalent of "#define
44 FOO" in source or -DFOO on Unix C compiler command line)
45 undef_macros : [string]
46 list of macros to undefine explicitly
47 library_dirs : [string]
48 list of directories to search for C/C++ libraries at link time
49 libraries : [string]
50 list of library names (not filenames or paths) to link against
51 runtime_library_dirs : [string]
52 list of directories to search for C/C++ libraries at run time
53 (for shared extensions, this is when the extension is loaded)
54 extra_objects : [string]
55 list of extra files to link with (eg. object files not implied
56 by 'sources', static library that must be explicitly specified,
57 binary resource files, etc.)
58 extra_compile_args : [string]
59 any extra platform- and compiler-specific information to use
60 when compiling the source files in 'sources'. For platforms and
61 compilers where "command line" makes sense, this is typically a
62 list of command-line arguments, but for other platforms it could
63 be anything.
64 extra_link_args : [string]
65 any extra platform- and compiler-specific information to use
66 when linking object files together to create the extension (or
67 to create a new static Python interpreter). Similar
68 interpretation as for 'extra_compile_args'.
69 export_symbols : [string]
70 list of symbols to be exported from a shared extension. Not
71 used on all platforms, and not generally necessary for Python
72 extensions, which typically export exactly one symbol: "init" +
73 extension_name.
74 export_symbol_file : string
75 name of file that lists symbols to export; the format of this
76 file is platform- and compiler-specific. This is even more
77 gratuitous and unnecessary than 'export_symbols'; I'll be happy
78 when it goes away forever.
79 """
80
81 def __init__ (self, name, sources,
82 include_dirs=None,
83 define_macros=None,
84 undef_macros=None,
85 library_dirs=None,
86 libraries=None,
87 runtime_library_dirs=None,
88 extra_objects=None,
89 extra_compile_args=None,
90 extra_link_args=None,
91 export_symbols=None,
92 export_symbol_file=None,
93 ):
94
95 assert type(name) is StringType, "'name' must be a string"
96 assert (type(sources) is ListType and
97 len(sources) >= 1 and
98 map(type, sources) == [StringType]*len(sources)), \
99 "'sources' must be a non-empty list of strings"
100
101 self.name = name
102 self.sources = sources
103 self.include_dirs = include_dirs or []
104 self.define_macros = define_macros or []
105 self.undef_macros = undef_macros or []
106 self.library_dirs = library_dirs or []
107 self.libraries = libraries or []
108 self.runtime_library_dirs = runtime_library_dirs or []
109 self.extra_objects = extra_objects or []
110 self.extra_compile_args = extra_compile_args or []
111 self.extra_link_args = extra_link_args or []
112 self.export_symbols = export_symbols or []
113 self.export_symbol_file = export_symbol_file
114
115# class Extension